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
 
 EDProducer (const EDProducer &)=delete
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
const EDProduceroperator= (const EDProducer &)=delete
 

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)
 
void produce (edm::Event &iEvent, const edm::EventSetup &iSetup) override
 
template<>
void produce (edm::Event &iEvent, const edm::EventSetup &iSetup)
 Implement the producer. More...
 

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<>
using CacheTypes = CacheContexts< T... >
 
using GlobalCache = typename CacheTypes::GlobalCache
 
using HasAbility = AbilityChecker< T... >
 
using InputProcessBlockCache = typename CacheTypes::InputProcessBlockCache
 
using LuminosityBlockCache = typename CacheTypes::LuminosityBlockCache
 
using LuminosityBlockContext = LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCache >
 
using LuminosityBlockSummaryCache = typename CacheTypes::LuminosityBlockSummaryCache
 
using RunCache = typename CacheTypes::RunCache
 
using RunContext = RunContextT< RunCache, GlobalCache >
 
using RunSummaryCache = typename CacheTypes::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 (tidy up: Ian Tomalin, 2020)

Definition at line 41 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.

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

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 (const auto& iTag : ttTracksInputTags_) {
89  ttTracksTokens_.push_back(consumes<std::vector<TTTrack<T> > >(iTag));
90 
91  produces<TTTrackAssociationMap<T> >(iTag.instance());
92  }
93 }
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::vector< edm::EDGetTokenT< std::vector< TTTrack< T > > > > ttTracksTokens_
std::vector< edm::InputTag > ttTracksInputTags_
Data members.
Log< level::Info, false > LogInfo
Class to store the L1 Track Trigger tracks.
Definition: TTTrack.h:29
edm::EDGetTokenT< TTStubAssociationMap< T > > ttStubTruthToken_
edm::EDGetTokenT< TTClusterAssociationMap< T > > ttClusterTruthToken_

◆ ~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 }
Log< level::Info, false > LogInfo

◆ 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 19Implement 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

Make the pointer to be put in the map

Get all the stubs of the TTTrack (theseStubs)

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

Fill the map associating each TP to a vector of L1 tracks. Do this using the association map of the clusters inside each stub, as stub associator misses stub –> all TP map (FIX).






















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 are >= 2 unknown stubs, go to the next track as this track may be COMBINATORIC or UNKNOWN (One unknown is allowed, if in 2S module).















If we are here, all the stubs on track 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 (stored in auxMap), to check if any are present in all stubs on Track.














Get all associated stubs of this TrackingParticle

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 this TP does not appear in all stubs (allowing one wrong stub) then try next TP.











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










Count how many TrackingParticles were associated to all stubs on this track. FIX: Could avoid this by using std::set for tpInAllStubs?









If only one TP associated to all stubs (allowing one incorrect) on track: GENUINE or LOOSELY_GENUINE. If 0 or >= 2 TP: COMBINATORIC WARNING: This means if one TP matches all stubs, and another matches all STUBS except one, then the trackToTrackingParticleMap will not be filled. WARNING: This also means that trackToTrackingParticleMap will be filled if one TP matches all stubs, except for an incorrect one in either PS or 2S modules.








Here, the track may only be GENUINE/LOOSELY_GENUINE CHECK: Surely if one incorrect PS stub, it can also be COMBINATORIC? Fill the map associating track to its principle TP.







End of loop over Tracks

Remove duplicates from the only output map that needs it. (Map gets multiple entries per track if it has several stubs belonging to same TP).





