CMS 3D CMS Logo

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