CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FastElectronSeedGenerator.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: EgammaElectronAlgos
4 // Class: FastElectronSeedGenerator.
5 //
13 //
14 // Original Author: Patrick Janot
15 //
16 //
18 
25 
26 #include "FastPixelHitMatcher.h"
28 
31 
34 
38 
42 
45 
46 #include <vector>
47 
48 //#define FAMOS_DEBUG
49 
51  const edm::ParameterSet &pset,
52  double pTMin,
53  const edm::InputTag& beamSpot)
54  :
55  dynamicphiroad_(pset.getParameter<bool>("dynamicPhiRoad")),
56  lowPtThreshold_(pset.getParameter<double>("LowPtThreshold")),
57  highPtThreshold_(pset.getParameter<double>("HighPtThreshold")),
58  sizeWindowENeg_(pset.getParameter<double>("SizeWindowENeg")),
59  phimin2_(pset.getParameter<double>("PhiMin2")),
60  phimax2_(pset.getParameter<double>("PhiMax2")),
61  deltaPhi1Low_(pset.getParameter<double>("DeltaPhi1Low")),
62  deltaPhi1High_(pset.getParameter<double>("DeltaPhi1High")),
63  deltaPhi2_(pset.getParameter<double>("DeltaPhi2")),
64  pTMin2(pTMin*pTMin),
65  myGSPixelMatcher(0),
66  fromTrackerSeeds_(pset.getParameter<bool>("fromTrackerSeeds")),
67  theUpdator(0), thePropagator(0),
68  // theMeasurementTracker(0),
69  // theNavigationSchool(0)
70  theSetup(0), theBeamSpot(beamSpot)
71 {
72 
73 #ifdef FAMOS_DEBUG
74  std::cout << "FromTrackerSeeds = " << fromTrackerSeeds_ << std::endl;
75 #endif
76 
77  // Instantiate the pixel hit matcher
78  searchInTIDTEC = pset.getParameter<bool>("searchInTIDTEC");
79  myGSPixelMatcher = new FastPixelHitMatcher(pset.getParameter<double>("ePhiMin1"),
80  pset.getParameter<double>("ePhiMax1"),
81  pset.getParameter<double>("pPhiMin1"),
82  pset.getParameter<double>("pPhiMax1"),
83  pset.getParameter<double>("PhiMin2"),
84  pset.getParameter<double>("PhiMax2"),
85  pset.getParameter<double>("z2MinB"),
86  pset.getParameter<double>("z2MaxB"),
87  pset.getParameter<double>("r2MinF"),
88  pset.getParameter<double>("r2MaxF"),
89  pset.getParameter<double>("rMinI"),
90  pset.getParameter<double>("rMaxI"),
91  pset.getParameter<bool>("searchInTIDTEC"));
92 
93 }
94 
96 
97  // delete theNavigationSchool;
98  delete myGSPixelMatcher;
99  // delete myMatchPos;
100  delete thePropagator;
101  delete theUpdator;
102 
103 }
104 
105 
107 
108  theSetup= &setup;
109 
111  setup.get<IdealMagneticFieldRecord>().get(pMF);
112  theMagField = &(*pMF);
113 
115  setup.get<TrackerDigiGeometryRecord>().get(geometry);
116  theTrackerGeometry = &(*geometry);
117 
119  setup.get<TrackerRecoGeometryRecord>().get( recoGeom );
120  theGeomSearchTracker = &(*recoGeom);
121 
123  setup.get<TrackerInteractionGeometryRecord>().get( interGeom );
124  theTrackerInteractionGeometry = &(*interGeom);
125 
127  setup.get<MagneticFieldMapRecord>().get(fieldMap);
128  theMagneticFieldMap = &(*fieldMap);
129 
131 
136 
137 }
138 
140  const reco::SuperClusterRefVector &sclRefs,
141  const SiTrackerGSMatchedRecHit2DCollection* theGSRecHits,
142  const edm::SimTrackContainer* theSimTracks,
144  const TrackerTopology *tTopo,
146 
147  // Take the seed collection.
148  theInitialSeedColl=seeds;
149 
150  // Get the beam spot
151  edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
152  e.getByLabel(theBeamSpot,recoBeamSpotHandle);
153 
154  // Get its position
155  BSPosition_ = recoBeamSpotHandle->position();
156  double sigmaZ=recoBeamSpotHandle->sigmaZ();
157  double sigmaZ0Error=recoBeamSpotHandle->sigmaZ0Error();
158  double sq=sqrt(sigmaZ*sigmaZ+sigmaZ0Error*sigmaZ0Error);
159  double zmin1 = BSPosition_.z()-3*sq;
160  double zmax1 = BSPosition_.z()+3*sq;
161 #ifdef FAMOS_DEBUG
162  std::cout << "Z Range for pixel matcher : " << zmin1 << " " << BSPosition_.z() << " " << zmax1 << std::endl;
163 #endif
164  myGSPixelMatcher->set1stLayerZRange(zmin1,zmax1);
165 
166  // A map of vector of pixel seeds, for each clusters
167  std::map<unsigned,std::vector<reco::ElectronSeed> > myPixelSeeds;
168 
169  // No seeding attempted if no hits !
170  if(theGSRecHits->size() == 0) return;
171 
172  if ( !fromTrackerSeeds_ ) {
173 
174  // The vector of simTrack Id's carrying GSRecHits
175  const std::vector<unsigned> theSimTrackIds = theGSRecHits->ids();
176 
177  // Loop over the simTrack carrying GSRecHits
178  for ( unsigned tkId=0; tkId != theSimTrackIds.size(); ++tkId ) {
179 
180  unsigned simTrackId = theSimTrackIds[tkId];
181  const SimTrack& theSimTrack = (*theSimTracks)[simTrackId];
182 
183  // Request a minimum pT for the sim track
184  if ( theSimTrack.momentum().perp2() < pTMin2 ) continue;
185 
186  // Request a minimum number of RecHits (total and in the pixel detector)
187  unsigned numberOfRecHits = 0;
188 
189  // The vector of rechits for seeding
190 
191  // 1) Cluster-pixel match seeding:
192  // Save a collection of Pixel +TEC +TID hits for seeding electrons
193  std::vector<unsigned> layerHit(6,static_cast<unsigned>(0));
194  // const SiTrackerGSMatchedRecHit2D *hit;
195  TrajectorySeedHitCandidate currentHit;
196  std::vector<TrajectorySeedHitCandidate> theHits;
197  TrajectorySeed theTrackerSeed;
198 
199  SiTrackerGSMatchedRecHit2DCollection::range theRecHitRange = theGSRecHits->get(simTrackId);
200  SiTrackerGSMatchedRecHit2DCollection::const_iterator theRecHitRangeIteratorBegin = theRecHitRange.first;
201  SiTrackerGSMatchedRecHit2DCollection::const_iterator theRecHitRangeIteratorEnd = theRecHitRange.second;
204 
205  for ( iterRecHit = theRecHitRangeIteratorBegin;
206  iterRecHit != theRecHitRangeIteratorEnd;
207  ++iterRecHit) {
208  ++numberOfRecHits;
209 
210  currentHit = TrajectorySeedHitCandidate(&(*iterRecHit),theTrackerGeometry,tTopo);
211  if ( ( currentHit.subDetId() <= 2 ) || // Pixel Hits
212  // Add TID/TEC (optional)
213  ( searchInTIDTEC &&
214  ( ( currentHit.subDetId() == 3 &&
215  currentHit.ringNumber() < 3 &&
216  currentHit.layerNumber() < 3 ) || // TID first two rings, first two layers
217  ( currentHit.subDetId() == 6 &&
218  currentHit.ringNumber() < 3 &&
219  currentHit.layerNumber() < 3 ) ) ) ) // TEC first two rings, first two layers
220  theHits.push_back(currentHit);
221  }
222 
223  // At least 3 hits
224  if ( numberOfRecHits < 3 ) continue;
225 
226  // At least 2 pixel hits
227  if ( theHits.size() < 2 ) continue;
228 
229  // Loop over clusters
230 
231  unsigned csize = sclRefs.size();
232  for (unsigned int i=0;i<csize;++i) {
233 
234  // Find the pixel seeds (actually only the best one is returned)
235  LogDebug ("run") << "new cluster, calling addAseedFromThisCluster";
236  addASeedToThisCluster(sclRefs[i],theHits,theTrackerSeed,myPixelSeeds[i]);
237 
238  }
239 
240  }
241  // 2) Check if the seed is in the a-priori seed collection
242  } else {
243 
244  // Loop over the tracker seed
245 #ifdef FAMOS_DEBUG
246  std::cout << "We have " << seeds->size() << " tracker seeds!" << std::endl;
247 #endif
248  for (unsigned int i=0;i<seeds->size();++i) {
249 
250  TrajectorySeedHitCandidate currentHit;
251  std::vector<TrajectorySeedHitCandidate> theHits;
252  const TrajectorySeed& theTrackerSeed = (*seeds)[i];
253  TrajectorySeed::range theSeedRange=theTrackerSeed.recHits();
254  TrajectorySeed::const_iterator theSeedRangeIteratorBegin = theSeedRange.first;
255  TrajectorySeed::const_iterator theSeedRangeIteratorEnd = theSeedRange.second;
256  TrajectorySeed::const_iterator theSeedItr = theSeedRangeIteratorBegin;
257 
258  for ( ; theSeedItr != theSeedRangeIteratorEnd; ++theSeedItr ) {
259  const SiTrackerGSMatchedRecHit2D * theSeedingRecHit =
260  (const SiTrackerGSMatchedRecHit2D*) (&(*theSeedItr));
261  currentHit = TrajectorySeedHitCandidate(theSeedingRecHit,theTrackerGeometry,tTopo);
262  theHits.push_back(currentHit);
263  }
264 
265  // Loop over clusters
266  unsigned csize = sclRefs.size();
267  for (unsigned int i=0;i<csize;++i) {
268 
269  // Find the pixel seeds (actually only the best one is returned)
270 #ifdef FAMOS_DEBUG
271  std::cout << "new cluster, calling addAseedFromThisCluster" << std::endl;
272 #endif
273  addASeedToThisCluster(sclRefs[i],theHits,theTrackerSeed,myPixelSeeds[i]);
274 
275  }
276  // End loop over clusters
277  }
278  // End loop over seeds
279  }
280  // end else
281 
282  // Back to the expected collection
283 
284  std::map<unsigned,std::vector<reco::ElectronSeed> >::const_iterator px = myPixelSeeds.begin();
285  std::map<unsigned,std::vector<reco::ElectronSeed> >::const_iterator pxEnd = myPixelSeeds.end();
286  for ( ; px!=pxEnd; ++px ) {
287  unsigned nSeeds = (px->second).size();
288  for ( unsigned ipx = 0; ipx<nSeeds; ++ipx ) {
289  out.push_back((px->second)[ipx]);
290  reco::ElectronSeed is = px->second[ipx];
291  }
292  }
293 
294  LogDebug ("run") << ": For event "<<e.id();
295  LogDebug ("run") <<"Nr of superclusters: "<<sclRefs.size()
296  <<", no. of ElectronSeeds found = " << out.size();
297 #ifdef FAMOS_DEBUG
298  std::cout << ": For event "<<e.id() << std::endl;
299  std::cout <<"Nr of superclusters: "<<sclRefs.size()
300  <<", no. of ElectronSeeds found = " << out.size() << std::endl;
301 #endif
302 
303 }
304 
305 void
307  std::vector<TrajectorySeedHitCandidate>& theHits,
308  const TrajectorySeed& theTrackerSeed,
309  std::vector<reco::ElectronSeed>& result)
310 {
311 
312  float clusterEnergy = seedCluster->energy();
313  GlobalPoint clusterPos(seedCluster->position().x(),
314  seedCluster->position().y(),
315  seedCluster->position().z());
316  const GlobalPoint vertexPos(BSPosition_.x(),BSPosition_.y(),BSPosition_.z());
317 
318 #ifdef FAMOS_DEBUG
319  std::cout << "[FastElectronSeedGenerator::seedsFromThisCluster] "
320  << "new supercluster with energy: " << clusterEnergy << std::endl;
321  std::cout << "[FastElectronSeedGenerator::seedsFromThisCluster] "
322  << "and position: " << clusterPos << std::endl;
323  std::cout << "Vertex position : " << vertexPos << std::endl;
324 #endif
325 
326  //Here change the deltaPhi window of the first pixel layer in function of the seed pT
327  if (dynamicphiroad_) {
328  float clusterEnergyT = clusterEnergy*sin(seedCluster->position().theta()) ;
329 
330  float deltaPhi1 = 0.875/clusterEnergyT + 0.055;
331  if (clusterEnergyT < lowPtThreshold_) deltaPhi1= deltaPhi1Low_;
332  if (clusterEnergyT > highPtThreshold_) deltaPhi1= deltaPhi1High_;
333 
334  float ephimin1 = -deltaPhi1*sizeWindowENeg_ ;
335  float ephimax1 = deltaPhi1*(1.-sizeWindowENeg_);
336  float pphimin1 = -deltaPhi1*(1.-sizeWindowENeg_);
337  float pphimax1 = deltaPhi1*sizeWindowENeg_;
338 
339  float phimin2 = -deltaPhi2_/2.;
340  float phimax2 = deltaPhi2_/2.;
341 
342  myGSPixelMatcher->set1stLayer(ephimin1,ephimax1,pphimin1,pphimax1);
343  myGSPixelMatcher->set2ndLayer(phimin2,phimax2);
344 
345  }
346 
347 
348 
350 
351  // Find the best pixel pair compatible with the cluster
352  std::vector<std::pair<ConstRecHitPointer,ConstRecHitPointer> > compatPixelHits =
353  myGSPixelMatcher->compatibleHits(clusterPos, vertexPos, clusterEnergy, theHits);
354 
355  // The corresponding origin vertex
356  double vertexZ = myGSPixelMatcher->getVertex();
357  GlobalPoint theVertex(BSPosition_.x(),BSPosition_.y(),vertexZ);
358 
359  // Create the Electron pixel seed.
360  if (!compatPixelHits.empty() ) {
361 #ifdef FAMOS_DEBUG
362  std::cout << "[FastElectronSeedGenerator::seedsFromThisCluster] "
363  << " electron compatible hits found " << std::endl;
364 #endif
365  // Pixel-matching case: create the seed from scratch
366  if (!fromTrackerSeeds_) {
367 
368  std::vector<std::pair<ConstRecHitPointer,ConstRecHitPointer> >::iterator v;
369  for (v = compatPixelHits.begin(); v != compatPixelHits.end(); ++v ) {
370 
371  bool valid = prepareElTrackSeed(v->first,v->second, theVertex);
372  if (valid) {
375  result.push_back(s);
376  }
377 
378  }
379 
380  // Here we take instead the seed from a-priori seed collection
381  } else {
382 
383  reco::ElectronSeed s(theTrackerSeed);
385  result.push_back(s);
386  }
387 
388  }
389 
390 #ifdef FAMOS_DEBUG
391  else
392  std::cout << "[FastElectronSeedGenerator::seedsFromThisCluster] "
393  << " No electron compatible hits found " << std::endl;
394 #endif
395 
396 
397  // And return !
398  return ;
399 
400 }
401 
403  ConstRecHitPointer outerhit,
404  const GlobalPoint& vertexPos)
405 {
406 
407  // debug prints
408  LogDebug("") <<"[FastElectronSeedGenerator::prepareElTrackSeed] "
409  << "inner PixelHit x,y,z "<<innerhit->globalPosition();
410  LogDebug("") <<"[FastElectronSeedGenerator::prepareElTrackSeed] "
411  << "outer PixelHit x,y,z "<<outerhit->globalPosition();
412 
413  // FIXME to be optimized moving them outside the loop
415  theSetup->get<IdealMagneticFieldRecord>().get(bfield);
416  float nomField = bfield->nominalValue();
417 
418  // make a spiral from the two hits and the vertex position
419  FastHelix helix(outerhit->globalPosition(),innerhit->globalPosition(),vertexPos,nomField,&*bfield);
420  if ( !helix.isValid()) return false;
421 
422  FreeTrajectoryState fts(helix.stateAtVertex());
423 
424  // Give infinite errors to start the fit (no pattern recognition here).
426  fts.setCurvilinearError(errorMatrix*100.);
427 
428  TrajectoryStateOnSurface propagatedState = thePropagator->propagate(fts,innerhit->det()->surface()) ;
429  if (!propagatedState.isValid()) return false;
430 
431  // The persitent trajectory state
432  pts_ = trajectoryStateTransform::persistentState(propagatedState, innerhit->geographicalId().rawId());
433 
434  // The corresponding rechits
435  recHits_.clear();
436  recHits_.push_back(innerhit->hit()->clone());
437  recHits_.push_back(outerhit->hit()->clone());
438 
439 
440  return true;
441 
442 }
443 
#define LogDebug(id)
void setCaloCluster(const CaloClusterRef &, unsigned char hitsMask=0, int subDet2=0, int subDet1=0, float hoe1=std::numeric_limits< float >::infinity(), float hoe2=std::numeric_limits< float >::infinity())
Definition: ElectronSeed.cc:71
T getParameter(std::string const &) const
virtual FreeTrajectoryState propagate(const FreeTrajectoryState &ftsStart, const GlobalPoint &pDest) const final
Definition: Propagator.h:119
int i
Definition: DBlmapReader.cc:9
std::pair< const_iterator, const_iterator > range
iterator range
Definition: RangeMap.h:50
void setupES(const edm::EventSetup &setup)
size_t size() const
return number of contained object
Definition: RangeMap.h:130
ROOT::Math::SMatrixIdentity AlgebraicMatrixID
const edm::EventSetup * theSetup
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
PTrajectoryStateOnDet persistentState(const TrajectoryStateOnSurface &ts, unsigned int detid)
const MagneticFieldMap * theMagneticFieldMap
range get(ID id, CMP comparator) const
Definition: RangeMap.h:79
const TrackerInteractionGeometry * theTrackerInteractionGeometry
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
PropagationDirection
TrajectorySeedCollection * theInitialSeedColl
void set1stLayer(float ephimin, float ephimax, float pphimin, float pphimax)
void addASeedToThisCluster(edm::Ref< reco::SuperClusterCollection > seedCluster, std::vector< TrajectorySeedHitCandidate > &theHits, const TrajectorySeed &theTrackerSeed, std::vector< reco::ElectronSeed > &result)
return((rh^lh)&mask)
PropagatorWithMaterial * thePropagator
C::const_iterator const_iterator
constant access iterator type
Definition: RangeMap.h:43
void push_back(D *&d)
Definition: OwnVector.h:280
void set1stLayerZRange(double zmin1, double zmax1)
std::vector< TrajectorySeed > TrajectorySeedCollection
FastElectronSeedGenerator(const edm::ParameterSet &pset, double pTMin, const edm::InputTag &beamSpot)
recHitContainer::const_iterator const_iterator
T sqrt(T t)
Definition: SSEVec.h:48
tuple result
Definition: query.py:137
void clear()
Definition: OwnVector.h:377
std::pair< const_iterator, const_iterator > range
const GeometricSearchTracker * theGeomSearchTracker
std::vector< ElectronSeed > ElectronSeedCollection
collection of ElectronSeed objects
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:413
FastPixelHitMatcher * myGSPixelMatcher
tuple out
Definition: dbtoconf.py:99
void run(edm::Event &e, const reco::SuperClusterRefVector &sclRefs, const SiTrackerGSMatchedRecHit2DCollection *theGSRecHits, const edm::SimTrackContainer *theSimTracks, TrajectorySeedCollection *seeds, const TrackerTopology *tTopo, reco::ElectronSeedCollection &out)
std::vector< std::pair< ConstRecHitPointer, ConstRecHitPointer > > compatibleHits(const GlobalPoint &xmeas, const GlobalPoint &vprim, float energy, std::vector< TrajectorySeedHitCandidate > &theHits)
bool prepareElTrackSeed(ConstRecHitPointer outerhit, ConstRecHitPointer innerhit, const GlobalPoint &vertexPos)
TransientTrackingRecHit::ConstRecHitPointer ConstRecHitPointer
const T & get() const
Definition: EventSetup.h:55
range recHits() const
unsigned int ringNumber() const
The Ring Number.
ESHandle< TrackerGeometry > geometry
edm::EventID id() const
Definition: EventBase.h:60
const math::XYZTLorentzVectorD & momentum() const
Definition: CoreSimTrack.h:22
size_type size() const
Size of the RefVector.
Definition: RefVector.h:99
void setES(const MagneticFieldMap *aFieldMap, const TrackerGeometry *aTrackerGeometry, const GeometricSearchTracker *geomSearchTracker, const TrackerInteractionGeometry *interactionGeometry)
tuple cout
Definition: gather_cfg.py:121
unsigned int layerNumber() const
The Layer Number.
dbl *** dir
Definition: mlp_gen.cc:35
std::vector< ID > ids() const
indentifier vector
Definition: RangeMap.h:177
unsigned int subDetId() const
The subdet Id.
std::vector< SimTrack > SimTrackContainer
void set2ndLayer(float phimin, float phimax)
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
tuple size
Write out results.
const TrackerGeometry * theTrackerGeometry