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 }
Vector3DBase
Definition: Vector3DBase.h:8
dtcalibration::Histograms
Definition: Histogram.h:9
RandomServiceHelper.t2
t2
Definition: RandomServiceHelper.py:257
DTSuperLayerId
Definition: DTSuperLayerId.h:12
dttmaxenums::L
Definition: DTTMax.h:29
dttmaxenums::c134
Definition: DTTMax.h:27
DTWireId::wire
int wire() const
Return the wire number.
Definition: DTWireId.h:42
hfClusterShapes_cfi.hits
hits
Definition: hfClusterShapes_cfi.py:5
PV3DBase::x
T x() const
Definition: PV3DBase.h:59
DTTMax::~DTTMax
virtual ~DTTMax()
Destructor.
Definition: DTTMax.cc:342
DTTMax::getTMax
std::vector< const TMax * > getTMax(const DTWireId &idWire)
Definition: DTTMax.cc:303
DTTTrigBaseSync
Definition: DTTTrigBaseSync.h:19
testProducerWithPsetDescEmpty_cfi.x2
x2
Definition: testProducerWithPsetDescEmpty_cfi.py:28
PV3DBase::theta
Geom::Theta< T > theta() const
Definition: PV3DBase.h:72
gather_cfg.cout
cout
Definition: gather_cfg.py:144
pos
Definition: PixelAliasList.h:18
dttmaxenums::noR
Definition: DTTMax.h:28
DTRecHit1D
Definition: DTRecHit1D.h:25
DTTMax::InfoLayer::InfoLayer
InfoLayer(const DTRecHit1D &rh_, const DTSuperLayer &isl, GlobalVector dir, GlobalPoint pos, const DTTTrigBaseSync &sync)
Definition: DTTMax.cc:21
DTTMax::InfoLayer::wireX
float wireX
Definition: DTTMax.h:70
DTTMax::theSegType
std::string theSegType
Definition: DTTMax.h:95
DTTMax::theSegDir
SegDir theSegDir
Definition: DTTMax.h:94
DTEnums
Definition: DTEnums.h:12
DTSuperLayer
Definition: DTSuperLayer.h:24
findQualityFiles.v
v
Definition: findQualityFiles.py:179
DTTMax::InfoLayer::rh
DTRecHit1D rh
Definition: DTTMax.h:67
dttmaxenums::TMaxCells
TMaxCells
Definition: DTTMax.h:27
PV3DBase::z
T z() const
Definition: PV3DBase.h:61
DTTMax::InfoLayer::time
float time
Definition: DTTMax.h:71
testProducerWithPsetDescEmpty_cfi.x1
x1
Definition: testProducerWithPsetDescEmpty_cfi.py:33
dttmaxenums::r72
Definition: DTTMax.h:28
RandomServiceHelper.t1
t1
Definition: RandomServiceHelper.py:256
funct::cos
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
DTTMax::TMax
Information on each of the four TMax values in a SL.
Definition: DTTMax.h:50
dttmaxenums::SigmaFactor
SigmaFactor
Definition: DTTMax.h:28
DTWireId
Definition: DTWireId.h:12
DTTMax::theTMaxes
std::vector< TMax * > theTMaxes
Definition: DTTMax.h:93
dttmaxenums::r78
Definition: DTTMax.h:28
Point3DBase< float, GlobalTag >
GeomDet::toLocal
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
Definition: GeomDet.h:58
RandomServiceHelper.t3
t3
Definition: RandomServiceHelper.py:258
dttmaxenums
Definition: DTTMax.h:26
dttmaxenums::c123
Definition: DTTMax.h:27
dttmaxenums::notInit
Definition: DTTMax.h:27
DTLayer.h
phase1PixelTopology::layer
constexpr std::array< uint8_t, layerIndexSize > layer
Definition: phase1PixelTopology.h:99
DTRecHit1D::localPosition
LocalPoint localPosition() const override
Return the 3-dimensional local position.
Definition: DTRecHit1D.h:47
type
type
Definition: SiPixelVCal_PayloadInspector.cc:39
gpuVertexFinder::hist
__shared__ Hist hist
Definition: gpuClusterTracksDBSCAN.h:48
DTTMax.h
gainCalibHelper::gainCalibPI::type
type
Definition: SiPixelGainCalibHelper.h:40
dumpMFGeometry_cfg.delta
delta
Definition: dumpMFGeometry_cfg.py:25
PV3DBase::y
T y() const
Definition: PV3DBase.h:60
DTTTrigBaseSync.h
DTLayer
Definition: DTLayer.h:25
DTRecHit1D::digiTime
float digiTime() const
Return the time (ns) of the digi used to build the rechit.
Definition: DTRecHit1D.h:79
dttmaxenums::c234
Definition: DTTMax.h:27
DTTTrigBaseSync::offset
double offset(const DTLayer *layer, const DTWireId &wireId, const GlobalPoint &globalPos) const
Definition: DTTTrigBaseSync.cc:13
std
Definition: JetResolutionObject.h:76
DTTMax::theInfoLayers
std::vector< InfoLayer * > theInfoLayers
Definition: DTTMax.h:92
dttmaxenums::r32
Definition: DTTMax.h:28
DTTMax::InfoLayer::idWire
DTWireId idWire
Definition: DTTMax.h:68
DTEnums::DTCellSide
DTCellSide
Which side of the DT cell.
Definition: DTEnums.h:15
DTTMax::debug
bool debug
Definition: DTTMax.h:87
DTSuperLayer::layer
const DTLayer * layer(const DTLayerId &id) const
Return the layer corresponding to the given id.
Definition: DTSuperLayer.cc:54
DTWireId::layerId
DTLayerId layerId() const
Return the corresponding LayerId.
Definition: DTWireId.h:45
dttmaxenums::c124
Definition: DTTMax.h:27
DTLayerId::layer
int layer() const
Return the layer number.
Definition: DTLayerId.h:42
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
DTTMax::DTTMax
DTTMax()
Definition: DTTMax.h:87
DTTMax::getInfoLayer
InfoLayer *& getInfoLayer(int layer)
Definition: DTTMax.h:84
dttmaxenums::R
Definition: DTTMax.h:29
DTSuperLayer.h
DTTMax::InfoLayer
Definition: DTTMax.h:64
hit
Definition: SiStripHitEffFromCalibTree.cc:88
DeadROC_duringRun.dir
dir
Definition: DeadROC_duringRun.py:23