CMS 3D CMS Logo

TrackFinder.cc
Go to the documentation of this file.
2 
3 #include <iostream>
4 #include <sstream>
5 
7 
8 
10  geometry_translator_(),
11  condition_helper_(),
12  sector_processor_lut_(),
13  pt_assign_engine_(),
14  sector_processors_(),
15  config_(iConfig),
16  tokenCSC_(iConsumes.consumes<CSCTag::digi_collection>(iConfig.getParameter<edm::InputTag>("CSCInput"))),
17  tokenRPC_(iConsumes.consumes<RPCTag::digi_collection>(iConfig.getParameter<edm::InputTag>("RPCInput"))),
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  useGEM_(iConfig.getParameter<bool>("GEMEnable")),
25  era_(iConfig.getParameter<std::string>("Era"))
26 {
27 
28  if (era_ == "Run2_2016") {
30  } else if (era_ == "Run2_2017" || era_ == "Run2_2018") {
32  } else {
33  edm::LogError("L1T") << "era_ = " << era_; 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 
87  sector_processors_.at(es).configure(
91  pt_assign_engine_.get(),
92  verbose_, endcap, sector,
93  minBX, maxBX, bxWindow, bxShiftCSC, bxShiftRPC, bxShiftGEM,
94  era_,
95  zoneBoundaries, zoneOverlap,
96  includeNeighbor, duplicateTheta, fixZonePhi, useNewZones, fixME11Edges,
97  pattDefinitions, symPattDefinitions, useSymPatterns,
98  thetaWindow, thetaWindowZone0, useRPC_, useSingleHits, bugSt2PhDiff, bugME11Dupes, bugAmbigThetaWin, twoStationSameBX,
99  maxRoadsPerZone, maxTracks, useSecondEarliest, bugSameSectorPt0,
100  readPtLUTFile, fixMode15HighPt, bug9BitDPhi, bugMode7CLCT, bugNegPt, bugGMTPhi, promoteMode7, modeQualVer
101  );
102  }
103  }
104 
105 } // End constructor: TrackFinder::TrackFinder()
106 
108 
109 }
110 
112  const edm::Event& iEvent, const edm::EventSetup& iSetup,
113  EMTFHitCollection& out_hits,
114  EMTFTrackCollection& out_tracks
115 ) {
116 
117  // Clear output collections
118  out_hits.clear();
119  out_tracks.clear();
120 
121  // Get the geometry for TP conversions
123 
124  // Get the conditions, primarily the firmware version and the BDT forests
126 
127  // ___________________________________________________________________________
128  // Extract all trigger primitives
129 
130  TriggerPrimitiveCollection muon_primitives;
131 
132  EMTFSubsystemCollector collector;
133  if (useCSC_)
134  collector.extractPrimitives(CSCTag(), iEvent, tokenCSC_, muon_primitives);
135  if (useRPC_)
136  collector.extractPrimitives(RPCTag(), iEvent, tokenRPC_, muon_primitives);
137  if (useGEM_)
138  collector.extractPrimitives(GEMTag(), iEvent, tokenGEM_, muon_primitives);
139 
140  // Check trigger primitives
141  if (verbose_ > 2) { // debug
142  std::cout << "Num of TriggerPrimitive: " << muon_primitives.size() << std::endl;
143  for (const auto& p : muon_primitives) {
144  p.print(std::cout);
145  }
146  }
147 
148  // ___________________________________________________________________________
149  // Run each sector processor
150 
151  // Reload primitive conversion LUTs if necessary
153 
154  // Reload pT LUT if necessary
156 
157  // MIN/MAX ENDCAP and TRIGSECTOR set in interface/Common.h
159  for (int sector = emtf::MIN_TRIGSECTOR; sector <= emtf::MAX_TRIGSECTOR; ++sector) {
161 
162  // Run-dependent configure. This overwrites many of the configurables passed by the python config file.
163  if (iEvent.isRealData() && fwConfig_) {
164  sector_processors_.at(es).configure_by_fw_version(condition_helper_.get_fw_version());
165  }
166 
167  // Process
168  sector_processors_.at(es).process(
169  iEvent.id().event(),
170  muon_primitives,
171  out_hits,
172  out_tracks
173  );
174  }
175  }
176 
177 
178  // ___________________________________________________________________________
179  // Check emulator input and output. They are printed in a way that is friendly
180  // for comparison with the firmware simulator.
181 
182  if (verbose_ > 0) { // debug
183  std::cout << "Run number: " << iEvent.id().run() << " pc_lut_ver: " << condition_helper_.get_pc_lut_version()
184  << " pt_lut_ver: " << condition_helper_.get_pt_lut_version() << ", " << pt_assign_engine_->get_pt_lut_version()
185  << " fw_ver: " << condition_helper_.get_fw_version()
186  << std::endl;
187 
189  for (int sector = emtf::MIN_TRIGSECTOR; sector <= emtf::MAX_TRIGSECTOR; ++sector) {
191 
192  // _____________________________________________________________________
193  // This prints the hits as raw text input to the firmware simulator
194  // "12345" is the BX separator
195 
196  std::cout << "==== Endcap " << endcap << " Sector " << sector << " Hits ====" << std::endl;
197  std::cout << "bx e s ss st vf ql cp wg id bd hs" << std::endl;
198 
199  bool empty_sector = true;
200  for (const auto& h : out_hits) {
201  if (h.Sector_idx() != es) continue;
202  empty_sector = false;
203  }
204 
205  for (int ibx = -3-5; (ibx < +3+5+5) && !empty_sector; ++ibx) {
206 
207  for (const auto& h : out_hits) {
208  if (h.Subsystem() == TriggerPrimitive::kCSC) {
209  if (h.Sector_idx() != es) continue;
210  if (h.BX() != ibx) continue;
211 
212  int bx = 1;
213  int endcap = (h.Endcap() == 1) ? 1 : 2;
214  int sector = h.PC_sector();
215  int station = (h.PC_station() == 0 && h.Subsector() == 1) ? 1 : h.PC_station();
216  int chamber = h.PC_chamber() + 1;
217  int strip = (h.Station() == 1 && h.Ring() == 4) ? h.Strip() + 128 : h.Strip(); // ME1/1a
218  int wire = h.Wire();
219  int valid = 1;
220  std::cout << bx << " " << endcap << " " << sector << " " << h.Subsector() << " "
221  << station << " " << valid << " " << h.Quality() << " " << h.Pattern() << " "
222  << wire << " " << chamber << " " << h.Bend() << " " << strip << std::endl;
223 
224  } else if (h.Subsystem() == TriggerPrimitive::kRPC) {
225  if (h.Sector_idx() != es) continue;
226  if (h.BX()+6 != ibx) continue; // RPC hits should be supplied 6 BX later relative to CSC hits
227 
228  // Assign RPC link index. Code taken from src/PrimitiveSelection.cc
229  int rpc_sub = -1;
230  int rpc_chm = -1;
231  if (!h.Neighbor()) {
232  rpc_sub = h.Subsector() - 1;
233  } else {
234  rpc_sub = 6;
235  }
236  if (h.Station() <= 2) {
237  rpc_chm = (h.Station() - 1);
238  } else {
239  rpc_chm = 2 + (h.Station() - 3)*2 + (h.Ring() - 2);
240  }
241 
242  int bx = 1;
243  int endcap = (h.Endcap() == 1) ? 1 : 2;
244  int sector = h.PC_sector();
245  int station = rpc_sub;
246  int chamber = rpc_chm + 1;
247  int strip = (h.Phi_fp() >> 2);
248  int wire = (h.Theta_fp() >> 2);
249  int valid = 2; // this marks RPC stub
250  std::cout << bx << " " << endcap << " " << sector << " " << 0 << " "
251  << station << " " << valid << " " << 0 << " " << 0 << " "
252  << wire << " " << chamber << " " << 0 << " " << strip << std::endl;
253  }
254  } // end loop over hits
255 
256  std::cout << "12345" << std::endl;
257  } // end loop over bx
258 
259  // _____________________________________________________________________
260  // This prints the tracks as raw text output from the firmware simulator
261 
262  std::cout << "==== Endcap " << endcap << " Sector " << sector << " Tracks ====" << std::endl;
263  std::cout << "bx e s a mo et ph cr q pt" << std::endl;
264 
265  for (const auto& t : out_tracks) {
266  if (t.Sector_idx() != es) continue;
267 
268  std::cout << t.BX() << " " << (t.Endcap() == 1 ? 1 : 2) << " " << t.Sector() << " " << t.PtLUT().address << " " << t.Mode() << " "
269  << (t.GMT_eta() >= 0 ? t.GMT_eta() : t.GMT_eta()+512)<< " " << t.GMT_phi() << " "
270  << t.GMT_charge() << " " << t.GMT_quality() << " " << t.Pt() << std::endl;
271  } // end loop over tracks
272 
273  } // end loop over sector
274  } // end loop over endcap
275  } // end debug
276 
277  return;
278 }
RunNumber_t run() const
Definition: EventID.h:39
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:41
int MAX_TRIGSECTOR
Definition: Common.h:61
bool useRPC_
Definition: TrackFinder.h:47
ConditionHelper condition_helper_
Definition: TrackFinder.h:33
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
GeometryTranslator geometry_translator_
Definition: TrackFinder.h:31
emtf::CSCTag CSCTag
Definition: Common.h:44
const edm::EDGetToken tokenCSC_
Definition: TrackFinder.h:43
void read(int pc_lut_version)
unsigned int get_pc_lut_version() const
int MIN_ENDCAP
Definition: Common.h:56
bool useCSC_
Definition: TrackFinder.h:47
void checkAndUpdateConditions(const edm::Event &iEvent, const edm::EventSetup &iSetup)
bool isRealData() const
Definition: EventBase.h:64
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:9
l1t::EMTFTrackCollection EMTFTrackCollection
Definition: Common.h:28
emtf::RPCTag RPCTag
Definition: Common.h:45
unsigned int get_fw_version() const
int iEvent
Definition: GenABIO.cc:230
const edm::EDGetToken tokenGEM_
Definition: TrackFinder.h:43
void checkAndUpdateGeometry(const edm::EventSetup &)
int MIN_TRIGSECTOR
Definition: Common.h:60
const L1TMuonEndCapForest & getForest() const
const edm::ParameterSet config_
Definition: TrackFinder.h:41
const edm::EDGetToken tokenRPC_
Definition: TrackFinder.h:43
std::string era_
Definition: TrackFinder.h:49
int primConvLUT_
Definition: TrackFinder.h:45
l1t::EMTFHitCollection EMTFHitCollection
Definition: Common.h:24
emtf::GEMTag GEMTag
Definition: Common.h:46
std::unique_ptr< PtAssignmentEngine > pt_assign_engine_
Definition: TrackFinder.h:37
emtf::sector_array< SectorProcessor > sector_processors_
Definition: TrackFinder.h:39
L1TMuon::TriggerPrimitiveCollection TriggerPrimitiveCollection
Definition: Common.h:33
int MAX_ENDCAP
Definition: Common.h:57
bool fwConfig_
Definition: TrackFinder.h:47
edm::EventID id() const
Definition: EventBase.h:60
HLT enums.
SectorProcessorLUT sector_processor_lut_
Definition: TrackFinder.h:35
void process(const edm::Event &iEvent, const edm::EventSetup &iSetup, EMTFHitCollection &out_hits, EMTFTrackCollection &out_tracks)
Definition: TrackFinder.cc:111
bool useGEM_
Definition: TrackFinder.h:47
unsigned int get_pt_lut_version() const