CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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  : seedingLayerToken_(consumes<SeedingLayerSetsHits>(conf.getParameter<edm::InputTag>("TripletsSrc"))),
27  magfieldToken_(esConsumes()),
28  trackerToken_(esConsumes()),
29  ttrhBuilderToken_(esConsumes(edm::ESInputTag("", conf.getParameter<std::string>("TTRHBuilder")))),
30  writeTriplets_(conf.getParameter<bool>("writeTriplets")),
31  seedOnMiddle_(conf.existsAs<bool>("seedOnMiddle") ? conf.getParameter<bool>("seedOnMiddle") : false),
32  rescaleError_(conf.existsAs<double>("rescaleError") ? conf.getParameter<double>("rescaleError") : 1.0),
33  tripletsVerbosity_(conf.getUntrackedParameter<uint32_t>("TripletsDebugLevel", 0)),
34  seedVerbosity_(conf.getUntrackedParameter<uint32_t>("seedDebugLevel", 0)),
35  helixVerbosity_(conf.getUntrackedParameter<uint32_t>("helixDebugLevel", 0)),
36  check_(conf.getParameter<edm::ParameterSet>("ClusterCheckPSet"), consumesCollector()),
37  maxTriplets_(conf.getParameter<int32_t>("maxTriplets")),
38  maxSeeds_(conf.getParameter<int32_t>("maxSeeds")) {
39  edm::ParameterSet regionConf = conf.getParameter<edm::ParameterSet>("RegionPSet");
40  float ptmin = regionConf.getParameter<double>("ptMin");
41  float originradius = regionConf.getParameter<double>("originRadius");
42  float halflength = regionConf.getParameter<double>("originHalfLength");
43  float originz = regionConf.getParameter<double>("originZPosition");
44  region_ = GlobalTrackingRegion(ptmin, originradius, halflength, originz);
45  pMin_ = regionConf.getParameter<double>("pMin");
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");
63  chargeThresholds_[StripSubdetector::TID] = ccct.getParameter<int32_t>("TID");
64  chargeThresholds_[StripSubdetector::TOB] = ccct.getParameter<int32_t>("TOB");
65  chargeThresholds_[StripSubdetector::TEC] = ccct.getParameter<int32_t>("TEC");
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);
101  if (tripletsOk) {
102  bool seedsOk = seeds(*output);
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 
128  tracker = &iSetup.getData(trackerToken_);
129  cloner = dynamic_cast<TkTransientTrackingRecHitBuilder const &>(iSetup.getData(ttrhBuilderToken_)).cloner();
130  // FIXME: these should come from ES too!!
133  theUpdator = new KFUpdator();
134 }
135 
137  bool operator()(const OrderedHitTriplet &trip1, const OrderedHitTriplet &trip2) const {
138  //FIXME: inner gives a SEGV
139 #if 0
140  //const SeedingHitSet::ConstRecHitPointer &ihit1 = trip1.inner();
141  //const SeedingHitSet::ConstRecHitPointer &ihit2 = trip2.inner();
142  const SeedingHitSet::ConstRecHitPointer &ihit1 = trip1.middle();
143  const SeedingHitSet::ConstRecHitPointer &ihit2 = trip2.middle();
144  const SeedingHitSet::ConstRecHitPointer &ohit1 = trip1.outer();
145  const SeedingHitSet::ConstRecHitPointer &ohit2 = trip2.outer();
146 #endif
151  float iy1 = ihit1->globalPosition().y();
152  float oy1 = ohit1->globalPosition().y();
153  float iy2 = ihit2->globalPosition().y();
154  float oy2 = ohit2->globalPosition().y();
155  if (oy1 - iy1 > 0) { // 1 Downgoing
156  if (oy2 - iy2 > 0) { // 2 Downgoing
157  // sort by inner, or by outer if inners are the same
158  return (iy1 != iy2 ? (iy1 > iy2) : (oy1 > oy2));
159  } else
160  return true; // else prefer downgoing
161  } else if (oy2 - iy2 > 0) {
162  return false; // prefer downgoing
163  } else { // both upgoing
164  // sort by inner, or by outer
165  return (iy1 != iy2 ? (iy1 < iy2) : (oy1 < oy2));
166  }
167  }
168 };
169 
171  hitTriplets.clear();
172  hitTriplets.reserve(0);
174  e.getByToken(seedingLayerToken_, hlayers);
175  const SeedingLayerSetsHits &layers = *hlayers;
176  if (layers.numberOfLayersInSet() != 3)
177  throw cms::Exception("CtfSpecialSeedGenerator")
178  << "You are using " << layers.numberOfLayersInSet() << " layers in set instead of 3 ";
179 
180  double minRho = region_.ptMin() / (0.003 * magfield->inTesla(GlobalPoint(0, 0, 0)).z());
181 
182  for (SeedingLayerSetsHits::LayerSetIndex layerIndex = 0; layerIndex < layers.size(); ++layerIndex) {
183  SeedingLayerSetsHits::SeedingLayerSet ls = layers[layerIndex];
185  auto innerHits = region_.hits(ls[0]);
186  auto middleHits = region_.hits(ls[1]);
187  auto outerHits = region_.hits(ls[2]);
188 
189  if (tripletsVerbosity_ > 0) {
190  std::cout << "GenericTripletGenerator iLss = " << seedingLayersToString(ls) << " (" << layerIndex
191  << "): # = " << innerHits.size() << "/" << middleHits.size() << "/" << outerHits.size() << std::endl;
192  }
193 
196  std::vector<TTRH> innerTTRHs, middleTTRHs, outerTTRHs;
197 
199  std::vector<bool> innerOk(innerHits.size(), true);
200  std::vector<bool> middleOk(middleHits.size(), true);
201  std::vector<bool> outerOk(outerHits.size(), true);
202 
203  size_t sizBefore = hitTriplets.size();
205  int idx = 0;
206  for (auto iOuterHit = outerHits.begin(); iOuterHit != outerHits.end(); ++idx, ++iOuterHit) {
207  outerTTRHs.push_back(&(**iOuterHit));
208  if (checkCharge_ && !checkCharge(outerTTRHs.back()->hit()))
209  outerOk[idx] = false;
210  }
211  idx = 0;
212  for (auto iMiddleHit = middleHits.begin(); iMiddleHit != middleHits.end(); ++idx, ++iMiddleHit) {
213  middleTTRHs.push_back(&(**iMiddleHit));
214  if (checkCharge_ && !checkCharge(middleTTRHs.back()->hit()))
215  middleOk[idx] = false;
216  }
217  idx = 0;
218  for (auto iInnerHit = innerHits.begin(); iInnerHit != innerHits.end(); ++idx, ++iInnerHit) {
219  innerTTRHs.push_back(&(**iInnerHit));
220  if (checkCharge_ && !checkCharge(innerTTRHs.back()->hit()))
221  innerOk[idx] = false;
222  }
224  checkNoisyModules(innerTTRHs, innerOk);
225  checkNoisyModules(middleTTRHs, middleOk);
226  checkNoisyModules(outerTTRHs, outerOk);
227  }
228 
229  for (auto iOuterHit = outerHits.begin(); iOuterHit != outerHits.end(); iOuterHit++) {
230  idx = iOuterHit - outerHits.begin();
231  TTRH &outerTTRH = outerTTRHs[idx];
232  GlobalPoint outerpos = outerTTRH->globalPosition(); // this caches by itself
233  bool outerok = outerOk[idx];
234  if (outerok < goodHitsPerSeed_ - 2) {
235  if (tripletsVerbosity_ > 2)
236  std::cout << "Skipping at first hit: " << (outerok) << " < " << (goodHitsPerSeed_ - 2) << std::endl;
237  continue;
238  }
239 
240  for (auto iMiddleHit = middleHits.begin(); iMiddleHit != middleHits.end(); iMiddleHit++) {
241  idx = iMiddleHit - middleHits.begin();
242  TTRH &middleTTRH = middleTTRHs[idx];
243  GlobalPoint middlepos = middleTTRH->globalPosition(); // this caches by itself
244  bool middleok = middleOk[idx];
245  if (outerok + middleok < goodHitsPerSeed_ - 1) {
246  if (tripletsVerbosity_ > 2)
247  std::cout << "Skipping at second hit: " << (outerok + middleok) << " < " << (goodHitsPerSeed_ - 1)
248  << std::endl;
249  continue;
250  }
251 
252  for (auto iInnerHit = innerHits.begin(); iInnerHit != innerHits.end(); iInnerHit++) {
253  idx = iInnerHit - innerHits.begin();
254  TTRH &innerTTRH = innerTTRHs[idx];
255  GlobalPoint innerpos = innerTTRH->globalPosition(); // this caches by itself
256  bool innerok = innerOk[idx];
257  if (outerok + middleok + innerok < goodHitsPerSeed_) {
258  if (tripletsVerbosity_ > 2)
259  std::cout << "Skipping at third hit: " << (outerok + middleok + innerok) << " < " << (goodHitsPerSeed_)
260  << std::endl;
261  continue;
262  }
263 
264  //***top-bottom
265  if (positiveYOnly &&
266  (innerpos.y() < 0 || middlepos.y() < 0 || outerpos.y() < 0 || outerpos.y() < innerpos.y()))
267  continue;
268  if (negativeYOnly &&
269  (innerpos.y() > 0 || middlepos.y() > 0 || outerpos.y() > 0 || outerpos.y() > innerpos.y()))
270  continue;
271  //***
272 
273  if (tripletsVerbosity_ > 2)
274  std::cout << "Trying seed with: " << innerpos << " + " << middlepos << " + " << outerpos << std::endl;
275  if (goodTriplet(innerpos, middlepos, outerpos, minRho)) {
276  OrderedHitTriplet oht(&(**iInnerHit), &(**iMiddleHit), &(**iOuterHit));
277  hitTriplets.push_back(oht);
278  if ((maxTriplets_ > 0) && (hitTriplets.size() > size_t(maxTriplets_))) {
279  hitTriplets.clear(); // clear
280  //OrderedHitTriplets().swap(hitTriplets); // really clear
281  edm::LogError("TooManyTriplets") << "Found too many triplets, bailing out.\n";
282  return false;
283  }
284  if (tripletsVerbosity_ > 3) {
285  std::cout << " accepted seed #" << (hitTriplets.size() - 1) << " w/: " << innerpos << " + " << middlepos
286  << " + " << outerpos << std::endl;
287  }
288  if (tripletsVerbosity_ == 2) {
289  std::cout << " good seed #" << (hitTriplets.size() - 1) << " w/: " << innerpos << " + " << middlepos
290  << " + " << outerpos << std::endl;
291  }
292  if (tripletsVerbosity_ > 3 && (helixVerbosity_ > 0)) { // debug the momentum here too
293  pqFromHelixFit(innerpos, middlepos, outerpos);
294  }
295  }
296  }
297  }
298  }
299  if ((tripletsVerbosity_ > 0) && (hitTriplets.size() > sizBefore)) {
300  std::cout << " iLss = " << seedingLayersToString(ls) << " (" << layerIndex
301  << "): # = " << innerHits.size() << "/" << middleHits.size() << "/" << outerHits.size() << ": Found "
302  << (hitTriplets.size() - sizBefore) << " seeds [running total: " << hitTriplets.size() << "]"
303  << std::endl;
304  }
305  }
306  std::sort(hitTriplets.begin(), hitTriplets.end(), HigherInnerHit());
307  return true;
308 }
310  DetId detid(hit->geographicalId());
311  if (detid.det() != DetId::Tracker)
312  return false; // should not happen
313  int subdet = detid.subdetId();
314  if (subdet < 3) { // pixel
315  return true;
316  } else {
317  if (typeid(*hit) == typeid(SiStripMatchedRecHit2D)) {
318  const SiStripMatchedRecHit2D *mhit = static_cast<const SiStripMatchedRecHit2D *>(hit);
319  if (matchedRecHitUsesAnd_) {
320  return checkCharge(mhit->monoHit(), subdet) && checkCharge(mhit->stereoHit(), subdet);
321  } else {
322  return checkCharge(mhit->monoHit(), subdet) || checkCharge(mhit->stereoHit(), subdet);
323  }
324  } else if (typeid(*hit) == typeid(SiStripRecHit2D)) {
325  return checkCharge(static_cast<const SiStripRecHit2D &>(*hit), subdet);
326  } else {
327  return true;
328  }
329  }
330 }
331 
332 // to be fixed to use OmniCluster
333 bool SimpleCosmicBONSeeder::checkCharge(const SiStripRecHit2D &hit, int subdetid) const {
334  const SiStripCluster *clust = hit.cluster().get();
335  int charge = std::accumulate(clust->amplitudes().begin(), clust->amplitudes().end(), int(0));
336  if (tripletsVerbosity_ > 1) {
337  std::cerr << "Hit on " << subdetid << ", charge = " << charge << ", threshold = " << chargeThresholds_[subdetid]
338  << ", detid = " << hit.geographicalId().rawId() << ", firstStrip = " << clust->firstStrip() << std::endl;
339  } else if ((tripletsVerbosity_ == 1) && (charge < chargeThresholds_[subdetid])) {
340  std::cerr << "Hit on " << subdetid << ", charge = " << charge << ", threshold = " << chargeThresholds_[subdetid]
341  << ", detid = " << hit.geographicalId().rawId() << ", firstStrip = " << clust->firstStrip() << std::endl;
342  }
343  return charge > chargeThresholds_[subdetid];
344 }
345 
346 void SimpleCosmicBONSeeder::checkNoisyModules(const std::vector<SeedingHitSet::ConstRecHitPointer> &hits,
347  std::vector<bool> &oks) const {
349  std::vector<TTRH>::const_iterator it = hits.begin(), start = it, end = hits.end();
350  std::vector<bool>::iterator ok = oks.begin(), okStart = ok;
351  while (start < end) {
352  DetId lastid = (*start)->geographicalId();
353  for (it = start + 1; (it < end) && ((*it)->geographicalId() == lastid); ++it) {
354  ++ok;
355  }
356  if ((it - start) > maxHitsPerModule_[lastid.subdetId()]) {
357  if (tripletsVerbosity_ > 0) {
358  std::cerr << "SimpleCosmicBONSeeder: Marking noisy module " << lastid.rawId() << ", it has " << (it - start)
359  << " rechits"
360  << " (threshold is " << maxHitsPerModule_[lastid.subdetId()] << ")" << std::endl;
361  }
362  std::fill(okStart, ok, false);
363  } else if (tripletsVerbosity_ > 0) {
364  if ((it - start) > std::min(4, maxHitsPerModule_[lastid.subdetId()] / 4)) {
365  std::cerr << "SimpleCosmicBONSeeder: Not marking noisy module " << lastid.rawId() << ", it has " << (it - start)
366  << " rechits"
367  << " (threshold is " << maxHitsPerModule_[lastid.subdetId()] << ")" << std::endl;
368  }
369  }
370  start = it;
371  okStart = ok;
372  }
373 }
374 
376  const GlobalPoint &middle,
377  const GlobalPoint &outer,
378  const double &minRho) const {
379  float dyOM = outer.y() - middle.y(), dyIM = inner.y() - middle.y();
380  if ((dyOM * dyIM > 0) && (fabs(dyOM) > 10) && (fabs(dyIM) > 10)) {
381  if (tripletsVerbosity_ > 2)
382  std::cout << " fail for non coherent dy" << std::endl;
383  return false;
384  }
385  float dzOM = outer.z() - middle.z(), dzIM = inner.z() - middle.z();
386  if ((dzOM * dzIM > 0) && (fabs(dzOM) > 50) && (fabs(dzIM) > 50)) {
387  if (tripletsVerbosity_ > 2)
388  std::cout << " fail for non coherent dz" << std::endl;
389  return false;
390  }
391  if (minRho > 0) {
392  FastCircle theCircle(inner, middle, outer);
393  if (theCircle.rho() < minRho) {
394  if (tripletsVerbosity_ > 2)
395  std::cout << " fail for pt cut" << std::endl;
396  return false;
397  }
398  }
399  return true;
400 }
401 
402 std::pair<GlobalVector, int> SimpleCosmicBONSeeder::pqFromHelixFit(const GlobalPoint &inner,
403  const GlobalPoint &middle,
404  const GlobalPoint &outer) const {
405  if (helixVerbosity_ > 0) {
406  std::cout << "DEBUG PZ =====" << std::endl;
407  FastHelix helix(inner, middle, outer, magfield->nominalValue(), &*magfield);
408  GlobalVector gv = helix.stateAtVertex().momentum(); // status on inner hit
409  std::cout << "FastHelix P = " << gv << "\n";
410  std::cout << "FastHelix Q = " << helix.stateAtVertex().charge() << "\n";
411  }
412 
413  // My attempt (with different approx from FastHelix)
414  // 1) fit the circle
415  FastCircle theCircle(inner, middle, outer);
416  double rho = theCircle.rho();
417 
418  // 2) Get the PT
419  GlobalVector tesla = magfield->inTesla(middle);
420  double pt = 0.01 * rho * (0.3 * tesla.z());
421 
422  // 3) Get the PX,PY at OUTER hit (VERTEX)
423  double dx1 = outer.x() - theCircle.x0();
424  double dy1 = outer.y() - theCircle.y0();
425  double py = pt * dx1 / rho, px = -pt * dy1 / rho;
426  if (px * (middle.x() - outer.x()) + py * (middle.y() - outer.y()) < 0.) {
427  px *= -1.;
428  py *= -1.;
429  }
430 
431  // 4) Get the PZ through pz = pT*(dz/d(R*phi)))
432  double dz = inner.z() - outer.z();
433  double sinphi = (dx1 * (inner.y() - theCircle.y0()) - dy1 * (inner.x() - theCircle.x0())) / (rho * rho);
434  double dphi = std::abs(std::asin(sinphi));
435  double pz = pt * dz / (dphi * rho);
436 
437  int myq = ((theCircle.x0() * py - theCircle.y0() * px) / tesla.z()) > 0. ? +1 : -1;
438 
439  std::pair<GlobalVector, int> mypq(GlobalVector(px, py, pz), myq);
440 
441  if (helixVerbosity_ > 1) {
442  std::cout << "Gio: pt = " << pt << std::endl;
443  std::cout << "Gio: dz = " << dz << ", sinphi = " << sinphi << ", dphi = " << dphi
444  << ", dz/drphi = " << (dz / dphi / rho) << std::endl;
445  }
446  if (helixVerbosity_ > 0) {
447  std::cout << "Gio's fit P = " << mypq.first << "\n";
448  std::cout << "Gio's fit Q = " << myq << "\n";
449  }
450 
451  return mypq;
452 }
453 
456 
457  for (size_t it = 0; it < hitTriplets.size(); it++) {
458  OrderedHitTriplet &trip = hitTriplets.at(it);
459 
461  tracker->idToDet((*(trip.inner())).geographicalId())->surface().toGlobal((*(trip.inner())).localPosition());
462 
463  GlobalPoint middle =
464  tracker->idToDet((*(trip.middle())).geographicalId())->surface().toGlobal((*(trip.middle())).localPosition());
465 
467  tracker->idToDet((*(trip.outer())).geographicalId())->surface().toGlobal((*(trip.outer())).localPosition());
468 
469  if (seedVerbosity_ > 1)
470  std::cout << "Processing triplet " << it << ": " << inner << " + " << middle << " + " << outer << std::endl;
471 
472  if ((outer.y() - inner.y()) * outer.y() < 0) {
473  std::swap(inner, outer);
474  trip = OrderedHitTriplet(trip.outer(), trip.middle(), trip.inner());
475 
476  if (seedVerbosity_ > 1) {
477  std::cout << "The seed was going away from CMS! swapped in <-> out" << std::endl;
478  std::cout << "Processing swapped triplet " << it << ": " << inner << " + " << middle << " + " << outer
479  << std::endl;
480  }
481  }
482 
483  // First use FastHelix out of the box
484  std::pair<GlobalVector, int> pq = pqFromHelixFit(inner, middle, outer);
485  GlobalVector gv = pq.first;
486  float ch = pq.second;
487  float Mom = sqrt(gv.x() * gv.x() + gv.y() * gv.y() + gv.z() * gv.z());
488 
489  if (Mom > 10000 || edm::isNotFinite(Mom)) {
490  if (seedVerbosity_ > 1)
491  std::cout << "Processing triplet " << it << ": fail for momentum." << std::endl;
492  continue;
493  }
494 
495  if (gv.perp() < region_.ptMin()) {
496  if (seedVerbosity_ > 1)
497  std::cout << "Processing triplet " << it << ": fail for pt = " << gv.perp() << " < ptMin = " << region_.ptMin()
498  << std::endl;
499  continue;
500  }
501 
502  const Propagator *propagator = nullptr;
503  if ((outer.y() - inner.y()) > 0) {
504  if (seedVerbosity_ > 1)
505  std::cout << "Processing triplet " << it << ": downgoing." << std::endl;
506  propagator = thePropagatorAl;
507  } else {
508  gv = -1 * gv;
509  ch = -1. * ch;
510  propagator = thePropagatorOp;
511  if (seedVerbosity_ > 1)
512  std::cout << "Processing triplet " << it << ": upgoing." << std::endl;
513  }
514 
515  if (seedVerbosity_ > 1) {
516  if ((gv.z() * (outer.z() - inner.z()) > 0) && (fabs(outer.z() - inner.z()) > 5) && (fabs(gv.z()) > .01)) {
517  std::cout << "ORRORE: outer.z()-inner.z() = " << (outer.z() - inner.z()) << ", gv.z() = " << gv.z()
518  << std::endl;
519  }
520  }
521 
522  GlobalTrajectoryParameters Gtp(outer, gv, int(ch), &(*magfield));
524  CosmicSeed.rescaleError(100);
525  if (seedVerbosity_ > 2) {
526  std::cout << "Processing triplet " << it << ". start from " << std::endl;
527  std::cout << " X = " << outer << ", P = " << gv << std::endl;
528  std::cout << " Cartesian error (X,P) = \n" << CosmicSeed.cartesianError().matrix() << std::endl;
529  }
530 
532  OrderedHitTriplet seedHits(trip.outer(), trip.middle(), trip.inner());
533  TSOS propagated, updated;
534  bool fail = false;
535  for (size_t ih = 0; ih < 3; ++ih) {
536  if ((ih == 2) && seedOnMiddle_) {
537  if (seedVerbosity_ > 2)
538  std::cout << "Stopping at middle hit, as requested." << std::endl;
539  break;
540  }
541  if (seedVerbosity_ > 2)
542  std::cout << "Processing triplet " << it << ", hit " << ih << "." << std::endl;
543  if (ih == 0) {
544  propagated = propagator->propagate(CosmicSeed, tracker->idToDet((*seedHits[ih]).geographicalId())->surface());
545  } else {
546  propagated = propagator->propagate(updated, tracker->idToDet((*seedHits[ih]).geographicalId())->surface());
547  }
548  if (!propagated.isValid()) {
549  if (seedVerbosity_ > 1)
550  std::cout << "Processing triplet " << it << ", hit " << ih << ": failed propagation." << std::endl;
551  fail = true;
552  break;
553  } else {
554  if (seedVerbosity_ > 2)
555  std::cout << "Processing triplet " << it << ", hit " << ih << ": propagated state = " << propagated;
556  }
557  SeedingHitSet::ConstRecHitPointer tthp = seedHits[ih];
558  auto newtth = static_cast<SeedingHitSet::RecHitPointer>(cloner(*tthp, propagated));
559  updated = theUpdator->update(propagated, *newtth);
560  hits.push_back(newtth);
561  if (!updated.isValid()) {
562  if (seedVerbosity_ > 1)
563  std::cout << "Processing triplet " << it << ", hit " << ih << ": failed update." << std::endl;
564  fail = true;
565  break;
566  } else {
567  if (seedVerbosity_ > 2)
568  std::cout << "Processing triplet " << it << ", hit " << ih << ": updated state = " << updated;
569  }
570  }
571  if (!fail && updated.isValid() && (updated.globalMomentum().perp() < region_.ptMin())) {
572  if (seedVerbosity_ > 1)
573  std::cout << "Processing triplet " << it << ": failed for final pt " << updated.globalMomentum().perp() << " < "
574  << region_.ptMin() << std::endl;
575  fail = true;
576  }
577  if (!fail && updated.isValid() && (updated.globalMomentum().mag() < pMin_)) {
578  if (seedVerbosity_ > 1)
579  std::cout << "Processing triplet " << it << ": failed for final p " << updated.globalMomentum().perp() << " < "
580  << pMin_ << std::endl;
581  fail = true;
582  }
583  if (!fail) {
584  if (rescaleError_ != 1.0) {
585  if (seedVerbosity_ > 2) {
586  std::cout << "Processing triplet " << it << ", rescale error by " << rescaleError_
587  << ": state BEFORE rescaling " << updated;
588  std::cout << " Cartesian error (X,P) before rescaling= \n"
589  << updated.cartesianError().matrix() << std::endl;
590  }
591  updated.rescaleError(rescaleError_);
592  }
593  if (seedVerbosity_ > 0) {
594  std::cout << "Processed triplet " << it << ": success (saved as #" << output.size() << ") : " << inner << " + "
595  << middle << " + " << outer << std::endl;
596  std::cout << " pt = " << updated.globalMomentum().perp() << " eta = " << updated.globalMomentum().eta()
597  << " phi = " << updated.globalMomentum().phi() << " ch = " << updated.charge() << std::endl;
598  if (seedVerbosity_ > 1) {
599  std::cout << " State:" << updated;
600  } else {
601  std::cout << " X = " << updated.globalPosition() << ", P = " << updated.globalMomentum() << std::endl;
602  }
603  std::cout << " Cartesian error (X,P) = \n" << updated.cartesianError().matrix() << std::endl;
604  }
605 
607  updated, (*(seedOnMiddle_ ? trip.middle() : trip.inner())).geographicalId().rawId());
608  output.push_back(TrajectorySeed(PTraj, hits, ((outer.y() - inner.y() > 0) ? alongMomentum : oppositeToMomentum)));
609  if ((maxSeeds_ > 0) && (output.size() > size_t(maxSeeds_))) {
610  output.clear();
611  edm::LogError("TooManySeeds") << "Found too many seeds, bailing out.\n";
612  return false;
613  }
614  }
615  }
616  return true;
617 }
618 
620  delete thePropagatorAl;
621  delete thePropagatorOp;
622  delete theUpdator;
623 }
static constexpr auto TEC
GlobalTrackingRegion region_
tuple propagator
unsigned short numberOfLayersInSet() const
Get number of layers in each SeedingLayerSets.
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
void init(const edm::EventSetup &c)
std::vector< LayerSetAndLayers > layers(const SeedingLayerSetsHits &sets)
Definition: LayerTriplets.cc:4
CartesianTrajectoryError cartesianError() const
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:171
T perp() const
Definition: PV3DBase.h:69
std::pair< GlobalVector, int > pqFromHelixFit(const GlobalPoint &inner, const GlobalPoint &middle, const GlobalPoint &outer) const
const TrackerGeometry * tracker
MiddleRecHit middle() const
int nominalValue() const
The nominal field value for this map in kGauss.
Definition: MagneticField.h:49
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
double x0() const
Definition: FastCircle.h:43
constexpr bool isNotFinite(T x)
Definition: isFinite.h:9
virtual GlobalVector inTesla(const GlobalPoint &gp) const =0
Field value ad specified global point, in Tesla.
const edm::EDGetTokenT< SeedingLayerSetsHits > seedingLayerToken_
ROOT::Math::SMatrixIdentity AlgebraicMatrixID
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:49
SiStripCluster const & amplitudes() const
unsigned short LayerSetIndex
OrderedHitTriplets hitTriplets
def ls
Definition: eostools.py:349
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
PTrajectoryStateOnDet persistentState(const TrajectoryStateOnSurface &ts, unsigned int detid)
T y() const
Definition: PV3DBase.h:60
uint16_t firstStrip() const
bool seeds(TrajectorySeedCollection &output)
bool checkCharge(const TrackingRecHit *hit) const
Log< level::Error, false > LogError
double rho() const
Definition: FastCircle.h:47
constexpr std::array< uint8_t, layerIndexSize > layer
SimpleCosmicBONSeeder(const edm::ParameterSet &conf)
bool getData(T &iHolder) const
Definition: EventSetup.h:122
InnerRecHit inner() const
void push_back(D *&d)
Definition: OwnVector.h:326
BaseTrackerRecHit const * ConstRecHitPointer
Definition: SeedingHitSet.h:14
TrackingRegion::Hits hits(const SeedingLayerSetsHits::SeedingLayer &layer) const override
get hits from layer compatible with region constraints
TrajectoryStateOnSurface update(const TrajectoryStateOnSurface &, const TrackingRecHit &) const override
Definition: KFUpdator.cc:177
std::vector< TrajectorySeed > TrajectorySeedCollection
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
T sqrt(T t)
Definition: SSEVec.h:19
bool triplets(const edm::Event &e)
PropagatorWithMaterial * thePropagatorOp
T z() const
Definition: PV3DBase.h:61
def move
Definition: eostools.py:511
size_t tooManyClusters(const edm::Event &e) const
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ClusterRef cluster() const
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:232
static constexpr auto TOB
auto const * begin() const
const MagneticField * magfield
const TrackerGeomDet * idToDet(DetId) const override
PropagatorWithMaterial * thePropagatorAl
const AlgebraicSymMatrix66 & matrix() const
virtual TrackingRecHit * clone() const =0
Definition: DetId.h:17
TrajectoryStateOnSurface TSOS
Definition: TestHits.cc:19
virtual TrackingRecHit const * hit() const
void rescaleError(double factor)
static constexpr auto TIB
SiStripRecHit2D stereoHit() const
void fill(std::map< std::string, TH1 * > &h, const std::string &s, double x)
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
float ptMin() const
minimal pt of interest
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > trackerToken_
TrajectoryStateOnSurface propagate(STA const &state, SUR const &surface) const
Definition: Propagator.h:50
auto const * end() const
bool goodTriplet(const GlobalPoint &inner, const GlobalPoint &middle, const GlobalPoint &outer, const double &minRho) const
SiStripRecHit2D monoHit() const
bool operator()(const OrderedHitTriplet &trip1, const OrderedHitTriplet &trip2) const
double ptmin
Definition: HydjetWrapper.h:84
double y0() const
Definition: FastCircle.h:45
void produce(edm::Event &e, const edm::EventSetup &c) override
string end
Definition: dataset.py:937
BaseTrackerRecHit const * SeedingHit
std::vector< int32_t > chargeThresholds_
tuple cout
Definition: gather_cfg.py:144
void checkNoisyModules(const std::vector< SeedingHitSet::ConstRecHitPointer > &hits, std::vector< bool > &oks) const
std::vector< int32_t > maxHitsPerModule_
DetId geographicalId() const
OuterRecHit outer() const
const edm::ESGetToken< TransientTrackingRecHitBuilder, TransientRecHitRecord > ttrhBuilderToken_
T x() const
Definition: PV3DBase.h:59
static constexpr auto TID
unsigned short size() const
Get the number of SeedingLayerSets.
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
unsigned int size() const override
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > magfieldToken_
Global3DVector GlobalVector
Definition: GlobalVector.h:10