CMS 3D CMS Logo

DTMeantimerPatternReco.cc
Go to the documentation of this file.
1 
8 /* This Class Header */
10 
11 /* Collaborating Class Header */
26 
27 /* C++ Headers */
28 #include <iterator>
29 using namespace std;
31 
32 /* ====================================================================== */
33 
34 typedef std::vector<std::shared_ptr<DTHitPairForFit>> hitCont;
35 typedef hitCont::const_iterator hitIter;
36 
39  : DTRecSegment2DBaseAlgo(pset), theFitter(new DTLinearFit()), theAlgoName("DTMeantimerPatternReco") {
40  theMaxAllowedHits = pset.getParameter<unsigned int>("MaxAllowedHits"); // 100
41  theAlphaMaxTheta = pset.getParameter<double>("AlphaMaxTheta"); // 0.1 ;
42  theAlphaMaxPhi = pset.getParameter<double>("AlphaMaxPhi"); // 1.0 ;
43  theMaxChi2 = pset.getParameter<double>("MaxChi2"); // 8.0 ;
44  debug = pset.getUntrackedParameter<bool>("debug");
47 }
48 
51  delete theUpdator;
52  delete theCleaner;
53  delete theFitter;
54 }
55 
56 /* Operations */
58  const std::vector<DTRecHit1DPair>& pairs) {
60  std::vector<std::shared_ptr<DTHitPairForFit>> hitsForFit = initHits(sl, pairs);
61 
62  vector<DTSegmentCand*> candidates = buildSegments(sl, hitsForFit);
63 
64  vector<DTSegmentCand*>::const_iterator cand = candidates.begin();
65  while (cand < candidates.end()) {
66  DTSLRecSegment2D* segment = (**cand);
67  theUpdator->update(segment, true);
68 
69  if (debug)
70  cout << "Reconstructed 2D segments " << *segment << endl;
71  result.push_back(segment);
72 
73  delete *(cand++); // delete the candidate!
74  }
75 
76  return result;
77 }
78 
80  // Get the DT Geometry
83 }
84 
85 vector<std::shared_ptr<DTHitPairForFit>> DTMeantimerPatternReco::initHits(const DTSuperLayer* sl,
86  const std::vector<DTRecHit1DPair>& hits) {
88  for (vector<DTRecHit1DPair>::const_iterator hit = hits.begin(); hit != hits.end(); ++hit) {
89  result.push_back(std::make_shared<DTHitPairForFit>(*hit, *sl, theDTGeometry));
90  }
91  return result;
92 }
93 
95  const DTSuperLayer* sl, const std::vector<std::shared_ptr<DTHitPairForFit>>& hits) {
96  vector<DTSegmentCand*> result;
98 
99  if (debug) {
100  cout << "buildSegments: " << sl->id() << " nHits " << hits.size() << endl;
101  for (hitIter hit = hits.begin(); hit != hits.end(); ++hit)
102  cout << **hit << " wire: " << (*hit)->id() << " DigiTime: " << (*hit)->digiTime() << endl;
103  }
104 
105  if (hits.size() > theMaxAllowedHits) {
106  if (debug) {
107  cout << "Warning: this SuperLayer " << sl->id() << " has too many hits : " << hits.size() << " max allowed is "
108  << theMaxAllowedHits << endl;
109  cout << "Skipping segment reconstruction... " << endl;
110  }
111  return result;
112  }
113 
114  GlobalPoint IP;
115  float DAlphaMax;
116  if ((sl->id()).superlayer() == 2) // Theta SL
117  DAlphaMax = theAlphaMaxTheta;
118  else // Phi SL
119  DAlphaMax = theAlphaMaxPhi;
120 
121  // get two hits in different layers and see if there are other hits
122  // compatible with them
123  for (hitCont::const_iterator firstHit = hits.begin(); firstHit != hits.end(); ++firstHit) {
124  for (hitCont::const_reverse_iterator lastHit = hits.rbegin(); (*lastHit) != (*firstHit); ++lastHit) {
125  // a geometrical sensibility cut for the two hits
126  if (!geometryFilter((*firstHit)->id(), (*lastHit)->id()))
127  continue;
128 
129  // create a set of hits for the fit (only the hits between the two selected ones)
130  hitCont hitsForFit;
131  for (hitCont::const_iterator tmpHit = firstHit + 1; (*tmpHit) != (*lastHit); tmpHit++)
132  if ((geometryFilter((*tmpHit)->id(), (*lastHit)->id())) && (geometryFilter((*tmpHit)->id(), (*firstHit)->id())))
133  hitsForFit.push_back(*tmpHit);
134 
135  for (int firstLR = 0; firstLR < 2; ++firstLR) {
136  for (int lastLR = 0; lastLR < 2; ++lastLR) {
137  // TODO move the global transformation in the DTHitPairForFit class
138  // when it will be moved I will able to remove the sl from the input parameter
139  GlobalPoint gposFirst = sl->toGlobal((*firstHit)->localPosition(codes[firstLR]));
140  GlobalPoint gposLast = sl->toGlobal((*lastHit)->localPosition(codes[lastLR]));
141  GlobalVector gvec = gposLast - gposFirst;
142  GlobalVector gvecIP = gposLast - IP;
143 
144  // difference in angle measured
145  float DAlpha = fabs(gvec.theta() - gvecIP.theta());
146  if (DAlpha > DAlphaMax)
147  continue;
148 
149  // if(debug) {
150  // cout << "Selected hit pair:" << endl;
151  // cout << " First " << *(*firstHit) << " Layer Id: " << (*firstHit)->id().layerId() << " Side: " << firstLR << " DigiTime: " << (*firstHit)->digiTime() << endl;
152  // cout << " Last " << *(*lastHit) << " Layer Id: " << (*lastHit)->id().layerId() << " Side: " << lastLR << " DigiTime: " << (*lastHit)->digiTime() << endl;
153  // }
154 
156  auto segCand = std::make_unique<DTSegmentCand>(pointSet, sl);
157  segCand->add(*firstHit, codes[firstLR]);
158  segCand->add(*lastHit, codes[lastLR]);
159 
160  // run hit adding/segment building
161  maxfound = 3;
162  addHits(segCand.get(), hitsForFit, result);
163  }
164  }
165  }
166  }
167 
168  // now I have a couple of segment hypotheses, should check for ghosts
169  if (debug) {
170  cout << "Result (before cleaning): " << result.size() << endl;
171  for (vector<DTSegmentCand*>::const_iterator seg = result.begin(); seg != result.end(); ++seg)
172  cout << *(*seg) << endl;
173  }
174 
176 
177  if (debug) {
178  cout << "Result (after cleaning): " << result.size() << endl;
179  for (vector<DTSegmentCand*>::const_iterator seg = result.begin(); seg != result.end(); ++seg)
180  cout << *(*seg) << endl;
181  }
182 
183  return result;
184 }
185 
187  const vector<std::shared_ptr<DTHitPairForFit>>& hits,
188  vector<DTSegmentCand*>& result) {
189  double chi2l, chi2r, t0l, t0r;
190  bool foundSomething = false;
191 
192  if (debug)
193  cout << " DTMeantimerPatternReco::addHit " << endl
194  << " Picked " << segCand->nHits() << " hits, " << hits.size() << " left." << endl;
195 
196  if (segCand->nHits() + hits.size() < maxfound)
197  return;
198 
199  // loop over the remaining hits
200  for (hitCont::const_iterator hit = hits.begin(); hit != hits.end(); ++hit) {
201  // if (debug) {
202  // cout << " Trying B: " << **hit<< " wire: " << (*hit)->id() << endl;
203  // printPattern(assHits,*hit);
204  // }
205 
208 
209  segCand->add(lhit);
210  bool left_ok = (fitWithT0(segCand, false) ? true : false);
211  chi2l = segCand->chi2();
212  t0l = segCand->t0();
213  segCand->removeHit(lhit);
214 
215  segCand->add(rhit);
216  bool right_ok = (fitWithT0(segCand, false) ? true : false);
217  chi2r = segCand->chi2();
218  t0r = segCand->t0();
219  segCand->removeHit(rhit);
220 
221  if (debug) {
222  int nHits = segCand->nHits() + 1;
223  cout << " Left: t0= " << t0l << " chi2/nHits= " << chi2l << "/" << nHits << " ok: " << left_ok << endl;
224  cout << " Right: t0= " << t0r << " chi2/nHits= " << chi2r << "/" << nHits << " ok: " << right_ok << endl;
225  }
226 
227  if (!left_ok && !right_ok)
228  continue;
229 
230  foundSomething = true;
231 
232  // prepare the hit set for the next search, start from the other side
233  hitCont hitsForFit;
234  for (hitCont::const_iterator tmpHit = hit + 1; tmpHit != hits.end(); tmpHit++)
235  if (geometryFilter((*tmpHit)->id(), (*hit)->id()))
236  hitsForFit.push_back(*tmpHit);
237 
238  reverse(hitsForFit.begin(), hitsForFit.end());
239 
240  // choose only one - left or right
241  if (segCand->nHits() > 3 && left_ok && right_ok) {
242  if (chi2l < chi2r - 0.1)
243  right_ok = false;
244  else if (chi2r < chi2l - 0.1)
245  left_ok = false;
246  }
247 
248  if (left_ok) {
249  segCand->add(lhit);
250  addHits(segCand, hitsForFit, result);
251  segCand->removeHit(lhit);
252  }
253 
254  if (right_ok) {
255  segCand->add(rhit);
256  addHits(segCand, hitsForFit, result);
257  segCand->removeHit(rhit);
258  }
259  }
260 
261  if (foundSomething)
262  return;
263  // if we didn't find any new hits compatible with the current candidate, we proceed to check and store the candidate
264 
265  // If we already have a segment with more hits from this hit pair - don't save this one.
266  if (segCand->nHits() < maxfound)
267  return;
268 
269  // Check if semgent Ok, calculate chi2
270  bool seg_ok = (fitWithT0(segCand, debug) ? true : false);
271  if (!seg_ok)
272  return;
273 
274  if (!segCand->good()) {
275  // if (debug) cout << " Segment not good() - skipping" << endl;
276  return;
277  }
278 
279  if (segCand->nHits() > maxfound)
280  maxfound = segCand->nHits();
281  if (debug)
282  cout << endl << " Seg t0= " << segCand->t0() << endl << *segCand << endl;
283 
284  if (checkDoubleCandidates(result, segCand)) {
285  result.push_back(new DTSegmentCand(*segCand));
286  if (debug)
287  cout << " Result is now " << result.size() << endl;
288  } else {
289  if (debug)
290  cout << " Exists - skipping" << endl;
291  }
292 }
293 
295  // return true;
296 
297  const int layerLowerCut[4] = {0, -1, -2, -2};
298  const int layerUpperCut[4] = {0, 2, 2, 3};
299  // const int layerLowerCut[4]={0,-2,-4,-5};
300  // const int layerUpperCut[4]={0, 3, 4, 6};
301 
302  // deal only with hits that are in the same SL
303  if (first.layerId().superlayerId().superLayer() != second.layerId().superlayerId().superLayer())
304  return true;
305 
306  int deltaLayer = abs(first.layerId().layer() - second.layerId().layer());
307 
308  // drop hits in the same layer
309  if (!deltaLayer)
310  return false;
311 
312  // protection against unexpected layer numbering
313  if (deltaLayer > 3) {
314  cout << "*** WARNING! DT Layer numbers differ by more than 3! for hits: " << endl;
315  cout << " " << first << endl;
316  cout << " " << second << endl;
317  return false;
318  }
319 
320  // accept only hits in cells "not too far away"
321  int deltaWire = first.wire() - second.wire();
322  if (second.layerId().layer() % 2 == 0)
323  deltaWire = -deltaWire; // yet another trick to get it right...
324  if ((deltaWire <= layerLowerCut[deltaLayer]) || (deltaWire >= layerUpperCut[deltaLayer]))
325  return false;
326 
327  return true;
328 }
329 
331  // perform the 3 parameter fit on the segment candidate
332  theUpdator->fit(seg, true, fitdebug);
333  double chi2 = seg->chi2();
334 
335  // Sanity check - drop segment candidates with a failed 3-par fit.
336  // (this includes segments with hits after the calculated t0 correction ending up
337  // beyond the chamber walls or on the other side of the wire)
338  if (chi2 == -1.)
339  return nullptr;
340 
341  // at this point we keep all 3-hit segments that passed the above check
342  if (seg->nHits() == 3)
343  return seg;
344 
345  // for segments with no t0 information we impose a looser chi2 cut
346  if (seg->t0() == 0) {
347  if (chi2 < 100.)
348  return seg;
349  else
350  return nullptr;
351  }
352 
353  // cut on chi2/ndof of the segment candidate
354  if ((chi2 / (seg->nHits() - 3) < theMaxChi2))
355  return seg;
356  else
357  return nullptr;
358 }
359 
361  for (vector<DTSegmentCand*>::iterator cand = cands.begin(); cand != cands.end(); ++cand) {
362  if (*(*cand) == *seg)
363  return false;
364  if (((*cand)->nHits() >= seg->nHits()) && ((*cand)->chi2ndof() < seg->chi2ndof()))
365  if ((*cand)->nSharedHitPairs(*seg) > int(seg->nHits() - 2))
366  return false;
367  }
368  return true;
369 }
370 
371 void DTMeantimerPatternReco::printPattern(vector<DTSegmentCand::AssPoint>& assHits, const DTHitPairForFit* hit) {
372  char mark[26] = {". . . . . . . . . . . . "};
373  int wire[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
374 
375  for (vector<DTSegmentCand::AssPoint>::const_iterator assHit = assHits.begin(); assHit != assHits.end(); ++assHit) {
376  int lay =
377  (((*assHit).first)->id().superlayerId().superLayer() - 1) * 4 + ((*assHit).first)->id().layerId().layer() - 1;
378  wire[lay] = ((*assHit).first)->id().wire();
379  if ((*assHit).second == DTEnums::Left)
380  mark[lay * 2] = 'L';
381  else
382  mark[lay * 2] = 'R';
383  }
384 
385  int lay = ((*hit).id().superlayerId().superLayer() - 1) * 4 + (*hit).id().layerId().layer() - 1;
386  wire[lay] = (*hit).id().wire();
387  mark[lay * 2] = '*';
388 
389  cout << " " << mark << endl << " ";
390  for (int i = 0; i < 12; i++)
391  if (wire[i])
392  cout << setw(2) << wire[i];
393  else
394  cout << " ";
395  cout << endl;
396 }
Vector3DBase
Definition: Vector3DBase.h:8
DTMeantimerPatternReco::theDTGeometry
edm::ESHandle< DTGeometry > theDTGeometry
Definition: DTMeantimerPatternReco.h:107
DTLinearFit
Definition: DTLinearFit.h:26
DTSegmentCand::t0
virtual double t0() const
the t0 of the segment
Definition: DTSegmentCand.h:67
DTSLRecSegment2D
Definition: DTSLRecSegment2D.h:15
hitIter
hitCont::const_iterator hitIter
Definition: DTMeantimerPatternReco.cc:35
mps_fire.i
i
Definition: mps_fire.py:428
DTMeantimerPatternReco::maxfound
unsigned int maxfound
Definition: DTMeantimerPatternReco.h:105
hit::id
unsigned int id
Definition: SiStripHitEffFromCalibTree.cc:92
hfClusterShapes_cfi.hits
hits
Definition: hfClusterShapes_cfi.py:5
DTSegmentCleaner.h
ESHandle.h
DTMeantimerPatternReco::theCleaner
DTSegmentCleaner * theCleaner
Definition: DTMeantimerPatternReco.h:103
DTMeantimerPatternReco::geometryFilter
bool geometryFilter(const DTWireId first, const DTWireId second) const
Definition: DTMeantimerPatternReco.cc:294
DTMeantimerPatternReco::initHits
std::vector< std::shared_ptr< DTHitPairForFit > > initHits(const DTSuperLayer *sl, const std::vector< DTRecHit1DPair > &hits)
Definition: DTMeantimerPatternReco.cc:85
PV3DBase::theta
Geom::Theta< T > theta() const
Definition: PV3DBase.h:72
DTMeantimerPatternReco::theUpdator
DTSegmentUpdator * theUpdator
Definition: DTMeantimerPatternReco.h:102
gather_cfg.cout
cout
Definition: gather_cfg.py:144
DTMeantimerPatternReco::buildSegments
std::vector< DTSegmentCand * > buildSegments(const DTSuperLayer *sl, const std::vector< std::shared_ptr< DTHitPairForFit >> &hits)
Definition: DTMeantimerPatternReco.cc:94
DTMeantimerPatternReco::reconstruct
edm::OwnVector< DTSLRecSegment2D > reconstruct(const DTSuperLayer *sl, const std::vector< DTRecHit1DPair > &hits) override
this function is called in the producer
Definition: DTMeantimerPatternReco.cc:57
DTMeantimerPatternReco::debug
bool debug
Definition: DTMeantimerPatternReco.h:101
DTMeantimerPatternReco::fitWithT0
DTSegmentCand * fitWithT0(DTSegmentCand *seg, const bool fitdebug)
Definition: DTMeantimerPatternReco.cc:330
DTMeantimerPatternReco::theMaxAllowedHits
unsigned int theMaxAllowedHits
Definition: DTMeantimerPatternReco.h:97
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:222
DTSegmentCand::nHits
virtual unsigned int nHits() const
Definition: DTSegmentCand.h:58
cuy.mark
mark
Definition: cuy.py:1010
DTSuperLayer::id
DTSuperLayerId id() const
Return the DetId of this SL.
Definition: DTSuperLayer.cc:34
DTMeantimerPatternReco::theFitter
DTLinearFit * theFitter
Definition: DTMeantimerPatternReco.h:66
DTSuperLayer
Definition: DTSuperLayer.h:24
hltPixelTracks_cff.chi2
chi2
Definition: hltPixelTracks_cff.py:25
DTMeantimerPatternReco::DTMeantimerPatternReco
DTMeantimerPatternReco(const edm::ParameterSet &pset)
Constructor.
Definition: DTMeantimerPatternReco.cc:38
singleTopDQM_cfi.setup
setup
Definition: singleTopDQM_cfi.py:37
DTMeantimerPatternReco.h
groupFilesInBlocks.reverse
reverse
Definition: groupFilesInBlocks.py:131
DTSegmentUpdator
Definition: DTSegmentUpdator.h:43
DTSegmentCand.h
DTSegmentCleaner
Definition: DTSegmentCleaner.h:31
DTEnums::Left
Definition: DTEnums.h:15
DTWireId
Definition: DTWireId.h:12
nHits
const caConstants::TupleMultiplicity *__restrict__ const HitsOnGPU *__restrict__ double *__restrict__ float *__restrict__ double *__restrict__ uint32_t nHits
Definition: BrokenLineFitOnGPU.h:27
DTSegmentUpdator::fit
bool fit(DTSegmentCand *seg, bool allow3par, const bool fitdebug) const
Definition: DTSegmentUpdator.cc:216
DTSegmentCand::AssPoint
std::pair< std::shared_ptr< DTHitPairForFit >, DTEnums::DTCellSide > AssPoint
Definition: DTSegmentCand.h:36
DTSegmentCand
Definition: DTSegmentCand.h:34
DTSegmentCand::chi2
virtual double chi2() const
the chi2 (NOT chi2/NDOF) of the fit
Definition: DTSegmentCand.h:61
DTSegmentCand::add
virtual void add(AssPoint newHit)
add hits to the hit list.
Definition: DTSegmentCand.cc:58
Point3DBase< float, GlobalTag >
DTMeantimerPatternReco::theMaxChi2
double theMaxChi2
Definition: DTMeantimerPatternReco.h:100
first
auto first
Definition: CAHitNtupletGeneratorKernelsImpl.h:125
DTLayer.h
DTSegmentCand::chi2ndof
virtual double chi2ndof() const
the chi2/NDOF of the fit
Definition: DTSegmentCand.h:64
DTGeometry.h
DTMeantimerPatternReco::printPattern
void printPattern(std::vector< DTSegmentCand::AssPoint > &assHits, const DTHitPairForFit *hit)
Definition: DTMeantimerPatternReco.cc:371
listHistos.IP
IP
Definition: listHistos.py:76
funct::true
true
Definition: Factorize.h:173
HLT_FULL_cff.cands
cands
Definition: HLT_FULL_cff.py:15161
GeomDet::toGlobal
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:49
edm::ParameterSet
Definition: ParameterSet.h:47
hitCont
std::vector< std::shared_ptr< DTHitPairForFit > > hitCont
Definition: DTMeantimerPatternReco.cc:34
DTMeantimerPatternReco::theAlphaMaxTheta
double theAlphaMaxTheta
Definition: DTMeantimerPatternReco.h:98
cand
Definition: decayParser.h:32
createfilelist.int
int
Definition: createfilelist.py:10
DTSegmentCand::AssPointCont
std::set< AssPoint, AssPointLessZ > AssPointCont
Definition: DTSegmentCand.h:38
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
DTHitPairForFit.h
DTLinearFit.h
edm::EventSetup
Definition: EventSetup.h:58
DTMeantimerPatternReco::setES
void setES(const edm::EventSetup &setup) override
Definition: DTMeantimerPatternReco.cc:79
DTSegmentUpdator::setES
void setES(const edm::EventSetup &setup)
set the setup
Definition: DTSegmentUpdator.cc:68
get
#define get
DTSegmentUpdator.h
DTSegmentCand::good
virtual bool good() const
Definition: DTSegmentCand.cc:100
DTMeantimerPatternReco::addHits
void addHits(DTSegmentCand *segCand, const std::vector< std::shared_ptr< DTHitPairForFit >> &hits, std::vector< DTSegmentCand * > &result)
Definition: DTMeantimerPatternReco.cc:186
DTEnums::Right
Definition: DTEnums.h:15
std
Definition: JetResolutionObject.h:76
HLT_FULL_cff.candidates
candidates
Definition: HLT_FULL_cff.py:55017
DTEnums::DTCellSide
DTCellSide
Which side of the DT cell.
Definition: DTEnums.h:15
DTMeantimerPatternReco::theAlphaMaxPhi
double theAlphaMaxPhi
Definition: DTMeantimerPatternReco.h:99
EventSetup.h
DTSegmentCleaner::clean
std::vector< DTSegmentCand * > clean(const std::vector< DTSegmentCand * > &inputCands) const
do the cleaning
Definition: DTSegmentCleaner.cc:36
DTSLRecSegment2D.h
DTSegmentCand::removeHit
virtual void removeHit(AssPoint hit)
remove hit from the candidate
Definition: DTSegmentCand.cc:65
DTHitPairForFit
Definition: DTHitPairForFit.h:31
DTMeantimerPatternReco::checkDoubleCandidates
bool checkDoubleCandidates(std::vector< DTSegmentCand * > &segs, DTSegmentCand *seg)
Definition: DTMeantimerPatternReco.cc:360
mps_fire.result
result
Definition: mps_fire.py:311
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ParameterSet.h
OwnVector.h
MuonGeometryRecord.h
MuonGeometryRecord
Definition: MuonGeometryRecord.h:34
GlobalPoint.h
DTSuperLayer.h
DTMeantimerPatternReco::~DTMeantimerPatternReco
~DTMeantimerPatternReco() override
Destructor.
Definition: DTMeantimerPatternReco.cc:50
hit
Definition: SiStripHitEffFromCalibTree.cc:88
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
DTRecSegment2DBaseAlgo
Definition: DTRecSegment2DBaseAlgo.h:32
edm::OwnVector
Definition: OwnVector.h:24
DTSegmentUpdator::update
void update(DTRecSegment4D *seg, const bool calcT0, bool allow3par) const
recompute hits position and refit the segment4D
Definition: DTSegmentUpdator.cc:73