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 }
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 {
38  edm::ParameterSet regionConf = conf_.getParameter<edm::ParameterSet>("RegionPSet");
39  float ptmin = regionConf.getParameter<double>("ptMin");
40  float originradius = regionConf.getParameter<double>("originRadius");
41  float halflength = regionConf.getParameter<double>("originHalfLength");
42  float originz = regionConf.getParameter<double>("originZPosition");
43  region_ = GlobalTrackingRegion(ptmin, originradius, halflength, originz);
44  pMin_ = regionConf.getParameter<double>("pMin");
45 
46  builderName = conf_.getParameter<std::string>("TTRHBuilder");
47 
48  //***top-bottom
49  positiveYOnly=conf_.getParameter<bool>("PositiveYOnly");
50  negativeYOnly=conf_.getParameter<bool>("NegativeYOnly");
51  //***
52 
53  produces<TrajectorySeedCollection>();
54  if (writeTriplets_) 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 
89 // Functions that gets called by framework every event
91 {
92  auto output = std::make_unique<TrajectorySeedCollection>();
93  auto outtriplets = std::make_unique<edm::OwnVector<TrackingRecHit>>();
94 
96  if (magfield->inTesla(GlobalPoint(0,0,0)).mag() > 0.01) {
97  size_t clustsOrZero = check_.tooManyClusters(ev);
98  if (clustsOrZero) {
99  edm::LogError("TooManyClusters") << "Found too many clusters (" << clustsOrZero << "), bailing out.\n";
100  } else {
101  init(es);
102  bool tripletsOk = triplets(ev,es);
103  if (tripletsOk) {
104 
105  bool seedsOk = seeds(*output,es);
106  if (!seedsOk) { }
107 
108  if (writeTriplets_) {
109  for (OrderedHitTriplets::const_iterator it = hitTriplets.begin(); it != hitTriplets.end(); ++it) {
110  const TrackingRecHit * hit1 = it->inner()->hit();
111  const TrackingRecHit * hit2 = it->middle()->hit();
112  const TrackingRecHit * hit3 = it->outer()->hit();
113  outtriplets->push_back(hit1->clone());
114  outtriplets->push_back(hit2->clone());
115  outtriplets->push_back(hit3->clone());
116  }
117  }
118  }
119  done();
120  }
121  }
122 
123  if (writeTriplets_) {
124  ev.put(std::move(outtriplets), "cosmicTriplets");
125  }
126  ev.put(std::move(output));
127 }
128 
129 void
131 {
132  iSetup.get<TrackerDigiGeometryRecord>().get(tracker);
134  cloner = ((TkTransientTrackingRecHitBuilder const *)(TTTRHBuilder.product()))->cloner();
135  // FIXME: these should come from ES too!!
138  theUpdator = new KFUpdator();
139 
140 }
141 
143  bool operator()(const OrderedHitTriplet &trip1, const OrderedHitTriplet &trip2) const {
144  //FIXME: inner gives a SEGV
145 #if 0
146  //const SeedingHitSet::ConstRecHitPointer &ihit1 = trip1.inner();
147  //const SeedingHitSet::ConstRecHitPointer &ihit2 = trip2.inner();
148  const SeedingHitSet::ConstRecHitPointer &ihit1 = trip1.middle();
149  const SeedingHitSet::ConstRecHitPointer &ihit2 = trip2.middle();
150  const SeedingHitSet::ConstRecHitPointer &ohit1 = trip1.outer();
151  const SeedingHitSet::ConstRecHitPointer &ohit2 = trip2.outer();
152 #endif
157  float iy1 = ihit1->globalPosition().y();
158  float oy1 = ohit1->globalPosition().y();
159  float iy2 = ihit2->globalPosition().y();
160  float oy2 = ohit2->globalPosition().y();
161  if (oy1 - iy1 > 0) { // 1 Downgoing
162  if (oy2 - iy2 > 0) { // 2 Downgoing
163  // sort by inner, or by outer if inners are the same
164  return (iy1 != iy2 ? (iy1 > iy2) : (oy1 > oy2));
165  } else return true; // else prefer downgoing
166  } else if (oy2 - iy2 > 0) {
167  return false; // prefer downgoing
168  } else { // both upgoing
169  // sort by inner, or by outer
170  return (iy1 != iy2 ? (iy1 < iy2) : (oy1 < oy2));
171  }
172  }
173 };
174 
176  hitTriplets.clear();
177  hitTriplets.reserve(0);
179  e.getByToken(seedingLayerToken_, hlayers);
180  const SeedingLayerSetsHits& layers = *hlayers;
181  if(layers.numberOfLayersInSet() != 3)
182  throw cms::Exception("CtfSpecialSeedGenerator") << "You are using " << layers.numberOfLayersInSet() <<" layers in set instead of 3 ";
183 
184  double minRho = region_.ptMin() / ( 0.003 * magfield->inTesla(GlobalPoint(0,0,0)).z() );
185 
186  for(SeedingLayerSetsHits::LayerSetIndex layerIndex=0; layerIndex < layers.size(); ++layerIndex) {
187  SeedingLayerSetsHits::SeedingLayerSet ls = layers[layerIndex];
189  auto innerHits = region_.hits(es, ls[0]);
190  auto middleHits = region_.hits(es, ls[1]);
191  auto outerHits = region_.hits(es, ls[2]);
192 
193  if (tripletsVerbosity_ > 0) {
194  std::cout << "GenericTripletGenerator iLss = " << seedingLayersToString(ls)
195  << " (" << layerIndex << "): # = "
196  << innerHits.size() << "/" << middleHits.size() << "/" << outerHits.size() << std::endl;
197  }
198 
201  std::vector<TTRH> innerTTRHs, middleTTRHs, outerTTRHs;
202 
204  std::vector<bool> innerOk( innerHits.size(), true);
205  std::vector<bool> middleOk(middleHits.size(), true);
206  std::vector<bool> outerOk( outerHits.size(), true);
207 
208  size_t sizBefore = hitTriplets.size();
210  int idx = 0;
211  for (auto iOuterHit = outerHits.begin(); iOuterHit != outerHits.end(); ++idx, ++iOuterHit){
212  outerTTRHs.push_back(&(**iOuterHit));
213  if (checkCharge_ && !checkCharge(outerTTRHs.back()->hit())) outerOk[idx] = false;
214  }
215  idx = 0;
216  for (auto iMiddleHit = middleHits.begin(); iMiddleHit != middleHits.end(); ++idx, ++iMiddleHit){
217  middleTTRHs.push_back(&(**iMiddleHit));
218  if (checkCharge_ && !checkCharge(middleTTRHs.back()->hit())) middleOk[idx] = false;
219  }
220  idx = 0;
221  for (auto iInnerHit = innerHits.begin(); iInnerHit != innerHits.end(); ++idx, ++iInnerHit){
222  innerTTRHs.push_back(&(**iInnerHit));
223  if (checkCharge_ && !checkCharge(innerTTRHs.back()->hit())) innerOk[idx] = false;
224  }
226  checkNoisyModules(innerTTRHs, innerOk);
227  checkNoisyModules(middleTTRHs, middleOk);
228  checkNoisyModules(outerTTRHs, outerOk);
229  }
230 
231  for (auto iOuterHit = outerHits.begin(); iOuterHit != outerHits.end(); iOuterHit++){
232  idx = iOuterHit - outerHits.begin();
233  TTRH & outerTTRH = outerTTRHs[idx];
234  GlobalPoint outerpos = outerTTRH->globalPosition(); // this caches by itself
235  bool outerok = outerOk[idx];
236  if (outerok < goodHitsPerSeed_ - 2) {
237  if (tripletsVerbosity_ > 2)
238  std::cout << "Skipping at first hit: " << (outerok) << " < " << (goodHitsPerSeed_ - 2) << std::endl;
239  continue;
240  }
241 
242  for (auto iMiddleHit = middleHits.begin(); iMiddleHit != middleHits.end(); iMiddleHit++){
243  idx = iMiddleHit - middleHits.begin();
244  TTRH & middleTTRH = middleTTRHs[idx];
245  GlobalPoint middlepos = middleTTRH->globalPosition(); // this caches by itself
246  bool middleok = middleOk[idx];
247  if (outerok+middleok < goodHitsPerSeed_ - 1) {
248  if (tripletsVerbosity_ > 2)
249  std::cout << "Skipping at second hit: " << (outerok+middleok) << " < " << (goodHitsPerSeed_ - 1) << 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_) << std::endl;
261  continue;
262  }
263 
264  //***top-bottom
265  if (positiveYOnly && (innerpos.y()<0 || middlepos.y()<0 || outerpos.y()<0
266  || outerpos.y() < innerpos.y()
267  ) ) continue;
268  if (negativeYOnly && (innerpos.y()>0 || middlepos.y()>0 || outerpos.y()>0
269  || outerpos.y() > innerpos.y()
270  ) ) continue;
271  //***
272 
273  if (tripletsVerbosity_ > 2) std::cout << "Trying seed with: " << innerpos << " + " << middlepos << " + " << outerpos << std::endl;
274  if (goodTriplet(innerpos,middlepos,outerpos,minRho)) {
275  OrderedHitTriplet oht(&(**iInnerHit),&(**iMiddleHit),&(**iOuterHit));
276  hitTriplets.push_back(oht);
277  if ((maxTriplets_ > 0) && (hitTriplets.size() > size_t(maxTriplets_))) {
278  hitTriplets.clear(); // clear
279  //OrderedHitTriplets().swap(hitTriplets); // really clear
280  edm::LogError("TooManyTriplets") << "Found too many triplets, bailing out.\n";
281  return false;
282  }
283  if (tripletsVerbosity_ > 3) {
284  std::cout << " accepted seed #" << (hitTriplets.size()-1) << " w/: "
285  << innerpos << " + " << middlepos << " + " << outerpos << std::endl;
286  }
287  if (tripletsVerbosity_ == 2) {
288  std::cout << " good seed #" << (hitTriplets.size()-1) << " w/: "
289  << innerpos << " + " << middlepos << " + " << outerpos << std::endl;
290  }
291  if (tripletsVerbosity_ > 3 && (helixVerbosity_ > 0)) { // debug the momentum here too
292  pqFromHelixFit(innerpos,middlepos,outerpos,es);
293  }
294  }
295  }
296  }
297  }
298  if ((tripletsVerbosity_ > 0) && (hitTriplets.size() > sizBefore)) {
299  std::cout << " iLss = " << seedingLayersToString(ls)
300  << " (" << layerIndex << "): # = "
301  << innerHits.size() << "/" << middleHits.size() << "/" << outerHits.size()
302  << ": Found " << (hitTriplets.size() - sizBefore) << " seeds [running total: " << hitTriplets.size() << "]"
303  << std::endl ;
304  }
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) 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, std::vector<bool> &oks) const {
348  std::vector<TTRH>::const_iterator it = hits.begin(), start = it, end = hits.end();
349  std::vector<bool>::iterator ok = oks.begin(), okStart = ok;
350  while (start < end) {
351  DetId lastid = (*start)->geographicalId();
352  for (it = start + 1; (it < end) && ((*it)->geographicalId() == lastid); ++it) {
353  ++ok;
354  }
355  if ( (it - start) > maxHitsPerModule_[lastid.subdetId()] ) {
356  if (tripletsVerbosity_ > 0) {
357  std::cerr << "SimpleCosmicBONSeeder: Marking noisy module " << lastid.rawId() << ", it has " << (it-start) << " rechits"
358  << " (threshold is " << maxHitsPerModule_[lastid.subdetId()] << ")" << std::endl;
359  }
360  std::fill(okStart,ok,false);
361  } else if (tripletsVerbosity_ > 0) {
362  if ( (it - start) > std::min(4,maxHitsPerModule_[lastid.subdetId()]/4) ) {
363  std::cerr << "SimpleCosmicBONSeeder: Not marking noisy module " << lastid.rawId() << ", it has " << (it-start) << " rechits"
364  << " (threshold is " << maxHitsPerModule_[lastid.subdetId()] << ")" << std::endl;
365  }
366  }
367  start = it; okStart = ok;
368  }
369 }
370 
371 bool SimpleCosmicBONSeeder::goodTriplet(const GlobalPoint &inner, const GlobalPoint & middle, const GlobalPoint & outer, const double &minRho) const {
372  float dyOM = outer.y() - middle.y(), dyIM = inner.y() - middle.y();
373  if ((dyOM * dyIM > 0) && (fabs(dyOM)>10) && (fabs(dyIM)>10)) {
374  if (tripletsVerbosity_ > 2) std::cout << " fail for non coherent dy" << std::endl;
375  return false;
376  }
377  float dzOM = outer.z() - middle.z(), dzIM = inner.z() - middle.z();
378  if ((dzOM * dzIM > 0) && (fabs(dzOM)>50) && (fabs(dzIM)>50)) {
379  if (tripletsVerbosity_ > 2) std::cout << " fail for non coherent dz" << std::endl;
380  return false;
381  }
382  if (minRho > 0) {
383  FastCircle theCircle(inner,middle,outer);
384  if (theCircle.rho() < minRho) {
385  if (tripletsVerbosity_ > 2) std::cout << " fail for pt cut" << std::endl;
386  return false;
387  }
388  }
389  return true;
390 }
391 
392 std::pair<GlobalVector,int>
394  const edm::EventSetup& iSetup) const {
395  if (helixVerbosity_ > 0) {
396  std::cout << "DEBUG PZ =====" << std::endl;
397  FastHelix helix(inner,middle,outer,magfield->nominalValue(), &*magfield);
398  GlobalVector gv=helix.stateAtVertex().momentum(); // status on inner hit
399  std::cout << "FastHelix P = " << gv << "\n";
400  std::cout << "FastHelix Q = " << helix.stateAtVertex().charge() << "\n";
401  }
402 
403  // My attempt (with different approx from FastHelix)
404  // 1) fit the circle
405  FastCircle theCircle(inner,middle,outer);
406  double rho = theCircle.rho();
407 
408  // 2) Get the PT
409  GlobalVector tesla = magfield->inTesla(middle);
410  double pt = 0.01 * rho * (0.3*tesla.z());
411 
412  // 3) Get the PX,PY at OUTER hit (VERTEX)
413  double dx1 = outer.x()-theCircle.x0();
414  double dy1 = outer.y()-theCircle.y0();
415  double py = pt*dx1/rho, px = -pt*dy1/rho;
416  if(px*(middle.x() - outer.x()) + py*(middle.y() - outer.y()) < 0.) {
417  px *= -1.; py *= -1.;
418  }
419 
420  // 4) Get the PZ through pz = pT*(dz/d(R*phi)))
421  double dz = inner.z() - outer.z();
422  double sinphi = ( dx1*(inner.y()-theCircle.y0()) - dy1*(inner.x()-theCircle.x0())) / (rho * rho);
423  double dphi = std::abs(std::asin(sinphi));
424  double pz = pt * dz / (dphi * rho);
425 
426  int myq = ((theCircle.x0()*py - theCircle.y0()*px) / tesla.z()) > 0. ? +1 : -1;
427 
428  std::pair<GlobalVector,int> mypq(GlobalVector(px,py,pz),myq);
429 
430  if (helixVerbosity_ > 1) {
431  std::cout << "Gio: pt = " << pt << std::endl;
432  std::cout << "Gio: dz = " << dz << ", sinphi = " << sinphi << ", dphi = " << dphi << ", dz/drphi = " << (dz/dphi/rho) << std::endl;
433  }
434  if (helixVerbosity_ > 0) {
435  std::cout << "Gio's fit P = " << mypq.first << "\n";
436  std::cout << "Gio's fit Q = " << myq << "\n";
437  }
438 
439  return mypq;
440 }
441 
443 {
445 
446  for (size_t it=0;it<hitTriplets.size();it++){
447  OrderedHitTriplet &trip = hitTriplets.at(it);
448 
449  GlobalPoint inner = tracker->idToDet((*(trip.inner())).geographicalId())->surface().
450  toGlobal((*(trip.inner())).localPosition());
451 
452  GlobalPoint middle = tracker->idToDet((*(trip.middle())).geographicalId())->surface().
453  toGlobal((*(trip.middle())).localPosition());
454 
455  GlobalPoint outer = tracker->idToDet((*(trip.outer())).geographicalId())->surface().
456  toGlobal((*(trip.outer())).localPosition());
457 
458  if (seedVerbosity_ > 1)
459  std::cout << "Processing triplet " << it << ": " << inner << " + " << middle << " + " << outer << std::endl;
460 
461  if ( (outer.y()-inner.y())*outer.y() < 0 ) {
462  std::swap(inner,outer);
463  trip = OrderedHitTriplet(trip.outer(),trip.middle(),trip.inner());
464 
465  if (seedVerbosity_ > 1) {
466  std::cout << "The seed was going away from CMS! swapped in <-> out" << std::endl;
467  std::cout << "Processing swapped triplet " << it << ": " << inner << " + " << middle << " + " << outer << std::endl;
468  }
469  }
470 
471  // First use FastHelix out of the box
472  std::pair<GlobalVector,int> pq = pqFromHelixFit(inner,middle,outer,iSetup);
473  GlobalVector gv = pq.first;
474  float ch = pq.second;
475  float Mom = sqrt( gv.x()*gv.x() + gv.y()*gv.y() + gv.z()*gv.z() );
476 
477  if(Mom > 10000 || edm::isNotFinite(Mom)) {
478  if (seedVerbosity_ > 1)
479  std::cout << "Processing triplet " << it << ": fail for momentum." << std::endl;
480  continue;
481  }
482 
483  if (gv.perp() < region_.ptMin()) {
484  if (seedVerbosity_ > 1)
485  std::cout << "Processing triplet " << it << ": fail for pt = " << gv.perp() << " < ptMin = " << region_.ptMin() << std::endl;
486  continue;
487  }
488 
489  const Propagator * propagator = nullptr;
490  if((outer.y()-inner.y())>0){
491  if (seedVerbosity_ > 1)
492  std::cout << "Processing triplet " << it << ": downgoing." << std::endl;
493  propagator = thePropagatorAl;
494  } else {
495  gv = -1*gv; ch = -1.*ch;
496  propagator = thePropagatorOp;
497  if (seedVerbosity_ > 1)
498  std::cout << "Processing triplet " << it << ": upgoing." << std::endl;
499  }
500 
501  if (seedVerbosity_ > 1) {
502  if (( gv.z() * (outer.z()-inner.z()) > 0 ) && ( fabs(outer.z()-inner.z()) > 5) && (fabs(gv.z()) > .01)) {
503  std::cout << "ORRORE: outer.z()-inner.z() = " << (outer.z()-inner.z()) << ", gv.z() = " << gv.z() << std::endl;
504  }
505  }
506 
507  GlobalTrajectoryParameters Gtp(outer,
508  gv,int(ch),
509  &(*magfield));
510  FreeTrajectoryState CosmicSeed(Gtp,
512  CosmicSeed.rescaleError(100);
513  if (seedVerbosity_ > 2) {
514  std::cout << "Processing triplet " << it << ". start from " << std::endl;
515  std::cout << " X = " << outer << ", P = " << gv << std::endl;
516  std::cout << " Cartesian error (X,P) = \n" << CosmicSeed.cartesianError().matrix() << std::endl;
517  }
518 
520  OrderedHitTriplet seedHits(trip.outer(),trip.middle(),trip.inner());
521  TSOS propagated, updated;
522  bool fail = false;
523  for (size_t ih = 0; ih < 3; ++ih) {
524  if ((ih == 2) && seedOnMiddle_) {
525  if (seedVerbosity_ > 2)
526  std::cout << "Stopping at middle hit, as requested." << std::endl;
527  break;
528  }
529  if (seedVerbosity_ > 2)
530  std::cout << "Processing triplet " << it << ", hit " << ih << "." << std::endl;
531  if (ih == 0) {
532  propagated = propagator->propagate(CosmicSeed, tracker->idToDet((*seedHits[ih]).geographicalId())->surface());
533  } else {
534  propagated = propagator->propagate(updated, tracker->idToDet((*seedHits[ih]).geographicalId())->surface());
535  }
536  if (!propagated.isValid()) {
537  if (seedVerbosity_ > 1)
538  std::cout << "Processing triplet " << it << ", hit " << ih << ": failed propagation." << std::endl;
539  fail = true; break;
540  } else {
541  if (seedVerbosity_ > 2)
542  std::cout << "Processing triplet " << it << ", hit " << ih << ": propagated state = " << propagated;
543  }
544  SeedingHitSet::ConstRecHitPointer tthp = seedHits[ih];
545  auto newtth = static_cast<SeedingHitSet::RecHitPointer>(cloner(*tthp,propagated));
546  updated = theUpdator->update(propagated, *newtth);
547  hits.push_back(newtth);
548  if (!updated.isValid()) {
549  if (seedVerbosity_ > 1)
550  std::cout << "Processing triplet " << it << ", hit " << ih << ": failed update." << std::endl;
551  fail = true; break;
552  } else {
553  if (seedVerbosity_ > 2)
554  std::cout << "Processing triplet " << it << ", hit " << ih << ": updated state = " << updated;
555  }
556  }
557  if (!fail && updated.isValid() && (updated.globalMomentum().perp() < region_.ptMin())) {
558  if (seedVerbosity_ > 1)
559  std::cout << "Processing triplet " << it <<
560  ": failed for final pt " << updated.globalMomentum().perp() << " < " << region_.ptMin() << std::endl;
561  fail = true;
562  }
563  if (!fail && updated.isValid() && (updated.globalMomentum().mag() < pMin_)) {
564  if (seedVerbosity_ > 1)
565  std::cout << "Processing triplet " << it <<
566  ": failed for final p " << updated.globalMomentum().perp() << " < " << pMin_ << std::endl;
567  fail = true;
568  }
569  if (!fail) {
570  if (rescaleError_ != 1.0) {
571  if (seedVerbosity_ > 2) {
572  std::cout << "Processing triplet " << it << ", rescale error by " << rescaleError_ << ": state BEFORE rescaling " << updated;
573  std::cout << " Cartesian error (X,P) before rescaling= \n" << updated.cartesianError().matrix() << std::endl;
574  }
575  updated.rescaleError(rescaleError_);
576  }
577  if (seedVerbosity_ > 0) {
578  std::cout << "Processed triplet " << it << ": success (saved as #"<<output.size()<<") : "
579  << inner << " + " << middle << " + " << outer << std::endl;
580  std::cout << " pt = " << updated.globalMomentum().perp() <<
581  " eta = " << updated.globalMomentum().eta() <<
582  " phi = " << updated.globalMomentum().phi() <<
583  " ch = " << updated.charge() << std::endl;
584  if (seedVerbosity_ > 1) {
585  std::cout << " State:" << updated;
586  } else {
587  std::cout << " X = " << updated.globalPosition() << ", P = " << updated.globalMomentum() << std::endl;
588  }
589  std::cout << " Cartesian error (X,P) = \n" << updated.cartesianError().matrix() << std::endl;
590  }
591 
593  (*(seedOnMiddle_ ? trip.middle() : trip.inner())).geographicalId().rawId());
594  output.push_back(TrajectorySeed(PTraj,hits,
595  ( (outer.y()-inner.y()>0) ? alongMomentum : oppositeToMomentum) ));
596  if ((maxSeeds_ > 0) && (output.size() > size_t(maxSeeds_))) {
597  output.clear();
598  edm::LogError("TooManySeeds") << "Found too many seeds, bailing out.\n";
599  return false;
600  }
601  }
602  }
603  return true;
604 }
605 
607  delete thePropagatorAl;
608  delete thePropagatorOp;
609  delete theUpdator;
610 }
611 
612 
Definition: start.py:1
T getParameter(std::string const &) const
GlobalTrackingRegion region_
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:136
bool triplets(const edm::Event &e, const edm::EventSetup &c)
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:186
T perp() const
Definition: PV3DBase.h:72
MiddleRecHit middle() const
int nominalValue() const
The nominal field value for this map in kGauss.
Definition: MagneticField.h:58
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
double x0() const
Definition: FastCircle.h:50
ROOT::Math::SMatrixIdentity AlgebraicMatrixID
unsigned short LayerSetIndex
OrderedHitTriplets hitTriplets
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
PTrajectoryStateOnDet persistentState(const TrajectoryStateOnSurface &ts, unsigned int detid)
T y() const
Definition: PV3DBase.h:63
bool ev
uint16_t firstStrip() const
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
bool checkCharge(const TrackingRecHit *hit) const
double rho() const
Definition: FastCircle.h:54
SimpleCosmicBONSeeder(const edm::ParameterSet &conf)
uint32_t rawId() const
get the raw id
Definition: DetId.h:44
InnerRecHit inner() const
edm::ESHandle< TrackerGeometry > tracker
std::pair< GlobalVector, int > pqFromHelixFit(const GlobalPoint &inner, const GlobalPoint &middle, const GlobalPoint &outer, const edm::EventSetup &iSetup) const
void push_back(D *&d)
Definition: OwnVector.h:290
TrajectoryStateOnSurface update(const TrajectoryStateOnSurface &, const TrackingRecHit &) const override
Definition: KFUpdator.cc:75
BaseTrackerRecHit const * ConstRecHitPointer
Definition: SeedingHitSet.h:11
T mag() const
Definition: PV3DBase.h:67
bool isNotFinite(T x)
Definition: isFinite.h:10
std::vector< TrajectorySeed > TrajectorySeedCollection
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
T sqrt(T t)
Definition: SSEVec.h:18
PropagatorWithMaterial * thePropagatorOp
T z() const
Definition: PV3DBase.h:64
edm::ESHandle< MagneticField > magfield
virtual TrackingRecHit * clone() const =0
size_t tooManyClusters(const edm::Event &e) const
edm::ESHandle< TransientTrackingRecHitBuilder > TTTRHBuilder
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
edm::EDGetTokenT< SeedingLayerSetsHits > seedingLayerToken_
ClusterRef cluster() const
#define end
Definition: vmac.h:39
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:245
T min(T a, T b)
Definition: MathUtil.h:58
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:38
TrackingRegion::Hits hits(const edm::EventSetup &es, const SeedingLayerSetsHits::SeedingLayer &layer) const override
get hits from layer compatible with region constraints
unsigned int size() const override
virtual GlobalVector inTesla(const GlobalPoint &gp) const =0
Field value ad specified global point, in Tesla.
PropagatorWithMaterial * thePropagatorAl
const AlgebraicSymMatrix66 & matrix() const
Definition: DetId.h:18
TrajectoryStateOnSurface TSOS
Definition: TestHits.cc:19
virtual TrackingRecHit const * hit() const
def ls(path, rec=False)
Definition: eostools.py:348
void rescaleError(double factor)
SiStripRecHit2D stereoHit() const
const T & get() const
Definition: EventSetup.h:59
bool seeds(TrajectorySeedCollection &output, const edm::EventSetup &iSetup)
float ptMin() const
minimal pt of interest
TrajectoryStateOnSurface propagate(STA const &state, SUR const &surface) const
Definition: Propagator.h:53
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:90
double y0() const
Definition: FastCircle.h:52
HLT enums.
void produce(edm::Event &e, const edm::EventSetup &c) override
const TrackerGeomDet * idToDet(DetId) const override
SeedingHitSet::ConstRecHitPointer SeedingHit
std::vector< int32_t > chargeThresholds_
void checkNoisyModules(const std::vector< SeedingHitSet::ConstRecHitPointer > &hits, std::vector< bool > &oks) const
std::vector< int32_t > maxHitsPerModule_
DetId geographicalId() const
OuterRecHit outer() const
def fail(errstr="")
T x() const
Definition: PV3DBase.h:62
unsigned short size() const
Get the number of SeedingLayerSets.
T const * product() const
Definition: ESHandle.h:86
const std::vector< uint8_t > & amplitudes() const
def move(src, dest)
Definition: eostools.py:510
Global3DVector GlobalVector
Definition: GlobalVector.h:10