CMS 3D CMS Logo

InputData.cc
Go to the documentation of this file.
11 
17 
18 #include <map>
19 #include <memory>
20 
21 using namespace std;
22 
23 namespace tmtt {
24 
25  InputData::InputData(const edm::Event& iEvent,
26  const edm::EventSetup& iSetup,
27  const Settings* settings,
28  StubWindowSuggest* stubWindowSuggest,
29  const DegradeBend* degradeBend,
30  const TrackerGeometry* trackerGeometry,
31  const TrackerTopology* trackerTopology,
32  const list<TrackerModule>& listTrackerModule,
34  const edm::EDGetTokenT<TTStubDetSetVec> stubToken,
35  const edm::EDGetTokenT<TTStubAssMap> stubTruthToken,
36  const edm::EDGetTokenT<TTClusterAssMap> clusterTruthToken,
38  : // Note if job will use MC truth info (or skip it to save CPU).
39  enableMCtruth_(settings->enableMCtruth()) {
41  edm::Handle<TTStubDetSetVec> ttStubHandle;
42  edm::Handle<TTStubAssMap> mcTruthTTStubHandle;
43  edm::Handle<TTClusterAssMap> mcTruthTTClusterHandle;
45  iEvent.getByToken(stubToken, ttStubHandle);
46  if (enableMCtruth_) {
47  iEvent.getByToken(tpToken, tpHandle);
48  iEvent.getByToken(stubTruthToken, mcTruthTTStubHandle);
49  iEvent.getByToken(clusterTruthToken, mcTruthTTClusterHandle);
50  iEvent.getByToken(genJetToken, genJetHandle);
51  }
52 
53  // Get TrackingParticle info
54 
55  if (enableMCtruth_) {
56  unsigned int tpCount = 0;
57  for (unsigned int i = 0; i < tpHandle->size(); i++) {
58  const TrackingParticle& tPart = tpHandle->at(i);
59  // Creating Ptr uses CPU, so apply Pt cut here, copied from TP::fillUse(), to avoid doing it too often.
60  constexpr float ptMinScale = 0.7;
61  const float ptMin = min(settings->genMinPt(), ptMinScale * settings->houghMinPt());
62  if (tPart.pt() > ptMin) {
63  TrackingParticlePtr tpPtr(tpHandle, i);
64  // Store the TrackingParticle info, using class TP to provide easy access to the most useful info.
65  TP tp(tpPtr, tpCount, settings);
66  // Only bother storing tp if it could be useful for tracking efficiency or fake rate measurements.
67  if (tp.use()) {
68  if (genJetHandle.isValid()) {
69  tp.fillNearestJetInfo(genJetHandle.product());
70  }
71 
72  vTPs_.push_back(tp);
73  tpCount++;
74  }
75  }
76  }
77  }
78 
79  // Also create map relating edm::Ptr<TrackingParticle> to TP.
80 
81  map<edm::Ptr<TrackingParticle>, const TP*> translateTP;
82 
83  if (enableMCtruth_) {
84  for (const TP& tp : vTPs_) {
85  const TrackingParticlePtr& tpPtr = tp.trackingParticlePtr();
86  translateTP[tpPtr] = &tp;
87  }
88  }
89 
90  // Initialize code for killing some stubs to model detector problems.
91  const StubKiller::KillOptions killOpt = static_cast<StubKiller::KillOptions>(settings->killScenario());
92  std::unique_ptr<const StubKiller> stubKiller;
93  if (killOpt != StubKiller::KillOptions::none) {
94  stubKiller = std::make_unique<StubKiller>(killOpt, trackerTopology, trackerGeometry, iEvent);
95  }
96 
97  // Loop over tracker modules to get module info & stubs.
98 
99  for (const TrackerModule& trackerModule : listTrackerModule) {
100  const DetId& stackedDetId = trackerModule.stackedDetId();
101  TTStubDetSetVec::const_iterator p_module = ttStubHandle->find(stackedDetId);
102  if (p_module != ttStubHandle->end()) {
103  for (TTStubDetSet::const_iterator p_ttstub = p_module->begin(); p_ttstub != p_module->end(); p_ttstub++) {
104  TTStubRef ttStubRef = edmNew::makeRefTo(ttStubHandle, p_ttstub);
105  const unsigned int stubIndex = vAllStubs_.size();
106 
107  // Store the Stub info, using class Stub to provide easy access to the most useful info.
108  vAllStubs_.emplace_back(
109  ttStubRef, stubIndex, settings, trackerTopology, &trackerModule, degradeBend, stubKiller.get());
110 
111  // Also fill truth associating stubs to tracking particles.
112  if (enableMCtruth_) {
113  Stub& stub = vAllStubs_.back();
114  stub.fillTruth(translateTP, mcTruthTTStubHandle, mcTruthTTClusterHandle);
115  }
116  }
117  }
118  }
119 
120  // Produced reduced list containing only the subset of stubs that the user has declared will be
121  // output by the front-end readout electronics.
122  for (Stub& s : vAllStubs_) {
123  if (s.frontendPass()) {
124  vStubs_.push_back(&s);
125  vStubsConst_.push_back(&s);
126  }
127  }
128  // Optionally sort stubs according to bend, so highest Pt ones are sent from DTC to GP first.
129  if (settings->orderStubsByBend()) {
130  auto orderStubsByBend = [](const Stub* a, const Stub* b) { return (std::abs(a->bend()) < std::abs(b->bend())); };
131  vStubs_.sort(orderStubsByBend);
132  }
133 
134  // Note list of stubs produced by each tracking particle.
135  // (By passing vAllStubs_ here instead of vStubs_, it means that any algorithmic efficiencies
136  // measured will be reduced if the tightened frontend electronics cuts, specified in section StubCuts
137  // of Analyze_Defaults_cfi.py, are not 100% efficient).
138  if (enableMCtruth_) {
139  for (TP& tp : vTPs_) {
140  tp.fillTruth(vAllStubs_);
141  }
142  }
143 
144  // If requested, recommend better FE stub window cuts.
145  if (settings->printStubWindows()) {
146  for (const Stub& s : vAllStubs_) {
147  stubWindowSuggest->process(trackerTopology, &s);
148  }
149  }
150  }
151 
152 } // namespace tmtt
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)
T const * product() const
Definition: Handle.h:70
constexpr float ptMin
data_type const * const_iterator
Definition: DetSetNew.h:31
const_iterator end(bool update=false) const
int iEvent
Definition: GenABIO.cc:224
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
Definition: DetId.h:17
=== This is the base class for the linearised chi-squared track fit algorithms.
Definition: Array2D.h:16
double b
Definition: hdecay.h:118
bool isValid() const
Definition: HandleBase.h:70
const_iterator find(id_type i, bool update=false) const
double a
Definition: hdecay.h:119
Monte Carlo truth information used for tracking validation.
double pt() const
Transverse momentum. Note this is taken from the first SimTrack only.