43 #include "HepMC/GenParticle.h"
44 #include "HepMC/SimpleVector.h"
45 #include "CLHEP/Units/GlobalPhysicalConstants.h"
57 : beamSpot_(conf.getParameter<
edm::
InputTag>(
"beamSpot")) {
59 histfile_ =
new TFile(
"electronpixelseeds.root",
"RECREATE");
64 tree_ =
new TTree(
"ElectronSeeds",
"ElectronSeed validation ntuple");
68 tree_->Branch(
"mcPt",
mcPt,
"mcPt[10]/F");
69 tree_->Branch(
"mcQ",
mcQ,
"mcQ[10]/F");
93 histeMC_ =
new TH1F(
"eMC",
"MC particle energy", 100, 0., 100.);
94 histeMCmatched_ =
new TH1F(
"eMCmatched",
"matched MC particle energy", 100, 0., 100.);
96 new TH1F(
"ecaldriveneMCmatched",
"matched MC particle energy, ecal driven", 100, 0., 100.);
98 new TH1F(
"trackerdriveneMCmatched",
"matched MC particle energy, tracker driven", 100, 0., 100.);
99 histp_ =
new TH1F(
"p",
"seed p", 100, 0., 100.);
100 histeclu_ =
new TH1F(
"clus energy",
"supercluster energy", 100, 0., 100.);
101 histpt_ =
new TH1F(
"pt",
"seed pt", 100, 0., 100.);
102 histptMC_ =
new TH1F(
"ptMC",
"MC particle pt", 100, 0., 100.);
103 histptMCmatched_ =
new TH1F(
"ptMCmatched",
"matched MC particle pt", 100, 0., 100.);
106 new TH1F(
"trackerdrivenptMCmatched",
"matched MC particle pt, tracker driven", 100, 0., 100.);
107 histetclu_ =
new TH1F(
"Et",
"supercluster Et", 100, 0., 100.);
108 histeffpt_ =
new TH1F(
"pt eff",
"seed effciency vs pt", 100, 0., 100.);
109 histeta_ =
new TH1F(
"seed eta",
"seed eta", 100, -2.5, 2.5);
110 histetaMC_ =
new TH1F(
"etaMC",
"MC particle eta", 100, -2.5, 2.5);
111 histetaMCmatched_ =
new TH1F(
"etaMCmatched",
"matched MC particle eta", 100, -2.5, 2.5);
113 new TH1F(
"ecaldrivenetaMCmatched",
"matched MC particle eta, ecal driven", 100, -2.5, 2.5);
115 new TH1F(
"trackerdrivenetaMCmatched",
"matched MC particle eta, tracker driven", 100, -2.5, 2.5);
116 histetaclu_ =
new TH1F(
"clus eta",
"supercluster eta", 100, -2.5, 2.5);
117 histeffeta_ =
new TH1F(
"eta eff",
"seed effciency vs eta", 100, -2.5, 2.5);
118 histq_ =
new TH1F(
"q",
"seed charge", 100, -2.5, 2.5);
119 histeoverp_ =
new TH1F(
"E/p",
"seed E/p", 100, 0., 10.);
120 histnbseeds_ =
new TH1I(
"nrs",
"Nr of seeds ", 50, 0., 25.);
121 histnbclus_ =
new TH1I(
"nrclus",
"Nr of superclusters ", 50, 0., 25.);
122 histnrseeds_ =
new TH1I(
"ns",
"Nr of seeds if clusters", 50, 0., 25.);
135 histetaEff->GetXaxis()->SetTitle(
"#eta");
136 histetaEff->GetYaxis()->SetTitle(
"Efficiency");
143 histptEff->GetXaxis()->SetTitle(
"p_{T}");
144 histptEff->GetYaxis()->SetTitle(
"Efficiency");
194 typedef recHitContainer::const_iterator const_iterator;
195 typedef std::pair<const_iterator, const_iterator>
range;
205 edm::LogInfo(
"") <<
"\n\n =================> Treating event " <<
e.id() <<
" Number of seeds "
209 float mass = .000511;
213 float dphi1 = 0., dphi2 = 0., drz1 = 0., drz2 = 0.;
214 float phi1 = 0., phi2 = 0., rz1 = 0., rz2 = 0.;
216 for (ElectronSeedCollection::const_iterator MyS = (*elSeeds).begin(); MyS != (*elSeeds).end(); ++MyS) {
217 LogDebug(
"") <<
"\nSeed nr " << is <<
": ";
218 range r = (*MyS).recHits();
219 LogDebug(
"") <<
" Number of RecHits= " << (*MyS).nHits();
226 LogDebug(
"") <<
" First hit local x,y,z " << (*it).localPosition() <<
" det " <<
id1.det() <<
" subdet "
228 LogDebug(
"") <<
" First hit global " << det1->
toGlobal((*it).localPosition());
234 LogDebug(
"") <<
" Second hit local x,y,z " << (*it).localPosition() <<
" det " <<
id2.det() <<
" subdet "
236 LogDebug(
"") <<
" Second hit global " << det2->
toGlobal((*it).localPosition());
242 for (TrackingRecHitCollection::const_iterator rhits =
r.first; rhits !=
r.second; rhits++)
243 det = pDD->
idToDet(((*rhits)).geographicalId());
249 LogDebug(
"") <<
" ElectronSeed outermost state position: " <<
t.globalPosition();
250 LogDebug(
"") <<
" ElectronSeed outermost state momentum: " <<
t.globalMomentum();
255 LogDebug(
"") <<
" ElectronSeed superCluster energy: " << theClus->energy() <<
", position: " << theClus->position();
256 LogDebug(
"") <<
" ElectronSeed outermost state Pt: " <<
t.globalMomentum().perp();
257 LogDebug(
"") <<
" ElectronSeed supercluster Et: "
258 << theClus->energy() *
sin(2. * atan(
exp(-theClus->position().eta())));
259 LogDebug(
"") <<
" ElectronSeed outermost momentum direction eta: " <<
t.globalMomentum().eta();
260 LogDebug(
"") <<
" ElectronSeed supercluster eta: " << theClus->position().eta();
261 LogDebug(
"") <<
" ElectronSeed seed charge: " << (*MyS).getCharge();
262 LogDebug(
"") <<
" ElectronSeed E/p: " << theClus->energy() /
t.globalMomentum().mag();
269 GlobalPoint xmeas(theClus->position().x(), theClus->position().y(), theClus->position().z());
271 float energy = theClus->energy();
285 DetId id = (*it).geographicalId();
295 float SCl_phi = xmeas.phi();
296 float localDphi = SCl_phi - hitPos.
phi();
308 if (
id.subdetId() % 2 == 1) {
320 double pxHit1z = hitPos.
z();
321 double pxHit1x = hitPos.
x();
322 double pxHit1y = hitPos.
y();
323 double r1diff = (pxHit1x - vprim.x()) * (pxHit1x - vprim.x()) + (pxHit1y - vprim.y()) * (pxHit1y - vprim.y());
324 r1diff =
sqrt(r1diff);
325 double r2diff = (xmeas.x() - pxHit1x) * (xmeas.x() - pxHit1x) + (xmeas.y() - pxHit1y) * (xmeas.y() - pxHit1y);
326 r2diff =
sqrt(r2diff);
327 double zVertexPred = pxHit1z - r1diff * (xmeas.z() - pxHit1z) / r2diff;
329 GlobalPoint vertexPred(vprim.x(), vprim.y(), zVertexPred);
337 phi2 = hitPos2.
phi();
339 rz2 = hitPos2.
perp();
341 if (
id2.subdetId() % 2 == 1) {
350 histpt_->Fill(
t.globalMomentum().perp());
351 histetclu_->Fill(theClus->energy() *
sin(2. * atan(
exp(-theClus->position().eta()))));
352 histeta_->Fill(
t.globalMomentum().eta());
354 histq_->Fill((*MyS).getCharge());
355 histeoverp_->Fill(theClus->energy() /
t.globalMomentum().mag());
363 seedEta[is] =
t.globalMomentum().eta();
364 seedPhi[is] =
t.globalMomentum().phi();
365 seedPt[is] =
t.globalMomentum().perp();
366 seedQ[is] = (*MyS).getCharge();
392 e.getByLabel(
"correctedHybridSuperClusters",
clusters);
402 e.getByLabel(
"generatorSmeared",
"", HepMCEvt);
406 HepMC::FourVector pAssSim;
408 for (HepMC::GenEvent::particle_const_iterator partIter = MCEvt->particles_begin(); partIter != MCEvt->particles_end();
410 for (HepMC::GenEvent::vertex_const_iterator vertIter = MCEvt->vertices_begin(); vertIter != MCEvt->vertices_end();
413 HepMC::GenVertex *creation = (*partIter)->production_vertex();
415 HepMC::FourVector momentum = (*partIter)->momentum();
417 int id = (*partIter)->pdg_id();
418 LogDebug(
"") <<
"MC particle id " <<
id <<
", creationVertex " << (*creation) <<
" cm, initialMomentum "
419 << momentum.rho() <<
" GeV/c" << std::endl;
421 if (
id == 11 ||
id == -11) {
424 if ((*partIter)->production_vertex()) {
425 if ((*partIter)->production_vertex()->particles_begin(
HepMC::parents) !=
427 mother = *((*partIter)->production_vertex()->particles_begin(
HepMC::parents));
429 if (((mother ==
nullptr) || ((mother !=
nullptr) && (mother->pdg_id() == 23)) ||
430 ((mother !=
nullptr) && (mother->pdg_id() == 32)) ||
431 ((mother !=
nullptr) && (
std::abs(mother->pdg_id()) == 24)))) {
433 pAssSim = genPc->momentum();
448 bool okSeedFound =
false;
449 double seedOkRatio = 999999.;
453 for (ElectronSeedCollection::const_iterator gsfIter = (*elSeeds).begin(); gsfIter != (*elSeeds).end();
455 range r = gsfIter->recHits();
457 for (TrackingRecHitCollection::const_iterator rhits =
r.first; rhits !=
r.second; rhits++)
458 det = pDD->
idToDet(((*rhits)).geographicalId());
462 float eta =
t.globalMomentum().eta();
463 float phi =
t.globalMomentum().phi();
464 float p =
t.globalMomentum().mag();
465 double dphi =
phi - pAssSim.phi();
467 dphi = dphi < 0 ? (CLHEP::twopi) + dphi : dphi - CLHEP::twopi;
473 double tmpSeedRatio =
p / pAssSim.t();
475 seedOkRatio = tmpSeedRatio;
476 bestElectronSeed = *gsfIter;
490 mcEta[ip] = pAssSim.eta();
491 mcPhi[ip] = pAssSim.phi();
492 mcPt[ip] = pAssSim.perp();
493 mcQ[ip] = ((
id == 11) ? -1. : +1.);
499 seedOkRatio = 999999.;
502 for (ElectronSeedCollection::const_iterator gsfIter = (*elSeeds).begin(); gsfIter != (*elSeeds).end();
504 range r = gsfIter->recHits();
506 for (TrackingRecHitCollection::const_iterator rhits =
r.first; rhits !=
r.second; rhits++)
507 det = pDD->
idToDet(((*rhits)).geographicalId());
511 float eta =
t.globalMomentum().eta();
512 float phi =
t.globalMomentum().phi();
513 float p =
t.globalMomentum().mag();
514 double dphi =
phi - pAssSim.phi();
516 dphi = dphi < 0 ? (CLHEP::twopi) + dphi : dphi - CLHEP::twopi;
518 if (gsfIter->isEcalDriven()) {
523 double tmpSeedRatio =
p / pAssSim.t();
525 seedOkRatio = tmpSeedRatio;
526 bestElectronSeed = *gsfIter;
543 seedOkRatio = 999999.;
546 for (ElectronSeedCollection::const_iterator gsfIter = (*elSeeds).begin(); gsfIter != (*elSeeds).end();
548 range r = gsfIter->recHits();
550 for (TrackingRecHitCollection::const_iterator rhits =
r.first; rhits !=
r.second; rhits++)
551 det = pDD->
idToDet(((*rhits)).geographicalId());
555 float eta =
t.globalMomentum().eta();
556 float phi =
t.globalMomentum().phi();
557 float p =
t.globalMomentum().mag();
558 double dphi =
phi - pAssSim.phi();
560 dphi = dphi < 0 ? (CLHEP::twopi) + dphi : dphi - CLHEP::twopi;
562 if (gsfIter->isTrackerDriven()) {
567 double tmpSeedRatio =
p / pAssSim.t();
569 seedOkRatio = tmpSeedRatio;
570 bestElectronSeed = *gsfIter;