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 
30 
31 #include <vector>
32 #include <utility>
33 
34 namespace {
35 
36  bool equivalent(const TrajectorySeed &s1, const TrajectorySeed &s2) {
37  if (s1.nHits() != s2.nHits())
38  return false;
39 
40  unsigned int nHits;
41  TrajectorySeed::range r1 = s1.recHits(), r2 = s2.recHits();
43  for (i1 = r1.first, i2 = r2.first, nHits = 0; i1 != r1.second; ++i1, ++i2, ++nHits) {
44  if (!i1->isValid() || !i2->isValid())
45  return false;
46  if (i1->geographicalId() != i2->geographicalId())
47  return false;
48  if (!(i1->localPosition() == i2->localPosition()))
49  return false;
50  }
51 
52  return true;
53  }
54 
55  void addSeed(reco::ElectronSeed &seed, const SeedWithInfo *info, bool positron, reco::ElectronSeedCollection &out) {
56  if (!info) {
57  out.emplace_back(seed);
58  return;
59  }
60 
61  if (positron) {
62  seed.setPosAttributes(info->dRz2, info->dPhi2, info->dRz1, info->dPhi1);
63  } else {
64  seed.setNegAttributes(info->dRz2, info->dPhi2, info->dRz1, info->dPhi1);
65  }
66  for (auto &res : out) {
67  if ((seed.caloCluster().key() == res.caloCluster().key()) && (seed.hitsMask() == res.hitsMask()) &&
68  equivalent(seed, res)) {
69  if (positron) {
70  if (res.dRZPos(1) == std::numeric_limits<float>::infinity() &&
72  res.setPosAttributes(info->dRz2, info->dPhi2, info->dRz1, info->dPhi1);
73  seed.setNegAttributes(res.dRZNeg(1), res.dPhiNeg(1), res.dRZNeg(0), res.dPhiNeg(0));
74  break;
75  } else {
76  if (res.dRZPos(1) != std::numeric_limits<float>::infinity()) {
77  if (res.dRZPos(1) != seed.dRZPos(1)) {
78  edm::LogWarning("ElectronSeedGenerator|BadValue")
79  << "this similar old seed already has another dRz2Pos"
80  << "\nold seed mask/dRz2/dPhi2/dRz2Pos/dPhi2Pos: " << (unsigned int)res.hitsMask() << "/"
81  << res.dRZNeg(1) << "/" << res.dPhiNeg(1) << "/" << res.dRZPos(1) << "/" << res.dPhiPos(1)
82  << "\nnew seed mask/dRz2/dPhi2/dRz2Pos/dPhi2Pos: " << (unsigned int)seed.hitsMask() << "/"
83  << seed.dRZNeg(1) << "/" << seed.dPhiNeg(1) << "/" << seed.dRZPos(1) << "/" << seed.dPhiPos(1);
84  }
85  }
86  }
87  } else {
88  if (res.dRZNeg(1) == std::numeric_limits<float>::infinity() &&
90  res.setNegAttributes(info->dRz2, info->dPhi2, info->dRz1, info->dPhi1);
91  seed.setPosAttributes(res.dRZPos(1), res.dPhiPos(1), res.dRZPos(0), res.dPhiPos(0));
92  break;
93  } else {
94  if (res.dRZNeg(1) != std::numeric_limits<float>::infinity()) {
95  if (res.dRZNeg(1) != seed.dRZNeg(1)) {
96  edm::LogWarning("ElectronSeedGenerator|BadValue")
97  << "this old seed already has another dRz2"
98  << "\nold seed mask/dRz2/dPhi2/dRz2Pos/dPhi2Pos: " << (unsigned int)res.hitsMask() << "/"
99  << res.dRZNeg(1) << "/" << res.dPhiNeg(1) << "/" << res.dRZPos(1) << "/" << res.dPhiPos(1)
100  << "\nnew seed mask/dRz2/dPhi2/dRz2Pos/dPhi2Pos: " << (unsigned int)seed.hitsMask() << "/"
101  << seed.dRZNeg(1) << "/" << seed.dPhiNeg(1) << "/" << seed.dRZPos(1) << "/" << seed.dPhiPos(1);
102  }
103  }
104  }
105  }
106  }
107  }
108 
109  out.emplace_back(seed);
110  }
111 
112  void seedsFromTrajectorySeeds(const std::vector<SeedWithInfo> &pixelSeeds,
113  const reco::ElectronSeed::CaloClusterRef &cluster,
115  bool positron) {
116  if (!pixelSeeds.empty()) {
117  LogDebug("ElectronSeedGenerator") << "Compatible " << (positron ? "positron" : "electron") << " seeds found.";
118  }
119 
120  std::vector<SeedWithInfo>::const_iterator s;
121  for (s = pixelSeeds.begin(); s != pixelSeeds.end(); s++) {
122  reco::ElectronSeed seed(s->seed);
123  seed.setCaloCluster(cluster);
124  seed.initTwoHitSeed(s->hitsMask);
125  addSeed(seed, &*s, positron, out);
126  }
127  }
128 
129 } // namespace
130 
132  : dynamicPhiRoad_(pset.getParameter<bool>("dynamicPhiRoad")),
133  verticesTag_(ts.token_vtx),
134  beamSpotTag_(ts.token_bs),
135  lowPtThresh_(pset.getParameter<double>("LowPtThreshold")),
136  highPtThresh_(pset.getParameter<double>("HighPtThreshold")),
137  nSigmasDeltaZ1_(pset.getParameter<double>("nSigmasDeltaZ1")),
138  deltaZ1WithVertex_(pset.getParameter<double>("deltaZ1WithVertex")),
139  sizeWindowENeg_(pset.getParameter<double>("SizeWindowENeg")),
140  deltaPhi1Low_(pset.getParameter<double>("DeltaPhi1Low")),
141  deltaPhi1High_(pset.getParameter<double>("DeltaPhi1High")),
142  // so that deltaPhi1 = dPhi1Coef1_ + dPhi1Coef2_/clusterEnergyT
143  dPhi1Coef2_(dynamicPhiRoad_ ? (deltaPhi1Low_ - deltaPhi1High_) / (1. / lowPtThresh_ - 1. / highPtThresh_) : 0.),
144  dPhi1Coef1_(dynamicPhiRoad_ ? deltaPhi1Low_ - dPhi1Coef2_ / lowPtThresh_ : 0.),
145  propagator_(nullptr),
146  // use of reco vertex
147  useRecoVertex_(pset.getParameter<bool>("useRecoVertex")),
148  // new B/F configurables
149  deltaPhi2B_(pset.getParameter<double>("DeltaPhi2B")),
150  deltaPhi2F_(pset.getParameter<double>("DeltaPhi2F")),
151  phiMin2B_(-pset.getParameter<double>("PhiMax2B")),
152  phiMin2F_(-pset.getParameter<double>("PhiMax2F")),
153  phiMax2B_(pset.getParameter<double>("PhiMax2B")),
154  phiMax2F_(pset.getParameter<double>("PhiMax2F")),
155  electronMatcher_(pset.getParameter<double>("ePhiMin1"),
156  pset.getParameter<double>("ePhiMax1"),
157  phiMin2B_,
158  phiMax2B_,
159  phiMin2F_,
160  phiMax2F_,
161  -pset.getParameter<double>("z2MaxB"),
162  pset.getParameter<double>("z2MaxB"),
163  -pset.getParameter<double>("r2MaxF"),
164  pset.getParameter<double>("r2MaxF"),
165  -pset.getParameter<double>("rMaxI"),
166  pset.getParameter<double>("rMaxI"),
167  useRecoVertex_),
168  positronMatcher_(pset.getParameter<double>("pPhiMin1"),
169  pset.getParameter<double>("pPhiMax1"),
170  phiMin2B_,
171  phiMax2B_,
172  phiMin2F_,
173  phiMax2F_,
174  -pset.getParameter<double>("z2MaxB"),
175  pset.getParameter<double>("z2MaxB"),
176  -pset.getParameter<double>("r2MaxF"),
177  pset.getParameter<double>("r2MaxF"),
178  -pset.getParameter<double>("rMaxI"),
179  pset.getParameter<double>("rMaxI"),
180  useRecoVertex_) {}
181 
183  // get records if necessary (called once per event)
184  bool tochange = false;
185 
188  cacheIDMagField_ = setup.get<IdealMagneticFieldRecord>().cacheIdentifier();
189  propagator_ = std::make_unique<PropagatorWithMaterial>(alongMomentum, .000511, &(*magField_));
190  tochange = true;
191  }
192 
194  cacheIDTrkGeom_ = setup.get<TrackerDigiGeometryRecord>().cacheIdentifier();
196  tochange = true; //FIXME
197  }
198 
199  if (tochange) {
202  }
203 }
204 
206  const edm::EventSetup &setup,
207  const reco::SuperClusterRefVector &sclRefs,
208  const std::vector<const TrajectorySeedCollection *> &seedsV,
211 
212  // get the beamspot from the Event:
213  auto const &beamSpot = e.get(beamSpotTag_);
214 
215  // if required get the vertices
216  std::vector<reco::Vertex> const *vertices = nullptr;
217  if (useRecoVertex_)
218  vertices = &e.get(verticesTag_);
219 
220  for (unsigned int i = 0; i < sclRefs.size(); ++i) {
221  // Find the seeds
222  LogDebug("ElectronSeedGenerator") << "new cluster, calling seedsFromThisCluster";
224  }
225 
226  LogDebug("ElectronSeedGenerator") << ": For event " << e.id();
227  LogDebug("ElectronSeedGenerator") << "Nr of superclusters after filter: " << sclRefs.size()
228  << ", no. of ElectronSeeds found = " << out.size();
229 }
230 
232  reco::BeamSpot const &beamSpot,
233  std::vector<reco::Vertex> const *vertices,
235  float clusterEnergy = seedCluster->energy();
236  GlobalPoint clusterPos(seedCluster->position().x(), seedCluster->position().y(), seedCluster->position().z());
237  reco::ElectronSeed::CaloClusterRef caloCluster(seedCluster);
238 
239  if (dynamicPhiRoad_) {
240  float clusterEnergyT = clusterEnergy / cosh(EleRelPoint(clusterPos, beamSpot.position()).eta());
241 
242  float deltaPhi1;
243  if (clusterEnergyT < lowPtThresh_) {
244  deltaPhi1 = deltaPhi1Low_;
245  } else if (clusterEnergyT > highPtThresh_) {
246  deltaPhi1 = deltaPhi1High_;
247  } else {
248  deltaPhi1 = dPhi1Coef1_ + dPhi1Coef2_ / clusterEnergyT;
249  }
250 
251  float ephimin1 = -deltaPhi1 * sizeWindowENeg_;
252  float ephimax1 = deltaPhi1 * (1. - sizeWindowENeg_);
253  float pphimin1 = -deltaPhi1 * (1. - sizeWindowENeg_);
254  float pphimax1 = deltaPhi1 * sizeWindowENeg_;
255 
256  float phimin2B = -deltaPhi2B_ / 2.;
257  float phimax2B = deltaPhi2B_ / 2.;
258  float phimin2F = -deltaPhi2F_ / 2.;
259  float phimax2F = deltaPhi2F_ / 2.;
260 
261  electronMatcher_.set1stLayer(ephimin1, ephimax1);
262  positronMatcher_.set1stLayer(pphimin1, pphimax1);
263  electronMatcher_.set2ndLayer(phimin2B, phimax2B, phimin2F, phimax2F);
264  positronMatcher_.set2ndLayer(phimin2B, phimax2B, phimin2F, phimax2F);
265  }
266 
267  if (!useRecoVertex_) // here use the beam spot position
268  {
269  double sigmaZ = beamSpot.sigmaZ();
270  double sigmaZ0Error = beamSpot.sigmaZ0Error();
271  double sq = sqrt(sigmaZ * sigmaZ + sigmaZ0Error * sigmaZ0Error);
272  double myZmin1 = beamSpot.position().z() - nSigmasDeltaZ1_ * sq;
273  double myZmax1 = beamSpot.position().z() + nSigmasDeltaZ1_ * sq;
274 
275  GlobalPoint vertexPos;
276  ele_convert(beamSpot.position(), vertexPos);
277 
278  electronMatcher_.set1stLayerZRange(myZmin1, myZmax1);
279  positronMatcher_.set1stLayerZRange(myZmin1, myZmax1);
280 
281  // try electron
282  auto elePixelSeeds = electronMatcher_(*initialSeedCollectionVector_, clusterPos, vertexPos, clusterEnergy, -1.);
283  seedsFromTrajectorySeeds(elePixelSeeds, caloCluster, out, false);
284  // try positron
285  auto posPixelSeeds = positronMatcher_(*initialSeedCollectionVector_, clusterPos, vertexPos, clusterEnergy, 1.);
286  seedsFromTrajectorySeeds(posPixelSeeds, caloCluster, out, true);
287 
288  } else if (vertices) // here we use the reco vertices
289  {
290  for (auto const &vertex : *vertices) {
291  GlobalPoint vertexPos(vertex.position().x(), vertex.position().y(), vertex.position().z());
292  double myZmin1, myZmax1;
293  if (vertexPos.z() == beamSpot.position().z()) { // in case vetex not found
294  double sigmaZ = beamSpot.sigmaZ();
295  double sigmaZ0Error = beamSpot.sigmaZ0Error();
296  double sq = sqrt(sigmaZ * sigmaZ + sigmaZ0Error * sigmaZ0Error);
297  myZmin1 = beamSpot.position().z() - nSigmasDeltaZ1_ * sq;
298  myZmax1 = beamSpot.position().z() + nSigmasDeltaZ1_ * sq;
299  } else { // a vertex has been recoed
300  myZmin1 = vertex.position().z() - deltaZ1WithVertex_;
301  myZmax1 = vertex.position().z() + deltaZ1WithVertex_;
302  }
303 
304  electronMatcher_.set1stLayerZRange(myZmin1, myZmax1);
305  positronMatcher_.set1stLayerZRange(myZmin1, myZmax1);
306 
307  // try electron
308  auto elePixelSeeds = electronMatcher_(*initialSeedCollectionVector_, clusterPos, vertexPos, clusterEnergy, -1.);
309  seedsFromTrajectorySeeds(elePixelSeeds, caloCluster, out, false);
310  // try positron
311  auto posPixelSeeds = positronMatcher_(*initialSeedCollectionVector_, clusterPos, vertexPos, clusterEnergy, 1.);
312  seedsFromTrajectorySeeds(posPixelSeeds, caloCluster, out, true);
313  }
314  }
315 }
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
ElectronSeedGenerator::cacheIDMagField_
unsigned long long cacheIDMagField_
Definition: ElectronSeedGenerator.h:92
testProducerWithPsetDescEmpty_cfi.i2
i2
Definition: testProducerWithPsetDescEmpty_cfi.py:46
electrons_cff.bool
bool
Definition: electrons_cff.py:372
mps_fire.i
i
Definition: mps_fire.py:355
MeasurementTrackerEvent.h
pwdgSkimBPark_cfi.beamSpot
beamSpot
Definition: pwdgSkimBPark_cfi.py:5
MessageLogger.h
ElectronSeedGenerator::deltaZ1WithVertex_
const float deltaZ1WithVertex_
Definition: ElectronSeedGenerator.h:75
ele_convert
void ele_convert(const Type1 &obj1, Type2 &obj2)
Definition: ElectronUtilities.h:16
TrajectorySeed::range
std::pair< const_iterator, const_iterator > range
Definition: TrajectorySeed.h:21
TrajectorySeed::nHits
unsigned int nHits() const
Definition: TrajectorySeed.h:53
PixelHitMatcher::set1stLayerZRange
void set1stLayerZRange(float zmin1, float zmax1)
Definition: PixelHitMatcher.cc:90
ElectronSeedGenerator::dPhi1Coef1_
const double dPhi1Coef1_
Definition: ElectronSeedGenerator.h:83
ElectronSeedGenerator::magField_
edm::ESHandle< MagneticField > magField_
Definition: ElectronSeedGenerator.h:87
testProducerWithPsetDescEmpty_cfi.i1
i1
Definition: testProducerWithPsetDescEmpty_cfi.py:45
ElectronSeedGenerator::positronMatcher_
PixelHitMatcher positronMatcher_
Definition: ElectronSeedGenerator.h:107
TrackerRecoGeometryRecord.h
TrajectorySeed::const_iterator
recHitContainer::const_iterator const_iterator
Definition: TrajectorySeed.h:20
ElectronSeedGenerator::sizeWindowENeg_
const float sizeWindowENeg_
Definition: ElectronSeedGenerator.h:76
info
static const TGPicture * info(bool iBackgroundIsBlack)
Definition: FWCollectionSummaryWidget.cc:152
ElectronSeedGenerator::trackerGeometry_
edm::ESHandle< TrackerGeometry > trackerGeometry_
Definition: ElectronSeedGenerator.h:88
edm::RefVector
Definition: EDProductfwd.h:27
CkfComponentsRecord.h
indexGen.s2
s2
Definition: indexGen.py:107
ElectronSeedGenerator.h
ElectronUtilities.h
infinity
const double infinity
Definition: CSCChamberFitter.cc:10
ElectronSeedGenerator::highPtThresh_
const float highPtThresh_
Definition: ElectronSeedGenerator.h:73
ElectronSeedGenerator::deltaPhi1High_
const float deltaPhi1High_
Definition: ElectronSeedGenerator.h:79
ElectronSeedGenerator::nSigmasDeltaZ1_
const float nSigmasDeltaZ1_
Definition: ElectronSeedGenerator.h:74
singleTopDQM_cfi.setup
setup
Definition: singleTopDQM_cfi.py:37
ElectronSeedGenerator::deltaPhi1Low_
const float deltaPhi1Low_
Definition: ElectronSeedGenerator.h:78
ElectronSeedGenerator::lowPtThresh_
const float lowPtThresh_
Definition: ElectronSeedGenerator.h:72
ElectronSeedGenerator::beamSpotTag_
const edm::EDGetTokenT< reco::BeamSpot > beamSpotTag_
Definition: ElectronSeedGenerator.h:70
edm::Ref
Definition: AssociativeIterator.h:58
hltEgammaHLTExtra_cfi.pixelSeeds
pixelSeeds
Definition: hltEgammaHLTExtra_cfi.py:6
ElectronSeedGenerator::cacheIDTrkGeom_
unsigned long long cacheIDTrkGeom_
Definition: ElectronSeedGenerator.h:94
IdealMagneticFieldRecord
Definition: IdealMagneticFieldRecord.h:11
ElectronSeedGenerator::setupES
void setupES(const edm::EventSetup &setup)
Definition: ElectronSeedGenerator.cc:182
alignCSCRings.s
s
Definition: alignCSCRings.py:92
EleRelPoint
Definition: ElectronUtilities.h:25
reco::ElectronSeed
Definition: ElectronSeed.h:51
TrackerTopologyRcd.h
PVValHelper::eta
Definition: PVValidationHelpers.h:69
TrackerDigiGeometryRecord
Definition: TrackerDigiGeometryRecord.h:15
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
reco::BeamSpot
Definition: BeamSpot.h:21
IdealMagneticFieldRecord.h
reco::ElectronSeedCollection
std::vector< ElectronSeed > ElectronSeedCollection
collection of ElectronSeed objects
Definition: ElectronSeedFwd.h:10
Point3DBase< float, GlobalTag >
edm::LogWarning
Definition: MessageLogger.h:141
PixelHitMatcher::set2ndLayer
void set2ndLayer(float dummyphi2minB, float dummyphi2maxB, float dummyphi2minF, float dummyphi2maxF)
Definition: PixelHitMatcher.cc:97
TrackerDigiGeometryRecord.h
bphysicsOniaDQM_cfi.vertex
vertex
Definition: bphysicsOniaDQM_cfi.py:7
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:670
edm::ParameterSet
Definition: ParameterSet.h:36
ElectronSeedGenerator::propagator_
std::unique_ptr< PropagatorWithMaterial > propagator_
Definition: ElectronSeedGenerator.h:89
PropagatorWithMaterial.h
ElectronSeedGenerator::ElectronSeedGenerator
ElectronSeedGenerator(const edm::ParameterSet &, const Tokens &)
Definition: ElectronSeedGenerator.cc:131
diffTwoXMLs.r2
r2
Definition: diffTwoXMLs.py:73
createfilelist.int
int
Definition: createfilelist.py:10
ElectronSeedGenerator::Tokens
Definition: ElectronSeedGenerator.h:43
ElectronSeedGenerator::seedsFromThisCluster
void seedsFromThisCluster(edm::Ref< reco::SuperClusterCollection > seedCluster, reco::BeamSpot const &beamSpot, std::vector< reco::Vertex > const *vertices, reco::ElectronSeedCollection &out)
Definition: ElectronSeedGenerator.cc:231
edm::EventSetup
Definition: EventSetup.h:57
get
#define get
res
Definition: Electron.h:6
ElectronSeedGenerator::deltaPhi2F_
const float deltaPhi2F_
Definition: ElectronSeedGenerator.h:99
ElectronSeedGenerator::dynamicPhiRoad_
const bool dynamicPhiRoad_
Definition: ElectronSeedGenerator.h:68
ElectronSeedGenerator::electronMatcher_
PixelHitMatcher electronMatcher_
Definition: ElectronSeedGenerator.h:106
ElectronSeedGenerator::deltaPhi2B_
const float deltaPhi2B_
Definition: ElectronSeedGenerator.h:98
PixelHitMatcher::setES
void setES(const MagneticField *, const TrackerGeometry *trackerGeometry)
Definition: PixelHitMatcher.cc:104
diffTwoXMLs.r1
r1
Definition: diffTwoXMLs.py:53
ElectronSeedGenerator::run
void run(edm::Event &, const edm::EventSetup &setup, const reco::SuperClusterRefVector &, const std::vector< const TrajectorySeedCollection * > &seedsV, reco::ElectronSeedCollection &)
Definition: ElectronSeedGenerator.cc:205
TrackingComponentsRecord.h
SuperCluster.h
ElectronSeedGenerator::initialSeedCollectionVector_
const std::vector< const TrajectorySeedCollection * > * initialSeedCollectionVector_
Definition: ElectronSeedGenerator.h:85
TrajectorySeed::recHits
range recHits() const
Definition: TrajectorySeed.h:52
TrajectorySeed
Definition: TrajectorySeed.h:17
edm::RefToBase< CaloCluster >
ElectronSeedGenerator::useRecoVertex_
const bool useRecoVertex_
Definition: ElectronSeedGenerator.h:96
ElectronSeedGenerator::dPhi1Coef2_
const double dPhi1Coef2_
Definition: ElectronSeedGenerator.h:82
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
SeedWithInfo
Definition: PixelHitMatcher.h:33
PixelHitMatcher::set1stLayer
void set1stLayer(float dummyphi1min, float dummyphi1max)
Definition: PixelHitMatcher.cc:83
edm::eventsetup::EventSetupRecord::cacheIdentifier
unsigned long long cacheIdentifier() const
Definition: EventSetupRecord.h:185
fftjetvertexadder_cfi.sigmaZ
sigmaZ
Definition: fftjetvertexadder_cfi.py:32
edm::Event
Definition: Event.h:73
edm::RefVector::size
size_type size() const
Size of the RefVector.
Definition: RefVector.h:102
alongMomentum
Definition: PropagationDirection.h:4
SurveyInfoScenario_cff.seed
seed
Definition: SurveyInfoScenario_cff.py:295
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
pwdgSkimBPark_cfi.vertices
vertices
Definition: pwdgSkimBPark_cfi.py:7
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
ElectronSeedGenerator::verticesTag_
const edm::EDGetTokenT< std::vector< reco::Vertex > > verticesTag_
Definition: ElectronSeedGenerator.h:69