CMS 3D CMS Logo

L1TMuonEndCapTrackProducer.cc
Go to the documentation of this file.
1 // Upgraded Encdap Muon Track Finding Algorithm //
3 // //
4 // Info: A human-readable version of the firmware based //
5 // track finding algorithm which will be implemented //
6 // in the upgraded endcaps of CMS. DT and RPC inputs //
7 // are not considered in this algorithm. //
8 // //
9 // Author: M. Carver (UF) //
11 
12 #define NUM_SECTORS 12
13 
16 #include "L1Trigger/CSCTrackFinder/test/src/RefTrack.h"
17 
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <math.h>
21 
32 
33 // New EDM output for detailed track and hit information - AWB 01.04.16
36 
37 using namespace L1TMuon;
39 // Pointers to the current geometry records
40 unsigned long long _geom_cache_id;
42 
43 
45 
46  inputTokenCSC = consumes<CSCCorrelatedLCTDigiCollection>(p.getParameter<edm::InputTag>("CSCInput"));
47  bxShiftCSC = p.getUntrackedParameter<int>("CSCInputBxShift", 0);
48  inputTokenRPC = consumes<RPCDigiCollection>(p.getParameter<edm::InputTag>("RPCInput"));
49 
50  produces<l1t::RegionalMuonCandBxCollection >("EMTF");
51  produces< l1t::EMTFTrackCollection >("");
52  produces< l1t::EMTFHitCollection >("");
53  produces< l1t::EMTFTrackExtraCollection >("");
54  produces< l1t::EMTFHitExtraCollection >("CSC");
55  produces< l1t::EMTFHitExtraCollection >("RPC");
56 
57 }
58 
59 
61  const edm::EventSetup& es) {
62 
63  //bool verbose = false;
64 
65  //fprintf (write,"12345\n"); //<-- part of printing text file to send verilog code, not needed if George's package is included
66 
67  //std::auto_ptr<L1TMuon::InternalTrackCollection> FoundTracks (new L1TMuon::InternalTrackCollection);
68  auto FoundTracks = std::make_unique<L1TMuon::InternalTrackCollection>();
69  auto OutputCands = std::make_unique<l1t::RegionalMuonCandBxCollection>();
70  auto OutTracks = std::make_unique<l1t::EMTFTrackCollection>();
71  auto OutHits = std::make_unique<l1t::EMTFHitCollection>();
72  auto OutputTracks = std::make_unique<l1t::EMTFTrackExtraCollection>();
73  auto OutputHits = std::make_unique<l1t::EMTFHitExtraCollection>();
74  auto OutputHitsRPC = std::make_unique<l1t::EMTFHitExtraCollection>();
75 
76  std::vector<BTrack> PTracks[NUM_SECTORS];
77  std::vector<BTrack> PTracks_BX[NUM_SECTORS][3];
78 
79  std::vector<TriggerPrimitive> tester;
80  std::vector<TriggerPrimitive> tester_rpc;
81  //std::vector<InternalTrack> FoundTracks;
82 
83  // Get the RPC geometry
85  unsigned long long geomid = geom.cacheIdentifier();
86  if( _geom_cache_id != geomid )
87  geom.get(_geom_rpc);
88 
89 
93 
95  ev.getByToken(inputTokenCSC, MDC);
96 
98  ev.getByToken(inputTokenRPC, RDC);
99 
100  std::vector<TriggerPrimitive> out;
101  std::vector<TriggerPrimitive> out_rpc;
102 
103  auto chamber = MDC->begin();
104  auto chend = MDC->end();
105  for( ; chamber != chend; ++chamber ) {
106  auto digi = (*chamber).second.first;
107  auto dend = (*chamber).second.second;
108  for( ; digi != dend; ++digi ) {
109  CSCCorrelatedLCTDigi tmp_digi = *digi;
110  tmp_digi.setBX( tmp_digi.getBX() + std::max(bxShiftCSC, -1*tmp_digi.getBX()) );
111  out.push_back(TriggerPrimitive((*chamber).first,tmp_digi));
112  l1t::EMTFHitExtra thisHit;
113  thisHit.ImportCSCDetId( (*chamber).first );
114  thisHit.ImportCSCCorrelatedLCTDigi( tmp_digi );
115  if (thisHit.Station() == 1 && thisHit.Ring() == 1 && thisHit.Strip() > 127) thisHit.set_ring(4);
116  thisHit.set_neighbor(0);
117  OutputHits->push_back( thisHit );
118  if ( ((thisHit.Ring() != 1 || thisHit.Station() == 1) && (thisHit.Chamber() % 6 == 2)) ||
119  ((thisHit.Ring() == 1 && thisHit.Station() > 1) && (thisHit.Chamber() % 3 == 1)) ) {
120  l1t::EMTFHitExtra neighborHit = thisHit;
121  neighborHit.set_neighbor(1);
122  OutputHits->push_back( neighborHit );
123  }
124  }
125  }
126 
127  auto rchamber = RDC->begin();
128  auto rchend = RDC->end();
129  for( ; rchamber != rchend; ++rchamber) {
130  auto rdigi = (*rchamber).second.first;
131  auto rdend = (*rchamber).second.second;
132  for( ; rdigi != rdend; ++rdigi) {
133  out_rpc.push_back(TriggerPrimitive( (*rchamber).first, rdigi->strip(), 0, rdigi->bx())); // Layer unset. How to access? - AWB 03.06.16
134  }
135  }
136 
137 
141 
142  // auto tpsrc = _tpinputs.cbegin();
143  //auto tpend = _tpinputs.cend();
144  // for( ; tpsrc != tpend; ++tpsrc ) {
145  // edm::Handle<TriggerPrimitiveCollection> tps;
146  // ev.getByLabel(*tpsrc,tps);
147  auto tp = out_rpc.cbegin();
148  auto tpend = out_rpc.cend();
149 
150  for( ; tp != tpend; ++tp ) {
151  if (tp->subsystem() == 2) tester_rpc.push_back(*tp);
152  }
153 
154  // Create extra converted hits for chambers with two LCTs (ambiguous strip/wire pairing)
155  for(unsigned int i1=0;i1<out.size();i1++){
156  tester.push_back(out[i1]);
157 
158  for(unsigned int i2=i1+1;i2<out.size();i2++){
159  if ( out[i1].detId<CSCDetId>().station() == out[i2].detId<CSCDetId>().station() &&
160  out[i1].detId<CSCDetId>().endcap() == out[i2].detId<CSCDetId>().endcap() &&
161  out[i1].detId<CSCDetId>().triggerSector() == out[i2].detId<CSCDetId>().triggerSector() &&
162  out[i1].detId<CSCDetId>().ring() == out[i2].detId<CSCDetId>().ring() &&
163  out[i1].detId<CSCDetId>().chamber() == out[i2].detId<CSCDetId>().chamber() &&
164  out[i1].getBX() == out[i2].getBX() && out[i1].Id() == out[i2].Id() &&
165  out[i1].getStrip() != out[i2].getStrip() && out[i1].getWire() != out[i2].getWire() ) {
166 
167  TriggerPrimitive NewWire1(out[i1],out[i2]);
168  TriggerPrimitive NewWire2(out[i2],out[i1]);
169  tester.push_back(NewWire1);
170  tester.push_back(NewWire2);
171  }
172  } // End loop: for(unsigned int i2=i1+1;i2<out.size();i2++)
173  } // End loop: for(unsigned int i1=0;i1<out.size();i1++)
174 
175  uint nHits = OutputHits->size();
176  for (uint iHit = 0; iHit < nHits; iHit++) {
177  for (uint jHit = iHit+1; jHit < nHits; jHit++) {
178  if ( OutputHits->at(iHit).Chamber() != OutputHits->at(jHit).Chamber() ) continue;
179  if ( (OutputHits->at(iHit).Ring() % 3) != (OutputHits->at(jHit).Ring() % 3) ) continue;
180  if ( OutputHits->at(iHit).Sector() != OutputHits->at(jHit).Sector() ) continue;
181  if ( OutputHits->at(iHit).Station() != OutputHits->at(jHit).Station() ) continue;
182  if ( OutputHits->at(iHit).Endcap() != OutputHits->at(jHit).Endcap() ) continue;
183  if ( OutputHits->at(iHit).BX() != OutputHits->at(jHit).BX() ) continue;
184  if ( OutputHits->at(iHit).Neighbor() != OutputHits->at(jHit).Neighbor() ) continue;
185  if ( OutputHits->at(iHit).Strip() == OutputHits->at(jHit).Strip() ) continue;
186  if ( OutputHits->at(iHit).Wire() == OutputHits->at(jHit).Wire() ) continue;
187 
188  l1t::EMTFHitExtra new_hit_1 = OutputHits->at(iHit).Clone();
189  l1t::EMTFHitExtra new_hit_2 = OutputHits->at(jHit).Clone();
190  new_hit_1.set_wire( OutputHits->at(jHit).Wire() );
191  new_hit_2.set_wire( OutputHits->at(iHit).Wire() );
192  new_hit_1.SetCSCLCTDigi( new_hit_1.CreateCSCCorrelatedLCTDigi() );
193  new_hit_2.SetCSCLCTDigi( new_hit_2.CreateCSCCorrelatedLCTDigi() );
194  OutputHits->push_back( new_hit_1 );
195  OutputHits->push_back( new_hit_2 );
196  }
197  }
198 
199  std::vector<ConvertedHit> CHits[NUM_SECTORS];
200  // MatchingOutput MO[NUM_SECTORS];
201 
202  for(int SectIndex=0;SectIndex<NUM_SECTORS;SectIndex++){//perform TF on all 12 sectors
203 
207 
208  std::vector<ConvertedHit> ConvHits = primConv_.convert(tester,SectIndex);
209  CHits[SectIndex] = ConvHits;
210 
211  l1t::EMTFHitExtraCollection tmp_hits_rpc = primConvRPC_.convert(tester_rpc, SectIndex, _geom_rpc);
212  for (uint iHit = 0; iHit < tmp_hits_rpc.size(); iHit++)
213  OutputHitsRPC->push_back( tmp_hits_rpc.at(iHit) );
214  std::vector<ConvertedHit> ConvHitsRPC = primConvRPC_.fillConvHits(tmp_hits_rpc);
215 
216  // Fill OutputHits with ConvertedHit information
217  for (uint iCHit = 0; iCHit < ConvHits.size(); iCHit++) {
218  // bool isMatched = false;
219 
220  for (uint iHit = 0; iHit < OutputHits->size(); iHit++) {
221  if ( ConvHits.at(iCHit).Station() == OutputHits->at(iHit).Station() &&
222  ( ConvHits.at(iCHit).Id() == OutputHits->at(iHit).CSC_ID() ||
223  ConvHits.at(iCHit).Id() == ( (OutputHits->at(iHit).Ring() != 4) // Account for either ME1/1a
224  ? OutputHits->at(iHit).CSC_ID() // CSC ID numbering convention
225  : OutputHits->at(iHit).CSC_ID() + 9 ) ) &&
226  ConvHits.at(iCHit).Wire() == OutputHits->at(iHit).Wire() &&
227  ConvHits.at(iCHit).Strip() == OutputHits->at(iHit).Strip() &&
228  ConvHits.at(iCHit).BX() - 6 == OutputHits->at(iHit).BX() &&
229  ConvHits.at(iCHit).IsNeighbor() == OutputHits->at(iHit).Neighbor() ) {
230  // isMatched = true;
231  OutputHits->at(iHit).set_neighbor ( ConvHits.at(iCHit).IsNeighbor());
232  OutputHits->at(iHit).set_sector_index( ConvHits.at(iCHit).SectorIndex() );
233  OutputHits->at(iHit).set_phi_zone ( ConvHits.at(iCHit).Zhit() );
234  OutputHits->at(iHit).set_phi_hit ( ConvHits.at(iCHit).Ph_hit() );
235  OutputHits->at(iHit).set_zone ( ConvHits.at(iCHit).Phzvl() );
236  OutputHits->at(iHit).set_phi_loc_int ( ConvHits.at(iCHit).Phi() );
237  OutputHits->at(iHit).set_theta_int ( ConvHits.at(iCHit).Theta() );
238 
239  // // Replace with ZoneWord - AWB 04.09.16
240  // OutputHits->at(iHit).SetZoneContribution ( ConvHits.at(iCHit).ZoneContribution() );
241  OutputHits->at(iHit).set_phi_loc_deg ( l1t::calc_phi_loc_deg( OutputHits->at(iHit).Phi_loc_int() ) );
242  OutputHits->at(iHit).set_phi_loc_rad ( l1t::calc_phi_loc_rad( OutputHits->at(iHit).Phi_loc_int() ) );
243  OutputHits->at(iHit).set_phi_glob_deg ( l1t::calc_phi_glob_deg_hit( OutputHits->at(iHit).Phi_loc_deg(), OutputHits->at(iHit).Sector_index() ) );
244  OutputHits->at(iHit).set_phi_glob_rad ( l1t::calc_phi_glob_rad_hit( OutputHits->at(iHit).Phi_loc_rad(), OutputHits->at(iHit).Sector_index() ) );
245  OutputHits->at(iHit).set_theta_deg ( l1t::calc_theta_deg_from_int( OutputHits->at(iHit).Theta_int() ) );
246  OutputHits->at(iHit).set_theta_rad ( l1t::calc_theta_rad_from_int( OutputHits->at(iHit).Theta_int() ) );
247  OutputHits->at(iHit).set_eta( l1t::calc_eta_from_theta_rad( OutputHits->at(iHit).Theta_rad() ) * OutputHits->at(iHit).Endcap() );
248 
249  OutHits->push_back( OutputHits->at(iHit).CreateEMTFHit() );
250  }
251  } // End loop: for (uint iHit = 0; iHit < OutputHits->size(); iHit++)
252 
253  // if (isMatched == false) {
254  // std::cout << "***********************************************" << std::endl;
255  // std::cout << "Unmatched ConvHit in event " << ev.id().event() << ", SectIndex " << SectIndex << std::endl;
256  // std::cout << "ConvHit: station = " << ConvHits.at(iCHit).Station() << ", CSC ID = " << ConvHits.at(iCHit).Id()
257  // << ", sector index = " << ConvHits.at(iCHit).SectorIndex() << ", subsector = " << ConvHits.at(iCHit).Sub()
258  // << ", wire = " << ConvHits.at(iCHit).Wire() << ", strip = " << ConvHits.at(iCHit).Strip()
259  // << ", BX = " << ConvHits.at(iCHit).BX() << ", neighbor = " << ConvHits.at(iCHit).IsNeighbor() << std::endl;
260 
261  // for (uint iHit = 0; iHit < OutputHits->size(); iHit++) {
262  // std::cout << "EMTFHitExtra: station = " << OutputHits->at(iHit).Station() << ", CSC ID = " << OutputHits->at(iHit).CSC_ID()
263  // << ", sector index = " << OutputHits->at(iHit).Sector_index() << ", subsector = " << OutputHits->at(iHit).Subsector()
264  // << ", wire = " << OutputHits->at(iHit).Wire() << ", strip = " << OutputHits->at(iHit).Strip()
265  // << ", BX = " << OutputHits->at(iHit).BX() << ", neighbor = " << OutputHits->at(iHit).Neighbor()
266  // << ", chamber = " << OutputHits->at(iHit).Chamber() << ", ring = " << OutputHits->at(iHit).Ring()
267  // << ", endcap = " << OutputHits->at(iHit).Endcap() << ", sector = " << OutputHits->at(iHit).Sector() << std::endl;
268  // }
269  // }
270 
271  } // End loop: for (uint iCHit = 0; iCHit < ConvHits.size(); iCHit++)
272 
273 
276  //for(std::vector<ConvertedHit>::iterator h = ConvHits.begin();h != ConvHits.end();h++){
277 
278  //if((h->Id()) > 9){h->SetId(h->Id() - 9);h->SetStrip(h->Strip() + 128);}
279  //fprintf (write,"0 1 1 %d %d\n",h->Sub(),h->Station());
280  //fprintf (write,"1 %d %d %d\n",h->Quality(),h->Pattern(),h->Wire());
281  //fprintf (write,"%d 0 %d\n",h->Id(),h->Strip());
282  //}
285 
286 
287 
293 
294  std::vector<std::vector<ConvertedHit>> GroupedHits = GroupBX(ConvHits);
295 
296 
300 
301  std::vector<ZonesOutput> Zout = Zones(GroupedHits);
302 
303 
308 
309  std::vector<PatternOutput> Pout = Patterns(Zout);
310  std::vector<PatternOutput> Pout_Hold = Pout;
311 
312  // PatternOutput Test = DeleteDuplicatePatterns(Pout);
313 
314  //PrintQuality(Test.detected);
315 
316 
321 
322  // SortingOutput Sout = SortSect(Test);
323  std::vector<SortingOutput> Sout_Hold = SortSect_Hold(Pout_Hold);
324 
325 
330 
331  // MatchingOutput Mout = PhiMatching(Sout);
332  std::vector<MatchingOutput> Mout_Hold = PhiMatching_Hold(Sout_Hold);
333 
338 
339  // std::vector<std::vector<DeltaOutput>> Dout = CalcDeltas(Mout);////
340  DeltaOutArr3 Dout_Hold = CalcDeltas_Hold(Mout_Hold);
341 
342 
347 
348  // std::vector<BTrack> Bout = BestTracks(Dout);
349  // PTracks[SectIndex] = Bout;
350 
351  std::vector<std::vector<BTrack>> Bout_Hold = BestTracks_Hold(Dout_Hold);
352  for(int bx=0;bx<3;bx++)
353  PTracks_BX[SectIndex][bx] = Bout_Hold[bx];
354 
355 
356  } // End loop: for(int SectIndex=0;SectIndex<NUM_SECTORS;SectIndex++)
357 
358 
362 
363  std::vector<BTrack> PTemp[NUM_SECTORS];
364  std::vector<BTrack> AllTracks, AllTracks_PreCancel;
365  for (int i=0; i<NUM_SECTORS; i++) PTemp[i] = PTracks[i];
366 
367  for(int bx=0;bx<3;bx++){
368  for(int j=0;j<36;j++){
369 
370  // if(PTemp[j/3][j%3].phi)//no track
371  // AllTracks.push_back(PTemp[j/3][j%3]);
372 
373  if(PTracks_BX[j/3][bx][j%3].phi) {//no track
374  AllTracks_PreCancel.push_back(PTracks_BX[j/3][bx][j%3]);
375  if (PTracks_BX[j/3][bx][j%3].theta == 0)
376  LogTrace("L1TMuonEndCapTrackProducer") << "PTrack_BX theta = 0" << std::endl;
377  }
378 
379  }
380  }
381 
382  // Cancel out tracks with identical hits
383  for (unsigned int i1 = 0; i1 < AllTracks_PreCancel.size(); i1++) {
384  bool dup = false;
385  int rank1 = AllTracks_PreCancel[i1].winner.Rank();
386  int rank2 = -99;
387  int i1_dup = i1;
388  int i2_dup = -99;
389  for (unsigned int i2 = 0; i2 < AllTracks_PreCancel.size(); i2++) {
390  if (i1 == i2) continue;
391  for (std::vector<ConvertedHit>::iterator A1 = AllTracks_PreCancel[i1].AHits.begin(); A1 != AllTracks_PreCancel[i1].AHits.end(); A1++) {
392  CSCDetId D1 = A1->TP().detId<CSCDetId>();
393  TriggerPrimitive::CSCData C1 = A1->TP().getCSCData();
394  for (std::vector<ConvertedHit>::iterator A2 = AllTracks_PreCancel[i2].AHits.begin(); A2 != AllTracks_PreCancel[i2].AHits.end(); A2++) {
395  CSCDetId D2 = A2->TP().detId<CSCDetId>();
396  TriggerPrimitive::CSCData C2 = A2->TP().getCSCData();
397  if ( A1->SectorIndex() == A2->SectorIndex() && D1.endcap() == D2.endcap() && D1.station() == D2.station() &&
398  D1.ring() == D2.ring() && D1.triggerSector() == D2.triggerSector() && D1.chamber() == D2.chamber() &&
399  C1.bx == C2.bx && C1.strip == C2.strip && C1.keywire == C2.keywire ) {
400  dup = true;
401  if (AllTracks_PreCancel[i2].winner.Rank() > rank2) {
402  i2_dup = i2;
403  rank2 = AllTracks_PreCancel[i2].winner.Rank();
404  } // Find the highest-ranked duplicate track
405  } // End if hits are identical
406  } // End loop over hits in track 2
407  } // End loop over hits in track 1
408  } // End second loop over tracks
409 
410  // Only use ordering when ranks are equal. Track order is not necessarily the same as FW. - AWB 21.09.16
411  if ( (!dup) || (rank1 > rank2) || (rank1 == rank2 && i1_dup < i2_dup) ) AllTracks.push_back(AllTracks_PreCancel[i1]);
412  } // End first loop over tracks
413 
414 
419 
420  std::vector<l1t::RegionalMuonCand> tester1;
421  std::vector<std::pair<int,l1t::RegionalMuonCand>> holder, holder2;
422 
423  for(unsigned int fbest=0;fbest<AllTracks.size();fbest++){
424 
425  if(AllTracks[fbest].phi){
426 
427  InternalTrack tempTrack;
428  tempTrack.setType(2);
429  tempTrack.phi = AllTracks[fbest].phi;
430  tempTrack.theta = AllTracks[fbest].theta;
431  tempTrack.rank = AllTracks[fbest].winner.Rank();
432  tempTrack.deltas = AllTracks[fbest].deltas;
433  std::vector<int> ps, ts;
434 
435  if (tempTrack.theta == 0) LogTrace("L1TMuonEndCapTrackProducer") << "Track has theta 0" << std::endl;
436 
437  l1t::EMTFTrackExtra thisTrack;
438  thisTrack.set_phi_loc_int ( AllTracks[fbest].phi );
439  thisTrack.set_theta_int ( AllTracks[fbest].theta );
440  thisTrack.set_rank ( AllTracks[fbest].winner.Rank() );
441  // thisTrack.set_deltas ( AllTracks[fbest].deltas );
442  int tempStraightness = 0;
443  int tempRank = thisTrack.Rank();
444  if (tempRank & 64)
445  tempStraightness |= 4;
446  if (tempRank & 16)
447  tempStraightness |= 2;
448  if (tempRank & 4)
449  tempStraightness |= 1;
450  thisTrack.set_straightness ( tempStraightness );
451 
452  int mode = 0;
453  if(tempTrack.rank & 32)
454  mode |= 8;
455  if(tempTrack.rank & 8)
456  mode |= 4;
457  if(tempTrack.rank & 2)
458  mode |= 2;
459  if(tempTrack.rank & 1)
460  mode |= 1;
461 
462  int sector = -1;
463  // bool ME13 = false;
464  int me1address = 0, me2address = 0, CombAddress = 0, mode_uncorr = 0;
465  int ebx = 20, sebx = 20;
466  int phis[4] = {-99,-99,-99,-99};
467 
468  int cHits_in_station[4] = {0,0,0,0};
469  int eHits_in_station[4] = {0,0,0,0};
470  for(std::vector<ConvertedHit>::iterator A = AllTracks[fbest].AHits.begin();A != AllTracks[fbest].AHits.end();A++){
471 
472  if(A->Phi() != -999){
473  cHits_in_station[A->TP().detId<CSCDetId>().station() - 1] += 1;
474 
475  l1t::EMTFHitExtra thisHit;
476  // thisHit.ImportCSCDetId( A->TP().detId<CSCDetId>() );
477 
478  for (uint iHit = 0; iHit < OutputHits->size(); iHit++) {
479  if ( (A->TP().detId<CSCDetId>().endcap() == 1) == (OutputHits->at(iHit).Endcap() == 1) &&
480  A->TP().detId<CSCDetId>().station() == OutputHits->at(iHit).Station() &&
481  A->TP().detId<CSCDetId>().triggerSector() == OutputHits->at(iHit).Sector() &&
482  A->TP().getCSCData().cscID == OutputHits->at(iHit).CSC_ID() &&
483  A->Wire() == OutputHits->at(iHit).Wire() &&
484  A->Strip() == OutputHits->at(iHit).Strip() &&
485  A->TP().getCSCData().bx - 6 == OutputHits->at(iHit).BX() &&
486  A->IsNeighbor() == OutputHits->at(iHit).Neighbor() ) {
487  thisHit = OutputHits->at(iHit);
488  // Hacky fix because ConvertedHits are not removed when theta windows are applied - AWB 30.06.16
489  if ( (A->TP().detId<CSCDetId>().station() == 1 && (mode & 8)) ||
490  (A->TP().detId<CSCDetId>().station() == 2 && (mode & 4)) ||
491  (A->TP().detId<CSCDetId>().station() == 3 && (mode & 2)) ||
492  (A->TP().detId<CSCDetId>().station() == 4 && (mode & 1)) ) {
493  eHits_in_station[OutputHits->at(iHit).Station() - 1] += 1;
494  thisTrack.push_HitExtraIndex(iHit);
495  thisTrack.push_HitExtra(thisHit);
496  }
497  break;
498  }
499  }
500 
501  if ( thisHit.Station() < 0 ) {
502  LogTrace("L1TMuonEndCapTrackProducer") << "!@#$ Converted hit with station " << A->TP().detId<CSCDetId>().station() << ", CSC_ID " << A->TP().getCSCData().cscID
503  << ", sector index " << A->SectorIndex() << ", subsector " << A->Sub()
504  << ", wire " << A->Wire() << ", strip " << A->Strip() << ", BX " << A->TP().getCSCData().bx - 6
505  << ", neighbor " << A->IsNeighbor() << " has no match" << std::endl;
506  for (uint iHit = 0; iHit < OutputHits->size(); iHit++)
507  LogTrace("L1TMuonEndCapTrackProducer") << "!@#$ Option " << iHit+1 << " with endcap " << OutputHits->at(iHit).Endcap()
508  << ", station " << OutputHits->at(iHit).Station() << ", CSC_ID " << OutputHits->at(iHit).CSC_ID()
509  << ", ring " << OutputHits->at(iHit).Ring() << ", chamber " << OutputHits->at(iHit).Chamber()
510  << ", wire " << OutputHits->at(iHit).Wire() << ", strip " << OutputHits->at(iHit).Strip()
511  << ", BX " << OutputHits->at(iHit).BX() << ", neighbor " << OutputHits->at(iHit).Neighbor() << std::endl;
512  }
513 
514  thisTrack.set_endcap ( thisHit.Endcap() );
515  thisTrack.set_sector_index ( thisHit.Sector_index() );
516  thisTrack.set_sector ( l1t::calc_sector_from_index( thisHit.Sector_index() ) );
517  thisTrack.set_sector_GMT ( l1t::calc_sector_GMT( thisHit.Sector() ) );
518  if ( thisHit.Neighbor() == 0 ) thisTrack.set_all_neighbor(0);
519  if ( thisHit.Neighbor() == 1 ) thisTrack.set_has_neighbor(1);
520  if ( thisHit.Neighbor() == 0 && thisTrack.Has_neighbor() == -999 ) thisTrack.set_has_neighbor(0);
521  if ( thisHit.Neighbor() == 1 && thisTrack.All_neighbor() == -999 ) thisTrack.set_all_neighbor(0);
522 
523  int station = A->TP().detId<CSCDetId>().station();
524  int id = A->TP().getCSCData().cscID;
525  int trknm = A->TP().getCSCData().trknmb;
526 
527  phis[station-1] = A->Phi();
528 
529 
530  if(A->TP().getCSCData().bx < ebx){
531  sebx = ebx;
532  ebx = A->TP().getCSCData().bx;
533  }
534  else if(A->TP().getCSCData().bx < sebx){
535  sebx = A->TP().getCSCData().bx;
536  }
537 
538  tempTrack.addStub(A->TP());
539  ps.push_back(A->Phi());
540  ts.push_back(A->Theta());
541 
542  sector = A->SectorIndex();
543 
544  switch(station){
545  case 1: mode_uncorr |= 8;break;
546  case 2: mode_uncorr |= 4;break;
547  case 3: mode_uncorr |= 2;break;
548  case 4: mode_uncorr |= 1;break;
549  default: mode_uncorr |= 0;
550  }
551 
552 
553  // if(A->TP().detId<CSCDetId>().station() == 1 && A->TP().detId<CSCDetId>().ring() == 3)
554  // ME13 = true;
555 
556  if(station == 1 && id > 3 && id < 7){
557 
558  int sub = 2;
559  if(A->TP().detId<CSCDetId>().chamber()%6 > 2)
560  sub = 1;
561 
562  me1address = id;
563  me1address -= 3;
564  me1address += 3*(sub - 1);
565  me1address = id<<1;//
566  me1address |= trknm-1;
567 
568  }
569 
570  if(station == 2 && id > 3){
571 
572  me2address = id;
573  me2address -= 3;
574  me2address = me2address<<1;
575  me2address |= trknm-1;
576 
577  }
578 
579  }
580 
581  }
582 
583  // if ( ( mode == 15 && (cHits_in_station[0] != 1 || cHits_in_station[1] != 1 || cHits_in_station[2] != 1 || cHits_in_station[3] != 1) ) ||
584  // ( mode == 14 && (cHits_in_station[0] != 1 || cHits_in_station[1] != 1 || cHits_in_station[2] != 1 || cHits_in_station[3] != 0) ) ||
585  // ( mode == 13 && (cHits_in_station[0] != 1 || cHits_in_station[1] != 1 || cHits_in_station[2] != 0 || cHits_in_station[3] != 1) ) ||
586  // ( mode == 11 && (cHits_in_station[0] != 1 || cHits_in_station[1] != 0 || cHits_in_station[2] != 1 || cHits_in_station[3] != 1) ) ||
587  // ( mode == 7 && (cHits_in_station[0] != 0 || cHits_in_station[1] != 1 || cHits_in_station[2] != 1 || cHits_in_station[3] != 1) ) )
588  // std::cout << "Mode " << mode << " track has " << cHits_in_station[0] << " / " << cHits_in_station[1] << " / "
589  // << cHits_in_station[2] << " / " << cHits_in_station[3] << " converted hits in stations 1 / 2 / 3 / 4" << std::endl;
590 
591  if ( ( mode == 15 && (eHits_in_station[0] != 1 || eHits_in_station[1] != 1 || eHits_in_station[2] != 1 || eHits_in_station[3] != 1) ) ||
592  ( mode == 14 && (eHits_in_station[0] != 1 || eHits_in_station[1] != 1 || eHits_in_station[2] != 1 || eHits_in_station[3] != 0) ) ||
593  ( mode == 13 && (eHits_in_station[0] != 1 || eHits_in_station[1] != 1 || eHits_in_station[2] != 0 || eHits_in_station[3] != 1) ) ||
594  ( mode == 11 && (eHits_in_station[0] != 1 || eHits_in_station[1] != 0 || eHits_in_station[2] != 1 || eHits_in_station[3] != 1) ) ||
595  ( mode == 7 && (eHits_in_station[0] != 0 || eHits_in_station[1] != 1 || eHits_in_station[2] != 1 || eHits_in_station[3] != 1) ) )
596  LogTrace("L1TMuonEndCapTrackProducer") << "Mode " << mode << " track has " << eHits_in_station[0] << " / " << eHits_in_station[1] << " / "
597  << eHits_in_station[2] << " / " << eHits_in_station[3] << " EMTF hits in stations 1 / 2 / 3 / 4" << std::endl;
598 
599  tempTrack.phis = ps;
600  tempTrack.thetas = ts;
601  tempTrack.deltas = AllTracks[fbest].deltas;
602 
603  // // Before Mulhearn cleanup, May 11
604  // unsigned long xmlpt_address = 0;
605  // float xmlpt = CalculatePt(tempTrack, es, mode, &xmlpt_address);
606 
607  // After Mulhearn cleanup, May 11
608  unsigned long xmlpt_address = ptAssignment_.calculateAddress(tempTrack, es, mode);
609  float xmlpt = ptAssignment_.calculatePt(xmlpt_address);
610 
611  tempTrack.pt = xmlpt*1.4;
612  //FoundTracks->push_back(tempTrack);
613 
614  CombAddress = (me2address<<4) | me1address;
615 
616  int charge = getCharge(phis[0],phis[1],phis[2],phis[3],mode);
617 
618  l1t::RegionalMuonCand outCand = MakeRegionalCand(xmlpt*1.4,AllTracks[fbest].phi,AllTracks[fbest].theta,
619  charge,mode,CombAddress,sector);
620 
621  float theta_angle = l1t::calc_theta_rad_from_int( AllTracks[fbest].theta );
622  float eta = l1t::calc_eta_from_theta_rad( theta_angle );
623 
624  thisTrack.set_phi_loc_deg ( l1t::calc_phi_loc_deg( thisTrack.Phi_loc_int() ) );
625  thisTrack.set_phi_loc_rad ( l1t::calc_phi_loc_rad( thisTrack.Phi_loc_int() ) );
626  thisTrack.set_phi_glob_deg ( l1t::calc_phi_glob_deg( thisTrack.Phi_loc_deg(), thisTrack.Sector() ) );
627  thisTrack.set_phi_glob_rad ( l1t::calc_phi_glob_rad( thisTrack.Phi_loc_rad(), thisTrack.Sector() ) );
628  thisTrack.set_quality ( outCand.hwQual());
629  thisTrack.set_mode ( mode );
630  thisTrack.set_first_bx ( ebx - 6 );
631  thisTrack.set_second_bx ( sebx - 6 );
632  thisTrack.set_bx ( thisTrack.Second_BX() );
633  thisTrack.set_phis ( ps );
634  thisTrack.set_thetas ( ts );
635  thisTrack.set_pt ( xmlpt*1.4 );
636  thisTrack.set_pt_XML ( xmlpt );
637  thisTrack.set_pt_LUT_addr( xmlpt_address );
638  thisTrack.set_charge ( (charge == 1) ? -1 : 1 ); // uGMT uses opposite of physical charge (to match pdgID)
639  thisTrack.set_charge_GMT ( charge );
640  thisTrack.set_theta_rad ( theta_angle );
641  thisTrack.set_theta_deg ( theta_angle * 180/Geom::pi() );
642  thisTrack.set_eta ( eta * thisTrack.Endcap() );
643  thisTrack.set_pt_GMT ( outCand.hwPt() );
644  thisTrack.set_phi_GMT ( outCand.hwPhi() );
645  thisTrack.set_eta_GMT ( outCand.hwEta() );
646 
647  thisTrack.ImportPtLUT ( thisTrack.Mode(), thisTrack.Pt_LUT_addr() );
648 
649  // thisTrack.phi_loc_rad(); // Need to implement - AWB 04.04.16
650  // thisTrack.phi_glob_rad(); // Need to implement - AWB 04.04.16
651 
652  // Use "ebx" for earliest LCT (used through August 24, 2016) - AWB 26.08.16
653  std::pair<int,l1t::RegionalMuonCand> outPair(sebx,outCand);
654 
655  // // Extra debugging output - AWB 29.03.16
656  // std::cout << "Input: eBX = " << ebx << ", seBX = " << sebx << ", pt = " << xmlpt*1.4
657  // << ", phi = " << AllTracks[fbest].phi << ", eta = " << eta
658  // << ", theta = " << AllTracks[fbest].theta << ", sign = " << 1
659  // << ", quality = " << mode << ", trackaddress = " << 1
660  // << ", sector = " << sector << std::endl;
661  // std::cout << "Output: BX = " << sebx << ", hwPt = " << outCand.hwPt() << ", hwPhi = " << outCand.hwPhi()
662  // << ", hwEta = " << outCand.hwEta() << ", hwSign = " << outCand.hwSign()
663  // << ", hwQual = " << outCand.hwQual() << ", link = " << outCand.link()
664  // << ", processor = " << outCand.processor()
665  // << ", trackFinderType = " << outCand.trackFinderType() << std::endl;
666  holder.push_back(outPair);
667  thisTrack.set_isGMT( 1 );
668 
669  OutputTracks->push_back( thisTrack );
670  OutTracks->push_back( thisTrack.CreateEMTFTrack() );
671  }
672  }
673 
674  OutputCands->setBXRange(-2,2);
675 
676  for(int sect=0;sect<12;sect++){
677 
678  for(unsigned int h=0;h<holder.size();h++){
679 
680  int bx = holder[h].first - 6;
681  int sector = holder[h].second.processor();
682  if(holder[h].second.trackFinderType() == 3)
683  sector += 6;
684 
685  if(sector == sect){
686  OutputCands->push_back(bx,holder[h].second);
687  }
688 
689  }
690  }
691 
692  //ev.put(std::move(FoundTracks), "DataITC");
693  ev.put(std::move(OutputCands), "EMTF");
694  ev.put(std::move(OutHits), ""); // EMTFHitCollection
695  ev.put(std::move(OutTracks), ""); // EMTFTrackCollection
696  ev.put(std::move(OutputHits), "CSC"); // EMTFHitExtraCollection
697  ev.put(std::move(OutputHitsRPC), "RPC"); // EMTFHitExtraCollection
698  ev.put(std::move(OutputTracks), ""); // EMTFTrackExtraCollection
699 
700 }//analyzer
701 
703 {
704 }
706 {
707 }
void set_mode(int bits)
Definition: EMTFTrack.h:52
std::vector< EMTFHitExtra > EMTFHitExtraCollection
Definition: EMTFHitExtra.h:112
void set_pt_GMT(int bits)
Definition: EMTFTrack.h:57
int chamber() const
Definition: CSCDetId.h:68
T getParameter(std::string const &) const
unsigned long long cacheIdentifier() const
Divides< B, C > D2
Definition: Factorize.h:145
void set_neighbor(int bits)
Definition: EMTFHit.h:73
T getUntrackedParameter(std::string const &, T const &) const
void set_phi_GMT(int bits)
Definition: EMTFTrack.h:65
int i
Definition: DBlmapReader.cc:9
float Phi_loc_rad() const
Definition: EMTFTrack.h:112
int Sector_index() const
Definition: EMTFHit.h:95
void set_bx(int bits)
Definition: EMTFTrack.h:55
void SetCSCLCTDigi(CSCCorrelatedLCTDigi digi)
Definition: EMTFHit.h:51
void set_quality(int bits)
Definition: EMTFTrack.h:54
void set_phi_loc_int(int bits)
Definition: EMTFTrack.h:62
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
void set_straightness(int bits)
int Strip() const
Definition: EMTFHit.h:104
void set_sector(int bits)
Definition: EMTFTrack.h:49
int Endcap() const
Definition: EMTFTrack.h:96
edm::ESHandle< RPCGeometry > _geom_rpc
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
float calc_phi_glob_rad_hit(float loc, int sect_ind)
Definition: EMTFHitTools.h:22
float Phi_loc_deg() const
Definition: EMTFTrack.h:111
void push_HitExtra(EMTFHitExtra bits)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
float calc_phi_loc_rad(int bits)
float calc_theta_deg_from_int(int _theta_int)
Definition: EMTFHitTools.h:16
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void set_charge_GMT(int bits)
Definition: EMTFTrack.h:69
void set_charge(int bits)
Definition: EMTFTrack.h:68
int Sector() const
Definition: EMTFTrack.h:97
DeltaOutArr3 CalcDeltas_Hold(const std::vector< MatchingOutput > &Mout)
Definition: Deltas.h:225
Geom::Theta< T > theta() const
void setType(unsigned type)
bool ev
int All_neighbor() const
Definition: EMTFTrack.h:141
void set_first_bx(int bits)
std::vector< int > thetas
void set_pt_LUT_addr(unsigned long bits)
Definition: EMTFTrack.h:58
void set_ring(int bits)
Definition: EMTFHit.h:65
int Second_BX() const
int Chamber() const
Definition: EMTFHit.h:97
int calc_sector_GMT(int _sector)
std::vector< PatternOutput > Patterns(std::vector< ZonesOutput > Zones)
int endcap() const
Definition: CSCDetId.h:93
U second(std::pair< T, U > const &p)
const int hwQual() const
Get quality code.
void set_pt(float val)
Definition: EMTFTrack.h:56
int calc_sector_from_index(int index)
int Sector() const
Definition: EMTFHit.h:94
unsigned long long _geom_cache_id
void addStub(const TriggerPrimitive &stub)
EMTFHitExtra Clone()
Definition: EMTFHitExtra.h:31
std::vector< SortingOutput > SortSect_Hold(std::vector< PatternOutput > Pout)
Definition: SortSector.h:139
void ImportPtLUT(int _mode, unsigned long _address)
void push_HitExtraIndex(uint bits)
CSCCorrelatedLCTDigi CreateCSCCorrelatedLCTDigi()
Definition: EMTFHitTools.cc:98
float calc_phi_loc_deg(int bits)
int Phi_loc_int() const
Definition: EMTFTrack.h:110
float calc_eta_from_theta_rad(float _theta_rad)
Definition: EMTFHitTools.h:18
Divides< A, C > D1
Definition: Factorize.h:144
void set_theta_deg(float val)
void get(HolderT &iHolder) const
void set_wire(int bits)
Definition: EMTFHit.h:75
void set_sector_index(int bits)
Definition: EMTFTrack.h:51
void set_all_neighbor(int bits)
Definition: EMTFTrack.h:93
void produce(edm::Event &, const edm::EventSetup &)
l1t::RegionalMuonCand MakeRegionalCand(float pt, int phi, int theta, int sign, int mode, int trackaddress, int sector)
int j
Definition: DBlmapReader.cc:9
std::vector< std::vector< int > > deltas
const int hwEta() const
Get compressed eta (returned int * 0.010875 = eta)
int Ring() const
Definition: EMTFHit.h:93
void set_isGMT(int bits)
void set_thetas(std::vector< int > _thetas)
void set_rank(int bits)
const int hwPhi() const
Get compressed local phi (returned int * 2*pi/576 = local phi in rad)
int getCharge(int phi1, int phi2, int phi3, int phi4, int mode)
void set_theta_int(int bits)
#define LogTrace(id)
int getBX() const
return BX
float calc_theta_rad_from_int(int _theta_int)
Definition: EMTFHitTools.h:17
std::vector< MatchingOutput > PhiMatching_Hold(std::vector< SortingOutput > Sout)
Definition: Matching.h:173
void set_phi_glob_rad(float val)
Definition: EMTFTrack.h:67
void set_eta_GMT(int bits)
Definition: EMTFTrack.h:60
std::vector< int > phis
void ImportCSCDetId(const CSCDetId &_detId)
Definition: EMTFHitTools.cc:21
void set_eta(float val)
Definition: EMTFTrack.h:59
int ring() const
Definition: CSCDetId.h:75
void set_has_neighbor(int bits)
Definition: EMTFTrack.h:92
int Station() const
Definition: EMTFHit.h:92
unsigned long Pt_LUT_addr() const
Definition: EMTFTrack.h:106
void setBX(unsigned int b)
set bx
void set_theta_rad(float val)
float calc_phi_glob_rad(float loc, int sect)
const T & get() const
Definition: EventSetup.h:56
int triggerSector() const
Definition: CSCDetId.cc:3
void set_endcap(int bits)
Definition: EMTFTrack.h:48
float calc_phi_glob_deg_hit(float loc, int sect_ind)
Definition: EMTFHitTools.h:19
void set_pt_XML(float val)
void set_phi_loc_rad(float val)
Definition: EMTFTrack.h:64
int Has_neighbor() const
Definition: EMTFTrack.h:140
const int hwPt() const
Get compressed pT (returned int * 0.5 = pT (GeV))
std::vector< std::vector< BTrack > > BestTracks_Hold(DeltaOutArr3 Dout)
Definition: BestTracks.h:202
int Mode() const
Definition: EMTFTrack.h:100
#define NUM_SECTORS
void set_sector_GMT(int bits)
Definition: EMTFTrack.h:50
EMTFTrack CreateEMTFTrack()
int Endcap() const
Definition: EMTFHit.h:91
int station() const
Definition: CSCDetId.h:86
void ImportCSCCorrelatedLCTDigi(const CSCCorrelatedLCTDigi &_digi)
Definition: EMTFHitTools.cc:91
int phi
TEMPORARY ADDITION by G. Brown ///.
std::vector< std::vector< ConvertedHit > > GroupBX(std::vector< ConvertedHit > ConvHits)
Definition: BXAnalyzer.h:17
float calc_phi_glob_deg(float loc, int sect)
constexpr double pi()
Definition: Pi.h:31
void set_phi_loc_deg(float val)
Definition: EMTFTrack.h:63
void set_second_bx(int bits)
std::vector< ZonesOutput > Zones(std::vector< std::vector< ConvertedHit >> Hits)
Definition: ZoneCreation.h:37
Int_t triggerSector(Int_t station, Int_t ring, Int_t chamber) const
void set_phis(std::vector< int > _phis)
int Neighbor() const
Definition: EMTFHit.h:101
void set_phi_glob_deg(float val)
Definition: EMTFTrack.h:66
def move(src, dest)
Definition: eostools.py:510