CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DTTMax.cc
Go to the documentation of this file.
1 /*
2  * See header file for a description of this class.
3  *
4  * $Date: 2009/05/13 13:25:04 $
5  * $Revision: 1.8 $
6  * \author Marina Giunta
7  */
8 
13 // Declare histograms for debugging purposes
15 
16 #include <map>
17 #include <iostream>
18 
19 using namespace std;
20 using namespace dttmaxenums;
21 using namespace DTEnums;
22 
25  rh(rh_), idWire(rh.wireId()), lr(rh.lrSide()) {
26  const DTLayer* layer = isl.layer(idWire.layerId());
27  LocalPoint wirePosInLayer(layer->specificTopology().wirePosition(idWire.wire()), 0, 0);
28  LocalPoint wirePosInSL=isl.toLocal(layer->toGlobal(wirePosInLayer));
29  wireX = wirePosInSL.x();
30 
31  //-- Correction for signal propagation along wire, t0 subtraction,
32  LocalVector segDir = layer->toLocal(dir);
33  LocalPoint segPos = layer->toLocal(pos);
34  LocalPoint segPosAtLayer = segPos + segDir*(-segPos.z())/cos(segDir.theta());
35  LocalPoint hitPos(rh.localPosition().x() ,segPosAtLayer.y(),0.);
36  time = rh.digiTime() - sync->offset(layer, idWire, layer->toGlobal(hitPos));
37 
38  if (time < 0. || time > 415.) {
39  // FIXME introduce time window to reject "out-of-time" digis
40  cout << " *** WARNING time = " << time << endl;
41  }
42  }
43 
44 
45 DTTMax::DTTMax(const vector<DTRecHit1D>& hits, const DTSuperLayer & isl, GlobalVector dir,
47  theInfoLayers(4,(InfoLayer*)0), //FIXME
48  theTMaxes(4,(TMax*)0)
49 {
50  // debug parameter for verbose output
51  debug = "true";
52 
53  // Collect all information using InfoLayer
54  for (vector<DTRecHit1D>::const_iterator hit=hits.begin(); hit!=hits.end();
55  ++hit) {
56  // cout << "Hit Pos " << (*hit).localPosition() << endl;
57 
58  InfoLayer* layInfo = new InfoLayer((*hit), isl, dir, pos, sync);
59  int ilay = layInfo->idWire.layer();
60  if (getInfoLayer(ilay)==0) {
61  getInfoLayer(ilay) = layInfo;
62  } else {
63  // FIXME: in case there is > 1 hit/layer, the first is taken and the others are IGNORED.
64  delete layInfo;
65  }
66  }
67 
68  // Get the segment direction
69  theSegDir = ((isl.toLocal(dir).x() < 0)? L : R);
70 
71  int layersIn = 0;
72  int nGoodHits=0;
73  for(vector<InfoLayer*>::const_iterator ilay = theInfoLayers.begin();
74  ilay != theInfoLayers.end(); ilay++) {
75  if ((*ilay) == 0 ) {
76  theSegType+= "X";
77  continue;
78  }
79  DTEnums::DTCellSide lOrR =(*ilay)->lr;
80  if(lOrR == Left) theSegType+= "L";
81  else if (lOrR == Right) theSegType+="R";
82  else theSegType+= "X";
83 
84  // layersIn : 6 = layers 1,2,3
85  // 7 = 1,2,4
86  // 8 = 1,3,4
87  // 9 = 2,3,4
88  // 10= 1,2,3,4
89  layersIn += (*ilay)->idWire.layer();
90  nGoodHits++;
91  }
92 
93  if(nGoodHits >=3 && (theSegType != "RRRR" && theSegType != "LLLL")) {
94  float t1 = 0.;
95  float t2 = 0.;
96  float t3 = 0.;
97  float t4 = 0.;
98  float x1 = 0.;
99  float x2 = 0.;
100  float x3 = 0.;
101  float x4 = 0.;
102 
103  if(layersIn <= 8 || layersIn == 10) {
104  t1 = getInfoLayer(1)->time;
105  x1 = getInfoLayer(1)->wireX;
106  }
107  if(layersIn <= 7 || layersIn >= 9) {
108  t2 = getInfoLayer(2)->time;
109  x2 = getInfoLayer(2)->wireX;
110  }
111  if(layersIn == 6 || layersIn >= 8) {
112  t3 = getInfoLayer(3)->time;
113  x3 = getInfoLayer(3)->wireX;
114  }
115  if( layersIn >= 7) {
116  t4 = getInfoLayer(4)->time;
117  x4 = getInfoLayer(4)->wireX;
118  }
119 
120  float t = 0.;
121  TMaxCells cGroup = notInit;
122  string type;
123  SigmaFactor sigma = noR; // Return the factor relating the width of the TMax distribution and the cell resolution
124  float halfCell = 2.1; // 2.1 is the half cell length in cm
125  float delta = 0.5; // (diff. wire pos.) < delta, halfCell+delta, .....
126  unsigned t0Factor = 99; // "quantity" of Delta(t0) included in the tmax formula
127 
128  //Debug
129  if (debug) {
130  cout << "seg. type: " << theSegType << " and dir: " << theSegDir << endl;
131  cout << "t1, t2, t3, t4: " << t1 << " " << t2 << " " << t3 << " " << t4 << endl;
132  cout << "x1, x2, x3, x4: " << x1 << " " << x2 << " " << x3 << " " << x4 << endl;
133  }
134 
135  //different t0 hists (if you have at least one hit within a certain distance from the wire)
136  unsigned hSubGroup = 99; //
137  if(t1 == 0. || t2 == 0. || t3 == 0. || t4 == 0.)
138  hSubGroup = 0; //if only 3 hits
139  else if(t1<=5. || t2<=5. || t3<=5. || t4<=5.)
140  hSubGroup = 1; //if distance of one hit from wire < 275um (v_drift=55um/ns)
141  else if(t1<=10. || t2<=10. || t3<=10. || t4<=10.)
142  hSubGroup = 2;
143  else if(t1<=20. || t2<=20. || t3<=20. || t4<=20.)
144  hSubGroup = 3;
145  else if(t1<=50. || t2<=50. || t3<=50. || t4<=50.)
146  hSubGroup = 4;
147 
148  if((layersIn == 6 || layersIn == 10) && (fabs(x1-x3)<delta)) {
149  cGroup = c123;
150  ((type+=theSegType[0])+=theSegType[1])+=theSegType[2];
151  sigma = r32;
152  if(type == "LRL" || type == "RLR") {
153  t0Factor = 2;
154  t = (t1+t3)/2.+t2;
155  hT123LRL->Fill(t);
156  }
157  else if((type == "LLR" && theSegDir == R) ||
158  (type == "RRL" && theSegDir == L)) {
159  t0Factor = 1;
160  t = (t3-t1)/2.+t2;
161  hT123LLR->Fill(t);
162  }
163  else if((type == "LRR" && theSegDir == R) ||
164  (type == "RLL" && theSegDir == L)) {
165  t0Factor = 1;
166  t = (t1-t3)/2.+t2;
167  hT123LRR->Fill(t);
168  }
169  else {
170  t = -1.;
171  sigma = noR;
172  hT123Bad->Fill(t);
173  }
174  theTMaxes[cGroup] = new TMax(t,cGroup,type,sigma,t0Factor,hSubGroup);
175  if(debug) cout << "tmax123 " << t << " " << type << endl;
176  }
177  if(layersIn == 7 || layersIn == 10) {
178  cGroup = c124;
179  type.clear();
180  sigma = r72;
181  ((type+=theSegType[0])+=theSegType[1])+=theSegType[3];
182  if((theSegType == "LRLR" && type == "LRR" && x1 > x4) ||
183  (theSegType == "RLRL" && type == "RLL" && x1 < x4)) {
184  t0Factor = 2;
185  t = 1.5*t2+t1-t4/2.;
186  hT124LRR1gt4->Fill(t);
187  }
188  else if((type == "LLR" && theSegDir == R && (fabs(x2-x4)<delta) && x1 < x2) ||
189  (type == "RRL" && theSegDir == L && (fabs(x2-x4)<delta) && x1 > x2)) {
190  t0Factor = 1;
191  t = 1.5*t2-t1+t4/2.;
192  hT124LLR->Fill(t);
193  }
194  else if((type == "LLL" && theSegDir == R && (fabs(x2-x4)<delta) && x1 < x2) ||
195  (type == "RRR" && theSegDir == L && (fabs(x2-x4)<delta) && x1 > x2)) {
196  t0Factor = 0;
197  t = 1.5*t2-t1-t4/2.;
198  hT124LLLR->Fill(t);
199  }
200  else if((type == "LLL" && theSegDir == L && (fabs(x2-x4)<delta)) ||
201  (type == "RRR" && theSegDir == R && (fabs(x2-x4)<delta))) {
202  t0Factor = 0;
203  t = -1.5*t2+t1+t4/2.;
204  hT124LLLL->Fill(t);
205  }
206  else if((type == "LRL" && theSegDir == L && (fabs(x2-x4)<delta)) ||
207  (type == "RLR" && theSegDir == R && (fabs(x2-x4)<delta))) {
208  t0Factor = 3;
209  t = 1.5*t2+t1+t4/2.;
210  hT124LRLL->Fill(t);
211  }
212  else if((type == "LRL" && theSegDir == R && (fabs(x1-x4)<(halfCell+delta))) ||
213  (type == "RLR" && theSegDir == L && (fabs(x1-x4)<(halfCell+delta)))) {
214  t0Factor = 99; // it's actually 1.5, but this value it's not used
215  t = 3./4.*t2+t1/2.+t4/4.;
216  sigma = r78;
217  hT124LRLR->Fill(t);
218  }
219  else if((type == "LRR" && theSegDir == R && x1 < x4 && (fabs(x1-x4)<(halfCell+delta)))||
220  (type == "RLL" && theSegDir == L && x1 > x4 && (fabs(x1-x4)<(halfCell+delta)))) {
221  t0Factor = 1;
222  t = 3./4.*t2+t1/2.-t4/4.;
223  sigma = r78;
224  hT124LRR1lt4->Fill(t);
225  }
226  else {
227  t = -1.;
228  sigma = noR;
229  hT124Bad->Fill(t);
230  }
231  theTMaxes[cGroup] = new TMax(t,cGroup,type,sigma,t0Factor,hSubGroup);
232  if(debug) cout << "tmax124 " << t << " " << t0Factor << " " << type << endl;
233  }
234  if(layersIn == 8 || layersIn == 10) {
235  cGroup = c134;
236  type.clear();
237  ((type+=theSegType[0])+=theSegType[2])+=theSegType[3];
238  sigma = r72;
239  if((type == "LLR" && x1 > x4 && theSegType == "LRLR") ||
240  (type == "RRL" && x1 < x4 && theSegType == "RLRL")) {
241  t0Factor = 2;
242  t = 1.5*t3+t4-t1/2.;
243  hT134LLR1gt4->Fill(t);
244  }
245  else if((type == "LLR" && x1 < x4 && (fabs(x1-x4)<(halfCell+delta))) ||
246  (type == "RRL" && x1 > x4 && (fabs(x1-x4)<(halfCell+delta)))) {
247  t0Factor = 1;
248  t = 3./4.*t3+t4/2.-t1/4.;
249  sigma = r78;
250  hT134LLR1lt4->Fill(t);
251  }
252  else if((type == "LRR" && theSegDir == R && x1 < x4 && (fabs(x1-x3)<delta)) ||
253  (type == "RLL" && theSegDir == L && x1 > x4 &&(fabs(x1-x3)<delta))) {
254  t0Factor = 1;
255  t = 1.5*t3-t4+t1/2.;
256  hT134LRR->Fill(t);
257  }
258  else if((type == "LRL" && theSegDir == R && (fabs(x1-x3)<delta)) ||
259  (type == "RLR" && theSegDir == L && (fabs(x1-x3)<delta))) {
260  t0Factor = 3;
261  t = 1.5*t3+t4+t1/2.;
262  hT134LRLR->Fill(t);
263  }
264  else if((type == "LRL" && theSegDir == L && (fabs(x1-x3)<(2.*halfCell+delta))) ||
265  (type == "RLR" && theSegDir == R && (fabs(x1-x3)<(2.*halfCell+delta)))) {
266  t0Factor = 99; // it's actually 1.5, but this value it's not used
267  t = 3./4.*t3+t4/2.+t1/4.;
268  sigma = r78;
269  hT134LRLL->Fill(t);
270  }
271  else if((type == "LLL" && theSegDir == L && x1 > x4 && (fabs(x1-x3)<delta)) ||
272  (type == "RRR" && theSegDir == R && x1 < x4 && (fabs(x1-x3)<delta))) {
273  t0Factor = 0;
274  t = 1.5*t3-t4-t1/2.;
275  hT134LLLL->Fill(t);
276  }
277  else if((type == "LLL" && theSegDir == R && (fabs(x1-x3)<delta)) ||
278  (type == "RRR" && theSegDir == L && (fabs(x1-x3)<delta))) {
279  t0Factor = 0;
280  t = -1.5*t3+t4+t1/2.;
281  hT134LLLR->Fill(t);
282  }
283  else {
284  t = -1;
285  sigma = noR;
286  hT134Bad->Fill(t);
287  }
288  theTMaxes[cGroup] = new TMax(t,cGroup,type,sigma,t0Factor,hSubGroup);
289  if(debug) cout << "tmax134 " << t << " " << t0Factor << " " << type << endl;
290  }
291  if((layersIn == 9 || layersIn == 10) && (fabs(x2-x4)<delta)) {
292  cGroup = c234;
293  type.clear();
294  ((type+=theSegType[1])+=theSegType[2])+=theSegType[3];
295  sigma = r32;
296  if((type == "LRL" ) ||
297  (type == "RLR" )) {
298  t0Factor = 2;
299  t = (t2+t4)/2.+t3;
300  hT234LRL->Fill(t);
301  }
302  else if((type == "LRR" && theSegDir == R) ||
303  (type == "RLL" && theSegDir == L)) {
304  t0Factor = 1;
305  t = (t2-t4)/2.+t3;
306  hT234LRR->Fill(t);
307  }
308  else if((type == "LLR" && theSegDir == R) ||
309  (type == "RRL" && theSegDir == L)) {
310  t0Factor = 1;
311  t = (t4-t2)/2.+t3;
312  hT234LLR->Fill(t);
313  }
314  else {
315  t = -1;
316  sigma = noR;
317  hT234Bad->Fill(t);
318  }
319  theTMaxes[cGroup] = new TMax(t,cGroup,type,sigma,t0Factor,hSubGroup);
320  if(debug) cout << "tmax234 " << t << " " << type << endl;
321  }
322  }
323 
324 }
325 
326 
327 vector<const DTTMax::TMax*> DTTMax::getTMax(const DTWireId & idWire) {
328  vector<const TMax*> v;
329  if(idWire.layer()==1) {
330  v.push_back(getTMax(c123)); //FIXME: needs pointer
331  v.push_back(getTMax(c124));
332  v.push_back(getTMax(c134));
333  }
334  else if(idWire.layer()==2) {
335  v.push_back(getTMax(c123));
336  v.push_back(getTMax(c124));
337  v.push_back(getTMax(c234));
338  }
339  else if(idWire.layer()==3) {
340  v.push_back(getTMax(c123));
341  v.push_back(getTMax(c134));
342  v.push_back(getTMax(c234));
343  }
344  else {
345  v.push_back(getTMax(c124));
346  v.push_back(getTMax(c134));
347  v.push_back(getTMax(c234));
348  }
349  return v;
350 }
351 
352 
353 
354 vector<const DTTMax::TMax*> DTTMax::getTMax(const DTSuperLayerId & isl) {
355  vector<const TMax*> v;
356  // add TMax* to the vector only if it really exists
357  if(getTMax(c123)) v.push_back(getTMax(c123));
358  if(getTMax(c124)) v.push_back(getTMax(c124));
359  if(getTMax(c134)) v.push_back(getTMax(c134));
360  if(getTMax(c234)) v.push_back(getTMax(c234));
361  return v;
362 }
363 
364 
366  return theTMaxes[cCase];
367 }
368 
369 /* Destructor */
371  for (vector<InfoLayer*>::const_iterator ilay = theInfoLayers.begin();
372  ilay != theInfoLayers.end(); ilay++) {
373  delete (*ilay);
374  }
375 
376  for (vector<TMax*>::const_iterator iTmax = theTMaxes.begin();
377  iTmax != theTMaxes.end(); iTmax++) {
378  delete (*iTmax);
379  }
380 }
SegDir theSegDir
Definition: DTTMax.h:93
TH1F * hT124LLR
Definition: Histogram.h:15
dbl * delta
Definition: mlp_gen.cc:36
type
Definition: HCALResponse.h:22
float wirePosition(int wireNumber) const
Returns the x position in the layer of a given wire number.
Definition: DTTopology.cc:88
TH1F * hT123Bad
Definition: Histogram.h:8
TH1F * hT123LRL
Definition: Histogram.h:9
TH1F * hT134LRLL
Definition: Histogram.h:25
TH1F * hT124LRLR
Definition: Histogram.h:19
TH1F * hT124LLLR
Definition: Histogram.h:16
TH1F * hT134LLR1lt4
Definition: Histogram.h:22
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:47
double offset(const DTLayer *layer, const DTWireId &wireId, const GlobalPoint &globalPos)
Information on each of the four TMax values in a SL.
Definition: DTTMax.h:48
T y() const
Definition: PV3DBase.h:62
DTCellSide
Which side of the DT cell.
Definition: DTEnums.h:17
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
Definition: GeomDet.h:62
TH1F * hT124LLLL
Definition: Histogram.h:17
TH1F * hT134LLLR
Definition: Histogram.h:27
int layer() const
Return the layer number.
Definition: DTLayerId.h:55
TH1F * hT134LRLR
Definition: Histogram.h:24
TH1F * hT124LRR1lt4
Definition: Histogram.h:14
virtual ~DTTMax()
Destructor.
Definition: DTTMax.cc:370
std::vector< const TMax * > getTMax(const DTWireId &idWire)
Definition: DTTMax.cc:327
DTRecHit1D rh
Definition: DTTMax.h:66
bool debug
Definition: DTTMax.h:86
Geom::Theta< T > theta() const
Definition: PV3DBase.h:74
const DTTopology & specificTopology() const
Definition: DTLayer.cc:44
TH1F * hT124LRR1gt4
Definition: Histogram.h:13
TH1F * hT123LRR
Definition: Histogram.h:11
DTTMax()
Definition: DTTMax.h:86
T z() const
Definition: PV3DBase.h:63
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
TH1F * hT124LRLL
Definition: Histogram.h:18
float digiTime() const
Return the time (ns) of the digi used to build the rechit.
Definition: DTRecHit1D.h:115
TH1F * hT234Bad
Definition: Histogram.h:28
const DTLayer * layer(DTLayerId id) const
Return the layer corresponding to the given id.
Definition: DTSuperLayer.cc:70
virtual LocalPoint localPosition() const
Return the 3-dimensional local position.
Definition: DTRecHit1D.h:62
TH1F * hT134LRR
Definition: Histogram.h:23
int wire() const
Return the wire number.
Definition: DTWireId.h:58
TH1F * hT234LRR
Definition: Histogram.h:31
InfoLayer *& getInfoLayer(int layer)
Definition: DTTMax.h:83
InfoLayer(DTRecHit1D rh_, const DTSuperLayer &isl, GlobalVector dir, GlobalPoint pos, DTTTrigBaseSync *sync)
Definition: DTTMax.cc:23
TH1F * hT234LRL
Definition: Histogram.h:29
DTWireId idWire
Definition: DTTMax.h:67
DTLayerId layerId() const
Return the corresponding LayerId.
Definition: DTWireId.h:64
TH1F * hT234LLR
Definition: Histogram.h:30
TH1F * hT134LLLL
Definition: Histogram.h:26
std::vector< TMax * > theTMaxes
Definition: DTTMax.h:92
TH1F * hT124Bad
Definition: Histogram.h:12
TH1F * hT134LLR1gt4
Definition: Histogram.h:21
tuple cout
Definition: gather_cfg.py:121
dbl *** dir
Definition: mlp_gen.cc:35
TH1F * hT134Bad
Definition: Histogram.h:20
TH1F * hT123LLR
Definition: Histogram.h:10
T x() const
Definition: PV3DBase.h:61
mathSSE::Vec4< T > v
std::vector< InfoLayer * > theInfoLayers
Definition: DTTMax.h:91
std::string theSegType
Definition: DTTMax.h:94