CMS 3D CMS Logo

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