CMS 3D CMS Logo

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