CMS 3D CMS Logo

ElectronSeedGenerator.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: EgammaElectronAlgos
4 // Class: ElectronSeedGenerator.
5 //
13 //
14 // Original Author: Ursula Berthon, Claude Charlot
15 // Created: Mon Mar 27 13:22:06 CEST 2006
16 //
17 
20 
26 
27 //#include "DataFormats/EgammaReco/interface/EcalCluster.h"
29 
31 //#include "DataFormats/BeamSpot/interface/BeamSpot.h"
32 //#include "DataFormats/Common/interface/Handle.h"
33 
37 
41 
43 
45 
46 
47 #include <vector>
48 #include <utility>
49 
50 
51 #ifdef COUNT_ElectronSeeds
52 namespace {
53  struct Count {
54  long long s=0;
55  long long n=0;
56  ~Count() { std::cout << "ElectronSeeds res " << s<<'/'<<n << std::endl;}
57  };
58 
59  Count stcount;
60 }
61 #endif
62 
63 
64 
67  : dynamicphiroad_(pset.getParameter<bool>("dynamicPhiRoad")),
68  fromTrackerSeeds_(pset.getParameter<bool>("fromTrackerSeeds")),
69  useRecoVertex_(false),
70  verticesTag_(ts.token_vtx),
71  beamSpotTag_(ts.token_bs),
72  lowPtThreshold_(pset.getParameter<double>("LowPtThreshold")),
73  highPtThreshold_(pset.getParameter<double>("HighPtThreshold")),
74  nSigmasDeltaZ1_(pset.getParameter<double>("nSigmasDeltaZ1")),
75  deltaZ1WithVertex_(0.5),
76  sizeWindowENeg_(pset.getParameter<double>("SizeWindowENeg")),
77  deltaPhi1Low_(pset.getParameter<double>("DeltaPhi1Low")),
78  deltaPhi1High_(pset.getParameter<double>("DeltaPhi1High")),
79  deltaPhi1Coef1_(0.), deltaPhi1Coef2_(0.),
80  myMatchEle(nullptr), myMatchPos(nullptr),
81  thePropagator(nullptr),
82  theMeasurementTracker(nullptr),
83  theMeasurementTrackerEventTag(ts.token_measTrkEvt),
84  theSetup(nullptr),
85  cacheIDMagField_(0),/*cacheIDGeom_(0),*/cacheIDNavSchool_(0),cacheIDCkfComp_(0),cacheIDTrkGeom_(0)
86 {
87  // so that deltaPhi1 = deltaPhi1Coef1_ + deltaPhi1Coef2_/clusterEnergyT
88  if (dynamicphiroad_)
89  {
92  }
93 
94  theMeasurementTrackerName = pset.getParameter<std::string>("measurementTrackerName");
95 
96  // use of reco vertex
97  useRecoVertex_ = pset.getParameter<bool>("useRecoVertex");
98  deltaZ1WithVertex_ = pset.getParameter<double>("deltaZ1WithVertex");
99 
100  // new B/F configurables
101  deltaPhi2B_ = pset.getParameter<double>("DeltaPhi2B") ;
102  deltaPhi2F_ = pset.getParameter<double>("DeltaPhi2F") ;
103 
104  phiMin2B_ = pset.getParameter<double>("PhiMin2B") ;
105  phiMin2F_ = pset.getParameter<double>("PhiMin2F") ;
106 
107  phiMax2B_ = pset.getParameter<double>("PhiMax2B") ;
108  phiMax2F_ = pset.getParameter<double>("PhiMax2F") ;
109 
110  // Instantiate the pixel hit matchers
112  ( pset.getParameter<double>("ePhiMin1"),
113  pset.getParameter<double>("ePhiMax1"),
114  phiMin2B_, phiMax2B_, phiMin2F_, phiMax2F_,
115  pset.getParameter<double>("z2MinB"),
116  pset.getParameter<double>("z2MaxB"),
117  pset.getParameter<double>("r2MinF"),
118  pset.getParameter<double>("r2MaxF"),
119  pset.getParameter<double>("rMinI"),
120  pset.getParameter<double>("rMaxI"),
121  pset.getParameter<bool>("searchInTIDTEC") ) ;
122 
124  ( pset.getParameter<double>("pPhiMin1"),
125  pset.getParameter<double>("pPhiMax1"),
126  phiMin2B_, phiMax2B_, phiMin2F_, phiMax2F_,
127  pset.getParameter<double>("z2MinB"),
128  pset.getParameter<double>("z2MaxB"),
129  pset.getParameter<double>("r2MinF"),
130  pset.getParameter<double>("r2MaxF"),
131  pset.getParameter<double>("rMinI"),
132  pset.getParameter<double>("rMaxI"),
133  pset.getParameter<bool>("searchInTIDTEC") ) ;
134 
135  theUpdator = new KFUpdator() ;
136 }
137 
139  {
140  delete myMatchEle ;
141  delete myMatchPos ;
142  delete thePropagator ;
143  delete theUpdator ;
144  }
145 
147 
148  // get records if necessary (called once per event)
149  bool tochange=false;
150 
153  cacheIDMagField_=setup.get<IdealMagneticFieldRecord>().cacheIdentifier();
154  if (thePropagator) delete thePropagator;
156  tochange=true;
157  }
158 
160  edm::ESHandle<MeasurementTracker> measurementTrackerHandle;
161  setup.get<CkfComponentsRecord>().get(theMeasurementTrackerName,measurementTrackerHandle);
162  cacheIDCkfComp_=setup.get<CkfComponentsRecord>().cacheIdentifier();
163  theMeasurementTracker = measurementTrackerHandle.product();
164  tochange=true;
165  }
166 
167  //edm::ESHandle<TrackerGeometry> trackerGeometryHandle;
169  cacheIDTrkGeom_=setup.get<TrackerDigiGeometryRecord>().cacheIdentifier();
171  tochange=true; //FIXME
172  }
173 
174  if (tochange) {
177  }
178 
181  setup.get<NavigationSchoolRecord>().get("SimpleNavigationSchool", nav);
182  cacheIDNavSchool_=setup.get<NavigationSchoolRecord>().cacheIdentifier();
184  }
185 
186 // if (cacheIDGeom_!=setup.get<TrackerRecoGeometryRecord>().cacheIdentifier()) {
187 // setup.get<TrackerRecoGeometryRecord>().get( theGeomSearchTracker );
188 // cacheIDGeom_=setup.get<TrackerRecoGeometryRecord>().cacheIdentifier();
189 // }
190 
191 }
192 
193 void display_seed( const std::string & title1, const std::string & title2, const reco::ElectronSeed & seed, edm::ESHandle<TrackerGeometry> trackerGeometry )
194  {
195  const PTrajectoryStateOnDet & startingState = seed.startingState() ;
196  const LocalTrajectoryParameters & parameters = startingState.parameters() ;
197  std::cout<<title1
198  <<" ("<<seed.subDet2()<<"/"<<seed.dRz2()<<"/"<<seed.dPhi2()<<")"
199  <<" ("<<seed.direction()<<"/"<<startingState.detId()<<"/"<<startingState.surfaceSide()<<"/"<<parameters.charge()<<"/"<<parameters.position()<<"/"<<parameters.momentum()<<")"
200  <<std::endl ;
201  }
202 
203 bool equivalent( const TrajectorySeed & s1, const TrajectorySeed & s2 )
204  {
205  if (s1.nHits()!=s2.nHits()) return false ;
206 
207  unsigned int nHits ;
208  TrajectorySeed::range r1 = s1.recHits(), r2 = s2.recHits() ;
210  for ( i1=r1.first, i2=r2.first, nHits=0 ; i1!=r1.second ; ++i1, ++i2, ++nHits )
211  {
212  if ( !i1->isValid() || !i2->isValid() ) return false ;
213  if ( i1->geographicalId()!=i2->geographicalId() ) return false ;
214  if ( ! ( i1->localPosition()==i2->localPosition() ) ) return false ;
215  }
216 
217  return true ;
218  }
219 
222  const reco::SuperClusterRefVector & sclRefs, const std::vector<float> & hoe1s, const std::vector<float> & hoe2s,
224  {
225  theInitialSeedColl = seeds ;
226 // bool duplicateTrajectorySeeds =false ;
227 // unsigned int i,j ;
228 // for (i=0;i<seeds->size();++i)
229 // for (j=i+1;j<seeds->size();++j)
230 // {
231 // const TrajectorySeed & s1 =(*seeds)[i] ;
232 // const TrajectorySeed & s2 =(*seeds)[j] ;
233 // if ( equivalent(s1,s2) )
234 // {
235 // const PTrajectoryStateOnDet & ss1 = s1.startingState() ;
236 // const LocalTrajectoryParameters & p1 = ss1.parameters() ;
237 // const PTrajectoryStateOnDet & ss2 = s2.startingState() ;
238 // const LocalTrajectoryParameters & p2 = ss2.parameters() ;
239 // duplicateTrajectorySeeds = true ;
240 // std::cout<<"Same hits for "
241 // <<"\n s["<<i<<"] ("<<s1.direction()<<"/"<<ss1.detId()<<"/"<<ss1.surfaceSide()<<"/"<<p1.charge()<<"/"<<p1.position()<<"/"<<p1.momentum()<<")"
242 // <<"\n s["<<j<<"] ("<<s2.direction()<<"/"<<ss2.detId()<<"/"<<ss2.surfaceSide()<<"/"<<p2.charge()<<"/"<<p2.position()<<"/"<<p2.momentum()<<")"
243 // <<std::endl ;
244 // }
245 // }
246 // if (duplicateTrajectorySeeds)
247 // { edm::LogWarning("ElectronSeedGenerator|DuplicateTrajectorySeeds")<<"We see several identical trajectory seeds." ; }
248 
249  //Retrieve tracker topology from geometry
251  setup.get<TrackerTopologyRcd>().get(tTopoHand);
252  const TrackerTopology *tTopo=tTopoHand.product();
253 
254  theSetup= &setup;
255 
256 
257  // Step A: set Event for the TrajectoryBuilder
260  myMatchEle->setEvent(*data);
261  myMatchPos->setEvent(*data);
262 
263  // get initial TrajectorySeeds if necessary
264  // if (fromTrackerSeeds_) e.getByToken(initialSeeds_, theInitialSeedColl);
265 
266  // get the beamspot from the Event:
267  //e.getByType(theBeamSpot);
269 
270  // if required get the vertices
272 
273  if (!fromTrackerSeeds_)
274  { throw cms::Exception("NotSupported") << "Here in ElectronSeedGenerator " << __FILE__ << ":" << __LINE__ << " I would like to do theMeasurementTracker->update(e); but that no longer makes sense.\n";
275  }
276 
277  for (unsigned int i=0;i<sclRefs.size();++i) {
278  // Find the seeds
279  recHits_.clear();
280 
281  LogDebug ("ElectronSeedGenerator") << "new cluster, calling seedsFromThisCluster";
282  seedsFromThisCluster(sclRefs[i],hoe1s[i],hoe2s[i],out,tTopo);
283  }
284 
285  LogDebug ("ElectronSeedGenerator") << ": For event "<<e.id();
286  LogDebug ("ElectronSeedGenerator") <<"Nr of superclusters after filter: "<<sclRefs.size()
287  <<", no. of ElectronSeeds found = " << out.size();
288 
289 #ifdef COUNT_ElectronSeeds
290  stcount.s+=sclRefs.size();
291  stcount.n+=out.size();
292 #endif
293 
294 }
295 
298  float hoe1, float hoe2,
299  reco::ElectronSeedCollection & out, const TrackerTopology *tTopo )
300 {
301  float clusterEnergy = seedCluster->energy() ;
302  GlobalPoint clusterPos
303  ( seedCluster->position().x(),
304  seedCluster->position().y(),
305  seedCluster->position().z() ) ;
306  reco::ElectronSeed::CaloClusterRef caloCluster(seedCluster) ;
307 
308  //LogDebug("") << "[ElectronSeedGenerator::seedsFromThisCluster] new supercluster with energy: " << clusterEnergy ;
309  //LogDebug("") << "[ElectronSeedGenerator::seedsFromThisCluster] and position: " << clusterPos ;
310 
311  if (dynamicphiroad_)
312  {
313  float clusterEnergyT = clusterEnergy / cosh( EleRelPoint(clusterPos,theBeamSpot->position()).eta() ) ;
314 
315  float deltaPhi1 ;
316  if (clusterEnergyT < lowPtThreshold_)
317  { deltaPhi1= deltaPhi1Low_ ; }
318  else if (clusterEnergyT > highPtThreshold_)
319  { deltaPhi1= deltaPhi1High_ ; }
320  else
321  { deltaPhi1 = deltaPhi1Coef1_ + deltaPhi1Coef2_/clusterEnergyT ; }
322 
323  float ephimin1 = -deltaPhi1*sizeWindowENeg_ ;
324  float ephimax1 = deltaPhi1*(1.-sizeWindowENeg_);
325  float pphimin1 = -deltaPhi1*(1.-sizeWindowENeg_);
326  float pphimax1 = deltaPhi1*sizeWindowENeg_;
327 
328  float phimin2B = -deltaPhi2B_/2. ;
329  float phimax2B = deltaPhi2B_/2. ;
330  float phimin2F = -deltaPhi2F_/2. ;
331  float phimax2F = deltaPhi2F_/2. ;
332 
333 
334  myMatchEle->set1stLayer(ephimin1,ephimax1);
335  myMatchPos->set1stLayer(pphimin1,pphimax1);
336  myMatchEle->set2ndLayer(phimin2B,phimax2B, phimin2F,phimax2F);
337  myMatchPos->set2ndLayer(phimin2B,phimax2B, phimin2F,phimax2F);
338  }
339 
341 
342  if (!useRecoVertex_) // here use the beam spot position
343  {
344  double sigmaZ=theBeamSpot->sigmaZ();
345  double sigmaZ0Error=theBeamSpot->sigmaZ0Error();
346  double sq=sqrt(sigmaZ*sigmaZ+sigmaZ0Error*sigmaZ0Error);
347  double myZmin1=theBeamSpot->position().z()-nSigmasDeltaZ1_*sq;
348  double myZmax1=theBeamSpot->position().z()+nSigmasDeltaZ1_*sq;
349 
350  GlobalPoint vertexPos ;
351  ele_convert(theBeamSpot->position(),vertexPos) ;
352 
353  myMatchEle->set1stLayerZRange(myZmin1,myZmax1);
354  myMatchPos->set1stLayerZRange(myZmin1,myZmax1);
355 
356  if (!fromTrackerSeeds_)
357  {
358  // try electron
359  std::vector<std::pair<RecHitWithDist,ConstRecHitPointer> > elePixelHits
360  = myMatchEle->compatibleHits(clusterPos,vertexPos,
361  clusterEnergy,-1., tTopo, *theNavigationSchool) ;
363  seedsFromRecHits(elePixelHits,dir,eleVertex,caloCluster,out,false) ;
364  // try positron
365  std::vector<std::pair<RecHitWithDist,ConstRecHitPointer> > posPixelHits
366  = myMatchPos->compatibleHits(clusterPos,vertexPos,clusterEnergy,1.,tTopo, *theNavigationSchool) ;
368  seedsFromRecHits(posPixelHits,dir,posVertex,caloCluster,out,true) ;
369  }
370  else
371  {
372  // try electron
373  std::vector<SeedWithInfo> elePixelSeeds
374  = myMatchEle->compatibleSeeds(theInitialSeedColl,clusterPos,vertexPos,clusterEnergy,-1.) ;
375  seedsFromTrajectorySeeds(elePixelSeeds,caloCluster,hoe1,hoe2,out,false) ;
376  // try positron
377  std::vector<SeedWithInfo> posPixelSeeds
378  = myMatchPos->compatibleSeeds(theInitialSeedColl,clusterPos,vertexPos,clusterEnergy,1.) ;
379  seedsFromTrajectorySeeds(posPixelSeeds,caloCluster,hoe1,hoe2,out,true) ;
380  }
381 
382  }
383  else // here we use the reco vertices
384  {
385 
386  myMatchEle->setUseRecoVertex(true) ; //Hit matchers need to know that the vertex is known
388 
389  const std::vector<reco::Vertex> * vtxCollection = theVertices.product() ;
390  std::vector<reco::Vertex>::const_iterator vtxIter ;
391  for (vtxIter = vtxCollection->begin(); vtxIter != vtxCollection->end() ; vtxIter++)
392  {
393 
394  GlobalPoint vertexPos(vtxIter->position().x(),vtxIter->position().y(),vtxIter->position().z());
395  double myZmin1, myZmax1 ;
396  if (vertexPos.z()==theBeamSpot->position().z())
397  { // in case vetex not found
398  double sigmaZ=theBeamSpot->sigmaZ();
399  double sigmaZ0Error=theBeamSpot->sigmaZ0Error();
400  double sq=sqrt(sigmaZ*sigmaZ+sigmaZ0Error*sigmaZ0Error);
401  myZmin1=theBeamSpot->position().z()-nSigmasDeltaZ1_*sq;
402  myZmax1=theBeamSpot->position().z()+nSigmasDeltaZ1_*sq;
403  }
404  else
405  { // a vertex has been recoed
406  myZmin1=vtxIter->position().z()-deltaZ1WithVertex_;
407  myZmax1=vtxIter->position().z()+deltaZ1WithVertex_;
408  }
409 
410  myMatchEle->set1stLayerZRange(myZmin1,myZmax1);
411  myMatchPos->set1stLayerZRange(myZmin1,myZmax1);
412 
413  if (!fromTrackerSeeds_)
414  {
415  // try electron
416  std::vector<std::pair<RecHitWithDist,ConstRecHitPointer> > elePixelHits
417  = myMatchEle->compatibleHits(clusterPos,vertexPos,clusterEnergy,-1.,tTopo, *theNavigationSchool) ;
418  seedsFromRecHits(elePixelHits,dir,vertexPos,caloCluster,out,false) ;
419  // try positron
420  std::vector<std::pair<RecHitWithDist,ConstRecHitPointer> > posPixelHits
421  = myMatchPos->compatibleHits(clusterPos,vertexPos,clusterEnergy,1.,tTopo, *theNavigationSchool) ;
422  seedsFromRecHits(posPixelHits,dir,vertexPos,caloCluster,out,true) ;
423  }
424  else
425  {
426  // try electron
427  std::vector<SeedWithInfo> elePixelSeeds
428  = myMatchEle->compatibleSeeds(theInitialSeedColl,clusterPos,vertexPos,clusterEnergy,-1.) ;
429  seedsFromTrajectorySeeds(elePixelSeeds,caloCluster,hoe1,hoe2,out,false) ;
430  // try positron
431  std::vector<SeedWithInfo> posPixelSeeds
432  = myMatchPos->compatibleSeeds(theInitialSeedColl,clusterPos,vertexPos,clusterEnergy,1.) ;
433  seedsFromTrajectorySeeds(posPixelSeeds,caloCluster,hoe1,hoe2,out,true) ;
434  }
435  }
436  }
437 
438  return ;
439  }
440 
442  ( std::vector<std::pair<RecHitWithDist,ConstRecHitPointer> > & pixelHits,
444  const GlobalPoint & vertexPos, const reco::ElectronSeed::CaloClusterRef & cluster,
446  bool positron )
447  {
448  if (!pixelHits.empty())
449  { LogDebug("ElectronSeedGenerator") << "Compatible "<<(positron?"positron":"electron")<<" hits found." ; }
450 
451  std::vector<std::pair<RecHitWithDist,ConstRecHitPointer> >::iterator v ;
452  for ( v = pixelHits.begin() ; v != pixelHits.end() ; v++ )
453  {
454  if (!positron)
455  { (*v).first.invert() ; }
456  if (!prepareElTrackSeed((*v).first.recHit(),(*v).second,vertexPos))
457  { continue ; }
459  seed.setCaloCluster(cluster) ;
460  addSeed(seed,nullptr,positron,out) ;
461  }
462  }
463 
465  ( const std::vector<SeedWithInfo> & pixelSeeds,
466  const reco::ElectronSeed::CaloClusterRef & cluster,
467  float hoe1, float hoe2,
469  bool positron )
470  {
471  if (!pixelSeeds.empty())
472  { LogDebug("ElectronSeedGenerator") << "Compatible "<<(positron?"positron":"electron")<<" seeds found." ; }
473 
474  std::vector<SeedWithInfo>::const_iterator s;
475  for ( s = pixelSeeds.begin() ; s != pixelSeeds.end() ; s++ )
476  {
477  reco::ElectronSeed seed(s->seed()) ;
478  seed.setCaloCluster(cluster);
479  seed.initTwoHitSeed(s->hitsMask());
480  addSeed(seed,&*s,positron,out) ;
481  }
482  }
483 
486  const SeedWithInfo * info,
487  bool positron,
489  {
490  if (!info)
491  { out.emplace_back(seed) ; return ; }
492 
493  if (positron)
494  { seed.setPosAttributes(info->dRz2(),info->dPhi2(),info->dRz1(),info->dPhi1()) ; }
495  else
496  { seed.setNegAttributes(info->dRz2(),info->dPhi2(),info->dRz1(),info->dPhi1()) ; }
497  reco::ElectronSeedCollection::iterator resItr ;
498  for ( resItr=out.begin() ; resItr!=out.end() ; ++resItr )
499  {
500  if ( (seed.caloCluster().key()==resItr->caloCluster().key()) &&
501  (seed.hitsMask()==resItr->hitsMask()) &&
502  equivalent(seed,*resItr) )
503  {
504  if (positron)
505  {
506  if ( resItr->dRz2Pos()==std::numeric_limits<float>::infinity() &&
507  resItr->dRz2()!=std::numeric_limits<float>::infinity() )
508  {
509  resItr->setPosAttributes(info->dRz2(),info->dPhi2(),info->dRz1(),info->dPhi1()) ;
510  seed.setNegAttributes(resItr->dRz2(),resItr->dPhi2(),resItr->dRz1(),resItr->dPhi1()) ;
511  break ;
512  }
513  else
514  {
515  if ( resItr->dRz2Pos()!=std::numeric_limits<float>::infinity() )
516  {
517  if ( resItr->dRz2Pos()!=seed.dRz2Pos() )
518  {
519  edm::LogWarning("ElectronSeedGenerator|BadValue")
520  <<"this similar old seed already has another dRz2Pos"
521  <<"\nold seed mask/dRz2/dPhi2/dRz2Pos/dPhi2Pos: "<<(unsigned int)resItr->hitsMask()<<"/"<<resItr->dRz2()<<"/"<<resItr->dPhi2()<<"/"<<resItr->dRz2Pos()<<"/"<<resItr->dPhi2Pos()
522  <<"\nnew seed mask/dRz2/dPhi2/dRz2Pos/dPhi2Pos: "<<(unsigned int)seed.hitsMask()<<"/"<<seed.dRz2()<<"/"<<seed.dPhi2()<<"/"<<seed.dRz2Pos()<<"/"<<seed.dPhi2Pos() ;
523  }
524 // else
525 // {
526 // edm::LogWarning("ElectronSeedGenerator|UnexpectedValue")
527 // <<"this old seed already knows its dRz2Pos, we suspect duplicates in input trajectry seeds"
528 // <<"\nold seed mask/dRz2/dPhi2/dRz2Pos/dPhi2Pos: "<<(unsigned int)resItr->hitsMask()<<"/"<<resItr->dRz2()<<"/"<<resItr->dPhi2()<<"/"<<resItr->dRz2Pos()<<"/"<<resItr->dPhi2Pos()
529 // <<"\nnew seed mask/dRz2/dPhi2/dRz2Pos/dPhi2Pos: "<<(unsigned int)seed.hitsMask()<<"/"<<seed.dRz2()<<"/"<<seed.dPhi2()<<"/"<<seed.dRz2Pos()<<"/"<<seed.dPhi2Pos() ;
530 // }
531  }
532 // if (resItr->dRz2()==std::numeric_limits<float>::infinity())
533 // {
534 // edm::LogWarning("ElectronSeedGenerator|BadValue")
535 // <<"this old seed has no dRz2, we suspect duplicates in input trajectry seeds"
536 // <<"\nold seed mask/dRz2/dPhi2/dRz2Pos/dPhi2Pos: "<<(unsigned int)resItr->hitsMask()<<"/"<<resItr->dRz2()<<"/"<<resItr->dPhi2()<<"/"<<resItr->dRz2Pos()<<"/"<<resItr->dPhi2Pos()
537 // <<"\nnew seed mask/dRz2/dPhi2/dRz2Pos/dPhi2Pos: "<<(unsigned int)seed.hitsMask()<<"/"<<seed.dRz2()<<"/"<<seed.dPhi2()<<"/"<<seed.dRz2Pos()<<"/"<<seed.dPhi2Pos() ;
538 // }
539  }
540  }
541  else
542  {
543  if ( resItr->dRz2()==std::numeric_limits<float>::infinity()
544  && resItr->dRz2Pos()!=std::numeric_limits<float>::infinity() )
545  {
546  resItr->setNegAttributes(info->dRz2(),info->dPhi2(),info->dRz1(),info->dPhi1()) ;
547  seed.setPosAttributes(resItr->dRz2Pos(),resItr->dPhi2Pos(),resItr->dRz1Pos(),resItr->dPhi1Pos()) ;
548  break ;
549  }
550  else
551  {
552  if ( resItr->dRz2()!=std::numeric_limits<float>::infinity() )
553  {
554  if (resItr->dRz2()!=seed.dRz2())
555  {
556  edm::LogWarning("ElectronSeedGenerator|BadValue")
557  <<"this old seed already has another dRz2"
558  <<"\nold seed mask/dRz2/dPhi2/dRz2Pos/dPhi2Pos: "<<(unsigned int)resItr->hitsMask()<<"/"<<resItr->dRz2()<<"/"<<resItr->dPhi2()<<"/"<<resItr->dRz2Pos()<<"/"<<resItr->dPhi2Pos()
559  <<"\nnew seed mask/dRz2/dPhi2/dRz2Pos/dPhi2Pos: "<<(unsigned int)seed.hitsMask()<<"/"<<seed.dRz2()<<"/"<<seed.dPhi2()<<"/"<<seed.dRz2Pos()<<"/"<<seed.dPhi2Pos() ;
560  }
561  // else
562  // {
563  // edm::LogWarning("ElectronSeedGenerator|UnexpectedValue")
564  // <<"this old seed already knows its dRz2, we suspect duplicates in input trajectry seeds"
565  // <<"\nold seed mask/dRz2/dPhi2/dRz2Pos/dPhi2Pos: "<<(unsigned int)resItr->hitsMask()<<"/"<<resItr->dRz2()<<"/"<<resItr->dPhi2()<<"/"<<resItr->dRz2Pos()<<"/"<<resItr->dPhi2Pos()
566  // <<"\nnew seed mask/dRz2/dPhi2/dRz2Pos/dPhi2Pos: "<<(unsigned int)seed.hitsMask()<<"/"<<seed.dRz2()<<"/"<<seed.dPhi2()<<"/"<<seed.dRz2Pos()<<"/"<<seed.dPhi2Pos() ;
567  // seed.setPosAttributes(resItr->dRz2Pos(),resItr->dPhi2Pos(),resItr->dRz1Pos(),resItr->dPhi1Pos()) ;
568  // }
569  }
570 // if (resItr->dRz2Pos()==std::numeric_limits<float>::infinity())
571 // {
572 // edm::LogWarning("ElectronSeedGenerator|BadValue")
573 // <<"this old seed has no dRz2Pos"
574 // <<"\nold seed mask/dRz2/dPhi2/dRz2Pos/dPhi2Pos: "<<(unsigned int)resItr->hitsMask()<<"/"<<resItr->dRz2()<<"/"<<resItr->dPhi2()<<"/"<<resItr->dRz2Pos()<<"/"<<resItr->dPhi2Pos()
575 // <<"\nnew seed mask/dRz2/dPhi2/dRz2Pos/dPhi2Pos: "<<(unsigned int)seed.hitsMask()<<"/"<<seed.dRz2()<<"/"<<seed.dPhi2()<<"/"<<seed.dRz2Pos()<<"/"<<seed.dPhi2Pos() ;
576 // }
577  }
578  }
579  }
580  }
581 
582  out.emplace_back(seed) ;
583  }
584 
586  ( ConstRecHitPointer innerhit,
587  ConstRecHitPointer outerhit,
588  const GlobalPoint& vertexPos )
589  {
590 
591  // debug prints
592  LogDebug("") <<"[ElectronSeedGenerator::prepareElTrackSeed] inner PixelHit x,y,z "<<innerhit->globalPosition();
593  LogDebug("") <<"[ElectronSeedGenerator::prepareElTrackSeed] outer PixelHit x,y,z "<<outerhit->globalPosition();
594 
595  recHits_.clear();
596 
597  SiPixelRecHit *pixhit=nullptr;
598  SiStripMatchedRecHit2D *striphit=nullptr;
599  const SiPixelRecHit* constpixhit = dynamic_cast <const SiPixelRecHit*> (innerhit->hit());
600  if (constpixhit) {
601  pixhit=new SiPixelRecHit(*constpixhit);
602  recHits_.push_back(pixhit);
603  } else return false;
604  constpixhit = dynamic_cast <const SiPixelRecHit *> (outerhit->hit());
605  if (constpixhit) {
606  pixhit=new SiPixelRecHit(*constpixhit);
607  recHits_.push_back(pixhit);
608  } else {
609  const SiStripMatchedRecHit2D * conststriphit=dynamic_cast <const SiStripMatchedRecHit2D *> (outerhit->hit());
610  if (conststriphit) {
611  striphit = new SiStripMatchedRecHit2D(*conststriphit);
612  recHits_.push_back(striphit);
613  } else return false;
614  }
615 
617 
618  // FIXME to be optimized outside the loop
620  theSetup->get<IdealMagneticFieldRecord>().get(bfield);
621  float nomField = bfield->nominalValue();
622 
623  // make a spiral
624  FastHelix helix(outerhit->globalPosition(),innerhit->globalPosition(),vertexPos,nomField,&*bfield);
625  if ( !helix.isValid()) {
626  return false;
627  }
628  FreeTrajectoryState fts(helix.stateAtVertex());
629  TSOS propagatedState = thePropagator->propagate(fts,innerhit->det()->surface()) ;
630  if (!propagatedState.isValid())
631  return false;
632  TSOS updatedState = theUpdator->update(propagatedState, *innerhit);
633 
634  TSOS propagatedState_out = thePropagator->propagate(updatedState,outerhit->det()->surface()) ;
635  if (!propagatedState_out.isValid())
636  return false;
637  TSOS updatedState_out = theUpdator->update(propagatedState_out, *outerhit);
638  // debug prints
639  LogDebug("") <<"[ElectronSeedGenerator::prepareElTrackSeed] final TSOS, position: "<<updatedState_out.globalPosition()<<" momentum: "<<updatedState_out.globalMomentum();
640  LogDebug("") <<"[ElectronSeedGenerator::prepareElTrackSeed] final TSOS Pt: "<<updatedState_out.globalMomentum().perp();
641  pts_ = trajectoryStateTransform::persistentState(updatedState_out, outerhit->geographicalId().rawId());
642 
643  return true;
644  }
#define LogDebug(id)
PropagationDirection direction() const
T getParameter(std::string const &) const
unsigned long long cacheIdentifier() const
unsigned long long cacheIDNavSchool_
double sigmaZ0Error() const
error on sigma z
Definition: BeamSpot.h:96
static const TGPicture * info(bool iBackgroundIsBlack)
T perp() const
Definition: PV3DBase.h:72
PixelHitMatcher * myMatchEle
void setupES(const edm::EventSetup &setup)
void setEvent(const MeasurementTrackerEvent &event)
void setPosAttributes(const float dRZ2=std::numeric_limits< float >::infinity(), const float dPhi2=std::numeric_limits< float >::infinity(), const float dRZ1=std::numeric_limits< float >::infinity(), const float dPhi1=std::numeric_limits< float >::infinity())
Definition: ElectronSeed.cc:99
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
LocalPoint position() const
Local x and y position coordinates.
TransientTrackingRecHit::ConstRecHitPointer ConstRecHitPointer
void setES(const MagneticField *, const MeasurementTracker *theMeasurementTracker, const TrackerGeometry *trackerGeometry)
const NavigationSchool * theNavigationSchool
float dRz1() const
edm::EDGetTokenT< MeasurementTrackerEvent > theMeasurementTrackerEventTag
PTrajectoryStateOnDet persistentState(const TrajectoryStateOnSurface &ts, unsigned int detid)
const edm::EventSetup * theSetup
float dRz2() const
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:1
GlobalPoint globalPosition() const
const CaloClusterRef & caloCluster() const
Definition: ElectronSeed.h:94
unsigned long long cacheIDMagField_
PropagationDirection
void run(edm::Event &, const edm::EventSetup &setup, const reco::SuperClusterRefVector &, const std::vector< float > &hoe1s, const std::vector< float > &hoe2s, TrajectorySeedCollection *seeds, reco::ElectronSeedCollection &)
#define nullptr
edm::Handle< std::vector< reco::Vertex > > theVertices
unsigned long long cacheIDTrkGeom_
void set2ndLayer(float dummyphi2minB, float dummyphi2maxB, float dummyphi2minF, float dummyphi2maxF)
TrajectorySeedCollection * theInitialSeedColl
void push_back(D *&d)
Definition: OwnVector.h:290
void set1stLayerZRange(float zmin1, float zmax1)
TrajectoryStateOnSurface update(const TrajectoryStateOnSurface &, const TrackingRecHit &) const override
Definition: KFUpdator.cc:75
float dPhi2() const
Definition: ElectronSeed.h:122
float dRz2Pos() const
Definition: ElectronSeed.h:127
const SurfaceType & surface() const
PTrajectoryStateOnDet pts_
edm::ESHandle< TrackerGeometry > theTrackerGeometry
void seedsFromThisCluster(edm::Ref< reco::SuperClusterCollection > seedCluster, float hoe1, float hoe2, reco::ElectronSeedCollection &out, const TrackerTopology *tTopo)
std::vector< TrajectorySeed > TrajectorySeedCollection
size_t key() const
Definition: RefToBase.h:250
recHitContainer::const_iterator const_iterator
T sqrt(T t)
Definition: SSEVec.h:18
void clear()
Definition: OwnVector.h:445
const double infinity
std::pair< const_iterator, const_iterator > range
unsigned int detId() const
PropagatorWithMaterial * thePropagator
edm::Handle< reco::BeamSpot > theBeamSpot
edm::EDGetTokenT< std::vector< reco::Vertex > > verticesTag_
LocalVector momentum() const
Momentum vector in the local frame.
std::vector< ElectronSeed > ElectronSeedCollection
collection of ElectronSeed objects
PixelHitMatcher * myMatchPos
float dRz2() const
Definition: ElectronSeed.h:126
void seedsFromRecHits(std::vector< std::pair< RecHitWithDist, ConstRecHitPointer > > &elePixelHits, PropagationDirection &dir, const GlobalPoint &vertexPos, const reco::ElectronSeed::CaloClusterRef &cluster, reco::ElectronSeedCollection &out, bool positron)
float dPhi1() const
float dPhi2() const
bool prepareElTrackSeed(ConstRecHitPointer outerhit, ConstRecHitPointer innerhit, const GlobalPoint &vertexPos)
TrajectoryStateOnSurface TSOS
Definition: TestHits.cc:19
edm::EDGetTokenT< reco::BeamSpot > beamSpotTag_
PTrajectoryStateOnDet const & startingState() const
float dPhi2Pos() const
Definition: ElectronSeed.h:123
T const * product() const
Definition: Handle.h:81
void set1stLayer(float dummyphi1min, float dummyphi1max)
void addSeed(reco::ElectronSeed &seed, const SeedWithInfo *info, bool positron, reco::ElectronSeedCollection &out)
void setNegAttributes(const float dRZ2=std::numeric_limits< float >::infinity(), const float dPhi2=std::numeric_limits< float >::infinity(), const float dRZ1=std::numeric_limits< float >::infinity(), const float dPhi1=std::numeric_limits< float >::infinity())
Definition: ElectronSeed.cc:87
const T & get() const
Definition: EventSetup.h:59
double sigmaZ() const
sigma z
Definition: BeamSpot.h:80
range recHits() const
ElectronSeedGenerator(const edm::ParameterSet &, const Tokens &)
void ele_convert(const Type1 &obj1, Type2 &obj2)
TrajectoryStateOnSurface propagate(STA const &state, SUR const &surface) const
Definition: Propagator.h:53
TrackCharge charge() const
Charge (-1, 0 or 1)
edm::ESHandle< MagneticField > theMagField
void setCaloCluster(const CaloClusterRef &clus)
Definition: ElectronSeed.h:89
return(e1-e2)*(e1-e2)+dp *dp
edm::EventID id() const
Definition: EventBase.h:60
bool equivalent(const TrajectorySeed &s1, const TrajectorySeed &s2)
unsigned int nHits() const
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
GlobalVector globalMomentum() const
void display_seed(const std::string &title1, const std::string &title2, const reco::ElectronSeed &seed, edm::ESHandle< TrackerGeometry > trackerGeometry)
const MeasurementTracker * theMeasurementTracker
unsigned int hitsMask() const
Definition: ElectronSeed.cc:44
size_type size() const
Size of the RefVector.
Definition: RefVector.h:107
int subDet2() const
Definition: ElectronSeed.h:129
const Point & position() const
position
Definition: BeamSpot.h:62
std::vector< SeedWithInfo > compatibleSeeds(TrajectorySeedCollection *seeds, const GlobalPoint &xmeas, const GlobalPoint &vprim, float energy, float charge)
dbl *** dir
Definition: mlp_gen.cc:35
std::vector< std::pair< RecHitWithDist, ConstRecHitPointer > > compatibleHits(const GlobalPoint &xmeas, const GlobalPoint &vprim, float energy, float charge, const TrackerTopology *tTopo, const NavigationSchool &navigationSchool)
void setUseRecoVertex(bool val)
T const * product() const
Definition: ESHandle.h:86
void seedsFromTrajectorySeeds(const std::vector< SeedWithInfo > &elePixelSeeds, const reco::ElectronSeed::CaloClusterRef &cluster, float hoe1, float hoe2, reco::ElectronSeedCollection &out, bool positron)
const LocalTrajectoryParameters & parameters() const
Our base class.
Definition: SiPixelRecHit.h:23
unsigned long long cacheIDCkfComp_