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