CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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<IdealGeometryRecord>().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 
214  float mass=.000511; // electron propagation
215  PropagatorWithMaterial* prop1stLayer = new PropagatorWithMaterial(oppositeToMomentum,mass,&(*theMagField));
216  PropagatorWithMaterial* prop2ndLayer = new PropagatorWithMaterial(alongMomentum,mass,&(*theMagField));
217 
218  float dphi1=0., dphi2=0., drz1=0., drz2=0.;
219  float phi1=0., phi2=0., rz1=0., rz2=0.;
220 
221  for( ElectronSeedCollection::const_iterator MyS= (*elSeeds).begin(); MyS != (*elSeeds).end(); ++MyS) {
222 
223  LogDebug("") <<"\nSeed nr "<<is<<": ";
224  range r=(*MyS).recHits();
225  LogDebug("")<<" Number of RecHits= "<<(*MyS).nHits();
226  const GeomDet *det1=0;const GeomDet *det2=0;
227 
229  DetId id1 = (*it).geographicalId();
230  det1 = pDD->idToDet(id1);
231  LogDebug("") <<" First hit local x,y,z "<<(*it).localPosition()<<" det "<<id1.det()<<" subdet "<<id1.subdetId();
232  LogDebug("") <<" First hit global "<<det1->toGlobal((*it).localPosition());
233  //std::cout <<" First hit local x,y,z "<<(*it).localPosition()<<" det "<<id1.det()<<" subdet "<<id1.subdetId()<< std::endl;
234  //std::cout <<" First hit global "<<det1->toGlobal((*it).localPosition())<< std::endl;
235  it++;
236  DetId id2 = (*it).geographicalId();
237  det2 = pDD->idToDet(id2);
238  LogDebug("") <<" Second hit local x,y,z "<<(*it).localPosition()<<" det "<<id2.det()<<" subdet "<<id2.subdetId();
239  LogDebug("") <<" Second hit global "<<det2->toGlobal((*it).localPosition());
240  //std::cout <<" Second hit local x,y,z "<<(*it).localPosition()<<" det "<<id2.det()<<" subdet "<<id2.subdetId()<< std::endl;
241  //std::cout <<" Second hit global "<<det2->toGlobal((*it).localPosition()) << std::endl;
242 
243  // state on last det
244  const GeomDet *det=0;
245  for (TrackingRecHitCollection::const_iterator rhits=r.first; rhits!=r.second; rhits++) det = pDD->idToDet(((*rhits)).geographicalId());
246  TrajectoryStateOnSurface t= trajectoryStateTransform::transientState((*MyS).startingState(), &(det->surface()), &(*theMagField));
247 
248  // debug
249 
250  LogDebug("")<<" ElectronSeed outermost state position: "<<t.globalPosition();
251  LogDebug("")<<" ElectronSeed outermost state momentum: "<<t.globalMomentum();
252  edm::RefToBase<CaloCluster> caloCluster = (*MyS).caloCluster() ;
253  if (caloCluster.isNull()) continue;
254  edm::Ref<SuperClusterCollection> theClus = caloCluster.castTo<SuperClusterRef>() ;
255  LogDebug("")<<" ElectronSeed superCluster energy: "<<theClus->energy()<<", position: "<<theClus->position();
256  LogDebug("")<<" ElectronSeed outermost state Pt: "<<t.globalMomentum().perp();
257  LogDebug("")<<" ElectronSeed supercluster Et: "<<theClus->energy()*sin(2.*atan(exp(-theClus->position().eta())));
258  LogDebug("")<<" ElectronSeed outermost momentum direction eta: "<<t.globalMomentum().eta();
259  LogDebug("")<<" ElectronSeed supercluster eta: "<<theClus->position().eta();
260  LogDebug("")<<" ElectronSeed seed charge: "<<(*MyS).getCharge();
261  LogDebug("")<<" ElectronSeed E/p: "<<theClus->energy()/t.globalMomentum().mag();
262 
263  // retreive SC and compute distances between hit position and prediction the same
264  // way as in the PixelHitMatcher
265 
266  // inputs are charge, cluster position, vertex position, cluster energy and B field
267  int charge = int((*MyS).getCharge());
268  GlobalPoint xmeas(theClus->position().x(),theClus->position().y(),theClus->position().z());
269  GlobalPoint vprim(theBeamSpot->position().x(),theBeamSpot->position().y(),theBeamSpot->position().z());
270  float energy = theClus->energy();
271 
272  FreeTrajectoryState fts = myFTS(&(*theMagField),xmeas, vprim,
273  energy, charge);
274  //std::cout << "[PixelHitMatcher::compatibleSeeds] fts position, momentum " <<
275  // fts.parameters().position() << " " << fts.parameters().momentum() << std::endl;
276 
278  TrajectoryStateOnSurface tsos(fts, *bpb(fts.position(), fts.momentum()));
279 
280  // TrajectorySeed::range r=(*seeds.product())[i].recHits();
281  // TrajectorySeed::range r=(*seeds)[i].recHits();
282 
283  // first Hit
284  it=r.first;
285  DetId id=(*it).geographicalId();
286  const GeomDet *geomdet=pDD->idToDet((*it).geographicalId());
287  LocalPoint lp=(*it).localPosition();
288  GlobalPoint hitPos=geomdet->surface().toGlobal(lp);
289 
291  tsos1 = prop1stLayer->propagate(tsos,geomdet->surface()) ;
292 
293  if (tsos1.isValid()) {
294 
295  std::pair<bool,double> est;
296 
297  //UB add test on phidiff
298  float SCl_phi = xmeas.phi();
299  float localDphi = SCl_phi-hitPos.phi();
300  if(localDphi>CLHEP::pi)localDphi-=(2*CLHEP::pi);
301  if(localDphi<-CLHEP::pi)localDphi+=(2*CLHEP::pi);
302  if(std::abs(localDphi)>2.5)continue;
303 
304  phi1 = hitPos.phi();
305  dphi1 = hitPos.phi() - tsos1.globalPosition().phi();
306  rz1 = hitPos.perp();
307  drz1 = hitPos.perp() - tsos1.globalPosition().perp();
308  if (id.subdetId()%2==1) {
309  drz1 = hitPos.z() - tsos1.globalPosition().z();
310  rz1 = hitPos.z();
311  }
312 
313  // now second Hit
314  it++;
315  DetId id2=(*it).geographicalId();
316  const GeomDet *geomdet2=pDD->idToDet((*it).geographicalId());
318 
319  // compute the z vertex from the cluster point and the found pixel hit
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;
328 
329  GlobalPoint vertexPred(vprim.x(),vprim.y(),zVertexPred);
330 
331  FreeTrajectoryState fts2 = myFTS(&(*theMagField),hitPos,vertexPred,energy, charge);
332  tsos2 = prop2ndLayer->propagate(fts2,geomdet2->surface()) ;
333 
334  if (tsos2.isValid()) {
335  LocalPoint lp2=(*it).localPosition();
336  GlobalPoint hitPos2=geomdet2->surface().toGlobal(lp2);
337  phi2 = hitPos2.phi();
338  dphi2 = hitPos2.phi() - tsos2.globalPosition().phi();
339  rz2 = hitPos2.perp();
340  drz2 = hitPos2.perp() - tsos2.globalPosition().perp();
341  if (id2.subdetId()%2==1) {
342  rz2 = hitPos2.z();
343  drz2 = hitPos2.z() - tsos2.globalPosition().z();
344  }
345  }
346 
347  }
348 
349  // fill the tree and histos
350 
351  histpt_->Fill(t.globalMomentum().perp());
352  histetclu_->Fill(theClus->energy()*sin(2.*atan(exp(-theClus->position().eta()))));
353  histeta_->Fill(t.globalMomentum().eta());
354  histetaclu_->Fill(theClus->position().eta());
355  histq_->Fill((*MyS).getCharge());
356  histeoverp_->Fill(theClus->energy()/t.globalMomentum().mag());
357 
358  if (is<10) {
359  superclusterEnergy[is] = theClus->energy();
360  superclusterEta[is] = theClus->position().eta();
361  superclusterPhi[is] = theClus->position().phi();
362  superclusterEt[is] = theClus->energy()*sin(2.*atan(exp(-theClus->position().eta())));
363  seedMomentum[is] = t.globalMomentum().mag();
364  seedEta[is] = t.globalMomentum().eta();
365  seedPhi[is] = t.globalMomentum().phi();
366  seedPt[is] = t.globalMomentum().perp();
367  seedQ[is] = (*MyS).getCharge();
368  seedSubdet1[is] = id1.subdetId();
369  switch (seedSubdet1[is]) {
370  case 1:
371  {
372 
373  seedLayer1[is] = tTopo->pxbLayer( id1);
374  seedSide1[is] = 0;
375  break;
376  }
377  case 2:
378  {
379 
380  seedLayer1[is] = tTopo->pxfDisk( id1);
381  seedSide1[is] = tTopo->pxfSide( id1);
382  break;
383  }
384  case 3:
385  {
386 
387  seedLayer1[is] = tTopo->tibLayer( id1);
388  seedSide1[is] = 0;
389  break;
390  }
391  case 4:
392  {
393 
394  seedLayer1[is] = tTopo->tidWheel( id1);
395  seedSide1[is] = tTopo->tidSide( id1);
396  break;
397  }
398  case 5:
399  {
400 
401  seedLayer1[is] = tTopo->tobLayer( id1);
402  seedSide1[is] = 0;
403  break;
404  }
405  case 6:
406  {
407 
408  seedLayer1[is] = tTopo->tecWheel( id1);
409  seedSide1[is] = tTopo->tecSide( id1);
410  break;
411  }
412  }
413  seedPhi1[is] = phi1;
414  seedRz1[is] = rz1;
415  seedDphi1[is] = dphi1;
416  seedDrz1[is] = drz1;
417  seedSubdet2[is] = id2.subdetId();
418  switch (seedSubdet2[is]) {
419  case 1:
420  {
421 
422  seedLayer2[is] = tTopo->pxbLayer( id2);
423  seedSide2[is] = 0;
424  break;
425  }
426  case 2:
427  {
428 
429  seedLayer2[is] = tTopo->pxfDisk( id2);
430  seedSide2[is] = tTopo->pxfSide( id2);
431  break;
432  }
433  case 3:
434  {
435 
436  seedLayer2[is] = tTopo->tibLayer( id2);
437  seedSide2[is] = 0;
438  break;
439  }
440  case 4:
441  {
442 
443  seedLayer2[is] = tTopo->tidWheel( id2);
444  seedSide2[is] = tTopo->tidSide( id2);
445  break;
446  }
447  case 5:
448  {
449 
450  seedLayer2[is] = tTopo->tobLayer( id2);
451  seedSide2[is] = 0;
452  break;
453  }
454  case 6:
455  {
456 
457  seedLayer2[is] = tTopo->tecWheel( id2);
458  seedSide2[is] = tTopo->tecSide( id2);
459  break;
460  }
461  }
462  seedDphi2[is] = dphi2;
463  seedDrz2[is] = drz2;
464  seedPhi2[is] = phi2;
465  seedRz2[is] = rz2;
466  }
467 
468  is++;
469 
470  }
471 
472  histnbseeds_->Fill(elSeeds.product()->size());
473 
474  // get input clusters
475 
477  //CC to be changed according to supercluster input
478  e.getByLabel("correctedHybridSuperClusters", clusters);
479  histnbclus_->Fill(clusters.product()->size());
480  if (clusters.product()->size()>0) histnrseeds_->Fill(elSeeds.product()->size());
481  // get MC information
482 
484  // this one is empty branch in current test files
485  //e.getByLabel("VtxSmeared", "", HepMCEvt);
486  //e.getByLabel("source", "", HepMCEvt);
487  e.getByLabel("generator", "", HepMCEvt);
488 
489  const HepMC::GenEvent* MCEvt = HepMCEvt->GetEvent();
490  HepMC::GenParticle* genPc=0;
491  HepMC::FourVector pAssSim;
492  int ip=0;
493  for (HepMC::GenEvent::particle_const_iterator partIter = MCEvt->particles_begin();
494  partIter != MCEvt->particles_end(); ++partIter) {
495 
496  for (HepMC::GenEvent::vertex_const_iterator vertIter = MCEvt->vertices_begin();
497  vertIter != MCEvt->vertices_end(); ++vertIter) {
498 
499  // CLHEP::HepLorentzVector creation = (*partIter)->CreationVertex();
500  HepMC::GenVertex * creation = (*partIter)->production_vertex();
501  // CLHEP::HepLorentzVector momentum = (*partIter)->Momentum();
502  HepMC::FourVector momentum = (*partIter)->momentum();
503  // HepPDT::ParticleID id = (*partIter)->particleID(); // electrons and positrons are 11 and -11
504  int id = (*partIter)->pdg_id(); // electrons and positrons are 11 and -11
505  LogDebug("") << "MC particle id " << id << ", creationVertex " << (*creation) << " cm, initialMomentum " << momentum.rho() << " GeV/c" << std::endl;
506 
507  if (id == 11 || id == -11) {
508 
509  // single primary electrons or electrons from Zs or Ws
510  HepMC::GenParticle* mother = 0;
511  if ( (*partIter)->production_vertex() ) {
512  if ( (*partIter)->production_vertex()->particles_begin(HepMC::parents) !=
513  (*partIter)->production_vertex()->particles_end(HepMC::parents))
514  mother = *((*partIter)->production_vertex()->particles_begin(HepMC::parents));
515  }
516  if ( ((mother == 0) || ((mother != 0) && (mother->pdg_id() == 23))
517  || ((mother != 0) && (mother->pdg_id() == 32))
518  || ((mother != 0) && (std::abs(mother->pdg_id()) == 24)))) {
519  genPc=(*partIter);
520  pAssSim = genPc->momentum();
521 
522  // EWK fiducial
523  //if (pAssSim.perp()> 100. || std::abs(pAssSim.eta())> 2.5) continue;
524  //if (pAssSim.perp()< 20. || (std::abs(pAssSim.eta())> 1.4442 && std::abs(pAssSim.eta())< 1.56) || std::abs(pAssSim.eta())> 2.5) continue;
525  // reconstruction fiducial
526  //if (pAssSim.perp()< 5. || std::abs(pAssSim.eta())> 2.5) continue;
527  if (std::abs(pAssSim.eta())> 2.5) continue;
528 
529  histptMC_->Fill(pAssSim.perp());
530  histetaMC_->Fill(pAssSim.eta());
531  histeMC_->Fill(pAssSim.rho());
532 
533  // looking for the best matching gsf electron
534  bool okSeedFound = false;
535  double seedOkRatio = 999999.;
536 
537  // find best matched seed
538  reco::ElectronSeed bestElectronSeed;
539  for( ElectronSeedCollection::const_iterator gsfIter= (*elSeeds).begin(); gsfIter != (*elSeeds).end(); ++gsfIter) {
540 
541  range r=gsfIter->recHits();
542  const GeomDet *det=0;
543  for (TrackingRecHitCollection::const_iterator rhits=r.first; rhits!=r.second; rhits++) det = pDD->idToDet(((*rhits)).geographicalId());
544  TrajectoryStateOnSurface t= trajectoryStateTransform::transientState(gsfIter->startingState(), &(det->surface()), &(*theMagField));
545 
546  float eta = t.globalMomentum().eta();
547  float phi = t.globalMomentum().phi();
548  float p = t.globalMomentum().mag();
549  double dphi = phi-pAssSim.phi();
550  if (std::abs(dphi)>CLHEP::pi)
551  dphi = dphi < 0? (CLHEP::twopi) + dphi : dphi - CLHEP::twopi;
552  double deltaR = sqrt(std::pow((eta-pAssSim.eta()),2) + std::pow(dphi,2));
553  if ( deltaR < 0.15 ){
554 // if ( deltaR < 0.3 ){
555  //if ( (genPc->pdg_id() == 11) && (gsfIter->charge() < 0.) || (genPc->pdg_id() == -11) &&
556  //(gsfIter->charge() > 0.) ){
557  double tmpSeedRatio = p/pAssSim.t();
558  if ( std::abs(tmpSeedRatio-1) < std::abs(seedOkRatio-1) ) {
559  seedOkRatio = tmpSeedRatio;
560  bestElectronSeed=*gsfIter;
561  okSeedFound = true;
562  }
563  //}
564  }
565  } // loop over rec ele to look for the best one
566 
567  // analysis when the mc track is found
568  if (okSeedFound){
569 
570  histptMCmatched_->Fill(pAssSim.perp());
571  histetaMCmatched_->Fill(pAssSim.eta());
572  histeMCmatched_->Fill(pAssSim.rho());
573  if (ip<10) {
574  mcEnergy[ip] = pAssSim.rho();
575  mcEta[ip] = pAssSim.eta();
576  mcPhi[ip] = pAssSim.phi();
577  mcPt[ip] = pAssSim.perp();
578  mcQ[ip] = ((id == 11) ? -1.: +1.);
579  }
580  }
581 
582  // efficiency for ecal driven only
583  okSeedFound = false;
584  seedOkRatio = 999999.;
585 
586  // find best matched seed
587  for( ElectronSeedCollection::const_iterator gsfIter= (*elSeeds).begin(); gsfIter != (*elSeeds).end(); ++gsfIter) {
588 
589  range r=gsfIter->recHits();
590  const GeomDet *det=0;
591  for (TrackingRecHitCollection::const_iterator rhits=r.first; rhits!=r.second; rhits++) det = pDD->idToDet(((*rhits)).geographicalId());
592  TrajectoryStateOnSurface t= trajectoryStateTransform::transientState(gsfIter->startingState(), &(det->surface()), &(*theMagField));
593 
594  float eta = t.globalMomentum().eta();
595  float phi = t.globalMomentum().phi();
596  float p = t.globalMomentum().mag();
597  double dphi = phi-pAssSim.phi();
598  if (std::abs(dphi)>CLHEP::pi)
599  dphi = dphi < 0? (CLHEP::twopi) + dphi : dphi - CLHEP::twopi;
600  double deltaR = sqrt(std::pow((eta-pAssSim.eta()),2) + std::pow(dphi,2));
601  if (gsfIter->isEcalDriven()) {
602  if ( deltaR < 0.15 ){
603 // if ( deltaR < 0.3 ){
604  //if ( (genPc->pdg_id() == 11) && (gsfIter->charge() < 0.) || (genPc->pdg_id() == -11) &&
605  //(gsfIter->charge() > 0.) ){
606  double tmpSeedRatio = p/pAssSim.t();
607  if ( std::abs(tmpSeedRatio-1) < std::abs(seedOkRatio-1) ) {
608  seedOkRatio = tmpSeedRatio;
609  bestElectronSeed=*gsfIter;
610  okSeedFound = true;
611  }
612  //}
613  }
614  } // end if ecal driven
615  } // loop over rec ele to look for the best one
616 
617  // analysis when the mc track is found
618  if (okSeedFound){
619 
620  histecaldrivenptMCmatched_->Fill(pAssSim.perp());
621  histecaldrivenetaMCmatched_->Fill(pAssSim.eta());
622  histecaldriveneMCmatched_->Fill(pAssSim.rho());
623  }
624 
625  // efficiency for tracker driven only
626  okSeedFound = false;
627  seedOkRatio = 999999.;
628 
629  // find best matched seed
630  for( ElectronSeedCollection::const_iterator gsfIter= (*elSeeds).begin(); gsfIter != (*elSeeds).end(); ++gsfIter) {
631 
632  range r=gsfIter->recHits();
633  const GeomDet *det=0;
634  for (TrackingRecHitCollection::const_iterator rhits=r.first; rhits!=r.second; rhits++) det = pDD->idToDet(((*rhits)).geographicalId());
635  TrajectoryStateOnSurface t= trajectoryStateTransform::transientState(gsfIter->startingState(), &(det->surface()), &(*theMagField));
636 
637  float eta = t.globalMomentum().eta();
638  float phi = t.globalMomentum().phi();
639  float p = t.globalMomentum().mag();
640  double dphi = phi-pAssSim.phi();
641  if (std::abs(dphi)>CLHEP::pi)
642  dphi = dphi < 0? (CLHEP::twopi) + dphi : dphi - CLHEP::twopi;
643  double deltaR = sqrt(std::pow((eta-pAssSim.eta()),2) + std::pow(dphi,2));
644  if (gsfIter->isTrackerDriven()) {
645  if ( deltaR < 0.15 ){
646 // if ( deltaR < 0.3 ){
647  //if ( (genPc->pdg_id() == 11) && (gsfIter->charge() < 0.) || (genPc->pdg_id() == -11) &&
648  //(gsfIter->charge() > 0.) ){
649  double tmpSeedRatio = p/pAssSim.t();
650  if ( std::abs(tmpSeedRatio-1) < std::abs(seedOkRatio-1) ) {
651  seedOkRatio = tmpSeedRatio;
652  bestElectronSeed=*gsfIter;
653  okSeedFound = true;
654  }
655  //}
656  }
657  } // end if ecal driven
658  } // loop over rec ele to look for the best one
659 
660  // analysis when the mc track is found
661  if (okSeedFound){
662 
663  histtrackerdrivenptMCmatched_->Fill(pAssSim.perp());
664  histtrackerdrivenetaMCmatched_->Fill(pAssSim.eta());
665  histtrackerdriveneMCmatched_->Fill(pAssSim.rho());
666  }
667 
668  } // end if mother W or Z
669 
670  } // end if gen part is electron
671 
672  } // end loop on vertices
673 
674  ip++;
675 
676  } // end loop on gen particles
677 
678  //tree_->Fill();
679 
680 }
681 
682 
#define LogDebug(id)
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:114
T getParameter(std::string const &) const
TPRegexp parents
Definition: eve_filter.cc:24
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:47
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
T y() const
Definition: PV3DBase.h:63
bool isNull() const
Checks for null.
Definition: RefToBase.h:270
#define abs(x)
Definition: mlp_lapack.h:159
GlobalPoint globalPosition() const
T eta() const
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:35
double charge(const std::vector< uint8_t > &Ampls)
virtual void analyze(const edm::Event &, const edm::EventSetup &)
edm::InputTag inputCollection_
T mag() const
Definition: PV3DBase.h:67
recHitContainer::const_iterator const_iterator
T sqrt(T t)
Definition: SSEVec.h:48
T z() const
Definition: PV3DBase.h:64
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:39
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
GlobalVector momentum() const
tuple conf
Definition: dbtoconf.py:185
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
Definition: DetId.h:20
GlobalPoint position() const
TrajectoryStateOnSurface transientState(const PTrajectoryStateOnDet &ts, const Surface *surface, const MagneticField *field)
const T & get() const
Definition: EventSetup.h:55
REF castTo() const
cast to a concrete type
Definition: RefToBase.h:241
T const * product() const
Definition: Handle.h:74
T eta() const
Definition: PV3DBase.h:76
edm::EventID id() const
Definition: EventBase.h:56
GlobalVector globalMomentum() const
double pi
Detector det() const
get the detector field from this detid
Definition: DetId.h:37
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
Definition: DDAxes.h:10