CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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 }
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  std::auto_ptr<TrajectorySeedCollection> output(new TrajectorySeedCollection());
93  std::auto_ptr<edm::OwnVector<TrackingRecHit> > outtriplets(new 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(outtriplets, "cosmicTriplets");
125  }
126  ev.put(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  using namespace ctfseeding;
177 
178  hitTriplets.clear();
179  hitTriplets.reserve(0);
181  e.getByToken(seedingLayerToken_, hlayers);
182  const SeedingLayerSetsHits& layers = *hlayers;
183  if(layers.numberOfLayersInSet() != 3)
184  throw cms::Exception("CtfSpecialSeedGenerator") << "You are using " << layers.numberOfLayersInSet() <<" layers in set instead of 3 ";
185 
186  double minRho = region_.ptMin() / ( 0.003 * magfield->inTesla(GlobalPoint(0,0,0)).z() );
187 
188  for(SeedingLayerSetsHits::LayerSetIndex layerIndex=0; layerIndex < layers.size(); ++layerIndex) {
191  auto innerHits = region_.hits(e, es, ls[0]);
192  auto middleHits = region_.hits(e, es, ls[1]);
193  auto outerHits = region_.hits(e, es, ls[2]);
194 
195  if (tripletsVerbosity_ > 0) {
196  std::cout << "GenericTripletGenerator iLss = " << seedingLayersToString(ls)
197  << " (" << layerIndex << "): # = "
198  << innerHits.size() << "/" << middleHits.size() << "/" << outerHits.size() << std::endl;
199  }
200 
203  std::vector<TTRH> innerTTRHs, middleTTRHs, outerTTRHs;
204 
206  std::vector<bool> innerOk( innerHits.size(), true);
207  std::vector<bool> middleOk(middleHits.size(), true);
208  std::vector<bool> outerOk( outerHits.size(), true);
209 
210  size_t sizBefore = hitTriplets.size();
212  int idx = 0;
213  for (auto iOuterHit = outerHits.begin(); iOuterHit != outerHits.end(); ++idx, ++iOuterHit){
214  outerTTRHs.push_back(&(**iOuterHit));
215  if (checkCharge_ && !checkCharge(outerTTRHs.back()->hit())) outerOk[idx] = false;
216  }
217  idx = 0;
218  for (auto iMiddleHit = middleHits.begin(); iMiddleHit != middleHits.end(); ++idx, ++iMiddleHit){
219  middleTTRHs.push_back(&(**iMiddleHit));
220  if (checkCharge_ && !checkCharge(middleTTRHs.back()->hit())) middleOk[idx] = false;
221  }
222  idx = 0;
223  for (auto iInnerHit = innerHits.begin(); iInnerHit != innerHits.end(); ++idx, ++iInnerHit){
224  innerTTRHs.push_back(&(**iInnerHit));
225  if (checkCharge_ && !checkCharge(innerTTRHs.back()->hit())) innerOk[idx] = false;
226  }
228  checkNoisyModules(innerTTRHs, innerOk);
229  checkNoisyModules(middleTTRHs, middleOk);
230  checkNoisyModules(outerTTRHs, outerOk);
231  }
232 
233  for (auto iOuterHit = outerHits.begin(); iOuterHit != outerHits.end(); iOuterHit++){
234  idx = iOuterHit - outerHits.begin();
235  TTRH & outerTTRH = outerTTRHs[idx];
236  GlobalPoint outerpos = outerTTRH->globalPosition(); // this caches by itself
237  bool outerok = outerOk[idx];
238  if (outerok < goodHitsPerSeed_ - 2) {
239  if (tripletsVerbosity_ > 2)
240  std::cout << "Skipping at first hit: " << (outerok) << " < " << (goodHitsPerSeed_ - 2) << std::endl;
241  continue;
242  }
243 
244  for (auto iMiddleHit = middleHits.begin(); iMiddleHit != middleHits.end(); iMiddleHit++){
245  idx = iMiddleHit - middleHits.begin();
246  TTRH & middleTTRH = middleTTRHs[idx];
247  GlobalPoint middlepos = middleTTRH->globalPosition(); // this caches by itself
248  bool middleok = middleOk[idx];
249  if (outerok+middleok < goodHitsPerSeed_ - 1) {
250  if (tripletsVerbosity_ > 2)
251  std::cout << "Skipping at second hit: " << (outerok+middleok) << " < " << (goodHitsPerSeed_ - 1) << std::endl;
252  continue;
253  }
254 
255  for (auto iInnerHit = innerHits.begin(); iInnerHit != innerHits.end(); iInnerHit++){
256  idx = iInnerHit - innerHits.begin();
257  TTRH & innerTTRH = innerTTRHs[idx];
258  GlobalPoint innerpos = innerTTRH->globalPosition(); // this caches by itself
259  bool innerok = innerOk[idx];
260  if (outerok+middleok+innerok < goodHitsPerSeed_) {
261  if (tripletsVerbosity_ > 2)
262  std::cout << "Skipping at third hit: " << (outerok+middleok+innerok) << " < " << (goodHitsPerSeed_) << std::endl;
263  continue;
264  }
265 
266  //***top-bottom
267  if (positiveYOnly && (innerpos.y()<0 || middlepos.y()<0 || outerpos.y()<0
268  || outerpos.y() < innerpos.y()
269  ) ) continue;
270  if (negativeYOnly && (innerpos.y()>0 || middlepos.y()>0 || outerpos.y()>0
271  || outerpos.y() > innerpos.y()
272  ) ) continue;
273  //***
274 
275  if (tripletsVerbosity_ > 2) 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/: "
287  << innerpos << " + " << middlepos << " + " << outerpos << std::endl;
288  }
289  if (tripletsVerbosity_ == 2) {
290  std::cout << " good seed #" << (hitTriplets.size()-1) << " w/: "
291  << innerpos << " + " << middlepos << " + " << 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)
302  << " (" << layerIndex << "): # = "
303  << innerHits.size() << "/" << middleHits.size() << "/" << outerHits.size()
304  << ": Found " << (hitTriplets.size() - sizBefore) << " seeds [running total: " << hitTriplets.size() << "]"
305  << std::endl ;
306  }
307 
308  }
310  return true;
311 }
313  DetId detid(hit->geographicalId());
314  if (detid.det() != DetId::Tracker) return false; // should not happen
315  int subdet = detid.subdetId();
316  if (subdet < 3) { // pixel
317  return true;
318  } else {
319  if (typeid(*hit) == typeid(SiStripMatchedRecHit2D)) {
320  const SiStripMatchedRecHit2D *mhit = static_cast<const SiStripMatchedRecHit2D *>(hit);
321  if (matchedRecHitUsesAnd_) {
322  return checkCharge(mhit->monoHit(), subdet) && checkCharge(mhit->stereoHit(), subdet);
323  } else {
324  return checkCharge(mhit->monoHit(), subdet) || checkCharge(mhit->stereoHit(), subdet);
325  }
326  } else if (typeid(*hit) == typeid(SiStripRecHit2D)) {
327  return checkCharge(static_cast<const SiStripRecHit2D &>(*hit), subdet);
328  } else {
329  return true;
330  }
331  }
332 }
333 
334 // to be fixed to use OmniCluster
335 bool SimpleCosmicBONSeeder::checkCharge(const SiStripRecHit2D &hit, int subdetid) const {
336  const SiStripCluster *clust = hit.cluster().get();
337  int charge = std::accumulate(clust->amplitudes().begin(), clust->amplitudes().end(), int(0));
338  if (tripletsVerbosity_ > 1) {
339  std::cerr << "Hit on " << subdetid << ", charge = " << charge << ", threshold = " << chargeThresholds_[subdetid]
340  << ", detid = " << hit.geographicalId().rawId() << ", firstStrip = " << clust->firstStrip() << std::endl;
341  } else if ((tripletsVerbosity_ == 1) && (charge < chargeThresholds_[subdetid])) {
342  std::cerr << "Hit on " << subdetid << ", charge = " << charge << ", threshold = " << chargeThresholds_[subdetid]
343  << ", detid = " << hit.geographicalId().rawId() << ", firstStrip = " << clust->firstStrip() << std::endl;
344  }
345  return charge > chargeThresholds_[subdetid];
346 }
347 
348 void SimpleCosmicBONSeeder::checkNoisyModules(const std::vector<SeedingHitSet::ConstRecHitPointer> &hits, 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) << " 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) << " rechits"
366  << " (threshold is " << maxHitsPerModule_[lastid.subdetId()] << ")" << std::endl;
367  }
368  }
369  start = it; okStart = ok;
370  }
371 }
372 
373 bool SimpleCosmicBONSeeder::goodTriplet(const GlobalPoint &inner, const GlobalPoint & middle, const GlobalPoint & outer, const double &minRho) const {
374  float dyOM = outer.y() - middle.y(), dyIM = inner.y() - middle.y();
375  if ((dyOM * dyIM > 0) && (fabs(dyOM)>10) && (fabs(dyIM)>10)) {
376  if (tripletsVerbosity_ > 2) std::cout << " fail for non coherent dy" << std::endl;
377  return false;
378  }
379  float dzOM = outer.z() - middle.z(), dzIM = inner.z() - middle.z();
380  if ((dzOM * dzIM > 0) && (fabs(dzOM)>50) && (fabs(dzIM)>50)) {
381  if (tripletsVerbosity_ > 2) std::cout << " fail for non coherent dz" << std::endl;
382  return false;
383  }
384  if (minRho > 0) {
385  FastCircle theCircle(inner,middle,outer);
386  if (theCircle.rho() < minRho) {
387  if (tripletsVerbosity_ > 2) std::cout << " fail for pt cut" << std::endl;
388  return false;
389  }
390  }
391  return true;
392 }
393 
394 std::pair<GlobalVector,int>
396  const edm::EventSetup& iSetup) const {
397  if (helixVerbosity_ > 0) {
398  std::cout << "DEBUG PZ =====" << std::endl;
399  FastHelix helix(inner,middle,outer,magfield->nominalValue(), &*magfield);
400  GlobalVector gv=helix.stateAtVertex().momentum(); // status on inner hit
401  std::cout << "FastHelix P = " << gv << "\n";
402  std::cout << "FastHelix Q = " << helix.stateAtVertex().charge() << "\n";
403  }
404 
405  // My attempt (with different approx from FastHelix)
406  // 1) fit the circle
407  FastCircle theCircle(inner,middle,outer);
408  double rho = theCircle.rho();
409 
410  // 2) Get the PT
411  GlobalVector tesla = magfield->inTesla(middle);
412  double pt = 0.01 * rho * (0.3*tesla.z());
413 
414  // 3) Get the PX,PY at OUTER hit (VERTEX)
415  double dx1 = outer.x()-theCircle.x0();
416  double dy1 = outer.y()-theCircle.y0();
417  double py = pt*dx1/rho, px = -pt*dy1/rho;
418  if(px*(middle.x() - outer.x()) + py*(middle.y() - outer.y()) < 0.) {
419  px *= -1.; py *= -1.;
420  }
421 
422  // 4) Get the PZ through pz = pT*(dz/d(R*phi)))
423  double dz = inner.z() - outer.z();
424  double sinphi = ( dx1*(inner.y()-theCircle.y0()) - dy1*(inner.x()-theCircle.x0())) / (rho * rho);
425  double dphi = std::abs(std::asin(sinphi));
426  double pz = pt * dz / (dphi * rho);
427 
428  int myq = ((theCircle.x0()*py - theCircle.y0()*px) / tesla.z()) > 0. ? +1 : -1;
429 
430  std::pair<GlobalVector,int> mypq(GlobalVector(px,py,pz),myq);
431 
432  if (helixVerbosity_ > 1) {
433  std::cout << "Gio: pt = " << pt << std::endl;
434  std::cout << "Gio: dz = " << dz << ", sinphi = " << sinphi << ", dphi = " << dphi << ", dz/drphi = " << (dz/dphi/rho) << std::endl;
435  }
436  if (helixVerbosity_ > 0) {
437  std::cout << "Gio's fit P = " << mypq.first << "\n";
438  std::cout << "Gio's fit Q = " << myq << "\n";
439  }
440 
441  return mypq;
442 }
443 
445 {
447 
448  for (size_t it=0;it<hitTriplets.size();it++){
449  OrderedHitTriplet &trip = const_cast<OrderedHitTriplet &>(hitTriplets[it]);
450 
451  GlobalPoint inner = tracker->idToDet((*(trip.inner())).geographicalId())->surface().
452  toGlobal((*(trip.inner())).localPosition());
453 
454  GlobalPoint middle = tracker->idToDet((*(trip.middle())).geographicalId())->surface().
455  toGlobal((*(trip.middle())).localPosition());
456 
457  GlobalPoint outer = tracker->idToDet((*(trip.outer())).geographicalId())->surface().
458  toGlobal((*(trip.outer())).localPosition());
459 
460  if (seedVerbosity_ > 1)
461  std::cout << "Processing triplet " << it << ": " << inner << " + " << middle << " + " << outer << std::endl;
462 
463  if ( (outer.y()-inner.y())*outer.y() < 0 ) {
464  std::swap(inner,outer);
465  trip = OrderedHitTriplet(trip.outer(),trip.middle(),trip.inner());
466 
467 // std::swap(const_cast<ctfseeding::SeedingHit &>(trip.inner()),
468 // const_cast<ctfseeding::SeedingHit &>(trip.outer()) );
469  if (seedVerbosity_ > 1) {
470  std::cout << "The seed was going away from CMS! swapped in <-> out" << std::endl;
471  std::cout << "Processing swapped triplet " << it << ": " << inner << " + " << middle << " + " << outer << std::endl;
472  }
473  }
474 
475  // First use FastHelix out of the box
476  std::pair<GlobalVector,int> pq = pqFromHelixFit(inner,middle,outer,iSetup);
477  GlobalVector gv = pq.first;
478  float ch = pq.second;
479  float Mom = sqrt( gv.x()*gv.x() + gv.y()*gv.y() + gv.z()*gv.z() );
480 
481  if(Mom > 10000 || edm::isNotFinite(Mom)) {
482  if (seedVerbosity_ > 1)
483  std::cout << "Processing triplet " << it << ": fail for momentum." << std::endl;
484  continue;
485  }
486 
487  if (gv.perp() < region_.ptMin()) {
488  if (seedVerbosity_ > 1)
489  std::cout << "Processing triplet " << it << ": fail for pt = " << gv.perp() << " < ptMin = " << region_.ptMin() << std::endl;
490  continue;
491  }
492 
493  const Propagator * propagator = 0;
494  if((outer.y()-inner.y())>0){
495  if (seedVerbosity_ > 1)
496  std::cout << "Processing triplet " << it << ": downgoing." << std::endl;
497  propagator = thePropagatorAl;
498  } else {
499  gv = -1*gv; ch = -1.*ch;
500  propagator = thePropagatorOp;
501  if (seedVerbosity_ > 1)
502  std::cout << "Processing triplet " << it << ": upgoing." << std::endl;
503  }
504 
505  if (seedVerbosity_ > 1) {
506  if (( gv.z() * (outer.z()-inner.z()) > 0 ) && ( fabs(outer.z()-inner.z()) > 5) && (fabs(gv.z()) > .01)) {
507  std::cout << "ORRORE: outer.z()-inner.z() = " << (outer.z()-inner.z()) << ", gv.z() = " << gv.z() << std::endl;
508  }
509  }
510 
511  GlobalTrajectoryParameters Gtp(outer,
512  gv,int(ch),
513  &(*magfield));
514  FreeTrajectoryState CosmicSeed(Gtp,
516  CosmicSeed.rescaleError(100);
517  if (seedVerbosity_ > 2) {
518  std::cout << "Processing triplet " << it << ". start from " << std::endl;
519  std::cout << " X = " << outer << ", P = " << gv << std::endl;
520  std::cout << " Cartesian error (X,P) = \n" << CosmicSeed.cartesianError().matrix() << std::endl;
521  }
522 
524  OrderedHitTriplet seedHits(trip.outer(),trip.middle(),trip.inner());
525  TSOS propagated, updated;
526  bool fail = false;
527  for (size_t ih = 0; ih < 3; ++ih) {
528  if ((ih == 2) && seedOnMiddle_) {
529  if (seedVerbosity_ > 2)
530  std::cout << "Stopping at middle hit, as requested." << std::endl;
531  break;
532  }
533  if (seedVerbosity_ > 2)
534  std::cout << "Processing triplet " << it << ", hit " << ih << "." << std::endl;
535  if (ih == 0) {
536  propagated = propagator->propagate(CosmicSeed, tracker->idToDet((*seedHits[ih]).geographicalId())->surface());
537  } else {
538  propagated = propagator->propagate(updated, tracker->idToDet((*seedHits[ih]).geographicalId())->surface());
539  }
540  if (!propagated.isValid()) {
541  if (seedVerbosity_ > 1)
542  std::cout << "Processing triplet " << it << ", hit " << ih << ": failed propagation." << std::endl;
543  fail = true; break;
544  } else {
545  if (seedVerbosity_ > 2)
546  std::cout << "Processing triplet " << it << ", hit " << ih << ": propagated state = " << propagated;
547  }
548  SeedingHitSet::ConstRecHitPointer tthp = seedHits[ih];
549  auto newtth = static_cast<SeedingHitSet::RecHitPointer>(cloner(*tthp,propagated));
550  updated = theUpdator->update(propagated, *newtth);
551  hits.push_back(newtth);
552  if (!updated.isValid()) {
553  if (seedVerbosity_ > 1)
554  std::cout << "Processing triplet " << it << ", hit " << ih << ": failed update." << std::endl;
555  fail = true; break;
556  } else {
557  if (seedVerbosity_ > 2)
558  std::cout << "Processing triplet " << it << ", hit " << ih << ": updated state = " << updated;
559  }
560  }
561  if (!fail && updated.isValid() && (updated.globalMomentum().perp() < region_.ptMin())) {
562  if (seedVerbosity_ > 1)
563  std::cout << "Processing triplet " << it <<
564  ": failed for final pt " << updated.globalMomentum().perp() << " < " << region_.ptMin() << std::endl;
565  fail = true;
566  }
567  if (!fail && updated.isValid() && (updated.globalMomentum().mag() < pMin_)) {
568  if (seedVerbosity_ > 1)
569  std::cout << "Processing triplet " << it <<
570  ": failed for final p " << updated.globalMomentum().perp() << " < " << pMin_ << std::endl;
571  fail = true;
572  }
573  if (!fail) {
574  if (rescaleError_ != 1.0) {
575  if (seedVerbosity_ > 2) {
576  std::cout << "Processing triplet " << it << ", rescale error by " << rescaleError_ << ": state BEFORE rescaling " << updated;
577  std::cout << " Cartesian error (X,P) before rescaling= \n" << updated.cartesianError().matrix() << std::endl;
578  }
579  updated.rescaleError(rescaleError_);
580  }
581  if (seedVerbosity_ > 0) {
582  std::cout << "Processed triplet " << it << ": success (saved as #"<<output.size()<<") : "
583  << inner << " + " << middle << " + " << outer << std::endl;
584  std::cout << " pt = " << updated.globalMomentum().perp() <<
585  " eta = " << updated.globalMomentum().eta() <<
586  " phi = " << updated.globalMomentum().phi() <<
587  " ch = " << updated.charge() << std::endl;
588  if (seedVerbosity_ > 1) {
589  std::cout << " State:" << updated;
590  } else {
591  std::cout << " X = " << updated.globalPosition() << ", P = " << updated.globalMomentum() << std::endl;
592  }
593  std::cout << " Cartesian error (X,P) = \n" << updated.cartesianError().matrix() << std::endl;
594  }
595 
597  (*(seedOnMiddle_ ? trip.middle() : trip.inner())).geographicalId().rawId());
598  output.push_back(TrajectorySeed(PTraj,hits,
599  ( (outer.y()-inner.y()>0) ? alongMomentum : oppositeToMomentum) ));
600  if ((maxSeeds_ > 0) && (output.size() > size_t(maxSeeds_))) {
601  output.clear();
602  edm::LogError("TooManySeeds") << "Found too many seeds, bailing out.\n";
603  return false;
604  }
605  }
606  }
607  return true;
608 }
609 
611  delete thePropagatorAl;
612  delete thePropagatorOp;
613  delete theUpdator;
614 }
615 
616 
T getParameter(std::string const &) const
GlobalTrackingRegion region_
virtual FreeTrajectoryState propagate(const FreeTrajectoryState &ftsStart, const GlobalPoint &pDest) const final
Definition: Propagator.h:119
tuple start
Check for commandline option errors.
Definition: dqm_diff.py:58
bool triplets(const edm::Event &e, const edm::EventSetup &c)
void init(const edm::EventSetup &c)
string fill
Definition: lumiContext.py:319
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
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
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
TrackingRegion::Hits hits(const edm::Event &ev, const edm::EventSetup &es, const SeedingLayerSetsHits::SeedingLayer &layer) const override
get hits from layer compatible with region constraints
double rho() const
Definition: FastCircle.h:54
SimpleCosmicBONSeeder(const edm::ParameterSet &conf)
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
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:280
BaseTrackerRecHit const * ConstRecHitPointer
Definition: SeedingHitSet.h:11
TrajectoryStateOnSurface update(const TrajectoryStateOnSurface &, const TrackingRecHit &) const
Definition: KFUpdator.cc:75
bool isNotFinite(T x)
Definition: isFinite.h:10
std::vector< TrajectorySeed > TrajectorySeedCollection
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:115
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
T sqrt(T t)
Definition: SSEVec.h:48
PropagatorWithMaterial * thePropagatorOp
T z() const
Definition: PV3DBase.h:64
edm::ESHandle< MagneticField > magfield
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:37
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:244
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:37
tuple conf
Definition: dbtoconf.py:185
PropagatorWithMaterial * thePropagatorAl
const AlgebraicSymMatrix66 & matrix() const
virtual TrackingRecHit * clone() const =0
Definition: DetId.h:18
TrajectoryStateOnSurface TSOS
Definition: TestHits.cc:19
virtual TrackingRecHit const * hit() const
void rescaleError(double factor)
SiStripRecHit2D stereoHit() const
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
const T & get() const
Definition: EventSetup.h:55
bool seeds(TrajectorySeedCollection &output, const edm::EventSetup &iSetup)
T const * product() const
Definition: ESHandle.h:86
float ptMin() const
minimal pt of interest
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:85
double y0() const
Definition: FastCircle.h:52
virtual void produce(edm::Event &e, const edm::EventSetup &c) override
BaseTrackerRecHit const * SeedingHit
std::vector< int32_t > chargeThresholds_
tuple cout
Definition: gather_cfg.py:121
void checkNoisyModules(const std::vector< SeedingHitSet::ConstRecHitPointer > &hits, std::vector< bool > &oks) const
std::vector< int32_t > maxHitsPerModule_
DetId geographicalId() const
volatile std::atomic< bool > shutdown_flag false
OuterRecHit outer() const
virtual unsigned int size() const
T x() const
Definition: PV3DBase.h:62
const std::vector< uint8_t > & amplitudes() const
Global3DVector GlobalVector
Definition: GlobalVector.h:10