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  // get beam spot
193  edm::Handle<reco::BeamSpot> theBeamSpot;
194  e.getByLabel(beamSpot_, theBeamSpot);
195 
196  // get seeds
197 
199  e.getByLabel(inputCollection_, elSeeds);
200  edm::LogInfo("") << "\n\n =================> Treating event " << e.id() << " Number of seeds "
201  << elSeeds.product()->size();
202  int is = 0;
203 
204  float mass = .000511; // electron propagation
205  PropagatorWithMaterial *prop1stLayer = new PropagatorWithMaterial(oppositeToMomentum, mass, &(*theMagField));
206  PropagatorWithMaterial *prop2ndLayer = new PropagatorWithMaterial(alongMomentum, mass, &(*theMagField));
207 
208  float dphi1 = 0., dphi2 = 0., drz1 = 0., drz2 = 0.;
209  float phi1 = 0., phi2 = 0., rz1 = 0., rz2 = 0.;
210 
211  for (ElectronSeedCollection::const_iterator MyS = (*elSeeds).begin(); MyS != (*elSeeds).end(); ++MyS) {
212  LogDebug("") << "\nSeed nr " << is << ": ";
213  const TrajectorySeed::RecHitRange r = MyS->recHits();
214  LogDebug("") << " Number of RecHits= " << (*MyS).nHits();
215  const GeomDet *det1 = nullptr;
216  const GeomDet *det2 = nullptr;
217 
218  auto it = r.begin();
219  DetId id1 = (*it).geographicalId();
220  det1 = pDD->idToDet(id1);
221  LogDebug("") << " First hit local x,y,z " << (*it).localPosition() << " det " << id1.det() << " subdet "
222  << id1.subdetId();
223  LogDebug("") << " First hit global " << det1->toGlobal((*it).localPosition());
224  //std::cout <<" First hit local x,y,z "<<(*it).localPosition()<<" det "<<id1.det()<<" subdet "<<id1.subdetId()<< std::endl;
225  //std::cout <<" First hit global "<<det1->toGlobal((*it).localPosition())<< std::endl;
226  it++;
227  DetId id2 = (*it).geographicalId();
228  det2 = pDD->idToDet(id2);
229  LogDebug("") << " Second hit local x,y,z " << (*it).localPosition() << " det " << id2.det() << " subdet "
230  << id2.subdetId();
231  LogDebug("") << " Second hit global " << det2->toGlobal((*it).localPosition());
232  //std::cout <<" Second hit local x,y,z "<<(*it).localPosition()<<" det "<<id2.det()<<" subdet "<<id2.subdetId()<< std::endl;
233  //std::cout <<" Second hit global "<<det2->toGlobal((*it).localPosition()) << std::endl;
234 
235  // state on last det
236  const GeomDet *det = nullptr;
237  for (auto const &recHit : r) {
238  det = pDD->idToDet(recHit.geographicalId());
239  }
241  trajectoryStateTransform::transientState((*MyS).startingState(), &(det->surface()), &(*theMagField));
242 
243  // debug
244 
245  LogDebug("") << " ElectronSeed outermost state position: " << t.globalPosition();
246  LogDebug("") << " ElectronSeed outermost state momentum: " << t.globalMomentum();
247  edm::RefToBase<CaloCluster> caloCluster = (*MyS).caloCluster();
248  if (caloCluster.isNull())
249  continue;
251  LogDebug("") << " ElectronSeed superCluster energy: " << theClus->energy() << ", position: " << theClus->position();
252  LogDebug("") << " ElectronSeed outermost state Pt: " << t.globalMomentum().perp();
253  LogDebug("") << " ElectronSeed supercluster Et: "
254  << theClus->energy() * sin(2. * atan(exp(-theClus->position().eta())));
255  LogDebug("") << " ElectronSeed outermost momentum direction eta: " << t.globalMomentum().eta();
256  LogDebug("") << " ElectronSeed supercluster eta: " << theClus->position().eta();
257  LogDebug("") << " ElectronSeed seed charge: " << (*MyS).getCharge();
258  LogDebug("") << " ElectronSeed E/p: " << theClus->energy() / t.globalMomentum().mag();
259 
260  // retreive SC and compute distances between hit position and prediction the same
261  // way as in the PixelHitMatcher
262 
263  // inputs are charge, cluster position, vertex position, cluster energy and B field
264  int charge = int((*MyS).getCharge());
265  GlobalPoint xmeas(theClus->position().x(), theClus->position().y(), theClus->position().z());
266  GlobalPoint vprim(theBeamSpot->position().x(), theBeamSpot->position().y(), theBeamSpot->position().z());
267  float energy = theClus->energy();
268 
269  auto fts = trackingTools::ftsFromVertexToPoint(*theMagField, xmeas, vprim, energy, charge);
270  //std::cout << "[PixelHitMatcher::compatibleSeeds] fts position, momentum " <<
271  // fts.parameters().position() << " " << fts.parameters().momentum() << std::endl;
272 
274  TrajectoryStateOnSurface tsos(fts, *bpb(fts.position(), fts.momentum()));
275 
276  // TrajectorySeed::range r=(*seeds.product())[i].recHits();
277  // TrajectorySeed::range r=(*seeds)[i].recHits();
278 
279  // first Hit
280  it = r.begin();
281  DetId id = (*it).geographicalId();
282  const GeomDet *geomdet = pDD->idToDet((*it).geographicalId());
283  LocalPoint lp = (*it).localPosition();
284  GlobalPoint hitPos = geomdet->surface().toGlobal(lp);
285 
287  tsos1 = prop1stLayer->propagate(tsos, geomdet->surface());
288 
289  if (tsos1.isValid()) {
290  //UB add test on phidiff
291  float SCl_phi = xmeas.phi();
292  float localDphi = SCl_phi - hitPos.phi();
293  if (localDphi > CLHEP::pi)
294  localDphi -= (2 * CLHEP::pi);
295  if (localDphi < -CLHEP::pi)
296  localDphi += (2 * CLHEP::pi);
297  if (std::abs(localDphi) > 2.5)
298  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  auto fts2 = trackingTools::ftsFromVertexToPoint(*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  // fill the tree and histos
345 
346  histpt_->Fill(t.globalMomentum().perp());
347  histetclu_->Fill(theClus->energy() * sin(2. * atan(exp(-theClus->position().eta()))));
348  histeta_->Fill(t.globalMomentum().eta());
349  histetaclu_->Fill(theClus->position().eta());
350  histq_->Fill((*MyS).getCharge());
351  histeoverp_->Fill(theClus->energy() / t.globalMomentum().mag());
352 
353  if (is < 10) {
354  superclusterEnergy[is] = theClus->energy();
355  superclusterEta[is] = theClus->position().eta();
356  superclusterPhi[is] = theClus->position().phi();
357  superclusterEt[is] = theClus->energy() * sin(2. * atan(exp(-theClus->position().eta())));
358  seedMomentum[is] = t.globalMomentum().mag();
359  seedEta[is] = t.globalMomentum().eta();
360  seedPhi[is] = t.globalMomentum().phi();
361  seedPt[is] = t.globalMomentum().perp();
362  seedQ[is] = (*MyS).getCharge();
363  seedSubdet1[is] = id1.subdetId();
364  seedLayer1[is] = tTopo->layer(id1);
365  seedSide1[is] = tTopo->side(id1);
366  seedPhi1[is] = phi1;
367  seedRz1[is] = rz1;
368  seedDphi1[is] = dphi1;
369  seedDrz1[is] = drz1;
370  seedSubdet2[is] = id2.subdetId();
371  seedLayer2[is] = tTopo->layer(id2);
372  seedSide2[is] = tTopo->side(id2);
373  seedDphi2[is] = dphi2;
374  seedDrz2[is] = drz2;
375  seedPhi2[is] = phi2;
376  seedRz2[is] = rz2;
377  }
378 
379  is++;
380  }
381 
382  histnbseeds_->Fill(elSeeds.product()->size());
383 
384  // get input clusters
385 
387  //CC to be changed according to supercluster input
388  e.getByLabel("correctedHybridSuperClusters", clusters);
389  histnbclus_->Fill(clusters.product()->size());
390  if (!clusters.product()->empty())
391  histnrseeds_->Fill(elSeeds.product()->size());
392  // get MC information
393 
395  // this one is empty branch in current test files
396  //e.getByLabel("generatorSmeared", "", HepMCEvt);
397  //e.getByLabel("source", "", HepMCEvt);
398  e.getByLabel("generatorSmeared", "", HepMCEvt);
399 
400  const HepMC::GenEvent *MCEvt = HepMCEvt->GetEvent();
401  HepMC::GenParticle *genPc = nullptr;
402  HepMC::FourVector pAssSim;
403  int ip = 0;
404  for (HepMC::GenEvent::particle_const_iterator partIter = MCEvt->particles_begin(); partIter != MCEvt->particles_end();
405  ++partIter) {
406  for (HepMC::GenEvent::vertex_const_iterator vertIter = MCEvt->vertices_begin(); vertIter != MCEvt->vertices_end();
407  ++vertIter) {
408  // CLHEP::HepLorentzVector creation = (*partIter)->CreationVertex();
409  HepMC::GenVertex *creation = (*partIter)->production_vertex();
410  // CLHEP::HepLorentzVector momentum = (*partIter)->Momentum();
411  HepMC::FourVector momentum = (*partIter)->momentum();
412  // HepPDT::ParticleID id = (*partIter)->particleID(); // electrons and positrons are 11 and -11
413  int id = (*partIter)->pdg_id(); // electrons and positrons are 11 and -11
414  LogDebug("") << "MC particle id " << id << ", creationVertex " << (*creation) << " cm, initialMomentum "
415  << momentum.rho() << " GeV/c" << std::endl;
416 
417  if (id == 11 || id == -11) {
418  // single primary electrons or electrons from Zs or Ws
419  HepMC::GenParticle *mother = nullptr;
420  if ((*partIter)->production_vertex()) {
421  if ((*partIter)->production_vertex()->particles_begin(HepMC::parents) !=
422  (*partIter)->production_vertex()->particles_end(HepMC::parents))
423  mother = *((*partIter)->production_vertex()->particles_begin(HepMC::parents));
424  }
425  if (((mother == nullptr) || ((mother != nullptr) && (mother->pdg_id() == 23)) ||
426  ((mother != nullptr) && (mother->pdg_id() == 32)) ||
427  ((mother != nullptr) && (std::abs(mother->pdg_id()) == 24)))) {
428  genPc = (*partIter);
429  pAssSim = genPc->momentum();
430 
431  // EWK fiducial
432  //if (pAssSim.perp()> 100. || std::abs(pAssSim.eta())> 2.5) continue;
433  //if (pAssSim.perp()< 20. || (std::abs(pAssSim.eta())> 1.4442 && std::abs(pAssSim.eta())< 1.56) || std::abs(pAssSim.eta())> 2.5) continue;
434  // reconstruction fiducial
435  //if (pAssSim.perp()< 5. || std::abs(pAssSim.eta())> 2.5) continue;
436  if (std::abs(pAssSim.eta()) > 2.5)
437  continue;
438 
439  histptMC_->Fill(pAssSim.perp());
440  histetaMC_->Fill(pAssSim.eta());
441  histeMC_->Fill(pAssSim.rho());
442 
443  // looking for the best matching gsf electron
444  bool okSeedFound = false;
445  double seedOkRatio = 999999.;
446 
447  // find best matched seed
448  reco::ElectronSeed bestElectronSeed;
449  for (ElectronSeedCollection::const_iterator gsfIter = (*elSeeds).begin(); gsfIter != (*elSeeds).end();
450  ++gsfIter) {
451  const GeomDet *det = nullptr;
452  for (auto const &recHit : gsfIter->recHits()) {
453  det = pDD->idToDet(recHit.geographicalId());
454  }
456  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  histptMCmatched_->Fill(pAssSim.perp());
482  histetaMCmatched_->Fill(pAssSim.eta());
483  histeMCmatched_->Fill(pAssSim.rho());
484  if (ip < 10) {
485  mcEnergy[ip] = pAssSim.rho();
486  mcEta[ip] = pAssSim.eta();
487  mcPhi[ip] = pAssSim.phi();
488  mcPt[ip] = pAssSim.perp();
489  mcQ[ip] = ((id == 11) ? -1. : +1.);
490  }
491  }
492 
493  // efficiency for ecal driven only
494  okSeedFound = false;
495  seedOkRatio = 999999.;
496 
497  // find best matched seed
498  for (ElectronSeedCollection::const_iterator gsfIter = (*elSeeds).begin(); gsfIter != (*elSeeds).end();
499  ++gsfIter) {
500  const GeomDet *det = nullptr;
501  for (auto const &recHit : gsfIter->recHits()) {
502  det = pDD->idToDet(recHit.geographicalId());
503  }
505  trajectoryStateTransform::transientState(gsfIter->startingState(), &(det->surface()), &(*theMagField));
506 
507  float eta = t.globalMomentum().eta();
508  float phi = t.globalMomentum().phi();
509  float p = t.globalMomentum().mag();
510  double dphi = phi - pAssSim.phi();
511  if (std::abs(dphi) > CLHEP::pi)
512  dphi = dphi < 0 ? (CLHEP::twopi) + dphi : dphi - CLHEP::twopi;
513  double deltaR = sqrt(std::pow((eta - pAssSim.eta()), 2) + std::pow(dphi, 2));
514  if (gsfIter->isEcalDriven()) {
515  if (deltaR < 0.15) {
516  // if ( deltaR < 0.3 ){
517  //if ( (genPc->pdg_id() == 11) && (gsfIter->charge() < 0.) || (genPc->pdg_id() == -11) &&
518  //(gsfIter->charge() > 0.) ){
519  double tmpSeedRatio = p / pAssSim.t();
520  if (std::abs(tmpSeedRatio - 1) < std::abs(seedOkRatio - 1)) {
521  seedOkRatio = tmpSeedRatio;
522  bestElectronSeed = *gsfIter;
523  okSeedFound = true;
524  }
525  //}
526  }
527  } // end if ecal driven
528  } // loop over rec ele to look for the best one
529 
530  // analysis when the mc track is found
531  if (okSeedFound) {
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();
543  ++gsfIter) {
544  const GeomDet *det = nullptr;
545  for (auto const &recHit : gsfIter->recHits()) {
546  det = pDD->idToDet(recHit.geographicalId());
547  }
549  trajectoryStateTransform::transientState(gsfIter->startingState(), &(det->surface()), &(*theMagField));
550 
551  float eta = t.globalMomentum().eta();
552  float phi = t.globalMomentum().phi();
553  float p = t.globalMomentum().mag();
554  double dphi = phi - pAssSim.phi();
555  if (std::abs(dphi) > CLHEP::pi)
556  dphi = dphi < 0 ? (CLHEP::twopi) + dphi : dphi - CLHEP::twopi;
557  double deltaR = sqrt(std::pow((eta - pAssSim.eta()), 2) + std::pow(dphi, 2));
558  if (gsfIter->isTrackerDriven()) {
559  if (deltaR < 0.15) {
560  // if ( deltaR < 0.3 ){
561  //if ( (genPc->pdg_id() == 11) && (gsfIter->charge() < 0.) || (genPc->pdg_id() == -11) &&
562  //(gsfIter->charge() > 0.) ){
563  double tmpSeedRatio = p / pAssSim.t();
564  if (std::abs(tmpSeedRatio - 1) < std::abs(seedOkRatio - 1)) {
565  seedOkRatio = tmpSeedRatio;
566  bestElectronSeed = *gsfIter;
567  okSeedFound = true;
568  }
569  //}
570  }
571  } // end if ecal driven
572  } // loop over rec ele to look for the best one
573 
574  // analysis when the mc track is found
575  if (okSeedFound) {
576  histtrackerdrivenptMCmatched_->Fill(pAssSim.perp());
577  histtrackerdrivenetaMCmatched_->Fill(pAssSim.eta());
578  histtrackerdriveneMCmatched_->Fill(pAssSim.rho());
579  }
580 
581  } // end if mother W or Z
582 
583  } // end if gen part is electron
584 
585  } // end loop on vertices
586 
587  ip++;
588 
589  } // end loop on gen particles
590 
591  //tree_->Fill();
592 }
ElectronSeedAnalyzer::beginJob
void beginJob() override
Definition: ElectronSeedAnalyzer.cc:62
TrackerGeometry::idToDet
const TrackerGeomDet * idToDet(DetId) const override
Definition: TrackerGeometry.cc:193
edm::RefToBase::isNull
bool isNull() const
Checks for null.
Definition: RefToBase.h:295
ElectronSeedAnalyzer::histecaldrivenetaMCmatched_
TH1F * histecaldrivenetaMCmatched_
Definition: ElectronSeedAnalyzer.h:70
ElectronSeedAnalyzer::superclusterEt
float superclusterEt[10]
Definition: ElectronSeedAnalyzer.h:47
TrackerTopology::side
unsigned int side(const DetId &id) const
Definition: TrackerTopology.cc:28
ElectronSeedAnalyzer::histtrackerdriveneMCmatched_
TH1F * histtrackerdriveneMCmatched_
Definition: ElectronSeedAnalyzer.h:57
FreeTrajectoryState.h
MessageLogger.h
ElectronSeedAnalyzer::histnbseeds_
TH1I * histnbseeds_
Definition: ElectronSeedAnalyzer.h:77
GeomDet
Definition: GeomDet.h:27
ElectronSeedAnalyzer::histecaldriveneMCmatched_
TH1F * histecaldriveneMCmatched_
Definition: ElectronSeedAnalyzer.h:56
edm::Handle::product
T const * product() const
Definition: Handle.h:70
ESHandle.h
PropagatorWithMaterial::propagate
TrajectoryStateOnSurface propagate(STA const &state, SUR const &surface) const
Definition: Propagator.h:50
ElectronSeedAnalyzer::histfile_
TFile * histfile_
Definition: ElectronSeedAnalyzer.h:44
ElectronSeedAnalyzer::seedDrz1
float seedDrz1[10]
Definition: ElectronSeedAnalyzer.h:52
PV3DBase::x
T x() const
Definition: PV3DBase.h:59
edm
HLT enums.
Definition: AlignableModifier.h:19
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
globals_cff.id1
id1
Definition: globals_cff.py:33
TrajectoryStateOnSurface::globalPosition
GlobalPoint globalPosition() const
Definition: TrajectoryStateOnSurface.h:65
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89287
ElectronSeedAnalyzer::histpt_
TH1F * histpt_
Definition: ElectronSeedAnalyzer.h:60
ElectronSeedAnalyzer::histeta_
TH1F * histeta_
Definition: ElectronSeedAnalyzer.h:67
ElectronSeedAnalyzer::superclusterEta
float superclusterEta[10]
Definition: ElectronSeedAnalyzer.h:47
ElectronSeedAnalyzer::seedMomentum
float seedMomentum[10]
Definition: ElectronSeedAnalyzer.h:48
oppositeToMomentum
Definition: PropagationDirection.h:4
TrackerTopology::layer
unsigned int layer(const DetId &id) const
Definition: TrackerTopology.cc:47
TrackingRecHitFwd.h
ElectronSeedAnalyzer::histtrackerdrivenetaMCmatched_
TH1F * histtrackerdrivenetaMCmatched_
Definition: ElectronSeedAnalyzer.h:71
ElectronSeedAnalyzer::mcEta
float mcEta[10]
Definition: ElectronSeedAnalyzer.h:46
ElectronSeedAnalyzer::histeMCmatched_
TH1F * histeMCmatched_
Definition: ElectronSeedAnalyzer.h:55
EDAnalyzer.h
ElectronSeedAnalyzer::~ElectronSeedAnalyzer
~ElectronSeedAnalyzer() override
Definition: ElectronSeedAnalyzer.cc:173
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
ElectronSeedAnalyzer::seedSide2
int seedSide2[10]
Definition: ElectronSeedAnalyzer.h:51
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
ElectronSeedAnalyzer::histeffpt_
TH1F * histeffpt_
Definition: ElectronSeedAnalyzer.h:66
edm::Handle< reco::BeamSpot >
ElectronSeedAnalyzer::ElectronSeedAnalyzer
ElectronSeedAnalyzer(const edm::ParameterSet &conf)
Definition: ElectronSeedAnalyzer.cc:56
ElectronSeedAnalyzer::seedSubdet1
int seedSubdet1[10]
Definition: ElectronSeedAnalyzer.h:49
ElectronSeedAnalyzer::seedPhi2
float seedPhi2[10]
Definition: ElectronSeedAnalyzer.h:53
rpcPointValidation_cfi.recHit
recHit
Definition: rpcPointValidation_cfi.py:7
ElectronSeedAnalyzer::histeffeta_
TH1F * histeffeta_
Definition: ElectronSeedAnalyzer.h:73
HepMC::GenEvent
Definition: hepmc_rootio.cc:9
ElectronSeedAnalyzer::histtrackerdrivenptMCmatched_
TH1F * histtrackerdrivenptMCmatched_
Definition: ElectronSeedAnalyzer.h:64
ElectronSeedFwd.h
edm::Ref< SuperClusterCollection >
funct::sin
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
PV3DBase::z
T z() const
Definition: PV3DBase.h:61
IdealMagneticFieldRecord
Definition: IdealMagneticFieldRecord.h:11
DetId
Definition: DetId.h:17
GeometricSearchTracker.h
ElectronSeedAnalyzer::histnrseeds_
TH1I * histnrseeds_
Definition: ElectronSeedAnalyzer.h:76
ElectronSeedAnalyzer::histnbclus_
TH1I * histnbclus_
Definition: ElectronSeedAnalyzer.h:78
GeomDet::surface
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
TrajectoryStateOnSurface
Definition: TrajectoryStateOnSurface.h:16
ElectronSeedAnalyzer::endJob
void endJob() override
Definition: ElectronSeedAnalyzer.cc:125
MakerMacros.h
TrackerTopology.h
edm::Range
Definition: Range.h:11
PropagatorWithMaterial
Definition: PropagatorWithMaterial.h:25
reco::ElectronSeed
Definition: ElectronSeed.h:51
trackingTools::ftsFromVertexToPoint
FreeTrajectoryState ftsFromVertexToPoint(MagneticField const &magField, GlobalPoint const &xmeas, GlobalPoint const &xvert, float momentum, TrackCharge charge)
Definition: ftsFromVertexToPoint.cc:17
TrackerTopologyRcd.h
ElectronSeedAnalyzer::seedDphi1
float seedDphi1[10]
Definition: ElectronSeedAnalyzer.h:52
edm::EventSetup::get
T get() const
Definition: EventSetup.h:80
PTrajectoryStateOnDet.h
BeamSpot.h
ElectronSeedAnalyzer::seedLayer2
int seedLayer2[10]
Definition: ElectronSeedAnalyzer.h:50
PVValHelper::eta
Definition: PVValidationHelpers.h:69
TrackerDigiGeometryRecord
Definition: TrackerDigiGeometryRecord.h:15
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
Surface::toGlobal
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:79
IdealMagneticFieldRecord.h
edm::ESHandle< TrackerTopology >
HCALHighEnergyHPDFilter_cfi.energy
energy
Definition: HCALHighEnergyHPDFilter_cfi.py:5
ElectronSeedAnalyzer::mcPhi
float mcPhi[10]
Definition: ElectronSeedAnalyzer.h:46
ElectronSeedAnalyzer::seedPhi1
float seedPhi1[10]
Definition: ElectronSeedAnalyzer.h:53
reco::BeamSpot::position
const Point & position() const
position
Definition: BeamSpot.h:59
Point3DBase< float, GlobalTag >
ElectronSeedAnalyzer::seedPhi
float seedPhi[10]
Definition: ElectronSeedAnalyzer.h:48
PbPb_ZMuSkimMuonDPG_cff.deltaR
deltaR
Definition: PbPb_ZMuSkimMuonDPG_cff.py:63
ElectronSeedAnalyzer::histetaMC_
TH1F * histetaMC_
Definition: ElectronSeedAnalyzer.h:68
ElectronSeedAnalyzer::histeclu_
TH1F * histeclu_
Definition: ElectronSeedAnalyzer.h:59
bsc_activity_cfg.clusters
clusters
Definition: bsc_activity_cfg.py:36
ALCARECOTkAlJpsiMuMu_cff.charge
charge
Definition: ALCARECOTkAlJpsiMuMu_cff.py:47
TrackerDigiGeometryRecord.h
SiPixelRecHitCollection.h
ElectronSeedAnalyzer::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: ElectronSeedAnalyzer.cc:182
GeomDet::toGlobal
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:49
ElectronSeedAnalyzer::seedDrz2
float seedDrz2[10]
Definition: ElectronSeedAnalyzer.h:52
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:223
edm::ParameterSet
Definition: ParameterSet.h:47
ElectronSeedAnalyzer::histeMC_
TH1F * histeMC_
Definition: ElectronSeedAnalyzer.h:54
Event.h
PropagatorWithMaterial.h
ElectronSeedAnalyzer::tree_
TTree * tree_
Definition: ElectronSeedAnalyzer.h:45
ElectronSeedAnalyzer::histeoverp_
TH1F * histeoverp_
Definition: ElectronSeedAnalyzer.h:75
ElectronSeedAnalyzer::histecaldrivenptMCmatched_
TH1F * histecaldrivenptMCmatched_
Definition: ElectronSeedAnalyzer.h:63
ElectronSeedAnalyzer::mcEnergy
float mcEnergy[10]
Definition: ElectronSeedAnalyzer.h:46
ElectronSeedAnalyzer::histetaclu_
TH1F * histetaclu_
Definition: ElectronSeedAnalyzer.h:72
PV3DBase::y
T y() const
Definition: PV3DBase.h:60
createfilelist.int
int
Definition: createfilelist.py:10
trajectoryStateTransform::transientState
TrajectoryStateOnSurface transientState(const PTrajectoryStateOnDet &ts, const Surface *surface, const MagneticField *field)
Definition: TrajectoryStateTransform.cc:35
ElectronSeedAnalyzer::beamSpot_
edm::InputTag beamSpot_
Definition: ElectronSeedAnalyzer.h:81
BarrelDetLayer.h
ElectronSeedAnalyzer::histetaMCmatched_
TH1F * histetaMCmatched_
Definition: ElectronSeedAnalyzer.h:69
MagneticField.h
ElectronSeedAnalyzer::histetclu_
TH1F * histetclu_
Definition: ElectronSeedAnalyzer.h:65
edm::EventSetup
Definition: EventSetup.h:57
edm::RefToBase::castTo
REF castTo() const
Definition: RefToBase.h:257
edm::HepMCProduct::GetEvent
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:34
ftsFromVertexToPoint.h
get
#define get
ElectronSeedAnalyzer::histq_
TH1F * histq_
Definition: ElectronSeedAnalyzer.h:74
alignCSCRings.r
r
Definition: alignCSCRings.py:93
ElectronSeedAnalyzer::seedEta
float seedEta[10]
Definition: ElectronSeedAnalyzer.h:48
ElectronSeedAnalyzer::seedRz2
float seedRz2[10]
Definition: ElectronSeedAnalyzer.h:53
DDAxes::phi
ElectronSeedAnalyzer::seedRz1
float seedRz1[10]
Definition: ElectronSeedAnalyzer.h:53
ElectronSeedAnalyzer::mcQ
float mcQ[10]
Definition: ElectronSeedAnalyzer.h:46
GeomDet.h
GenParticle.GenParticle
GenParticle
Definition: GenParticle.py:18
std
Definition: JetResolutionObject.h:76
SuperClusterFwd.h
ElectronSeedAnalyzer::seedDphi2
float seedDphi2[10]
Definition: ElectronSeedAnalyzer.h:52
ElectronSeedAnalyzer::seedLayer1
int seedLayer1[10]
Definition: ElectronSeedAnalyzer.h:50
Frameworkfwd.h
ElectronSeedAnalyzer::seedPt
float seedPt[10]
Definition: ElectronSeedAnalyzer.h:48
ElectronSeedAnalyzer::seedSide1
int seedSide1[10]
Definition: ElectronSeedAnalyzer.h:51
PerpendicularBoundPlaneBuilder
Definition: PerpendicularBoundPlaneBuilder.h:11
SuperCluster.h
ForwardDetLayer.h
ElectronSeedAnalyzer::seedSubdet2
int seedSubdet2[10]
Definition: ElectronSeedAnalyzer.h:49
ElectronSeedAnalyzer::superclusterPhi
float superclusterPhi[10]
Definition: ElectronSeedAnalyzer.h:47
EgHLTOffHistBins_cfi.mass
mass
Definition: EgHLTOffHistBins_cfi.py:34
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::RefToBase< CaloCluster >
ElectronSeedAnalyzer::histptMC_
TH1F * histptMC_
Definition: ElectronSeedAnalyzer.h:61
funct::pow
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
PerpendicularBoundPlaneBuilder.h
ElectronSeedAnalyzer::mcPt
float mcPt[10]
Definition: ElectronSeedAnalyzer.h:46
pi
const Double_t pi
Definition: trackSplitPlot.h:36
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ElectronSeedAnalyzer::superclusterEnergy
float superclusterEnergy[10]
Definition: ElectronSeedAnalyzer.h:47
ElectronSeedAnalyzer::histptMCmatched_
TH1F * histptMCmatched_
Definition: ElectronSeedAnalyzer.h:62
TrackerTopologyRcd
Definition: TrackerTopologyRcd.h:10
ParameterSet.h
HepMCProduct.h
OwnVector.h
globals_cff.id2
id2
Definition: globals_cff.py:34
ElectronSeedAnalyzer::histp_
TH1F * histp_
Definition: ElectronSeedAnalyzer.h:58
JetChargeProducer_cfi.exp
exp
Definition: JetChargeProducer_cfi.py:6
parents
TPRegexp parents
Definition: eve_filter.cc:21
edm::Event
Definition: Event.h:73
ElectronSeedAnalyzer::inputCollection_
edm::InputTag inputCollection_
Definition: ElectronSeedAnalyzer.h:80
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
PV3DBase::perp
T perp() const
Definition: PV3DBase.h:69
ElectronSeedAnalyzer::seedQ
float seedQ[10]
Definition: ElectronSeedAnalyzer.h:48
edm::InputTag
Definition: InputTag.h:15
alongMomentum
Definition: PropagationDirection.h:4
PV3DBase::phi
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
TrajectoryStateOnSurface::isValid
bool isValid() const
Definition: TrajectoryStateOnSurface.h:54
ElectronSeed.h
ElectronSeedAnalyzer.h
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37