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 
14 
15 #include <numeric>
16 
17 using namespace std;
19  conf_(conf),
20  theLsb(conf.getParameter<edm::ParameterSet>("TripletsPSet"), consumesCollector()),
21  writeTriplets_(conf.getParameter<bool>("writeTriplets")),
22  seedOnMiddle_(conf.existsAs<bool>("seedOnMiddle") ? conf.getParameter<bool>("seedOnMiddle") : false),
23  rescaleError_(conf.existsAs<double>("rescaleError") ? conf.getParameter<double>("rescaleError") : 1.0),
24  tripletsVerbosity_(conf.getParameter<edm::ParameterSet>("TripletsPSet").getUntrackedParameter<uint32_t>("debugLevel",0)),
25  seedVerbosity_(conf.getUntrackedParameter<uint32_t>("seedDebugLevel",0)),
26  helixVerbosity_(conf.getUntrackedParameter<uint32_t>("helixDebugLevel",0)),
27  check_(conf.getParameter<edm::ParameterSet>("ClusterCheckPSet"), consumesCollector()),
28  maxTriplets_(conf.getParameter<int32_t>("maxTriplets")),
29  maxSeeds_(conf.getParameter<int32_t>("maxSeeds"))
30 {
31  edm::ParameterSet regionConf = conf_.getParameter<edm::ParameterSet>("RegionPSet");
32  float ptmin = regionConf.getParameter<double>("ptMin");
33  float originradius = regionConf.getParameter<double>("originRadius");
34  float halflength = regionConf.getParameter<double>("originHalfLength");
35  float originz = regionConf.getParameter<double>("originZPosition");
36  region_ = GlobalTrackingRegion(ptmin, originradius, halflength, originz);
37  pMin_ = regionConf.getParameter<double>("pMin");
38 
39  builderName = conf_.getParameter<std::string>("TTRHBuilder");
40 
41  //***top-bottom
42  positiveYOnly=conf_.getParameter<bool>("PositiveYOnly");
43  negativeYOnly=conf_.getParameter<bool>("NegativeYOnly");
44  //***
45 
46  produces<TrajectorySeedCollection>();
47  if (writeTriplets_) produces<edm::OwnVector<TrackingRecHit> >("cosmicTriplets");
48 
49  layerTripletNames_ = conf_.getParameter<edm::ParameterSet>("TripletsPSet").getParameter<std::vector<std::string> >("layerList");
50 
51  if (conf.existsAs<edm::ParameterSet>("ClusterChargeCheck")) {
52  edm::ParameterSet cccc = conf.getParameter<edm::ParameterSet>("ClusterChargeCheck");
53  checkCharge_ = cccc.getParameter<bool>("checkCharge");
54  matchedRecHitUsesAnd_ = cccc.getParameter<bool>("matchedRecHitsUseAnd");
55  chargeThresholds_.resize(7,0);
56  edm::ParameterSet ccct = cccc.getParameter<edm::ParameterSet>("Thresholds");
58  chargeThresholds_[StripSubdetector::TID] = ccct.getParameter<int32_t>("TID");
59  chargeThresholds_[StripSubdetector::TOB] = ccct.getParameter<int32_t>("TOB");
60  chargeThresholds_[StripSubdetector::TEC] = ccct.getParameter<int32_t>("TEC");
61  } else {
62  checkCharge_ = false;
63  }
64  if (conf.existsAs<edm::ParameterSet>("HitsPerModuleCheck")) {
65  edm::ParameterSet hpmcc = conf.getParameter<edm::ParameterSet>("HitsPerModuleCheck");
66  checkMaxHitsPerModule_ = hpmcc.getParameter<bool>("checkHitsPerModule");
68  edm::ParameterSet hpmct = hpmcc.getParameter<edm::ParameterSet>("Thresholds");
69  maxHitsPerModule_[StripSubdetector::TIB] = hpmct.getParameter<int32_t>("TIB");
70  maxHitsPerModule_[StripSubdetector::TID] = hpmct.getParameter<int32_t>("TID");
71  maxHitsPerModule_[StripSubdetector::TOB] = hpmct.getParameter<int32_t>("TOB");
72  maxHitsPerModule_[StripSubdetector::TEC] = hpmct.getParameter<int32_t>("TEC");
73  } else {
74  checkMaxHitsPerModule_ = false;
75  }
77  goodHitsPerSeed_ = conf.getParameter<int32_t>("minimumGoodHitsInSeed");
78  } else {
79  goodHitsPerSeed_ = 0;
80  }
81 
82 }
83 
84 // Functions that gets called by framework every event
86 {
87  std::auto_ptr<TrajectorySeedCollection> output(new TrajectorySeedCollection());
88  std::auto_ptr<edm::OwnVector<TrackingRecHit> > outtriplets(new edm::OwnVector<TrackingRecHit>());
89 
91  if (magfield->inTesla(GlobalPoint(0,0,0)).mag() > 0.01) {
92  size_t clustsOrZero = check_.tooManyClusters(ev);
93  if (clustsOrZero) {
94  edm::LogError("TooManyClusters") << "Found too many clusters (" << clustsOrZero << "), bailing out.\n";
95  } else {
96  init(es);
97  bool tripletsOk = triplets(ev,es);
98  if (tripletsOk) {
99 
100  bool seedsOk = seeds(*output,es);
101  if (!seedsOk) { }
102 
103  if (writeTriplets_) {
104  for (OrderedHitTriplets::const_iterator it = hitTriplets.begin(); it != hitTriplets.end(); ++it) {
105  const TrackingRecHit * hit1 = it->inner()->hit();
106  const TrackingRecHit * hit2 = it->middle()->hit();
107  const TrackingRecHit * hit3 = it->outer()->hit();
108  outtriplets->push_back(hit1->clone());
109  outtriplets->push_back(hit2->clone());
110  outtriplets->push_back(hit3->clone());
111  }
112  }
113  }
114  done();
115  }
116  }
117 
118  if (writeTriplets_) {
119  ev.put(outtriplets, "cosmicTriplets");
120  }
121  ev.put(output);
122 }
123 
124 void
126 {
127  iSetup.get<TrackerDigiGeometryRecord>().get(tracker);
129 
130  // FIXME: these should come from ES too!!
133  theUpdator = new KFUpdator();
134 
135 }
136 
138  bool operator()(const OrderedHitTriplet &trip1, const OrderedHitTriplet &trip2) const {
139  //FIXME: inner gives a SEGV
140 #if 0
141  //const TransientTrackingRecHit::ConstRecHitPointer &ihit1 = trip1.inner();
142  //const TransientTrackingRecHit::ConstRecHitPointer &ihit2 = trip2.inner();
145  const TransientTrackingRecHit::ConstRecHitPointer &ohit1 = trip1.outer();
146  const TransientTrackingRecHit::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 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  using namespace ctfseeding;
172 
173  hitTriplets.clear();
174  hitTriplets.reserve(0);
175  if(theLsb.check(es)) {
176  theLss = theLsb.layers(es);
177  }
178  SeedingLayerSets::const_iterator iLss;
179 
180  double minRho = region_.ptMin() / ( 0.003 * magfield->inTesla(GlobalPoint(0,0,0)).z() );
181 
182  for (iLss = theLss.begin(); iLss != theLss.end(); iLss++){
183  SeedingLayers ls = *iLss;
184  if (ls.size() != 3){
185  throw cms::Exception("CtfSpecialSeedGenerator") << "You are using " << ls.size() <<" layers in set instead of 3 ";
186  }
187 
189  std::vector<SeedingHit> innerHits = region_.hits(e, es, &ls[0]);
190  std::vector<SeedingHit> middleHits = region_.hits(e, es, &ls[1]);
191  std::vector<SeedingHit> outerHits = region_.hits(e, es, &ls[2]);
192  std::vector<SeedingHit>::const_iterator iOuterHit,iMiddleHit,iInnerHit;
193 
194  if (tripletsVerbosity_ > 0) {
195  std::cout << "GenericTripletGenerator iLss = " << layerTripletNames_[iLss - theLss.begin()]
196  << " (" << (iLss - theLss.begin()) << "): # = "
197  << innerHits.size() << "/" << middleHits.size() << "/" << outerHits.size() << std::endl;
198  }
199 
202  std::vector<TTRH> innerTTRHs, middleTTRHs, outerTTRHs;
203 
205  std::vector<bool> innerOk( innerHits.size(), true);
206  std::vector<bool> middleOk(middleHits.size(), true);
207  std::vector<bool> outerOk( outerHits.size(), true);
208 
209  size_t sizBefore = hitTriplets.size();
211  int idx = 0;
212  for (iOuterHit = outerHits.begin(), idx = 0; iOuterHit != outerHits.end(); ++idx, ++iOuterHit){
213  outerTTRHs.push_back(ls[2].hitBuilder()->build((**iOuterHit).hit()));
214  if (checkCharge_ && !checkCharge(outerTTRHs.back()->hit())) outerOk[idx] = false;
215  }
216  for (iMiddleHit = middleHits.begin(), idx = 0; iMiddleHit != middleHits.end(); ++idx, ++iMiddleHit){
217  middleTTRHs.push_back(ls[1].hitBuilder()->build((**iMiddleHit).hit()));
218  if (checkCharge_ && !checkCharge(middleTTRHs.back()->hit())) middleOk[idx] = false;
219  }
220  for (iInnerHit = innerHits.begin(), idx = 0; iInnerHit != innerHits.end(); ++idx, ++iInnerHit){
221  innerTTRHs.push_back(ls[0].hitBuilder()->build((**iInnerHit).hit()));
222  if (checkCharge_ && !checkCharge(innerTTRHs.back()->hit())) innerOk[idx] = false;
223  }
225  checkNoisyModules(innerTTRHs, innerOk);
226  checkNoisyModules(middleTTRHs, middleOk);
227  checkNoisyModules(outerTTRHs, outerOk);
228  }
229 
230  for (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 (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) << std::endl;
249  continue;
250  }
251 
252  for (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_) << std::endl;
260  continue;
261  }
262 
263  //***top-bottom
264  if (positiveYOnly && (innerpos.y()<0 || middlepos.y()<0 || outerpos.y()<0
265  || outerpos.y() < innerpos.y()
266  ) ) continue;
267  if (negativeYOnly && (innerpos.y()>0 || middlepos.y()>0 || outerpos.y()>0
268  || outerpos.y() > innerpos.y()
269  ) ) continue;
270  //***
271 
272  if (tripletsVerbosity_ > 2) std::cout << "Trying seed with: " << innerpos << " + " << middlepos << " + " << outerpos << std::endl;
273  if (goodTriplet(innerpos,middlepos,outerpos,minRho)) {
274  OrderedHitTriplet oht(*iInnerHit,*iMiddleHit,*iOuterHit);
275  hitTriplets.push_back(oht);
276  if ((maxTriplets_ > 0) && (hitTriplets.size() > size_t(maxTriplets_))) {
277  hitTriplets.clear(); // clear
278  //OrderedHitTriplets().swap(hitTriplets); // really clear
279  edm::LogError("TooManyTriplets") << "Found too many triplets, bailing out.\n";
280  return false;
281  }
282  if (tripletsVerbosity_ > 3) {
283  std::cout << " accepted seed #" << (hitTriplets.size()-1) << " w/: "
284  << innerpos << " + " << middlepos << " + " << outerpos << std::endl;
285  }
286  if (tripletsVerbosity_ == 2) {
287  std::cout << " good seed #" << (hitTriplets.size()-1) << " w/: "
288  << innerpos << " + " << middlepos << " + " << outerpos << std::endl;
289  }
290  if (tripletsVerbosity_ > 3 && (helixVerbosity_ > 0)) { // debug the momentum here too
291  pqFromHelixFit(innerpos,middlepos,outerpos,es);
292  }
293  }
294  }
295  }
296  }
297  if ((tripletsVerbosity_ > 0) && (hitTriplets.size() > sizBefore)) {
298  std::cout << " iLss = " << layerTripletNames_[iLss - theLss.begin()]
299  << " (" << (iLss - theLss.begin()) << "): # = "
300  << innerHits.size() << "/" << middleHits.size() << "/" << outerHits.size()
301  << ": Found " << (hitTriplets.size() - sizBefore) << " seeds [running total: " << hitTriplets.size() << "]"
302  << std::endl ;
303  }
304 
305  }
307  return true;
308 }
310  DetId detid(hit->geographicalId());
311  if (detid.det() != DetId::Tracker) return false; // should not happen
312  int subdet = detid.subdetId();
313  if (subdet < 3) { // pixel
314  return true;
315  } else {
316  if (typeid(*hit) == typeid(SiStripMatchedRecHit2D)) {
317  const SiStripMatchedRecHit2D *mhit = static_cast<const SiStripMatchedRecHit2D *>(hit);
318  if (matchedRecHitUsesAnd_) {
319  return checkCharge(mhit->monoHit(), subdet) && checkCharge(mhit->stereoHit(), subdet);
320  } else {
321  return checkCharge(mhit->monoHit(), subdet) || checkCharge(mhit->stereoHit(), subdet);
322  }
323  } else if (typeid(*hit) == typeid(SiStripRecHit2D)) {
324  return checkCharge(static_cast<const SiStripRecHit2D &>(*hit), subdet);
325  } else {
326  return true;
327  }
328  }
329 }
330 
331 // to be fixed to use OmniCluster
332 bool SimpleCosmicBONSeeder::checkCharge(const SiStripRecHit2D &hit, int subdetid) const {
333  const SiStripCluster *clust = (hit.cluster().isNonnull() ? hit.cluster().get() : hit.cluster_regional().get());
334  int charge = std::accumulate(clust->amplitudes().begin(), clust->amplitudes().end(), int(0));
335  if (tripletsVerbosity_ > 1) {
336  std::cerr << "Hit on " << subdetid << ", charge = " << charge << ", threshold = " << chargeThresholds_[subdetid]
337  << ", detid = " << hit.geographicalId().rawId() << ", firstStrip = " << clust->firstStrip() << std::endl;
338  } else if ((tripletsVerbosity_ == 1) && (charge < chargeThresholds_[subdetid])) {
339  std::cerr << "Hit on " << subdetid << ", charge = " << charge << ", threshold = " << chargeThresholds_[subdetid]
340  << ", detid = " << hit.geographicalId().rawId() << ", firstStrip = " << clust->firstStrip() << std::endl;
341  }
342  return charge > chargeThresholds_[subdetid];
343 }
344 
345 void SimpleCosmicBONSeeder::checkNoisyModules(const std::vector<TransientTrackingRecHit::RecHitPointer> &hits, std::vector<bool> &oks) const {
347  std::vector<TTRH>::const_iterator it = hits.begin(), start = it, end = hits.end();
348  std::vector<bool>::iterator ok = oks.begin(), okStart = ok;
349  while (start < end) {
350  DetId lastid = (*start)->geographicalId();
351  for (it = start + 1; (it < end) && ((*it)->geographicalId() == lastid); ++it) {
352  ++ok;
353  }
354  if ( (it - start) > maxHitsPerModule_[lastid.subdetId()] ) {
355  if (tripletsVerbosity_ > 0) {
356  std::cerr << "SimpleCosmicBONSeeder: Marking noisy module " << lastid.rawId() << ", it has " << (it-start) << " rechits"
357  << " (threshold is " << maxHitsPerModule_[lastid.subdetId()] << ")" << std::endl;
358  }
359  std::fill(okStart,ok,false);
360  } else if (tripletsVerbosity_ > 0) {
361  if ( (it - start) > std::min(4,maxHitsPerModule_[lastid.subdetId()]/4) ) {
362  std::cerr << "SimpleCosmicBONSeeder: Not marking noisy module " << lastid.rawId() << ", it has " << (it-start) << " rechits"
363  << " (threshold is " << maxHitsPerModule_[lastid.subdetId()] << ")" << std::endl;
364  }
365  }
366  start = it; okStart = ok;
367  }
368 }
369 
370 bool SimpleCosmicBONSeeder::goodTriplet(const GlobalPoint &inner, const GlobalPoint & middle, const GlobalPoint & outer, const double &minRho) const {
371  float dyOM = outer.y() - middle.y(), dyIM = inner.y() - middle.y();
372  if ((dyOM * dyIM > 0) && (fabs(dyOM)>10) && (fabs(dyIM)>10)) {
373  if (tripletsVerbosity_ > 2) std::cout << " fail for non coherent dy" << std::endl;
374  return false;
375  }
376  float dzOM = outer.z() - middle.z(), dzIM = inner.z() - middle.z();
377  if ((dzOM * dzIM > 0) && (fabs(dzOM)>50) && (fabs(dzIM)>50)) {
378  if (tripletsVerbosity_ > 2) std::cout << " fail for non coherent dz" << std::endl;
379  return false;
380  }
381  if (minRho > 0) {
382  FastCircle theCircle(inner,middle,outer);
383  if (theCircle.rho() < minRho) {
384  if (tripletsVerbosity_ > 2) std::cout << " fail for pt cut" << std::endl;
385  return false;
386  }
387  }
388  return true;
389 }
390 
391 std::pair<GlobalVector,int>
393  const edm::EventSetup& iSetup) const {
394  if (helixVerbosity_ > 0) {
395  std::cout << "DEBUG PZ =====" << std::endl;
396  FastHelix helix(inner,middle,outer,magfield->nominalValue(), &*magfield);
397  GlobalVector gv=helix.stateAtVertex().momentum(); // status on inner hit
398  std::cout << "FastHelix P = " << gv << "\n";
399  std::cout << "FastHelix Q = " << helix.stateAtVertex().charge() << "\n";
400  }
401 
402  // My attempt (with different approx from FastHelix)
403  // 1) fit the circle
404  FastCircle theCircle(inner,middle,outer);
405  double rho = theCircle.rho();
406 
407  // 2) Get the PT
408  GlobalVector tesla = magfield->inTesla(middle);
409  double pt = 0.01 * rho * (0.3*tesla.z());
410 
411  // 3) Get the PX,PY at OUTER hit (VERTEX)
412  double dx1 = outer.x()-theCircle.x0();
413  double dy1 = outer.y()-theCircle.y0();
414  double py = pt*dx1/rho, px = -pt*dy1/rho;
415  if(px*(middle.x() - outer.x()) + py*(middle.y() - outer.y()) < 0.) {
416  px *= -1.; py *= -1.;
417  }
418 
419  // 4) Get the PZ through pz = pT*(dz/d(R*phi)))
420  double dz = inner.z() - outer.z();
421  double sinphi = ( dx1*(inner.y()-theCircle.y0()) - dy1*(inner.x()-theCircle.x0())) / (rho * rho);
422  double dphi = std::abs(std::asin(sinphi));
423  double pz = pt * dz / (dphi * rho);
424 
425  int myq = ((theCircle.x0()*py - theCircle.y0()*px) / tesla.z()) > 0. ? +1 : -1;
426 
427  std::pair<GlobalVector,int> mypq(GlobalVector(px,py,pz),myq);
428 
429  if (helixVerbosity_ > 1) {
430  std::cout << "Gio: pt = " << pt << std::endl;
431  std::cout << "Gio: dz = " << dz << ", sinphi = " << sinphi << ", dphi = " << dphi << ", dz/drphi = " << (dz/dphi/rho) << std::endl;
432  }
433  if (helixVerbosity_ > 0) {
434  std::cout << "Gio's fit P = " << mypq.first << "\n";
435  std::cout << "Gio's fit Q = " << myq << "\n";
436  }
437 
438  return mypq;
439 }
440 
442 {
444 
445  for (size_t it=0;it<hitTriplets.size();it++){
446  const OrderedHitTriplet &trip = hitTriplets[it];
447 
448  GlobalPoint inner = tracker->idToDet((*(trip.inner())).geographicalId())->surface().
449  toGlobal((*(trip.inner())).localPosition());
450 
451  GlobalPoint middle = tracker->idToDet((*(trip.middle())).geographicalId())->surface().
452  toGlobal((*(trip.middle())).localPosition());
453 
454  GlobalPoint outer = tracker->idToDet((*(trip.outer())).geographicalId())->surface().
455  toGlobal((*(trip.outer())).localPosition());
456 
457  if (seedVerbosity_ > 1)
458  std::cout << "Processing triplet " << it << ": " << inner << " + " << middle << " + " << outer << std::endl;
459 
460  if ( (outer.y()-inner.y())*outer.y() < 0 ) {
461  std::swap(inner,outer);
462  std::swap(const_cast<TransientTrackingRecHit::ConstRecHitPointer &>(trip.inner()),
463  const_cast<TransientTrackingRecHit::ConstRecHitPointer &>(trip.outer()) );
464 
465 // std::swap(const_cast<ctfseeding::SeedingHit &>(trip.inner()),
466 // const_cast<ctfseeding::SeedingHit &>(trip.outer()) );
467  if (seedVerbosity_ > 1) {
468  std::cout << "The seed was going away from CMS! swapped in <-> out" << std::endl;
469  std::cout << "Processing swapped triplet " << it << ": " << inner << " + " << middle << " + " << outer << std::endl;
470  }
471  }
472 
473  // First use FastHelix out of the box
474  std::pair<GlobalVector,int> pq = pqFromHelixFit(inner,middle,outer,iSetup);
475  GlobalVector gv = pq.first;
476  float ch = pq.second;
477  float Mom = sqrt( gv.x()*gv.x() + gv.y()*gv.y() + gv.z()*gv.z() );
478 
479  if(Mom > 10000 || edm::isNotFinite(Mom)) {
480  if (seedVerbosity_ > 1)
481  std::cout << "Processing triplet " << it << ": fail for momentum." << std::endl;
482  continue;
483  }
484 
485  if (gv.perp() < region_.ptMin()) {
486  if (seedVerbosity_ > 1)
487  std::cout << "Processing triplet " << it << ": fail for pt = " << gv.perp() << " < ptMin = " << region_.ptMin() << std::endl;
488  continue;
489  }
490 
491  const Propagator * propagator = 0;
492  if((outer.y()-inner.y())>0){
493  if (seedVerbosity_ > 1)
494  std::cout << "Processing triplet " << it << ": downgoing." << std::endl;
495  propagator = thePropagatorAl;
496  } else {
497  gv = -1*gv; ch = -1.*ch;
498  propagator = thePropagatorOp;
499  if (seedVerbosity_ > 1)
500  std::cout << "Processing triplet " << it << ": upgoing." << std::endl;
501  }
502 
503  if (seedVerbosity_ > 1) {
504  if (( gv.z() * (outer.z()-inner.z()) > 0 ) && ( fabs(outer.z()-inner.z()) > 5) && (fabs(gv.z()) > .01)) {
505  std::cout << "ORRORE: outer.z()-inner.z() = " << (outer.z()-inner.z()) << ", gv.z() = " << gv.z() << std::endl;
506  }
507  }
508 
509  GlobalTrajectoryParameters Gtp(outer,
510  gv,int(ch),
511  &(*magfield));
512  FreeTrajectoryState CosmicSeed(Gtp,
514  CosmicSeed.rescaleError(100);
515  if (seedVerbosity_ > 2) {
516  std::cout << "Processing triplet " << it << ". start from " << std::endl;
517  std::cout << " X = " << outer << ", P = " << gv << std::endl;
518  std::cout << " Cartesian error (X,P) = \n" << CosmicSeed.cartesianError().matrix() << std::endl;
519  }
520 
522  OrderedHitTriplet seedHits(trip.outer(),trip.middle(),trip.inner());
523  TSOS propagated, updated;
524  bool fail = false;
525  for (size_t ih = 0; ih < 3; ++ih) {
526  if ((ih == 2) && seedOnMiddle_) {
527  if (seedVerbosity_ > 2)
528  std::cout << "Stopping at middle hit, as requested." << std::endl;
529  break;
530  }
531  if (seedVerbosity_ > 2)
532  std::cout << "Processing triplet " << it << ", hit " << ih << "." << std::endl;
533  if (ih == 0) {
534  propagated = propagator->propagate(CosmicSeed, tracker->idToDet((*seedHits[ih]).geographicalId())->surface());
535  } else {
536  propagated = propagator->propagate(updated, tracker->idToDet((*seedHits[ih]).geographicalId())->surface());
537  }
538  if (!propagated.isValid()) {
539  if (seedVerbosity_ > 1)
540  std::cout << "Processing triplet " << it << ", hit " << ih << ": failed propagation." << std::endl;
541  fail = true; break;
542  } else {
543  if (seedVerbosity_ > 2)
544  std::cout << "Processing triplet " << it << ", hit " << ih << ": propagated state = " << propagated;
545  }
546  const TransientTrackingRecHit::ConstRecHitPointer & tthp = seedHits[ih];
547  TransientTrackingRecHit::RecHitPointer newtth = tthp->clone(propagated);
548  hits.push_back(newtth->hit()->clone());
549  updated = theUpdator->update(propagated, *newtth);
550  if (!updated.isValid()) {
551  if (seedVerbosity_ > 1)
552  std::cout << "Processing triplet " << it << ", hit " << ih << ": failed update." << std::endl;
553  fail = true; break;
554  } else {
555  if (seedVerbosity_ > 2)
556  std::cout << "Processing triplet " << it << ", hit " << ih << ": updated state = " << updated;
557  }
558  }
559  if (!fail && updated.isValid() && (updated.globalMomentum().perp() < region_.ptMin())) {
560  if (seedVerbosity_ > 1)
561  std::cout << "Processing triplet " << it <<
562  ": failed for final pt " << updated.globalMomentum().perp() << " < " << region_.ptMin() << std::endl;
563  fail = true;
564  }
565  if (!fail && updated.isValid() && (updated.globalMomentum().mag() < pMin_)) {
566  if (seedVerbosity_ > 1)
567  std::cout << "Processing triplet " << it <<
568  ": failed for final p " << updated.globalMomentum().perp() << " < " << pMin_ << std::endl;
569  fail = true;
570  }
571  if (!fail) {
572  if (rescaleError_ != 1.0) {
573  if (seedVerbosity_ > 2) {
574  std::cout << "Processing triplet " << it << ", rescale error by " << rescaleError_ << ": state BEFORE rescaling " << updated;
575  std::cout << " Cartesian error (X,P) before rescaling= \n" << updated.cartesianError().matrix() << std::endl;
576  }
577  updated.rescaleError(rescaleError_);
578  }
579  if (seedVerbosity_ > 0) {
580  std::cout << "Processed triplet " << it << ": success (saved as #"<<output.size()<<") : "
581  << inner << " + " << middle << " + " << outer << std::endl;
582  std::cout << " pt = " << updated.globalMomentum().perp() <<
583  " eta = " << updated.globalMomentum().eta() <<
584  " phi = " << updated.globalMomentum().phi() <<
585  " ch = " << updated.charge() << std::endl;
586  if (seedVerbosity_ > 1) {
587  std::cout << " State:" << updated;
588  } else {
589  std::cout << " X = " << updated.globalPosition() << ", P = " << updated.globalMomentum() << std::endl;
590  }
591  std::cout << " Cartesian error (X,P) = \n" << updated.cartesianError().matrix() << std::endl;
592  }
593 
595  (*(seedOnMiddle_ ? trip.middle() : trip.inner())).geographicalId().rawId());
596  output.push_back(TrajectorySeed(PTraj,hits,
597  ( (outer.y()-inner.y()>0) ? alongMomentum : oppositeToMomentum) ));
598  if ((maxSeeds_ > 0) && (output.size() > size_t(maxSeeds_))) {
599  output.clear();
600  edm::LogError("TooManySeeds") << "Found too many seeds, bailing out.\n";
601  return false;
602  }
603  }
604  }
605  return true;
606 }
607 
609  delete thePropagatorAl;
610  delete thePropagatorOp;
611  delete theUpdator;
612 }
613 
614 
T getParameter(std::string const &) const
GlobalTrackingRegion region_
ctfseeding::SeedingLayerSets layers(const edm::EventSetup &es)
tuple start
Check for commandline option errors.
Definition: dqm_diff.py:58
const OuterRecHit & outer() const
bool triplets(const edm::Event &e, const edm::EventSetup &c)
void init(const edm::EventSetup &c)
string fill
Definition: lumiContext.py:319
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:184
T perp() const
Definition: PV3DBase.h:72
double x0() const
Definition: FastCircle.h:50
ROOT::Math::SMatrixIdentity AlgebraicMatrixID
OrderedHitTriplets hitTriplets
Definition: DDAxes.h:10
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
PTrajectoryStateOnDet persistentState(const TrajectoryStateOnSurface &ts, unsigned int detid)
T y() const
Definition: PV3DBase.h:63
const InnerRecHit & inner() const
const MiddleRecHit & middle() const
bool check(const edm::EventSetup &es)
uint16_t firstStrip() const
void checkNoisyModules(const std::vector< TransientTrackingRecHit::RecHitPointer > &hits, std::vector< bool > &oks) const
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
bool checkCharge(const TrackingRecHit *hit) const
double charge(const std::vector< uint8_t > &Ampls)
double rho() const
Definition: FastCircle.h:54
SimpleCosmicBONSeeder(const edm::ParameterSet &conf)
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
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:273
SeedingLayerSetsBuilder theLsb
bool isNotFinite(T x)
Definition: isFinite.h:10
std::vector< TrajectorySeed > TrajectorySeedCollection
const T & max(const T &a, const T &b)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
ctfseeding::SeedingLayerSets theLss
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
#define end
Definition: vmac.h:37
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 TrajectoryStateOnSurface propagate(const FreeTrajectoryState &, const Surface &) const
Definition: Propagator.cc:12
virtual TrackingRecHit * clone() const =0
Definition: DetId.h:18
TrajectoryStateOnSurface TSOS
Definition: TestHits.cc:19
void rescaleError(double factor)
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)
bool goodTriplet(const GlobalPoint &inner, const GlobalPoint &middle, const GlobalPoint &outer, const double &minRho) 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
std::vector< std::string > layerTripletNames_
TransientTrackingRecHit::ConstRecHitPointer SeedingHit
std::vector< int32_t > chargeThresholds_
tuple cout
Definition: gather_cfg.py:121
std::vector< int32_t > maxHitsPerModule_
DetId geographicalId() const
volatile std::atomic< bool > shutdown_flag false
virtual unsigned int size() const
T x() const
Definition: PV3DBase.h:62
const std::vector< uint8_t > & amplitudes() const
std::vector< SeedingLayer > SeedingLayers
Global3DVector GlobalVector
Definition: GlobalVector.h:10