CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PrimitiveConverter.cc
Go to the documentation of this file.
1 
7 #include <cassert>
8 #include <iostream>
9 #include <fstream>
10 
12 
16 
19 
21 
22 using namespace std;
23 
24 int ph_offsets[6][9] = { {39, 57, 76, 39, 58, 76, 41, 60, 79},
25  {95, 114, 132, 95, 114, 133, 98, 116, 135},
26  {38, 76, 113, 39, 58, 76, 95, 114, 132},
27  {38, 76, 113, 39, 58, 76, 95, 114, 132},
28  {38, 76, 113, 38, 57, 76, 95, 113, 132},
29  {21, 21, 23, 1, 21, 1, 21, 1, 20} };
30 
31 bool neighbor(int endcap,int sector,int SectIndex,int id,int sub,int station){
32 
33  bool neighbor = false;
34 
35  int CompIndex = (endcap - 1)*6 + sector - 1;
36  bool AdSector = false;
37  if((SectIndex == 0 && CompIndex == 5) ||
38  (SectIndex == 1 && CompIndex == 0) ||
39  (SectIndex == 2 && CompIndex == 1) ||
40  (SectIndex == 3 && CompIndex == 2) ||
41  (SectIndex == 4 && CompIndex == 3) ||
42  (SectIndex == 5 && CompIndex == 4) ||
43  (SectIndex == 6 && CompIndex == 11) ||
44  (SectIndex == 7 && CompIndex == 6) ||
45  (SectIndex == 8 && CompIndex == 7) ||
46  (SectIndex == 9 && CompIndex == 8) ||
47  (SectIndex == 10 && CompIndex == 9) ||
48  (SectIndex == 11 && CompIndex == 10) ){AdSector = true;}
49 
50  if(AdSector && sub == 2 && station == 1 && (id == 3 || id == 6 || id == 9) )
51  neighbor = true;
52 
53  if(AdSector && station > 1 && (id == 3 || id == 9) )
54  neighbor = true;
55 
56  return neighbor;
57 }
58 
59 template <typename T>
60 static void read_buf(const char * name, T * buf, unsigned size){
61  ifstream input(edm::FileInPath(name).fullPath().c_str());
62  for (unsigned i=0; i<size; i++){
63  input >> buf[i];
64  }
65 }
66 
67 
69  read_buf("L1Trigger/L1TMuon/data/emtf_luts/ph_lut_v1/ph_disp_neighbor.txt", &Ph_Disp_Neighbor_[0][0], 12*61);
70  read_buf("L1Trigger/L1TMuon/data/emtf_luts/ph_lut_v1/ph_init_neighbor.txt", &Ph_Init_Neighbor_[0][0][0], 12*5*16);
71  read_buf("L1Trigger/L1TMuon/data/emtf_luts/ph_lut_v1/th_corr_neighbor.txt", &Th_Corr_Neighbor_[0][0][0][0], 2*12*4*96);
72  read_buf("L1Trigger/L1TMuon/data/emtf_luts/ph_lut_v1/th_init_neighbor.txt", &Th_Init_Neighbor_[0][0], 12*61);
73  read_buf("L1Trigger/L1TMuon/data/emtf_luts/ph_lut_v1/th_lut_st1_neighbor.txt", &Th_LUT_St1_Neighbor_[0][0][0][0], 2*12*16*64);
74  read_buf("L1Trigger/L1TMuon/data/emtf_luts/ph_lut_v1/th_lut_st234_neighbor.txt", &Th_LUT_St234_Neighbor_[0][0][0][0], 3*12*11*112);
75 }
76 
77 std::vector<ConvertedHit> PrimitiveConverter::convert(std::vector<L1TMuon::TriggerPrimitive> TriggPrim, int SectIndex){
78 
79  //bool verbose = false;
80 
81  std::vector<ConvertedHit> ConvHits;
82  for(std::vector<L1TMuon::TriggerPrimitive>::iterator C1 = TriggPrim.begin();C1 != TriggPrim.end();C1++){
83 
88  CSCDetId Det = C3.detId<CSCDetId>();
89 
90  int station = Det.station(), chamber = Det.chamber(), ring = Det.ring(), wire = C3.getCSCData().keywire;
91  int sector = Det.triggerSector(), strip = C3.getCSCData().strip, pattern = C3.getPattern(), Id = C3.Id();
92  int quality = C3.getCSCData().quality, BX = C3.getCSCData().bx, endcap = Det.endcap();
93 
94  if (station == 1 && ring == 1 && strip > 127) ring = 4;
95  int sub = 0;
96 
101 
102  if (station == 1)//is this correct? I know it starts from 1 so not quite what I intended I think.
103  {
104  if(chamber%6 > 2)
105  sub = 1;
106  else
107  sub = 2;
108  }
109 
110  bool IsNeighbor = neighbor(endcap,sector,SectIndex,Id,sub,station);
111 
112  if(ring == 4){Id += 9;}
113 
114  if( (SectIndex == (endcap - 1)*6 + sector - 1 ) || IsNeighbor ) {
115 
119 
120  int ph_tmp = -999, th_tmp = -999;
121  int clctpatcor = -999, clctpatsign = -999;
122  int eightstrip = -999;
123 
124  int factor = (station == 1 && ring == 4) ? 1707://ME1/1a1707?
125  (station == 1 && ring == 3) ? 947: //ME1/3//changed Id > 6 to ring == 3.
126  (station == 1 && ring == 1) ? 1301://ME1/1b
127  1024;//all other chambers
128 
129  bool ph_reverse = (endcap == 1 && station >= 3) ? 1:
130  (endcap == 2 && station < 3) ? 1: 0;
131 
132  int ph_coverage = (station <= 1 && Id > 6 && Id < 10) ? 15 : //30 :
133  (station >= 2 && Id <= 3) ? 40 : 20; //80 : 40;
134 
135  int th_coverage = (station == 1 && Id <= 3) ? 45 :
136  (station == 1 && Id > 6 && Id < 10) ? 27 :
137  (station == 1 && Id > 3) ? 39 :
138  (station == 2 && Id <= 3) ? 43 :
139  (station == 2 && Id > 3) ? 56 :
140  (station == 3 && Id <= 3) ? 34 :
141  (station == 3 && Id > 3) ? 52 :
142  (station == 4 && Id <= 3) ? 28 :
143  (station == 4 && Id > 3) ? 50 : 0;
144 
145  int ph_zone_bnd1 = (station <= 1 && (Id <= 3 || Id > 9)) ? 41 :
146  (station == 2 && Id <= 3) ? 41 :
147  (station == 2 && Id > 3) ? 87 :
148  (station == 3 && Id > 3) ? 49 :
149  (station == 4 && Id > 3) ? 49 : 127;
150 
151  int ph_zone_bnd2 = (station == 3 && Id > 3) ? 87 : 127;
152 
153  int zone_overlap = 2;
154 
155  int fph = -999, th = -999, ph_hit = -999, phzvl = -999;// th_hit = -999, ////
156 
160 
161  int LUTi = -999;
162  int nId = Id;
163  if(IsNeighbor){
164 
165  if(station < 2){
166  nId = 12 + Id/3;
167  }
168  else{
169  int xx = Id;
170  if(xx > 6) xx = 6;
171  nId = 9 + xx/3;
172  }
173  }
174  switch(station)
175  {
176  case 1:
177  switch(sub)
178  {
179  case 1: LUTi = nId - 1;break;
180  case 2: LUTi = 15 + nId;break;
181  default:;//std::cout<<"Sub is out of range"<<std::endl;
182  }
183  break;
184  case 2: LUTi = 27 + nId;break;
185  case 3: LUTi = 38 + nId;break;
186  case 4: LUTi = 49 + nId;break;
187  default:;//std::cout<<"station is out of range"<<std::endl;
188  }
189  if(IsNeighbor && station == 1){
190  switch(sub)
191  {
192  case 1: LUTi = 15 + nId;break;
193  case 2: LUTi = nId - 1;break;
194  default:;//std::cout<<"Sub is out of range"<<std::endl;
195  }
196  }
197 
201 
202  clctpatcor = 0;
203  clctpatsign = 0;
204 
205  if(pattern > 0 && pattern < 11){
206  clctpatsign = ((pattern%2) == 0);
207  if(pattern >= 2) {clctpatcor = 5;}
208  if(pattern >= 6) {clctpatcor = 2;}
209  if(pattern == 10) {clctpatcor = 0;clctpatsign = 0;}
210  }
211 
215 
216  eightstrip = 8*strip;
217  int patcor = clctpatcor;
218 
219  if(station == 1 || Id > 3){//10 Degree Chambers
220  eightstrip = (eightstrip>>1);
221  patcor = (patcor>>1);
222  if(ring == 4 && strip > 127) eightstrip -= 512;
223  }
224 
225  if(clctpatsign) patcor = -patcor;
226  eightstrip += patcor;
227 
231 
232  ph_tmp = ((eightstrip*factor)>>10);
233  int phShift = (ph_tmp>>5);
234  int phLow = 0;
235 
236  if(ph_reverse){
237  ph_tmp = -ph_tmp;
238  phShift = -phShift;
239  phLow = ph_coverage;
240  }
241 
242  int phInitIndex = Id;
243 
244  if(station == 1){
245  int neighborId = C3.Id()/3;
246  int subId = sub;
247  if(IsNeighbor ){
248  subId = 1;
249  phInitIndex = 12 + neighborId;
250  if(ring == 4)
251  phInitIndex = 16;//phInitIndex++;
252  }
253  fph = Ph_Init_Neighbor_[SectIndex][subId-1][phInitIndex - 1] + ph_tmp;
254  }
255  else{
256  int neighborId = Id/3;
257  if(neighborId > 2) neighborId = 2;
258 
259  if(IsNeighbor) phInitIndex = 9 + neighborId;
260 
261  fph = Ph_Init_Neighbor_[SectIndex][station][phInitIndex - 1] + ph_tmp;
262  }
263 
264  if (station == 0 || nId == -1 || SectIndex < 0 || SectIndex > 11 || LUTi < 0 || LUTi > 60) {
265  LogDebug("L1TMuonEndCap") << "\n*********************************************************************" << std::endl;
266  LogDebug("L1TMuonEndCap") << "EMTF malformed LCT: BX " << C3.getCSCData().bx << ", endcap " << Det.endcap()
267  << ", station " << Det.station() << ", sector " << Det.triggerSector()
268  << ", ring " << Det.ring() << ", ID " << C3.Id() << ", chamber " << Det.chamber()
269  << ", strip " << C3.getCSCData().strip << ", wire " << C3.getCSCData().keywire
270  << ", pattern " << C3.getPattern() << ", quality " << C3.getCSCData().quality << std::endl;
271  LogDebug("L1TMuonEndCap") << "Produces: station " << station << ", nId " << nId
272  << ", SectIndex " << SectIndex << ", LUTi " << LUTi << std::endl;
273  continue;
274  }
275 
276  ph_hit = phLow + phShift + (Ph_Disp_Neighbor_[SectIndex][LUTi]>>1);
277 
281 
282  int index = -999;
283  int th_corr = -999;
284  int idl = Id;
285 
286  if(station == 1){
287  int neighborId = C3.Id()/3;
288  int subId = sub;
289  if(IsNeighbor){
290  subId = 1;
291  idl = 12 + neighborId;
292  if(ring == 4) idl = 16;
293  }
294  th_tmp = Th_LUT_St1_Neighbor_[subId-1][SectIndex][idl -1][wire];
295  }
296  else{
297  int neighborId = Id/3;
298  if(neighborId > 2) neighborId = 2;
299  if(IsNeighbor) idl = 9 + neighborId;
300  th_tmp = Th_LUT_St234_Neighbor_[station-2][SectIndex][idl-1][wire];
301  }
302 
303  th = th_tmp + Th_Init_Neighbor_[SectIndex][LUTi];
304  int rth = th;
305 
306  if(station == 1 && (ring == 1 || ring == 4) /*&& endcap == 1*/){
307 
308  index = (wire>>4)*32 + (eightstrip>>4);
309 
310  int corrIndex = Id;
311  int subId = sub;
312  if(corrIndex > 3) corrIndex -= 9;
313 
314  if(IsNeighbor && ring == 4){
315  subId = 1;
316  corrIndex++;
317  }
318 
319  th_corr = Th_Corr_Neighbor_[subId-1][SectIndex][corrIndex-1][index];
320 
321  if(ph_reverse) th_corr = -th_corr;
322 
323  th_tmp += th_corr; // add correction to th_tmp
324  if(th_tmp < 0 || wire == 0) th_tmp = 0;
325 
326  if(th_tmp > th_coverage)//this is one change that I'm not sure if it does anything good or not
327  th_tmp = th_coverage;
328 
329  th_tmp &= 0x3f; //keep only lowest 6 bits
330 
331  if (th_tmp <= th_coverage) th = th_tmp + Th_Init_Neighbor_[SectIndex][LUTi];
332  else th = rth; //was -999
333  }
334 
338 
339  if(th != -999){
340  phzvl = 0;
341  if (th <= (ph_zone_bnd1 + zone_overlap)) phzvl |= 1;
342  if (th > (ph_zone_bnd2 - zone_overlap)) phzvl |= 4;
343  if ((th > (ph_zone_bnd1 - zone_overlap)) && (th <= (ph_zone_bnd2 + zone_overlap))) phzvl |= 2;
344  }
345 
351 
352  if(ring == 4){
353  Id -= 9;
354  if(strip < 128) strip += 128;
355  }
356 
357  //determination of zone contribution
358  int zoneword = 0, zhit = -99, zmask[4] = {1,2,4,8};
359  bool zoneConditions[4] {((phzvl & 1) && (Id < 4)),
360  (((phzvl & 2) && (Id < 4) && (station < 3)) || ((phzvl & 1) && (Id > 3) && (station > 2))),
361  (((phzvl & 1) && (Id > 3) && (Id < 7) && (station == 1)) || ((phzvl & 1) && (Id > 3) && (station == 2)) || ((phzvl & 2) && (Id > 3) && (station > 2))),
362  ( ((station == 1) && (Id > 6)) || ((phzvl & 2) && (Id > 3) && (station == 2)) || ((phzvl & 4) && (station == 3) && (Id > 3)) )};
363 
364  for(int z=0;z<4;z++){
365  if(zoneConditions[z]) zoneword |= zmask[z];
366  }
367 
368  int cindex = Id - 1;
369  int sindex = station;
370  if(sub == 1) sindex--;
371 
372  if(IsNeighbor){
373  sindex = 5;
374  if(station == 1) cindex = Id/3 - 1;
375  else cindex = (station - 1)*2 + ((Id > 6) ? 2:1);
376  }
377 
378  zhit = ph_hit + ph_offsets[sindex][cindex];
379 
384 
386 
387  int in = 0;
388  if(IsNeighbor) in = 1;
389 
390  Hit.SetValues(fph,th,ph_hit,phzvl,station,sub,Id,quality,pattern,wire,strip,BX);
391  Hit.AddTheta(th);
392  Hit.SetTP(C3);
393  Hit.SetZhit(zhit);
394  Hit.SetSectorIndex(SectIndex);
395  Hit.SetNeighbor(in);
396  Hit.SetZoneWord(zoneword);
397 
398  if(Hit.Theta() != -999 && Hit.Phi() > 0 ){//if theta is valid
399  ConvHits.push_back(Hit);
400  }
401  else {
402  LogDebug("L1TMuonEndCap") << "\n#####################################################################" << std::endl;
403  LogDebug("L1TMuonEndCap") << "LCT w/o theta/phi: BX " << C3.getCSCData().bx << ", endcap " << Det.endcap()
404  << ", station " << Det.station() << ", sector " << Det.triggerSector()
405  << ", ring " << Det.ring() << ", ID " << C3.Id() << ", chamber " << Det.chamber()
406  << ", strip " << C3.getCSCData().strip << ", wire " << C3.getCSCData().keywire
407  << ", pattern " << C3.getPattern() << ", quality " << C3.getCSCData().quality << std::endl;
408  LogDebug("L1TMuonEndCap") << "Has fph " << fph << ", th " << th << ", ph_hit " << ph_hit
409  << ", phzvl " << phzvl << ", station " << station << ", sub " << sub
410  << ", Id " << Id << ", quality " << quality << ", pattern " << pattern
411  << ", wire " << wire << ", strip " << strip << ", BX " << BX << std::endl;
412  }
413 
414  } //if sector == sectIndex
415  }
416  return ConvHits;
417 }
#define LogDebug(id)
int chamber() const
Definition: CSCDetId.h:68
int i
Definition: DBlmapReader.cc:9
static void read_buf(const char *name, T *buf, unsigned size)
void SetNeighbor(int neighbor)
void SetZoneWord(int zword)
bool neighbor(int endcap, int sector, int SectIndex, int id, int sub, int station)
const CSCData getCSCData() const
static std::string const input
Definition: EdmProvDump.cc:44
int endcap() const
Definition: CSCDetId.h:93
void SetTP(L1TMuon::TriggerPrimitive tp)
std::vector< ConvertedHit > convert(std::vector< L1TMuon::TriggerPrimitive > TriggPrim, int SectIndex)
SeedingHitSet::ConstRecHitPointer Hit
int ring() const
Definition: CSCDetId.h:75
int triggerSector() const
Definition: CSCDetId.cc:3
void AddTheta(int theta)
void SetZhit(int zhit)
void SetValues(int phi, int theta, int ph_hit, int phzvl, int station, int sub, int id, int quality, int pattern, int wire, int strip, int BX)
int station() const
Definition: CSCDetId.h:86
long double T
tuple size
Write out results.
void SetSectorIndex(int sectorIndex)
int ph_offsets[6][9]