CMS 3D CMS Logo

SimpleCosmicBONSeeder.cc
Go to the documentation of this file.
1 //
2 // Package: RecoTracker/TkSeedGenerator
3 // Class: GlobalPixelLessSeedGenerator
4 //
5 // From CosmicSeedGenerator+SimpleCosmicBONSeeder, with changes by Giovanni
6 // to seed Cosmics with B != 0
7 
15 
16 #include <numeric>
17 
18 namespace {
19  std::string seedingLayersToString(const SeedingLayerSetsHits::SeedingLayerSet &layer) {
20  return layer[0].name() + "+" + layer[1].name() + "+" + layer[2].name();
21  }
22 } // namespace
23 
24 using namespace std;
26  : conf_(conf),
27  seedingLayerToken_(consumes<SeedingLayerSetsHits>(conf.getParameter<edm::InputTag>("TripletsSrc"))),
28  writeTriplets_(conf.getParameter<bool>("writeTriplets")),
29  seedOnMiddle_(conf.existsAs<bool>("seedOnMiddle") ? conf.getParameter<bool>("seedOnMiddle") : false),
30  rescaleError_(conf.existsAs<double>("rescaleError") ? conf.getParameter<double>("rescaleError") : 1.0),
31  tripletsVerbosity_(conf.getUntrackedParameter<uint32_t>("TripletsDebugLevel", 0)),
32  seedVerbosity_(conf.getUntrackedParameter<uint32_t>("seedDebugLevel", 0)),
33  helixVerbosity_(conf.getUntrackedParameter<uint32_t>("helixDebugLevel", 0)),
34  check_(conf.getParameter<edm::ParameterSet>("ClusterCheckPSet"), consumesCollector()),
35  maxTriplets_(conf.getParameter<int32_t>("maxTriplets")),
36  maxSeeds_(conf.getParameter<int32_t>("maxSeeds")) {
37  edm::ParameterSet regionConf = conf_.getParameter<edm::ParameterSet>("RegionPSet");
38  float ptmin = regionConf.getParameter<double>("ptMin");
39  float originradius = regionConf.getParameter<double>("originRadius");
40  float halflength = regionConf.getParameter<double>("originHalfLength");
41  float originz = regionConf.getParameter<double>("originZPosition");
42  region_ = GlobalTrackingRegion(ptmin, originradius, halflength, originz);
43  pMin_ = regionConf.getParameter<double>("pMin");
44 
45  builderName = conf_.getParameter<std::string>("TTRHBuilder");
46 
47  //***top-bottom
48  positiveYOnly = conf_.getParameter<bool>("PositiveYOnly");
49  negativeYOnly = conf_.getParameter<bool>("NegativeYOnly");
50  //***
51 
52  produces<TrajectorySeedCollection>();
53  if (writeTriplets_)
54  produces<edm::OwnVector<TrackingRecHit>>("cosmicTriplets");
55 
56  if (conf.existsAs<edm::ParameterSet>("ClusterChargeCheck")) {
57  edm::ParameterSet cccc = conf.getParameter<edm::ParameterSet>("ClusterChargeCheck");
58  checkCharge_ = cccc.getParameter<bool>("checkCharge");
59  matchedRecHitUsesAnd_ = cccc.getParameter<bool>("matchedRecHitsUseAnd");
60  chargeThresholds_.resize(7, 0);
61  edm::ParameterSet ccct = cccc.getParameter<edm::ParameterSet>("Thresholds");
66  } else {
67  checkCharge_ = false;
68  }
69  if (conf.existsAs<edm::ParameterSet>("HitsPerModuleCheck")) {
70  edm::ParameterSet hpmcc = conf.getParameter<edm::ParameterSet>("HitsPerModuleCheck");
71  checkMaxHitsPerModule_ = hpmcc.getParameter<bool>("checkHitsPerModule");
73  edm::ParameterSet hpmct = hpmcc.getParameter<edm::ParameterSet>("Thresholds");
74  maxHitsPerModule_[StripSubdetector::TIB] = hpmct.getParameter<int32_t>("TIB");
75  maxHitsPerModule_[StripSubdetector::TID] = hpmct.getParameter<int32_t>("TID");
76  maxHitsPerModule_[StripSubdetector::TOB] = hpmct.getParameter<int32_t>("TOB");
77  maxHitsPerModule_[StripSubdetector::TEC] = hpmct.getParameter<int32_t>("TEC");
78  } else {
79  checkMaxHitsPerModule_ = false;
80  }
82  goodHitsPerSeed_ = conf.getParameter<int32_t>("minimumGoodHitsInSeed");
83  } else {
84  goodHitsPerSeed_ = 0;
85  }
86 }
87 
88 // Functions that gets called by framework every event
90  auto output = std::make_unique<TrajectorySeedCollection>();
91  auto outtriplets = std::make_unique<edm::OwnVector<TrackingRecHit>>();
92 
94  if (magfield->inTesla(GlobalPoint(0, 0, 0)).mag() > 0.01) {
95  size_t clustsOrZero = check_.tooManyClusters(ev);
96  if (clustsOrZero) {
97  edm::LogError("TooManyClusters") << "Found too many clusters (" << clustsOrZero << "), bailing out.\n";
98  } else {
99  init(es);
100  bool tripletsOk = triplets(ev, es);
101  if (tripletsOk) {
102  bool seedsOk = seeds(*output, es);
103  if (!seedsOk) {
104  }
105 
106  if (writeTriplets_) {
107  for (OrderedHitTriplets::const_iterator it = hitTriplets.begin(); it != hitTriplets.end(); ++it) {
108  const TrackingRecHit *hit1 = it->inner()->hit();
109  const TrackingRecHit *hit2 = it->middle()->hit();
110  const TrackingRecHit *hit3 = it->outer()->hit();
111  outtriplets->push_back(hit1->clone());
112  outtriplets->push_back(hit2->clone());
113  outtriplets->push_back(hit3->clone());
114  }
115  }
116  }
117  done();
118  }
119  }
120 
121  if (writeTriplets_) {
122  ev.put(std::move(outtriplets), "cosmicTriplets");
123  }
124  ev.put(std::move(output));
125 }
126 
130  cloner = ((TkTransientTrackingRecHitBuilder const *)(TTTRHBuilder.product()))->cloner();
131  // FIXME: these should come from ES too!!
134  theUpdator = new KFUpdator();
135 }
136 
138  bool operator()(const OrderedHitTriplet &trip1, const OrderedHitTriplet &trip2) const {
139  //FIXME: inner gives a SEGV
140 #if 0
141  //const SeedingHitSet::ConstRecHitPointer &ihit1 = trip1.inner();
142  //const SeedingHitSet::ConstRecHitPointer &ihit2 = trip2.inner();
143  const SeedingHitSet::ConstRecHitPointer &ihit1 = trip1.middle();
144  const SeedingHitSet::ConstRecHitPointer &ihit2 = trip2.middle();
145  const SeedingHitSet::ConstRecHitPointer &ohit1 = trip1.outer();
146  const SeedingHitSet::ConstRecHitPointer &ohit2 = trip2.outer();
147 #endif
152  float iy1 = ihit1->globalPosition().y();
153  float oy1 = ohit1->globalPosition().y();
154  float iy2 = ihit2->globalPosition().y();
155  float oy2 = ohit2->globalPosition().y();
156  if (oy1 - iy1 > 0) { // 1 Downgoing
157  if (oy2 - iy2 > 0) { // 2 Downgoing
158  // sort by inner, or by outer if inners are the same
159  return (iy1 != iy2 ? (iy1 > iy2) : (oy1 > oy2));
160  } else
161  return true; // else prefer downgoing
162  } else if (oy2 - iy2 > 0) {
163  return false; // prefer downgoing
164  } else { // both upgoing
165  // sort by inner, or by outer
166  return (iy1 != iy2 ? (iy1 < iy2) : (oy1 < oy2));
167  }
168  }
169 };
170 
172  hitTriplets.clear();
173  hitTriplets.reserve(0);
175  e.getByToken(seedingLayerToken_, hlayers);
176  const SeedingLayerSetsHits &layers = *hlayers;
177  if (layers.numberOfLayersInSet() != 3)
178  throw cms::Exception("CtfSpecialSeedGenerator")
179  << "You are using " << layers.numberOfLayersInSet() << " layers in set instead of 3 ";
180 
181  double minRho = region_.ptMin() / (0.003 * magfield->inTesla(GlobalPoint(0, 0, 0)).z());
182 
183  for (SeedingLayerSetsHits::LayerSetIndex layerIndex = 0; layerIndex < layers.size(); ++layerIndex) {
186  auto innerHits = region_.hits(es, ls[0]);
187  auto middleHits = region_.hits(es, ls[1]);
188  auto outerHits = region_.hits(es, ls[2]);
189 
190  if (tripletsVerbosity_ > 0) {
191  std::cout << "GenericTripletGenerator iLss = " << seedingLayersToString(ls) << " (" << layerIndex
192  << "): # = " << innerHits.size() << "/" << middleHits.size() << "/" << outerHits.size() << std::endl;
193  }
194 
197  std::vector<TTRH> innerTTRHs, middleTTRHs, outerTTRHs;
198 
200  std::vector<bool> innerOk(innerHits.size(), true);
201  std::vector<bool> middleOk(middleHits.size(), true);
202  std::vector<bool> outerOk(outerHits.size(), true);
203 
204  size_t sizBefore = hitTriplets.size();
206  int idx = 0;
207  for (auto iOuterHit = outerHits.begin(); iOuterHit != outerHits.end(); ++idx, ++iOuterHit) {
208  outerTTRHs.push_back(&(**iOuterHit));
209  if (checkCharge_ && !checkCharge(outerTTRHs.back()->hit()))
210  outerOk[idx] = false;
211  }
212  idx = 0;
213  for (auto iMiddleHit = middleHits.begin(); iMiddleHit != middleHits.end(); ++idx, ++iMiddleHit) {
214  middleTTRHs.push_back(&(**iMiddleHit));
215  if (checkCharge_ && !checkCharge(middleTTRHs.back()->hit()))
216  middleOk[idx] = false;
217  }
218  idx = 0;
219  for (auto iInnerHit = innerHits.begin(); iInnerHit != innerHits.end(); ++idx, ++iInnerHit) {
220  innerTTRHs.push_back(&(**iInnerHit));
221  if (checkCharge_ && !checkCharge(innerTTRHs.back()->hit()))
222  innerOk[idx] = false;
223  }
225  checkNoisyModules(innerTTRHs, innerOk);
226  checkNoisyModules(middleTTRHs, middleOk);
227  checkNoisyModules(outerTTRHs, outerOk);
228  }
229 
230  for (auto iOuterHit = outerHits.begin(); iOuterHit != outerHits.end(); iOuterHit++) {
231  idx = iOuterHit - outerHits.begin();
232  TTRH &outerTTRH = outerTTRHs[idx];
233  GlobalPoint outerpos = outerTTRH->globalPosition(); // this caches by itself
234  bool outerok = outerOk[idx];
235  if (outerok < goodHitsPerSeed_ - 2) {
236  if (tripletsVerbosity_ > 2)
237  std::cout << "Skipping at first hit: " << (outerok) << " < " << (goodHitsPerSeed_ - 2) << std::endl;
238  continue;
239  }
240 
241  for (auto iMiddleHit = middleHits.begin(); iMiddleHit != middleHits.end(); iMiddleHit++) {
242  idx = iMiddleHit - middleHits.begin();
243  TTRH &middleTTRH = middleTTRHs[idx];
244  GlobalPoint middlepos = middleTTRH->globalPosition(); // this caches by itself
245  bool middleok = middleOk[idx];
246  if (outerok + middleok < goodHitsPerSeed_ - 1) {
247  if (tripletsVerbosity_ > 2)
248  std::cout << "Skipping at second hit: " << (outerok + middleok) << " < " << (goodHitsPerSeed_ - 1)
249  << std::endl;
250  continue;
251  }
252 
253  for (auto iInnerHit = innerHits.begin(); iInnerHit != innerHits.end(); iInnerHit++) {
254  idx = iInnerHit - innerHits.begin();
255  TTRH &innerTTRH = innerTTRHs[idx];
256  GlobalPoint innerpos = innerTTRH->globalPosition(); // this caches by itself
257  bool innerok = innerOk[idx];
258  if (outerok + middleok + innerok < goodHitsPerSeed_) {
259  if (tripletsVerbosity_ > 2)
260  std::cout << "Skipping at third hit: " << (outerok + middleok + innerok) << " < " << (goodHitsPerSeed_)
261  << std::endl;
262  continue;
263  }
264 
265  //***top-bottom
266  if (positiveYOnly &&
267  (innerpos.y() < 0 || middlepos.y() < 0 || outerpos.y() < 0 || outerpos.y() < innerpos.y()))
268  continue;
269  if (negativeYOnly &&
270  (innerpos.y() > 0 || middlepos.y() > 0 || outerpos.y() > 0 || outerpos.y() > innerpos.y()))
271  continue;
272  //***
273 
274  if (tripletsVerbosity_ > 2)
275  std::cout << "Trying seed with: " << innerpos << " + " << middlepos << " + " << outerpos << std::endl;
276  if (goodTriplet(innerpos, middlepos, outerpos, minRho)) {
277  OrderedHitTriplet oht(&(**iInnerHit), &(**iMiddleHit), &(**iOuterHit));
278  hitTriplets.push_back(oht);
279  if ((maxTriplets_ > 0) && (hitTriplets.size() > size_t(maxTriplets_))) {
280  hitTriplets.clear(); // clear
281  //OrderedHitTriplets().swap(hitTriplets); // really clear
282  edm::LogError("TooManyTriplets") << "Found too many triplets, bailing out.\n";
283  return false;
284  }
285  if (tripletsVerbosity_ > 3) {
286  std::cout << " accepted seed #" << (hitTriplets.size() - 1) << " w/: " << innerpos << " + " << middlepos
287  << " + " << outerpos << std::endl;
288  }
289  if (tripletsVerbosity_ == 2) {
290  std::cout << " good seed #" << (hitTriplets.size() - 1) << " w/: " << innerpos << " + " << middlepos
291  << " + " << outerpos << std::endl;
292  }
293  if (tripletsVerbosity_ > 3 && (helixVerbosity_ > 0)) { // debug the momentum here too
294  pqFromHelixFit(innerpos, middlepos, outerpos, es);
295  }
296  }
297  }
298  }
299  }
300  if ((tripletsVerbosity_ > 0) && (hitTriplets.size() > sizBefore)) {
301  std::cout << " iLss = " << seedingLayersToString(ls) << " (" << layerIndex
302  << "): # = " << innerHits.size() << "/" << middleHits.size() << "/" << outerHits.size() << ": Found "
303  << (hitTriplets.size() - sizBefore) << " seeds [running total: " << hitTriplets.size() << "]"
304  << std::endl;
305  }
306  }
307  std::sort(hitTriplets.begin(), hitTriplets.end(), HigherInnerHit());
308  return true;
309 }
311  DetId detid(hit->geographicalId());
312  if (detid.det() != DetId::Tracker)
313  return false; // should not happen
314  int subdet = detid.subdetId();
315  if (subdet < 3) { // pixel
316  return true;
317  } else {
318  if (typeid(*hit) == typeid(SiStripMatchedRecHit2D)) {
319  const SiStripMatchedRecHit2D *mhit = static_cast<const SiStripMatchedRecHit2D *>(hit);
320  if (matchedRecHitUsesAnd_) {
321  return checkCharge(mhit->monoHit(), subdet) && checkCharge(mhit->stereoHit(), subdet);
322  } else {
323  return checkCharge(mhit->monoHit(), subdet) || checkCharge(mhit->stereoHit(), subdet);
324  }
325  } else if (typeid(*hit) == typeid(SiStripRecHit2D)) {
326  return checkCharge(static_cast<const SiStripRecHit2D &>(*hit), subdet);
327  } else {
328  return true;
329  }
330  }
331 }
332 
333 // to be fixed to use OmniCluster
334 bool SimpleCosmicBONSeeder::checkCharge(const SiStripRecHit2D &hit, int subdetid) const {
335  const SiStripCluster *clust = hit.cluster().get();
336  int charge = std::accumulate(clust->amplitudes().begin(), clust->amplitudes().end(), int(0));
337  if (tripletsVerbosity_ > 1) {
338  std::cerr << "Hit on " << subdetid << ", charge = " << charge << ", threshold = " << chargeThresholds_[subdetid]
339  << ", detid = " << hit.geographicalId().rawId() << ", firstStrip = " << clust->firstStrip() << std::endl;
340  } else if ((tripletsVerbosity_ == 1) && (charge < chargeThresholds_[subdetid])) {
341  std::cerr << "Hit on " << subdetid << ", charge = " << charge << ", threshold = " << chargeThresholds_[subdetid]
342  << ", detid = " << hit.geographicalId().rawId() << ", firstStrip = " << clust->firstStrip() << std::endl;
343  }
344  return charge > chargeThresholds_[subdetid];
345 }
346 
347 void SimpleCosmicBONSeeder::checkNoisyModules(const std::vector<SeedingHitSet::ConstRecHitPointer> &hits,
348  std::vector<bool> &oks) const {
350  std::vector<TTRH>::const_iterator it = hits.begin(), start = it, end = hits.end();
351  std::vector<bool>::iterator ok = oks.begin(), okStart = ok;
352  while (start < end) {
353  DetId lastid = (*start)->geographicalId();
354  for (it = start + 1; (it < end) && ((*it)->geographicalId() == lastid); ++it) {
355  ++ok;
356  }
357  if ((it - start) > maxHitsPerModule_[lastid.subdetId()]) {
358  if (tripletsVerbosity_ > 0) {
359  std::cerr << "SimpleCosmicBONSeeder: Marking noisy module " << lastid.rawId() << ", it has " << (it - start)
360  << " rechits"
361  << " (threshold is " << maxHitsPerModule_[lastid.subdetId()] << ")" << std::endl;
362  }
363  std::fill(okStart, ok, false);
364  } else if (tripletsVerbosity_ > 0) {
365  if ((it - start) > std::min(4, maxHitsPerModule_[lastid.subdetId()] / 4)) {
366  std::cerr << "SimpleCosmicBONSeeder: Not marking noisy module " << lastid.rawId() << ", it has " << (it - start)
367  << " rechits"
368  << " (threshold is " << maxHitsPerModule_[lastid.subdetId()] << ")" << std::endl;
369  }
370  }
371  start = it;
372  okStart = ok;
373  }
374 }
375 
377  const GlobalPoint &middle,
378  const GlobalPoint &outer,
379  const double &minRho) const {
380  float dyOM = outer.y() - middle.y(), dyIM = inner.y() - middle.y();
381  if ((dyOM * dyIM > 0) && (fabs(dyOM) > 10) && (fabs(dyIM) > 10)) {
382  if (tripletsVerbosity_ > 2)
383  std::cout << " fail for non coherent dy" << std::endl;
384  return false;
385  }
386  float dzOM = outer.z() - middle.z(), dzIM = inner.z() - middle.z();
387  if ((dzOM * dzIM > 0) && (fabs(dzOM) > 50) && (fabs(dzIM) > 50)) {
388  if (tripletsVerbosity_ > 2)
389  std::cout << " fail for non coherent dz" << std::endl;
390  return false;
391  }
392  if (minRho > 0) {
393  FastCircle theCircle(inner, middle, outer);
394  if (theCircle.rho() < minRho) {
395  if (tripletsVerbosity_ > 2)
396  std::cout << " fail for pt cut" << std::endl;
397  return false;
398  }
399  }
400  return true;
401 }
402 
403 std::pair<GlobalVector, int> SimpleCosmicBONSeeder::pqFromHelixFit(const GlobalPoint &inner,
404  const GlobalPoint &middle,
405  const GlobalPoint &outer,
406  const edm::EventSetup &iSetup) const {
407  if (helixVerbosity_ > 0) {
408  std::cout << "DEBUG PZ =====" << std::endl;
409  FastHelix helix(inner, middle, outer, magfield->nominalValue(), &*magfield);
410  GlobalVector gv = helix.stateAtVertex().momentum(); // status on inner hit
411  std::cout << "FastHelix P = " << gv << "\n";
412  std::cout << "FastHelix Q = " << helix.stateAtVertex().charge() << "\n";
413  }
414 
415  // My attempt (with different approx from FastHelix)
416  // 1) fit the circle
417  FastCircle theCircle(inner, middle, outer);
418  double rho = theCircle.rho();
419 
420  // 2) Get the PT
421  GlobalVector tesla = magfield->inTesla(middle);
422  double pt = 0.01 * rho * (0.3 * tesla.z());
423 
424  // 3) Get the PX,PY at OUTER hit (VERTEX)
425  double dx1 = outer.x() - theCircle.x0();
426  double dy1 = outer.y() - theCircle.y0();
427  double py = pt * dx1 / rho, px = -pt * dy1 / rho;
428  if (px * (middle.x() - outer.x()) + py * (middle.y() - outer.y()) < 0.) {
429  px *= -1.;
430  py *= -1.;
431  }
432 
433  // 4) Get the PZ through pz = pT*(dz/d(R*phi)))
434  double dz = inner.z() - outer.z();
435  double sinphi = (dx1 * (inner.y() - theCircle.y0()) - dy1 * (inner.x() - theCircle.x0())) / (rho * rho);
436  double dphi = std::abs(std::asin(sinphi));
437  double pz = pt * dz / (dphi * rho);
438 
439  int myq = ((theCircle.x0() * py - theCircle.y0() * px) / tesla.z()) > 0. ? +1 : -1;
440 
441  std::pair<GlobalVector, int> mypq(GlobalVector(px, py, pz), myq);
442 
443  if (helixVerbosity_ > 1) {
444  std::cout << "Gio: pt = " << pt << std::endl;
445  std::cout << "Gio: dz = " << dz << ", sinphi = " << sinphi << ", dphi = " << dphi
446  << ", dz/drphi = " << (dz / dphi / rho) << std::endl;
447  }
448  if (helixVerbosity_ > 0) {
449  std::cout << "Gio's fit P = " << mypq.first << "\n";
450  std::cout << "Gio's fit Q = " << myq << "\n";
451  }
452 
453  return mypq;
454 }
455 
458 
459  for (size_t it = 0; it < hitTriplets.size(); it++) {
460  OrderedHitTriplet &trip = hitTriplets.at(it);
461 
463  tracker->idToDet((*(trip.inner())).geographicalId())->surface().toGlobal((*(trip.inner())).localPosition());
464 
465  GlobalPoint middle =
466  tracker->idToDet((*(trip.middle())).geographicalId())->surface().toGlobal((*(trip.middle())).localPosition());
467 
469  tracker->idToDet((*(trip.outer())).geographicalId())->surface().toGlobal((*(trip.outer())).localPosition());
470 
471  if (seedVerbosity_ > 1)
472  std::cout << "Processing triplet " << it << ": " << inner << " + " << middle << " + " << outer << std::endl;
473 
474  if ((outer.y() - inner.y()) * outer.y() < 0) {
476  trip = OrderedHitTriplet(trip.outer(), trip.middle(), trip.inner());
477 
478  if (seedVerbosity_ > 1) {
479  std::cout << "The seed was going away from CMS! swapped in <-> out" << std::endl;
480  std::cout << "Processing swapped triplet " << it << ": " << inner << " + " << middle << " + " << outer
481  << std::endl;
482  }
483  }
484 
485  // First use FastHelix out of the box
486  std::pair<GlobalVector, int> pq = pqFromHelixFit(inner, middle, outer, iSetup);
487  GlobalVector gv = pq.first;
488  float ch = pq.second;
489  float Mom = sqrt(gv.x() * gv.x() + gv.y() * gv.y() + gv.z() * gv.z());
490 
491  if (Mom > 10000 || edm::isNotFinite(Mom)) {
492  if (seedVerbosity_ > 1)
493  std::cout << "Processing triplet " << it << ": fail for momentum." << std::endl;
494  continue;
495  }
496 
497  if (gv.perp() < region_.ptMin()) {
498  if (seedVerbosity_ > 1)
499  std::cout << "Processing triplet " << it << ": fail for pt = " << gv.perp() << " < ptMin = " << region_.ptMin()
500  << std::endl;
501  continue;
502  }
503 
504  const Propagator *propagator = nullptr;
505  if ((outer.y() - inner.y()) > 0) {
506  if (seedVerbosity_ > 1)
507  std::cout << "Processing triplet " << it << ": downgoing." << std::endl;
509  } else {
510  gv = -1 * gv;
511  ch = -1. * ch;
513  if (seedVerbosity_ > 1)
514  std::cout << "Processing triplet " << it << ": upgoing." << std::endl;
515  }
516 
517  if (seedVerbosity_ > 1) {
518  if ((gv.z() * (outer.z() - inner.z()) > 0) && (fabs(outer.z() - inner.z()) > 5) && (fabs(gv.z()) > .01)) {
519  std::cout << "ORRORE: outer.z()-inner.z() = " << (outer.z() - inner.z()) << ", gv.z() = " << gv.z()
520  << std::endl;
521  }
522  }
523 
524  GlobalTrajectoryParameters Gtp(outer, gv, int(ch), &(*magfield));
526  CosmicSeed.rescaleError(100);
527  if (seedVerbosity_ > 2) {
528  std::cout << "Processing triplet " << it << ". start from " << std::endl;
529  std::cout << " X = " << outer << ", P = " << gv << std::endl;
530  std::cout << " Cartesian error (X,P) = \n" << CosmicSeed.cartesianError().matrix() << std::endl;
531  }
532 
534  OrderedHitTriplet seedHits(trip.outer(), trip.middle(), trip.inner());
535  TSOS propagated, updated;
536  bool fail = false;
537  for (size_t ih = 0; ih < 3; ++ih) {
538  if ((ih == 2) && seedOnMiddle_) {
539  if (seedVerbosity_ > 2)
540  std::cout << "Stopping at middle hit, as requested." << std::endl;
541  break;
542  }
543  if (seedVerbosity_ > 2)
544  std::cout << "Processing triplet " << it << ", hit " << ih << "." << std::endl;
545  if (ih == 0) {
546  propagated = propagator->propagate(CosmicSeed, tracker->idToDet((*seedHits[ih]).geographicalId())->surface());
547  } else {
548  propagated = propagator->propagate(updated, tracker->idToDet((*seedHits[ih]).geographicalId())->surface());
549  }
550  if (!propagated.isValid()) {
551  if (seedVerbosity_ > 1)
552  std::cout << "Processing triplet " << it << ", hit " << ih << ": failed propagation." << std::endl;
553  fail = true;
554  break;
555  } else {
556  if (seedVerbosity_ > 2)
557  std::cout << "Processing triplet " << it << ", hit " << ih << ": propagated state = " << propagated;
558  }
559  SeedingHitSet::ConstRecHitPointer tthp = seedHits[ih];
560  auto newtth = static_cast<SeedingHitSet::RecHitPointer>(cloner(*tthp, propagated));
561  updated = theUpdator->update(propagated, *newtth);
562  hits.push_back(newtth);
563  if (!updated.isValid()) {
564  if (seedVerbosity_ > 1)
565  std::cout << "Processing triplet " << it << ", hit " << ih << ": failed update." << std::endl;
566  fail = true;
567  break;
568  } else {
569  if (seedVerbosity_ > 2)
570  std::cout << "Processing triplet " << it << ", hit " << ih << ": updated state = " << updated;
571  }
572  }
573  if (!fail && updated.isValid() && (updated.globalMomentum().perp() < region_.ptMin())) {
574  if (seedVerbosity_ > 1)
575  std::cout << "Processing triplet " << it << ": failed for final pt " << updated.globalMomentum().perp() << " < "
576  << region_.ptMin() << std::endl;
577  fail = true;
578  }
579  if (!fail && updated.isValid() && (updated.globalMomentum().mag() < pMin_)) {
580  if (seedVerbosity_ > 1)
581  std::cout << "Processing triplet " << it << ": failed for final p " << updated.globalMomentum().perp() << " < "
582  << pMin_ << std::endl;
583  fail = true;
584  }
585  if (!fail) {
586  if (rescaleError_ != 1.0) {
587  if (seedVerbosity_ > 2) {
588  std::cout << "Processing triplet " << it << ", rescale error by " << rescaleError_
589  << ": state BEFORE rescaling " << updated;
590  std::cout << " Cartesian error (X,P) before rescaling= \n"
591  << updated.cartesianError().matrix() << std::endl;
592  }
593  updated.rescaleError(rescaleError_);
594  }
595  if (seedVerbosity_ > 0) {
596  std::cout << "Processed triplet " << it << ": success (saved as #" << output.size() << ") : " << inner << " + "
597  << middle << " + " << outer << std::endl;
598  std::cout << " pt = " << updated.globalMomentum().perp() << " eta = " << updated.globalMomentum().eta()
599  << " phi = " << updated.globalMomentum().phi() << " ch = " << updated.charge() << std::endl;
600  if (seedVerbosity_ > 1) {
601  std::cout << " State:" << updated;
602  } else {
603  std::cout << " X = " << updated.globalPosition() << ", P = " << updated.globalMomentum() << std::endl;
604  }
605  std::cout << " Cartesian error (X,P) = \n" << updated.cartesianError().matrix() << std::endl;
606  }
607 
609  updated, (*(seedOnMiddle_ ? trip.middle() : trip.inner())).geographicalId().rawId());
610  output.push_back(TrajectorySeed(PTraj, hits, ((outer.y() - inner.y() > 0) ? alongMomentum : oppositeToMomentum)));
611  if ((maxSeeds_ > 0) && (output.size() > size_t(maxSeeds_))) {
612  output.clear();
613  edm::LogError("TooManySeeds") << "Found too many seeds, bailing out.\n";
614  return false;
615  }
616  }
617  }
618  return true;
619 }
620 
622  delete thePropagatorAl;
623  delete thePropagatorOp;
624  delete theUpdator;
625 }
Vector3DBase
Definition: Vector3DBase.h:8
SimpleCosmicBONSeeder::chargeThresholds_
std::vector< int32_t > chargeThresholds_
Definition: SimpleCosmicBONSeeder.h:94
TrackerGeometry::idToDet
const TrackerGeomDet * idToDet(DetId) const override
Definition: TrackerGeometry.cc:193
SiStripCluster::begin
uint8_t const * begin() const
Definition: SiStripCluster.h:62
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
eostools.ls
def ls(path, rec=False)
Definition: eostools.py:349
KFUpdator::update
TrajectoryStateOnSurface update(const TrajectoryStateOnSurface &, const TrackingRecHit &) const override
Definition: KFUpdator.cc:177
SimpleCosmicBONSeeder::thePropagatorAl
PropagatorWithMaterial * thePropagatorAl
Definition: SimpleCosmicBONSeeder.h:83
MagneticField::inTesla
virtual GlobalVector inTesla(const GlobalPoint &gp) const =0
Field value ad specified global point, in Tesla.
electrons_cff.bool
bool
Definition: electrons_cff.py:393
start
Definition: start.py:1
funct::false
false
Definition: Factorize.h:29
TrajectorySeedCollection
std::vector< TrajectorySeed > TrajectorySeedCollection
Definition: TrajectorySeedCollection.h:6
hfClusterShapes_cfi.hits
hits
Definition: hfClusterShapes_cfi.py:5
edm::isNotFinite
constexpr bool isNotFinite(T x)
Definition: isFinite.h:9
PV3DBase::x
T x() const
Definition: PV3DBase.h:59
FastHelix
Definition: FastHelix.h:26
DiDispStaMuonMonitor_cfi.pt
pt
Definition: DiDispStaMuonMonitor_cfi.py:39
convertSQLitetoXML_cfg.output
output
Definition: convertSQLitetoXML_cfg.py:72
min
T min(T a, T b)
Definition: MathUtil.h:58
SimpleCosmicBONSeeder::seedingLayerToken_
edm::EDGetTokenT< SeedingLayerSetsHits > seedingLayerToken_
Definition: SimpleCosmicBONSeeder.h:68
multPhiCorr_741_25nsDY_cfi.py
py
Definition: multPhiCorr_741_25nsDY_cfi.py:12
edm
HLT enums.
Definition: AlignableModifier.h:19
SimpleCosmicBONSeeder.h
TrackingRecHit::hit
virtual TrackingRecHit const * hit() const
Definition: TrackingRecHit.h:75
trajectoryStateTransform::persistentState
PTrajectoryStateOnDet persistentState(const TrajectoryStateOnSurface &ts, unsigned int detid)
Definition: TrajectoryStateTransform.cc:14
SeedingHit
SeedingHitSet::ConstRecHitPointer SeedingHit
Definition: SimpleCosmicBONSeeder.cc:14
SimpleCosmicBONSeeder::init
void init(const edm::EventSetup &c)
Definition: SimpleCosmicBONSeeder.cc:127
gather_cfg.cout
cout
Definition: gather_cfg.py:144
SeedingHitSet::ConstRecHitPointer
BaseTrackerRecHit const * ConstRecHitPointer
Definition: SeedingHitSet.h:10
SimpleCosmicBONSeeder::TTTRHBuilder
edm::ESHandle< TransientTrackingRecHitBuilder > TTTRHBuilder
Definition: SimpleCosmicBONSeeder.h:80
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89353
SimpleCosmicBONSeeder::seedOnMiddle_
bool seedOnMiddle_
Definition: SimpleCosmicBONSeeder.h:73
TransientRecHitRecord
Definition: TransientRecHitRecord.h:14
SeedingLayerSetsHits
Definition: SeedingLayerSetsHits.h:18
FastCircle::y0
double y0() const
Definition: FastCircle.h:45
HigherInnerHit
Definition: SimpleCosmicBONSeeder.cc:137
oppositeToMomentum
Definition: PropagationDirection.h:4
SimpleCosmicBONSeeder::checkCharge
bool checkCharge(const TrackingRecHit *hit) const
Definition: SimpleCosmicBONSeeder.cc:310
SimpleCosmicBONSeeder::triplets
bool triplets(const edm::Event &e, const edm::EventSetup &c)
Definition: SimpleCosmicBONSeeder.cc:171
SiStripRecHit2D
Definition: SiStripRecHit2D.h:7
edm::ParameterSet::existsAs
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:171
GlobalVector
Global3DVector GlobalVector
Definition: GlobalVector.h:10
GlobalTrackingRegion::hits
TrackingRegion::Hits hits(const edm::EventSetup &es, const SeedingLayerSetsHits::SeedingLayer &layer) const override
get hits from layer compatible with region constraints
Definition: GlobalTrackingRegion.cc:29
convertSQLiteXML.ok
bool ok
Definition: convertSQLiteXML.py:98
edm::Handle
Definition: AssociativeIterator.h:50
GlobalTrackingRegion
Definition: GlobalTrackingRegion.h:13
SimpleCosmicBONSeeder::seedVerbosity_
uint32_t seedVerbosity_
Definition: SimpleCosmicBONSeeder.h:76
SimpleCosmicBONSeeder::hitTriplets
OrderedHitTriplets hitTriplets
Definition: SimpleCosmicBONSeeder.h:89
SimpleCosmicBONSeeder::tripletsVerbosity_
uint32_t tripletsVerbosity_
Definition: SimpleCosmicBONSeeder.h:76
SimpleCosmicBONSeeder::done
void done()
Definition: SimpleCosmicBONSeeder.cc:621
SeedingLayerSetsHits::LayerSetIndex
unsigned short LayerSetIndex
Definition: SeedingLayerSetsHits.h:28
TkTransientTrackingRecHitBuilder
Definition: TkTransientTrackingRecHitBuilder.h:15
heavyIonCSV_trainingSettings.idx
idx
Definition: heavyIonCSV_trainingSettings.py:5
SiStripCluster::firstStrip
uint16_t firstStrip() const
Definition: SiStripCluster.h:47
SimpleCosmicBONSeeder::cloner
TkClonerImpl cloner
Definition: SimpleCosmicBONSeeder.h:81
SimpleCosmicBONSeeder::pqFromHelixFit
std::pair< GlobalVector, int > pqFromHelixFit(const GlobalPoint &inner, const GlobalPoint &middle, const GlobalPoint &outer, const edm::EventSetup &iSetup) const
Definition: SimpleCosmicBONSeeder.cc:403
PV3DBase::z
T z() const
Definition: PV3DBase.h:61
AlgebraicMatrixID
ROOT::Math::SMatrixIdentity AlgebraicMatrixID
Definition: AlgebraicROOTObjects.h:72
SimpleCosmicBONSeeder::builderName
std::string builderName
Definition: SimpleCosmicBONSeeder.h:66
IdealMagneticFieldRecord
Definition: IdealMagneticFieldRecord.h:11
Propagator
Definition: Propagator.h:44
DetId
Definition: DetId.h:17
SimpleCosmicBONSeeder::maxHitsPerModule_
std::vector< int32_t > maxHitsPerModule_
Definition: SimpleCosmicBONSeeder.h:96
TrajectoryStateOnSurface
Definition: TrajectoryStateOnSurface.h:16
PropagatorWithMaterial
Definition: PropagatorWithMaterial.h:25
SimpleCosmicBONSeeder::checkCharge_
bool checkCharge_
Definition: SimpleCosmicBONSeeder.h:92
FastCircle::rho
double rho() const
Definition: FastCircle.h:47
edm::EventSetup::get
T get() const
Definition: EventSetup.h:80
FreeTrajectoryState::cartesianError
CartesianTrajectoryError cartesianError() const
Definition: FreeTrajectoryState.h:81
CurvilinearTrajectoryError
Definition: CurvilinearTrajectoryError.h:27
SeedingLayerSetsHits.h
TrackCandidateProducer_cfi.propagator
propagator
Definition: TrackCandidateProducer_cfi.py:17
SimpleCosmicBONSeeder::magfield
edm::ESHandle< MagneticField > magfield
Definition: SimpleCosmicBONSeeder.h:78
std::swap
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
Definition: DataFrameContainer.h:209
SurfaceOrientation::inner
Definition: Surface.h:19
SimpleCosmicBONSeeder::rescaleError_
double rescaleError_
Definition: SimpleCosmicBONSeeder.h:74
TrackerDigiGeometryRecord
Definition: TrackerDigiGeometryRecord.h:15
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
SimpleCosmicBONSeeder::goodTriplet
bool goodTriplet(const GlobalPoint &inner, const GlobalPoint &middle, const GlobalPoint &outer, const double &minRho) const
Definition: SimpleCosmicBONSeeder.cc:376
mps_fire.end
end
Definition: mps_fire.py:242
MagneticField::nominalValue
int nominalValue() const
The nominal field value for this map in kGauss.
Definition: MagneticField.h:49
SiStripMatchedRecHit2D::stereoHit
SiStripRecHit2D stereoHit() const
Definition: SiStripMatchedRecHit2D.h:25
SimpleCosmicBONSeeder::conf_
edm::ParameterSet conf_
Definition: SimpleCosmicBONSeeder.h:65
SimpleCosmicBONSeeder::thePropagatorOp
PropagatorWithMaterial * thePropagatorOp
Definition: SimpleCosmicBONSeeder.h:84
StripSubdetector::TIB
static constexpr auto TIB
Definition: StripSubdetector.h:16
GlobalTrajectoryParameters
Definition: GlobalTrajectoryParameters.h:15
SimpleCosmicBONSeeder::produce
void produce(edm::Event &e, const edm::EventSetup &c) override
Definition: SimpleCosmicBONSeeder.cc:89
SimpleCosmicBONSeeder::check_
ClusterChecker check_
Definition: SimpleCosmicBONSeeder.h:86
GlobalPoint
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
TrackingRegion::ptMin
float ptMin() const
minimal pt of interest
Definition: TrackingRegion.h:83
Point3DBase< float, GlobalTag >
OrderedHitTriplet::middle
MiddleRecHit middle() const
Definition: OrderedHitTriplet.h:20
SimpleCosmicBONSeeder::theUpdator
KFUpdator * theUpdator
Definition: SimpleCosmicBONSeeder.h:82
SimpleCosmicBONSeeder::matchedRecHitUsesAnd_
bool matchedRecHitUsesAnd_
Definition: SimpleCosmicBONSeeder.h:93
SimpleCosmicBONSeeder::region_
GlobalTrackingRegion region_
Definition: SimpleCosmicBONSeeder.h:69
SimpleCosmicBONSeeder::seeds
bool seeds(TrajectorySeedCollection &output, const edm::EventSetup &iSetup)
Definition: SimpleCosmicBONSeeder.cc:456
DetId::subdetId
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum)
Definition: DetId.h:48
DDAxes::rho
SimpleCosmicBONSeeder::maxSeeds_
int32_t maxSeeds_
Definition: SimpleCosmicBONSeeder.h:87
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
OrderedHitTriplet::outer
OuterRecHit outer() const
Definition: OrderedHitTriplet.h:21
FastCircle::x0
double x0() const
Definition: FastCircle.h:43
ALCARECOTkAlJpsiMuMu_cff.charge
charge
Definition: ALCARECOTkAlJpsiMuMu_cff.py:47
ntuplemaker.fill
fill
Definition: ntuplemaker.py:304
SimpleCosmicBONSeeder::pMin_
double pMin_
Definition: SimpleCosmicBONSeeder.h:70
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
DetId::Tracker
Definition: DetId.h:25
SimpleCosmicBONSeeder::SimpleCosmicBONSeeder
SimpleCosmicBONSeeder(const edm::ParameterSet &conf)
Definition: SimpleCosmicBONSeeder.cc:25
ParameterSet
Definition: Functions.h:16
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
SiStripCluster::end
uint8_t const * end() const
Definition: SiStripCluster.h:63
SiStripMatchedRecHit2D::monoHit
SiStripRecHit2D monoHit() const
Definition: SiStripMatchedRecHit2D.h:26
PV3DBase::y
T y() const
Definition: PV3DBase.h:60
createfilelist.int
int
Definition: createfilelist.py:10
SimpleCosmicBONSeeder::writeTriplets_
bool writeTriplets_
Definition: SimpleCosmicBONSeeder.h:71
SimpleCosmicBONSeeder::checkNoisyModules
void checkNoisyModules(const std::vector< SeedingHitSet::ConstRecHitPointer > &hits, std::vector< bool > &oks) const
Definition: SimpleCosmicBONSeeder.cc:347
OrderedHitTriplets::size
unsigned int size() const override
Definition: OrderedHitTriplets.h:13
edm::EventSetup
Definition: EventSetup.h:57
FastCircle
Definition: FastCircle.h:33
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
SiStripCluster::amplitudes
SiStripCluster const & amplitudes() const
Definition: SiStripCluster.h:69
get
#define get
SimpleCosmicBONSeeder::helixVerbosity_
uint32_t helixVerbosity_
Definition: SimpleCosmicBONSeeder.h:76
TrackingRecHit::clone
virtual TrackingRecHit * clone() const =0
CartesianTrajectoryError::matrix
const AlgebraicSymMatrix66 & matrix() const
Definition: CartesianTrajectoryError.h:28
TrackingRecHit
Definition: TrackingRecHit.h:21
PV3DBase::mag
T mag() const
Definition: PV3DBase.h:64
multPhiCorr_741_25nsDY_cfi.px
px
Definition: multPhiCorr_741_25nsDY_cfi.py:10
HigherInnerHit::operator()
bool operator()(const OrderedHitTriplet &trip1, const OrderedHitTriplet &trip2) const
Definition: SimpleCosmicBONSeeder.cc:138
SimpleCosmicBONSeeder::negativeYOnly
bool negativeYOnly
Definition: SimpleCosmicBONSeeder.h:103
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
StripSubdetector::TEC
static constexpr auto TEC
Definition: StripSubdetector.h:19
isFinite.h
FreeTrajectoryState
Definition: FreeTrajectoryState.h:27
SiStripMatchedRecHit2D
Definition: SiStripMatchedRecHit2D.h:8
PVValHelper::dz
Definition: PVValidationHelpers.h:50
SimpleCosmicBONSeeder::tracker
edm::ESHandle< TrackerGeometry > tracker
Definition: SimpleCosmicBONSeeder.h:79
OrderedHitTriplet::inner
InnerRecHit inner() const
Definition: OrderedHitTriplet.h:19
ev
bool ev
Definition: Hydjet2Hadronizer.cc:95
SeedingLayerSetsHits::SeedingLayerSet
Definition: SeedingLayerSetsHits.h:65
StripSubdetector::TOB
static constexpr auto TOB
Definition: StripSubdetector.h:18
SimpleCosmicBONSeeder::goodHitsPerSeed_
int goodHitsPerSeed_
Definition: SimpleCosmicBONSeeder.h:91
ptmin
double ptmin
Definition: HydjetWrapper.h:84
OrderedHitTriplet
Definition: OrderedHitTriplet.h:11
TrajectorySeed
Definition: TrajectorySeed.h:18
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
ConsumesCollector.h
cms::Exception
Definition: Exception.h:70
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
PTrajectoryStateOnDet
Definition: PTrajectoryStateOnDet.h:10
command_line.start
start
Definition: command_line.py:167
SiStripMatchedRecHit2D.h
SurfaceOrientation::outer
Definition: Surface.h:19
SimpleCosmicBONSeeder::checkMaxHitsPerModule_
bool checkMaxHitsPerModule_
Definition: SimpleCosmicBONSeeder.h:95
edm::Event
Definition: Event.h:73
EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.cerr
cerr
Definition: EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.py:8
AlgebraicSymMatrix55
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
Definition: AlgebraicROOTObjects.h:23
SiStripCluster
Definition: SiStripCluster.h:9
ClusterChecker::tooManyClusters
size_t tooManyClusters(const edm::Event &e) const
Definition: ClusterChecker.cc:44
SiStripRecHit2D.h
PV3DBase::perp
T perp() const
Definition: PV3DBase.h:69
TSOS
TrajectoryStateOnSurface TSOS
Definition: TestHits.cc:19
alongMomentum
Definition: PropagationDirection.h:4
hgcalTopologyTester_cfi.layers
layers
Definition: hgcalTopologyTester_cfi.py:8
KFUpdator
Definition: KFUpdator.h:32
StripSubdetector::TID
static constexpr auto TID
Definition: StripSubdetector.h:17
hit
Definition: SiStripHitEffFromCalibTree.cc:88
SimpleCosmicBONSeeder::maxTriplets_
int32_t maxTriplets_
Definition: SimpleCosmicBONSeeder.h:87
FreeTrajectoryState::rescaleError
void rescaleError(double factor)
Definition: FreeTrajectoryState.cc:46
edm::OwnVector< TrackingRecHit >
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
SimpleCosmicBONSeeder::positiveYOnly
bool positiveYOnly
Definition: SimpleCosmicBONSeeder.h:102