Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Truth flags to decoded tracks #69

Open
wants to merge 10 commits into
base: 14_0_X
Choose a base branch
from
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ __init__.py
.#*
#*#
*~
*/NanoNizer
42 changes: 22 additions & 20 deletions NtupleProducer/plugins/BuildFile.xml
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
<use name="CommonTools/UtilAlgos"/>
<use name="CommonTools/Utils"/>
<use name="DataFormats/Candidate"/>
<use name="DataFormats/PatCandidates"/>
<use name="DataFormats/HepMCCandidate"/>
<use name="DataFormats/JetReco"/>
<use name="DataFormats/L1TrackTrigger"/>
<use name="DataFormats/METReco"/>
<use name="DataFormats/Math"/>
<use name="DataFormats/NanoAOD"/>
<use name="DataFormats/L1TParticleFlow"/>
<use name="FWCore/Framework"/>
<use name="FWCore/ParameterSet"/>
<use name="FWCore/ServiceRegistry"/>
<use name="L1Trigger/Phase2L1ParticleFlow"/>
<use name="MagneticField/Engine"/>
<use name="MagneticField/Records"/>
<use name="PhysicsTools/NanoAOD"/>
<use name="L1Trigger/L1THGCal"/>

<use name="CommonTools/UtilAlgos" />
<use name="CommonTools/Utils" />
<use name="DataFormats/Candidate" />
<use name="DataFormats/PatCandidates" />
<use name="DataFormats/HepMCCandidate" />
<use name="DataFormats/JetReco" />
<use name="DataFormats/L1TrackTrigger" />
<use name="DataFormats/METReco" />
<use name="DataFormats/Math" />
<use name="DataFormats/NanoAOD" />
<use name="DataFormats/L1TParticleFlow" />
<use name="FWCore/Framework" />
<use name="FWCore/ParameterSet" />
<use name="FWCore/ServiceRegistry" />
<use name="L1Trigger/Phase2L1ParticleFlow" />
<use name="MagneticField/Engine" />
<use name="MagneticField/Records" />
<use name="PhysicsTools/NanoAOD" />
<use name="L1Trigger/L1THGCal" />
<use name="SimTracker/TrackTriggerAssociation" />
<use name="heppdt" />
<use name="hepmc" />
<!-- <use name="Utilities/General"/> -->
<flags EDM_PLUGIN="1"/>
102 changes: 102 additions & 0 deletions NtupleProducer/plugins/L1DecTkTruthTableProducer.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// user include files
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/global/EDProducer.h"
#include "FWCore/Framework/interface/Event.h"

#include "DataFormats/Common/interface/Handle.h"
#include "DataFormats/Common/interface/View.h"
#include "DataFormats/Common/interface/RefToPtr.h"

#include "DataFormats/L1TParticleFlow/interface/PFTrack.h"
#include "DataFormats/Math/interface/deltaR.h"

#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/InputTag.h"

#include "DataFormats/NanoAOD/interface/FlatTable.h"

#include "CommonTools/Utils/interface/StringCutObjectSelector.h"
#include "CommonTools/Utils/interface/StringObjectFunction.h"

#include "L1Trigger/Phase2L1ParticleFlow/interface/L1TPFUtils.h"

#include "SimTracker/TrackTriggerAssociation/interface/TTTrackAssociationMap.h"

#include <algorithm>

class L1DecTkTruthTableProducer : public edm::global::EDProducer<> {
public:
explicit L1DecTkTruthTableProducer(const edm::ParameterSet&);
~L1DecTkTruthTableProducer();

private:
virtual void produce(edm::StreamID id, edm::Event& iEvent, const edm::EventSetup& iSetup) const override;
//std::vector<l1t::PFTrack>

std::string name_;
edm::EDGetTokenT<std::vector<l1t::PFTrack>> decTks_;
edm::EDGetTokenT<TTTrackAssociationMap<Ref_Phase2TrackerDigi_>> ttTrackMCTruthToken_;
};

L1DecTkTruthTableProducer::L1DecTkTruthTableProducer(const edm::ParameterSet& iConfig)
: name_(iConfig.getParameter<std::string>("name")),
decTks_(consumes<std::vector<l1t::PFTrack>>(iConfig.getParameter<edm::InputTag>("src"))),
ttTrackMCTruthToken_(consumes<TTTrackAssociationMap<Ref_Phase2TrackerDigi_>>(
iConfig.getParameter<edm::InputTag>("MCTruthTrackInputTag")))
{
produces<nanoaod::FlatTable>();
}

L1DecTkTruthTableProducer::~L1DecTkTruthTableProducer() {}

// ------------ method called for each event ------------
void L1DecTkTruthTableProducer::produce(edm::StreamID id, edm::Event& iEvent, const edm::EventSetup& iSetup) const {
edm::Handle<std::vector<l1t::PFTrack>> decTks;
edm::Handle<TTTrackAssociationMap<Ref_Phase2TrackerDigi_>> MCTruthTTTrackHandle;
iEvent.getByToken(decTks_, decTks);
iEvent.getByToken(ttTrackMCTruthToken_, MCTruthTTTrackHandle);

// create the table
unsigned int ncands = decTks->size();
auto out = std::make_unique<nanoaod::FlatTable>(ncands, name_, false, true);

std::vector<int> isGenuine(ncands), isLooselyGenuine(ncands), isUnknown(ncands), isCombinatoric(ncands), isReal(ncands);
std::vector<unsigned int> tpmatch(ncands);

for (unsigned int i = 0; i < ncands; ++i) {
const auto tkPtr = edm::refToPtr((*decTks)[i].track());
isGenuine[i] = MCTruthTTTrackHandle->isGenuine(tkPtr);
isLooselyGenuine[i] = MCTruthTTTrackHandle->isLooselyGenuine(tkPtr);
isUnknown[i] = MCTruthTTTrackHandle->isUnknown(tkPtr);
isCombinatoric[i] = MCTruthTTTrackHandle->isCombinatoric(tkPtr);
tpmatch[i] = (isCombinatoric[i]) + (isUnknown[i] << 1) + (isLooselyGenuine[i] << 2) + (isGenuine[i] << 3);

edm::Ptr<TrackingParticle> my_tp = MCTruthTTTrackHandle->findTrackingParticlePtr(tkPtr);
int tmp_isReal;
if (my_tp.isNull()) {
tmp_isReal = 0;
} else {
int tmp = (my_tp->eventId().event());
if (tmp > 0) {
tmp_isReal = 2;
} else {
tmp_isReal = 1;
}
}
isReal[i] = tmp_isReal;
}

out->addColumn<float>("isGenuine", isGenuine, "");
out->addColumn<float>("isLooselyGenuine", isLooselyGenuine, "");
out->addColumn<float>("isUnknown", isUnknown, "");
out->addColumn<float>("isCombinatoric", isCombinatoric, "");
out->addColumn<float>("isReal", isReal, "");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if "isReal" is an appropriate name. This variable is 0 if the track is combinatoric, 1 if the track was generated by a tracking particle produced in the hard scattering, 2 if the track is due to pileup

out->addColumn<float>("tpmatch", tpmatch, "");

// save to the event branches
iEvent.put(std::move(out));
}

//define this as a plug-in
#include "FWCore/Framework/interface/MakerMacros.h"
DEFINE_FWK_MODULE(L1DecTkTruthTableProducer);
Loading