test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Deltas.h
Go to the documentation of this file.
1 
9 
10 DeltaOutput Deltas(MatchingOutput Mout, int zone, int winner){
11 
12  //bool verbose = false;
13 
14  PhOutput phmatch = Mout.PhiMatch();
15  ThOutput thmatch = Mout.ThetaMatch();
16  // ThOutput2 t2 = Mout.TMatch2(); // Unused ... also we later declare an "unsigned int t2" - confusing! - AWB 29.08.16
17 
21  int dphi[6] = {-999,-999,-999,-999,-999,-999};
22  int dtmp2[6] = {-999,-999,-999,-999,-999,-999};
23  int dtmp2_ths[6][2] = {{-999,-999},{-999,-999},{-999,-999},{-999,-999},{-999,-999},{-999,-999}};
24 
25 
26  for(int s1=0;s1<3;s1++){
27 
28  for(int s2=s1+1;s2<4;s2++){
29 
33 
34  if((s1 == 0) && (phmatch.x[zone][winner][s1].Phi() != -999) && (phmatch.x[zone][winner][s2].Phi() != -999)){ //if using station one and both hits are valid
35 
36  dphi[s2-1] = phmatch.x[zone][winner][s1].Phi() - phmatch.x[zone][winner][s2].Phi();
37  }
38  else if((s1 != 0) && (phmatch.x[zone][winner][s1].Phi() != -999) && (phmatch.x[zone][winner][s2].Phi() != -999)){//if not using station one and both hits are valid
39 
40  dphi[s1+s2] = phmatch.x[zone][winner][s1].Phi() - phmatch.x[zone][winner][s2].Phi();
41  }
42 
43 
47 
48  for(unsigned int t1=0;t1<phmatch.x[zone][winner][s1].AllThetas().size();t1++){
49  for(unsigned int t2=0;t2<phmatch.x[zone][winner][s2].AllThetas().size();t2++){
50 
51  int dth_tmp = phmatch.x[zone][winner][s2].AllThetas()[t2] - phmatch.x[zone][winner][s1].AllThetas()[t1];
52 
53  if(s1 == 0){
54 
55  if(dtmp2[s2-1] == -999){
56  dtmp2[s2-1] = dth_tmp;
57  dtmp2_ths[s2-1][0] = phmatch.x[zone][winner][s1].AllThetas()[t1];
58  dtmp2_ths[s2-1][1] = phmatch.x[zone][winner][s2].AllThetas()[t2];
59  }
60  else if(abs(dth_tmp) < abs(dtmp2[s2-1])){
61  dtmp2[s2-1] = dth_tmp;
62  dtmp2_ths[s2-1][0] = phmatch.x[zone][winner][s1].AllThetas()[t1];
63  dtmp2_ths[s2-1][1] = phmatch.x[zone][winner][s2].AllThetas()[t2];
64  }
65 
66  }
67  else{
68 
69  if(dtmp2[s2+s1] == -999){
70  dtmp2[s2+s1] = dth_tmp;
71  dtmp2_ths[s1+s2][0] = phmatch.x[zone][winner][s1].AllThetas()[t1];
72  dtmp2_ths[s2+s1][1] = phmatch.x[zone][winner][s2].AllThetas()[t2];
73  }
74  else if(abs(dth_tmp) < abs(dtmp2[s2+s1])){
75  dtmp2[s2+s1] = dth_tmp;
76  dtmp2_ths[s1+s2][0] = phmatch.x[zone][winner][s1].AllThetas()[t1];
77  dtmp2_ths[s2+s1][1] = phmatch.x[zone][winner][s2].AllThetas()[t2];
78  }
79  }
80 
81  }
82  }
83 
84  }
85  }
86 
87  int vmask[3] = {0,0,0};
88  const unsigned int mask[6] = {0x3,0x5,0x9,0x6,0xa,0xc};
101  const unsigned int mindex[6] = {0,0,0,1,1,2};//vmasindex-->says that the first three entries of mask belong to vmask[0] etc...
102 
103  for(int p=0;p<6;p++){
104 
105  if((abs(dtmp2[p]) <= 4) && (dtmp2[p] != -999)){//if dtheta is small enought and valid
106  vmask[mindex[p]] |= mask[p];
107  }
108  }
109 
110  unsigned int vstat = vmask[0];
111 
112  if( !vstat || (vstat & vmask[1])){vstat |= vmask[1];}
113  if( !vstat || (vstat & vmask[2])){vstat |= vmask[2];}
114 
115  //if(vstat ){std::cout<<"vstat = "<<vstat<<std::endl;}//
116  /*
117  //const unsigned int vstatindex[11] = {0xc,0xa,0x6,0xe,0x9,0x5,0xd,0x3,0xb,0x7,0xf};
135  //const unsigned int viindex[2][11] = {{5,4,3,3,2,1,1,0,0,0,0},{5,4,3,5,2,1,5,0,4,3,3}};///index on which entry of vstatindex[11] to choose for both dphi and dtheta
136  */
137 
138  std::vector<int> d (6,-999);
139  std::vector<std::vector<int>> deltas (2,d);//deltas[0]->dPhi & deltas[1]->dTheta
140 
141  for(int i=0;i<6;i++){
142 
143  deltas[0][i] = dphi[i];
144  deltas[1][i] = dtmp2[i];
145  }
146 
148  int phi = 0, theta = 0;//, id = 0;
149  if(vstat & 2){//ME2 Present
150 
151  //phi is simple, we have only one per station to choose from
152  phi = phmatch.x[zone][winner][1].Phi();
153 
154  //for theta, select delta to best station, use dtmpi as index
155  if(dtmp2[0] != -999){
156  theta = dtmp2_ths[0][1];//t2[zone][winner][1][id];
157  }
158  else if(dtmp2[3] != -999){
159  theta = dtmp2_ths[3][0];//t2[zone][winner][1][id];
160  }
161  else if(dtmp2[4] != -999){
162  theta = dtmp2_ths[4][0];//t2[zone][winner][1][id];
163  }
164 
165  }
166  else if(vstat & 4){//ME3 Present, but not ME2
167 
168  phi = phmatch.x[zone][winner][2].Phi();
169  if(dtmp2[1] != -999){
170  theta = dtmp2_ths[1][1];//t2[zone][winner][2][id];
171  }
172  else if(dtmp2[5] != -999){
173  theta = dtmp2_ths[5][0];//t2[zone][winner][2][id];
174  }
175  }
176  else if(vstat & 8){//ME4 Present but not ME2 or ME3
177  phi = phmatch.x[zone][winner][3].Phi();
178  if(dtmp2[2] != -999){
179  theta = dtmp2_ths[2][1];//t2[zone][winner][3][id];
180  }
181  }
182 
184 
185  int rank = (Mout.Winners()[zone][winner].Rank()<<1);
186 
187  //if(rank) std::cout<<"rank = "<<rank<<"\n";
189  if(vstat & 8){rank |= 1;}else{rank &= 0x7e;}//if station 4 add to rank, else keep everythign and zero the bit which indicates station 4 is present
190  if(vstat & 4){rank |= 2;}else{rank &= 0x7d;}//if station 3 add to rank, else keep everythign and zero the bit which indicates station 3 is present
191  if(vstat & 2){rank |= 8;}else{rank &= 0x77;}//if station 2 add to rank, else keep everythign and zero the bit which indicates station 2 is present
192  if(vstat & 1){rank |= 32;}else{rank &= 0x5f;}//if station 1 add to rank, else keep everythign and zero the bit which indicates station 1 is present
193  if(vstat == 0 || vstat == 1 || vstat == 2 || vstat == 4 || vstat == 8){rank = 0;}//removes single, and ME3--ME4 hit combinations
195  Mout.SetPhOut(phmatch);
196  Winner win = Mout.Winners()[zone][winner];
197  win.SetRank(rank);
198 
199  output.SetValues(Mout,deltas,phi,theta,win);
200 
201  return output;
202 
203 }
204 
205 std::vector<std::vector<DeltaOutput>> CalcDeltas(MatchingOutput Mout){
206 
207  DeltaOutput output;output.SetNull();
208 
209  std::vector<DeltaOutput> o (3,output);
210  std::vector<std::vector<DeltaOutput>> out (4,o);
211 
212  for(int zone=0;zone<4;zone++){
213  for(int winner=0;winner<3;winner++){
214  out[zone][winner] = Deltas(Mout, zone, winner);
215  }
216  }
217 
218  return out;
219 }
220 
221 DeltaOutArr3 CalcDeltas_Hold(const std::vector<MatchingOutput> & Mout){
222 
224  output.SetNull();
225  DeltaOutArr3 Output = { {{{output}}} };
226 
227  for(int bx=0;bx<3;bx++){
228  for(int zone=0;zone<4;zone++){
229  for(int winner=0;winner<3;winner++){
230  Output.x[bx][zone][winner] = Deltas(Mout[bx], zone, winner);
231  }
232  }
233  }
234 
235  return Output;
236 
237 }
int i
Definition: DBlmapReader.cc:9
DeltaOutput Deltas(MatchingOutput Mout, int zone, int winner)
Definition: Deltas.h:10
void SetPhOut(PhOutput ph_output)
ThOutput ThetaMatch()
std::vector< std::vector< Winner > > Winners()
ConvertedHit x[4][3][4]
DeltaOutArr3 CalcDeltas_Hold(const std::vector< MatchingOutput > &Mout)
Definition: Deltas.h:221
Geom::Theta< T > theta() const
DeltaOutput x[3][4][3]
Definition: deltas.h:18
tuple s2
Definition: indexGen.py:106
tuple d
Definition: ztail.py:151
auto const T2 &decltype(t1.eta()) t2
Definition: deltaR.h:16
void SetRank(int rank)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::vector< int > AllThetas()
void SetValues(MatchingOutput Mout, std::vector< std::vector< int >> Deltas, int Phi, int Theta, Winner winner)
Geom::Phi< T > phi() const
#define Output(cl)
Definition: vmac.h:192
PhOutput PhiMatch()
std::vector< std::vector< DeltaOutput > > CalcDeltas(MatchingOutput Mout)
Definition: Deltas.h:205