49 #include "HepMC/GenParticle.h"
50 #include "HepMC/SimpleVector.h"
51 #include "CLHEP/Units/GlobalPhysicalConstants.h"
65 histfile_ =
new TFile(
"electronpixelseeds.root",
"RECREATE");
71 tree_ =
new TTree(
"ElectronSeeds",
"ElectronSeed validation ntuple");
72 tree_->Branch(
"mcEnergy",mcEnergy,
"mcEnergy[10]/F");
73 tree_->Branch(
"mcEta",mcEta,
"mcEta[10]/F");
74 tree_->Branch(
"mcPhi",mcPhi,
"mcPhi[10]/F");
75 tree_->Branch(
"mcPt",mcPt,
"mcPt[10]/F");
76 tree_->Branch(
"mcQ",mcQ,
"mcQ[10]/F");
77 tree_->Branch(
"superclusterEnergy",superclusterEnergy,
"superclusterEnergy[10]/F");
78 tree_->Branch(
"superclusterEta",superclusterEta,
"superclusterEta[10]/F");
79 tree_->Branch(
"superclusterPhi",superclusterPhi,
"superclusterPhi[10]/F");
80 tree_->Branch(
"superclusterEt",superclusterEt,
"superclusterEt[10]/F");
81 tree_->Branch(
"seedMomentum",seedMomentum,
"seedMomentum[10]/F");
82 tree_->Branch(
"seedEta",seedEta,
"seedEta[10]/F");
83 tree_->Branch(
"seedPhi",seedPhi,
"seedPhi[10]/F");
84 tree_->Branch(
"seedPt",seedPt,
"seedPt[10]/F");
85 tree_->Branch(
"seedQ",seedQ,
"seedQ[10]/F");
86 tree_->Branch(
"seedSubdet1",seedSubdet1,
"seedSubdet1[10]/I");
87 tree_->Branch(
"seedLayer1",seedLayer1,
"seedLayer1[10]/I");
88 tree_->Branch(
"seedSide1",seedSide1,
"seedSide1[10]/I");
89 tree_->Branch(
"seedPhi1",seedPhi1,
"seedPhi1[10]/F");
90 tree_->Branch(
"seedDphi1",seedDphi1,
"seedDphi1[10]/F");
91 tree_->Branch(
"seedDrz1",seedDrz1,
"seedDrz1[10]/F");
92 tree_->Branch(
"seedRz1",seedRz1,
"seedRz1[10]/F");
93 tree_->Branch(
"seedSubdet2",seedSubdet2,
"seedSubdet2[10]/I");
94 tree_->Branch(
"seedLayer2",seedLayer2,
"seedLayer2[10]/I");
95 tree_->Branch(
"seedSide2",seedSide2,
"seedSide2[10]/I");
96 tree_->Branch(
"seedPhi2",seedPhi2,
"seedPhi2[10]/F");
97 tree_->Branch(
"seedDphi2",seedDphi2,
"seedDphi2[10]/F");
98 tree_->Branch(
"seedRz2",seedRz2,
"seedRz2[10]/F");
99 tree_->Branch(
"seedDrz2",seedDrz2,
"seedDrz2[10]/F");
100 histeMC_ =
new TH1F(
"eMC",
"MC particle energy",100,0.,100.);
101 histeMCmatched_ =
new TH1F(
"eMCmatched",
"matched MC particle energy",100,0.,100.);
102 histecaldriveneMCmatched_ =
new TH1F(
"ecaldriveneMCmatched",
"matched MC particle energy, ecal driven",100,0.,100.);
103 histtrackerdriveneMCmatched_ =
new TH1F(
"trackerdriveneMCmatched",
"matched MC particle energy, tracker driven",100,0.,100.);
104 histp_ =
new TH1F(
"p",
"seed p",100,0.,100.);
105 histeclu_ =
new TH1F(
"clus energy",
"supercluster energy",100,0.,100.);
106 histpt_ =
new TH1F(
"pt",
"seed pt",100,0.,100.);
107 histptMC_ =
new TH1F(
"ptMC",
"MC particle pt",100,0.,100.);
108 histptMCmatched_ =
new TH1F(
"ptMCmatched",
"matched MC particle pt",100,0.,100.);
109 histecaldrivenptMCmatched_ =
new TH1F(
"ecaldrivenptMCmatched",
"matched MC particle pt, ecal driven",100,0.,100.);
110 histtrackerdrivenptMCmatched_ =
new TH1F(
"trackerdrivenptMCmatched",
"matched MC particle pt, tracker driven",100,0.,100.);
111 histetclu_ =
new TH1F(
"Et",
"supercluster Et",100,0.,100.);
112 histeffpt_ =
new TH1F(
"pt eff",
"seed effciency vs pt",100,0.,100.);
113 histeta_ =
new TH1F(
"seed eta",
"seed eta",100,-2.5,2.5);
114 histetaMC_ =
new TH1F(
"etaMC",
"MC particle eta",100,-2.5,2.5);
115 histetaMCmatched_ =
new TH1F(
"etaMCmatched",
"matched MC particle eta",100,-2.5,2.5);
116 histecaldrivenetaMCmatched_ =
new TH1F(
"ecaldrivenetaMCmatched",
"matched MC particle eta, ecal driven",100,-2.5,2.5);
117 histtrackerdrivenetaMCmatched_ =
new TH1F(
"trackerdrivenetaMCmatched",
"matched MC particle eta, tracker driven",100,-2.5,2.5);
118 histetaclu_ =
new TH1F(
"clus eta",
"supercluster eta",100,-2.5,2.5);
119 histeffeta_ =
new TH1F(
"eta eff",
"seed effciency vs eta",100,-2.5,2.5);
120 histq_ =
new TH1F(
"q",
"seed charge",100,-2.5,2.5);
121 histeoverp_ =
new TH1F(
"E/p",
"seed E/p",100,0.,10.);
122 histnbseeds_ =
new TH1I(
"nrs",
"Nr of seeds ",50,0.,25.);
123 histnbclus_ =
new TH1I(
"nrclus",
"Nr of superclusters ",50,0.,25.);
124 histnrseeds_ =
new TH1I(
"ns",
"Nr of seeds if clusters",50,0.,25.);
134 TH1F *histetaEff = (TH1F*)histetaMCmatched_->Clone(
"histetaEff");
136 histetaEff->Divide(histetaMCmatched_,histeta_,1,1,
"b");
138 histetaEff->GetXaxis()->SetTitle(
"#eta");
139 histetaEff->GetYaxis()->SetTitle(
"Efficiency");
142 TH1F *histptEff = (TH1F*)histptMCmatched_->Clone(
"histotEff");
144 histptEff->Divide(histptMCmatched_,histpt_,1,1,
"b");
146 histptEff->GetXaxis()->SetTitle(
"p_{T}");
147 histptEff->GetYaxis()->SetTitle(
"Efficiency");
149 histeMCmatched_->Write();
150 histecaldriveneMCmatched_->Write();
151 histtrackerdriveneMCmatched_->Write();
156 histptMCmatched_->Write();
157 histecaldrivenptMCmatched_->Write();
158 histtrackerdrivenptMCmatched_->Write();
163 histetaMCmatched_->Write();
164 histecaldrivenetaMCmatched_->Write();
165 histtrackerdrivenetaMCmatched_->Write();
167 histetaclu_->Write();
168 histeffeta_->Write();
170 histeoverp_->Write();
171 histnbseeds_->Write();
172 histnbclus_->Write();
173 histnrseeds_->Write();
196 typedef recHitContainer::const_iterator const_iterator;
197 typedef std::pair<const_iterator,const_iterator> range;
208 edm::LogInfo(
"")<<
"\n\n =================> Treating event "<<e.
id()<<
" Number of seeds "<<elSeeds.
product()->size();
216 float dphi1=0., dphi2=0., drz1=0., drz2=0.;
217 float phi1=0., phi2=0., rz1=0., rz2=0.;
219 for( ElectronSeedCollection::const_iterator MyS= (*elSeeds).begin(); MyS != (*elSeeds).end(); ++MyS) {
221 LogDebug(
"") <<
"\nSeed nr "<<is<<
": ";
222 range
r=(*MyS).recHits();
223 LogDebug(
"")<<
" Number of RecHits= "<<(*MyS).nHits();
227 DetId id1 = (*it).geographicalId();
228 det1 = pDD->idToDet(id1);
229 LogDebug(
"") <<
" First hit local x,y,z "<<(*it).localPosition()<<
" det "<<id1.
det()<<
" subdet "<<id1.
subdetId();
234 DetId id2 = (*it).geographicalId();
235 det2 = pDD->idToDet(id2);
236 LogDebug(
"") <<
" Second hit local x,y,z "<<(*it).localPosition()<<
" det "<<id2.
det()<<
" subdet "<<id2.
subdetId();
237 LogDebug(
"") <<
" Second hit global "<<det2->
toGlobal((*it).localPosition());
243 for (TrackingRecHitCollection::const_iterator rhits=r.first; rhits!=r.second; rhits++) det = pDD->idToDet(((*rhits)).geographicalId());
251 if (caloCluster.
isNull())
continue;
253 LogDebug(
"")<<
" ElectronSeed superCluster energy: "<<theClus->energy()<<
", position: "<<theClus->position();
255 LogDebug(
"")<<
" ElectronSeed supercluster Et: "<<theClus->energy()*
sin(2.*atan(
exp(-theClus->position().eta())));
257 LogDebug(
"")<<
" ElectronSeed supercluster eta: "<<theClus->position().eta();
258 LogDebug(
"")<<
" ElectronSeed seed charge: "<<(*MyS).getCharge();
265 int charge = int((*MyS).getCharge());
266 GlobalPoint xmeas(theClus->position().x(),theClus->position().y(),theClus->position().z());
267 GlobalPoint vprim(theBeamSpot->position().x(),theBeamSpot->position().y(),theBeamSpot->position().z());
268 float energy = theClus->energy();
283 DetId id=(*it).geographicalId();
284 const GeomDet *geomdet=pDD->idToDet((*it).geographicalId());
293 std::pair<bool,double> est;
296 float SCl_phi = xmeas.phi();
297 float localDphi = SCl_phi-hitPos.
phi();
300 if(
std::abs(localDphi)>2.5)
continue;
306 if (
id.subdetId()%2==1) {
313 DetId id2=(*it).geographicalId();
314 const GeomDet *geomdet2=pDD->idToDet((*it).geographicalId());
318 double pxHit1z = hitPos.
z();
319 double pxHit1x = hitPos.
x();
320 double pxHit1y = hitPos.
y();
321 double r1diff = (pxHit1x-vprim.x())*(pxHit1x-vprim.x()) + (pxHit1y-vprim.y())*(pxHit1y-vprim.y());
323 double r2diff = (xmeas.x()-pxHit1x)*(xmeas.x()-pxHit1x) + (xmeas.y()-pxHit1y)*(xmeas.y()-pxHit1y);
325 double zVertexPred = pxHit1z - r1diff*(xmeas.z()-pxHit1z)/r2diff;
327 GlobalPoint vertexPred(vprim.x(),vprim.y(),zVertexPred);
335 phi2 = hitPos2.
phi();
337 rz2 = hitPos2.
perp();
350 histetclu_->Fill(theClus->energy()*
sin(2.*atan(
exp(-theClus->position().eta()))));
352 histetaclu_->Fill(theClus->position().eta());
353 histq_->Fill((*MyS).getCharge());
357 superclusterEnergy[is] = theClus->energy();
358 superclusterEta[is] = theClus->position().eta();
359 superclusterPhi[is] = theClus->position().phi();
360 superclusterEt[is] = theClus->energy()*
sin(2.*atan(
exp(-theClus->position().eta())));
365 seedQ[is] = (*MyS).getCharge();
367 switch (seedSubdet1[is]) {
371 seedLayer1[is] = pxbid1.
layer();
378 seedLayer1[is] = pxfid1.
disk();
379 seedSide1[is] = pxfid1.side();
385 seedLayer1[is] = tibid1.
layer();
392 seedLayer1[is] = tidid1.
wheel();
393 seedSide1[is] = tidid1.side();
399 seedLayer1[is] = tobid1.
layer();
406 seedLayer1[is] = tecid1.
wheel();
407 seedSide1[is] = tecid1.side();
413 seedDphi1[is] = dphi1;
416 switch (seedSubdet2[is]) {
420 seedLayer2[is] = pxbid2.
layer();
427 seedLayer2[is] = pxfid2.
disk();
428 seedSide2[is] = pxfid2.side();
434 seedLayer2[is] = tibid2.
layer();
441 seedLayer2[is] = tidid2.
wheel();
442 seedSide2[is] = tidid2.side();
448 seedLayer2[is] = tobid2.
layer();
455 seedLayer2[is] = tecid2.
wheel();
456 seedSide2[is] = tecid2.side();
460 seedDphi2[is] = dphi2;
470 histnbseeds_->Fill(elSeeds.
product()->size());
476 e.
getByLabel(
"correctedHybridSuperClusters", clusters);
477 histnbclus_->Fill(clusters.
product()->size());
478 if (clusters.
product()->size()>0) histnrseeds_->Fill(elSeeds.
product()->size());
487 const HepMC::GenEvent* MCEvt = HepMCEvt->GetEvent();
489 HepMC::FourVector pAssSim;
491 for (HepMC::GenEvent::particle_const_iterator partIter = MCEvt->particles_begin();
492 partIter != MCEvt->particles_end(); ++partIter) {
494 for (HepMC::GenEvent::vertex_const_iterator vertIter = MCEvt->vertices_begin();
495 vertIter != MCEvt->vertices_end(); ++vertIter) {
498 HepMC::GenVertex * creation = (*partIter)->production_vertex();
500 HepMC::FourVector momentum = (*partIter)->momentum();
502 int id = (*partIter)->pdg_id();
503 LogDebug(
"") <<
"MC particle id " <<
id <<
", creationVertex " << (*creation) <<
" cm, initialMomentum " << momentum.rho() <<
" GeV/c" << std::endl;
505 if (
id == 11 ||
id == -11) {
509 if ( (*partIter)->production_vertex() ) {
510 if ( (*partIter)->production_vertex()->particles_begin(
HepMC::parents) !=
512 mother = *((*partIter)->production_vertex()->particles_begin(
HepMC::parents));
514 if ( ((mother == 0) || ((mother != 0) && (mother->pdg_id() == 23))
515 || ((mother != 0) && (mother->pdg_id() == 32))
516 || ((mother != 0) && (
std::abs(mother->pdg_id()) == 24)))) {
518 pAssSim = genPc->momentum();
525 if (
std::abs(pAssSim.eta())> 2.5)
continue;
527 histptMC_->Fill(pAssSim.perp());
528 histetaMC_->Fill(pAssSim.eta());
529 histeMC_->Fill(pAssSim.rho());
532 bool okSeedFound =
false;
533 double seedOkRatio = 999999.;
537 for( ElectronSeedCollection::const_iterator gsfIter= (*elSeeds).begin(); gsfIter != (*elSeeds).end(); ++gsfIter) {
539 range
r=gsfIter->recHits();
541 for (TrackingRecHitCollection::const_iterator rhits=r.first; rhits!=r.second; rhits++) det = pDD->idToDet(((*rhits)).geographicalId());
547 double dphi = phi-pAssSim.phi();
549 dphi = dphi < 0? (CLHEP::twopi) + dphi : dphi - CLHEP::twopi;
551 if ( deltaR < 0.15 ){
555 double tmpSeedRatio = p/pAssSim.t();
557 seedOkRatio = tmpSeedRatio;
558 bestElectronSeed=*gsfIter;
568 histptMCmatched_->Fill(pAssSim.perp());
569 histetaMCmatched_->Fill(pAssSim.eta());
570 histeMCmatched_->Fill(pAssSim.rho());
572 mcEnergy[ip] = pAssSim.rho();
573 mcEta[ip] = pAssSim.eta();
574 mcPhi[ip] = pAssSim.phi();
575 mcPt[ip] = pAssSim.perp();
576 mcQ[ip] = ((
id == 11) ? -1.: +1.);
582 seedOkRatio = 999999.;
585 for( ElectronSeedCollection::const_iterator gsfIter= (*elSeeds).begin(); gsfIter != (*elSeeds).end(); ++gsfIter) {
587 range
r=gsfIter->recHits();
589 for (TrackingRecHitCollection::const_iterator rhits=r.first; rhits!=r.second; rhits++) det = pDD->idToDet(((*rhits)).geographicalId());
595 double dphi = phi-pAssSim.phi();
597 dphi = dphi < 0? (CLHEP::twopi) + dphi : dphi - CLHEP::twopi;
599 if (gsfIter->isEcalDriven()) {
600 if ( deltaR < 0.15 ){
604 double tmpSeedRatio = p/pAssSim.t();
606 seedOkRatio = tmpSeedRatio;
607 bestElectronSeed=*gsfIter;
618 histecaldrivenptMCmatched_->Fill(pAssSim.perp());
619 histecaldrivenetaMCmatched_->Fill(pAssSim.eta());
620 histecaldriveneMCmatched_->Fill(pAssSim.rho());
625 seedOkRatio = 999999.;
628 for( ElectronSeedCollection::const_iterator gsfIter= (*elSeeds).begin(); gsfIter != (*elSeeds).end(); ++gsfIter) {
630 range
r=gsfIter->recHits();
632 for (TrackingRecHitCollection::const_iterator rhits=r.first; rhits!=r.second; rhits++) det = pDD->idToDet(((*rhits)).geographicalId());
638 double dphi = phi-pAssSim.phi();
640 dphi = dphi < 0? (CLHEP::twopi) + dphi : dphi - CLHEP::twopi;
642 if (gsfIter->isTrackerDriven()) {
643 if ( deltaR < 0.15 ){
647 double tmpSeedRatio = p/pAssSim.t();
649 seedOkRatio = tmpSeedRatio;
650 bestElectronSeed=*gsfIter;
661 histtrackerdrivenptMCmatched_->Fill(pAssSim.perp());
662 histtrackerdrivenetaMCmatched_->Fill(pAssSim.eta());
663 histtrackerdriveneMCmatched_->Fill(pAssSim.rho());
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
T getParameter(std::string const &) const
unsigned int layer() const
layer id
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Sin< T >::type sin(const T &t)
Geom::Phi< T > phi() const
bool isNull() const
Checks for null.
GlobalPoint globalPosition() const
bool getByType(Handle< PROD > &result) const
Exp< T >::type exp(const T &t)
virtual ~ElectronSeedAnalyzer()
virtual void analyze(const edm::Event &, const edm::EventSetup &)
unsigned int layer() const
layer id
uint32_t rawId() const
get the raw id
recHitContainer::const_iterator const_iterator
int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
GlobalVector momentum() const
unsigned int disk() const
disk id
double deltaR(double eta1, double eta2, double phi1, double phi2)
virtual TrajectoryStateOnSurface propagate(const TrajectoryStateOnSurface &tsos, const Plane &plane) const
GlobalPoint position() const
REF castTo() const
cast to a concrete type
T const * product() const
unsigned int wheel() const
wheel id
unsigned int layer() const
layer id
GlobalVector globalMomentum() const
Detector det() const
get the detector field from this detid
ElectronSeedAnalyzer(const edm::ParameterSet &conf)
virtual const BoundPlane & surface() const
The nominal surface of the GeomDet.
Power< A, B >::type pow(const A &a, const B &b)
unsigned int wheel() const
wheel id