CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
TTTrackAssociator< T > Class Template Reference

Plugin to create the MC truth for TTTracks. More...

#include <TTTrackAssociator.h>

Inheritance diagram for TTTrackAssociator< T >:
edm::stream::EDProducer<>

Public Member Functions

 TTTrackAssociator (const edm::ParameterSet &iConfig)
 Constructors. More...
 
 ~TTTrackAssociator () override
 Destructor. More...
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndRuns () const final
 

Private Member Functions

void beginRun (const edm::Run &run, const edm::EventSetup &iSetup) override
 Mandatory methods. More...
 
void endRun (const edm::Run &run, const edm::EventSetup &iSetup) override
 End run. More...
 
template<>
void produce (edm::Event &iEvent, const edm::EventSetup &iSetup)
 
More...
 
template<>
void produce (edm::Event &iEvent, const edm::EventSetup &iSetup)
 Implement the producer. More...
 
void produce (edm::Event &iEvent, const edm::EventSetup &iSetup) override
 

Private Attributes

edm::EDGetTokenT< TTClusterAssociationMap< T > > TTClusterTruthToken
 
edm::EDGetTokenT< TTStubAssociationMap< T > > TTStubTruthToken
 
bool TTTrackAllowOneFalse2SStub
 
std::vector< edm::InputTagTTTracksInputTags
 Data members. More...
 
std::vector< edm::EDGetTokenT< std::vector< TTTrack< T > > > > TTTracksTokens
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer<>
typedef CacheContexts< T... > CacheTypes
 
typedef CacheTypes::GlobalCache GlobalCache
 
typedef AbilityChecker< T... > HasAbility
 
typedef CacheTypes::LuminosityBlockCache LuminosityBlockCache
 
typedef LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCacheLuminosityBlockContext
 
typedef CacheTypes::LuminosityBlockSummaryCache LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache, GlobalCacheRunContext
 
typedef CacheTypes::RunSummaryCache RunSummaryCache
 

Detailed Description

template<typename T>
class TTTrackAssociator< T >

Plugin to create the MC truth for TTTracks.

After moving from SimDataFormats to DataFormats, the template structure of the class was maintained in order to accomodate any types other than PixelDigis in case there is such a need in the future.

Author
Nicola Pozzobon
Date
2013, Jul 19

Definition at line 40 of file TTTrackAssociator.h.

Constructor & Destructor Documentation

◆ TTTrackAssociator()

template<typename T >
TTTrackAssociator< T >::TTTrackAssociator ( const edm::ParameterSet iConfig)
explicit

Constructors.

Close class.

NOTE since pattern hit correlation must be performed within a stacked module, one must store Clusters in a proper way, providing easy access to them in a detector/member-wise way

Implementation of methods

Here, in the header file, the methods which do not depend on the specific type <T> that can fit the template. Other methods, with type-specific features, are implemented in the source file. Constructors

Definition at line 77 of file TTTrackAssociator.h.

77  {
78  TTTracksInputTags = iConfig.getParameter<std::vector<edm::InputTag> >("TTTracks");
79  TTClusterTruthToken = consumes<TTClusterAssociationMap<T> >(iConfig.getParameter<edm::InputTag>("TTClusterTruth"));
80  TTStubTruthToken = consumes<TTStubAssociationMap<T> >(iConfig.getParameter<edm::InputTag>("TTStubTruth"));
81  TTTrackAllowOneFalse2SStub = iConfig.getParameter<bool>("TTTrackAllowOneFalse2SStub");
83  edm::LogInfo("TTTrackAssociator< ") << "Allow track if no more than one 2S stub doesn't match truth.";
84  } else {
85  edm::LogInfo("TTTrackAssociator< ") << "All 2S stubs must match truth.";
86  }
87 
88  for (auto iTag = TTTracksInputTags.begin(); iTag != TTTracksInputTags.end(); iTag++) {
89  TTTracksTokens.push_back(consumes<std::vector<TTTrack<T> > >(*iTag));
90 
91  produces<TTTrackAssociationMap<T> >((*iTag).instance());
92  }
93 }

References edm::ParameterSet::getParameter(), and TTTrackAssociation_cfi::TTTrackAllowOneFalse2SStub.

◆ ~TTTrackAssociator()

template<typename T >
TTTrackAssociator< T >::~TTTrackAssociator ( )
override

Destructor.

Definition at line 97 of file TTTrackAssociator.h.

97 {}

Member Function Documentation

◆ beginRun()

