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