CMS 3D CMS Logo

SiStripElectronAnalyzer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: RecoEgamma/Examples
4 // Class : SiStripElectronAnalyzer
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: Jim Pivarski
10 // Created: Fri May 26 16:49:38 EDT 2006
11 //
12 
44 
45 #include "TBranch.h"
46 #include "TFile.h"
47 #include "TH1F.h"
48 #include "TNtuple.h"
49 #include "TTree.h"
50 
51 #include <memory>
52 #include <map>
53 #include <cmath>
54 
55 #define myMaxHits 1000
56 
58 public:
60  ~SiStripElectronAnalyzer() override;
61 
62  void analyze(const edm::Event&, const edm::EventSetup&) override;
63  void beginJob() override;
64  virtual void initNtuple(void);
65  void endJob(void) override;
66 
67 private:
68  double unwrapPhi(double phi) const {
69  while (phi > M_PI) {
70  phi -= 2. * M_PI;
71  }
72  while (phi < -M_PI) {
73  phi += 2. * M_PI;
74  }
75  return phi;
76  }
77 
78  // ----------member data ---------------------------
81 
83 
84  TFile* file_;
85  TH1F* numCand_;
92 
97 
98  TH1F* ptDiff;
99  TH1F* pDiff;
110 
114 
115  TTree* myTree_;
116 
122 
127 
131 
132  // errors in local coords
136 
140 
143 
144  // mono corresponds to "rphi" only hits
149 
153 
154  // errors in local coords
158 
162 
165 
166  // matched hits
171 
175 
176  // errors in local coords
180 
184 
187 
204 };
205 
208 
210  : topoToken_(esConsumes()), trackerToken_(esConsumes()) {
211  //now do what ever initialization is needed
212  fileName_ = iConfig.getParameter<std::string>("fileName");
213 
214  file_ = new TFile(fileName_.c_str(), "RECREATE");
215  numCand_ = new TH1F("numCandidates", "Number of candidates found", 10, -0.5, 9.5);
216  numElectrons_ = new TH1F("numElectrons", "Number of Electrons found", 10, -0.5, 9.5);
217  numSuperClusters_ = new TH1F("numSuperClusters", "Number of Ecal SuperClusters", 50, 0, 50);
218 
219  energySuperClusters_ = new TH1F("energySuperClusters", "Super Cluster Energy - all ", 200, 0, 2000.);
220  energySuperClustersEl_ = new TH1F("energySuperClustersEl", "Super Cluster Energy - Electron Cands ", 200, 0., 2000.);
221 
222  sizeSuperClusters_ = new TH1F("sizeSuperClusters", "Super Cluster Size - all ", 20, 0, 19);
223  sizeSuperClustersEl_ = new TH1F("sizeSuperClustersEl", "Super Cluster Size - Electron Cands ", 20, 0, 19);
224 
225  emaxSuperClusters_ = new TH1F("emaxSuperClusters", "Super Cluster Emax - all ", 200, 0, 2000.);
226  emaxSuperClustersEl_ = new TH1F("emaxSuperClustersEl", "Super Cluster Emax - Electron Cands ", 200, 0, 2000.);
227 
228  phiWidthSuperClusters_ = new TH1F("phiWidthSuperClusters", "Super Cluster Width - all ", 20, 0., 0.05);
229  phiWidthSuperClustersEl_ = new TH1F("phiWidthSuperClustersEl", "Super Cluster Width - Electron Cands ", 20, 0., 0.05);
230 
231  ptDiff = new TH1F("ptDiff", " ptDiff ", 20, -10., 10.);
232  pDiff = new TH1F("pDiff", " pDiff ", 100, -50., 50.);
233 
234  pElectronFailed = new TH1F("pElectronFailed", " pElectronFailed ", 55, 0., 110.);
235  ptElectronFailed = new TH1F("ptElectronFailed", " ptElectronFailed ", 55, 0., 110.);
236 
237  pElectronPassed = new TH1F("pElectronPassed", " pElectronPassed ", 55, 0., 110.);
238  ptElectronPassed = new TH1F("ptElectronPassed", " ptElectronPassed ", 55, 0., 110.);
239 
240  sizeSuperClustersFailed = new TH1F("sizeSuperClustersFailed", "Super Cluster Size - Failed ", 20, 0, 19);
241  sizeSuperClustersPassed = new TH1F("sizeSuperClustersPassed", "Super Cluster Size - Passed ", 20, 0, 19);
242 
243  energySuperClustersPassed = new TH1F("energySuperClustersPassed", "Super Cluster Energy - Passed ", 125, 0, 250.);
244  energySuperClustersFailed = new TH1F("energySuperClustersFailed", "Super Cluster Energy - Failed ", 125, 0, 250.);
245 
246  eOverPFailed = new TH1F("eOverPFailed", " E over P - Failed ", 50, 0, 10.);
247  eOverPPassed = new TH1F("eOverPPassed", " E over P - Passed ", 50, 0, 10.);
248 
249  numSiStereoHits_ = new TH1F("numSiStereoHits", "Number of Si StereoHits", 100, 0, 1000);
250  numSiMonoHits_ = new TH1F("numSiMonoHits", "Number of Si MonoHits", 100, 0, 1000);
251  numSiMatchedHits_ = new TH1F("numSiMatchedHits", "Number of Si MatchedHits", 100, 0, 1000);
252 
254 
255  mctruthProducer_ = iConfig.getParameter<std::string>("mctruthProducer");
256  mctruthCollection_ = iConfig.getParameter<std::string>("mctruthCollection");
257 
258  superClusterProducer_ = iConfig.getParameter<std::string>("superClusterProducer");
259  superClusterCollection_ = iConfig.getParameter<std::string>("superClusterCollection");
260 
261  eBRecHitProducer_ = iConfig.getParameter<std::string>("recHitProducer");
262  eBRecHitCollection_ = iConfig.getParameter<std::string>("recHitCollection");
263 
264  siElectronProducer_ = iConfig.getParameter<std::string>("siElectronProducer");
265  siElectronCollection_ = iConfig.getParameter<std::string>("siElectronCollection");
266 
267  electronProducer_ = iConfig.getParameter<std::string>("electronProducer");
268  electronCollection_ = iConfig.getParameter<std::string>("electronCollection");
269 
270  siHitProducer_ = iConfig.getParameter<std::string>("siHitProducer");
271  siRphiHitCollection_ = iConfig.getParameter<std::string>("siRphiHitCollection");
272  siStereoHitCollection_ = iConfig.getParameter<std::string>("siStereoHitCollection");
273  siMatchedHitCollection_ = iConfig.getParameter<std::string>("siMatchedHitCollection");
274 }
275 
276 // SiStripElectronAnalyzer::SiStripElectronAnalyzer(const SiStripElectronAnalyzer& rhs)
277 // {
278 // // do actual copying here;
279 // }
280 
282  // do anything here that needs to be done at desctruction time
283  // (e.g. close files, deallocate resources etc.)
284 
285  file_->Write();
286  file_->Close();
287 }
288 
289 //
290 // assignment operators
291 //
292 // const SiStripElectronAnalyzer& SiStripElectronAnalyzer::operator=(const SiStripElectronAnalyzer& rhs)
293 // {
294 // //An exception safe implementation is
295 // SiStripElectronAnalyzer temp(rhs);
296 // swap(rhs);
297 //
298 // return *this;
299 // }
300 
301 //
302 // member functions
303 //
304 // init for TTree
306  myTree_ = new TTree("myTree", "my first Tree example");
307 
308  myTree_->Branch("NShowers", &NShowers_, "NShowers/I");
309 
310  // first specify the ECAL clusters
311  // need to explicitly include array length.
312  myTree_->Branch("EShower", &EShower_, "EShower[1000]/F");
313  myTree_->Branch("XShower", &XShower_, "XShower[1000]/F");
314  myTree_->Branch("YShower", &YShower_, "YShower[1000]/F");
315  myTree_->Branch("ZShower", &ZShower_, "ZShower[1000]/F");
316 
317  // second specify the Si Stereo Hits
318  myTree_->Branch("NStereoHits", &NStereoHits_, "NStereoHits/I");
319  myTree_->Branch("StereoHitX", &StereoHitX_, "StereoHitX[1000]/F");
320  myTree_->Branch("StereoHitY", &StereoHitY_, "StereoHitY[1000]/F");
321  myTree_->Branch("StereoHitZ", &StereoHitZ_, "StereoHitZ[1000]/F");
322 
323  myTree_->Branch("StereoHitR", &StereoHitR_, "StereoHitR[1000]/F");
324  myTree_->Branch("StereoHitPhi", &StereoHitPhi_, "StereoHitPhi[1000]/F");
325  myTree_->Branch("StereoHitTheta", &StereoHitTheta_, "StereoHitTheta[1000]/F");
326 
327  myTree_->Branch("StereoHitSigX", &StereoHitSigX_, "StereoHitSigX[1000]/F");
328  myTree_->Branch("StereoHitSigY", &StereoHitSigY_, "StereoHitSigY[1000]/F");
329  myTree_->Branch("StereoHitCorr", &StereoHitCorr_, "StereoHitCorr[1000]/F");
330 
331  myTree_->Branch("StereoHitSignal", &StereoHitSignal_, "StereoHitSignal[1000]/F");
332  myTree_->Branch("StereoHitNoise", &StereoHitNoise_, "StereoHitNoise[1000]/F");
333  myTree_->Branch("StereoHitWidth", &StereoHitWidth_, "StereoHitWidth[1000]/I");
334 
335  myTree_->Branch("StereoDetector", &StereoDetector_, "StereoDetector[1000]/I");
336  myTree_->Branch("StereoLayer", &StereoLayer_, "StereoLayer[1000]/I");
337 
338  // specify the Si mono (rphi) hits
339  myTree_->Branch("NMonoHits", &NMonoHits_, "NMonoHits/I");
340  myTree_->Branch("MonoHitX", &MonoHitX_, "MonoHitX[1000]/F");
341  myTree_->Branch("MonoHitY", &MonoHitY_, "MonoHitY[1000]/F");
342  myTree_->Branch("MonoHitZ", &MonoHitZ_, "MonoHitZ[1000]/F");
343 
344  myTree_->Branch("MonoHitR", &MonoHitR_, "MonoHitR[1000]/F");
345  myTree_->Branch("MonoHitPhi", &MonoHitPhi_, "MonoHitPhi[1000]/F");
346  myTree_->Branch("MonoHitTheta", &MonoHitTheta_, "MonoHitTheta[1000]/F");
347 
348  myTree_->Branch("MonoHitSigX", &MonoHitSigX_, "MonoHitSigX[1000]/F");
349  myTree_->Branch("MonoHitSigY", &MonoHitSigY_, "MonoHitSigY[1000]/F");
350  myTree_->Branch("MonoHitCorr", &MonoHitCorr_, "MonoHitCorr[1000]/F");
351 
352  myTree_->Branch("MonoHitSignal", &MonoHitSignal_, "MonoHitSignal[1000]/F");
353  myTree_->Branch("MonoHitNoise", &MonoHitNoise_, "MonoHitNoise[1000]/F");
354  myTree_->Branch("MonoHitWidth", &MonoHitWidth_, "MonoHitWidth[1000]/I");
355 
356  myTree_->Branch("MonoDetector", &MonoDetector_, "MonoDetector[1000]/I");
357  myTree_->Branch("MonoLayer", &MonoLayer_, "MonoLayer[1000]/I");
358 
359  // specify the Si matched (rphi) hits
360  myTree_->Branch("NMatchedHits", &NMatchedHits_, "NMatchedHits/I");
361  myTree_->Branch("MatchedHitX", &MatchedHitX_, "MatchedHitX[1000]/F");
362  myTree_->Branch("MatchedHitY", &MatchedHitY_, "MatchedHitY[1000]/F");
363  myTree_->Branch("MatchedHitZ", &MatchedHitZ_, "MatchedHitZ[1000]/F");
364 
365  myTree_->Branch("MatchedHitR", &MatchedHitR_, "MatchedHitR[1000]/F");
366  myTree_->Branch("MatchedHitPhi", &MatchedHitPhi_, "MatchedHitPhi[1000]/F");
367  myTree_->Branch("MatchedHitTheta", &MatchedHitTheta_, "MatchedHitTheta[1000]/F");
368 
369  myTree_->Branch("MatchedHitSigX", &MatchedHitSigX_, "MatchedHitSigX[1000]/F");
370  myTree_->Branch("MatchedHitSigY", &MatchedHitSigY_, "MatchedHitSigY[1000]/F");
371  myTree_->Branch("MatchedHitCorr", &MatchedHitCorr_, "MatchedHitCorr[1000]/F");
372 
373  myTree_->Branch("MatchedHitSignal", &MatchedHitSignal_, "MatchedHitSignal[1000]/F");
374  myTree_->Branch("MatchedHitNoise", &MatchedHitNoise_, "MatchedHitNoise[1000]/F");
375  myTree_->Branch("MatchedHitWidth", &MatchedHitWidth_, "MatchedHitWidth[1000]/I");
376 
377  myTree_->Branch("MatchedDetector", &MatchedDetector_, "MatchedDetector[1000]/I");
378  myTree_->Branch("MatchedLayer", &MatchedLayer_, "MatchedLayer[1000]/I");
379 }
380 
382  LogDebug("") << " In initNtuple ";
383 
384  NShowers_ = -999;
385  for (int init = 0; init < myMaxHits; ++init) {
386  EShower_[init] = -999.;
387  XShower_[init] = -999.;
388  YShower_[init] = -999.;
389  ZShower_[init] = -999.;
390  }
391  NStereoHits_ = -999;
392 
393  for (int init = 0; init < myMaxHits; ++init) {
394  StereoHitX_[init] = -999.;
395  StereoHitY_[init] = -999.;
396  StereoHitZ_[init] = -999.;
397  StereoHitR_[init] = -999.;
398  StereoHitPhi_[init] = -999.;
399  StereoHitTheta_[init] = -999.;
400 
401  StereoHitSignal_[init] = -999.;
402  StereoHitNoise_[init] = -999.;
403  StereoHitWidth_[init] = -999;
404  ;
405  }
406 
407  NMonoHits_ = -999;
408  for (int init = 0; init < myMaxHits; ++init) {
409  MonoHitX_[init] = -999.;
410  MonoHitY_[init] = -999.;
411  MonoHitZ_[init] = -999.;
412  MonoHitR_[init] = -999.;
413  MonoHitPhi_[init] = -999.;
414  MonoHitTheta_[init] = -999.;
415 
416  MonoHitSignal_[init] = -999.;
417  MonoHitNoise_[init] = -999.;
418  MonoHitWidth_[init] = -999;
419  ;
420  }
421 
422  NMatchedHits_ = -999;
423  for (int init = 0; init < myMaxHits; ++init) {
424  MatchedHitX_[init] = -999.;
425  MatchedHitY_[init] = -999.;
426  MatchedHitZ_[init] = -999.;
427  MatchedHitR_[init] = -999.;
428  MatchedHitPhi_[init] = -999.;
429  MatchedHitTheta_[init] = -999.;
430 
431  MatchedHitSignal_[init] = -999.;
432  MatchedHitNoise_[init] = -999.;
433  MatchedHitWidth_[init] = -999;
434  ;
435  }
436 }
437 
438 // ------------ method called to produce the data ------------
440  //Retrieve tracker topology from geometry
442 
443  using namespace std; // so you can say "cout" and "endl"
444 
445  initNtuple();
446 
447  // http://cmsdoc.cern.ch/swdev/lxr/CMSSW/source/clhep/CLHEP/HepMC/GenParticle.h
448  // http://cmsdoc.cern.ch/swdev/lxr/CMSSW/source/clhep/CLHEP/HepMC/GenVertex.h
449  // removed by JED - causes trouble in release post 0_9_0
450  // edm::Handle<edm::HepMCProduct> mctruthHandle;
451  // iEvent.getByLabel(mctruthProducer_, mctruthCollection_, mctruthHandle);
452  // HepMC::GenEvent mctruth = mctruthHandle->getHepMCData();
453 
454  // for (HepMC::GenEvent::particle_const_iterator partIter = mctruth.particles_begin();
455  // partIter != mctruth.particles_end();
456  // ++partIter) {
457  // // for (HepMC::GenEvent::vertex_const_iterator vertIter = mctruth.vertices_begin();
458  // // vertIter != mctruth.vertices_end();
459  // // ++vertIter) {
460  // CLHEP::HepLorentzVector creation = (*partIter)->CreationVertex();
461  // CLHEP::HepLorentzVector momentum = (*partIter)->Momentum();
462  // HepPDT::ParticleID id = (*partIter)->particleID(); // electrons and positrons are 11 and -11
463  // edm::LogInfo("") << "MC particle id " << id.pid() << ", creationVertex " << creation << " cm, initialMomentum " << momentum << " GeV/c" << endl;
464  // }
465 
466  // load the rechits for the Ecal
468  iEvent.getByLabel(eBRecHitProducer_, eBRecHitCollection_, pRecHits);
469  // Create a pointer to the RecHits - unused for now
470  // const EcalRecHitCollection *hitCollection = pRecHits.product();
471 
472  // http://cmsdoc.cern.ch/swdev/lxr/CMSSW/source/self/DataFormats/EgammaReco/interface/SuperCluster.h
474  iEvent.getByLabel(superClusterProducer_, superClusterCollection_, clusterHandle);
475 
478 
479  LogDebug("") << " Start loop over " << clusterHandle->end() - clusterHandle->begin() << " superClusters ";
480 
481  for (reco::SuperClusterCollection::const_iterator clusterIter = clusterHandle->begin();
482  clusterIter != clusterHandle->end();
483  ++clusterIter) {
484  double energy = clusterIter->energy();
485  math::XYZPoint position = clusterIter->position();
486  std::ostringstream str;
487 
488  str << " SuperCluster " << energy << " GeV, position " << position << " cm"
489  << "\n";
490 
492  sizeSuperClusters_->Fill(clusterIter->clustersSize());
493  // this only makes sense for hybrid superclusters
494 
495  // try to point to the constituent clusters for this SuperCluster
496 
497  str << "About to loop over basicClusters"
498  << "\n";
499 
500  double emaxSuperCluster = 0.;
501  double phibar = 0.;
502  double phi2bar = 0.;
503  double eTotSuperCluster = 0.;
504 
505  for (reco::CaloCluster_iterator basicClusterIter = clusterIter->clustersBegin();
506  basicClusterIter != clusterIter->clustersEnd();
507  ++basicClusterIter) {
508  //std::vector<DetId> theIds= (*basicClusterIter)->getHitsByDetId();
509 
510  str << " basicCluster Energy " << (*basicClusterIter)->energy() << " Position " << (*basicClusterIter)->position()
511  << " \n"
512  << " Position phi " << (*basicClusterIter)->position().phi() << " recHits "
513  << (*basicClusterIter)->size() << " \n";
514 
515  double eCluster = (*basicClusterIter)->energy();
516  if (eCluster > emaxSuperCluster) {
517  emaxSuperCluster = eCluster;
518  }
519  eTotSuperCluster += eCluster;
520  double phiCluster = (*basicClusterIter)->position().phi();
521  phibar += eCluster * phiCluster;
522  phi2bar += eCluster * phiCluster * phiCluster;
523 
524  } // end of basicClusterIter loop
525 
526  phibar = phibar / eTotSuperCluster;
527  phi2bar = phi2bar / eTotSuperCluster;
528  double phiWidth = phi2bar - phibar * phibar;
529  if (phiWidth > 0.) {
530  phiWidth = std::pow(phiWidth, 0.5);
531  } else {
532  phiWidth = 0.;
533  }
534  str << " SuperCluster stats "
535  << "\n";
536  str << "phibar " << phibar << " phi2bar " << phi2bar << " eTotSuperCluster " << eTotSuperCluster << " phiWidth "
537  << phiWidth << std::endl;
538 
540 
541  emaxSuperClusters_->Fill(emaxSuperCluster);
542 
543  str << " Done with this SuperCluster " << std::endl;
544 
545  LogDebug("") << str.str();
546 
547  } // end of loop over superClusters
548 
549  LogDebug("") << " End loop over superClusters ";
550 
553 
555  //
556  // loop over all EcalRecHits and print out their x,y,z,E
557  // edm::LogInfo("") << " Dumping all recHits in this event " << endl ;
558  // for(EcalRecHitCollection::const_iterator _blah = hitCollection->begin();
559  // _blah != hitCollection->end() ; ++_blah ) {
560  // edm::LogInfo("") << "Ecal RecHit Energy: " << _blah->energy() << endl ;
561  // // " Position " << _blah.position() << endl ;
562  // }
563  //
564  // edm::LogInfo("") << "Dump finished " << endl ;
565  //
567 
568  // DataFormats/EgammaCandidates/src/SiStripElectron.cc
569  edm::Handle<reco::SiStripElectronCollection> siStripElectronHandle;
570  iEvent.getByLabel(siElectronProducer_, siElectronCollection_, siStripElectronHandle);
571 
573 
574  LogDebug("") << " Dumping Algo's guess of SiStripElectron Candidate Info ";
575  int numberOfElectrons = 0;
576  // need to check if fit succeeded
577  LogDebug("") << " Number of SiStripElectrons " << siStripElectronHandle->size();
578 
579  for (reco::SiStripElectronCollection::const_iterator electronIter = siStripElectronHandle->begin();
580  electronIter != siStripElectronHandle->end();
581  ++electronIter) {
582  LogDebug("") << "about to get stuff from electroncandidate " << numberOfElectrons << "\n"
583  << "supercluster energy = " << electronIter->superCluster()->energy() << "\n"
584  << "fit results are phi(r) = " << electronIter->phiAtOrigin() << " + " << electronIter->phiVsRSlope()
585  << "*r"
586  << "\n"
587  << " chi2 " << electronIter->chi2() << " ndof " << electronIter->ndof() << "\n"
588  << " Pt " << electronIter->pt() << "\n"
589  << "P, Px, Py, Pz " << electronIter->p() << " " << electronIter->px() << " " << electronIter->py()
590  << " " << electronIter->pz() << "\n"
591  << "you get the idea...";
592 
593  // make plots for supercluster that an electron has been associ w/. here
594  energySuperClustersEl_->Fill(electronIter->superCluster()->energy());
595  sizeSuperClustersEl_->Fill(electronIter->superCluster()->clustersSize());
596 
597  // loop over basicClusters to get energy
598  double emaxSuperCluster = 0.;
599  double phibar = 0.;
600  double phi2bar = 0.;
601  double eTotSuperCluster = 0.;
602 
603  for (reco::CaloCluster_iterator basicClusterIter = electronIter->superCluster()->clustersBegin();
604  basicClusterIter != electronIter->superCluster()->clustersEnd();
605  ++basicClusterIter) {
606  //std::vector<DetId> theIds= (*basicClusterIter)->getHitsByDetId();
607 
608  double eCluster = (*basicClusterIter)->energy();
609  if (eCluster > emaxSuperCluster) {
610  emaxSuperCluster = eCluster;
611  }
612  eTotSuperCluster += eCluster;
613  double phiCluster = (*basicClusterIter)->position().phi();
614  phibar += eCluster * phiCluster;
615  phi2bar += eCluster * phiCluster * phiCluster;
616  }
617 
618  phibar = phibar / eTotSuperCluster;
619  phi2bar = phi2bar / eTotSuperCluster;
620  double phiWidth = phi2bar - phibar * phibar;
621  if (phiWidth > 0.) {
622  phiWidth = std::pow(phiWidth, 0.5);
623  } else {
624  phiWidth = 0.;
625  }
626 
628 
629  emaxSuperClustersEl_->Fill(emaxSuperCluster);
630 
631  numberOfElectrons++;
632  }
633 
634  numCand_->Fill(siStripElectronHandle->size());
635 
637 
638  // Now loop over the electrons (ie the fitted things.)
639 
640  LogDebug("") << " About to check Electrons";
641 
644 
645  numElectrons_->Fill(electrons->end() - electrons->begin());
646 
647  // set up vector of bool for SiStrips having or not having Electrons
648  // this causes a warning because of variable array size at compilation time ;
649  // BAD bool hasElectron_[siStripElectronHandle->end()- siStripElectronHandle->begin()] ;
650  bool* hasElectron_ = new bool[siStripElectronHandle->end() - siStripElectronHandle->begin()];
651  for (int icount = 0; icount < siStripElectronHandle->end() - siStripElectronHandle->begin(); ++icount) {
652  hasElectron_[icount] = false;
653  }
654 
655  // also set up a counter to associate the ith electron to the jth strippy
656  // Electron_to_strippy[i] = j: i-th Electron is j-th strippy
657  // BAD unsigned int Electron_to_strippy[electrons->end()- electrons->begin()];
658  unsigned int* Electron_to_strippy = new unsigned int[electrons->end() - electrons->begin()];
659  for (int icount = 0; icount < electrons->end() - electrons->begin(); ++icount) {
660  Electron_to_strippy[icount] = 0;
661  }
662 
663  unsigned int ecount = 0;
664  for (reco::ElectronCollection::const_iterator electronIter = electrons->begin(); electronIter != electrons->end();
665  ++electronIter) {
666  LogDebug("") << " Associating Electrons to Strippies ";
667  LogDebug("") << " PT is " << electronIter->track()->pt();
668 
669  reco::TrackRef tr = (*electronIter).track();
670  uint32_t id = (*electronIter->track()->recHitsBegin())->geographicalId().rawId();
671  LocalPoint pos = (*electronIter->track()->recHitsBegin())->localPosition();
672 
673  unsigned int icount = 0;
674  LogDebug("") << " About to loop over Strippies "
675  << " \n "
676  << " icount " << icount << " max " << siStripElectronHandle->end() - siStripElectronHandle->begin();
677 
678  for (reco::SiStripElectronCollection::const_iterator strippyiter = siStripElectronHandle->begin();
679  strippyiter != siStripElectronHandle->end();
680  ++strippyiter) {
681  bool hitInCommon = false;
682  // loop over rphi hits
683  for (std::vector<SiStripRecHit2D>::const_iterator hiter = strippyiter->rphiRecHits().begin();
684  hiter != strippyiter->rphiRecHits().end();
685  ++hiter) {
686  if (hiter->geographicalId().rawId() == id && (hiter->localPosition() - pos).mag() < 1e-10) {
687  hitInCommon = true;
688  break;
689  }
690  }
691 
692  for (std::vector<SiStripRecHit2D>::const_iterator hiter = strippyiter->stereoRecHits().begin();
693  hiter != strippyiter->stereoRecHits().end();
694  ++hiter) {
695  if (hiter->geographicalId().rawId() == id && (hiter->localPosition() - pos).mag() < 1e-10) {
696  hitInCommon = true;
697  break;
698  }
699  }
700  if (hitInCommon) { //this Electron belongs to this SiStripElectron.
701  hasElectron_[icount] = true;
702  Electron_to_strippy[ecount] = icount;
703  ptDiff->Fill(std::abs(electronIter->track()->pt()) - std::abs(strippyiter->pt()));
704  pDiff->Fill(std::abs(electronIter->track()->p()) - std::abs(strippyiter->p()));
705  }
706  icount++;
707  } // Sistrip loop
708  ecount++;
709  } // Electrons
710 
711  LogDebug("") << " Done looping over Electrons ";
712 
713  unsigned int counter = 0;
714  for (reco::SiStripElectronCollection::const_iterator strippyIter = siStripElectronHandle->begin();
715  strippyIter != siStripElectronHandle->end();
716  ++strippyIter) {
717  bool skipThis = !hasElectron_[counter];
718  if (skipThis) {
719  // plot stuff for SIStripElectrons that don't have fits associated
720 
721  LogDebug("") << " SiStrip Failed Electron "
722  << " \n "
723  << " p " << strippyIter->p() << " \n "
724  << " pt " << strippyIter->pt() << " \n "
725  << " SuperClust size " << strippyIter->superCluster()->clustersSize();
726 
727  pElectronFailed->Fill(std::abs(strippyIter->p()));
728  ptElectronFailed->Fill(std::abs(strippyIter->pt()));
729  sizeSuperClustersFailed->Fill(strippyIter->superCluster()->clustersSize());
730  LogDebug("") << " done filling Failed histos ";
731  // energySuperClustersFailed->Fill(strippyIter->superCluster()->energy());
732  // if(strippyIter->p()>0.) {
733  // eOverPFailed->Fill(strippyIter->superCluster()->energy()/strippyIter->p());
734  // }else {
735  // eOverPFailed->Fill(-1.0);
736  // }
737 
738  } else {
739  LogDebug("") << " SiStrip Passed Electron "
740  << " \n "
741  << " p " << strippyIter->p() << " \n "
742  << " pt " << strippyIter->pt() << " \n "
743  << " SuperClust size " << strippyIter->superCluster()->clustersSize();
744  pElectronPassed->Fill(std::abs(strippyIter->p()));
745  ptElectronPassed->Fill(std::abs(strippyIter->pt()));
746  sizeSuperClustersPassed->Fill(strippyIter->superCluster()->clustersSize());
747  LogDebug("") << " done filling passed histos ";
748  // energySuperClustersPassed->Fill(strippyIter->superCluster()->energy());
749  // if(strippyIter->p()>0.) {
750  // eOverPPassed->Fill(strippyIter->superCluster()->energy()/strippyIter->p());
751  // }else {
752  // eOverPPassed->Fill(-1.0);
753  // }
754 
755  } // skipThis
756  counter++;
757  }
758 
759  LogDebug("") << "Dump info for all electrons ";
760 
761  for (reco::ElectronCollection::const_iterator electronIter1 = electrons->begin(); electronIter1 != electrons->end();
762  ++electronIter1) {
763  reco::TrackRef tr1 = (*electronIter1).track();
764  // let's find its associated SiStripElectron and SuperCluster
765  unsigned int ecount1 = electronIter1 - electrons->begin();
766  unsigned int stripCount1 = 0;
767  reco::SiStripElectronCollection::const_iterator strippyIter1;
768  for (reco::SiStripElectronCollection::const_iterator strippyIter = siStripElectronHandle->begin();
769  strippyIter != siStripElectronHandle->end();
770  ++strippyIter) {
771  if (Electron_to_strippy[ecount1] == stripCount1) {
772  strippyIter1 = strippyIter;
773  break;
774  }
775  stripCount1++;
776  } // strippy loop
777  ecount1++;
778 
779  std::ostringstream str;
780 
781  str << " SiStripElect p , px, py, pz " << strippyIter1->p() << " " << strippyIter1->px() << " "
782  << strippyIter1->py() << " " << strippyIter1->pz() << "\n " << std::endl;
783 
784  str << " Electron p px, py, pz, = " << tr1->p() << " " << tr1->px() << " " << tr1->py() << " " << tr1->pz()
785  << "\n"
786  << std::endl;
787 
788  double EClust1 = strippyIter1->superCluster()->energy();
789  double XClust1 = strippyIter1->superCluster()->x();
790  double YClust1 = strippyIter1->superCluster()->y();
791  double ZClust1 = strippyIter1->superCluster()->z();
792 
793  double rho1 = sqrt(XClust1 * XClust1 + YClust1 * YClust1 + ZClust1 * ZClust1);
794  double costheta1 = ZClust1 / rho1;
795  double sintheta1 = sqrt(1 - costheta1 * costheta1);
796  if (ZClust1 < 0) {
797  sintheta1 = -sintheta1;
798  }
799  double cosphi1 = XClust1 / sqrt(XClust1 * XClust1 + YClust1 * YClust1);
800  double sinphi1 = YClust1 / sqrt(XClust1 * XClust1 + YClust1 * YClust1);
801 
802  str << " Ecal for electron E, px, py, pz " << EClust1 << " " << EClust1 * sintheta1 * cosphi1 << " "
803  << EClust1 * sintheta1 * sinphi1 << " " << EClust1 * costheta1 << "\n"
804  << std::endl;
805 
806  LogDebug("") << str.str();
807 
808  } // loop over electrons
809  LogDebug("") << "Done Dumping info for all electrons ";
810 
812  // LogDebug("")<< " Checking Electrons" ;
813  // LogDebug("")<< " PT is " << electronIter->track()->pt() ;
814  // reco::TrackRef tr =(*electronIter).track();
816  if (electrons->end() - electrons->begin() > 1) {
817  edm::LogInfo("") << " Two electrons in this event " << std::endl;
818  for (reco::ElectronCollection::const_iterator electronIter1 = electrons->begin();
819  electronIter1 != electrons->end() - 1;
820  ++electronIter1) {
821  reco::TrackRef tr1 = (*electronIter1).track();
822 
823  // let's find its associated SiStripElectron and SuperCluster
824  // use the Electron_to_strippy[] array
825  unsigned int ecount1 = electronIter1 - electrons->begin();
826  // loop over strippies to find the corresponding one
827  unsigned int stripCount1 = 0;
828  reco::SiStripElectronCollection::const_iterator strippyIter1;
829  for (reco::SiStripElectronCollection::const_iterator strippyIter = siStripElectronHandle->begin();
830  strippyIter != siStripElectronHandle->end();
831  ++strippyIter) {
832  if (Electron_to_strippy[ecount1] == stripCount1) {
833  strippyIter1 = strippyIter;
834  break;
835  }
836  stripCount1++;
837  } // strippy loop
838 
839  double EClust1 = strippyIter1->superCluster()->energy();
840  double XClust1 = strippyIter1->superCluster()->x();
841  double YClust1 = strippyIter1->superCluster()->y();
842  double ZClust1 = strippyIter1->superCluster()->z();
843 
844  for (reco::ElectronCollection::const_iterator electronIter2 = electronIter1 + 1;
845  electronIter2 != electrons->end();
846  ++electronIter2) {
847  reco::TrackRef tr2 = (*electronIter2).track();
848 
849  unsigned int ecount2 = electronIter2 - electrons->begin();
850  unsigned int stripCount2 = 0;
851  reco::SiStripElectronCollection::const_iterator strippyIter2;
852  for (reco::SiStripElectronCollection::const_iterator strippyIter = siStripElectronHandle->begin();
853  strippyIter != siStripElectronHandle->end();
854  ++strippyIter) {
855  if (Electron_to_strippy[ecount2] == stripCount2) {
856  strippyIter2 = strippyIter;
857  break;
858  }
859  stripCount2++;
860  } // strippy loop
861 
862  double EClust2 = strippyIter2->superCluster()->energy();
863  double XClust2 = strippyIter2->superCluster()->x();
864  double YClust2 = strippyIter2->superCluster()->y();
865  double ZClust2 = strippyIter2->superCluster()->z();
866 
867  // now get supercluster from this:
868 
869  edm::LogInfo("") << " Electron p1 = " << tr1->p() << " p1x " << tr1->px() << " p1y " << tr1->py() << " p1z "
870  << tr1->pz() << std::endl;
871 
872  edm::LogInfo("") << " Electron p2 = " << tr2->p() << " p2x " << tr2->px() << " p2y " << tr2->py() << " p2z "
873  << tr2->pz() << std::endl;
874 
875  // combine the two in an (e,e) pair
876  double Zpx = tr1->px() + tr2->px();
877  double Zpy = tr1->py() + tr2->py();
878  double Zpz = tr1->pz() + tr2->pz();
879  double Ze = std::abs(tr1->p()) + std::abs(tr2->p());
880  edm::LogInfo("") << " Z mass " << sqrt(Ze * Ze - Zpx * Zpx - Zpy * Zpy - Zpz * Zpz) << std::endl;
881 
882  // combine the SuperClusts into a Z
883  double rho1 = sqrt(XClust1 * XClust1 + YClust1 * YClust1 + ZClust1 * ZClust1);
884  double costheta1 = ZClust1 / rho1;
885  double sintheta1 = sqrt(1 - costheta1 * costheta1);
886  if (ZClust1 < 0) {
887  sintheta1 = -sintheta1;
888  }
889  double cosphi1 = XClust1 / sqrt(XClust1 * XClust1 + YClust1 * YClust1);
890  double sinphi1 = YClust1 / sqrt(XClust1 * XClust1 + YClust1 * YClust1);
891 
892  double rho2 = sqrt(XClust2 * XClust2 + YClust2 * YClust2 + ZClust2 * ZClust2);
893  double costheta2 = ZClust2 / rho2;
894  double sintheta2 = sqrt(1 - costheta2 * costheta2);
895  if (ZClust2 < 0) {
896  sintheta2 = -sintheta2;
897  }
898  double cosphi2 = XClust2 / sqrt(XClust2 * XClust2 + YClust2 * YClust2);
899  double sinphi2 = YClust2 / sqrt(XClust2 * XClust2 + YClust2 * YClust2);
900 
901  edm::LogInfo("") << "Energy of supercluster for 1st electron " << EClust1 << " "
902  << EClust1 * sintheta1 * cosphi1 << " " << EClust1 * sintheta1 * sinphi1 << " "
903  << EClust1 * costheta1 << " " << std::endl;
904 
905  edm::LogInfo("") << "Energy of supercluster for 2nd electron " << EClust2 << " "
906  << EClust2 * sintheta2 * cosphi2 << " " << EClust2 * sintheta2 * sinphi2 << " "
907  << EClust2 * costheta2 << " " << std::endl;
908 
909  // get the supercluster pair
910  double Zgpx = EClust1 * sintheta1 * cosphi1 + EClust2 * sintheta2 * cosphi2;
911  double Zgpy = EClust1 * sintheta1 * sinphi1 + EClust2 * sintheta2 * sinphi2;
912  double Zgpz = EClust1 * costheta1 + EClust2 * costheta2;
913  double ZgE = EClust1 + EClust2;
914 
915  edm::LogInfo("") << " Z mass from ECAL " << sqrt(ZgE * ZgE - Zgpx * Zgpx - Zgpy * Zgpy - Zgpz * Zgpz)
916  << std::endl;
917 
918  } //inner loop
919  } // outer loop
920  } // m(ee) loop
921 
922  delete[] hasElectron_;
923  delete[] Electron_to_strippy;
924 
928  LogDebug("") << " About to dump tracker info ";
929 
931 
933  iEvent.getByLabel(siHitProducer_, siRphiHitCollection_, rphiHitsHandle);
934 
936  iEvent.getByLabel(siHitProducer_, siStereoHitCollection_, stereoHitsHandle);
937 
939  iEvent.getByLabel(siHitProducer_, siMatchedHitCollection_, matchedHitsHandle);
940 
942 
944  NShowers_ = 0;
945  for (reco::SuperClusterCollection::const_iterator clusterIter = clusterHandle->begin();
946  clusterIter != clusterHandle->end();
947  ++clusterIter) {
948  double energy = clusterIter->energy();
949  math::XYZPoint position = clusterIter->position();
950  if (NShowers_ < myMaxHits) {
952  XShower_[NShowers_] = position.x();
953  YShower_[NShowers_] = position.y();
954  ZShower_[NShowers_] = position.z();
955  ++NShowers_;
956  }
957  // Loop over all crystals in this supercluster - see
958  // RecoEcal/EgamaClusterProducers/src/EgammaSimpleAnalyzer.cc
959  // Look also at DataFormats/EgammaReco/interface/SuperCluster.h
960  }
963 
964  LogDebug("") << " Looping over stereo hits ";
965 
967  int myHits = 0;
968  for (SiStripRecHit2DCollection::DataContainer::const_iterator hit = stereoHitsHandle->data().begin(),
969  hitend = stereoHitsHandle->data().end();
970  hit != hitend;
971  ++hit) {
972  DetId id(hit->geographicalId());
973  if ((hit->geographicalId()).subdetId() == StripSubdetector::TIB ||
974  (hit->geographicalId()).subdetId() == StripSubdetector::TOB) {
975  GlobalPoint position = trackerHandle->idToDet(hit->geographicalId())->surface().toGlobal(hit->localPosition());
976  //from RecoLocalTracker/SiStripClusterizer/test/TestCluster.cc
977  // cf also TrackHitAssociator.cc SiStripRecHitMatcher.cc SiStrip1DMeasurementTransformator.cc (KalmanUpdators)
978  SiStripRecHit2D const rechit = *hit;
979  // LocalPoint myposition = rechit.localPosition() ;
980  LocalError myerror = rechit.localPositionError();
981 
982  // Get layer and subdetector ID here for this hit
983  // see SiStripRecHitConverter/test/ValHit.cc
984  Int_t siLayerNum = 0;
985  Int_t siDetNum = 0;
986  string siDetName = "";
987  if ((hit->geographicalId()).subdetId() == StripSubdetector::TIB) {
988  // siLayerNum = tTopo->tibLayer(rechit->geographicalID());
989  siLayerNum = tTopo->tibLayer(id);
990  siDetNum = 1;
991  siDetName = "TIB";
992  } else if ((hit->geographicalId()).subdetId() == StripSubdetector::TOB) {
993  siLayerNum = tTopo->tobLayer(id);
994  siDetNum = 2;
995  siDetName = "TOB";
996  // } else if ( (hit->geographicalId()).subdetId() == StripSubdetector::TID ){
997  // // should we use side/wheel/ring/module/stereo() ?
998  // siLayerNum = tTopo->tidWheel(id);
999  // siDetNum = 3 ;
1000  // siDetName = "TID" ;
1001  // }else if ( (hit->geographicalId()).subdetId() == StripSubdetector::TEC ){
1002  // //choices are side/petal/wheel/ring/module/glued/stereo
1003  // siLayerNum = tTopo->tecWheel(id);
1004  // siDetNum = 4 ;
1005  // siDetName = "TEC" ;
1006  } else {
1007  siLayerNum = -999;
1008  siDetNum = -999;
1009  siDetName = "NULL";
1010  }
1011  // LogDebug("") << siDetName << " " << siLayerNum ;
1012 
1013  const SiStripRecHit2D::ClusterRef& clust = rechit.cluster();
1014  double Signal = 0;
1015  double Noise2 = 0;
1016  int StripCount = 0;
1017  if (clust.isNonnull()) {
1018  // LogDebug("") << " barycenter " << clust->barycenter() ;
1019  // const std::vector<uint16_t> amplitudes=clust->amplitudes();
1020  const auto& amplitudes = clust->amplitudes();
1021  for (size_t i = 0; i < amplitudes.size(); i++) {
1022  Signal += amplitudes[i];
1023  //ignore for now Noise2 +=SiStripNoiseService_.getNoise(detid,clust->firstStrip()+i)*SiStripNoiseService_.getNoise(detid,clust->firstStrip()+i);
1024  StripCount++;
1025  }
1026  } else {
1027  LogDebug("") << " null cluster ";
1028  }
1029  // LogDebug("") << "Signal " << Signal << " Noise2 " << Noise2 << " StripCount " << StripCount ;
1030  // Dump position
1031  // LogDebug("") << " Stereo "
1032  // << "local position: "<<myposition.x()<<" "
1033  // << myposition.y()<<" "<<myposition.z()<<"\n"
1034  // << "local error: "<<myerror.xx()<<" "
1035  // << myerror.xy()<<" "<<myerror.yy() << "\n"
1036  // << "global position: " << position.x() << " "
1037  // << position.y()<<" "<< position.z()<<"\n"
1038  // << " siDetNum " << siDetNum
1039  // << " siLayerNum " << siLayerNum ;
1040 
1041  if (myHits < myMaxHits) {
1042  StereoHitX_[myHits] = position.x();
1043  StereoHitY_[myHits] = position.y();
1044  StereoHitZ_[myHits] = position.z();
1045 
1046  StereoHitR_[myHits] = position.perp();
1047  StereoHitPhi_[myHits] = position.phi();
1048  StereoHitTheta_[myHits] = position.theta();
1049 
1050  StereoHitSigX_[myHits] = sqrt(myerror.xx());
1051  StereoHitSigY_[myHits] = sqrt(myerror.yy());
1052  StereoHitCorr_[myHits] = myerror.xy() / sqrt(myerror.xx() * myerror.yy());
1053 
1054  StereoHitSignal_[myHits] = Signal;
1055  StereoHitNoise_[myHits] = Noise2;
1056  StereoHitWidth_[myHits] = StripCount;
1057 
1058  StereoDetector_[myHits] = siDetNum;
1059  StereoLayer_[myHits] = siLayerNum;
1060 
1061  ++myHits;
1062  }
1063  } // end if this is the right subdetector
1064  } // end loop over hits
1065  NStereoHits_ = myHits;
1066 
1068 
1071 
1072  LogDebug("") << " Looping over Mono Hits ";
1074  myHits = 0;
1075  for (SiStripRecHit2DCollection::DataContainer::const_iterator hit = rphiHitsHandle->data().begin(),
1076  hitend = rphiHitsHandle->data().end();
1077  hit != hitend;
1078  ++hit) {
1079  DetId id(hit->geographicalId());
1080 
1081  if ((hit->geographicalId()).subdetId() == StripSubdetector::TIB ||
1082  (hit->geographicalId()).subdetId() == StripSubdetector::TOB) {
1083  GlobalPoint position = trackerHandle->idToDet(hit->geographicalId())->surface().toGlobal(hit->localPosition());
1084  //from RecoLocalTracker/SiStripClusterizer/test/TestCluster.cc
1085  // cf also TrackHitAssociator.cc SiStripRecHitMatcher.cc SiStrip1DMeasurementTransformator.cc (KalmanUpdators)
1086  SiStripRecHit2D const rechit = *hit;
1087  // LocalPoint myposition = rechit.localPosition() ;
1088  LocalError myerror = rechit.localPositionError();
1089 
1090  // Get layer and subdetector ID here for this hit
1091  // see SiStripRecHitConverter/test/ValHit.cc
1092  Int_t siLayerNum = 0;
1093  Int_t siDetNum = 0;
1094  string siDetName = "";
1095  if ((hit->geographicalId()).subdetId() == StripSubdetector::TIB) {
1096  // siLayerNum = tTopo->tibLayer(rechit->geographicalID());
1097  siLayerNum = tTopo->tibLayer(id);
1098  siDetNum = 1;
1099  siDetName = "TIB";
1100  } else if ((hit->geographicalId()).subdetId() == StripSubdetector::TOB) {
1101  siLayerNum = tTopo->tobLayer(id);
1102  siDetNum = 2;
1103  siDetName = "TOB";
1104  // } else if ( (hit->geographicalId()).subdetId() == StripSubdetector::TID ){
1105  // // should we use side/wheel/ring/module/stereo() ?
1106  // siLayerNum = tTopo->tidWheel(id);
1107  // siDetNum = 3 ;
1108  // siDetName = "TID" ;
1109  // }else if ( (hit->geographicalId()).subdetId() == StripSubdetector::TEC ){
1110  // //choices are side/petal/wheel/ring/module/glued/stereo
1111  // siLayerNum = tTopo->tecWheel(id);
1112  // siDetNum = 4 ;
1113  // siDetName = "TEC"
1114  ;
1115  } else {
1116  siLayerNum = -999;
1117  siDetNum = -999;
1118  siDetName = "NULL";
1119  }
1120  // LogDebug("") << siDetName << " " << siLayerNum ;
1121  const SiStripRecHit2D::ClusterRef& clust = rechit.cluster();
1122  double Signal = 0;
1123  double Noise2 = 0;
1124  int StripCount = 0;
1125  if (clust.isNonnull()) {
1126  // LogDebug("") << " barycenter " << clust->barycenter() ;
1127  // const std::vector<uint16_t> amplitudes=clust->amplitudes();
1128  const auto& amplitudes = clust->amplitudes();
1129  for (size_t i = 0; i < amplitudes.size(); i++) {
1130  Signal += amplitudes[i];
1131  //ignore for now Noise2 +=SiStripNoiseService_.getNoise(detid,clust->firstStrip()+i)*SiStripNoiseService_.getNoise(detid,clust->firstStrip()+i);
1132  StripCount++;
1133  }
1134  } else {
1135  LogDebug("") << " null cluster ";
1136  }
1137  // LogDebug("") << "Signal " << Signal << " Noise2 " << Noise2 << " StripCount " << StripCount ;
1138 
1139  // Dump position info
1140  // LogDebug("") << " Mono "
1141  // << "local position: "<<myposition.x()<<" "
1142  // << myposition.y()<<" "<<myposition.z()<<"\n"
1143  // <<"local error: "<<myerror.xx()<<" "
1144  // << myerror.xy()<<" "<<myerror.yy() << "\n"
1145  // << "global position: " << position.x() << " "
1146  // << position.y()<<" "<< position.z()<<"\n"
1147  // << " siDetNum " << siDetNum
1148  // << " siLayerNum " << siLayerNum ;
1149 
1150  if (myHits < myMaxHits) {
1151  MonoHitX_[myHits] = position.x();
1152  MonoHitY_[myHits] = position.y();
1153  MonoHitZ_[myHits] = position.z();
1154 
1155  MonoHitR_[myHits] = position.perp();
1156  MonoHitPhi_[myHits] = position.phi();
1157  MonoHitTheta_[myHits] = position.theta();
1158 
1159  MonoHitSigX_[myHits] = sqrt(myerror.xx());
1160  MonoHitSigY_[myHits] = sqrt(myerror.yy());
1161  MonoHitCorr_[myHits] = myerror.xy() / sqrt(myerror.xx() * myerror.yy());
1162 
1163  MonoHitSignal_[myHits] = Signal;
1164  MonoHitNoise_[myHits] = Noise2;
1165  MonoHitWidth_[myHits] = StripCount;
1166 
1167  MonoDetector_[myHits] = siDetNum;
1168  MonoLayer_[myHits] = siLayerNum;
1169 
1170  ++myHits;
1171  } // of if(myHits < myMaxHits)
1172  // LogDebug("")<< "end of myHits < myMaxHits " ;
1173  } // end if this is the right subdetector
1174  // LogDebug("")<< "end of TIB/TOB check " ;
1175  } // end loop over hits
1176  // LogDebug("")<< " end of loop over hits " ;
1177  NMonoHits_ = myHits;
1178 
1179  numSiMonoHits_->Fill(NMonoHits_);
1180 
1183 
1184  LogDebug("") << " Loop over Matched Hits ";
1185 
1187  myHits = 0;
1188  for (SiStripMatchedRecHit2DCollection::DataContainer::const_iterator hit = matchedHitsHandle->data().begin(),
1189  hitend = matchedHitsHandle->data().end();
1190  hit != hitend;
1191  ++hit) {
1192  DetId id(hit->geographicalId());
1193  if ((hit->geographicalId()).subdetId() == StripSubdetector::TIB ||
1194  (hit->geographicalId()).subdetId() == StripSubdetector::TOB) {
1195  GlobalPoint position = trackerHandle->idToDet(hit->geographicalId())->surface().toGlobal(hit->localPosition());
1196  SiStripMatchedRecHit2D const rechit = *hit;
1197  // LocalPoint myposition = rechit.localPosition() ;
1198  LocalError myerror = rechit.localPositionError();
1199 
1200  // Get layer and subdetector ID here for this hit
1201  // see SiStripRecHitConverter/test/ValHit.cc
1202  Int_t siLayerNum = 0;
1203  Int_t siDetNum = 0;
1204  string siDetName = "";
1205  if ((hit->geographicalId()).subdetId() == StripSubdetector::TIB) {
1206  siLayerNum = tTopo->tibLayer(id);
1207  siDetNum = 1;
1208  siDetName = "TIB";
1209  } else if ((hit->geographicalId()).subdetId() == StripSubdetector::TOB) {
1210  siLayerNum = tTopo->tobLayer(id);
1211  siDetNum = 2;
1212  siDetName = "TOB";
1213  // } else if ( (hit->geographicalId()).subdetId() == StripSubdetector::TID ){
1214  // // should we use side/wheel/ring/module/stereo() ?
1215  // siLayerNum = tTopo->tidWheel(id);
1216  // siDetNum = 3 ;
1217  // siDetName = "TID" ;
1218  // }else if ( (hit->geographicalId()).subdetId() == StripSubdetector::TEC ){
1219  // //choices are side/petal/wheel/ring/module/glued/stereo
1220  // siLayerNum = tTopo->tecWheel(id);
1221  // siDetNum = 4 ;
1222  // siDetName = "TEC" ;
1223  } else {
1224  siLayerNum = -999;
1225  siDetNum = -999;
1226  siDetName = "NULL";
1227  }
1228  // const edm::Ref<edm::DetSetVector<SiStripCluster>, SiStripCluster, edm::refhelper::FindForDetSetVector<SiStripCluster> > clust=rechit.cluster();
1229  double Signal = 0;
1230  double Noise2 = 0;
1231  int StripCount = 0;
1232  // if(clust.isNonnull()) {
1233  // LogDebug("") << " barycenter " << clust->barycenter() ;
1234  // const std::vector<uint16_t> amplitudes=clust->amplitudes();
1235  // for(size_t i = 0 ; i<amplitudes.size(); i++ ){
1236  // Signal +=amplitudes[i] ;
1237  // //ignore for now Noise2 +=SiStripNoiseService_.getNoise(detid,clust->firstStrip()+i)*SiStripNoiseService_.getNoise(detid,clust->firstStrip()+i);
1238  // StripCount++;
1239  // }
1240  // } else {
1241  // LogDebug("") << " null cluster " ;
1242  // }
1243  // LogDebug("") << "Signal " << Signal << " Noise2 " << Noise2 << " StripCount " << StripCount ;
1244 
1245  // Dump position info
1246  // LogDebug("") << " Matched "
1247  // << "local position: "<<myposition.x()<<" "
1248  // << myposition.y()<<" "<<myposition.z()<<"\n"
1249  // << "local error: "<<myerror.xx()<<" "
1250  // << myerror.xy()<<" "<<myerror.yy() << "\n"
1251  // << "global position: " << position.x() << " "
1252  // << position.y()<<" "<< position.z()<<"\n"
1253  // << " siDetNum " << siDetNum
1254  // << " siLayerNum " << siLayerNum ;
1255 
1256  if (myHits < myMaxHits) {
1257  MatchedHitX_[myHits] = position.x();
1258  MatchedHitY_[myHits] = position.y();
1259  MatchedHitZ_[myHits] = position.z();
1260 
1261  MatchedHitR_[myHits] = position.perp();
1262  MatchedHitPhi_[myHits] = position.phi();
1263  MatchedHitTheta_[myHits] = position.theta();
1264 
1265  MatchedHitSigX_[myHits] = sqrt(myerror.xx());
1266  MatchedHitSigY_[myHits] = sqrt(myerror.yy());
1267  MatchedHitCorr_[myHits] = myerror.xy() / sqrt(myerror.xx() * myerror.yy());
1268 
1269  MatchedHitSignal_[myHits] = Signal;
1270  MatchedHitNoise_[myHits] = Noise2;
1271  MatchedHitWidth_[myHits] = StripCount;
1272 
1273  MatchedDetector_[myHits] = siDetNum;
1274  MatchedLayer_[myHits] = siLayerNum;
1275 
1276  ++myHits;
1277  }
1278  } // end if this is the right subdetector (TIB/TOB)
1279  } // end loop over hits
1280  NMatchedHits_ = myHits;
1281 
1283 
1285 
1288  LogDebug("") << "Writing to myTree with " << NShowers_ << " Showers " << NStereoHits_ << " Si StereoHits "
1289  << NMonoHits_ << " Si MonoHits " << NMatchedHits_ << " Si MatchedHits ";
1290 
1291  myTree_->Fill();
1292 
1293 } // end of Analyzer
1294 
1296  LogDebug("") << "Entering endJob ";
1297  file_->cd();
1298  numCand_->Write();
1299  numElectrons_->Write();
1300  numSuperClusters_->Write();
1301 
1302  energySuperClusters_->Write();
1303  sizeSuperClusters_->Write();
1304  emaxSuperClusters_->Write();
1305  phiWidthSuperClusters_->Write();
1306 
1307  energySuperClustersEl_->Write();
1308  sizeSuperClustersEl_->Write();
1309  emaxSuperClustersEl_->Write();
1310  phiWidthSuperClustersEl_->Write();
1311 
1312  ptDiff->Write();
1313  pDiff->Write();
1314  pElectronFailed->Write();
1315  ptElectronFailed->Write();
1316  pElectronPassed->Write();
1317  ptElectronPassed->Write();
1318  sizeSuperClustersPassed->Write();
1319  sizeSuperClustersFailed->Write();
1320  // energySuperClustersPassed->Write();
1321  // energySuperClustersFailed->Write();
1322  // eOverPPassed->Write();
1323  // eOverPFailed->Write();
1324 
1325  numSiStereoHits_->Write();
1326  numSiMonoHits_->Write();
1327  numSiMatchedHits_->Write();
1328 
1329  // disable for large dataset
1330  LogDebug("") << " Writing out ntuple is disabled for now ";
1331  myTree_->Write();
1332 
1333  file_->Close();
1334 }
1335 
1336 //
1337 // const member functions
1338 //
1339 
1340 //
1341 // static member functions
1342 //
#define myMaxHits
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
unsigned int tobLayer(const DetId &id) const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
SiStripElectronAnalyzer(const edm::ParameterSet &)
int init
Definition: HydjetWrapper.h:64
data_type const * data(size_t cell) const
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
ClusterRef cluster() const
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > trackerToken_
float yy() const
Definition: LocalError.h:24
int iEvent
Definition: GenABIO.cc:224
T sqrt(T t)
Definition: SSEVec.h:19
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
static constexpr auto TOB
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:151
const TrackerGeomDet * idToDet(DetId) const override
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:49
#define M_PI
Log< level::Info, false > LogInfo
Definition: init.py:1
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
float xy() const
Definition: LocalError.h:23
LocalError localPositionError() const override
Definition: DetId.h:17
static constexpr auto TIB
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > topoToken_
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
static std::atomic< unsigned int > counter
static int position[264][3]
Definition: ReadPGInfo.cc:289
void analyze(const edm::Event &, const edm::EventSetup &) override
double unwrapPhi(double phi) const
unsigned int tibLayer(const DetId &id) const
#define str(s)
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
float xx() const
Definition: LocalError.h:22
#define LogDebug(id)