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 
42 
45 
47 
49 #include "HepMC/GenParticle.h"
50 #include "HepMC/SimpleVector.h"
51 #include "CLHEP/Units/GlobalPhysicalConstants.h"
52 
53 #include <iostream>
54 #include "TFile.h"
55 #include "TH1F.h"
56 #include "TH1I.h"
57 #include "TTree.h"
58 
59 using namespace std;
60 using namespace reco;
61 
63 {
64  inputCollection_=conf.getParameter<edm::InputTag>("inputCollection") ;
65  histfile_ = new TFile("electronpixelseeds.root","RECREATE");
66 }
67 
69 {
70  histfile_->cd();
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.);
125 }
126 
128 {
129  histfile_->cd();
130  tree_->Print();
131  tree_->Write();
132 
133  // efficiency vs eta
134  TH1F *histetaEff = (TH1F*)histetaMCmatched_->Clone("histetaEff");
135  histetaEff->Reset();
136  histetaEff->Divide(histetaMCmatched_,histeta_,1,1,"b");
137  histetaEff->Print();
138  histetaEff->GetXaxis()->SetTitle("#eta");
139  histetaEff->GetYaxis()->SetTitle("Efficiency");
140 
141  // efficiency vs pt
142  TH1F *histptEff = (TH1F*)histptMCmatched_->Clone("histotEff");
143  histptEff->Reset();
144  histptEff->Divide(histptMCmatched_,histpt_,1,1,"b");
145  histptEff->Print();
146  histptEff->GetXaxis()->SetTitle("p_{T}");
147  histptEff->GetYaxis()->SetTitle("Efficiency");
148 
149  histeMCmatched_->Write();
150  histecaldriveneMCmatched_->Write();
151  histtrackerdriveneMCmatched_->Write();
152  histeMC_->Write();
153  histp_->Write();
154  histeclu_->Write();
155  histpt_->Write();
156  histptMCmatched_->Write();
157  histecaldrivenptMCmatched_->Write();
158  histtrackerdrivenptMCmatched_->Write();
159  histptMC_->Write();
160  histetclu_->Write();
161  histeffpt_->Write();
162  histeta_->Write();
163  histetaMCmatched_->Write();
164  histecaldrivenetaMCmatched_->Write();
165  histtrackerdrivenetaMCmatched_->Write();
166  histetaMC_->Write();
167  histetaclu_->Write();
168  histeffeta_->Write();
169  histq_->Write();
170  histeoverp_->Write();
171  histnbseeds_->Write();
172  histnbclus_->Write();
173  histnrseeds_->Write();
174 }
175 
177 {
178  // do anything here that needs to be done at desctruction time
179  // (e.g. close files, deallocate resources etc.)
180  //tree_->Print();
181  histfile_->Write();
182  histeMC_->Write();
183  histfile_->Close();
184 }
185 
187 {
188 
190  edm::ESHandle<MagneticField> theMagField ;
191  iSetup.get<TrackerDigiGeometryRecord> ().get(pDD);
192  iSetup.get<IdealMagneticFieldRecord>().get(theMagField);
193 
194  // rereads the seeds for test purposes
195  typedef edm::OwnVector<TrackingRecHit> recHitContainer;
196  typedef recHitContainer::const_iterator const_iterator;
197  typedef std::pair<const_iterator,const_iterator> range;
198 
199 
200  // get beam spot
201  edm::Handle<reco::BeamSpot> theBeamSpot;
202  e.getByType(theBeamSpot);
203 
204  // get seeds
205 
207  e.getByLabel(inputCollection_,elSeeds);
208  edm::LogInfo("")<<"\n\n =================> Treating event "<<e.id()<<" Number of seeds "<<elSeeds.product()->size();
209  int is=0;
210 
212  float mass=.000511; // electron propagation
213  PropagatorWithMaterial* prop1stLayer = new PropagatorWithMaterial(oppositeToMomentum,mass,&(*theMagField));
214  PropagatorWithMaterial* prop2ndLayer = new PropagatorWithMaterial(alongMomentum,mass,&(*theMagField));
215 
216  float dphi1=0., dphi2=0., drz1=0., drz2=0.;
217  float phi1=0., phi2=0., rz1=0., rz2=0.;
218 
219  for( ElectronSeedCollection::const_iterator MyS= (*elSeeds).begin(); MyS != (*elSeeds).end(); ++MyS) {
220 
221  LogDebug("") <<"\nSeed nr "<<is<<": ";
222  range r=(*MyS).recHits();
223  LogDebug("")<<" Number of RecHits= "<<(*MyS).nHits();
224  const GeomDet *det1=0;const GeomDet *det2=0;
225 
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();
230  LogDebug("") <<" First hit global "<<det1->toGlobal((*it).localPosition());
231  //std::cout <<" First hit local x,y,z "<<(*it).localPosition()<<" det "<<id1.det()<<" subdet "<<id1.subdetId()<< std::endl;
232  //std::cout <<" First hit global "<<det1->toGlobal((*it).localPosition())<< std::endl;
233  it++;
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());
238  //std::cout <<" Second hit local x,y,z "<<(*it).localPosition()<<" det "<<id2.det()<<" subdet "<<id2.subdetId()<< std::endl;
239  //std::cout <<" Second hit global "<<det2->toGlobal((*it).localPosition()) << std::endl;
240 
241  // state on last det
242  const GeomDet *det=0;
243  for (TrackingRecHitCollection::const_iterator rhits=r.first; rhits!=r.second; rhits++) det = pDD->idToDet(((*rhits)).geographicalId());
244  TrajectoryStateOnSurface t= transformer_.transientState((*MyS).startingState(), &(det->surface()), &(*theMagField));
245 
246  // debug
247 
248  LogDebug("")<<" ElectronSeed outermost state position: "<<t.globalPosition();
249  LogDebug("")<<" ElectronSeed outermost state momentum: "<<t.globalMomentum();
250  edm::RefToBase<CaloCluster> caloCluster = (*MyS).caloCluster() ;
251  if (caloCluster.isNull()) continue;
252  edm::Ref<SuperClusterCollection> theClus = caloCluster.castTo<SuperClusterRef>() ;
253  LogDebug("")<<" ElectronSeed superCluster energy: "<<theClus->energy()<<", position: "<<theClus->position();
254  LogDebug("")<<" ElectronSeed outermost state Pt: "<<t.globalMomentum().perp();
255  LogDebug("")<<" ElectronSeed supercluster Et: "<<theClus->energy()*sin(2.*atan(exp(-theClus->position().eta())));
256  LogDebug("")<<" ElectronSeed outermost momentum direction eta: "<<t.globalMomentum().eta();
257  LogDebug("")<<" ElectronSeed supercluster eta: "<<theClus->position().eta();
258  LogDebug("")<<" ElectronSeed seed charge: "<<(*MyS).getCharge();
259  LogDebug("")<<" ElectronSeed E/p: "<<theClus->energy()/t.globalMomentum().mag();
260 
261  // retreive SC and compute distances between hit position and prediction the same
262  // way as in the PixelHitMatcher
263 
264  // inputs are charge, cluster position, vertex position, cluster energy and B field
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();
269 
270  FreeTrajectoryState fts = myFTS(&(*theMagField),xmeas, vprim,
271  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  std::pair<bool,double> est;
294 
295  //UB add test on phidiff
296  float SCl_phi = xmeas.phi();
297  float localDphi = SCl_phi-hitPos.phi();
298  if(localDphi>CLHEP::pi)localDphi-=(2*CLHEP::pi);
299  if(localDphi<-CLHEP::pi)localDphi+=(2*CLHEP::pi);
300  if(std::abs(localDphi)>2.5)continue;
301 
302  phi1 = hitPos.phi();
303  dphi1 = hitPos.phi() - tsos1.globalPosition().phi();
304  rz1 = hitPos.perp();
305  drz1 = hitPos.perp() - tsos1.globalPosition().perp();
306  if (id.subdetId()%2==1) {
307  drz1 = hitPos.z() - tsos1.globalPosition().z();
308  rz1 = hitPos.z();
309  }
310 
311  // now second Hit
312  it++;
313  DetId id2=(*it).geographicalId();
314  const GeomDet *geomdet2=pDD->idToDet((*it).geographicalId());
316 
317  // compute the z vertex from the cluster point and the found pixel hit
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());
322  r1diff=sqrt(r1diff);
323  double r2diff = (xmeas.x()-pxHit1x)*(xmeas.x()-pxHit1x) + (xmeas.y()-pxHit1y)*(xmeas.y()-pxHit1y);
324  r2diff=sqrt(r2diff);
325  double zVertexPred = pxHit1z - r1diff*(xmeas.z()-pxHit1z)/r2diff;
326 
327  GlobalPoint vertexPred(vprim.x(),vprim.y(),zVertexPred);
328 
329  FreeTrajectoryState fts2 = myFTS(&(*theMagField),hitPos,vertexPred,energy, charge);
330  tsos2 = prop2ndLayer->propagate(fts2,geomdet2->surface()) ;
331 
332  if (tsos2.isValid()) {
333  LocalPoint lp2=(*it).localPosition();
334  GlobalPoint hitPos2=geomdet2->surface().toGlobal(lp2);
335  phi2 = hitPos2.phi();
336  dphi2 = hitPos2.phi() - tsos2.globalPosition().phi();
337  rz2 = hitPos2.perp();
338  drz2 = hitPos2.perp() - tsos2.globalPosition().perp();
339  if (id2.subdetId()%2==1) {
340  rz2 = hitPos2.z();
341  drz2 = hitPos2.z() - tsos2.globalPosition().z();
342  }
343  }
344 
345  }
346 
347  // fill the tree and histos
348 
349  histpt_->Fill(t.globalMomentum().perp());
350  histetclu_->Fill(theClus->energy()*sin(2.*atan(exp(-theClus->position().eta()))));
351  histeta_->Fill(t.globalMomentum().eta());
352  histetaclu_->Fill(theClus->position().eta());
353  histq_->Fill((*MyS).getCharge());
354  histeoverp_->Fill(theClus->energy()/t.globalMomentum().mag());
355 
356  if (is<10) {
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())));
361  seedMomentum[is] = t.globalMomentum().mag();
362  seedEta[is] = t.globalMomentum().eta();
363  seedPhi[is] = t.globalMomentum().phi();
364  seedPt[is] = t.globalMomentum().perp();
365  seedQ[is] = (*MyS).getCharge();
366  seedSubdet1[is] = id1.subdetId();
367  switch (seedSubdet1[is]) {
368  case 1:
369  {
370  PXBDetId pxbid1( id1.rawId() );
371  seedLayer1[is] = pxbid1.layer();
372  seedSide1[is] = 0;
373  break;
374  }
375  case 2:
376  {
377  PXFDetId pxfid1( id1.rawId() );
378  seedLayer1[is] = pxfid1.disk();
379  seedSide1[is] = pxfid1.side();
380  break;
381  }
382  case 3:
383  {
384  TIBDetId tibid1( id1.rawId() );
385  seedLayer1[is] = tibid1.layer();
386  seedSide1[is] = 0;
387  break;
388  }
389  case 4:
390  {
391  TIDDetId tidid1( id1.rawId() );
392  seedLayer1[is] = tidid1.wheel();
393  seedSide1[is] = tidid1.side();
394  break;
395  }
396  case 5:
397  {
398  TOBDetId tobid1( id1.rawId() );
399  seedLayer1[is] = tobid1.layer();
400  seedSide1[is] = 0;
401  break;
402  }
403  case 6:
404  {
405  TECDetId tecid1( id1.rawId() );
406  seedLayer1[is] = tecid1.wheel();
407  seedSide1[is] = tecid1.side();
408  break;
409  }
410  }
411  seedPhi1[is] = phi1;
412  seedRz1[is] = rz1;
413  seedDphi1[is] = dphi1;
414  seedDrz1[is] = drz1;
415  seedSubdet2[is] = id2.subdetId();
416  switch (seedSubdet2[is]) {
417  case 1:
418  {
419  PXBDetId pxbid2( id2.rawId() );
420  seedLayer2[is] = pxbid2.layer();
421  seedSide2[is] = 0;
422  break;
423  }
424  case 2:
425  {
426  PXFDetId pxfid2( id2.rawId() );
427  seedLayer2[is] = pxfid2.disk();
428  seedSide2[is] = pxfid2.side();
429  break;
430  }
431  case 3:
432  {
433  TIBDetId tibid2( id2.rawId() );
434  seedLayer2[is] = tibid2.layer();
435  seedSide2[is] = 0;
436  break;
437  }
438  case 4:
439  {
440  TIDDetId tidid2( id2.rawId() );
441  seedLayer2[is] = tidid2.wheel();
442  seedSide2[is] = tidid2.side();
443  break;
444  }
445  case 5:
446  {
447  TOBDetId tobid2( id2.rawId() );
448  seedLayer2[is] = tobid2.layer();
449  seedSide2[is] = 0;
450  break;
451  }
452  case 6:
453  {
454  TECDetId tecid2( id2.rawId() );
455  seedLayer2[is] = tecid2.wheel();
456  seedSide2[is] = tecid2.side();
457  break;
458  }
459  }
460  seedDphi2[is] = dphi2;
461  seedDrz2[is] = drz2;
462  seedPhi2[is] = phi2;
463  seedRz2[is] = rz2;
464  }
465 
466  is++;
467 
468  }
469 
470  histnbseeds_->Fill(elSeeds.product()->size());
471 
472  // get input clusters
473 
475  //CC to be changed according to supercluster input
476  e.getByLabel("correctedHybridSuperClusters", clusters);
477  histnbclus_->Fill(clusters.product()->size());
478  if (clusters.product()->size()>0) histnrseeds_->Fill(elSeeds.product()->size());
479  // get MC information
480 
482  // this one is empty branch in current test files
483  //e.getByLabel("VtxSmeared", "", HepMCEvt);
484  //e.getByLabel("source", "", HepMCEvt);
485  e.getByLabel("generator", "", HepMCEvt);
486 
487  const HepMC::GenEvent* MCEvt = HepMCEvt->GetEvent();
488  HepMC::GenParticle* genPc=0;
489  HepMC::FourVector pAssSim;
490  int ip=0;
491  for (HepMC::GenEvent::particle_const_iterator partIter = MCEvt->particles_begin();
492  partIter != MCEvt->particles_end(); ++partIter) {
493 
494  for (HepMC::GenEvent::vertex_const_iterator vertIter = MCEvt->vertices_begin();
495  vertIter != MCEvt->vertices_end(); ++vertIter) {
496 
497  // CLHEP::HepLorentzVector creation = (*partIter)->CreationVertex();
498  HepMC::GenVertex * creation = (*partIter)->production_vertex();
499  // CLHEP::HepLorentzVector momentum = (*partIter)->Momentum();
500  HepMC::FourVector momentum = (*partIter)->momentum();
501  // HepPDT::ParticleID id = (*partIter)->particleID(); // electrons and positrons are 11 and -11
502  int id = (*partIter)->pdg_id(); // electrons and positrons are 11 and -11
503  LogDebug("") << "MC particle id " << id << ", creationVertex " << (*creation) << " cm, initialMomentum " << momentum.rho() << " GeV/c" << std::endl;
504 
505  if (id == 11 || id == -11) {
506 
507  // single primary electrons or electrons from Zs or Ws
508  HepMC::GenParticle* mother = 0;
509  if ( (*partIter)->production_vertex() ) {
510  if ( (*partIter)->production_vertex()->particles_begin(HepMC::parents) !=
511  (*partIter)->production_vertex()->particles_end(HepMC::parents))
512  mother = *((*partIter)->production_vertex()->particles_begin(HepMC::parents));
513  }
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)))) {
517  genPc=(*partIter);
518  pAssSim = genPc->momentum();
519 
520  // EWK fiducial
521  //if (pAssSim.perp()> 100. || std::abs(pAssSim.eta())> 2.5) continue;
522  //if (pAssSim.perp()< 20. || (std::abs(pAssSim.eta())> 1.4442 && std::abs(pAssSim.eta())< 1.56) || std::abs(pAssSim.eta())> 2.5) continue;
523  // reconstruction fiducial
524  //if (pAssSim.perp()< 5. || std::abs(pAssSim.eta())> 2.5) continue;
525  if (std::abs(pAssSim.eta())> 2.5) continue;
526 
527  histptMC_->Fill(pAssSim.perp());
528  histetaMC_->Fill(pAssSim.eta());
529  histeMC_->Fill(pAssSim.rho());
530 
531  // looking for the best matching gsf electron
532  bool okSeedFound = false;
533  double seedOkRatio = 999999.;
534 
535  // find best matched seed
536  reco::ElectronSeed bestElectronSeed;
537  for( ElectronSeedCollection::const_iterator gsfIter= (*elSeeds).begin(); gsfIter != (*elSeeds).end(); ++gsfIter) {
538 
539  range r=gsfIter->recHits();
540  const GeomDet *det=0;
541  for (TrackingRecHitCollection::const_iterator rhits=r.first; rhits!=r.second; rhits++) det = pDD->idToDet(((*rhits)).geographicalId());
542  TrajectoryStateOnSurface t= transformer_.transientState(gsfIter->startingState(), &(det->surface()), &(*theMagField));
543 
544  float eta = t.globalMomentum().eta();
545  float phi = t.globalMomentum().phi();
546  float p = t.globalMomentum().mag();
547  double dphi = phi-pAssSim.phi();
548  if (std::abs(dphi)>CLHEP::pi)
549  dphi = dphi < 0? (CLHEP::twopi) + dphi : dphi - CLHEP::twopi;
550  double deltaR = sqrt(std::pow((eta-pAssSim.eta()),2) + std::pow(dphi,2));
551  if ( deltaR < 0.15 ){
552 // if ( deltaR < 0.3 ){
553  //if ( (genPc->pdg_id() == 11) && (gsfIter->charge() < 0.) || (genPc->pdg_id() == -11) &&
554  //(gsfIter->charge() > 0.) ){
555  double tmpSeedRatio = p/pAssSim.t();
556  if ( std::abs(tmpSeedRatio-1) < std::abs(seedOkRatio-1) ) {
557  seedOkRatio = tmpSeedRatio;
558  bestElectronSeed=*gsfIter;
559  okSeedFound = true;
560  }
561  //}
562  }
563  } // loop over rec ele to look for the best one
564 
565  // analysis when the mc track is found
566  if (okSeedFound){
567 
568  histptMCmatched_->Fill(pAssSim.perp());
569  histetaMCmatched_->Fill(pAssSim.eta());
570  histeMCmatched_->Fill(pAssSim.rho());
571  if (ip<10) {
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.);
577  }
578  }
579 
580  // efficiency for ecal driven only
581  okSeedFound = false;
582  seedOkRatio = 999999.;
583 
584  // find best matched seed
585  for( ElectronSeedCollection::const_iterator gsfIter= (*elSeeds).begin(); gsfIter != (*elSeeds).end(); ++gsfIter) {
586 
587  range r=gsfIter->recHits();
588  const GeomDet *det=0;
589  for (TrackingRecHitCollection::const_iterator rhits=r.first; rhits!=r.second; rhits++) det = pDD->idToDet(((*rhits)).geographicalId());
590  TrajectoryStateOnSurface t= transformer_.transientState(gsfIter->startingState(), &(det->surface()), &(*theMagField));
591 
592  float eta = t.globalMomentum().eta();
593  float phi = t.globalMomentum().phi();
594  float p = t.globalMomentum().mag();
595  double dphi = phi-pAssSim.phi();
596  if (std::abs(dphi)>CLHEP::pi)
597  dphi = dphi < 0? (CLHEP::twopi) + dphi : dphi - CLHEP::twopi;
598  double deltaR = sqrt(std::pow((eta-pAssSim.eta()),2) + std::pow(dphi,2));
599  if (gsfIter->isEcalDriven()) {
600  if ( deltaR < 0.15 ){
601 // if ( deltaR < 0.3 ){
602  //if ( (genPc->pdg_id() == 11) && (gsfIter->charge() < 0.) || (genPc->pdg_id() == -11) &&
603  //(gsfIter->charge() > 0.) ){
604  double tmpSeedRatio = p/pAssSim.t();
605  if ( std::abs(tmpSeedRatio-1) < std::abs(seedOkRatio-1) ) {
606  seedOkRatio = tmpSeedRatio;
607  bestElectronSeed=*gsfIter;
608  okSeedFound = true;
609  }
610  //}
611  }
612  } // end if ecal driven
613  } // loop over rec ele to look for the best one
614 
615  // analysis when the mc track is found
616  if (okSeedFound){
617 
618  histecaldrivenptMCmatched_->Fill(pAssSim.perp());
619  histecaldrivenetaMCmatched_->Fill(pAssSim.eta());
620  histecaldriveneMCmatched_->Fill(pAssSim.rho());
621  }
622 
623  // efficiency for tracker driven only
624  okSeedFound = false;
625  seedOkRatio = 999999.;
626 
627  // find best matched seed
628  for( ElectronSeedCollection::const_iterator gsfIter= (*elSeeds).begin(); gsfIter != (*elSeeds).end(); ++gsfIter) {
629 
630  range r=gsfIter->recHits();
631  const GeomDet *det=0;
632  for (TrackingRecHitCollection::const_iterator rhits=r.first; rhits!=r.second; rhits++) det = pDD->idToDet(((*rhits)).geographicalId());
633  TrajectoryStateOnSurface t= transformer_.transientState(gsfIter->startingState(), &(det->surface()), &(*theMagField));
634 
635  float eta = t.globalMomentum().eta();
636  float phi = t.globalMomentum().phi();
637  float p = t.globalMomentum().mag();
638  double dphi = phi-pAssSim.phi();
639  if (std::abs(dphi)>CLHEP::pi)
640  dphi = dphi < 0? (CLHEP::twopi) + dphi : dphi - CLHEP::twopi;
641  double deltaR = sqrt(std::pow((eta-pAssSim.eta()),2) + std::pow(dphi,2));
642  if (gsfIter->isTrackerDriven()) {
643  if ( deltaR < 0.15 ){
644 // if ( deltaR < 0.3 ){
645  //if ( (genPc->pdg_id() == 11) && (gsfIter->charge() < 0.) || (genPc->pdg_id() == -11) &&
646  //(gsfIter->charge() > 0.) ){
647  double tmpSeedRatio = p/pAssSim.t();
648  if ( std::abs(tmpSeedRatio-1) < std::abs(seedOkRatio-1) ) {
649  seedOkRatio = tmpSeedRatio;
650  bestElectronSeed=*gsfIter;
651  okSeedFound = true;
652  }
653  //}
654  }
655  } // end if ecal driven
656  } // loop over rec ele to look for the best one
657 
658  // analysis when the mc track is found
659  if (okSeedFound){
660 
661  histtrackerdrivenptMCmatched_->Fill(pAssSim.perp());
662  histtrackerdrivenetaMCmatched_->Fill(pAssSim.eta());
663  histtrackerdriveneMCmatched_->Fill(pAssSim.rho());
664  }
665 
666  } // end if mother W or Z
667 
668  } // end if gen part is electron
669 
670  } // end loop on vertices
671 
672  ip++;
673 
674  } // end loop on gen particles
675 
676  //tree_->Fill();
677 
678 }
679 
680 
#define LogDebug(id)
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:78
T getParameter(std::string const &) const
TPRegexp parents
Definition: eve_filter.cc:24
T perp() const
Definition: PV3DBase.h:66
unsigned int layer() const
layer id
Definition: TOBDetId.h:39
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:49
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Geom::Phi< T > phi() const
Definition: PV3DBase.h:63
T y() const
Definition: PV3DBase.h:57
bool isNull() const
Checks for null.
Definition: RefToBase.h:270
#define abs(x)
Definition: mlp_lapack.h:159
GlobalPoint globalPosition() const
bool getByType(Handle< PROD > &result) const
Definition: Event.h:397
Exp< T >::type exp(const T &t)
Definition: Exp.h:22
T eta() const
double charge(const std::vector< uint8_t > &Ampls)
virtual void analyze(const edm::Event &, const edm::EventSetup &)
unsigned int layer() const
layer id
Definition: PXBDetId.h:35
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
T mag() const
Definition: PV3DBase.h:61
recHitContainer::const_iterator const_iterator
T sqrt(T t)
Definition: SSEVec.h:28
T z() const
Definition: PV3DBase.h:58
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:355
GlobalVector momentum() const
unsigned int disk() const
disk id
Definition: PXFDetId.h:43
tuple conf
Definition: dbtoconf.py:185
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
virtual TrajectoryStateOnSurface propagate(const TrajectoryStateOnSurface &tsos, const Plane &plane) const
Definition: DetId.h:20
GlobalPoint position() const
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
unsigned int wheel() const
wheel id
Definition: TECDetId.h:52
unsigned int layer() const
layer id
Definition: TIBDetId.h:41
T eta() const
Definition: PV3DBase.h:70
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:56
ElectronSeedAnalyzer(const edm::ParameterSet &conf)
virtual const BoundPlane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
unsigned int wheel() const
wheel id
Definition: TIDDetId.h:50
Definition: DDAxes.h:10