CMS 3D CMS Logo

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

Generated on Tue Jun 9 17:43:34 2009 for CMSSW by  doxygen 1.5.4