template<typename T >
void TTTrackAssociator< T >::beginRun ( const edm::Run run,
const edm::EventSetup iSetup 
)
overrideprivate

Mandatory methods.

Begin run.

Print some information when loaded

Definition at line 101 of file TTTrackAssociator.h.

101  {
103  edm::LogInfo("TTStubAssociator< ") << "TTTrackAssociator< " << templateNameFinder<T>() << " > loaded.";
104 }

◆ endRun()

template<typename T >
void TTTrackAssociator< T >::endRun ( const edm::Run run,
const edm::EventSetup iSetup 
)
overrideprivate

End run.

Definition at line 108 of file TTTrackAssociator.h.

108 {}

◆ produce() [1/3]

template<>
void TTTrackAssociator< Ref_Phase2TrackerDigi_ >::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
private


Here, in the source file, the methods which do depend on the specific type <T> that can fit the template.

Author
Nicola Pozzobon
Date
2013, Jul 19 Implement the producer

Exit if real data

Get the Stub and Cluster MC truth

Loop over InputTags to handle multiple collections

Prepare output

Get the Tracks already stored away

Prepare the necessary maps

Counter needed to build the edm::Ptr to the TTTrack

Make the pointer to be put in the map

Get the stubs of the TTTrack (theseStubs)

Auxiliary map to store TP addresses and TP edm::Ptr

Fill the inclusive map which is careless of the stub classification

Prepare the maps wrt TrackingParticle

Fill the auxiliary map

Fill the other auxiliary map

End of loop over the clusters

Check if the stub is unknown

End of loop over the stubs

If there more than 2 unknown stubs, go to the next track as this track may be COMBINATORIC or UNKNOWN

If we are here, all the stubs are either combinatoric or genuine and there is no more than one fake stub in the track Loop over all the TrackingParticle which have been found in the track at some point (stored in auxMap)

Get all the stubs from this TrackingParticle

Loop over the stubs

We want that all the stubs of the track are included in the container of all the stubs produced by this particular TrackingParticle which we already know is one of the TrackingParticles that released hits in this track we are evaluating right now

If the TrackingParticle does not appear in all stubs but one then go to the next track

If we are here, it means that the TrackingParticle generates hits in all stubs but one of the current track so put it into the vector

Count how many TrackingParticles we do have

If only one TrackingParticle, GENUINE if different than one, COMBINATORIC

Here, the track may only be GENUINE Fill the map

End of loop over Tracks

Clean the only map that needs cleaning Prepare the output map wrt TrackingParticle

Get the vector of edm::Ptr< TTTrack >

Sort and remove duplicates

Also, create the pointer to the TTClusterAssociationMap

Put the maps in the association object

Put output in the event

End of loop over InputTags

Definition at line 14 of file TTTrackAssociator.cc.

