CMS 3D CMS Logo

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