CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/RecoEgamma/Examples/plugins/SiStripElectronAnalyzer.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     RecoEgamma/Examples
00004 // Class  :     SiStripElectronAnalyzer
00005 //
00006 // Implementation:
00007 //     <Notes on implementation>
00008 //
00009 // Original Author:  Jim Pivarski
00010 //         Created:  Fri May 26 16:49:38 EDT 2006
00011 // $Id: SiStripElectronAnalyzer.cc,v 1.13 2010/10/19 17:34:56 wmtan Exp $
00012 //
00013 
00014 // system include files
00015 #include <memory>
00016 
00017 // user include files
00018 #include "RecoEgamma/Examples/plugins/SiStripElectronAnalyzer.h"
00019 
00020 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00021 #include "FWCore/Framework/interface/Event.h"
00022 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00023 
00024 #include "DataFormats/Math/interface/Point3D.h"
00025 #include "DataFormats/Common/interface/Handle.h"
00026 #include "FWCore/Framework/interface/ESHandle.h"
00027 #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
00028 #include "DataFormats/EgammaReco/interface/SuperCluster.h"
00029 #include "DataFormats/EgammaReco/interface/BasicCluster.h"
00030 #include "DataFormats/CaloRecHit/interface/CaloClusterFwd.h"
00031 
00032 #include "RecoEcal/EgammaCoreTools/interface/PositionCalc.h"
00033 #include "DataFormats/DetId/interface/DetId.h"
00034 #include "DataFormats/EgammaCandidates/interface/Electron.h"
00035 #include "DataFormats/EgammaCandidates/interface/ElectronFwd.h"
00036 #include "DataFormats/EgammaCandidates/interface/SiStripElectron.h"
00037 #include "DataFormats/EgammaCandidates/interface/SiStripElectronFwd.h"
00038 
00039 // for Si hits
00040 #include "DataFormats/TrackReco/interface/Track.h"
00041 #include "DataFormats/TrackerRecHit2D/interface/SiStripRecHit2DCollection.h"
00042 #include "DataFormats/TrackerRecHit2D/interface/SiStripRecHit2D.h"
00043 #include "DataFormats/TrackerRecHit2D/interface/SiStripMatchedRecHit2DCollection.h"
00044 #include "DataFormats/TrackerRecHit2D/interface/SiStripMatchedRecHit2D.h"
00045 #include "Geometry/CommonDetUnit/interface/GeomDetUnit.h"
00046 #include "Geometry/CommonDetUnit/interface/GeomDetType.h"
00047 #include "Geometry/CommonDetUnit/interface/GeomDetEnumerators.h"
00048 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00049 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00050 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
00051 #include "DataFormats/SiStripDetId/interface/TIBDetId.h"
00052 #include "DataFormats/SiStripDetId/interface/TOBDetId.h"
00053 #include "DataFormats/SiStripDetId/interface/TIDDetId.h"
00054 #include "DataFormats/SiStripDetId/interface/TECDetId.h"
00055 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
00056 #include "DataFormats/TrackerRecHit2D/interface/SiStripRecHit2DCollection.h"
00057 
00058 //
00059 // constants, enums and typedefs
00060 //
00061 
00062 
00063 //
00064 // static data member definitions
00065 //
00066 
00067 //
00068 // constructors and destructor
00069 //
00070 SiStripElectronAnalyzer::SiStripElectronAnalyzer(const edm::ParameterSet& iConfig)
00071 {
00072   //now do what ever initialization is needed
00073   fileName_ = iConfig.getParameter<std::string>("fileName");
00074 
00075   file_ = new TFile(fileName_.c_str(), "RECREATE");
00076   numCand_ = new TH1F("numCandidates", "Number of candidates found", 10, -0.5, 9.5);
00077   numElectrons_ = new TH1F("numElectrons", "Number of Electrons found", 10, -0.5, 9.5);
00078   numSuperClusters_ = new TH1F("numSuperClusters","Number of Ecal SuperClusters", 50, 0, 50);
00079 
00080 
00081   energySuperClusters_= new TH1F("energySuperClusters","Super Cluster Energy - all ", 200 , 0, 2000.);
00082   energySuperClustersEl_= new TH1F("energySuperClustersEl","Super Cluster Energy - Electron Cands ", 200, 0., 2000.);
00083 
00084 
00085   sizeSuperClusters_= new TH1F("sizeSuperClusters","Super Cluster Size - all ", 20, 0, 19);
00086   sizeSuperClustersEl_= new TH1F("sizeSuperClustersEl","Super Cluster Size - Electron Cands ", 20, 0, 19);
00087 
00088   emaxSuperClusters_= new TH1F("emaxSuperClusters","Super Cluster Emax - all ", 200, 0, 2000.);
00089   emaxSuperClustersEl_= new TH1F("emaxSuperClustersEl","Super Cluster Emax - Electron Cands ", 200, 0, 2000.);
00090 
00091   phiWidthSuperClusters_ = new TH1F("phiWidthSuperClusters", "Super Cluster Width - all ",20,  0., 0.05 );
00092   phiWidthSuperClustersEl_ = new TH1F("phiWidthSuperClustersEl", "Super Cluster Width - Electron Cands ", 20 , 0., 0.05 );
00093 
00094 
00095 
00096 
00097 
00098   ptDiff = new TH1F("ptDiff"," ptDiff ", 20, -10.,10.);
00099   pDiff = new TH1F("pDiff"," pDiff ", 100, -50.,50.);
00100 
00101 
00102   pElectronFailed  = new TH1F("pElectronFailed"," pElectronFailed ", 55, 0.,110.);
00103   ptElectronFailed  = new TH1F("ptElectronFailed"," ptElectronFailed ", 55, 0.,110.);
00104 
00105 
00106   pElectronPassed  = new TH1F("pElectronPassed"," pElectronPassed ", 55, 0.,110.);
00107   ptElectronPassed  = new TH1F("ptElectronPassed"," ptElectronPassed ", 55, 0.,110.);
00108 
00109 
00110   sizeSuperClustersFailed= new TH1F("sizeSuperClustersFailed","Super Cluster Size - Failed ", 20, 0, 19);
00111   sizeSuperClustersPassed= new TH1F("sizeSuperClustersPassed","Super Cluster Size - Passed ", 20, 0, 19);
00112 
00113 
00114   energySuperClustersPassed= new TH1F("energySuperClustersPassed","Super Cluster Energy - Passed ", 125, 0, 250.);
00115   energySuperClustersFailed= new TH1F("energySuperClustersFailed","Super Cluster Energy - Failed ", 125, 0, 250.);
00116 
00117 
00118   eOverPFailed = new TH1F("eOverPFailed"," E over P - Failed ", 50, 0, 10.) ;
00119   eOverPPassed = new TH1F("eOverPPassed"," E over P - Passed ", 50, 0, 10.) ;
00120 
00121 
00122 
00123 
00124   numSiStereoHits_ = new TH1F("numSiStereoHits","Number of Si StereoHits",100,0,1000);
00125   numSiMonoHits_ = new TH1F("numSiMonoHits","Number of Si MonoHits",100,0,1000);
00126   numSiMatchedHits_ = new TH1F("numSiMatchedHits","Number of Si MatchedHits",100,0,1000);
00127 
00128 
00129 
00131 
00132 
00133 
00134   mctruthProducer_ = iConfig.getParameter<std::string>("mctruthProducer");
00135   mctruthCollection_ = iConfig.getParameter<std::string>("mctruthCollection");
00136 
00137   superClusterProducer_ = iConfig.getParameter<std::string>("superClusterProducer");
00138   superClusterCollection_ = iConfig.getParameter<std::string>("superClusterCollection");
00139 
00140   eBRecHitProducer_ = iConfig.getParameter<std::string>("recHitProducer");
00141   eBRecHitCollection_ = iConfig.getParameter<std::string>("recHitCollection");
00142 
00143   siElectronProducer_ = iConfig.getParameter<std::string>("siElectronProducer");
00144   siElectronCollection_ = iConfig.getParameter<std::string>("siElectronCollection");
00145 
00146   electronProducer_ = iConfig.getParameter<std::string>("electronProducer");
00147   electronCollection_ = iConfig.getParameter<std::string>("electronCollection");
00148 
00149   siHitProducer_ = iConfig.getParameter<std::string>("siHitProducer");
00150   siRphiHitCollection_ = iConfig.getParameter<std::string>("siRphiHitCollection");
00151   siStereoHitCollection_ = iConfig.getParameter<std::string>("siStereoHitCollection");
00152   siMatchedHitCollection_ = iConfig.getParameter<std::string>("siMatchedHitCollection");
00153 
00154 }
00155 
00156 // SiStripElectronAnalyzer::SiStripElectronAnalyzer(const SiStripElectronAnalyzer& rhs)
00157 // {
00158 //    // do actual copying here;
00159 // }
00160 
00161 SiStripElectronAnalyzer::~SiStripElectronAnalyzer()
00162 {
00163 
00164   // do anything here that needs to be done at desctruction time
00165   // (e.g. close files, deallocate resources etc.)
00166 
00167   file_->Write();
00168   file_->Close();
00169 }
00170 
00171 //
00172 // assignment operators
00173 //
00174 // const SiStripElectronAnalyzer& SiStripElectronAnalyzer::operator=(const SiStripElectronAnalyzer& rhs)
00175 // {
00176 //   //An exception safe implementation is
00177 //   SiStripElectronAnalyzer temp(rhs);
00178 //   swap(rhs);
00179 //
00180 //   return *this;
00181 // }
00182 
00183 //
00184 // member functions
00185 //
00186 // init for TTree
00187 void SiStripElectronAnalyzer::beginJob(){
00188 
00189   myTree_ = new TTree("myTree","my first Tree example");
00190 
00191   myTree_->Branch("NShowers",&NShowers_,"NShowers/I");
00192 
00193 
00194   // first specify the ECAL clusters
00195   // need to explicitly include array length.
00196   myTree_->Branch("EShower",&EShower_,"EShower[1000]/F");
00197   myTree_->Branch("XShower",&XShower_,"XShower[1000]/F");
00198   myTree_->Branch("YShower",&YShower_,"YShower[1000]/F");
00199   myTree_->Branch("ZShower",&ZShower_,"ZShower[1000]/F");
00200 
00201   // second specify the Si Stereo Hits
00202   myTree_->Branch("NStereoHits",&NStereoHits_,"NStereoHits/I");
00203   myTree_->Branch("StereoHitX",&StereoHitX_,"StereoHitX[1000]/F");
00204   myTree_->Branch("StereoHitY",&StereoHitY_,"StereoHitY[1000]/F");
00205   myTree_->Branch("StereoHitZ",&StereoHitZ_,"StereoHitZ[1000]/F");
00206 
00207   myTree_->Branch("StereoHitR",&StereoHitR_,"StereoHitR[1000]/F");
00208   myTree_->Branch("StereoHitPhi",&StereoHitPhi_,"StereoHitPhi[1000]/F");
00209   myTree_->Branch("StereoHitTheta",&StereoHitTheta_,"StereoHitTheta[1000]/F");
00210 
00211   myTree_->Branch("StereoHitSigX",&StereoHitSigX_,"StereoHitSigX[1000]/F");
00212   myTree_->Branch("StereoHitSigY",&StereoHitSigY_,"StereoHitSigY[1000]/F");
00213   myTree_->Branch("StereoHitCorr",&StereoHitCorr_,"StereoHitCorr[1000]/F");
00214 
00215   myTree_->Branch("StereoHitSignal",&StereoHitSignal_,"StereoHitSignal[1000]/F");
00216   myTree_->Branch("StereoHitNoise",&StereoHitNoise_,"StereoHitNoise[1000]/F");
00217   myTree_->Branch("StereoHitWidth",&StereoHitWidth_,"StereoHitWidth[1000]/I");
00218 
00219   myTree_->Branch("StereoDetector",&StereoDetector_,"StereoDetector[1000]/I");
00220   myTree_->Branch("StereoLayer",&StereoLayer_,"StereoLayer[1000]/I");
00221 
00222 
00223   // specify the Si mono (rphi) hits
00224   myTree_->Branch("NMonoHits",&NMonoHits_,"NMonoHits/I");
00225   myTree_->Branch("MonoHitX",&MonoHitX_,"MonoHitX[1000]/F");
00226   myTree_->Branch("MonoHitY",&MonoHitY_,"MonoHitY[1000]/F");
00227   myTree_->Branch("MonoHitZ",&MonoHitZ_,"MonoHitZ[1000]/F");
00228 
00229 
00230   myTree_->Branch("MonoHitR",&MonoHitR_,"MonoHitR[1000]/F");
00231   myTree_->Branch("MonoHitPhi",&MonoHitPhi_,"MonoHitPhi[1000]/F");
00232   myTree_->Branch("MonoHitTheta",&MonoHitTheta_,"MonoHitTheta[1000]/F");
00233 
00234   myTree_->Branch("MonoHitSigX",&MonoHitSigX_,"MonoHitSigX[1000]/F");
00235   myTree_->Branch("MonoHitSigY",&MonoHitSigY_,"MonoHitSigY[1000]/F");
00236   myTree_->Branch("MonoHitCorr",&MonoHitCorr_,"MonoHitCorr[1000]/F");
00237 
00238   myTree_->Branch("MonoHitSignal",&MonoHitSignal_,"MonoHitSignal[1000]/F");
00239   myTree_->Branch("MonoHitNoise",&MonoHitNoise_,"MonoHitNoise[1000]/F");
00240   myTree_->Branch("MonoHitWidth",&MonoHitWidth_,"MonoHitWidth[1000]/I");
00241 
00242   myTree_->Branch("MonoDetector",&MonoDetector_,"MonoDetector[1000]/I");
00243   myTree_->Branch("MonoLayer",&MonoLayer_,"MonoLayer[1000]/I");
00244 
00245   // specify the Si matched (rphi) hits
00246   myTree_->Branch("NMatchedHits",&NMatchedHits_,"NMatchedHits/I");
00247   myTree_->Branch("MatchedHitX",&MatchedHitX_,"MatchedHitX[1000]/F");
00248   myTree_->Branch("MatchedHitY",&MatchedHitY_,"MatchedHitY[1000]/F");
00249   myTree_->Branch("MatchedHitZ",&MatchedHitZ_,"MatchedHitZ[1000]/F");
00250 
00251   myTree_->Branch("MatchedHitR",&MatchedHitR_,"MatchedHitR[1000]/F");
00252   myTree_->Branch("MatchedHitPhi",&MatchedHitPhi_,"MatchedHitPhi[1000]/F");
00253   myTree_->Branch("MatchedHitTheta",&MatchedHitTheta_,"MatchedHitTheta[1000]/F");
00254 
00255   myTree_->Branch("MatchedHitSigX",&MatchedHitSigX_,"MatchedHitSigX[1000]/F");
00256   myTree_->Branch("MatchedHitSigY",&MatchedHitSigY_,"MatchedHitSigY[1000]/F");
00257   myTree_->Branch("MatchedHitCorr",&MatchedHitCorr_,"MatchedHitCorr[1000]/F");
00258 
00259   myTree_->Branch("MatchedHitSignal",&MatchedHitSignal_,"MatchedHitSignal[1000]/F");
00260   myTree_->Branch("MatchedHitNoise",&MatchedHitNoise_,"MatchedHitNoise[1000]/F");
00261   myTree_->Branch("MatchedHitWidth",&MatchedHitWidth_,"MatchedHitWidth[1000]/I");
00262 
00263   myTree_->Branch("MatchedDetector",&MatchedDetector_,"MatchedDetector[1000]/I");
00264   myTree_->Branch("MatchedLayer",&MatchedLayer_,"MatchedLayer[1000]/I");
00265 
00266 }
00267 
00268 void SiStripElectronAnalyzer::initNtuple(){
00269 
00270   LogDebug("") << " In initNtuple " ;
00271 
00272   NShowers_ = -999 ;
00273   for (int init = 0 ; init < myMaxHits ; ++init){
00274     EShower_[init] = -999.;
00275     XShower_[init] = -999.;
00276     YShower_[init] = -999.;
00277     ZShower_[init] = -999.;
00278   }
00279   NStereoHits_ = -999 ;
00280 
00281   for (int init = 0 ; init < myMaxHits ; ++init){
00282     StereoHitX_[init] = -999.;
00283     StereoHitY_[init] = -999.;
00284     StereoHitZ_[init] = -999.;
00285     StereoHitR_[init] = -999.;
00286     StereoHitPhi_[init] = -999.;
00287     StereoHitTheta_[init] = -999.;
00288 
00289     StereoHitSignal_[init] = -999.;
00290     StereoHitNoise_[init] = -999.;
00291     StereoHitWidth_[init] = -999 ;;
00292   }
00293 
00294   NMonoHits_ = -999 ;
00295   for (int init = 0 ; init < myMaxHits ; ++init){
00296     MonoHitX_[init] = -999.;
00297     MonoHitY_[init] = -999.;
00298     MonoHitZ_[init] = -999.;
00299     MonoHitR_[init] = -999.;
00300     MonoHitPhi_[init] = -999.;
00301     MonoHitTheta_[init] = -999.;
00302 
00303     MonoHitSignal_[init] = -999.;
00304     MonoHitNoise_[init] = -999.;
00305     MonoHitWidth_[init] = -999 ;;
00306   }
00307 
00308   NMatchedHits_ = -999 ;
00309   for (int init = 0 ; init < myMaxHits ; ++init){
00310     MatchedHitX_[init] = -999.;
00311     MatchedHitY_[init] = -999.;
00312     MatchedHitZ_[init] = -999.;
00313     MatchedHitR_[init] = -999.;
00314     MatchedHitPhi_[init] = -999.;
00315     MatchedHitTheta_[init] = -999.;
00316 
00317     MatchedHitSignal_[init] = -999.;
00318     MatchedHitNoise_[init] = -999.;
00319     MatchedHitWidth_[init] = -999 ;;
00320   }
00321 
00322 
00323 
00324 }
00325 
00326 // ------------ method called to produce the data  ------------
00327 void
00328 SiStripElectronAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00329 {
00330   using namespace std;  // so you can say "cout" and "endl"
00331 
00332   initNtuple();
00333 
00334 
00335   // https://cmsdoc.cern.ch/swdev/lxr/CMSSW/source/clhep/CLHEP/HepMC/GenParticle.h
00336   // https://cmsdoc.cern.ch/swdev/lxr/CMSSW/source/clhep/CLHEP/HepMC/GenVertex.h
00337   // removed by JED - causes trouble in release post 0_9_0
00338   //   edm::Handle<edm::HepMCProduct> mctruthHandle;
00339   //   iEvent.getByLabel(mctruthProducer_, mctruthCollection_, mctruthHandle);
00340   //   HepMC::GenEvent mctruth = mctruthHandle->getHepMCData();
00341 
00342   //   for (HepMC::GenEvent::particle_const_iterator partIter = mctruth.particles_begin();
00343   //    partIter != mctruth.particles_end();
00344   //    ++partIter) {
00345   // //    for (HepMC::GenEvent::vertex_const_iterator vertIter = mctruth.vertices_begin();
00346   // //         vertIter != mctruth.vertices_end();
00347   // //         ++vertIter) {
00348   //    CLHEP::HepLorentzVector creation = (*partIter)->CreationVertex();
00349   //    CLHEP::HepLorentzVector momentum = (*partIter)->Momentum();
00350   //   HepPDT::ParticleID id = (*partIter)->particleID();  // electrons and positrons are 11 and -11
00351   //     edm::LogInfo("") << "MC particle id " << id.pid() << ", creationVertex " << creation << " cm, initialMomentum " << momentum << " GeV/c" << endl;
00352   //  }
00353 
00354   // load the rechits for the Ecal
00355   edm::Handle<EcalRecHitCollection> pRecHits;
00356   iEvent.getByLabel(eBRecHitProducer_, eBRecHitCollection_, pRecHits);
00357   // Create a pointer to the RecHits  - unused for now
00358   //  const EcalRecHitCollection *hitCollection = pRecHits.product();
00359 
00360 
00361   // https://cmsdoc.cern.ch/swdev/lxr/CMSSW/source/self/DataFormats/EgammaReco/interface/SuperCluster.h
00362   edm::Handle<reco::SuperClusterCollection> clusterHandle;
00363   iEvent.getByLabel(superClusterProducer_, superClusterCollection_, clusterHandle);
00364 
00365 
00368 
00369   LogDebug("") << " Start loop over "
00370                << clusterHandle->end()-clusterHandle->begin()
00371                << "  superClusters " ;
00372 
00373   for (reco::SuperClusterCollection::const_iterator clusterIter = clusterHandle->begin();
00374        clusterIter != clusterHandle->end();
00375        ++clusterIter) {
00376     double energy = clusterIter->energy();
00377     math::XYZPoint position = clusterIter->position();
00378     std::ostringstream str;
00379 
00380     str  << " SuperCluster " << energy << " GeV, position "
00381          << position << " cm" << "\n" ;
00382 
00383     energySuperClusters_->Fill(energy);
00384     sizeSuperClusters_->Fill(clusterIter->clustersSize());
00385     // this only makes sense for hybrid superclusters
00386 
00387     // try to point to the constituent clusters for this SuperCluster
00388 
00389     str << "About to loop over basicClusters" << "\n" ;
00390 
00391     double emaxSuperCluster = 0. ;
00392     double phibar = 0. ;
00393     double phi2bar = 0. ;
00394     double eTotSuperCluster = 0. ;
00395 
00396 
00397 
00398     for (reco::CaloCluster_iterator basicClusterIter = clusterIter->clustersBegin() ;
00399          basicClusterIter != clusterIter->clustersEnd() ;
00400          ++basicClusterIter ){
00401 
00402       //std::vector<DetId> theIds= (*basicClusterIter)->getHitsByDetId();
00403 
00404       str << " basicCluster Energy " << (*basicClusterIter)->energy()
00405           << " Position " << (*basicClusterIter)->position()
00406           << " \n"
00407           << "        Position phi " << (*basicClusterIter)->position().phi()
00408           << " recHits " << (*basicClusterIter)->size()
00409           << " \n" ;
00410 
00411       double eCluster =  (*basicClusterIter)->energy();
00412       if(eCluster > emaxSuperCluster  ){
00413         emaxSuperCluster = eCluster ;
00414       }
00415       eTotSuperCluster += eCluster ;
00416       double phiCluster = (*basicClusterIter)->position().phi() ;
00417       phibar += eCluster * phiCluster ;
00418       phi2bar += eCluster * phiCluster * phiCluster ;
00419 
00420 
00421     } // end of basicClusterIter loop
00422 
00423 
00424 
00425     phibar= phibar /eTotSuperCluster ;
00426     phi2bar= phi2bar /eTotSuperCluster ;
00427     double phiWidth = phi2bar - phibar*phibar ;
00428     if(phiWidth>0.) {
00429       phiWidth = std::pow(phiWidth,0.5);
00430     }else{
00431       phiWidth =0.;
00432     }
00433     str << " SuperCluster stats " << "\n" ;
00434     str << "phibar " << phibar
00435         << " phi2bar " << phi2bar
00436         << " eTotSuperCluster " << eTotSuperCluster
00437         << " phiWidth " << phiWidth
00438         << std::endl  ;
00439 
00440     phiWidthSuperClusters_->Fill(phiWidth);
00441 
00442     emaxSuperClusters_->Fill(emaxSuperCluster);
00443 
00444     str << " Done with this SuperCluster " << std::endl;
00445 
00446     LogDebug("") << str.str() ;
00447 
00448   } // end of loop over superClusters
00449 
00450   LogDebug("") << " End loop over superClusters ";
00451 
00454 
00455 
00457   //
00458   // loop over all EcalRecHits and print out their x,y,z,E
00459   //  edm::LogInfo("") << " Dumping all recHits in this event " << endl ;
00460   // for(EcalRecHitCollection::const_iterator _blah = hitCollection->begin();
00461   //     _blah != hitCollection->end() ; ++_blah ) {
00462   //   edm::LogInfo("") << "Ecal RecHit Energy: " << _blah->energy() << endl ;
00463   //   //      " Position " << _blah.position() << endl ;
00464   //  }
00465   //
00466   //  edm::LogInfo("") << "Dump finished " << endl ;
00467   //
00469 
00470 
00471 
00472 
00473   // DataFormats/EgammaCandidates/src/SiStripElectron.cc
00474   edm::Handle<reco::SiStripElectronCollection> siStripElectronHandle;
00475   iEvent.getByLabel(siElectronProducer_, siElectronCollection_, siStripElectronHandle);
00476 
00477 
00478 
00480 
00481 
00482   LogDebug("") << " Dumping Algo's guess of SiStripElectron Candidate Info " ;
00483   int numberOfElectrons = 0;
00484   // need to check if fit succeeded
00485   LogDebug("") << " Number of SiStripElectrons  " << siStripElectronHandle->size() ;
00486 
00487 
00488   for (reco::SiStripElectronCollection::const_iterator electronIter = siStripElectronHandle->begin();
00489        electronIter != siStripElectronHandle->end();  ++electronIter) {
00490 
00491 
00492     LogDebug("")  << "about to get stuff from electroncandidate "
00493                   << numberOfElectrons << "\n"
00494                   << "supercluster energy = "
00495                   << electronIter->superCluster()->energy() << "\n"
00496                   << "fit results are phi(r) = "
00497                   << electronIter->phiAtOrigin() << " + "
00498                   << electronIter->phiVsRSlope() << "*r" << "\n"
00499                   << " chi2 " << electronIter->chi2()
00500                   << " ndof " << electronIter->ndof() << "\n"
00501                   << " Pt " << electronIter->pt() << "\n"
00502                   << "P, Px, Py, Pz  "
00503                   << electronIter->p() << " "
00504                   << electronIter->px() << " "
00505                   << electronIter->py() << " "
00506                   << electronIter->pz() << "\n"
00507                   << "you get the idea..." ;
00508 
00509     // make plots for supercluster that an electron has been associ w/. here
00510     energySuperClustersEl_->Fill(electronIter->superCluster()->energy());
00511     sizeSuperClustersEl_->Fill(electronIter->superCluster()->clustersSize());
00512 
00513     // loop over basicClusters to get energy
00514     double emaxSuperCluster = 0. ;
00515     double phibar = 0. ;
00516     double phi2bar = 0. ;
00517     double eTotSuperCluster = 0. ;
00518 
00519     for (reco::CaloCluster_iterator basicClusterIter = electronIter->superCluster()->clustersBegin() ;
00520          basicClusterIter != electronIter->superCluster()->clustersEnd() ;
00521          ++basicClusterIter ){
00522 
00523       //std::vector<DetId> theIds= (*basicClusterIter)->getHitsByDetId();
00524 
00525       double eCluster =  (*basicClusterIter)->energy();
00526       if(eCluster > emaxSuperCluster  ){
00527         emaxSuperCluster = eCluster ;
00528       }
00529       eTotSuperCluster += eCluster ;
00530       double phiCluster = (*basicClusterIter)->position().phi() ;
00531       phibar += eCluster * phiCluster ;
00532       phi2bar += eCluster * phiCluster * phiCluster ;
00533 
00534     }
00535 
00536     phibar=phibar/eTotSuperCluster ;
00537     phi2bar=phi2bar/eTotSuperCluster ;
00538     double phiWidth = phi2bar - phibar*phibar ;
00539     if(phiWidth>0.) {
00540       phiWidth = std::pow(phiWidth,0.5);
00541     }else{
00542       phiWidth =0.;
00543     }
00544 
00545     phiWidthSuperClustersEl_->Fill(phiWidth);
00546 
00547     emaxSuperClustersEl_->Fill(emaxSuperCluster);
00548 
00549     numberOfElectrons++;
00550   }
00551 
00552   numCand_->Fill(siStripElectronHandle->size());
00553 
00555 
00556 
00557 
00558   // Now loop over the electrons (ie the fitted things.)
00559 
00560   LogDebug("")<< " About to check Electrons" ;
00561 
00562   edm::Handle<reco::ElectronCollection> electrons ;
00563   iEvent.getByLabel(electronProducer_, electronCollection_, electrons);
00564 
00565   numElectrons_->Fill(electrons->end()- electrons->begin());
00566 
00567   // set up vector of bool for SiStrips having or not having Electrons
00568   // this causes a warning because of variable array size at compilation time ;
00569   // BAD  bool hasElectron_[siStripElectronHandle->end()- siStripElectronHandle->begin()] ;
00570   bool* hasElectron_ = new bool[siStripElectronHandle->end()- siStripElectronHandle->begin()] ;
00571   for (int icount = 0 ;
00572        icount < siStripElectronHandle->end()- siStripElectronHandle->begin() ;
00573        ++icount)
00574     { hasElectron_[icount] = false ;}
00575 
00576   // also set up a counter to associate the ith electron to the jth strippy
00577   // Electron_to_strippy[i] = j: i-th Electron is j-th strippy
00578   // BAD  unsigned int Electron_to_strippy[electrons->end()- electrons->begin()];
00579   unsigned int* Electron_to_strippy = new unsigned int[electrons->end()- electrons->begin()];
00580   for (int icount = 0 ;
00581        icount <electrons->end()- electrons->begin();  ++icount)
00582     { Electron_to_strippy[icount] = 0 ;}
00583 
00584   unsigned int ecount=0 ;
00585   for (reco::ElectronCollection::const_iterator electronIter = electrons->begin();
00586        electronIter != electrons->end(); ++electronIter ){
00587 
00588 
00589     LogDebug("")<< " Associating Electrons to Strippies " ;
00590     LogDebug("")<< " PT is " << electronIter->track()->pt() ;
00591 
00592     reco::TrackRef tr =(*electronIter).track();
00593     uint32_t id = (*electronIter->track()->recHitsBegin())->geographicalId().rawId();
00594     LocalPoint pos = (*electronIter->track()->recHitsBegin())->localPosition();
00595 
00596     unsigned int icount = 0 ;
00597     LogDebug("") << " About to loop over Strippies " << " \n "
00598                  << " icount " << icount
00599                  << " max " << siStripElectronHandle->end()- siStripElectronHandle->begin() ;
00600 
00601     for (reco::SiStripElectronCollection::const_iterator strippyiter = siStripElectronHandle->begin();
00602          strippyiter != siStripElectronHandle->end(); ++strippyiter) {
00603 
00604       bool hitInCommon = false;
00605       // loop over rphi hits
00606       for (std::vector<SiStripRecHit2D>::const_iterator
00607              hiter = strippyiter->rphiRecHits().begin();
00608            hiter != strippyiter->rphiRecHits().end();
00609            ++hiter) {
00610         if (hiter->geographicalId().rawId() == id  &&
00611             (hiter->localPosition() - pos).mag() < 1e-10) {
00612           hitInCommon = true;
00613           break;
00614         }
00615       }
00616 
00617       for (std::vector<SiStripRecHit2D>::const_iterator
00618              hiter = strippyiter->stereoRecHits().begin();
00619            hiter != strippyiter->stereoRecHits().end();
00620            ++hiter) {
00621         if (hiter->geographicalId().rawId() == id  &&
00622             (hiter->localPosition() - pos).mag() < 1e-10) {
00623           hitInCommon = true;
00624           break;
00625         }
00626       }
00627       if (hitInCommon) {  //this Electron belongs to this SiStripElectron.
00628         hasElectron_[icount] = true ;
00629         Electron_to_strippy[ecount]= icount ;
00630         ptDiff->Fill( std::abs(electronIter->track()->pt()) - std::abs(strippyiter->pt()) );
00631         pDiff->Fill( std::abs(electronIter->track()->p()) - std::abs(strippyiter->p()) );
00632 
00633       }
00634       icount++ ;
00635     } // Sistrip loop
00636     ecount++;
00637   } // Electrons
00638 
00639   LogDebug("") << " Done looping over Electrons " ;
00640 
00641 
00642   unsigned int counter = 0 ;
00643   for (reco::SiStripElectronCollection::const_iterator strippyIter = siStripElectronHandle->begin();  strippyIter != siStripElectronHandle->end();  ++strippyIter) {
00644 
00645 
00646     bool skipThis = !hasElectron_[counter] ;
00647     if( skipThis ) {
00648       // plot stuff for SIStripElectrons that don't have fits associated
00649 
00650       LogDebug("") << " SiStrip Failed Electron " << " \n " <<
00651         " p " << strippyIter->p() << " \n " <<
00652         " pt " << strippyIter->pt() << " \n " <<
00653         " SuperClust size " << strippyIter->superCluster()->clustersSize() ;
00654 
00655       pElectronFailed->Fill( std::abs(strippyIter->p()) );
00656       ptElectronFailed->Fill( std::abs(strippyIter->pt()) );
00657       sizeSuperClustersFailed->Fill(strippyIter->superCluster()->clustersSize());
00658       LogDebug("") << " done filling Failed histos " ;
00659       //      energySuperClustersFailed->Fill(strippyIter->superCluster()->energy());
00660       //       if(strippyIter->p()>0.) {
00661       //        eOverPFailed->Fill(strippyIter->superCluster()->energy()/strippyIter->p());
00662       //       }else {
00663       //        eOverPFailed->Fill(-1.0);
00664       //       }
00665 
00666     } else {
00667       LogDebug("") << " SiStrip Passed Electron " << " \n " <<
00668         " p " << strippyIter->p() << " \n " <<
00669         " pt " << strippyIter->pt() << " \n " <<
00670         " SuperClust size " << strippyIter->superCluster()->clustersSize() ;
00671       pElectronPassed->Fill( std::abs(strippyIter->p()) );
00672       ptElectronPassed->Fill( std::abs(strippyIter->pt()) );
00673       sizeSuperClustersPassed->Fill(strippyIter->superCluster()->clustersSize());
00674       LogDebug("") << " done filling passed histos " ;
00675       //      energySuperClustersPassed->Fill(strippyIter->superCluster()->energy());
00676       //       if(strippyIter->p()>0.) {
00677       //        eOverPPassed->Fill(strippyIter->superCluster()->energy()/strippyIter->p());
00678       //       }else {
00679       //        eOverPPassed->Fill(-1.0);
00680       //       }
00681 
00682     } // skipThis
00683     counter++;
00684   }
00685 
00686   LogDebug("")<< "Dump info for all electrons ";
00687 
00688   for (reco::ElectronCollection::const_iterator electronIter1 = electrons->begin();
00689        electronIter1 != electrons->end(); ++electronIter1 ){
00690     reco::TrackRef tr1 =(*electronIter1).track();
00691     // let's find its associated SiStripElectron and SuperCluster
00692     unsigned int ecount1= electronIter1-electrons->begin() ;
00693     unsigned int stripCount1 = 0 ;
00694     reco::SiStripElectronCollection::const_iterator strippyIter1 ;
00695     for (reco::SiStripElectronCollection::const_iterator strippyIter = siStripElectronHandle->begin();
00696          strippyIter != siStripElectronHandle->end();  ++strippyIter) {
00697       if(Electron_to_strippy[ecount1]==stripCount1 ) {
00698         strippyIter1 = strippyIter ;
00699         break ; }
00700       stripCount1++ ;
00701     } // strippy loop
00702     ecount1++;
00703 
00704     std::ostringstream str;
00705 
00706 
00707     str << " SiStripElect p , px, py, pz " << strippyIter1->p()
00708         << "  " << strippyIter1->px()
00709         << "  " << strippyIter1->py()
00710         << "  " << strippyIter1->pz()
00711         << "\n " << std::endl ;
00712 
00713 
00714     str  << " Electron p px, py, pz,  = " << tr1->p()
00715          << "  " << tr1->px()
00716          << "  " << tr1->py()
00717          << "  " << tr1->pz()
00718          << "\n" <<  std::endl ;
00719 
00720 
00721     double EClust1 = strippyIter1->superCluster()->energy() ;
00722     double XClust1 = strippyIter1->superCluster()->x();
00723     double YClust1 = strippyIter1->superCluster()->y();
00724     double ZClust1 = strippyIter1->superCluster()->z();
00725 
00726     double rho1 = sqrt(XClust1*XClust1+YClust1*YClust1+ZClust1*ZClust1) ;
00727     double costheta1 = ZClust1/rho1 ;
00728     double sintheta1 = sqrt(1-costheta1*costheta1);
00729     if(ZClust1<0 ) { sintheta1 = - sintheta1 ; }
00730     double cosphi1 = XClust1/sqrt(XClust1*XClust1+YClust1*YClust1);
00731     double sinphi1 = YClust1/sqrt(XClust1*XClust1+YClust1*YClust1);
00732 
00733     str << " Ecal for electron E, px, py, pz "
00734         << EClust1 << " "
00735         << EClust1*sintheta1*cosphi1 << " "
00736         << EClust1*sintheta1*sinphi1  << " "
00737         << EClust1*costheta1
00738         << "\n" << std::endl ;
00739 
00740     LogDebug("") << str.str() ;
00741 
00742   } // loop over electrons
00743  LogDebug("")<< "Done Dumping info for all electrons ";
00744 
00746   // LogDebug("")<< " Checking Electrons" ;
00747   //  LogDebug("")<< " PT is " << electronIter->track()->pt() ;
00748   //    reco::TrackRef tr =(*electronIter).track();
00750   if(electrons->end()-electrons->begin()> 1) {
00751     edm::LogInfo("") << " Two electrons in this event " << std::endl;
00752     for (reco::ElectronCollection::const_iterator electronIter1 = electrons->begin();
00753          electronIter1 != electrons->end()-1; ++electronIter1 ){
00754       reco::TrackRef tr1 =(*electronIter1).track();
00755 
00756       // let's find its associated SiStripElectron and SuperCluster
00757       // use the Electron_to_strippy[] array
00758       unsigned int ecount1= electronIter1-electrons->begin() ;
00759       // loop over strippies to find the corresponding one
00760       unsigned int stripCount1 = 0 ;
00761       reco::SiStripElectronCollection::const_iterator strippyIter1 ;
00762       for (reco::SiStripElectronCollection::const_iterator strippyIter = siStripElectronHandle->begin();  strippyIter != siStripElectronHandle->end();  ++strippyIter) {
00763         if(Electron_to_strippy[ecount1]==stripCount1 ) {
00764           strippyIter1 = strippyIter ;
00765           break ; }
00766         stripCount1++ ;
00767       } // strippy loop
00768 
00769       double EClust1 = strippyIter1->superCluster()->energy() ;
00770       double XClust1 = strippyIter1->superCluster()->x();
00771       double YClust1 = strippyIter1->superCluster()->y();
00772       double ZClust1 = strippyIter1->superCluster()->z();
00773 
00774       for (reco::ElectronCollection::const_iterator electronIter2 = electronIter1+1;
00775            electronIter2 != electrons->end(); ++electronIter2 ){
00776 
00777         reco::TrackRef tr2 =(*electronIter2).track();
00778 
00779         unsigned int ecount2= electronIter2-electrons->begin() ;
00780         unsigned int stripCount2 = 0 ;
00781         reco::SiStripElectronCollection::const_iterator strippyIter2 ;
00782         for (reco::SiStripElectronCollection::const_iterator strippyIter = siStripElectronHandle->begin();  strippyIter != siStripElectronHandle->end();  ++strippyIter) {
00783           if(Electron_to_strippy[ecount2]==stripCount2 ) {
00784             strippyIter2 = strippyIter ;
00785             break ; }
00786           stripCount2++ ;
00787         } // strippy loop
00788 
00789 
00790 
00791         double EClust2 = strippyIter2->superCluster()->energy() ;
00792         double XClust2 = strippyIter2->superCluster()->x();
00793         double YClust2 = strippyIter2->superCluster()->y();
00794         double ZClust2 = strippyIter2->superCluster()->z();
00795 
00796 
00797         // now get supercluster from this:
00798 
00799 
00800         edm::LogInfo("")  << " Electron p1 = " << tr1->p()
00801                           << " p1x " << tr1->px()
00802                           << " p1y " << tr1->py()
00803                           << " p1z " << tr1->pz()
00804                           << std::endl ;
00805 
00806 
00807         edm::LogInfo("")  << " Electron p2 = " << tr2->p()
00808                           << " p2x " << tr2->px()
00809                           << " p2y " << tr2->py()
00810                           << " p2z " << tr2->pz()
00811                           << std::endl ;
00812 
00813 
00814         // combine the two in an (e,e) pair
00815         double Zpx = tr1->px()+tr2->px() ;
00816         double Zpy = tr1->py()+tr2->py() ;
00817         double Zpz = tr1->pz()+tr2->pz() ;
00818         double Ze = std::abs(tr1->p())+std::abs(tr2->p()) ;
00819         edm::LogInfo("") << " Z mass " <<
00820           sqrt(Ze*Ze-Zpx*Zpx-Zpy*Zpy-Zpz*Zpz) << std::endl ;
00821 
00822         // combine the SuperClusts into a Z
00823         double rho1 = sqrt(XClust1*XClust1+YClust1*YClust1+ZClust1*ZClust1) ;
00824         double costheta1 = ZClust1/rho1 ;
00825         double sintheta1 = sqrt(1-costheta1*costheta1);
00826         if(ZClust1<0 ) { sintheta1 = - sintheta1 ; }
00827         double cosphi1 = XClust1/sqrt(XClust1*XClust1+YClust1*YClust1);
00828         double sinphi1 = YClust1/sqrt(XClust1*XClust1+YClust1*YClust1);
00829 
00830         double rho2 = sqrt(XClust2*XClust2+YClust2*YClust2+ZClust2*ZClust2) ;
00831         double costheta2 = ZClust2/rho2 ;
00832         double sintheta2 = sqrt(1-costheta2*costheta2);
00833         if(ZClust2<0 ) { sintheta2 = - sintheta2 ; }
00834         double cosphi2 = XClust2/sqrt(XClust2*XClust2+YClust2*YClust2);
00835         double sinphi2 = YClust2/sqrt(XClust2*XClust2+YClust2*YClust2);
00836 
00837         edm::LogInfo("") << "Energy of supercluster for 1st electron "
00838                          << EClust1 << " "
00839                          << EClust1*sintheta1*cosphi1 << " "
00840                          << EClust1*sintheta1*sinphi1  << " "
00841                          << EClust1*costheta1  << " "
00842                          << std::endl ;
00843 
00844         edm::LogInfo("") << "Energy of supercluster for 2nd electron "
00845                          << EClust2 << " "
00846                          << EClust2*sintheta2*cosphi2 << " "
00847                          << EClust2*sintheta2*sinphi2  << " "
00848                          << EClust2*costheta2  << " "
00849                          << std::endl ;
00850 
00851 
00852         // get the supercluster pair
00853         double Zgpx = EClust1*sintheta1*cosphi1+EClust2*sintheta2*cosphi2 ;
00854         double Zgpy = EClust1*sintheta1*sinphi1+EClust2*sintheta2*sinphi2 ;
00855         double Zgpz = EClust1*costheta1+EClust2*costheta2 ;
00856         double ZgE = EClust1+EClust2 ;
00857 
00858         edm::LogInfo("") << " Z mass from ECAL " <<
00859           sqrt(ZgE*ZgE-Zgpx*Zgpx-Zgpy*Zgpy-Zgpz*Zgpz) << std::endl ;
00860 
00861 
00862       } //inner loop
00863     } // outer loop
00864   }// m(ee) loop
00865 
00866   delete[] hasElectron_;
00867   delete[] Electron_to_strippy;
00868 
00872   LogDebug("") << " About to dump tracker info " ;
00873 
00874   edm::ESHandle<TrackerGeometry> trackerHandle;
00875   iSetup.get<TrackerDigiGeometryRecord>().get(trackerHandle);
00876 
00877   edm::Handle<SiStripRecHit2DCollection> rphiHitsHandle;
00878   iEvent.getByLabel(siHitProducer_, siRphiHitCollection_, rphiHitsHandle);
00879 
00880   edm::Handle<SiStripRecHit2DCollection> stereoHitsHandle;
00881   iEvent.getByLabel(siHitProducer_, siStereoHitCollection_, stereoHitsHandle);
00882 
00883   edm::Handle<SiStripMatchedRecHit2DCollection> matchedHitsHandle;
00884   iEvent.getByLabel(siHitProducer_, siMatchedHitCollection_, matchedHitsHandle);
00885 
00887 
00889   NShowers_=0 ;
00890   for (reco::SuperClusterCollection::const_iterator clusterIter = clusterHandle->begin();
00891        clusterIter != clusterHandle->end();
00892        ++clusterIter) {
00893     double energy = clusterIter->energy();
00894     math::XYZPoint position = clusterIter->position();
00895     if(NShowers_ < myMaxHits ) {
00896       EShower_[NShowers_] = energy ;
00897       XShower_[NShowers_] = position.x() ;
00898       YShower_[NShowers_] = position.y() ;
00899       ZShower_[NShowers_] = position.z() ;
00900       ++NShowers_ ;
00901     }
00902     // Loop over all crystals in this supercluster - see
00903     // RecoEcal/EgamaClusterProducers/src/EgammaSimpleAnalyzer.cc
00904     // Look also at DataFormats/EgammaReco/interface/SuperCluster.h
00905 
00906   }
00907   numSuperClusters_->Fill(NShowers_);
00909 
00910 
00911   LogDebug("") << " Looping over stereo hits " ;
00912 
00913 
00915   int myHits = 0 ;
00916   for (SiStripRecHit2DCollection::DataContainer::const_iterator hit = stereoHitsHandle->data().begin(), hitend = stereoHitsHandle->data().end();
00917           hit != hitend;  ++hit) {
00918       DetId id(hit->geographicalId());
00919       if( (hit->geographicalId()).subdetId() == StripSubdetector::TIB  ||
00920           (hit->geographicalId()).subdetId() == StripSubdetector::TOB    ) {
00921         GlobalPoint position = trackerHandle->idToDet(hit->geographicalId())->surface().toGlobal(hit->localPosition());
00922         //from RecoLocalTracker/SiStripClusterizer/test/TestCluster.cc
00923         // cf also TrackHitAssociator.cc SiStripRecHitMatcher.cc SiStrip1DMeasurementTransformator.cc (KalmanUpdators)
00924         SiStripRecHit2D const rechit = *hit ;
00925         //      LocalPoint myposition = rechit.localPosition() ;
00926         LocalError myerror = rechit.localPositionError();
00927 
00928         // Get layer and subdetector ID here for this hit
00929         // see SiStripRecHitConverter/test/ValHit.cc
00930         Int_t siLayerNum = 0 ;
00931         Int_t siDetNum = 0 ;
00932         string siDetName = "" ;
00933         if( (hit->geographicalId()).subdetId() == StripSubdetector::TIB ){
00934           //       siLayerNum = TIBDetId(rechit->geographicalID()).layer();
00935           siLayerNum = TIBDetId(id).layer();
00936           siDetNum = 1 ;
00937           siDetName = "TIB" ;
00938         } else if ( (hit->geographicalId()).subdetId() == StripSubdetector::TOB ){
00939           siLayerNum = TOBDetId(id).layer();
00940           siDetNum = 2 ;
00941           siDetName = "TOB" ;
00942           //            } else if ( (hit->geographicalId()).subdetId() == StripSubdetector::TID ){
00943           //      // should we use side/wheel/ring/module/stereo() ?
00944           //      siLayerNum = TIDDetId(id).wheel();
00945           //      siDetNum = 3 ;
00946           //      siDetName = "TID" ;
00947           //    }else if ( (hit->geographicalId()).subdetId() == StripSubdetector::TEC ){
00948           //      //choices are side/petal/wheel/ring/module/glued/stereo
00949           //      siLayerNum = TECDetId(id).wheel();
00950           //      siDetNum = 4 ;
00951           //      siDetName = "TEC" ;
00952         }else {
00953           siLayerNum = -999 ;
00954           siDetNum = -999 ;
00955           siDetName = "NULL" ;
00956         }
00957         //      LogDebug("") << siDetName << " " << siLayerNum ;
00958 
00959         const SiStripRecHit2D::ClusterRef & clust=rechit.cluster();
00960         double Signal = 0 ;
00961         double Noise2 = 0 ;
00962         int StripCount = 0 ;
00963         if(clust.isNonnull()) {
00964           //      LogDebug("") << " barycenter " << clust->barycenter() ;
00965           //      const std::vector<uint16_t> amplitudes=clust->amplitudes();
00966           const std::vector<uint8_t> amplitudes=clust->amplitudes();
00967           for(size_t i = 0 ; i<amplitudes.size(); i++ ){
00968             Signal +=amplitudes[i] ;
00969             //ignore for now         Noise2 +=SiStripNoiseService_.getNoise(detid,clust->firstStrip()+i)*SiStripNoiseService_.getNoise(detid,clust->firstStrip()+i);
00970             StripCount++;
00971           }
00972         } else {
00973           LogDebug("") << " null cluster " ;
00974         }
00975         //      LogDebug("") << "Signal " << Signal << " Noise2 " << Noise2 << " StripCount " << StripCount ;
00976         // Dump position
00977         //      LogDebug("") << " Stereo "
00978         //                       << "local position: "<<myposition.x()<<" "
00979         //                       << myposition.y()<<" "<<myposition.z()<<"\n"
00980         //                       << "local error: "<<myerror.xx()<<" "
00981         //                       << myerror.xy()<<" "<<myerror.yy() << "\n"
00982         //                       << "global position: " << position.x() << " "
00983         //                       <<  position.y()<<" "<< position.z()<<"\n"
00984         //                       << " siDetNum " << siDetNum
00985         //                       << " siLayerNum " << siLayerNum ;
00986 
00987 
00988         if( myHits < myMaxHits ) {
00989           StereoHitX_[myHits] = position.x();
00990           StereoHitY_[myHits] = position.y();
00991           StereoHitZ_[myHits] = position.z();
00992 
00993           StereoHitR_[myHits]=position.perp();
00994           StereoHitPhi_[myHits]=position.phi();
00995           StereoHitTheta_[myHits]=position.theta();
00996 
00997           StereoHitSigX_[myHits]=sqrt(myerror.xx());
00998           StereoHitSigY_[myHits]=sqrt(myerror.yy());
00999           StereoHitCorr_[myHits]=myerror.xy()/sqrt(myerror.xx()*myerror.yy());
01000 
01001           StereoHitSignal_[myHits] = Signal ;
01002           StereoHitNoise_[myHits] = Noise2 ;
01003           StereoHitWidth_[myHits] = StripCount ;
01004 
01005           StereoDetector_[myHits] = siDetNum ;
01006           StereoLayer_[myHits] = siLayerNum ;
01007 
01008           ++myHits ;
01009         }
01010       } // end if this is the right subdetector
01011   } // end loop over hits
01012   NStereoHits_ = myHits ;
01013 
01014   numSiStereoHits_->Fill(NStereoHits_);
01015 
01018 
01019   LogDebug("") << " Looping over Mono Hits " ;
01021   myHits = 0 ;
01022   for (SiStripRecHit2DCollection::DataContainer::const_iterator hit = rphiHitsHandle->data().begin(), hitend = rphiHitsHandle->data().end();
01023           hit != hitend;  ++hit) {
01024       DetId id(hit->geographicalId());
01025 
01026       if ((hit->geographicalId()).subdetId() == StripSubdetector::TIB ||
01027           (hit->geographicalId()).subdetId() == StripSubdetector::TOB) {
01028 
01029         GlobalPoint position = trackerHandle->idToDet(hit->geographicalId())->surface().toGlobal(hit->localPosition());
01030         //from RecoLocalTracker/SiStripClusterizer/test/TestCluster.cc
01031         // cf also TrackHitAssociator.cc SiStripRecHitMatcher.cc SiStrip1DMeasurementTransformator.cc (KalmanUpdators)
01032         SiStripRecHit2D const rechit = *hit ;
01033         //      LocalPoint myposition = rechit.localPosition() ;
01034         LocalError myerror = rechit.localPositionError();
01035 
01036         // Get layer and subdetector ID here for this hit
01037         // see SiStripRecHitConverter/test/ValHit.cc
01038         Int_t siLayerNum = 0 ;
01039         Int_t siDetNum = 0 ;
01040         string siDetName = "" ;
01041         if( (hit->geographicalId()).subdetId() == StripSubdetector::TIB ){
01042           //       siLayerNum = TIBDetId(rechit->geographicalID()).layer();
01043           siLayerNum = TIBDetId(id).layer();
01044           siDetNum = 1 ;
01045           siDetName = "TIB" ;
01046         } else if ( (hit->geographicalId()).subdetId() == StripSubdetector::TOB ){
01047           siLayerNum = TOBDetId(id).layer();
01048           siDetNum = 2 ;
01049           siDetName = "TOB" ;
01050           //    } else if ( (hit->geographicalId()).subdetId() == StripSubdetector::TID ){
01051           //      // should we use side/wheel/ring/module/stereo() ?
01052           //      siLayerNum = TIDDetId(id).wheel();
01053           //      siDetNum = 3 ;
01054           //      siDetName = "TID" ;
01055           //    }else if ( (hit->geographicalId()).subdetId() == StripSubdetector::TEC ){
01056           //      //choices are side/petal/wheel/ring/module/glued/stereo
01057           //      siLayerNum = TECDetId(id).wheel();
01058           //      siDetNum = 4 ;
01059           //      siDetName = "TEC"
01060           ;
01061         }else {
01062           siLayerNum = -999 ;
01063           siDetNum = -999 ;
01064           siDetName = "NULL" ;
01065         }
01066         //      LogDebug("") << siDetName << " " << siLayerNum ;
01067         const SiStripRecHit2D::ClusterRef & clust=rechit.cluster();
01068         double Signal = 0 ;
01069         double Noise2 = 0 ;
01070         int StripCount = 0 ;
01071         if(clust.isNonnull()) {
01072           //      LogDebug("") << " barycenter " << clust->barycenter() ;
01073           //      const std::vector<uint16_t> amplitudes=clust->amplitudes();
01074           const std::vector<uint8_t> amplitudes=clust->amplitudes();
01075           for(size_t i = 0 ; i<amplitudes.size(); i++ ){
01076             Signal +=amplitudes[i] ;
01077             //ignore for now         Noise2 +=SiStripNoiseService_.getNoise(detid,clust->firstStrip()+i)*SiStripNoiseService_.getNoise(detid,clust->firstStrip()+i);
01078             StripCount++;
01079           }
01080         } else {
01081           LogDebug("") << " null cluster " ;
01082         }
01083         //      LogDebug("") << "Signal " << Signal << " Noise2 " << Noise2 << " StripCount " << StripCount ;
01084 
01085         // Dump position info
01086         //      LogDebug("") << " Mono "
01087         //                       << "local position: "<<myposition.x()<<" "
01088         //                       << myposition.y()<<" "<<myposition.z()<<"\n"
01089         //                       <<"local error: "<<myerror.xx()<<" "
01090         //                       << myerror.xy()<<" "<<myerror.yy() << "\n"
01091         //                       << "global position: " << position.x() << " "
01092         //                       <<  position.y()<<" "<< position.z()<<"\n"
01093         //                       << " siDetNum " << siDetNum
01094         //                       << " siLayerNum " << siLayerNum ;
01095 
01096         if( myHits < myMaxHits ) {
01097           MonoHitX_[myHits] = position.x();
01098           MonoHitY_[myHits] = position.y();
01099           MonoHitZ_[myHits] = position.z();
01100 
01101           MonoHitR_[myHits]=position.perp();
01102           MonoHitPhi_[myHits]=position.phi();
01103           MonoHitTheta_[myHits]=position.theta();
01104 
01105           MonoHitSigX_[myHits]=sqrt(myerror.xx());
01106           MonoHitSigY_[myHits]=sqrt(myerror.yy());
01107           MonoHitCorr_[myHits]=myerror.xy()/sqrt(myerror.xx()*myerror.yy());
01108 
01109 
01110           MonoHitSignal_[myHits] = Signal ;
01111           MonoHitNoise_[myHits] = Noise2 ;
01112           MonoHitWidth_[myHits] = StripCount ;
01113 
01114           MonoDetector_[myHits] = siDetNum ;
01115           MonoLayer_[myHits] = siLayerNum ;
01116 
01117           ++myHits ;
01118         }  // of  if(myHits < myMaxHits)
01119         //      LogDebug("")<< "end of myHits < myMaxHits " ;
01120       } // end if this is the right subdetector
01121       //      LogDebug("")<< "end of TIB/TOB check " ;
01122   } // end loop over hits
01123   //    LogDebug("")<< " end of loop over hits  " ;
01124   NMonoHits_ = myHits ;
01125 
01126   numSiMonoHits_->Fill(NMonoHits_);
01127 
01128 
01131 
01132   LogDebug("") << "  Loop over Matched Hits " ;
01133 
01135   myHits = 0 ;
01136   for (SiStripMatchedRecHit2DCollection::DataContainer::const_iterator hit = matchedHitsHandle->data().begin(), hitend = matchedHitsHandle->data().end();
01137           hit != hitend;  ++hit) {
01138         DetId id(hit->geographicalId());
01139         if ((hit->geographicalId()).subdetId() == StripSubdetector::TIB  ||
01140           (hit->geographicalId()).subdetId() == StripSubdetector::TOB    ) {
01141         GlobalPoint position = trackerHandle->idToDet(hit->geographicalId())->surface().toGlobal(hit->localPosition());
01142         SiStripMatchedRecHit2D const rechit = *hit ;
01143         //      LocalPoint myposition = rechit.localPosition() ;
01144         LocalError myerror = rechit.localPositionError();
01145 
01146         // Get layer and subdetector ID here for this hit
01147         // see SiStripRecHitConverter/test/ValHit.cc
01148         Int_t siLayerNum = 0 ;
01149         Int_t siDetNum = 0 ;
01150         string siDetName = "" ;
01151         if( (hit->geographicalId()).subdetId() == StripSubdetector::TIB ){
01152           siLayerNum = TIBDetId(id).layer();
01153           siDetNum = 1 ;
01154           siDetName = "TIB" ;
01155         } else if ( (hit->geographicalId()).subdetId() == StripSubdetector::TOB ){
01156           siLayerNum = TOBDetId(id).layer();
01157           siDetNum = 2 ;
01158           siDetName = "TOB" ;
01159           //            } else if ( (hit->geographicalId()).subdetId() == StripSubdetector::TID ){
01160           //              // should we use side/wheel/ring/module/stereo() ?
01161           //              siLayerNum = TIDDetId(id).wheel();
01162           //              siDetNum = 3 ;
01163           //              siDetName = "TID" ;
01164           //            }else if ( (hit->geographicalId()).subdetId() == StripSubdetector::TEC ){
01165           //              //choices are side/petal/wheel/ring/module/glued/stereo
01166           //              siLayerNum = TECDetId(id).wheel();
01167           //              siDetNum = 4 ;
01168           //              siDetName = "TEC" ;
01169         }else {
01170           siLayerNum = -999 ;
01171           siDetNum = -999 ;
01172           siDetName = "NULL" ;
01173         }
01174         //      const edm::Ref<edm::DetSetVector<SiStripCluster>, SiStripCluster, edm::refhelper::FindForDetSetVector<SiStripCluster> > clust=rechit.cluster();
01175         double Signal = 0 ;
01176         double Noise2 = 0 ;
01177         int StripCount = 0 ;
01178         //      if(clust.isNonnull()) {
01179         //        LogDebug("") << " barycenter " << clust->barycenter() ;
01180         //        const std::vector<uint16_t> amplitudes=clust->amplitudes();
01181         //        for(size_t i = 0 ; i<amplitudes.size(); i++ ){
01182         //          Signal +=amplitudes[i] ;
01183         //          //ignore for now         Noise2 +=SiStripNoiseService_.getNoise(detid,clust->firstStrip()+i)*SiStripNoiseService_.getNoise(detid,clust->firstStrip()+i);
01184         //          StripCount++;
01185         //        }
01186         //      } else {
01187         //        LogDebug("") << " null cluster " ;
01188         //      }
01189         //      LogDebug("") << "Signal " << Signal << " Noise2 " << Noise2 << " StripCount " << StripCount ;
01190 
01191         // Dump position info
01192         //      LogDebug("") << " Matched "
01193         //                       << "local position: "<<myposition.x()<<" "
01194         //                       << myposition.y()<<" "<<myposition.z()<<"\n"
01195         //                       << "local error: "<<myerror.xx()<<" "
01196         //                       << myerror.xy()<<" "<<myerror.yy() << "\n"
01197         //                       << "global position: " << position.x() << " "
01198         //                       <<  position.y()<<" "<< position.z()<<"\n"
01199         //                       << " siDetNum " << siDetNum
01200         //                       << " siLayerNum " << siLayerNum ;
01201 
01202         if( myHits < myMaxHits ) {
01203           MatchedHitX_[myHits] = position.x();
01204           MatchedHitY_[myHits] = position.y();
01205           MatchedHitZ_[myHits] = position.z();
01206 
01207 
01208           MatchedHitR_[myHits]=position.perp();
01209           MatchedHitPhi_[myHits]=position.phi();
01210           MatchedHitTheta_[myHits]=position.theta();
01211 
01212           MatchedHitSigX_[myHits]=sqrt(myerror.xx());
01213           MatchedHitSigY_[myHits]=sqrt(myerror.yy());
01214           MatchedHitCorr_[myHits]=myerror.xy()/sqrt(myerror.xx()*myerror.yy());
01215 
01216 
01217 
01218           MatchedHitSignal_[myHits] = Signal ;
01219           MatchedHitNoise_[myHits] = Noise2 ;
01220           MatchedHitWidth_[myHits] = StripCount ;
01221 
01222           MatchedDetector_[myHits] = siDetNum ;
01223           MatchedLayer_[myHits] = siLayerNum ;
01224 
01225           ++myHits ;
01226         }
01227       } // end if this is the right subdetector (TIB/TOB)
01228   } // end loop over hits
01229   NMatchedHits_ = myHits ;
01230 
01231   numSiMatchedHits_->Fill(NMatchedHits_);
01232 
01234 
01235 
01236 
01239   LogDebug("") << "Writing to myTree with " << NShowers_ << " Showers "
01240                << NStereoHits_ << " Si StereoHits "
01241                << NMonoHits_ << " Si MonoHits "
01242                << NMatchedHits_ << " Si MatchedHits " ;
01243 
01244   myTree_->Fill();
01245 
01246 
01247 
01248 
01249 
01250 } // end of Analyzer
01251 
01252 
01253 void SiStripElectronAnalyzer::endJob(){
01254   LogDebug("") << "Entering endJob " ;
01255   file_->cd() ;
01256   numCand_->Write();
01257   numElectrons_->Write();
01258   numSuperClusters_->Write();
01259 
01260   energySuperClusters_->Write();
01261   sizeSuperClusters_->Write();
01262   emaxSuperClusters_->Write();
01263   phiWidthSuperClusters_->Write();
01264 
01265   energySuperClustersEl_->Write();
01266   sizeSuperClustersEl_->Write();
01267   emaxSuperClustersEl_->Write();
01268   phiWidthSuperClustersEl_->Write();
01269 
01270   ptDiff->Write();
01271   pDiff->Write();
01272   pElectronFailed->Write();
01273   ptElectronFailed->Write();
01274   pElectronPassed->Write();
01275   ptElectronPassed->Write();
01276   sizeSuperClustersPassed->Write();
01277   sizeSuperClustersFailed->Write();
01278   //   energySuperClustersPassed->Write();
01279   //   energySuperClustersFailed->Write();
01280   //   eOverPPassed->Write();
01281   //   eOverPFailed->Write();
01282 
01283 
01284   numSiStereoHits_->Write();
01285   numSiMonoHits_->Write();
01286   numSiMatchedHits_->Write();
01287 
01288   // disable for large dataset
01289   LogDebug("") << " Writing out ntuple is disabled for now " ;
01290    myTree_->Write();
01291 
01292 
01293   file_->Close();
01294 }
01295 
01296 
01297 //
01298 // const member functions
01299 //
01300 
01301 //
01302 // static member functions
01303 //