14  {
16  if (iEvent.isRealData())
17  return;
18 
21  iEvent.getByToken(TTClusterTruthToken, TTClusterAssociationMapHandle);
23  iEvent.getByToken(TTStubTruthToken, TTStubAssociationMapHandle);
24 
25  int ncont1 = 0;
26 
28  for (auto iTag = TTTracksTokens.begin(); iTag != TTTracksTokens.end(); iTag++) {
30  auto associationMapForOutput = std::make_unique<TTTrackAssociationMap<Ref_Phase2TrackerDigi_>>();
31 
34  iEvent.getByToken(*iTag, TTTrackHandle);
35 
37  std::map<edm::Ptr<TTTrack<Ref_Phase2TrackerDigi_>>, edm::Ptr<TrackingParticle>> trackToTrackingParticleMap;
38  std::map<edm::Ptr<TrackingParticle>, std::vector<edm::Ptr<TTTrack<Ref_Phase2TrackerDigi_>>>>
39  trackingParticleToTrackVectorMap;
40  trackToTrackingParticleMap.clear();
41  trackingParticleToTrackVectorMap.clear();
42 
43  // Start the loop on tracks
44 
45  unsigned int j = 0;
46  typename std::vector<TTTrack<Ref_Phase2TrackerDigi_>>::const_iterator inputIter;
47  for (inputIter = TTTrackHandle->begin(); inputIter != TTTrackHandle->end(); ++inputIter) {
49  edm::Ptr<TTTrack<Ref_Phase2TrackerDigi_>> tempTrackPtr(TTTrackHandle, j++);
50 
52  std::vector<edm::Ref<edmNew::DetSetVector<TTStub<Ref_Phase2TrackerDigi_>>, TTStub<Ref_Phase2TrackerDigi_>>>
53  theseStubs = tempTrackPtr->getStubRefs();
54 
56  std::map<const TrackingParticle*, edm::Ptr<TrackingParticle>> auxMap;
57  auxMap.clear();
58  int mayCombinUnknown = 0;
59 
61  for (unsigned int is = 0; is < theseStubs.size(); is++) {
62  // std::vector< edm::Ref< edmNew::DetSetVector< TTCluster< Ref_Phase2TrackerDigi_ > >, TTCluster< Ref_Phase2TrackerDigi_ > > > theseClusters = theseStubs.at(is)->getClusterRefs();
63  for (unsigned int ic = 0; ic < 2; ic++) {
64  std::vector<edm::Ptr<TrackingParticle>> tempTPs =
65  TTClusterAssociationMapHandle->findTrackingParticlePtrs(theseStubs.at(is)->clusterRef(ic));
66  for (unsigned int itp = 0; itp < tempTPs.size(); itp++) // List of TPs linked to stub clusters
67  {
68  edm::Ptr<TrackingParticle> testTP = tempTPs.at(itp);
69 
70  if (testTP.isNull()) // No TP linked to this cluster
71  continue;
72 
74  if (trackingParticleToTrackVectorMap.find(testTP) == trackingParticleToTrackVectorMap.end()) {
75  std::vector<edm::Ptr<TTTrack<Ref_Phase2TrackerDigi_>>> trackVector;
76  trackVector.clear();
77  trackingParticleToTrackVectorMap.insert(std::make_pair(testTP, trackVector));
78  }
79  trackingParticleToTrackVectorMap.find(testTP)->second.push_back(tempTrackPtr);
80 
82  if (auxMap.find(testTP.get()) == auxMap.end()) {
83  auxMap.insert(std::make_pair(testTP.get(), testTP));
84  }
85  }
86  }
87 
89  if (TTStubAssociationMapHandle->isUnknown(theseStubs.at(is)))
90  ++mayCombinUnknown;
91 
92  }
93 
96  if (mayCombinUnknown >= 2)
97  continue;
98 
103 
104  std::vector<const TrackingParticle*> tpInAllStubs;
105 
106  std::map<const TrackingParticle*, edm::Ptr<TrackingParticle>>::const_iterator iterAuxMap;
107  for (iterAuxMap = auxMap.begin(); iterAuxMap != auxMap.end(); ++iterAuxMap) {
109  std::vector<edm::Ref<edmNew::DetSetVector<TTStub<Ref_Phase2TrackerDigi_>>, TTStub<Ref_Phase2TrackerDigi_>>>
110  tempStubs = TTStubAssociationMapHandle->findTTStubRefs(iterAuxMap->second);
111 
112  int nnotfound = 0;
113  //bool allFound = true;
115  // for ( unsigned int js = 0; js < theseStubs.size() && allFound; js++ )
116  for (unsigned int js = 0; js < theseStubs.size(); js++) {
121  if (std::find(tempStubs.begin(), tempStubs.end(), theseStubs.at(js)) == tempStubs.end()) {
122  // allFound = false;
123  ++nnotfound;
124  }
125  }
126 
129  if (nnotfound > 1)
130  //if (!allFound)
131  continue;
132 
136  tpInAllStubs.push_back(iterAuxMap->first);
137  }
138 
140  std::sort(tpInAllStubs.begin(), tpInAllStubs.end());
141  tpInAllStubs.erase(std::unique(tpInAllStubs.begin(), tpInAllStubs.end()), tpInAllStubs.end());
142  unsigned int nTPs = tpInAllStubs.size();
143 
146  if (nTPs != 1)
147  continue;
148 
151  trackToTrackingParticleMap.insert(std::make_pair(tempTrackPtr, auxMap.find(tpInAllStubs.at(0))->second));
152 
153  }
154 
157  typename std::map<edm::Ptr<TrackingParticle>, std::vector<edm::Ptr<TTTrack<Ref_Phase2TrackerDigi_>>>>::iterator
158  iterMapToClean;
159  for (iterMapToClean = trackingParticleToTrackVectorMap.begin();
160  iterMapToClean != trackingParticleToTrackVectorMap.end();
161  ++iterMapToClean) {
163  std::vector<edm::Ptr<TTTrack<Ref_Phase2TrackerDigi_>>> tempVector = iterMapToClean->second;
164 
166  std::sort(tempVector.begin(), tempVector.end());
167  tempVector.erase(std::unique(tempVector.begin(), tempVector.end()), tempVector.end());
168 
169  iterMapToClean->second = tempVector;
170  }
171 
173  edm::RefProd<TTStubAssociationMap<Ref_Phase2TrackerDigi_>> theStubAssoMap(TTStubAssociationMapHandle);
174 
176  associationMapForOutput->setTTTrackToTrackingParticleMap(trackToTrackingParticleMap);
177  associationMapForOutput->setTrackingParticleToTTTracksMap(trackingParticleToTrackVectorMap);
178  associationMapForOutput->setTTStubAssociationMap(theStubAssoMap);
179  associationMapForOutput->setAllowOneFalse2SStub(TTTrackAllowOneFalse2SStub);
180 
182  iEvent.put(std::move(associationMapForOutput), TTTracksInputTags.at(ncont1).instance());
183 
184  ++ncont1;
185  }
186 }

