CMS 3D CMS Logo

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