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 
34 using namespace L1TMuon;
35 
36 
38 
39  inputTokenCSC = consumes<CSCCorrelatedLCTDigiCollection>(p.getParameter<edm::InputTag>("CSCInput"));
40 
41  produces<l1t::RegionalMuonCandBxCollection >("EMTF");
42 }
43 
44 
46  const edm::EventSetup& es) {
47 
48  //bool verbose = false;
49 
50 
51  //std::cout<<"Start Upgraded Track Finder Producer::::: event = "<<ev.id().event()<<"\n\n";
52 
53  //fprintf (write,"12345\n"); //<-- part of printing text file to send verilog code, not needed if George's package is included
54 
55 
56  //std::auto_ptr<L1TMuon::InternalTrackCollection> FoundTracks (new L1TMuon::InternalTrackCollection);
57  std::auto_ptr<l1t::RegionalMuonCandBxCollection > OutputCands (new l1t::RegionalMuonCandBxCollection);
58 
59  std::vector<BTrack> PTracks[NUM_SECTORS];
60 
61  std::vector<TriggerPrimitive> tester;
62  //std::vector<InternalTrack> FoundTracks;
63 
64 
68 
70  ev.getByToken(inputTokenCSC, MDC);
71  std::vector<TriggerPrimitive> out;
72 
73  auto chamber = MDC->begin();
74  auto chend = MDC->end();
75  for( ; chamber != chend; ++chamber ) {
76  auto digi = (*chamber).second.first;
77  auto dend = (*chamber).second.second;
78  for( ; digi != dend; ++digi ) {
79  out.push_back(TriggerPrimitive((*chamber).first,*digi));
80  }
81  }
82 
83 
87 
88  // auto tpsrc = _tpinputs.cbegin();
89  //auto tpend = _tpinputs.cend();
90  // for( ; tpsrc != tpend; ++tpsrc ) {
91  // edm::Handle<TriggerPrimitiveCollection> tps;
92  // ev.getByLabel(*tpsrc,tps);
93  auto tp = out.cbegin();
94  auto tpend = out.cend();
95 
96  for( ; tp != tpend; ++tp ) {
97  if(tp->subsystem() == 1)
98  {
99  //TriggerPrimitiveRef tpref(out,tp - out.cbegin());
100 
101  tester.push_back(*tp);
102 
103  //if(verbose) std::cout<<"\ntrigger prim found station:"<<tp->detId<CSCDetId>().station()<<std::endl;
104  }
105 
106  }
107  //}
108  std::vector<ConvertedHit> CHits[NUM_SECTORS];
110 
111 for(int SectIndex=0;SectIndex<NUM_SECTORS;SectIndex++){//perform TF on all 12 sectors
112 
113 
114 
118 
119 
120  std::vector<ConvertedHit> ConvHits = PrimConv(tester,SectIndex);
121  CHits[SectIndex] = ConvHits;
122 
123 
126  //for(std::vector<ConvertedHit>::iterator h = ConvHits.begin();h != ConvHits.end();h++){
127 
128  //if((h->Id()) > 9){h->SetId(h->Id() - 9);h->SetStrip(h->Strip() + 128);}
129  //fprintf (write,"0 1 1 %d %d\n",h->Sub(),h->Station());
130  //fprintf (write,"1 %d %d %d\n",h->Quality(),h->Pattern(),h->Wire());
131  //fprintf (write,"%d 0 %d\n",h->Id(),h->Strip());
132  //}
135 
136 
137 
143 
144 
145  std::vector<std::vector<ConvertedHit>> GroupedHits = GroupBX(ConvHits);
146 
147 
151 
152  std::vector<ZonesOutput> Zout = Zones(GroupedHits);
153 
154 
159 
160 
161  std::vector<PatternOutput> Pout = Patterns(Zout);
162 
164 
165  //PrintQuality(Test.detected);
166 
167 
172 
173 
174  SortingOutput Sout = SortSect(Test);
175 
176 
181 
182 
183  MatchingOutput Mout = PhiMatching(Sout);
184  MO[SectIndex] = Mout;
185 
190 
191 
192  std::vector<std::vector<DeltaOutput>> Dout = CalcDeltas(Mout);
193 
194 
199 
200 
201  std::vector<BTrack> Bout = BestTracks(Dout);
202  PTracks[SectIndex] = Bout;
203 
204 
205 
206  }
207 
212 
213 
214  BTrack FourBest[4];//ok
215  std::vector<BTrack> PTemp[NUM_SECTORS];
216  for (int i=0; i<NUM_SECTORS; i++) PTemp[i] = PTracks[i];
217 
218  int windex[4] = {-1,-1,-1,-1};
219 
220 
221 
222  for(int i=0;i<4;i++){
223 
224  for(int j=0;j<36;j++){
225 
226 
227  if(!PTemp[j/3][j%3].phi)//no track
228  continue;
229 
230  if((windex[0] == j) || (windex[1] == j) || (windex[2] == j) || (windex[3] == j))//already picked
231  continue;
232 
233  if(PTracks[j/3][j%3].winner.Rank() > FourBest[i].winner.Rank()){
234 
235  FourBest[i] = PTemp[j/3][j%3];
236  windex[i] = j;
237 
238  }
239 
240  }
241 }
242 
247 
248  for(int fbest=0;fbest<4;fbest++){
249 
250  if(FourBest[fbest].phi){
251 
252 
253  InternalTrack tempTrack;
254  tempTrack.setType(2);
255  tempTrack.phi = FourBest[fbest].phi;
256  tempTrack.theta = FourBest[fbest].theta;
257  tempTrack.rank = FourBest[fbest].winner.Rank();
258  tempTrack.deltas = FourBest[fbest].deltas;
259  std::vector<int> ps, ts;
260 
261 
262  int sector = -1;
263  bool ME13 = false;
264  int me1address = 0, me2address = 0, CombAddress = 0, mode = 0;
265 
266  for(std::vector<ConvertedHit>::iterator A = FourBest[fbest].AHits.begin();A != FourBest[fbest].AHits.end();A++){
267 
268  if(A->Phi() != -999){
269 
270  int station = A->TP().detId<CSCDetId>().station();
271  int id = A->TP().getCSCData().cscID;
272  int trknm = A->TP().getCSCData().trknmb;
273 
274  tempTrack.addStub(A->TP());
275  ps.push_back(A->Phi());
276  ts.push_back(A->Theta());
277  sector = (A->TP().detId<CSCDetId>().endcap() -1)*6 + A->TP().detId<CSCDetId>().triggerSector() - 1;
278  //std::cout<<"Q: "<<A->Quality()<<", keywire: "<<A->Wire()<<", strip: "<<A->Strip()<<std::endl;
279 
280  switch(station){
281  case 1: mode |= 8;break;
282  case 2: mode |= 4;break;
283  case 3: mode |= 2;break;
284  case 4: mode |= 1;break;
285  default: mode |= 0;
286  }
287 
288 
289  if(A->TP().detId<CSCDetId>().station() == 1 && A->TP().detId<CSCDetId>().ring() == 3)
290  ME13 = true;
291 
292  if(station == 1 && id > 3 && id < 7){
293 
294  int sub = 2;
295  if(A->TP().detId<CSCDetId>().chamber()%6 > 2)
296  sub = 1;
297 
298  me1address = id;
299  me1address -= 3;
300  me1address += 3*(sub - 1);
301  me1address = id<<1;//
302  me1address |= trknm-1;
303 
304  }
305 
306  if(station == 2 && id > 3){
307 
308  me2address = id;
309  me2address -= 3;
310  me2address = me2address<<1;
311  me2address |= trknm-1;
312 
313  }
314 
315 
316  }
317 
318  }
319  tempTrack.phis = ps;
320  tempTrack.thetas = ts;
321 
322  float xmlpt = CalculatePt(tempTrack,es);
323  tempTrack.pt = xmlpt*1.4;
324  //FoundTracks->push_back(tempTrack);
325 
326  CombAddress = (me2address<<4) | me1address;
327 
328 
329  l1t::RegionalMuonCand outCand = MakeRegionalCand(xmlpt*1.4,FourBest[fbest].phi,FourBest[fbest].theta,
330  CombAddress,mode,1,sector);
331  // NOTE: assuming that all candidates come from the central BX:
332  int bx = 0;
333  float theta_angle = (FourBest[fbest].theta*0.2851562 + 8.5)*(3.14159265359/180);
334  float eta = (-1)*log(tan(theta_angle/2));
335  if(!ME13 && fabs(eta) > 1.1)
336  OutputCands->push_back(bx, outCand);
337  }
338  }
339 
340 
341 //ev.put( FoundTracks, "DataITC");
342 ev.put( OutputCands, "EMTF");
343  //std::cout<<"End Upgraded Track Finder Prducer:::::::::::::::::::::::::::\n:::::::::::::::::::::::::::::::::::::::::::::::::\n\n";
344 
345 }//analyzer
346 
348 {
349 
350 }
352 {
353 
354 }
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
SortingOutput SortSect(PatternOutput Pout)
Definition: SortSector.h:11
int Rank()
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)
Winner winner
bool ev
MatchingOutput PhiMatching(SortingOutput Sout)
Definition: Matching.h:12
std::vector< int > thetas
std::vector< PatternOutput > Patterns(std::vector< ZonesOutput > Zones)
std::vector< std::vector< int > > deltas
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
std::vector< ConvertedHit > AHits
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
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:42
Int_t triggerSector(Int_t station, Int_t ring, Int_t chamber) const