CMS 3D CMS Logo

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

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

#include <TTStubAssociator.h>

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

Public Member Functions

 TTStubAssociator (const edm::ParameterSet &iConfig)
 Constructors. More...
 
 ~TTStubAssociator () override
 Destructor. More...
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () 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::ESHandle< TrackerGeometrytheTrackerGeometry
 
edm::ESHandle< TrackerTopologytheTrackerTopology
 
std::vector< edm::InputTagTTClusterTruthInputTags
 
std::vector< edm::EDGetTokenT< TTClusterAssociationMap< T > > > TTClusterTruthTokens
 
std::vector< edm::InputTagTTStubsInputTags
 Data members. More...
 
std::vector< edm::EDGetTokenT< edmNew::DetSetVector< TTStub< T > > > > TTStubsTokens
 

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 TTStubAssociator< T >

Plugin to create the MC truth for TTStubs.

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 44 of file TTStubAssociator.h.

Constructor & Destructor Documentation

◆ TTStubAssociator()

template<typename T >
TTStubAssociator< T >::TTStubAssociator ( 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 81 of file TTStubAssociator.h.

81  {
82  TTStubsInputTags = iConfig.getParameter<std::vector<edm::InputTag> >("TTStubs");
83  TTClusterTruthInputTags = iConfig.getParameter<std::vector<edm::InputTag> >("TTClusterTruth");
84 
85  for (auto iTag = TTClusterTruthInputTags.begin(); iTag != TTClusterTruthInputTags.end(); iTag++) {
86  TTClusterTruthTokens.push_back(consumes<TTClusterAssociationMap<T> >(*iTag));
87  }
88 
89  for (auto iTag = TTStubsInputTags.begin(); iTag != TTStubsInputTags.end(); iTag++) {
90  TTStubsTokens.push_back(consumes<edmNew::DetSetVector<TTStub<T> > >(*iTag));
91 
92  produces<TTStubAssociationMap<T> >((*iTag).instance());
93  }
94 }

References edm::ParameterSet::getParameter().

◆ ~TTStubAssociator()

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

Destructor.

Definition at line 98 of file TTStubAssociator.h.

98 {}

Member Function Documentation

◆ beginRun()

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

Mandatory methods.

Begin run.

Print some information when loaded

Definition at line 102 of file TTStubAssociator.h.

102  {
104  edm::LogInfo("TTStubAssociator< ") << templateNameFinder<T>() << " > loaded.";
105 
108 }

References edm::EventSetup::get(), and get.

◆ endRun()

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

End run.

Definition at line 112 of file TTStubAssociator.h.

112 {}

◆ produce() [1/3]

template<>
void TTStubAssociator< 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

Exit if the vectors are uncorrectly dimensioned

Loop over the InputTags to handle multiple collections

Prepare output

Get the Stubs already stored away

Get the Cluster MC truth

Prepare the necessary maps

Loop over the input Stubs

Get the DetSets of the Clusters

Make the reference to be put in the map

Get the two clusters

Fill the inclusive map which is careless of the stub classification

Prepare the maps wrt TrackingParticle

Fill the auxiliary map

GENUINE for clusters means not combinatoric and not unknown: same MC truth content MUST be found in both clusters composing the stub

If at least one cluster is unknown, it means either unknown, either combinatoric Do nothing, and go to the next Stub

Here both are clusters are genuine/combinatoric If both clusters have some known SimTrack content they must be compared to each other

If both clusters are genuine, they must be associated to the same TrackingParticle in order to return a genuine stub. Period. Note we can perform safely this comparison because, if both clusters are genuine, their TrackingParticle shall NEVER be NULL

Two genuine clusters with same SimTrack content mean genuine

Fill the map: by construction, this will always be the first time the stub is inserted into the map: no need for "find"

At this point, go to the next Stub

It means combinatoric

End of two genuine clusters

Here, at least one cluster is combinatoric

Skip NULL pointers

Skip NULL pointers

Same SimTrack is present in both clusters

If two different SimTracks are found in both clusters, then the stub is for sure combinatoric

End of double loop over SimTracks of both clusters

If two different SimTracks are found in both clusters, go to the next stub

No SimTracks were found to be in both clusters

Only one SimTrack was found to be present in both clusters even if one of the clusters (or both) are combinatoric: this means there is only one track that participates in both clusters, hence the stub is genuine

Fill the map: by construction, this will always be the first time the stub is inserted into the map: no need for "find"

At this point, go to the next Stub

End of one single SimTrack in both clusters

End of "at least one cluster is combinatoric"

End of "both clusters are known, somehow..."

End of loop over Stubs

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

Get the vector of references to TTStub

Sort and remove duplicates

Put the vector in the output map

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 TTStubAssociator.cc.

14  {
16  if (iEvent.isRealData())
17  return;
18 
20  if (TTClusterTruthInputTags.size() != TTStubsInputTags.size()) {
21  edm::LogError("TTStubAsso ") << "E R R O R! the InputTag vectors have different size!";
22  return;
23  }
24 
25  int ncont1 = 0;
26 
27  const TrackerGeometry* const theTrackerGeom = theTrackerGeometry.product();
28  const TrackerTopology* const tTopo = theTrackerTopology.product();
29 
31 
32  for (auto iTag = TTStubsTokens.begin(); iTag != TTStubsTokens.end(); iTag++) {
34  auto associationMapForOutput = std::make_unique<TTStubAssociationMap<Ref_Phase2TrackerDigi_>>();
35 
38  iEvent.getByToken(*iTag, TTStubHandle);
39 
42  iEvent.getByToken(TTClusterTruthTokens.at(ncont1), TTClusterAssociationMapHandle);
43 
45  std::map<edm::Ref<edmNew::DetSetVector<TTStub<Ref_Phase2TrackerDigi_>>, TTStub<Ref_Phase2TrackerDigi_>>,
47  stubToTrackingParticleMap;
48  std::map<edm::Ptr<TrackingParticle>,
49  std::vector<edm::Ref<edmNew::DetSetVector<TTStub<Ref_Phase2TrackerDigi_>>, TTStub<Ref_Phase2TrackerDigi_>>>>
50  trackingParticleToStubVectorMap;
51  stubToTrackingParticleMap.clear();
52  trackingParticleToStubVectorMap.clear();
53 
55 
56  if (!TTStubHandle->empty()) {
57  for (auto gd = theTrackerGeom->dets().begin(); gd != theTrackerGeom->dets().end(); gd++) {
58  DetId detid = (*gd)->geographicalId();
59  if (detid.subdetId() != StripSubdetector::TOB && detid.subdetId() != StripSubdetector::TID)
60  continue; // only run on OT
61 
62  if (!tTopo->isLower(detid))
63  continue; // loop on the stacks: choose the lower arbitrarily
64 
65  DetId stackDetid = tTopo->stack(detid); // Stub module detid
66 
67  if (TTStubHandle->find(stackDetid) == TTStubHandle->end())
68  continue;
69 
71  edmNew::DetSet<TTStub<Ref_Phase2TrackerDigi_>> stubs = (*TTStubHandle)[stackDetid];
72 
73  for (auto contentIter = stubs.begin(); contentIter != stubs.end(); ++contentIter) {
76  edmNew::makeRefTo(TTStubHandle, contentIter);
77 
79  // std::vector< edm::Ref< edmNew::DetSetVector< TTCluster< Ref_Phase2TrackerDigi_ > >, TTCluster< Ref_Phase2TrackerDigi_ > > > theseClusters = tempStubRef->getClusterRefs();
80 
82  for (unsigned int ic = 0; ic < 2; ic++) {
83  std::vector<edm::Ptr<TrackingParticle>> tempTPs =
84  TTClusterAssociationMapHandle->findTrackingParticlePtrs(tempStubRef->clusterRef(ic));
85 
86  for (unsigned int itp = 0; itp < tempTPs.size(); itp++) {
87  edm::Ptr<TrackingParticle> testTP = tempTPs.at(itp);
88 
89  if (testTP.isNull())
90  continue;
91 
93  if (trackingParticleToStubVectorMap.find(testTP) == trackingParticleToStubVectorMap.end()) {
96  stubVector;
97  stubVector.clear();
98  trackingParticleToStubVectorMap.insert(std::make_pair(testTP, stubVector));
99  }
100  trackingParticleToStubVectorMap.find(testTP)->second.push_back(tempStubRef);
101  }
102  }
103 
107  if (TTClusterAssociationMapHandle->isUnknown(tempStubRef->clusterRef(0)) ||
108  TTClusterAssociationMapHandle->isUnknown(tempStubRef->clusterRef(1))) {
112  continue;
113  } else {
117  if (TTClusterAssociationMapHandle->isGenuine(tempStubRef->clusterRef(0)) &&
118  TTClusterAssociationMapHandle->isGenuine(tempStubRef->clusterRef(1))) {
122  if (TTClusterAssociationMapHandle->findTrackingParticlePtr(tempStubRef->clusterRef(0)).get() ==
123  TTClusterAssociationMapHandle->findTrackingParticlePtr(tempStubRef->clusterRef(1)).get()) {
126  TTClusterAssociationMapHandle->findTrackingParticlePtr(tempStubRef->clusterRef(0));
127 
130  stubToTrackingParticleMap.insert(std::make_pair(tempStubRef, testTP));
131 
133  continue;
134  } else {
136  continue;
137  }
138  }
139  else {
141  TrackingParticle* prevTPAddress = nullptr;
142  unsigned int whichTP = 0;
143 
144  std::vector<edm::Ptr<TrackingParticle>> trackingParticles0 =
145  TTClusterAssociationMapHandle->findTrackingParticlePtrs(tempStubRef->clusterRef(0));
146  std::vector<edm::Ptr<TrackingParticle>> trackingParticles1 =
147  TTClusterAssociationMapHandle->findTrackingParticlePtrs(tempStubRef->clusterRef(1));
148 
149  bool escape = false;
150 
151  for (unsigned int i = 0; i < trackingParticles0.size() && !escape; i++) {
153  if (trackingParticles0.at(i).isNull())
154  continue;
155 
156  for (unsigned int k = 0; k < trackingParticles1.size() && !escape; k++) {
158  if (trackingParticles1.at(k).isNull())
159  continue;
160 
161  if (trackingParticles0.at(i).get() == trackingParticles1.at(k).get()) {
163  if (prevTPAddress == nullptr) {
164  prevTPAddress = const_cast<TrackingParticle*>(trackingParticles1.at(k).get());
165  whichTP = k;
166  }
167 
170  if (prevTPAddress != const_cast<TrackingParticle*>(trackingParticles1.at(k).get())) {
171  escape = true;
172  continue;
173  }
174  }
175  }
176  }
177 
180  if (escape)
181  continue;
182 
183  if (prevTPAddress == nullptr) {
185  continue;
186  } else {
191  edm::Ptr<TrackingParticle> testTP = trackingParticles1.at(whichTP);
192 
195  stubToTrackingParticleMap.insert(std::make_pair(tempStubRef, testTP));
196 
198  continue;
199  }
200  }
201  }
202  }
203  }
204  }
205 
208  typename std::map<edm::Ptr<TrackingParticle>,
209  std::vector<edm::Ref<edmNew::DetSetVector<TTStub<Ref_Phase2TrackerDigi_>>,
210  TTStub<Ref_Phase2TrackerDigi_>>>>::iterator iterMapToClean;
211  for (iterMapToClean = trackingParticleToStubVectorMap.begin();
212  iterMapToClean != trackingParticleToStubVectorMap.end();
213  ++iterMapToClean) {
215  std::vector<edm::Ref<edmNew::DetSetVector<TTStub<Ref_Phase2TrackerDigi_>>, TTStub<Ref_Phase2TrackerDigi_>>>
216  tempVector = iterMapToClean->second;
217 
219  std::sort(tempVector.begin(), tempVector.end());
220  tempVector.erase(std::unique(tempVector.begin(), tempVector.end()), tempVector.end());
221 
223  iterMapToClean->second = tempVector;
224  }
225 
227  edm::RefProd<TTClusterAssociationMap<Ref_Phase2TrackerDigi_>> theCluAssoMap(TTClusterAssociationMapHandle);
228 
230  associationMapForOutput->setTTStubToTrackingParticleMap(stubToTrackingParticleMap);
231  associationMapForOutput->setTrackingParticleToTTStubsMap(trackingParticleToStubVectorMap);
232  associationMapForOutput->setTTClusterAssociationMap(theCluAssoMap);
233 
235  iEvent.put(std::move(associationMapForOutput), TTStubsInputTags.at(ncont1).instance());
236 
237  ++ncont1;
238  }
239 }

References edmNew::DetSet< T >::begin(), TrackerGeometry::dets(), edmNew::DetSet< T >::end(), get, mps_fire::i, iEvent, TrackerTopology::isLower(), edm::Ptr< T >::isNull(), dqmdumpme::k, edmNew::makeRefTo(), eostools::move(), TrackerTopology::stack(), DetId::subdetId(), StripSubdetector::TID, StripSubdetector::TOB, tier0::unique(), and trackerHitRTTI::vector.

◆ produce() [2/3]

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

Implement the producer.

◆ produce() [3/3]

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

Member Data Documentation

◆ theTrackerGeometry

template<typename T >
edm::ESHandle<TrackerGeometry> TTStubAssociator< T >::theTrackerGeometry
private

Definition at line 62 of file TTStubAssociator.h.

◆ theTrackerTopology

template<typename T >
edm::ESHandle<TrackerTopology> TTStubAssociator< T >::theTrackerTopology
private

Definition at line 63 of file TTStubAssociator.h.

◆ TTClusterTruthInputTags

template<typename T >
std::vector<edm::InputTag> TTStubAssociator< T >::TTClusterTruthInputTags
private

Definition at line 57 of file TTStubAssociator.h.

◆ TTClusterTruthTokens

template<typename T >
std::vector<edm::EDGetTokenT<TTClusterAssociationMap<T> > > TTStubAssociator< T >::TTClusterTruthTokens
private

Definition at line 60 of file TTStubAssociator.h.

◆ TTStubsInputTags

template<typename T >
std::vector<edm::InputTag> TTStubAssociator< T >::TTStubsInputTags
private

Data members.

Definition at line 56 of file TTStubAssociator.h.

◆ TTStubsTokens

template<typename T >
std::vector<edm::EDGetTokenT<edmNew::DetSetVector<TTStub<T> > > > TTStubAssociator< T >::TTStubsTokens
private

Definition at line 59 of file TTStubAssociator.h.

edm::RefProd
Definition: EDProductfwd.h:25
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
TTStubAssociator::TTStubsTokens
std::vector< edm::EDGetTokenT< edmNew::DetSetVector< TTStub< T > > > > TTStubsTokens
Definition: TTStubAssociator.h:59
mps_fire.i
i
Definition: mps_fire.py:428
TTClusterAssociationMap
NOTE: this is needed even if it seems not.
Definition: TTClusterAssociationMap.h:33
TrackerTopology::isLower
bool isLower(const DetId &id) const
Definition: TrackerTopology.cc:195
TTStubAssociator::TTClusterTruthInputTags
std::vector< edm::InputTag > TTClusterTruthInputTags
Definition: TTStubAssociator.h:57
TrackerTopology
Definition: TrackerTopology.h:16
edmNew::makeRefTo
edm::Ref< typename HandleT::element_type, typename HandleT::element_type::value_type::value_type > makeRefTo(const HandleT &iHandle, typename HandleT::element_type::value_type::const_iterator itIter)
Definition: DetSetVectorNew.h:689
TrackerTopology::stack
uint32_t stack(const DetId &id) const
Definition: TrackerTopology.cc:104
TTStubAssociator::TTStubsInputTags
std::vector< edm::InputTag > TTStubsInputTags
Data members.
Definition: TTStubAssociator.h:56
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
edm::Handle
Definition: AssociativeIterator.h:50
edm::Ref
Definition: AssociativeIterator.h:58
DetId
Definition: DetId.h:17
edmNew::DetSet::end
iterator end()
Definition: DetSetNew.h:56
edm::EventSetup::get
T get() const
Definition: EventSetup.h:80
TrackerDigiGeometryRecord
Definition: TrackerDigiGeometryRecord.h:15
TrackingParticle
Monte Carlo truth information used for tracking validation.
Definition: TrackingParticle.h:29
TTStub
Class to store the L1 Track Trigger stubs.
Definition: TTStub.h:22
edmNew::DetSet
Definition: DetSetNew.h:22
dqmdumpme.k
k
Definition: dqmdumpme.py:60
DetId::subdetId
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum)
Definition: DetId.h:48
TTStubAssociator::theTrackerTopology
edm::ESHandle< TrackerTopology > theTrackerTopology
Definition: TTStubAssociator.h:63
iEvent
int iEvent
Definition: GenABIO.cc:224
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
edmNew::DetSet::begin
iterator begin()
Definition: DetSetNew.h:54
TrackerGeometry::dets
const DetContainer & dets() const override
Returm a vector of all GeomDet (including all GeomDetUnits)
Definition: TrackerGeometry.h:62
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
get
#define get
edm::Ptr< TrackingParticle >
edmNew::DetSetVector
Definition: DetSetNew.h:13
TTStubAssociator::TTClusterTruthTokens
std::vector< edm::EDGetTokenT< TTClusterAssociationMap< T > > > TTClusterTruthTokens
Definition: TTStubAssociator.h:60
eostools.move
def move(src, dest)
Definition: eostools.py:511
tier0.unique
def unique(seq, keepstr=True)
Definition: tier0.py:24
StripSubdetector::TOB
static constexpr auto TOB
Definition: StripSubdetector.h:18
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
TrackerTopologyRcd
Definition: TrackerTopologyRcd.h:10
TTStubAssociator::theTrackerGeometry
edm::ESHandle< TrackerGeometry > theTrackerGeometry
Definition: TTStubAssociator.h:62
edm::Ptr::isNull
bool isNull() const
Checks for null.
Definition: Ptr.h:142
StripSubdetector::TID
static constexpr auto TID
Definition: StripSubdetector.h:17
TrackerGeometry
Definition: TrackerGeometry.h:14