CMS 3D CMS Logo

TrackFinder.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <sstream>
3 #include <string>
4 
10 
23 
25 
26 using namespace emtf::phase2;
27 
28 TrackFinder::TrackFinder(const edm::ParameterSet& i_config, edm::ConsumesCollector&& i_consumes_collector)
29  : context_(i_config, i_consumes_collector), tp_collectors_(), sector_processors_() {
30  // ===========================================================================
31  // Emulation Setup
32  // ===========================================================================
33 
34  // Register Trigger Primitives
35  if (this->context_.config_.csc_en_) {
36  tp_collectors_.push_back(std::make_unique<CSCTPCollector>(context_, i_consumes_collector));
37  }
38 
39  if (this->context_.config_.rpc_en_) {
40  tp_collectors_.push_back(std::make_unique<RPCTPCollector>(context_, i_consumes_collector));
41  }
42 
43  if (this->context_.config_.gem_en_) {
44  tp_collectors_.push_back(std::make_unique<GEMTPCollector>(context_, i_consumes_collector));
45  }
46 
47  if (this->context_.config_.me0_en_) {
48  tp_collectors_.push_back(std::make_unique<ME0TPCollector>(context_, i_consumes_collector));
49  }
50 
51  if (this->context_.config_.ge0_en_) {
52  tp_collectors_.push_back(std::make_unique<GE0TPCollector>(context_, i_consumes_collector));
53  }
54 
55  // Register Sector Processor
56  for (unsigned int endcap = kMinEndcap; endcap <= kMaxEndcap; ++endcap) {
57  for (unsigned int sector = kMinTrigSector; sector <= kMaxTrigSector; ++sector) {
58  sector_processors_.push_back(std::make_unique<SectorProcessor>(context_, endcap, sector));
59  }
60  }
61 }
62 
64  // Do Nothing
65 }
66 
68  // Input
69  const edm::Event& i_event,
70  const edm::EventSetup& i_event_setup,
71  // Output
72  EMTFHitCollection& out_hits,
73  EMTFTrackCollection& out_tracks,
74  EMTFInputCollection& out_inputs) {
75  // ===========================================================================
76  // Clear output collections
77  // ===========================================================================
78 
79  out_hits.clear();
80  out_tracks.clear();
81  out_inputs.clear();
82 
83  // ===========================================================================
84  // Load the event configuration
85  // ===========================================================================
86 
87  context_.update(i_event, i_event_setup);
88 
89  // ===========================================================================
90  // Collect trigger primitives
91  // ===========================================================================
92 
93  // Build BX Sequence
94  std::vector<int> bx_sequence;
95 
96  {
97  auto min_bx = this->context_.config_.min_bx_;
98  auto delay_bx = this->context_.config_.bx_window_ - 1;
99  auto max_bx = this->context_.config_.max_bx_ + delay_bx;
100 
101  for (int bx = min_bx; bx <= max_bx; ++bx) {
102  bx_sequence.push_back(bx);
103  }
104  }
105 
106  // Collect TP per BX
107  BXTPCMap bx_tpc_map;
108 
109  for (auto& tp_collector : tp_collectors_) {
110  tp_collector->collect(i_event, bx_tpc_map);
111  }
112 
113  // Debug Info
114  if (this->context_.config_.verbosity_ > 4) {
115  int n_tp = 0;
116 
117  // Loop BX
118  for (const auto& bx : bx_sequence) {
119  // Get trigger primitives for this BX
120  auto bx_tpc_map_it = bx_tpc_map.find(bx);
121  auto bx_tpc_map_end = bx_tpc_map.end();
122 
123  // Short-Circuit: Empty trigger primitive collection
124  if (bx_tpc_map_it == bx_tpc_map_end) {
125  continue;
126  }
127 
128  // Reference TPC
129  auto& bx_tpc = bx_tpc_map_it->second;
130 
131  // Short-Circuit: Empty trigger primitive collection
132  if (bx_tpc.empty()) {
133  continue;
134  }
135 
136  // Print trigger primitives
137  edm::LogInfo("L1TEMTFpp") << "==========================================================================="
138  << std::endl;
139  edm::LogInfo("L1TEMTFpp") << "Begin TPC BX " << bx << " Dump" << std::endl;
140  edm::LogInfo("L1TEMTFpp") << "---------------------------------------------------------------------------"
141  << std::endl;
142 
143  n_tp += bx_tpc.size();
144 
145  for (const auto& tp_entry : bx_tpc) {
146  tp_entry.tp_.print(std::cout);
147 
148  edm::LogInfo("L1TEMTFpp") << "---------------------------------------------------------------------------"
149  << std::endl;
150  }
151 
152  edm::LogInfo("L1TEMTFpp") << "End TPC BX " << bx << " Dump" << std::endl;
153  edm::LogInfo("L1TEMTFpp") << "==========================================================================="
154  << std::endl;
155  }
156 
157  // Print TPrimitives Summary
158  if (n_tp > 0) {
159  edm::LogInfo("L1TEMTFpp") << "Num of TriggerPrimitive: " << n_tp << std::endl;
160  edm::LogInfo("L1TEMTFpp") << "==========================================================================="
161  << std::endl;
162  }
163  }
164 
165  // ===========================================================================
166  // Run sector processors
167  // ===========================================================================
168 
169  // Before event
170  for (auto& sector_processor : sector_processors_) {
171  sector_processor->configureEvent(i_event);
172  }
173 
174  // Orderly loop BX
175  for (const auto& bx : bx_sequence) {
176  // Get trigger primitives for this BX
177  auto bx_tpc_map_it = bx_tpc_map.find(bx);
178  auto bx_tpc_map_end = bx_tpc_map.end();
179 
180  TPCollection* bx_tpc_ptr = nullptr;
181 
182  if (bx_tpc_map_it != bx_tpc_map_end) {
183  bx_tpc_ptr = &(bx_tpc_map_it->second);
184  }
185 
186  // Loop over all sector processors
187  for (auto& sector_processor : sector_processors_) {
188  // Before BX
189  sector_processor->configureBx(bx);
190 
191  // Select trigger primitives in BX
192  if (bx_tpc_ptr != nullptr) {
193  for (const auto& tp_entry : *bx_tpc_ptr) {
194  const auto& tp = tp_entry.tp_;
195  const auto& tp_info = tp_entry.info_;
196 
197  sector_processor->select(tp, tp_info);
198  }
199  }
200 
201  // Process trigger primitives
202  sector_processor->process(out_hits, out_tracks, out_inputs);
203  }
204 
205  // Free memory: Removes BX TPCollections after all Sector Processors have selected their TPrimitives
206  if (bx_tpc_ptr != nullptr) {
207  bx_tpc_map.erase(bx_tpc_map_it);
208  }
209  }
210 
211  // Free memory: Drops any BX TPCollections outside of the [min bx, max bx] range
212  bx_tpc_map.clear();
213 }
214 
216  // Do Nothing
217 }
218 
220  // Do Nothing
221 }
void process(const edm::Event &, const edm::EventSetup &, EMTFHitCollection &, EMTFTrackCollection &, EMTFInputCollection &)
Definition: TrackFinder.cc:67
void update(const edm::Event &, const edm::EventSetup &)
Definition: EMTFContext.cc:69
std::vector< std::unique_ptr< TPCollector > > tp_collectors_
Definition: TrackFinder.h:32
l1t::phase2::EMTFTrackCollection EMTFTrackCollection
Definition: EMTFTypes.h:31
l1t::phase2::EMTFInputCollection EMTFInputCollection
Definition: EMTFTypes.h:35
constexpr int kMaxEndcap
Definition: EMTFConstants.h:7
std::vector< std::unique_ptr< SectorProcessor > > sector_processors_
Definition: TrackFinder.h:33
std::map< int, TPCollection > BXTPCMap
Definition: EMTFTypes.h:22
l1t::phase2::EMTFHitCollection EMTFHitCollection
Definition: EMTFTypes.h:27
Log< level::Info, false > LogInfo
TrackFinder(const edm::ParameterSet &, edm::ConsumesCollector &&)
Definition: TrackFinder.cc:28
constexpr int kMinTrigSector
Definition: EMTFConstants.h:20
constexpr int kMinEndcap
Definition: EMTFConstants.h:6
constexpr int kMaxTrigSector
Definition: EMTFConstants.h:21
std::vector< TPEntry > TPCollection
Definition: EMTFTypes.h:21
EMTFConfiguration config_
Definition: EMTFContext.h:39