CMS 3D CMS Logo

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