Get the vector of edm::Ptr< TTTrack > (CHECK: Couldn't this be done by reference, to save CPU?)




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.

References spr::find(), iEvent, eostools::move(), AlCaHLTBitMon_ParallelJobs::p, edm::second(), jetUpdater_cfi::sort, TTTrackAssociation_cfi::TTTrackAllowOneFalse2SStub, and tier0::unique().

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 (const auto& iTag : ttTracksTokens_) {
30  auto associationMapForOutput = std::make_unique<TTTrackAssociationMap<Ref_Phase2TrackerDigi_>>();
31 
34  iEvent.getByToken(iTag, TTTrackHandle);
35 
37  std::map<TTTrackPtr, TrackingParticlePtr> trackToTrackingParticleMap;
38  std::map<TrackingParticlePtr, std::vector<TTTrackPtr>> trackingParticleToTrackVectorMap;
39 
40  // Start the loop on tracks
41 
42  for (unsigned int jTrk = 0; jTrk < TTTrackHandle->size(); jTrk++) {
44  TTTrackPtr tempTrackPtr(TTTrackHandle, jTrk);
45 
47  const std::vector<TTStubRef>& theseStubs = tempTrackPtr->getStubRefs();
48 
50  std::map<const TrackingParticle*, TrackingParticlePtr> auxMap;
51  int mayCombinUnknown = 0;
52 
56  for (const TTStubRef& stub : theseStubs) {
57  for (unsigned int ic = 0; ic < 2; ic++) {
58  const std::vector<TrackingParticlePtr>& tempTPs =
59  ttClusterAssociationMapHandle->findTrackingParticlePtrs(stub->clusterRef(ic));
60  for (const TrackingParticlePtr& testTP : tempTPs) // List of TPs linked to stub clusters
61  {
62  if (testTP.isNull()) // No TP linked to this cluster
63  continue;
64 
66  if (trackingParticleToTrackVectorMap.find(testTP) == trackingParticleToTrackVectorMap.end()) {
67  std::vector<TTTrackPtr> trackVector;
68  trackingParticleToTrackVectorMap.emplace(testTP, trackVector);
69  }
70  trackingParticleToTrackVectorMap.find(testTP)->second.push_back(tempTrackPtr);
71 
73  if (auxMap.find(testTP.get()) == auxMap.end()) {
74  auxMap.emplace(testTP.get(), testTP);
75  }
76  }
77  }
78 
80  if (ttStubAssociationMapHandle->isUnknown(stub))
81  ++mayCombinUnknown;
82 
83  }
84 
88  if (mayCombinUnknown >= 2)
89  continue;
90 
95 
96  std::vector<const TrackingParticle*> tpInAllStubs;
97 
98  for (const auto& auxPair : auxMap) {
100  const std::vector<TTStubRef>& tempStubs = ttStubAssociationMapHandle->findTTStubRefs(auxPair.second);
101 
102  // Count stubs on track that are not related to this TP
103  int nnotfound = 0;
104  for (const TTStubRef& stub : theseStubs) {
109  if (std::find(tempStubs.begin(), tempStubs.end(), stub) == tempStubs.end()) {
110  ++nnotfound;
111  }
112  }
113 
116  if (nnotfound > 1)
117  continue;
118 
122  tpInAllStubs.push_back(auxPair.first);
123  }
124 
127  std::sort(tpInAllStubs.begin(), tpInAllStubs.end());
128  tpInAllStubs.erase(std::unique(tpInAllStubs.begin(), tpInAllStubs.end()), tpInAllStubs.end());
129  unsigned int nTPs = tpInAllStubs.size();
130 
137  if (nTPs != 1)
138  continue;
139 
143  trackToTrackingParticleMap.emplace(tempTrackPtr, auxMap.find(tpInAllStubs.at(0))->second);
144 
145  }
146 
149  for (auto& p : trackingParticleToTrackVectorMap) {
152  std::vector<TTTrackPtr>& tempVector = p.second;
153 
155  std::sort(tempVector.begin(), tempVector.end());
156  tempVector.erase(std::unique(tempVector.begin(), tempVector.end()), tempVector.end());
157  }
158 
160  edm::RefProd<TTStubAssociationMap<Ref_Phase2TrackerDigi_>> theStubAssoMap(ttStubAssociationMapHandle);
161 
163  associationMapForOutput->setTTTrackToTrackingParticleMap(trackToTrackingParticleMap);
164  associationMapForOutput->setTrackingParticleToTTTracksMap(trackingParticleToTrackVectorMap);
165  associationMapForOutput->setTTStubAssociationMap(theStubAssoMap);
166  associationMapForOutput->setAllowOneFalse2SStub(TTTrackAllowOneFalse2SStub);
167 
169  iEvent.put(std::move(associationMapForOutput), ttTracksInputTags_.at(ncont1).instance());
170 
171  ++ncont1;
172  }
173 }
std::vector< edm::EDGetTokenT< std::vector< TTTrack< T > > > > ttTracksTokens_
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
U second(std::pair< T, U > const &p)
std::vector< edm::InputTag > ttTracksInputTags_
Data members.
int iEvent
Definition: GenABIO.cc:224
def unique(seq, keepstr=True)
Definition: tier0.py:24
edm::EDGetTokenT< TTStubAssociationMap< T > > ttStubTruthToken_
edm::EDGetTokenT< TTClusterAssociationMap< T > > ttClusterTruthToken_
def move(src, dest)
Definition: eostools.py:511

◆ produce() [2/3]

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

◆ produce() [3/3]

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

Implement the producer.

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 53 of file TTTrackAssociator.h.

◆ ttTracksTokens_

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

Definition at line 55 of file TTTrackAssociator.h.