CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
GEDPhotonGSCrysFixer.cc
Go to the documentation of this file.
1 #include <vector>
2 #include <memory>
3 
5 
7 
10 
14 
18 
20 
21 namespace {
23  getNewCore(reco::Photon const& oldPho, edm::Handle<reco::PhotonCoreCollection> const& newCores, edm::ValueMap<reco::SuperClusterRef> const& scMap)
24  {
25  for (unsigned iC(0); iC != newCores->size(); ++iC) {
26  reco::PhotonCoreRef newCore(newCores, iC);
27  auto&& oldSCRef(scMap[newCore]);
28  if (oldSCRef.isNonnull() && oldSCRef == oldPho.superCluster())
29  return newCore;
30  }
31  return reco::PhotonCoreRef(newCores.id());
32  }
33 }
34 
35 
37  energyCorrector_(config, consumesCollector())
38 {
39  getToken(inputPhotonsToken_, config, "photons");
40  getToken(newCoresToken_, config, "newCores");
41  getToken(newCoresToOldSCMapToken_, config, "newCores");
42  getToken(ebHitsToken_, config, "barrelEcalHits");
43  getToken(verticesToken_, config, "primaryVertexProducer");
44 
45  if(config.existsAs<edm::ParameterSet>("regressionConfig")) {
46  auto&& collector(consumesCollector());
47  energyCorrector_.gedRegression()->setConsumes(collector);
48  }
49 
50  // output photon collection
51  produces<reco::PhotonCollection>();
52  // new photon -> old photon
53  produces<PhotonRefMap>();
54 }
55 
57 {
58 }
59 
60 void
62 {
63  energyCorrector_.init(_setup);
64 
65  edm::ESHandle<CaloGeometry> geometryHandle;
66  _setup.get<CaloGeometryRecord>().get(geometryHandle);
67  geometry_ = geometryHandle.product();
68 
69  edm::ESHandle<CaloTopology> topologyHandle;
70  _setup.get<CaloTopologyRecord>().get(topologyHandle);
71  topology_ = topologyHandle.product();
72 }
73 
74 void
76 {
77  std::auto_ptr<reco::PhotonCollection> pOutput(new reco::PhotonCollection);
78 
79  auto&& inputPhotonsHandle(getHandle(_event, inputPhotonsToken_, "photons"));
80  auto& inputPhotons(*inputPhotonsHandle);
81  auto&& newCoresHandle(getHandle(_event, newCoresToken_, "newCores"));
82  auto& newCoresToOldSCMap(*getHandle(_event, newCoresToOldSCMapToken_, "newCores"));
83  auto& ebHits(*getHandle(_event, ebHitsToken_, "ebHits"));
84  auto& vertices(*getHandle(_event, verticesToken_, "vertices"));
85 
86  energyCorrector_.init(_setup);
88  energyCorrector_.gedRegression()->setEvent(_event);
89  energyCorrector_.gedRegression()->setEventContent(_setup);
90  }
91 
92  std::vector<reco::PhotonRef> oldPhotons;
93 
94  unsigned iP(0);
95  for (auto& inPhoton : inputPhotons) {
96  auto&& refToBase(inputPhotons.refAt(iP++));
97  oldPhotons.emplace_back(refToBase.id(), &inPhoton, refToBase.key());
98 
99  auto&& newCore(getNewCore(inPhoton, newCoresHandle, newCoresToOldSCMap));
100 
101  auto& oldSC(*inPhoton.photonCore()->superCluster());
102  auto& newSC(*newCore->superCluster());
103 
104  if (GainSwitchTools::hasEBGainSwitchIn5x5(oldSC, &ebHits, topology_)) {
105  auto&& caloPosition(newSC.position());
106 
107  // will fix p4 later, but we apparently need the direction right
108  auto&& direction((caloPosition - inPhoton.vertex()).unit());
109  math::XYZTLorentzVectorD p4(direction.x(), direction.y(), direction.z(), 1.);
110 
111  pOutput->emplace_back(p4, caloPosition, newCore, inPhoton.vertex());
112  auto& outPhoton(pOutput->back());
113 
115  fflags.isEB = inPhoton.isEB();
116  fflags.isEE = inPhoton.isEE();
117  fflags.isEBEtaGap = inPhoton.isEBEtaGap();
118  fflags.isEBPhiGap = inPhoton.isEBPhiGap();
119  fflags.isEERingGap = inPhoton.isEERingGap();
120  fflags.isEEDeeGap = inPhoton.isEEDeeGap();
121  fflags.isEBEEGap = inPhoton.isEBEEGap();
122 
123  outPhoton.setFiducialVolumeFlags(fflags);
124 
126  iso04.ecalRecHitSumEt = inPhoton.ecalRecHitSumEtConeDR04();
127  iso04.hcalTowerSumEt = inPhoton.hcalTowerSumEtConeDR04();
128  iso04.hcalDepth1TowerSumEt = inPhoton.hcalDepth1TowerSumEtConeDR04();
129  iso04.hcalDepth2TowerSumEt = inPhoton.hcalDepth2TowerSumEtConeDR04();
130  iso04.hcalTowerSumEtBc = inPhoton.hcalTowerSumEtBcConeDR04();
131  iso04.hcalDepth1TowerSumEtBc = inPhoton.hcalDepth1TowerSumEtBcConeDR04();
132  iso04.hcalDepth2TowerSumEtBc = inPhoton.hcalDepth2TowerSumEtBcConeDR04();
133  iso04.trkSumPtSolidCone = inPhoton.trkSumPtSolidConeDR04();
134  iso04.trkSumPtHollowCone = inPhoton.trkSumPtHollowConeDR04();
135  iso04.nTrkSolidCone = inPhoton.nTrkSolidConeDR04();
136  iso04.nTrkHollowCone = inPhoton.nTrkHollowConeDR04();
137 
139  iso03.ecalRecHitSumEt = inPhoton.ecalRecHitSumEtConeDR03();
140  iso03.hcalTowerSumEt = inPhoton.hcalTowerSumEtConeDR03();
141  iso03.hcalDepth1TowerSumEt = inPhoton.hcalDepth1TowerSumEtConeDR03();
142  iso03.hcalDepth2TowerSumEt = inPhoton.hcalDepth2TowerSumEtConeDR03();
143  iso03.hcalTowerSumEtBc = inPhoton.hcalTowerSumEtBcConeDR03();
144  iso03.hcalDepth1TowerSumEtBc = inPhoton.hcalDepth1TowerSumEtBcConeDR03();
145  iso03.hcalDepth2TowerSumEtBc = inPhoton.hcalDepth2TowerSumEtBcConeDR03();
146  iso03.trkSumPtSolidCone = inPhoton.trkSumPtSolidConeDR03();
147  iso03.trkSumPtHollowCone = inPhoton.trkSumPtHollowConeDR03();
148  iso03.nTrkSolidCone = inPhoton.nTrkSolidConeDR03();
149  iso03.nTrkHollowCone = inPhoton.nTrkHollowConeDR03();
150 
151  outPhoton.setIsolationVariables(iso04, iso03);
152 
153  auto& newSeed(*newSC.seed());
154 
155  auto&& cov(EcalClusterTools::covariances(newSeed, &ebHits, topology_, geometry_));
156  auto&& locCov(EcalClusterTools::localCovariances(newSeed, &ebHits, topology_));
157  auto&& cov55(noZS::EcalClusterTools::covariances(newSeed, &ebHits, topology_, geometry_));
158  auto&& locCov55(noZS::EcalClusterTools::localCovariances(newSeed, &ebHits, topology_));
159 
160  auto& oldSS(inPhoton.showerShapeVariables());
162 
163  newSS.e1x5 = EcalClusterTools::e1x5(newSeed, &ebHits, topology_);
164  newSS.e2x5 = EcalClusterTools::e2x5Max(newSeed, &ebHits, topology_);
165  newSS.e3x3 = EcalClusterTools::e3x3(newSeed, &ebHits, topology_);
166  newSS.e5x5 = EcalClusterTools::e5x5(newSeed, &ebHits, topology_);
167  newSS.maxEnergyXtal = EcalClusterTools::eMax(newSeed, &ebHits);
168  newSS.sigmaEtaEta = std::sqrt(cov[0]);
169  newSS.sigmaIetaIeta = std::sqrt(locCov[0]);
170  newSS.hcalDepth1OverEcal = oldSS.hcalDepth1OverEcal * oldSC.energy() / newSC.energy();
171  newSS.hcalDepth2OverEcal = oldSS.hcalDepth2OverEcal * oldSC.energy() / newSC.energy();
172  newSS.hcalDepth1OverEcalBc = oldSS.hcalDepth1OverEcalBc * oldSC.energy() / newSC.energy();
173  newSS.hcalDepth2OverEcalBc = oldSS.hcalDepth2OverEcalBc * oldSC.energy() / newSC.energy();
174  newSS.hcalTowersBehindClusters = oldSS.hcalTowersBehindClusters;
175  newSS.sigmaIetaIphi = locCov[1];
176  newSS.sigmaIphiIphi = (edm::isFinite(locCov[2]) ? std::sqrt(locCov[2]) : 0.);
177  newSS.e2nd = EcalClusterTools::e2nd(newSeed, &ebHits);
178  newSS.eTop = EcalClusterTools::eTop(newSeed, &ebHits, topology_);
179  newSS.eLeft = EcalClusterTools::eLeft(newSeed, &ebHits, topology_);
180  newSS.eRight = EcalClusterTools::eRight(newSeed, &ebHits, topology_);
181  newSS.eBottom = EcalClusterTools::eBottom(newSeed, &ebHits, topology_);
182  newSS.e1x3 = EcalClusterTools::e1x3(newSeed, &ebHits, topology_);
183  newSS.e2x2 = EcalClusterTools::e2x2(newSeed, &ebHits, topology_);
184  newSS.e2x5Max = EcalClusterTools::e2x5Max(newSeed, &ebHits, topology_);
185  newSS.e2x5Left = EcalClusterTools::e2x5Left(newSeed, &ebHits, topology_);
186  newSS.e2x5Right = EcalClusterTools::e2x5Right(newSeed, &ebHits, topology_);
187  newSS.e2x5Top = EcalClusterTools::e2x5Top(newSeed, &ebHits, topology_);
188  newSS.e2x5Bottom = EcalClusterTools::e2x5Bottom(newSeed, &ebHits, topology_);
189  newSS.effSigmaRR = oldSS.effSigmaRR;
190 
191  outPhoton.setShowerShapeVariables(newSS);
192 
194  new55SS.e1x5 = noZS::EcalClusterTools::e1x5(newSeed, &ebHits, topology_);
195  new55SS.e2x5 = noZS::EcalClusterTools::e2x5Max(newSeed, &ebHits, topology_);
196  new55SS.e3x3 = noZS::EcalClusterTools::e3x3(newSeed, &ebHits, topology_);
197  new55SS.e5x5 = noZS::EcalClusterTools::e5x5(newSeed, &ebHits, topology_);
198  new55SS.maxEnergyXtal = noZS::EcalClusterTools::eMax(newSeed, &ebHits);
199  new55SS.sigmaEtaEta = std::sqrt(cov55[0]);
200  new55SS.sigmaIetaIeta = std::sqrt(locCov55[0]);
201  new55SS.sigmaIetaIphi = locCov55[1];
202  new55SS.sigmaIphiIphi = (edm::isFinite(locCov55[2]) ? std::sqrt(locCov55[2]) : 0.);
203  new55SS.e2nd = noZS::EcalClusterTools::e2nd(newSeed, &ebHits);
204  new55SS.eTop = noZS::EcalClusterTools::eTop(newSeed, &ebHits, topology_);
205  new55SS.eLeft = noZS::EcalClusterTools::eLeft(newSeed, &ebHits, topology_);
206  new55SS.eRight = noZS::EcalClusterTools::eRight(newSeed, &ebHits, topology_);
207  new55SS.eBottom = noZS::EcalClusterTools::eBottom(newSeed, &ebHits, topology_);
208  new55SS.e1x3 = noZS::EcalClusterTools::e1x3(newSeed, &ebHits, topology_);
209  new55SS.e2x2 = noZS::EcalClusterTools::e2x2(newSeed, &ebHits, topology_);
210  new55SS.e2x5Max = noZS::EcalClusterTools::e2x5Max(newSeed, &ebHits, topology_);
211  new55SS.e2x5Left = noZS::EcalClusterTools::e2x5Left(newSeed, &ebHits, topology_);
212  new55SS.e2x5Right = noZS::EcalClusterTools::e2x5Right(newSeed, &ebHits, topology_);
213  new55SS.e2x5Top = noZS::EcalClusterTools::e2x5Top(newSeed, &ebHits, topology_);
214  new55SS.e2x5Bottom = noZS::EcalClusterTools::e2x5Bottom(newSeed, &ebHits, topology_);
215  new55SS.effSigmaRR = oldSS.effSigmaRR;
216 
217  outPhoton.full5x5_setShowerShapeVariables(new55SS);
218 
220  mipVars.mipChi2 = inPhoton.mipChi2();
221  mipVars.mipTotEnergy = inPhoton.mipTotEnergy();
222  mipVars.mipSlope = inPhoton.mipSlope();
223  mipVars.mipIntercept = inPhoton.mipIntercept();
224  mipVars.mipNhitCone = inPhoton.mipNhitCone();
225  mipVars.mipIsHalo = inPhoton.mipIsHalo();
226 
227  outPhoton.setMIPVariables(mipVars);
228 
229  outPhoton.setPflowIsolationVariables(inPhoton.getPflowIsolationVariables());
230 
232  pfid.nClusterOutsideMustache = inPhoton.nClusterOutsideMustache();
233  pfid.etOutsideMustache = inPhoton.etOutsideMustache();
234  pfid.mva = inPhoton.pfMVA();
235 
236  outPhoton.setPflowIDVariables(pfid);
237 
238  energyCorrector_.calculate(_event, outPhoton, newSeed.hitsAndFractions()[0].first.subdetId(), vertices, _setup);
239 
240  outPhoton.setP4(outPhoton.p4(inPhoton.getCandidateP4type()));
241  outPhoton.setCandidateP4type(inPhoton.getCandidateP4type());
242  }
243  else {
244  pOutput->emplace_back(inPhoton);
245  auto& outPhoton(pOutput->back());
246  outPhoton.setPhotonCore(newCore);
247  }
248  }
249 
250  edm::OrphanHandle<reco::PhotonCollection> newPhotonsHandle(_event.put(pOutput));
251 
252  std::auto_ptr<PhotonRefMap> pRefMap(new PhotonRefMap);
253  PhotonRefMap::Filler refMapFiller(*pRefMap);
254  refMapFiller.insert(newPhotonsHandle, oldPhotons.begin(), oldPhotons.end());
255  refMapFiller.fill();
256  _event.put(pRefMap);
257 }
CaloGeometry const * geometry_
static float e2x5Bottom(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology *topology)
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:186
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > > XYZTLorentzVectorD
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:14
static std::vector< float > covariances(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology *topology, const CaloGeometry *geometry, float w0=4.7)
reco::SuperClusterRef superCluster() const
Ref to SuperCluster.
void produce(edm::Event &, const edm::EventSetup &) override
ProductID id() const
Definition: HandleBase.cc:15
static float eMax(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits)
PhotonEnergyCorrector energyCorrector_
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:52
edm::EDGetTokenT< reco::VertexCollection > verticesToken_
std::unique_ptr< ModifyObjectValueBase > & gedRegression()
static float e2x5Top(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology *topology)
edm::EDGetTokenT< EcalRecHitCollection > ebHitsToken_
bool isFinite(T x)
GEDPhotonGSCrysFixer(const edm::ParameterSet &)
static float e2x2(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology *topology)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
string unit
Definition: csvLumiCalc.py:46
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
T sqrt(T t)
Definition: SSEVec.h:18
double p4[4]
Definition: TauolaWrapper.h:92
static float e2nd(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits)
static float e2x5Max(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology *topology)
static float eBottom(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology *topology)
static float e2x5Right(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology *topology)
void init(const edm::EventSetup &theEventSetup)
void getToken(edm::EDGetTokenT< T > &token, edm::ParameterSet const &pset, std::string const &label, std::string const &instance="")
edm::Handle< T > getHandle(edm::Event const &iEvent, edm::EDGetTokenT< T > const &token, std::string const &name)
static float eTop(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology *topology)
void calculate(edm::Event &evt, reco::Photon &, int subdet, const reco::VertexCollection &vtxcol, const edm::EventSetup &iSetup)
edm::ValueMap< reco::PhotonRef > PhotonRefMap
std::vector< Photon > PhotonCollection
collectin of Photon objects
Definition: PhotonFwd.h:9
const T & get() const
Definition: EventSetup.h:56
T const * product() const
Definition: ESHandle.h:86
static float e2x5Left(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology *topology)
void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override
static bool hasEBGainSwitchIn5x5(const reco::SuperCluster &superClus, const EcalRecHitCollection *recHits, const CaloTopology *topology)
static float eRight(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology *topology)
static float e3x3(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology *topology)
static float e1x3(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology *topology)
CaloTopology const * topology_
static float eLeft(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology *topology)
static std::vector< float > localCovariances(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology *topology, float w0=4.7)
edm::EDGetTokenT< SCRefMap > newCoresToOldSCMapToken_
static float e1x5(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology *topology)
edm::EDGetTokenT< PhotonView > inputPhotonsToken_
edm::EDGetTokenT< reco::PhotonCoreCollection > newCoresToken_
edm::Ref< PhotonCoreCollection > PhotonCoreRef
reference to an object in a collection of PhotonCore objects
Definition: PhotonCoreFwd.h:15
static float e5x5(const reco::BasicCluster &cluster, const EcalRecHitCollection *recHits, const CaloTopology *topology)