Class Reference for E1039 Core & Analysis Software
TriggerRoad.cxx
Go to the documentation of this file.
1 #include <iomanip>
2 #include <stdlib.h>
3 #include <algorithm>
4 
5 #include "TriggerRoad.h"
6 #include "geom_svc/GeomSvc.h"
7 
9 
11 {
12  targetWeight = 0.;
13  dumpWeight = 0.;
14  lowMWeight = 0.;
15  highMWeight = 0.;
16 
17  detectorIDs.clear();
18  elementIDs.clear();
19 
20  px_min = 0.;
21  px_max = 0.;
22  px_mean = 0.;
23 
24  rndf = 0.;
25 
26  nPlus = 0;
27  nMinus = 0;
28 
29  enabled = true;
30 }
31 
32 TriggerRoad::TriggerRoad(std::list<int> uniqueIDs)
33 {
34  for(std::list<int>::iterator iter = uniqueIDs.begin(); iter != uniqueIDs.end(); ++iter)
35  {
36  if(*iter < 0) continue;
37 
38  int elementID = *iter % 100;
39  int detectorID = (*iter - elementID)/100;
40 
41  addElement(detectorID, elementID);
42  }
43 }
44 
45 TriggerRoad::TriggerRoad(Tracklet& tracklet) : detectorIDs(4), elementIDs(4)
46 {
47  GeomSvc* p_geomSvc = GeomSvc::instance();
48  const int hodoIDs[2][4] = {{32, 38, 40, 46}, {31, 37, 39, 45}};
49 
50  int tb = 0;
51  for(int i = 0; i < 4; ++i)
52  {
53  tb += (p_geomSvc->isInPlane(hodoIDs[0][i], 0., tracklet.getExpPositionY(p_geomSvc->getPlanePosition(hodoIDs[0][i]))) ? 1 : -1);
54  //std::cout << i << " " << tb << " " << p_geomSvc->getPlanePosition(hodoIDs[0][i]) << " " << tracklet.getExpPositionY(p_geomSvc->getPlanePosition(hodoIDs[0][i])) << std::endl;
55  }
56 
57  if(tb == 0)
58  {
59  detectorIDs.clear();
60  return;
61  }
62 
63  tb = tb > 0 ? 0 : 1;
64  for(int i = 0; i < 4; ++i)
65  {
66  detectorIDs[i] = hodoIDs[tb][i];
67  elementIDs[i] = p_geomSvc->getExpElementID(hodoIDs[tb][i], tracklet.getExpPositionX(p_geomSvc->getPlanePosition(hodoIDs[tb][i])));
68  //std::cout << i << " " << detectorIDs[i] << " " << elementIDs[i] << std::endl;
69  }
70 }
71 
72 TriggerRoad::TriggerRoad(SRecTrack& track) : detectorIDs(4), elementIDs(4)
73 {
74  GeomSvc* p_geomSvc = GeomSvc::instance();
75  const int hodoIDs[2][4] = {{32, 38, 40, 46}, {31, 37, 39, 45}};
76 
77  double x_exp[4], y_exp[4];
78  for(int i = 0; i < 4; ++i)
79  {
80  track.getExpPositionFast(p_geomSvc->getPlanePosition(hodoIDs[0][i]), x_exp[i], y_exp[i]);
81  }
82 
83  int tb = 0;
84  for(int i = 0; i < 4; ++i)
85  {
86  tb += (p_geomSvc->isInPlane(hodoIDs[0][i], 0., y_exp[i]) ? 1 : -1);
87  }
88 
89  if(tb == 0)
90  {
91  detectorIDs.clear();
92  return;
93  }
94 
95  tb = tb > 0 ? 0 : 1;
96  for(int i = 0; i < 4; ++i)
97  {
98  detectorIDs[i] = hodoIDs[tb][i];
99  elementIDs[i] = p_geomSvc->getExpElementID(hodoIDs[tb][i], x_exp[i]);
100  //std::cout << i << " " << detectorIDs[i] << " " << elementIDs[i] << std::endl;
101  }
102 }
103 
105 {
106  if(!enabled) return false;
107  if(detectorIDs.size() != 4) return false;
108  if(getTB() == 0) return false;
109 
110  //Add whatever here
111 
112  return true;
113 }
114 
116 {
117  std::cout << "For this road: " << ratio() << std::endl;
118  for(int i = 0; i < 4; i++)
119  {
120  std::cout << detectorIDs[i] << " " << elementIDs[i] << " : ";
121  }
122  std::cout << std::endl;
123 }
124 
125 std::ostream& operator << (std::ostream& os, const TriggerRoad& road)
126 {
127  //os << std::setw(6) << road.detectorIDs[0] << std::setw(6) << road.detectorIDs[1] << std::setw(6) << road.detectorIDs[2] << std::setw(6) << road.detectorIDs[3]
128  os << std::setw(6) << road.elementIDs[0] << std::setw(6) << road.elementIDs[1] << std::setw(6) << road.elementIDs[2] << std::setw(6) << road.elementIDs[3]
129  << std::setprecision(3) << std::setw(10) << std::setiosflags(std::ios::right) << road.px_mean
130  << std::setprecision(3) << std::setw(10) << std::setiosflags(std::ios::right) << road.getpXWidth()
131  << std::setprecision(3) << std::setw(10) << std::setiosflags(std::ios::right) << road.px_min
132  << std::setprecision(3) << std::setw(10) << std::setiosflags(std::ios::right) << road.px_max
133  << std::setw(6) << std::setiosflags(std::ios::right) << abs(road.groupID)
134  << std::setw(10) << road.getNEntries()
135  << std::setprecision(4) << std::setw(20) << std::setiosflags(std::ios::right) << road.weight()
136  << std::setprecision(4) << std::setw(20) << std::setiosflags(std::ios::right) << road.ratio()
137  //<< std::setprecision(4) << std::setw(20) << std::setiosflags(std::ios::right) << road.nPlus
138  //<< std::setprecision(4) << std::setw(20) << std::setiosflags(std::ios::right) << road.nMinus
139  << std::setprecision(5) << std::setw(20) << std::setiosflags(std::ios::right) << road.rndf;
140 
141  return os;
142 }
143 
145 {
146  roadID = -1;
147  targetWeight = 0.;
148  dumpWeight = 0.;
149 
150  detectorIDs.clear();
151  elementIDs.clear();
152 
153  pXs.clear();
154 
155  enabled = true;
156 }
157 
158 void TriggerRoad::addElement(int detectorID, int elementID)
159 {
160  if(std::find(detectorIDs.begin(), detectorIDs.end(), detectorID) != detectorIDs.end()) return;
161 
162  detectorIDs.push_back(detectorID);
163  elementIDs.push_back(elementID);
164 }
165 
166 bool TriggerRoad::operator==(const TriggerRoad& elem) const
167 {
168  if(detectorIDs.size() != elem.detectorIDs.size()) return false;
169 
170  int nElements = detectorIDs.size();
171  for(int i = 0; i < nElements; i++)
172  {
173  if(detectorIDs[i] != elem.detectorIDs[i]) return false;
174  if(elementIDs[i] != elem.elementIDs[i]) return false;
175  }
176 
177  return true;
178 }
179 
180 bool TriggerRoad::byTargetDump(const TriggerRoad& elem1, const TriggerRoad& elem2)
181 {
182  return elem1.ratio() > elem2.ratio();
183 }
184 
185 bool TriggerRoad::byWeight(const TriggerRoad& elem1, const TriggerRoad& elem2)
186 {
187  return elem1.weight() > elem2.weight();
188 }
189 
190 bool TriggerRoad::byMass(const TriggerRoad& elem1, const TriggerRoad& elem2)
191 {
192  return elem1.mratio() > elem2.mratio();
193 }
194 
195 bool TriggerRoad::byPt(const TriggerRoad& elem1, const TriggerRoad& elem2)
196 {
197  return elem1.px_min > elem2.px_min;
198 }
199 
200 bool TriggerRoad::byRndFrequency(const TriggerRoad& elem1, const TriggerRoad& elem2)
201 {
202  return elem1.rndf > elem2.rndf;
203 }
204 
206 {
207  targetWeight += elem.targetWeight;
208  dumpWeight += elem.dumpWeight;
209  lowMWeight += elem.lowMWeight;
210  highMWeight += elem.highMWeight;
211 
212  px_mean = (px_mean*pXs.size() + elem.px_mean*elem.pXs.size())/(pXs.size() + elem.pXs.size());
213  px_min = px_min < elem.px_min ? px_min : elem.px_min;
214  px_max = px_max > elem.px_max ? px_max : elem.px_max;
215  pXs.insert(pXs.end(), elem.pXs.begin(), elem.pXs.end());
216 
217  nPlus += elem.nPlus;
218  nMinus += elem.nMinus;
219 
220  return *this;
221 }
222 
224 {
225  double sum = 0.;
226  for(unsigned int i = 0; i < pXs.size(); i++)
227  {
228  sum += pXs[i];
229  }
230 
231  return sum/pXs.size();
232 }
233 
235 {
236  if(detectorIDs.size() != 4) return 0;
237 
238  return getTB()*((elementIDs[0]-1)*16*16*16 + (elementIDs[1]-1)*16*16 + (elementIDs[2]-1)*16 + elementIDs[3]);
239 }
240 
242 {
243  double sigma = 0.;
244  for(unsigned int i = 0; i < pXs.size(); i++)
245  {
246  sigma += ((pXs[i] - px_mean)*(pXs[i] - px_mean));
247  }
248 
249  return sqrt(sigma/pXs.size());
250 }
251 
253 {
254  GeomSvc* p_geomSvc = GeomSvc::instance();
255 
256  int LR = 0;
257  for(int i = 1; i < 4; i++)
258  {
259  if(elementIDs[i] < p_geomSvc->getPlaneNElements(detectorIDs[i])/2)
260  {
261  LR += 1;
262  }
263  else
264  {
265  LR += -1;
266  }
267  }
268 
269  int LR1 = 0;
270  LR1 = elementIDs[0] < p_geomSvc->getPlaneNElements(detectorIDs[0])/2 ? 1 : -1;
271 
272  if(LR*LR1 == 3) return 1;
273  if(LR*LR1 == -3) return -1;
274  return 0;
275 }
276 
278 {
279  int TB = 0;
280  for(int i = 0; i < 4; i++)
281  {
282  if((detectorIDs[i] & 1) == 0)
283  {
284  TB += 1;
285  }
286  else
287  {
288  TB += -1;
289  }
290  }
291 
292  if(TB == 4) return 1;
293  if(TB == -4) return -1;
294  return 0;
295 }
296 
298 {
299  TriggerRoad reflected = *this;
300 
301  int corr = getTB();
302  for(int i = 0; i < 4; ++i)
303  {
304  reflected.detectorIDs[i] -= corr;
305  }
306 
307  return reflected;
308 }
309 
311 {
312  GeomSvc* p_geomSvc = GeomSvc::instance();
313  TriggerRoad reflected = *this;
314 
315  for(int i = 0; i < 4; ++i)
316  {
317  int nElements = p_geomSvc->getPlaneNElements(detectorIDs[i]);
318  reflected.elementIDs[i] = nElements - reflected.elementIDs[i] + 1;
319  }
320 
321  return reflected;
322 }
323 
324 std::list<TriggerRoad> TriggerRoad::makeRoadList(int nHits, int dIDs[], int eIDs[], double z, double mass, double pX, double weight)
325 {
326  GeomSvc* p_geomSvc = GeomSvc::instance();
327 
328  std::list<TriggerRoad> roads_new;
329  std::vector<std::pair<int, int> > hodoHits[4];
330  for(int i = 0; i < nHits; i++)
331  {
332  std::string detectorName = p_geomSvc->getDetectorName(dIDs[i]);
333  if(detectorName.find("H1T") != std::string::npos || detectorName.find("H1B") != std::string::npos)
334  {
335  hodoHits[0].push_back(std::make_pair(dIDs[i], eIDs[i]));
336  }
337  else if(detectorName.find("H2T") != std::string::npos || detectorName.find("H2B") != std::string::npos)
338  {
339  hodoHits[1].push_back(std::make_pair(dIDs[i], eIDs[i]));
340  }
341  else if(detectorName.find("H3T") != std::string::npos || detectorName.find("H3B") != std::string::npos)
342  {
343  hodoHits[2].push_back(std::make_pair(dIDs[i], eIDs[i]));
344  }
345  else if(detectorName.find("H4T") != std::string::npos || detectorName.find("H4B") != std::string::npos)
346  {
347  hodoHits[3].push_back(std::make_pair(dIDs[i], eIDs[i]));
348  }
349  }
350 
351  for(std::vector<std::pair<int, int> >::iterator iter = hodoHits[0].begin(); iter != hodoHits[0].end(); ++iter)
352  {
353  for(std::vector<std::pair<int, int> >::iterator jter = hodoHits[1].begin(); jter != hodoHits[1].end(); ++jter)
354  {
355  for(std::vector<std::pair<int, int> >::iterator kter = hodoHits[2].begin(); kter != hodoHits[2].end(); ++kter)
356  {
357  for(std::vector<std::pair<int, int> >::iterator lter = hodoHits[3].begin(); lter != hodoHits[3].end(); ++lter)
358  {
359  TriggerRoad road_new;
360  road_new.addElement(iter->first, iter->second);
361  road_new.addElement(jter->first, jter->second);
362  road_new.addElement(kter->first, kter->second);
363  road_new.addElement(lter->first, lter->second);
364  road_new.enable();
365 
366  if(!road_new.isValid()) continue;
367 
368  pX = fabs(pX);
369  road_new.pXs.push_back(pX);
370  road_new.px_mean = pX;
371  road_new.px_min = pX;
372  road_new.px_max = pX;
373  if(z > 0)
374  {
375  road_new.dumpWeight = weight;
376  }
377  else
378  {
379  road_new.targetWeight = weight;
380  }
381 
382  if(mass < 4.)
383  {
384  road_new.lowMWeight = weight;
385  }
386  else
387  {
388  road_new.highMWeight = weight;
389  }
390 
391  road_new.px_mean = pX;
392  roads_new.push_back(road_new);
393  roads_new.push_back(road_new.reflectTB());
394  }
395  }
396  }
397  }
398 
399  //if(roads_new.size() > 1) std::cout << "!!!!!!!!!!!!!!!! " << roads_new.size() << std::endl;
400  return roads_new;
401 }
std::ostream & operator<<(std::ostream &os, const TriggerRoad &road)
ClassImp(TriggerRoad) TriggerRoad
Definition: TriggerRoad.cxx:8
User interface class about the geometry of detector planes.
Definition: GeomSvc.h:164
double getPlanePosition(int detectorID) const
Definition: GeomSvc.h:235
static GeomSvc * instance()
singlton instance
Definition: GeomSvc.cxx:212
int getPlaneNElements(int detectorID) const
Definition: GeomSvc.h:260
int getExpElementID(int detectorID, double pos_exp)
Definition: GeomSvc.cxx:677
std::string getDetectorName(const int &detectorID) const
Definition: GeomSvc.h:223
bool isInPlane(int detectorID, double x, double y)
See if a point is in a plane.
Definition: GeomSvc.cxx:622
void getExpPositionFast(Double_t z, Double_t &x, Double_t &y, Int_t iNode=-1)
Definition: SRecEvent.cxx:267
double getExpPositionY(double z) const
double getExpPositionX(double z) const
static std::list< TriggerRoad > makeRoadList(int nHits, int dIDs[], int eIDs[], double z, double mass, double pX, double weight)
double px_min
Definition: TriggerRoad.h:104
std::vector< double > pXs
Definition: TriggerRoad.h:103
double getpXMean() const
double weight() const
Definition: TriggerRoad.h:48
double getpXWidth() const
double highMWeight
Definition: TriggerRoad.h:100
void enable()
Definition: TriggerRoad.h:36
double mratio() const
Definition: TriggerRoad.h:50
static bool byRndFrequency(const TriggerRoad &elem1, const TriggerRoad &elem2)
TriggerRoad & operator+=(const TriggerRoad &elem)
double px_mean
Definition: TriggerRoad.h:106
double rndf
Definition: TriggerRoad.h:109
static bool byMass(const TriggerRoad &elem1, const TriggerRoad &elem2)
static bool byTargetDump(const TriggerRoad &elem1, const TriggerRoad &elem2)
TriggerRoad reflectLR()
bool isValid()
bool operator==(const TriggerRoad &elem) const
double ratio() const
Definition: TriggerRoad.h:49
int getNEntries() const
Definition: TriggerRoad.h:53
double lowMWeight
Definition: TriggerRoad.h:99
double dumpWeight
Definition: TriggerRoad.h:98
std::vector< int > elementIDs
Definition: TriggerRoad.h:116
TriggerRoad reflectTB()
std::vector< int > detectorIDs
Definition: TriggerRoad.h:115
double targetWeight
Definition: TriggerRoad.h:97
double px_max
Definition: TriggerRoad.h:105
void addElement(int detectorID, int elementID)
static bool byWeight(const TriggerRoad &elem1, const TriggerRoad &elem2)
static bool byPt(const TriggerRoad &elem1, const TriggerRoad &elem2)