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 
33 
34 
35 using namespace L1TMuon;
36 
37 
39 
40  inputTokenCSC = consumes<CSCCorrelatedLCTDigiCollection>(p.getParameter<edm::InputTag>("CSCInput"));
41 
42  produces<l1t::RegionalMuonCandBxCollection >("EMTF");
43 }
44 
45 
47  const edm::EventSetup& es) {
48 
49  //bool verbose = false;
50 
51 
52  //std::cout<<"Start Upgraded Track Finder Producer::::: event = "<<ev.id().event()<<"\n\n";
53 
54  //fprintf (write,"12345\n"); //<-- part of printing text file to send verilog code, not needed if George's package is included
55 
56 
57  //std::auto_ptr<L1TMuon::InternalTrackCollection> FoundTracks (new L1TMuon::InternalTrackCollection);
58  std::auto_ptr<l1t::RegionalMuonCandBxCollection > OutputCands (new l1t::RegionalMuonCandBxCollection);
59 
60  std::vector<BTrack> PTracks[NUM_SECTORS];
61 
62  std::vector<TriggerPrimitive> tester;
63  //std::vector<InternalTrack> FoundTracks;
64 
65 
69 
71  ev.getByToken(inputTokenCSC, MDC);
72  std::vector<TriggerPrimitive> out;
73 
74  auto chamber = MDC->begin();
75  auto chend = MDC->end();
76  for( ; chamber != chend; ++chamber ) {
77  auto digi = (*chamber).second.first;
78  auto dend = (*chamber).second.second;
79  for( ; digi != dend; ++digi ) {
80  out.push_back(TriggerPrimitive((*chamber).first,*digi));
81  }
82  }
83 
84 
88 
89  // auto tpsrc = _tpinputs.cbegin();
90  //auto tpend = _tpinputs.cend();
91  // for( ; tpsrc != tpend; ++tpsrc ) {
92  // edm::Handle<TriggerPrimitiveCollection> tps;
93  // ev.getByLabel(*tpsrc,tps);
94  auto tp = out.cbegin();
95  auto tpend = out.cend();
96 
97  for( ; tp != tpend; ++tp ) {
98  if(tp->subsystem() == 1)
99  {
100  //TriggerPrimitiveRef tpref(out,tp - out.cbegin());
101 
102  tester.push_back(*tp);
103 
104  //std::cout<<"\ntrigger prim found station:"<<tp->detId<CSCDetId>().station()<<std::endl;
105  }
106 
107  }
108  //}
109  std::vector<ConvertedHit> CHits[NUM_SECTORS];
111 
112 for(int SectIndex=0;SectIndex<NUM_SECTORS;SectIndex++){//perform TF on all 12 sectors
113 
114 
115 
119 
120 
121  std::vector<ConvertedHit> ConvHits = PrimConv(tester,SectIndex);
122  CHits[SectIndex] = ConvHits;
123 
124 
127  //for(std::vector<ConvertedHit>::iterator h = ConvHits.begin();h != ConvHits.end();h++){
128 
129  //if((h->Id()) > 9){h->SetId(h->Id() - 9);h->SetStrip(h->Strip() + 128);}
130  //fprintf (write,"0 1 1 %d %d\n",h->Sub(),h->Station());
131  //fprintf (write,"1 %d %d %d\n",h->Quality(),h->Pattern(),h->Wire());
132  //fprintf (write,"%d 0 %d\n",h->Id(),h->Strip());
133  //}
136 
137 
138 
144 
145 
146  std::vector<std::vector<ConvertedHit>> GroupedHits = GroupBX(ConvHits);
147 
148 
152 
153  std::vector<ZonesOutput> Zout = Zones(GroupedHits);
154 
155 
160 
161 
162  std::vector<PatternOutput> Pout = Patterns(Zout);
163 
165 
166  //PrintQuality(Test.detected);
167 
168 
173 
174 
175  SortingOutput Sout = SortSect(Test);
176 
177 
182 
183 
184  MatchingOutput Mout = PhiMatching(Sout);
185  MO[SectIndex] = Mout;
186 
191 
192 
193  std::vector<std::vector<DeltaOutput>> Dout = CalcDeltas(Mout);
194 
195 
200 
201 
202  std::vector<BTrack> Bout = BestTracks(Dout);
203  PTracks[SectIndex] = Bout;
204 
205 
206 
207  }
208 
212 
213  std::vector<BTrack> PTemp[NUM_SECTORS];
214  std::vector<BTrack> AllTracks;
215  for (int i=0; i<NUM_SECTORS; i++) PTemp[i] = PTracks[i];
216 
217 
218  for(int j=0;j<36;j++){
219 
220 
221  if(PTemp[j/3][j%3].phi)//no track
222  AllTracks.push_back(PTemp[j/3][j%3]);
223 
224 
225 
226  }
227 
232 
233  std::vector<l1t::RegionalMuonCand> tester1;
234  std::vector<std::pair<int,l1t::RegionalMuonCand>> holder;
235 
236  for(unsigned int fbest=0;fbest<AllTracks.size();fbest++){
237 
238  if(AllTracks[fbest].phi){
239 
240 
241  InternalTrack tempTrack;
242  tempTrack.setType(2);
243  tempTrack.phi = AllTracks[fbest].phi;
244  tempTrack.theta = AllTracks[fbest].theta;
245  tempTrack.rank = AllTracks[fbest].winner.Rank();
246  tempTrack.deltas = AllTracks[fbest].deltas;
247  std::vector<int> ps, ts;
248 
249 
250  int sector = -1;
251  bool ME13 = false;
252  int me1address = 0, me2address = 0, CombAddress = 0, mode = 0;
253  int ebx = 20, sebx = 20;
254  int phis[4] = {-99,-99,-99,-99};
255 
256  for(std::vector<ConvertedHit>::iterator A = AllTracks[fbest].AHits.begin();A != AllTracks[fbest].AHits.end();A++){
257 
258  if(A->Phi() != -999){
259 
260  int station = A->TP().detId<CSCDetId>().station();
261  int id = A->TP().getCSCData().cscID;
262  int trknm = A->TP().getCSCData().trknmb;//A->TP().getCSCData().bx
263 
264  phis[station-1] = A->Phi();
265 
266 
267  if(A->TP().getCSCData().bx < ebx){
268  sebx = ebx;
269  ebx = A->TP().getCSCData().bx;
270  }
271  else if(A->TP().getCSCData().bx < sebx){
272  sebx = A->TP().getCSCData().bx;
273  }
274 
275  tempTrack.addStub(A->TP());
276  ps.push_back(A->Phi());
277  ts.push_back(A->Theta());
278  sector = (A->TP().detId<CSCDetId>().endcap() -1)*6 + A->TP().detId<CSCDetId>().triggerSector() - 1;
279  //std::cout<<"Q: "<<A->Quality()<<", keywire: "<<A->Wire()<<", strip: "<<A->Strip()<<std::endl;
280 
281  switch(station){
282  case 1: mode |= 8;break;
283  case 2: mode |= 4;break;
284  case 3: mode |= 2;break;
285  case 4: mode |= 1;break;
286  default: mode |= 0;
287  }
288 
289 
290  if(A->TP().detId<CSCDetId>().station() == 1 && A->TP().detId<CSCDetId>().ring() == 3)
291  ME13 = true;
292 
293  if(station == 1 && id > 3 && id < 7){
294 
295  int sub = 2;
296  if(A->TP().detId<CSCDetId>().chamber()%6 > 2)
297  sub = 1;
298 
299  me1address = id;
300  me1address -= 3;
301  me1address += 3*(sub - 1);
302  me1address = id<<1;//
303  me1address |= trknm-1;
304 
305  }
306 
307  if(station == 2 && id > 3){
308 
309  me2address = id;
310  me2address -= 3;
311  me2address = me2address<<1;
312  me2address |= trknm-1;
313 
314  }
315 
316 
317  }
318 
319  }
320  tempTrack.phis = ps;
321  tempTrack.thetas = ts;
322 
323  float xmlpt = CalculatePt(tempTrack,es);
324  tempTrack.pt = xmlpt*1.4;
325  //FoundTracks->push_back(tempTrack);
326 
327  CombAddress = (me2address<<4) | me1address;
328 
329  int charge = getCharge(phis[0],phis[1],phis[2],phis[3],mode);
330 
331  l1t::RegionalMuonCand outCand = MakeRegionalCand(xmlpt*1.4,AllTracks[fbest].phi,AllTracks[fbest].theta,
332  charge,mode,CombAddress,sector);
333  // NOTE: assuming that all candidates come from the central BX:
334  //int bx = 0;
335  float theta_angle = (AllTracks[fbest].theta*0.2851562 + 8.5)*(3.14159265359/180);
336  float eta = (-1)*log(tan(theta_angle/2));
337  std::pair<int,l1t::RegionalMuonCand> outPair(sebx,outCand);
338 
339  if(!ME13 && fabs(eta) > 1.1)
340  holder.push_back(outPair);
341  }
342  }
343 
344 OutputCands->setBXRange(-2,2);
345 
346 for(int sect=0;sect<12;sect++){
347 
348  for(unsigned int h=0;h<holder.size();h++){
349 
350  int bx = holder[h].first - 6;
351  int sector = holder[h].second.processor();
352  if(holder[h].second.trackFinderType() == 3)
353  sector += 6;
354 
355  if(sector == sect){
356  OutputCands->push_back(bx,holder[h].second);
357  }
358 
359  }
360 }
361 
362 
363 //ev.put( FoundTracks, "DataITC");
364 ev.put( OutputCands, "EMTF");
365  //std::cout<<"End Upgraded Track Finder Prducer:::::::::::::::::::::::::::\n:::::::::::::::::::::::::::::::::::::::::::::::::\n\n";
366 
367 }//analyzer
368 
370 {
371 
372 }
374 {
375 
376 }
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
SortingOutput SortSect(PatternOutput Pout)
Definition: SortSector.h:11
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
l1t::RegionalMuonCand MakeRegionalCand(float pt, int phi, int theta, int sign, int quality, int trackaddress, int sector)
Geom::Theta< T > theta() const
void setType(unsigned type)
bool ev
MatchingOutput PhiMatching(SortingOutput Sout)
Definition: Matching.h:12
std::vector< int > thetas
std::vector< PatternOutput > Patterns(std::vector< ZonesOutput > Zones)
U second(std::pair< T, U > const &p)
void addStub(const TriggerPrimitive &stub)
float CalculatePt(L1TMuon::InternalTrack track, const edm::EventSetup &es)
Definition: PtAssignment.h:958
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
void produce(edm::Event &, const edm::EventSetup &)
int j
Definition: DBlmapReader.cc:9
std::vector< std::vector< int > > deltas
int getCharge(int phi1, int phi2, int phi3, int phi4, int mode)
std::vector< int > phis
std::vector< ConvertedHit > PrimConv(std::vector< TriggerPrimitive > TriggPrim, int SectIndex)
Geom::Phi< T > phi() const
std::vector< BTrack > BestTracks(std::vector< std::vector< DeltaOutput >> Dout)
Definition: BestTracks.h:13
#define NUM_SECTORS
std::vector< std::vector< DeltaOutput > > CalcDeltas(MatchingOutput Mout)
Definition: Deltas.h:280
PatternOutput DeleteDuplicatePatterns(std::vector< PatternOutput > Pout)
Definition: BXAnalyzer.h:40
int phi
TEMPORARY ADDITION by G. Brown ///.
std::vector< std::vector< ConvertedHit > > GroupBX(std::vector< ConvertedHit > ConvHits)
Definition: BXAnalyzer.h:14
std::vector< ZonesOutput > Zones(std::vector< std::vector< ConvertedHit >> Hits)
Definition: ZoneCreation.h:39
Int_t triggerSector(Int_t station, Int_t ring, Int_t chamber) const