12 BarrelSuperClusterCollection_ =
13 consumes<reco::SuperClusterCollection>(ps.
getParameter<
InputTag>(
"BarrelSuperClusterCollection"));
14 EndcapSuperClusterCollection_ =
15 consumes<reco::SuperClusterCollection>(ps.
getParameter<
InputTag>(
"EndcapSuperClusterCollection"));
16 reducedBarrelRecHitCollection_ =
18 reducedEndcapRecHitCollection_ =
20 SimTrackCollection_ = consumes<SimTrackContainer>(ps.
getParameter<
InputTag>(
"simTrackCollection"));
21 SimVertexCollection_ = consumes<SimVertexContainer>(ps.
getParameter<
InputTag>(
"simVertexCollection"));
30 h_EB_eRecoEtrueReference = fs->
make<TH1F>(
"EB_eRecoEtrueReference",
"EB_eRecoEtrueReference", 440, 0., 1.1);
31 h_EB_e9EtrueReference = fs->
make<TH1F>(
"EB_e9EtrueReference",
"EB_e9EtrueReference", 440, 0., 1.1);
32 h_EB_e25EtrueReference = fs->
make<TH1F>(
"EB_e25EtrueReference",
"EB_e25EtrueReference", 440, 0., 1.1);
33 h_EE_eRecoEtrueReference = fs->
make<TH1F>(
"EE_eRecoEtrueReference",
"EE_eRecoEtrueReference", 440, 0., 1.1);
34 h_EE_e9EtrueReference = fs->
make<TH1F>(
"EE_e9EtrueReference",
"EE_e9EtrueReference", 440, 0., 1.1);
35 h_EE_e25EtrueReference = fs->
make<TH1F>(
"EE_e25EtrueReference",
"EE_e25EtrueReference", 440, 0., 1.1);
36 h_EB_eTrue = fs->
make<TH1F>(
"EB_eTrue",
"EB_eTrue", 41, 40., 60.);
37 h_EE_eTrue = fs->
make<TH1F>(
"EE_eTrue",
"EE_eTrue", 41, 40., 60.);
38 h_EB_converted = fs->
make<TH1F>(
"EB_converted",
"EB_converted", 2, 0., 2.);
39 h_EE_converted = fs->
make<TH1F>(
"EE_converted",
"EE_converted", 2, 0., 2.);
43 LogInfo(
"ContainmentCorrectionAnalyzer") <<
"Analyzing event " << evt.
id() <<
"\n";
46 std::vector<SimTrack> theSimTracks;
50 labelsForToken(SimTrackCollection_, l);
53 theSimTracks.insert(theSimTracks.end(), SimTk->begin(), SimTk->end());
55 LogError(
"ContainmentCorrectionAnalyzer") <<
"Error! can't get collection with label " << l.
module;
58 std::vector<SimVertex> theSimVertexes;
61 labelsForToken(SimVertexCollection_, l);
64 theSimVertexes.insert(theSimVertexes.end(), SimVtx->begin(), SimVtx->end());
66 LogError(
"ContainmentCorrectionAnalyzer") <<
"Error! can't get collection with label " << l.
module;
71 evt.
getByToken(BarrelSuperClusterCollection_, pHybridBarrelSuperClusters);
72 labelsForToken(BarrelSuperClusterCollection_, l);
74 if (pHybridBarrelSuperClusters.
isValid()) {
75 BarrelSuperClusters = pHybridBarrelSuperClusters.
product();
77 LogError(
"ContainmentCorrectionAnalyzer") <<
"Error! can't get collection with label " << l.
module;
82 evt.
getByToken(EndcapSuperClusterCollection_, pMulti5x5EndcapSuperClusters);
83 labelsForToken(EndcapSuperClusterCollection_, l);
85 if (pMulti5x5EndcapSuperClusters.
isValid())
86 EndcapSuperClusters = pMulti5x5EndcapSuperClusters.
product();
88 LogError(
"ContainmentCorrectionAnalyzer") <<
"Error! can't get collection with label " << l.
module;
93 evt.
getByToken(reducedBarrelRecHitCollection_, pEBRecHits);
94 labelsForToken(reducedBarrelRecHitCollection_, l);
97 ebRecHits = pEBRecHits.
product();
99 LogError(
"ContainmentCorrectionAnalyzer") <<
"Error! can't get collection with label " << l.
module;
104 evt.
getByToken(reducedEndcapRecHitCollection_, pEERecHits);
105 labelsForToken(reducedEndcapRecHitCollection_, l);
108 eeRecHits = pEERecHits.
product();
110 LogError(
"ContainmentCorrectionAnalyzer") <<
"Error! can't get collection with label " << l.
module;
117 topology = pTopology.
product();
119 std::vector<EcalSimPhotonMCTruth>
photons = findMcTruth(theSimTracks, theSimVertexes);
124 int mc_size = photons.size();
125 mcEnergy.resize(mc_size);
126 mcEta.resize(mc_size);
127 mcPhi.resize(mc_size);
128 mcPt.resize(mc_size);
129 isConverted.resize(mc_size);
130 x_vtx.resize(mc_size);
131 y_vtx.resize(mc_size);
132 z_vtx.resize(mc_size);
134 superClusterEnergy.resize(mc_size);
135 superClusterEta.resize(mc_size);
136 superClusterPhi.resize(mc_size);
137 superClusterEt.resize(mc_size);
141 seedXtal.resize(mc_size);
145 for (
unsigned int ipho = 0; ipho < photons.size(); ipho++) {
147 double phiTrue = photons[ipho].fourMomentum().phi();
148 double vtxPerp =
sqrt(vtx.x() * vtx.x() + vtx.y() * vtx.y());
149 double etaTrue =
ecalEta(photons[ipho].fourMomentum().
eta(), vtx.z(), vtxPerp);
150 double etTrue = photons[ipho].fourMomentum().e() / cosh(etaTrue);
152 mcEnergy[nMCphotons - 1] = photons[ipho].fourMomentum().e();
153 mcEta[nMCphotons - 1] = etaTrue;
154 mcPhi[nMCphotons - 1] = phiTrue;
155 mcPt[nMCphotons - 1] = etTrue;
156 isConverted[nMCphotons - 1] = photons[ipho].isAConversion();
157 x_vtx[nMCphotons - 1] = vtx.x();
158 y_vtx[nMCphotons - 1] = vtx.y();
159 z_vtx[nMCphotons - 1] = vtx.z();
162 if (std::fabs(etaTrue) < 1.479) {
163 h_EB_eTrue->Fill(photons[ipho].fourMomentum().
e());
164 h_EB_converted->Fill(photons[ipho].isAConversion());
166 if (std::fabs(etaTrue) >= 1.6) {
167 h_EE_eTrue->Fill(photons[ipho].fourMomentum().
e());
168 h_EE_converted->Fill(photons[ipho].isAConversion());
172 if (std::fabs(etaTrue) < 1.479) {
178 double closestParticleDistance = 999;
179 for (reco::SuperClusterCollection::const_iterator aClus = BarrelSuperClusters->begin();
180 aClus != BarrelSuperClusters->end();
182 etaCurrent = aClus->
position().eta();
183 phiCurrent = aClus->position().phi();
186 if (deltaR < closestParticleDistance) {
189 closestParticleDistance =
deltaR;
194 if (closestParticleDistance < 0.3) {
197 superClusterEnergy[nRECOphotons - 1] = nearSC->
rawEnergy();
198 superClusterEta[nRECOphotons - 1] = nearSC->
position().eta();
199 superClusterPhi[nRECOphotons - 1] = nearSC->
position().phi();
200 superClusterEt[nRECOphotons - 1] = nearSC->
rawEnergy() / std::cosh(nearSC->
position().eta());
201 iMC[nRECOphotons - 1] = nMCphotons - 1;
204 seedXtal[nRECOphotons - 1] = EcalClusterTools::getMaximum(*theSeed, ebRecHits).first;
206 e9[nRECOphotons - 1] = EcalClusterTools::e3x3(*theSeed, ebRecHits, topology);
207 e25[nRECOphotons - 1] = EcalClusterTools::e5x5(*theSeed, ebRecHits, topology);
212 if (std::fabs(etaTrue) >= 1.6) {
218 double closestParticleDistance = 999;
219 for (reco::SuperClusterCollection::const_iterator aClus = EndcapSuperClusters->begin();
220 aClus != EndcapSuperClusters->end();
222 etaCurrent = aClus->
position().eta();
223 phiCurrent = aClus->position().phi();
226 if (deltaR < closestParticleDistance) {
229 closestParticleDistance =
deltaR;
234 if (closestParticleDistance < 0.3) {
238 superClusterEnergy[nRECOphotons - 1] = nearSC->
rawEnergy() + psEnergy;
239 superClusterEta[nRECOphotons - 1] = nearSC->
position().eta();
240 superClusterPhi[nRECOphotons - 1] = nearSC->
position().phi();
241 superClusterEt[nRECOphotons - 1] = (nearSC->
rawEnergy() + psEnergy) / std::cosh(nearSC->
position().eta());
242 iMC[nRECOphotons - 1] = nMCphotons - 1;
245 seedXtal[nRECOphotons - 1] = EcalClusterTools::getMaximum(*theSeed, eeRecHits).first;
247 e9[nRECOphotons - 1] = EcalClusterTools::e3x3(*theSeed, eeRecHits, topology) + psEnergy;
248 e25[nRECOphotons - 1] = EcalClusterTools::e5x5(*theSeed, eeRecHits, topology) + psEnergy;
254 for (
int i = 0;
i < nRECOphotons;
i++) {
256 if (fabs(superClusterEta[
i]) < 1.479) {
257 if (isConverted[iMC[i]] != 1) {
258 int ietaAbs = (seedXtal[
i] >> 9) & 0x7F;
259 int iphi = seedXtal[
i] & 0x1FF;
260 if (ietaAbs > 5 && ietaAbs < 21 && ((iphi % 20) > 5) && ((iphi % 20) < 16)) {
261 h_EB_eRecoEtrueReference->Fill(superClusterEnergy[i] / mcEnergy[iMC[i]]);
262 h_EB_e9EtrueReference->Fill(e9[i] / mcEnergy[iMC[i]]);
263 h_EB_e25EtrueReference->Fill(e25[i] / mcEnergy[iMC[i]]);
269 if (fabs(superClusterEta[i]) > 1.6) {
270 if (isConverted[iMC[i]] != 1) {
271 if (fabs(superClusterEta[i]) > 1.7 && fabs(superClusterEta[i] < 2.3) &&
272 ((superClusterPhi[i] > -
CLHEP::pi / 2. + 0.1 && superClusterPhi[i] <
CLHEP::pi / 2. - 0.1) ||
273 (superClusterPhi[i] >
CLHEP::pi / 2. + 0.1) || (superClusterPhi[i] < -
CLHEP::pi / 2. - 0.1))) {
274 h_EE_eRecoEtrueReference->Fill(superClusterEnergy[i] / mcEnergy[iMC[i]]);
275 h_EE_e9EtrueReference->Fill(e9[i] / mcEnergy[iMC[i]]);
276 h_EE_e25EtrueReference->Fill(e25[i] / mcEnergy[iMC[i]]);
287 const float R_ECAL = 136.5;
291 if (EtaParticle != 0.) {
293 float ZEcal = (R_ECAL - plane_Radius) * sinh(EtaParticle) + Zvertex;
296 Theta = atan(R_ECAL / ZEcal);
302 if (fabs(ETA) > etaBarrelEndcap) {
304 if (EtaParticle < 0.0)
306 float Zlen = Zend - Zvertex;
307 float RR = Zlen / sinh(EtaParticle);
308 Theta = atan((RR + plane_Radius) / Zend);
311 ETA = -
log(
tan(0.5 * Theta));
316 LogWarning(
"") <<
"[ContainmentCorrectionAnalyzer::ecalEta] Warning: Eta " 317 "equals to zero, not correcting";
324 std::vector<SimVertex> &theSimVertices) {
325 std::vector<EcalSimPhotonMCTruth>
result;
327 geantToIndex_.clear();
335 const int ELECTRON_FLAV = 1;
336 const int PIZERO_FLAV = 2;
337 const int PHOTON_FLAV = 3;
341 std::vector<SimTrack *> photonTracks;
342 std::vector<SimTrack *> pizeroTracks;
343 std::vector<const SimTrack *> trkFromConversion;
345 std::vector<int> convInd;
347 fillMcTruth(theSimTracks, theSimVertices);
351 std::vector<SimTrack>::iterator iFirstSimTk = theSimTracks.begin();
352 if (!(*iFirstSimTk).noVertex()) {
353 iPV = (*iFirstSimTk).vertIndex();
354 int vtxId = (*iFirstSimTk).vertIndex();
355 primVtx = theSimVertices[vtxId];
356 partType1 = (*iFirstSimTk).type();
361 if (iFirstSimTk != theSimTracks.end()) {
362 if ((*iFirstSimTk).vertIndex() == iPV) {
363 partType2 = (*iFirstSimTk).type();
368 for (std::vector<SimTrack>::iterator iSimTk = theSimTracks.begin(); iSimTk != theSimTracks.end(); ++iSimTk) {
369 if ((*iSimTk).noVertex())
373 if ((*iSimTk).vertIndex() == iPV) {
375 if ((*iSimTk).type() == 22) {
376 convInd.push_back(0);
377 photonTracks.push_back(&(*iSimTk));
384 }
else if (npv == 1) {
385 if (
abs(partType1) == 11) {
386 ievflav = ELECTRON_FLAV;
387 }
else if (partType1 == 111) {
388 ievflav = PIZERO_FLAV;
389 }
else if (partType1 == 22) {
390 ievflav = PHOTON_FLAV;
392 }
else if (npv == 2) {
393 if (
abs(partType1) == 11 &&
abs(partType2) == 11) {
394 ievflav = ELECTRON_FLAV;
395 }
else if (partType1 == 111 && partType2 == 111) {
396 ievflav = PIZERO_FLAV;
397 }
else if (partType1 == 22 && partType2 == 22) {
398 ievflav = PHOTON_FLAV;
403 int isAconversion = 0;
404 if (ievflav == PHOTON_FLAV) {
408 for (std::vector<SimTrack *>::iterator iPhoTk = photonTracks.begin(); iPhoTk != photonTracks.end(); ++iPhoTk) {
409 trkFromConversion.clear();
410 for (std::vector<SimTrack>::iterator iSimTk = theSimTracks.begin(); iSimTk != theSimTracks.end(); ++iSimTk) {
411 if ((*iSimTk).noVertex())
413 if ((*iSimTk).vertIndex() == iPV)
415 if (
abs((*iSimTk).type()) != 11)
417 int vertexId = (*iSimTk).vertIndex();
418 SimVertex vertex = theSimVertices[vertexId];
422 std::map<unsigned, unsigned>::iterator
association = geantToIndex_.find(motherGeantId);
423 if (association != geantToIndex_.end())
424 motherId = association->second;
428 if (theSimTracks[motherId].trackId() == (*iPhoTk)->trackId()) {
430 trkFromConversion.push_back(&(*iSimTk));
435 if (!trkFromConversion.empty()) {
438 convInd[iPho] = nConv;
439 int convVtxId = trkFromConversion[0]->vertIndex();
440 SimVertex convVtx = theSimVertices[convVtxId];
444 if (trkFromConversion.size() > 1) {
455 (*iPhoTk)->momentum(),
465 (*iPhoTk)->momentum(),
480 unsigned nVtx = simVertices.size();
481 unsigned nTks = simTracks.size();
486 for (
unsigned it = 0; it < nTks; ++it) {
487 geantToIndex_[simTracks[it].trackId()] = it;
T getParameter(std::string const &) const
const math::XYZPoint & position() const
cluster centroid position
std::vector< EcalSimPhotonMCTruth > findMcTruth(std::vector< SimTrack > &theSimTracks, std::vector< SimVertex > &theSimVertices)
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > > XYZTLorentzVectorD
Lorentz vector with cylindrical internal representation using pseudorapidity.
CaloTopology const * topology(0)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
T * make(const Args &...args) const
make new ROOT object
float ecalEta(float EtaParticle, float Zvertex, float plane_Radius)
std::vector< SuperCluster > SuperClusterCollection
collection of SuperCluser objectr
~ContainmentCorrectionAnalyzer() override
Tan< T >::type tan(const T &t)
static float etaBarrelEndcap
Abs< T >::type abs(const T &t)
const math::XYZTLorentzVectorD & position() const
Namespace of DDCMS conversion namespace.
double rawEnergy() const
raw uncorrected energy (sum of energies of component BasicClusters)
T const * product() const
void analyze(const edm::Event &, const edm::EventSetup &) override
ContainmentCorrectionAnalyzer(const edm::ParameterSet &)
const CaloClusterPtr & seed() const
seed BasicCluster
double preshowerEnergy() const
energy deposited in preshower
T const * product() const
Power< A, B >::type pow(const A &a, const B &b)
void fillMcTruth(std::vector< SimTrack > &theSimTracks, std::vector< SimVertex > &theSimVertices)