CMS 3D CMS Logo

ElectronSeedAnalyzer.cc
Go to the documentation of this file.
1 
2 // user include files
10 
19 
22 
27 
35 
38 
41 
43 
45 #include "HepMC/GenParticle.h"
46 #include "HepMC/SimpleVector.h"
47 #include "CLHEP/Units/GlobalPhysicalConstants.h"
48 
49 #include <iostream>
50 #include "TFile.h"
51 #include "TH1F.h"
52 #include "TH1I.h"
53 #include "TTree.h"
54 
55 using namespace std;
56 using namespace reco;
57 
59  beamSpot_(conf.getParameter<edm::InputTag>("beamSpot"))
60 {
61  inputCollection_=conf.getParameter<edm::InputTag>("inputCollection") ;
62  histfile_ = new TFile("electronpixelseeds.root","RECREATE");
63 }
64 
66 {
67  histfile_->cd();
68  tree_ = new TTree("ElectronSeeds","ElectronSeed validation ntuple");
69  tree_->Branch("mcEnergy",mcEnergy,"mcEnergy[10]/F");
70  tree_->Branch("mcEta",mcEta,"mcEta[10]/F");
71  tree_->Branch("mcPhi",mcPhi,"mcPhi[10]/F");
72  tree_->Branch("mcPt",mcPt,"mcPt[10]/F");
73  tree_->Branch("mcQ",mcQ,"mcQ[10]/F");
74  tree_->Branch("superclusterEnergy",superclusterEnergy,"superclusterEnergy[10]/F");
75  tree_->Branch("superclusterEta",superclusterEta,"superclusterEta[10]/F");
76  tree_->Branch("superclusterPhi",superclusterPhi,"superclusterPhi[10]/F");
77  tree_->Branch("superclusterEt",superclusterEt,"superclusterEt[10]/F");
78  tree_->Branch("seedMomentum",seedMomentum,"seedMomentum[10]/F");
79  tree_->Branch("seedEta",seedEta,"seedEta[10]/F");
80  tree_->Branch("seedPhi",seedPhi,"seedPhi[10]/F");
81  tree_->Branch("seedPt",seedPt,"seedPt[10]/F");
82  tree_->Branch("seedQ",seedQ,"seedQ[10]/F");
83  tree_->Branch("seedSubdet1",seedSubdet1,"seedSubdet1[10]/I");
84  tree_->Branch("seedLayer1",seedLayer1,"seedLayer1[10]/I");
85  tree_->Branch("seedSide1",seedSide1,"seedSide1[10]/I");
86  tree_->Branch("seedPhi1",seedPhi1,"seedPhi1[10]/F");
87  tree_->Branch("seedDphi1",seedDphi1,"seedDphi1[10]/F");
88  tree_->Branch("seedDrz1",seedDrz1,"seedDrz1[10]/F");
89  tree_->Branch("seedRz1",seedRz1,"seedRz1[10]/F");
90  tree_->Branch("seedSubdet2",seedSubdet2,"seedSubdet2[10]/I");
91  tree_->Branch("seedLayer2",seedLayer2,"seedLayer2[10]/I");
92  tree_->Branch("seedSide2",seedSide2,"seedSide2[10]/I");
93  tree_->Branch("seedPhi2",seedPhi2,"seedPhi2[10]/F");
94  tree_->Branch("seedDphi2",seedDphi2,"seedDphi2[10]/F");
95  tree_->Branch("seedRz2",seedRz2,"seedRz2[10]/F");
96  tree_->Branch("seedDrz2",seedDrz2,"seedDrz2[10]/F");
97  histeMC_ = new TH1F("eMC","MC particle energy",100,0.,100.);
98  histeMCmatched_ = new TH1F("eMCmatched","matched MC particle energy",100,0.,100.);
99  histecaldriveneMCmatched_ = new TH1F("ecaldriveneMCmatched","matched MC particle energy, ecal driven",100,0.,100.);
100  histtrackerdriveneMCmatched_ = new TH1F("trackerdriveneMCmatched","matched MC particle energy, tracker driven",100,0.,100.);
101  histp_ = new TH1F("p","seed p",100,0.,100.);
102  histeclu_ = new TH1F("clus energy","supercluster energy",100,0.,100.);
103  histpt_ = new TH1F("pt","seed pt",100,0.,100.);
104  histptMC_ = new TH1F("ptMC","MC particle pt",100,0.,100.);
105  histptMCmatched_ = new TH1F("ptMCmatched","matched MC particle pt",100,0.,100.);
106  histecaldrivenptMCmatched_ = new TH1F("ecaldrivenptMCmatched","matched MC particle pt, ecal driven",100,0.,100.);
107  histtrackerdrivenptMCmatched_ = new TH1F("trackerdrivenptMCmatched","matched MC particle pt, tracker driven",100,0.,100.);
108  histetclu_ = new TH1F("Et","supercluster Et",100,0.,100.);
109  histeffpt_ = new TH1F("pt eff","seed effciency vs pt",100,0.,100.);
110  histeta_ = new TH1F("seed eta","seed eta",100,-2.5,2.5);
111  histetaMC_ = new TH1F("etaMC","MC particle eta",100,-2.5,2.5);
112  histetaMCmatched_ = new TH1F("etaMCmatched","matched MC particle eta",100,-2.5,2.5);
113  histecaldrivenetaMCmatched_ = new TH1F("ecaldrivenetaMCmatched","matched MC particle eta, ecal driven",100,-2.5,2.5);
114  histtrackerdrivenetaMCmatched_ = new TH1F("trackerdrivenetaMCmatched","matched MC particle eta, tracker driven",100,-2.5,2.5);
115  histetaclu_ = new TH1F("clus eta","supercluster eta",100,-2.5,2.5);
116  histeffeta_ = new TH1F("eta eff","seed effciency vs eta",100,-2.5,2.5);
117  histq_ = new TH1F("q","seed charge",100,-2.5,2.5);
118  histeoverp_ = new TH1F("E/p","seed E/p",100,0.,10.);
119  histnbseeds_ = new TH1I("nrs","Nr of seeds ",50,0.,25.);
120  histnbclus_ = new TH1I("nrclus","Nr of superclusters ",50,0.,25.);
121  histnrseeds_ = new TH1I("ns","Nr of seeds if clusters",50,0.,25.);
122 }
123 
125 {
126  histfile_->cd();
127  tree_->Print();
128  tree_->Write();
129 
130  // efficiency vs eta
131  TH1F *histetaEff = (TH1F*)histetaMCmatched_->Clone("histetaEff");
132  histetaEff->Reset();
133  histetaEff->Divide(histetaMCmatched_,histeta_,1,1,"b");
134  histetaEff->Print();
135  histetaEff->GetXaxis()->SetTitle("#eta");
136  histetaEff->GetYaxis()->SetTitle("Efficiency");
137 
138  // efficiency vs pt
139  TH1F *histptEff = (TH1F*)histptMCmatched_->Clone("histotEff");
140  histptEff->Reset();
141  histptEff->Divide(histptMCmatched_,histpt_,1,1,"b");
142  histptEff->Print();
143  histptEff->GetXaxis()->SetTitle("p_{T}");
144  histptEff->GetYaxis()->SetTitle("Efficiency");
145 
146  histeMCmatched_->Write();
147  histecaldriveneMCmatched_->Write();
149  histeMC_->Write();
150  histp_->Write();
151  histeclu_->Write();
152  histpt_->Write();
153  histptMCmatched_->Write();
156  histptMC_->Write();
157  histetclu_->Write();
158  histeffpt_->Write();
159  histeta_->Write();
160  histetaMCmatched_->Write();
163  histetaMC_->Write();
164  histetaclu_->Write();
165  histeffeta_->Write();
166  histq_->Write();
167  histeoverp_->Write();
168  histnbseeds_->Write();
169  histnbclus_->Write();
170  histnrseeds_->Write();
171 }
172 
174 {
175  // do anything here that needs to be done at desctruction time
176  // (e.g. close files, deallocate resources etc.)
177  //tree_->Print();
178  histfile_->Write();
179  histeMC_->Write();
180  histfile_->Close();
181 }
182 
184 {
185  //Retrieve tracker topology from geometry
187  iSetup.get<TrackerTopologyRcd>().get(tTopo);
188 
189 
190 
192  edm::ESHandle<MagneticField> theMagField ;
193  iSetup.get<TrackerDigiGeometryRecord> ().get(pDD);
194  iSetup.get<IdealMagneticFieldRecord>().get(theMagField);
195 
196  // rereads the seeds for test purposes
197  typedef edm::OwnVector<TrackingRecHit> recHitContainer;
198  typedef recHitContainer::const_iterator const_iterator;
199  typedef std::pair<const_iterator,const_iterator> range;
200 
201 
202  // get beam spot
203  edm::Handle<reco::BeamSpot> theBeamSpot;
204  e.getByLabel(beamSpot_, theBeamSpot);
205 
206  // get seeds
207 
209  e.getByLabel(inputCollection_,elSeeds);
210  edm::LogInfo("")<<"\n\n =================> Treating event "<<e.id()<<" Number of seeds "<<elSeeds.product()->size();
211  int is=0;
212 
213  float mass=.000511; // electron propagation
214  PropagatorWithMaterial* prop1stLayer = new PropagatorWithMaterial(oppositeToMomentum,mass,&(*theMagField));
215  PropagatorWithMaterial* prop2ndLayer = new PropagatorWithMaterial(alongMomentum,mass,&(*theMagField));
216 
217  float dphi1=0., dphi2=0., drz1=0., drz2=0.;
218  float phi1=0., phi2=0., rz1=0., rz2=0.;
219 
220  for( ElectronSeedCollection::const_iterator MyS= (*elSeeds).begin(); MyS != (*elSeeds).end(); ++MyS) {
221 
222  LogDebug("") <<"\nSeed nr "<<is<<": ";
223  range r=(*MyS).recHits();
224  LogDebug("")<<" Number of RecHits= "<<(*MyS).nHits();
225  const GeomDet *det1=nullptr;const GeomDet *det2=nullptr;
226 
228  DetId id1 = (*it).geographicalId();
229  det1 = pDD->idToDet(id1);
230  LogDebug("") <<" First hit local x,y,z "<<(*it).localPosition()<<" det "<<id1.det()<<" subdet "<<id1.subdetId();
231  LogDebug("") <<" First hit global "<<det1->toGlobal((*it).localPosition());
232  //std::cout <<" First hit local x,y,z "<<(*it).localPosition()<<" det "<<id1.det()<<" subdet "<<id1.subdetId()<< std::endl;
233  //std::cout <<" First hit global "<<det1->toGlobal((*it).localPosition())<< std::endl;
234  it++;
235  DetId id2 = (*it).geographicalId();
236  det2 = pDD->idToDet(id2);
237  LogDebug("") <<" Second hit local x,y,z "<<(*it).localPosition()<<" det "<<id2.det()<<" subdet "<<id2.subdetId();
238  LogDebug("") <<" Second hit global "<<det2->toGlobal((*it).localPosition());
239  //std::cout <<" Second hit local x,y,z "<<(*it).localPosition()<<" det "<<id2.det()<<" subdet "<<id2.subdetId()<< std::endl;
240  //std::cout <<" Second hit global "<<det2->toGlobal((*it).localPosition()) << std::endl;
241 
242  // state on last det
243  const GeomDet *det=nullptr;
244  for (TrackingRecHitCollection::const_iterator rhits=r.first; rhits!=r.second; rhits++) det = pDD->idToDet(((*rhits)).geographicalId());
245  TrajectoryStateOnSurface t= trajectoryStateTransform::transientState((*MyS).startingState(), &(det->surface()), &(*theMagField));
246 
247  // debug
248 
249  LogDebug("")<<" ElectronSeed outermost state position: "<<t.globalPosition();
250  LogDebug("")<<" ElectronSeed outermost state momentum: "<<t.globalMomentum();
251  edm::RefToBase<CaloCluster> caloCluster = (*MyS).caloCluster() ;
252  if (caloCluster.isNull()) continue;
253  edm::Ref<SuperClusterCollection> theClus = caloCluster.castTo<SuperClusterRef>() ;
254  LogDebug("")<<" ElectronSeed superCluster energy: "<<theClus->energy()<<", position: "<<theClus->position();
255  LogDebug("")<<" ElectronSeed outermost state Pt: "<<t.globalMomentum().perp();
256  LogDebug("")<<" ElectronSeed supercluster Et: "<<theClus->energy()*sin(2.*atan(exp(-theClus->position().eta())));
257  LogDebug("")<<" ElectronSeed outermost momentum direction eta: "<<t.globalMomentum().eta();
258  LogDebug("")<<" ElectronSeed supercluster eta: "<<theClus->position().eta();
259  LogDebug("")<<" ElectronSeed seed charge: "<<(*MyS).getCharge();
260  LogDebug("")<<" ElectronSeed E/p: "<<theClus->energy()/t.globalMomentum().mag();
261 
262  // retreive SC and compute distances between hit position and prediction the same
263  // way as in the PixelHitMatcher
264 
265  // inputs are charge, cluster position, vertex position, cluster energy and B field
266  int charge = int((*MyS).getCharge());
267  GlobalPoint xmeas(theClus->position().x(),theClus->position().y(),theClus->position().z());
268  GlobalPoint vprim(theBeamSpot->position().x(),theBeamSpot->position().y(),theBeamSpot->position().z());
269  float energy = theClus->energy();
270 
271  FreeTrajectoryState fts = FTSFromVertexToPointFactory::get(*theMagField, xmeas, vprim, energy, charge);
272  //std::cout << "[PixelHitMatcher::compatibleSeeds] fts position, momentum " <<
273  // fts.parameters().position() << " " << fts.parameters().momentum() << std::endl;
274 
276  TrajectoryStateOnSurface tsos(fts, *bpb(fts.position(), fts.momentum()));
277 
278  // TrajectorySeed::range r=(*seeds.product())[i].recHits();
279  // TrajectorySeed::range r=(*seeds)[i].recHits();
280 
281  // first Hit
282  it=r.first;
283  DetId id=(*it).geographicalId();
284  const GeomDet *geomdet=pDD->idToDet((*it).geographicalId());
285  LocalPoint lp=(*it).localPosition();
286  GlobalPoint hitPos=geomdet->surface().toGlobal(lp);
287 
289  tsos1 = prop1stLayer->propagate(tsos,geomdet->surface()) ;
290 
291  if (tsos1.isValid()) {
292 
293  //UB add test on phidiff
294  float SCl_phi = xmeas.phi();
295  float localDphi = SCl_phi-hitPos.phi();
296  if(localDphi>CLHEP::pi)localDphi-=(2*CLHEP::pi);
297  if(localDphi<-CLHEP::pi)localDphi+=(2*CLHEP::pi);
298  if(std::abs(localDphi)>2.5)continue;
299 
300  phi1 = hitPos.phi();
301  dphi1 = hitPos.phi() - tsos1.globalPosition().phi();
302  rz1 = hitPos.perp();
303  drz1 = hitPos.perp() - tsos1.globalPosition().perp();
304  if (id.subdetId()%2==1) {
305  drz1 = hitPos.z() - tsos1.globalPosition().z();
306  rz1 = hitPos.z();
307  }
308 
309  // now second Hit
310  it++;
311  DetId id2=(*it).geographicalId();
312  const GeomDet *geomdet2=pDD->idToDet((*it).geographicalId());
314 
315  // compute the z vertex from the cluster point and the found pixel hit
316  double pxHit1z = hitPos.z();
317  double pxHit1x = hitPos.x();
318  double pxHit1y = hitPos.y();
319  double r1diff = (pxHit1x-vprim.x())*(pxHit1x-vprim.x()) + (pxHit1y-vprim.y())*(pxHit1y-vprim.y());
320  r1diff=sqrt(r1diff);
321  double r2diff = (xmeas.x()-pxHit1x)*(xmeas.x()-pxHit1x) + (xmeas.y()-pxHit1y)*(xmeas.y()-pxHit1y);
322  r2diff=sqrt(r2diff);
323  double zVertexPred = pxHit1z - r1diff*(xmeas.z()-pxHit1z)/r2diff;
324 
325  GlobalPoint vertexPred(vprim.x(),vprim.y(),zVertexPred);
326 
327  FreeTrajectoryState fts2 = FTSFromVertexToPointFactory::get(*theMagField, hitPos, vertexPred, energy, charge);
328  tsos2 = prop2ndLayer->propagate(fts2,geomdet2->surface()) ;
329 
330  if (tsos2.isValid()) {
331  LocalPoint lp2=(*it).localPosition();
332  GlobalPoint hitPos2=geomdet2->surface().toGlobal(lp2);
333  phi2 = hitPos2.phi();
334  dphi2 = hitPos2.phi() - tsos2.globalPosition().phi();
335  rz2 = hitPos2.perp();
336  drz2 = hitPos2.perp() - tsos2.globalPosition().perp();
337  if (id2.subdetId()%2==1) {
338  rz2 = hitPos2.z();
339  drz2 = hitPos2.z() - tsos2.globalPosition().z();
340  }
341  }
342 
343  }
344 
345  // fill the tree and histos
346 
347  histpt_->Fill(t.globalMomentum().perp());
348  histetclu_->Fill(theClus->energy()*sin(2.*atan(exp(-theClus->position().eta()))));
349  histeta_->Fill(t.globalMomentum().eta());
350  histetaclu_->Fill(theClus->position().eta());
351  histq_->Fill((*MyS).getCharge());
352  histeoverp_->Fill(theClus->energy()/t.globalMomentum().mag());
353 
354  if (is<10) {
355  superclusterEnergy[is] = theClus->energy();
356  superclusterEta[is] = theClus->position().eta();
357  superclusterPhi[is] = theClus->position().phi();
358  superclusterEt[is] = theClus->energy()*sin(2.*atan(exp(-theClus->position().eta())));
359  seedMomentum[is] = t.globalMomentum().mag();
360  seedEta[is] = t.globalMomentum().eta();
361  seedPhi[is] = t.globalMomentum().phi();
362  seedPt[is] = t.globalMomentum().perp();
363  seedQ[is] = (*MyS).getCharge();
364  seedSubdet1[is] = id1.subdetId();
365  seedLayer1[is]=tTopo->layer(id1);
366  seedSide1[is]=tTopo->side(id1);
367  seedPhi1[is] = phi1;
368  seedRz1[is] = rz1;
369  seedDphi1[is] = dphi1;
370  seedDrz1[is] = drz1;
371  seedSubdet2[is] = id2.subdetId();
372  seedLayer2[is]=tTopo->layer(id2);
373  seedSide2[is]=tTopo->side(id2);
374  seedDphi2[is] = dphi2;
375  seedDrz2[is] = drz2;
376  seedPhi2[is] = phi2;
377  seedRz2[is] = rz2;
378  }
379 
380  is++;
381 
382  }
383 
384  histnbseeds_->Fill(elSeeds.product()->size());
385 
386  // get input clusters
387 
389  //CC to be changed according to supercluster input
390  e.getByLabel("correctedHybridSuperClusters", clusters);
391  histnbclus_->Fill(clusters.product()->size());
392  if (!clusters.product()->empty()) histnrseeds_->Fill(elSeeds.product()->size());
393  // get MC information
394 
396  // this one is empty branch in current test files
397  //e.getByLabel("generatorSmeared", "", HepMCEvt);
398  //e.getByLabel("source", "", HepMCEvt);
399  e.getByLabel("generatorSmeared", "", HepMCEvt);
400 
401  const HepMC::GenEvent* MCEvt = HepMCEvt->GetEvent();
402  HepMC::GenParticle* genPc=nullptr;
403  HepMC::FourVector pAssSim;
404  int ip=0;
405  for (HepMC::GenEvent::particle_const_iterator partIter = MCEvt->particles_begin();
406  partIter != MCEvt->particles_end(); ++partIter) {
407 
408  for (HepMC::GenEvent::vertex_const_iterator vertIter = MCEvt->vertices_begin();
409  vertIter != MCEvt->vertices_end(); ++vertIter) {
410 
411  // CLHEP::HepLorentzVector creation = (*partIter)->CreationVertex();
412  HepMC::GenVertex * creation = (*partIter)->production_vertex();
413  // CLHEP::HepLorentzVector momentum = (*partIter)->Momentum();
414  HepMC::FourVector momentum = (*partIter)->momentum();
415  // HepPDT::ParticleID id = (*partIter)->particleID(); // electrons and positrons are 11 and -11
416  int id = (*partIter)->pdg_id(); // electrons and positrons are 11 and -11
417  LogDebug("") << "MC particle id " << id << ", creationVertex " << (*creation) << " cm, initialMomentum " << momentum.rho() << " GeV/c" << std::endl;
418 
419  if (id == 11 || id == -11) {
420 
421  // single primary electrons or electrons from Zs or Ws
422  HepMC::GenParticle* mother = nullptr;
423  if ( (*partIter)->production_vertex() ) {
424  if ( (*partIter)->production_vertex()->particles_begin(HepMC::parents) !=
425  (*partIter)->production_vertex()->particles_end(HepMC::parents))
426  mother = *((*partIter)->production_vertex()->particles_begin(HepMC::parents));
427  }
428  if ( ((mother == nullptr) || ((mother != nullptr) && (mother->pdg_id() == 23))
429  || ((mother != nullptr) && (mother->pdg_id() == 32))
430  || ((mother != nullptr) && (std::abs(mother->pdg_id()) == 24)))) {
431  genPc=(*partIter);
432  pAssSim = genPc->momentum();
433 
434  // EWK fiducial
435  //if (pAssSim.perp()> 100. || std::abs(pAssSim.eta())> 2.5) continue;
436  //if (pAssSim.perp()< 20. || (std::abs(pAssSim.eta())> 1.4442 && std::abs(pAssSim.eta())< 1.56) || std::abs(pAssSim.eta())> 2.5) continue;
437  // reconstruction fiducial
438  //if (pAssSim.perp()< 5. || std::abs(pAssSim.eta())> 2.5) continue;
439  if (std::abs(pAssSim.eta())> 2.5) continue;
440 
441  histptMC_->Fill(pAssSim.perp());
442  histetaMC_->Fill(pAssSim.eta());
443  histeMC_->Fill(pAssSim.rho());
444 
445  // looking for the best matching gsf electron
446  bool okSeedFound = false;
447  double seedOkRatio = 999999.;
448 
449  // find best matched seed
450  reco::ElectronSeed bestElectronSeed;
451  for( ElectronSeedCollection::const_iterator gsfIter= (*elSeeds).begin(); gsfIter != (*elSeeds).end(); ++gsfIter) {
452 
453  range r=gsfIter->recHits();
454  const GeomDet *det=nullptr;
455  for (TrackingRecHitCollection::const_iterator rhits=r.first; rhits!=r.second; rhits++) det = pDD->idToDet(((*rhits)).geographicalId());
456  TrajectoryStateOnSurface t= trajectoryStateTransform::transientState(gsfIter->startingState(), &(det->surface()), &(*theMagField));
457 
458  float eta = t.globalMomentum().eta();
459  float phi = t.globalMomentum().phi();
460  float p = t.globalMomentum().mag();
461  double dphi = phi-pAssSim.phi();
462  if (std::abs(dphi)>CLHEP::pi)
463  dphi = dphi < 0? (CLHEP::twopi) + dphi : dphi - CLHEP::twopi;
464  double deltaR = sqrt(std::pow((eta-pAssSim.eta()),2) + std::pow(dphi,2));
465  if ( deltaR < 0.15 ){
466 // if ( deltaR < 0.3 ){
467  //if ( (genPc->pdg_id() == 11) && (gsfIter->charge() < 0.) || (genPc->pdg_id() == -11) &&
468  //(gsfIter->charge() > 0.) ){
469  double tmpSeedRatio = p/pAssSim.t();
470  if ( std::abs(tmpSeedRatio-1) < std::abs(seedOkRatio-1) ) {
471  seedOkRatio = tmpSeedRatio;
472  bestElectronSeed=*gsfIter;
473  okSeedFound = true;
474  }
475  //}
476  }
477  } // loop over rec ele to look for the best one
478 
479  // analysis when the mc track is found
480  if (okSeedFound){
481 
482  histptMCmatched_->Fill(pAssSim.perp());
483  histetaMCmatched_->Fill(pAssSim.eta());
484  histeMCmatched_->Fill(pAssSim.rho());
485  if (ip<10) {
486  mcEnergy[ip] = pAssSim.rho();
487  mcEta[ip] = pAssSim.eta();
488  mcPhi[ip] = pAssSim.phi();
489  mcPt[ip] = pAssSim.perp();
490  mcQ[ip] = ((id == 11) ? -1.: +1.);
491  }
492  }
493 
494  // efficiency for ecal driven only
495  okSeedFound = false;
496  seedOkRatio = 999999.;
497 
498  // find best matched seed
499  for( ElectronSeedCollection::const_iterator gsfIter= (*elSeeds).begin(); gsfIter != (*elSeeds).end(); ++gsfIter) {
500 
501  range r=gsfIter->recHits();
502  const GeomDet *det=nullptr;
503  for (TrackingRecHitCollection::const_iterator rhits=r.first; rhits!=r.second; rhits++) det = pDD->idToDet(((*rhits)).geographicalId());
504  TrajectoryStateOnSurface t= trajectoryStateTransform::transientState(gsfIter->startingState(), &(det->surface()), &(*theMagField));
505 
506  float eta = t.globalMomentum().eta();
507  float phi = t.globalMomentum().phi();
508  float p = t.globalMomentum().mag();
509  double dphi = phi-pAssSim.phi();
510  if (std::abs(dphi)>CLHEP::pi)
511  dphi = dphi < 0? (CLHEP::twopi) + dphi : dphi - CLHEP::twopi;
512  double deltaR = sqrt(std::pow((eta-pAssSim.eta()),2) + std::pow(dphi,2));
513  if (gsfIter->isEcalDriven()) {
514  if ( deltaR < 0.15 ){
515 // if ( deltaR < 0.3 ){
516  //if ( (genPc->pdg_id() == 11) && (gsfIter->charge() < 0.) || (genPc->pdg_id() == -11) &&
517  //(gsfIter->charge() > 0.) ){
518  double tmpSeedRatio = p/pAssSim.t();
519  if ( std::abs(tmpSeedRatio-1) < std::abs(seedOkRatio-1) ) {
520  seedOkRatio = tmpSeedRatio;
521  bestElectronSeed=*gsfIter;
522  okSeedFound = true;
523  }
524  //}
525  }
526  } // end if ecal driven
527  } // loop over rec ele to look for the best one
528 
529  // analysis when the mc track is found
530  if (okSeedFound){
531 
532  histecaldrivenptMCmatched_->Fill(pAssSim.perp());
533  histecaldrivenetaMCmatched_->Fill(pAssSim.eta());
534  histecaldriveneMCmatched_->Fill(pAssSim.rho());
535  }
536 
537  // efficiency for tracker driven only
538  okSeedFound = false;
539  seedOkRatio = 999999.;
540 
541  // find best matched seed
542  for( ElectronSeedCollection::const_iterator gsfIter= (*elSeeds).begin(); gsfIter != (*elSeeds).end(); ++gsfIter) {
543 
544  range r=gsfIter->recHits();
545  const GeomDet *det=nullptr;
546  for (TrackingRecHitCollection::const_iterator rhits=r.first; rhits!=r.second; rhits++) det = pDD->idToDet(((*rhits)).geographicalId());
547  TrajectoryStateOnSurface t= trajectoryStateTransform::transientState(gsfIter->startingState(), &(det->surface()), &(*theMagField));
548 
549  float eta = t.globalMomentum().eta();
550  float phi = t.globalMomentum().phi();
551  float p = t.globalMomentum().mag();
552  double dphi = phi-pAssSim.phi();
553  if (std::abs(dphi)>CLHEP::pi)
554  dphi = dphi < 0? (CLHEP::twopi) + dphi : dphi - CLHEP::twopi;
555  double deltaR = sqrt(std::pow((eta-pAssSim.eta()),2) + std::pow(dphi,2));
556  if (gsfIter->isTrackerDriven()) {
557  if ( deltaR < 0.15 ){
558 // if ( deltaR < 0.3 ){
559  //if ( (genPc->pdg_id() == 11) && (gsfIter->charge() < 0.) || (genPc->pdg_id() == -11) &&
560  //(gsfIter->charge() > 0.) ){
561  double tmpSeedRatio = p/pAssSim.t();
562  if ( std::abs(tmpSeedRatio-1) < std::abs(seedOkRatio-1) ) {
563  seedOkRatio = tmpSeedRatio;
564  bestElectronSeed=*gsfIter;
565  okSeedFound = true;
566  }
567  //}
568  }
569  } // end if ecal driven
570  } // loop over rec ele to look for the best one
571 
572  // analysis when the mc track is found
573  if (okSeedFound){
574 
575  histtrackerdrivenptMCmatched_->Fill(pAssSim.perp());
576  histtrackerdrivenetaMCmatched_->Fill(pAssSim.eta());
577  histtrackerdriveneMCmatched_->Fill(pAssSim.rho());
578  }
579 
580  } // end if mother W or Z
581 
582  } // end if gen part is electron
583 
584  } // end loop on vertices
585 
586  ip++;
587 
588  } // end loop on gen particles
589 
590  //tree_->Fill();
591 
592 }
593 
594 
#define LogDebug(id)
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:106
T getParameter(std::string const &) const
static FreeTrajectoryState get(MagneticField const &magField, GlobalPoint const &xmeas, GlobalPoint const &xvert, float momentum, TrackCharge charge)
TPRegexp parents
Definition: eve_filter.cc:21
T perp() const
Definition: PV3DBase.h:72
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:54
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
unsigned int side(const DetId &id) const
T y() const
Definition: PV3DBase.h:63
GlobalPoint globalPosition() const
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:42
const Double_t pi
edm::InputTag inputCollection_
T mag() const
Definition: PV3DBase.h:67
recHitContainer::const_iterator const_iterator
T sqrt(T t)
Definition: SSEVec.h:18
T z() const
Definition: PV3DBase.h:64
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:41
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:480
GlobalVector momentum() const
Definition: DetId.h:18
GlobalPoint position() const
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:38
TrajectoryStateOnSurface transientState(const PTrajectoryStateOnDet &ts, const Surface *surface, const MagneticField *field)
T const * product() const
Definition: Handle.h:74
void analyze(const edm::Event &, const edm::EventSetup &) override
REF castTo() const
Definition: RefToBase.h:289
bool isNull() const
Checks for null.
Definition: RefToBase.h:331
TrajectoryStateOnSurface propagate(STA const &state, SUR const &surface) const
Definition: Propagator.h:53
unsigned int layer(const DetId &id) const
T eta() const
Definition: PV3DBase.h:76
edm::EventID id() const
Definition: EventBase.h:59
fixed size matrix
HLT enums.
GlobalVector globalMomentum() const
T get() const
Definition: EventSetup.h:71
const TrackerGeomDet * idToDet(DetId) const override
const Point & position() const
position
Definition: BeamSpot.h:62
T x() const
Definition: PV3DBase.h:62
ElectronSeedAnalyzer(const edm::ParameterSet &conf)
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:39