CMS 3D CMS Logo

TrackFinder.cc
Go to the documentation of this file.
4 
5 #include <iostream>
6 #include <sstream>
7 
9 
10 
12  geometry_translator_(),
13  condition_helper_(),
14  sector_processor_lut_(),
15  pt_assign_engine_(),
16  sector_processors_(),
17  config_(iConfig),
18  tokenCSC_(iConsumes.consumes<CSCTag::digi_collection>(iConfig.getParameter<edm::InputTag>("CSCInput"))),
19  tokenRPC_(iConsumes.consumes<RPCTag::digi_collection>(iConfig.getParameter<edm::InputTag>("RPCInput"))),
20  tokenGEM_(iConsumes.consumes<GEMTag::digi_collection>(iConfig.getParameter<edm::InputTag>("GEMInput"))),
21  verbose_(iConfig.getUntrackedParameter<int>("verbosity")),
22  useCSC_(iConfig.getParameter<bool>("CSCEnable")),
23  useRPC_(iConfig.getParameter<bool>("RPCEnable")),
24  useGEM_(iConfig.getParameter<bool>("GEMEnable"))
25 {
26 
27  auto minBX = iConfig.getParameter<int>("MinBX");
28  auto maxBX = iConfig.getParameter<int>("MaxBX");
29  auto bxWindow = iConfig.getParameter<int>("BXWindow");
30  auto bxShiftCSC = iConfig.getParameter<int>("CSCInputBXShift");
31  auto bxShiftRPC = iConfig.getParameter<int>("RPCInputBXShift");
32  auto bxShiftGEM = iConfig.getParameter<int>("GEMInputBXShift");
33 
34  const auto& spPCParams16 = config_.getParameter<edm::ParameterSet>("spPCParams16");
35  auto zoneBoundaries = spPCParams16.getParameter<std::vector<int> >("ZoneBoundaries");
36  auto zoneOverlap = spPCParams16.getParameter<int>("ZoneOverlap");
37  auto includeNeighbor = spPCParams16.getParameter<bool>("IncludeNeighbor");
38  auto duplicateTheta = spPCParams16.getParameter<bool>("DuplicateTheta");
39  auto fixZonePhi = spPCParams16.getParameter<bool>("FixZonePhi");
40  auto useNewZones = spPCParams16.getParameter<bool>("UseNewZones");
41  auto fixME11Edges = spPCParams16.getParameter<bool>("FixME11Edges");
42 
43  const auto& spPRParams16 = config_.getParameter<edm::ParameterSet>("spPRParams16");
44  auto pattDefinitions = spPRParams16.getParameter<std::vector<std::string> >("PatternDefinitions");
45  auto symPattDefinitions = spPRParams16.getParameter<std::vector<std::string> >("SymPatternDefinitions");
46  auto useSymPatterns = spPRParams16.getParameter<bool>("UseSymmetricalPatterns");
47 
48  const auto& spTBParams16 = config_.getParameter<edm::ParameterSet>("spTBParams16");
49  auto thetaWindow = spTBParams16.getParameter<int>("ThetaWindow");
50  auto thetaWindowRPC = spTBParams16.getParameter<int>("ThetaWindowRPC");
51  auto useSingleHits = spTBParams16.getParameter<bool>("UseSingleHits");
52  auto bugSt2PhDiff = spTBParams16.getParameter<bool>("BugSt2PhDiff");
53  auto bugME11Dupes = spTBParams16.getParameter<bool>("BugME11Dupes");
54 
55  const auto& spGCParams16 = config_.getParameter<edm::ParameterSet>("spGCParams16");
56  auto maxRoadsPerZone = spGCParams16.getParameter<int>("MaxRoadsPerZone");
57  auto maxTracks = spGCParams16.getParameter<int>("MaxTracks");
58  auto useSecondEarliest = spGCParams16.getParameter<bool>("UseSecondEarliest");
59  auto bugSameSectorPt0 = spGCParams16.getParameter<bool>("BugSameSectorPt0");
60 
61  const auto& spPAParams16 = config_.getParameter<edm::ParameterSet>("spPAParams16");
62  auto ptLUTVersion = spPAParams16.getParameter<int>("PtLUTVersion");
63  auto readPtLUTFile = spPAParams16.getParameter<bool>("ReadPtLUTFile");
64  auto fixMode15HighPt = spPAParams16.getParameter<bool>("FixMode15HighPt");
65  auto bug9BitDPhi = spPAParams16.getParameter<bool>("Bug9BitDPhi");
66  auto bugMode7CLCT = spPAParams16.getParameter<bool>("BugMode7CLCT");
67  auto bugNegPt = spPAParams16.getParameter<bool>("BugNegPt");
68  auto bugGMTPhi = spPAParams16.getParameter<bool>("BugGMTPhi");
69  auto promoteMode7 = spPAParams16.getParameter<bool>("PromoteMode7");
70 
73 
74  fw_version_ = 999999;
75  pt_lut_version_ = 888888;
76  pc_lut_version_ = 777777;
77 
78  // Configure sector processors
80  for (int sector = emtf::MIN_TRIGSECTOR; sector <= emtf::MAX_TRIGSECTOR; ++sector) {
82 
83  sector_processors_.at(es).configure(
88  verbose_, endcap, sector,
89  minBX, maxBX, bxWindow, bxShiftCSC, bxShiftRPC, bxShiftGEM,
90  zoneBoundaries, zoneOverlap,
91  includeNeighbor, duplicateTheta, fixZonePhi, useNewZones, fixME11Edges,
92  pattDefinitions, symPattDefinitions, useSymPatterns,
93  thetaWindow, thetaWindowRPC, useSingleHits, bugSt2PhDiff, bugME11Dupes,
94  maxRoadsPerZone, maxTracks, useSecondEarliest, bugSameSectorPt0,
95  ptLUTVersion, readPtLUTFile, fixMode15HighPt, bug9BitDPhi, bugMode7CLCT, bugNegPt, bugGMTPhi, promoteMode7
96  );
97  }
98  }
99 
100 } // End constructor: TrackFinder::TrackFinder()
101 
103 
104 }
105 
107  const edm::Event& iEvent, const edm::EventSetup& iSetup,
108  EMTFHitCollection& out_hits,
109  EMTFTrackCollection& out_tracks
110 ) {
111 
112  // Clear output collections
113  out_hits.clear();
114  out_tracks.clear();
115 
116  // Get the geometry for TP conversions
118 
119  // ___________________________________________________________________________
120  // Get the conditions: firmware version, PC LUT version, pT BDT forests
121  bool new_conditions = condition_helper_.checkAndUpdateConditions(iEvent, iSetup);
122  // std::cout << "\nDo we have new conditions? Yes (1) or no (0)? -- " << new_conditions << std::endl;
123  // std::cout << " * Before updating conditions, fw_version_ = " << fw_version_ << ", pt_lut_version_ = " << pt_lut_version_ << ", pc_lut_version_ = " << pc_lut_version_ << std::endl;
124 
125  if (new_conditions) {
126 
128  // No RPC or GEM hits in 2016
129  if (fw_version_ != 0 && fw_version_ < 50000) {
130  useRPC_ = false;
131  useGEM_ = false;
132  }
133 
136 
137  // Reload primitive conversion LUTs if necessary
138  // std::cout << "Configured with pc_lut_version_ = " << pc_lut_version_ << std::endl;
140 
141  // std::cout << "Configured with pt_lut_version_ = " << pt_lut_version_ << std::endl;
142  if ( pt_lut_version_ <= 5 ) {
145  } else {
148  }
149  // Reload pT LUT if necessary
151  }
152 
153  // std::cout << " * After changes, fw_version_ = " << fw_version_ << ", pt_lut_version_ = " << pt_lut_version_ << ", pc_lut_version_ = " << pc_lut_version_ << std::endl;
154 
155  // ___________________________________________________________________________
156  // Extract all trigger primitives
157 
158  TriggerPrimitiveCollection muon_primitives;
159 
160  EMTFSubsystemCollector collector;
161  if (useCSC_)
162  collector.extractPrimitives(CSCTag(), iEvent, tokenCSC_, muon_primitives);
163  if (useRPC_)
164  collector.extractPrimitives(RPCTag(), iEvent, tokenRPC_, muon_primitives);
165  if (useGEM_)
166  collector.extractPrimitives(GEMTag(), iEvent, tokenGEM_, muon_primitives);
167 
168  // Check trigger primitives
169  if (verbose_ > 2) { // debug
170  std::cout << "Num of TriggerPrimitive: " << muon_primitives.size() << std::endl;
171  for (const auto& p : muon_primitives) {
172  p.print(std::cout);
173  }
174  }
175 
176  // ___________________________________________________________________________
177  // Run each sector processor
178 
179  // MIN/MAX ENDCAP and TRIGSECTOR set in interface/Common.h
181  for (int sector = emtf::MIN_TRIGSECTOR; sector <= emtf::MAX_TRIGSECTOR; ++sector) {
183 
184  // Run-dependent configure. This overwrites many of the configurables passed by the python config file.
185  if (new_conditions) {
186  if (iEvent.isRealData()) {
187  sector_processors_.at(es).configure_by_fw_version( fw_version_ );
188  }
189  sector_processors_.at(es).set_pt_lut_version( pt_lut_version_ );
190  }
191 
192  // Process
193  sector_processors_.at(es).process(
194  iEvent.id().event(),
195  muon_primitives,
196  out_hits,
197  out_tracks
198  );
199  }
200  }
201 
202 
203  // ___________________________________________________________________________
204  // Check emulator input and output. They are printed in a way that is friendly
205  // for comparison with the firmware simulator.
206 
207  if (verbose_ > 0) { // debug
208 
210  for (int sector = emtf::MIN_TRIGSECTOR; sector <= emtf::MAX_TRIGSECTOR; ++sector) {
212 
213  // _____________________________________________________________________
214  // This prints the hits as raw text input to the firmware simulator
215  // "12345" is the BX separator
216 
217  std::cout << "==== Endcap " << endcap << " Sector " << sector << " Hits ====" << std::endl;
218  std::cout << "bx e s ss st vf ql cp wg id bd hs" << std::endl;
219 
220  bool empty_sector = true;
221  for (const auto& h : out_hits) {
222  if (h.Sector_idx() != es) continue;
223  empty_sector = false;
224  }
225 
226  for (int ibx = -3-5; (ibx < +3+5+5) && !empty_sector; ++ibx) {
227 
228  for (const auto& h : out_hits) {
229  if (h.Subsystem() == TriggerPrimitive::kCSC) {
230  if (h.Sector_idx() != es) continue;
231  if (h.BX() != ibx) continue;
232 
233  int bx = 1;
234  int endcap = (h.Endcap() == 1) ? 1 : 2;
235  int sector = h.PC_sector();
236  int station = (h.PC_station() == 0 && h.Subsector() == 1) ? 1 : h.PC_station();
237  int chamber = h.PC_chamber() + 1;
238  int strip = (h.Station() == 1 && h.Ring() == 4) ? h.Strip() + 128 : h.Strip(); // ME1/1a
239  int wire = h.Wire();
240  int valid = 1;
241  std::cout << bx << " " << endcap << " " << sector << " " << h.Subsector() << " "
242  << station << " " << valid << " " << h.Quality() << " " << h.Pattern() << " "
243  << wire << " " << chamber << " " << h.Bend() << " " << strip << std::endl;
244 
245  } else if (h.Subsystem() == TriggerPrimitive::kRPC) {
246  if (h.Sector_idx() != es) continue;
247  if (h.BX()+5 != ibx) continue; // RPC hits should be supplied 5 BX later relative to CSC hits
248 
249  // Assign RPC link index. Code taken from src/PrimitiveSelection.cc
250  int rpc_sub = -1;
251  int rpc_chm = -1;
252  if (!h.Neighbor()) {
253  rpc_sub = h.Subsector() - 1;
254  } else {
255  rpc_sub = 6;
256  }
257  if (h.Station() <= 2) {
258  rpc_chm = (h.Station() - 1);
259  } else {
260  rpc_chm = 2 + (h.Station() - 3)*2 + (h.Ring() - 2);
261  }
262 
263  int bx = 1;
264  int endcap = (h.Endcap() == 1) ? 1 : 2;
265  int sector = h.PC_sector();
266  int station = rpc_sub;
267  int chamber = rpc_chm + 1;
268  int strip = (h.Phi_fp() >> 2);
269  int wire = (h.Theta_fp() >> 2);
270  int valid = 2; // this marks RPC stub
271  std::cout << bx << " " << endcap << " " << sector << " " << 0 << " "
272  << station << " " << valid << " " << 0 << " " << 0 << " "
273  << wire << " " << chamber << " " << 0 << " " << strip << std::endl;
274  }
275  } // end loop over hits
276 
277  std::cout << "12345" << std::endl;
278  } // end loop over bx
279 
280  // _____________________________________________________________________
281  // This prints the tracks as raw text output from the firmware simulator
282 
283  std::cout << "==== Endcap " << endcap << " Sector " << sector << " Tracks ====" << std::endl;
284  std::cout << "bx e s a mo et ph cr q pt" << std::endl;
285 
286  for (const auto& t : out_tracks) {
287  if (t.Sector_idx() != es) continue;
288 
289  std::cout << t.BX() << " " << (t.Endcap() == 1 ? 1 : 2) << " " << t.Sector() << " " << t.PtLUT().address << " " << t.Mode() << " "
290  << (t.GMT_eta() >= 0 ? t.GMT_eta() : t.GMT_eta()+512)<< " " << t.GMT_phi() << " "
291  << t.GMT_charge() << " " << t.GMT_quality() << " " << t.Pt() << std::endl;
292  } // end loop over tracks
293 
294  } // end loop over sector
295  } // end loop over endcap
296  } // end debug
297 
298  return;
299 }
unsigned int fw_version_
Definition: TrackFinder.h:34
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:41
int MAX_TRIGSECTOR
Definition: Common.h:53
bool useRPC_
Definition: TrackFinder.h:52
ConditionHelper condition_helper_
Definition: TrackFinder.h:33
GeometryTranslator geometry_translator_
Definition: TrackFinder.h:31
emtf::CSCTag CSCTag
Definition: Common.h:36
const edm::EDGetToken tokenCSC_
Definition: TrackFinder.h:48
unsigned int get_pc_lut_version() const
int MIN_ENDCAP
Definition: Common.h:48
void load(const L1TMuonEndCapForest *payload)
bool useCSC_
Definition: TrackFinder.h:52
bool isRealData() const
Definition: EventBase.h:64
TrackFinder(const edm::ParameterSet &iConfig, edm::ConsumesCollector &&iConsumes)
Definition: TrackFinder.cc:11
void read(unsigned pc_lut_version)
l1t::EMTFTrackCollection EMTFTrackCollection
Definition: Common.h:25
emtf::RPCTag RPCTag
Definition: Common.h:37
unsigned int get_fw_version() const
unsigned int pt_lut_version_
Definition: TrackFinder.h:35
int iEvent
Definition: GenABIO.cc:230
const edm::EDGetToken tokenGEM_
Definition: TrackFinder.h:48
void checkAndUpdateGeometry(const edm::EventSetup &)
int MIN_TRIGSECTOR
Definition: Common.h:52
const L1TMuonEndCapForest & getForest() const
const edm::ParameterSet config_
Definition: TrackFinder.h:46
const edm::EDGetToken tokenRPC_
Definition: TrackFinder.h:48
l1t::EMTFHitCollection EMTFHitCollection
Definition: Common.h:21
emtf::GEMTag GEMTag
Definition: Common.h:38
unsigned int pc_lut_version_
Definition: TrackFinder.h:36
emtf::sector_array< SectorProcessor > sector_processors_
Definition: TrackFinder.h:44
bool checkAndUpdateConditions(const edm::Event &iEvent, const edm::EventSetup &iSetup)
void extractPrimitives(T tag, const edm::Event &iEvent, const edm::EDGetToken &token, TriggerPrimitiveCollection &out)
L1TMuon::TriggerPrimitiveCollection TriggerPrimitiveCollection
Definition: Common.h:30
int MAX_ENDCAP
Definition: Common.h:49
edm::EventID id() const
Definition: EventBase.h:60
HLT enums.
SectorProcessorLUT sector_processor_lut_
Definition: TrackFinder.h:38
void process(const edm::Event &iEvent, const edm::EventSetup &iSetup, EMTFHitCollection &out_hits, EMTFTrackCollection &out_tracks)
Definition: TrackFinder.cc:106
std::unique_ptr< PtAssignmentEngine > pt_assign_engine_2017_
Definition: TrackFinder.h:42
std::unique_ptr< PtAssignmentEngine > pt_assign_engine_2016_
Definition: TrackFinder.h:41
bool useGEM_
Definition: TrackFinder.h:52
PtAssignmentEngine * pt_assign_engine_
Definition: TrackFinder.h:40
unsigned int get_pt_lut_version() const
void set_ptLUTVersion(int ptLUTVersion)