References spr::find(), edm::Ptr< T >::get(), iEvent, edm::Ptr< T >::isNull(), dqmiolumiharvest::j, eostools::move(), edm::second(), TTTrackAssociation_cfi::TTTrackAllowOneFalse2SStub, and tier0::unique().

◆ produce() [2/3]

template<>
void TTTrackAssociator< Ref_Phase2TrackerDigi_ >::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
private

Implement the producer.

◆ produce() [3/3]

template<typename T >
void TTTrackAssociator< T >::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivate

Member Data Documentation

◆ TTClusterTruthToken

template<typename T >
edm::EDGetTokenT<TTClusterAssociationMap<T> > TTTrackAssociator< T >::TTClusterTruthToken
private

Definition at line 57 of file TTTrackAssociator.h.

◆ TTStubTruthToken

template<typename T >
edm::EDGetTokenT<TTStubAssociationMap<T> > TTTrackAssociator< T >::TTStubTruthToken
private

Definition at line 56 of file TTTrackAssociator.h.

◆ TTTrackAllowOneFalse2SStub

template<typename T >
bool TTTrackAssociator< T >::TTTrackAllowOneFalse2SStub
private

Definition at line 59 of file TTTrackAssociator.h.

◆ TTTracksInputTags

template<typename T >
std::vector<edm::InputTag> TTTrackAssociator< T >::TTTracksInputTags
private

Data members.

Definition at line 52 of file TTTrackAssociator.h.

◆ TTTracksTokens

template<typename T >
std::vector<edm::EDGetTokenT<std::vector<TTTrack<T> > > > TTTrackAssociator< T >::TTTracksTokens
private

Definition at line 54 of file TTTrackAssociator.h.

edm::RefProd
Definition: EDProductfwd.h:25
edm::LogInfo
Definition: MessageLogger.h:254
TTTrack
Class to store the L1 Track Trigger tracks.
Definition: TTTrack.h:26
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:215
edm::Ptr::get
T const * get() const
Returns C++ pointer to the item.
Definition: Ptr.h:139
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
edm::Handle
Definition: AssociativeIterator.h:50
TTStub
Class to store the L1 Track Trigger stubs.
Definition: TTStub.h:22
TTTrackAssociator::TTTrackAllowOneFalse2SStub
bool TTTrackAllowOneFalse2SStub
Definition: TTTrackAssociator.h:59
iEvent
int iEvent
Definition: GenABIO.cc:224
TTTrackAssociator::TTClusterTruthToken
edm::EDGetTokenT< TTClusterAssociationMap< T > > TTClusterTruthToken
Definition: TTTrackAssociator.h:57
edm::Ptr< TrackingParticle >
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
eostools.move
def move(src, dest)
Definition: eostools.py:511
tier0.unique
def unique(seq, keepstr=True)
Definition: tier0.py:24
TTTrackAssociator::TTStubTruthToken
edm::EDGetTokenT< TTStubAssociationMap< T > > TTStubTruthToken
Definition: TTTrackAssociator.h:56
TTTrackAssociator::TTTracksInputTags
std::vector< edm::InputTag > TTTracksInputTags
Data members.
Definition: TTTrackAssociator.h:52
TTTrackAssociator::TTTracksTokens
std::vector< edm::EDGetTokenT< std::vector< TTTrack< T > > > > TTTracksTokens
Definition: TTTrackAssociator.h:54
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
edm::Ptr::isNull
bool isNull() const
Checks for null.
Definition: Ptr.h:142
edm::InputTag
Definition: InputTag.h:15