CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/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.14 2013/01/02 20:41:37 dlange 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/TrackerCommon/interface/TrackerTopology.h"
00052 #include "Geometry/Records/interface/IdealGeometryRecord.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(){
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   //Retrieve tracker topology from geometry
00329   edm::ESHandle<TrackerTopology> tTopo;
00330   iSetup.get<IdealGeometryRecord>().get(tTopo);
00331 
00332 
00333   using namespace std;  // so you can say "cout" and "endl"
00334 
00335   initNtuple();
00336 
00337 
00338   // http://cmsdoc.cern.ch/swdev/lxr/CMSSW/source/clhep/CLHEP/HepMC/GenParticle.h
00339   // http://cmsdoc.cern.ch/swdev/lxr/CMSSW/source/clhep/CLHEP/HepMC/GenVertex.h
00340   // removed by JED - causes trouble in release post 0_9_0
00341   //   edm::Handle<edm::HepMCProduct> mctruthHandle;
00342   //   iEvent.getByLabel(mctruthProducer_, mctruthCollection_, mctruthHandle);
00343   //   HepMC::GenEvent mctruth = mctruthHandle->getHepMCData();
00344 
00345   //   for (HepMC::GenEvent::particle_const_iterator partIter = mctruth.particles_begin();
00346   //    partIter != mctruth.particles_end();
00347   //    ++partIter) {
00348   // //    for (HepMC::GenEvent::vertex_const_iterator vertIter = mctruth.vertices_begin();
00349   // //         vertIter != mctruth.vertices_end();
00350   // //         ++vertIter) {
00351   //    CLHEP::HepLorentzVector creation = (*partIter)->CreationVertex();
00352   //    CLHEP::HepLorentzVector momentum = (*partIter)->Momentum();
00353   //   HepPDT::ParticleID id = (*partIter)->particleID();  // electrons and positrons are 11 and -11
00354   //     edm::LogInfo("") << "MC particle id " << id.pid() << ", creationVertex " << creation << " cm, initialMomentum " << momentum << " GeV/c" << endl;
00355   //  }
00356 
00357   // load the rechits for the Ecal
00358   edm::Handle<EcalRecHitCollection> pRecHits;
00359   iEvent.getByLabel(eBRecHitProducer_, eBRecHitCollection_, pRecHits);
00360   // Create a pointer to the RecHits  - unused for now
00361   //  const EcalRecHitCollection *hitCollection = pRecHits.product();
00362 
00363 
00364   // http://cmsdoc.cern.ch/swdev/lxr/CMSSW/source/self/DataFormats/EgammaReco/interface/SuperCluster.h
00365   edm::Handle<reco::SuperClusterCollection> clusterHandle;
00366   iEvent.getByLabel(superClusterProducer_, superClusterCollection_, clusterHandle);
00367 
00368 
00371 
00372   LogDebug("") << " Start loop over "
00373                << clusterHandle->end()-clusterHandle->begin()
00374                << "  superClusters " ;
00375 
00376   for (reco::SuperClusterCollection::const_iterator clusterIter = clusterHandle->begin();
00377        clusterIter != clusterHandle->end();
00378        ++clusterIter) {
00379     double energy = clusterIter->energy();
00380     math::XYZPoint position = clusterIter->position();
00381     std::ostringstream str;
00382 
00383     str  << " SuperCluster " << energy << " GeV, position "
00384          << position << " cm" << "\n" ;
00385 
00386     energySuperClusters_->Fill(energy);
00387     sizeSuperClusters_->Fill(clusterIter->clustersSize());
00388     // this only makes sense for hybrid superclusters
00389 
00390     // try to point to the constituent clusters for this SuperCluster
00391 
00392     str << "About to loop over basicClusters" << "\n" ;
00393 
00394     double emaxSuperCluster = 0. ;
00395     double phibar = 0. ;
00396     double phi2bar = 0. ;
00397     double eTotSuperCluster = 0. ;
00398 
00399 
00400 
00401     for (reco::CaloCluster_iterator basicClusterIter = clusterIter->clustersBegin() ;
00402          basicClusterIter != clusterIter->clustersEnd() ;
00403          ++basicClusterIter ){
00404 
00405       //std::vector<DetId> theIds= (*basicClusterIter)->getHitsByDetId();
00406 
00407       str << " basicCluster Energy " << (*basicClusterIter)->energy()
00408           << " Position " << (*basicClusterIter)->position()
00409           << " \n"
00410           << "        Position phi " << (*basicClusterIter)->position().phi()
00411           << " recHits " << (*basicClusterIter)->size()
00412           << " \n" ;
00413 
00414       double eCluster =  (*basicClusterIter)->energy();
00415       if(eCluster > emaxSuperCluster  ){
00416         emaxSuperCluster = eCluster ;
00417       }
00418       eTotSuperCluster += eCluster ;
00419       double phiCluster = (*basicClusterIter)->position().phi() ;
00420       phibar += eCluster * phiCluster ;
00421       phi2bar += eCluster * phiCluster * phiCluster ;
00422 
00423 
00424     } // end of basicClusterIter loop
00425 
00426 
00427 
00428     phibar= phibar /eTotSuperCluster ;
00429     phi2bar= phi2bar /eTotSuperCluster ;
00430     double phiWidth = phi2bar - phibar*phibar ;
00431     if(phiWidth>0.) {
00432       phiWidth = std::pow(phiWidth,0.5);
00433     }else{
00434       phiWidth =0.;
00435     }
00436     str << " SuperCluster stats " << "\n" ;
00437     str << "phibar " << phibar
00438         << " phi2bar " << phi2bar
00439         << " eTotSuperCluster " << eTotSuperCluster
00440         << " phiWidth " << phiWidth
00441         << std::endl  ;
00442 
00443     phiWidthSuperClusters_->Fill(phiWidth);
00444 
00445     emaxSuperClusters_->Fill(emaxSuperCluster);
00446 
00447     str << " Done with this SuperCluster " << std::endl;
00448 
00449     LogDebug("") << str.str() ;
00450 
00451   } // end of loop over superClusters
00452 
00453   LogDebug("") << " End loop over superClusters ";
00454 
00457 
00458 
00460   //
00461   // loop over all EcalRecHits and print out their x,y,z,E
00462   //  edm::LogInfo("") << " Dumping all recHits in this event " << endl ;
00463   // for(EcalRecHitCollection::const_iterator _blah = hitCollection->begin();
00464   //     _blah != hitCollection->end() ; ++_blah ) {
00465   //   edm::LogInfo("") << "Ecal RecHit Energy: " << _blah->energy() << endl ;
00466   //   //      " Position " << _blah.position() << endl ;
00467   //  }
00468   //
00469   //  edm::LogInfo("") << "Dump finished " << endl ;
00470   //
00472 
00473 
00474 
00475 
00476   // DataFormats/EgammaCandidates/src/SiStripElectron.cc
00477   edm::Handle<reco::SiStripElectronCollection> siStripElectronHandle;
00478   iEvent.getByLabel(siElectronProducer_, siElectronCollection_, siStripElectronHandle);
00479 
00480 
00481 
00483 
00484 
00485   LogDebug("") << " Dumping Algo's guess of SiStripElectron Candidate Info " ;
00486   int numberOfElectrons = 0;
00487   // need to check if fit succeeded
00488   LogDebug("") << " Number of SiStripElectrons  " << siStripElectronHandle->size() ;
00489 
00490 
00491   for (reco::SiStripElectronCollection::const_iterator electronIter = siStripElectronHandle->begin();
00492        electronIter != siStripElectronHandle->end();  ++electronIter) {
00493 
00494 
00495     LogDebug("")  << "about to get stuff from electroncandidate "
00496                   << numberOfElectrons << "\n"
00497                   << "supercluster energy = "
00498                   << electronIter->superCluster()->energy() << "\n"
00499                   << "fit results are phi(r) = "
00500                   << electronIter->phiAtOrigin() << " + "
00501                   << electronIter->phiVsRSlope() << "*r" << "\n"
00502                   << " chi2 " << electronIter->chi2()
00503                   << " ndof " << electronIter->ndof() << "\n"
00504                   << " Pt " << electronIter->pt() << "\n"
00505                   << "P, Px, Py, Pz  "
00506                   << electronIter->p() << " "
00507                   << electronIter->px() << " "
00508                   << electronIter->py() << " "
00509                   << electronIter->pz() << "\n"
00510                   << "you get the idea..." ;
00511 
00512     // make plots for supercluster that an electron has been associ w/. here
00513     energySuperClustersEl_->Fill(electronIter->superCluster()->energy());
00514     sizeSuperClustersEl_->Fill(electronIter->superCluster()->clustersSize());
00515 
00516     // loop over basicClusters to get energy
00517     double emaxSuperCluster = 0. ;
00518     double phibar = 0. ;
00519     double phi2bar = 0. ;
00520     double eTotSuperCluster = 0. ;
00521 
00522     for (reco::CaloCluster_iterator basicClusterIter = electronIter->superCluster()->clustersBegin() ;
00523          basicClusterIter != electronIter->superCluster()->clustersEnd() ;
00524          ++basicClusterIter ){
00525 
00526       //std::vector<DetId> theIds= (*basicClusterIter)->getHitsByDetId();
00527 
00528       double eCluster =  (*basicClusterIter)->energy();
00529       if(eCluster > emaxSuperCluster  ){
00530         emaxSuperCluster = eCluster ;
00531       }
00532       eTotSuperCluster += eCluster ;
00533       double phiCluster = (*basicClusterIter)->position().phi() ;
00534       phibar += eCluster * phiCluster ;
00535       phi2bar += eCluster * phiCluster * phiCluster ;
00536 
00537     }
00538 
00539     phibar=phibar/eTotSuperCluster ;
00540     phi2bar=phi2bar/eTotSuperCluster ;
00541     double phiWidth = phi2bar - phibar*phibar ;
00542     if(phiWidth>0.) {
00543       phiWidth = std::pow(phiWidth,0.5);
00544     }else{
00545       phiWidth =0.;
00546     }
00547 
00548     phiWidthSuperClustersEl_->Fill(phiWidth);
00549 
00550     emaxSuperClustersEl_->Fill(emaxSuperCluster);
00551 
00552     numberOfElectrons++;
00553   }
00554 
00555   numCand_->Fill(siStripElectronHandle->size());
00556 
00558 
00559 
00560 
00561   // Now loop over the electrons (ie the fitted things.)
00562 
00563   LogDebug("")<< " About to check Electrons" ;
00564 
00565   edm::Handle<reco::ElectronCollection> electrons ;
00566   iEvent.getByLabel(electronProducer_, electronCollection_, electrons);
00567 
00568   numElectrons_->Fill(electrons->end()- electrons->begin());
00569 
00570   // set up vector of bool for SiStrips having or not having Electrons
00571   // this causes a warning because of variable array size at compilation time ;
00572   // BAD  bool hasElectron_[siStripElectronHandle->end()- siStripElectronHandle->begin()] ;
00573   bool* hasElectron_ = new bool[siStripElectronHandle->end()- siStripElectronHandle->begin()] ;
00574   for (int icount = 0 ;
00575        icount < siStripElectronHandle->end()- siStripElectronHandle->begin() ;
00576        ++icount)
00577     { hasElectron_[icount] = false ;}
00578 
00579   // also set up a counter to associate the ith electron to the jth strippy
00580   // Electron_to_strippy[i] = j: i-th Electron is j-th strippy
00581   // BAD  unsigned int Electron_to_strippy[electrons->end()- electrons->begin()];
00582   unsigned int* Electron_to_strippy = new unsigned int[electrons->end()- electrons->begin()];
00583   for (int icount = 0 ;
00584        icount <electrons->end()- electrons->begin();  ++icount)
00585     { Electron_to_strippy[icount] = 0 ;}
00586 
00587   unsigned int ecount=0 ;
00588   for (reco::ElectronCollection::const_iterator electronIter = electrons->begin();
00589        electronIter != electrons->end(); ++electronIter ){
00590 
00591 
00592     LogDebug("")<< " Associating Electrons to Strippies " ;
00593     LogDebug("")<< " PT is " << electronIter->track()->pt() ;
00594 
00595     reco::TrackRef tr =(*electronIter).track();
00596     uint32_t id = (*electronIter->track()->recHitsBegin())->geographicalId().rawId();
00597     LocalPoint pos = (*electronIter->track()->recHitsBegin())->localPosition();
00598 
00599     unsigned int icount = 0 ;
00600     LogDebug("") << " About to loop over Strippies " << " \n "
00601                  << " icount " << icount
00602                  << " max " << siStripElectronHandle->end()- siStripElectronHandle->begin() ;
00603 
00604     for (reco::SiStripElectronCollection::const_iterator strippyiter = siStripElectronHandle->begin();
00605          strippyiter != siStripElectronHandle->end(); ++strippyiter) {
00606 
00607       bool hitInCommon = false;
00608       // loop over rphi hits
00609       for (std::vector<SiStripRecHit2D>::const_iterator
00610              hiter = strippyiter->rphiRecHits().begin();
00611            hiter != strippyiter->rphiRecHits().end();
00612            ++hiter) {
00613         if (hiter->geographicalId().rawId() == id  &&
00614             (hiter->localPosition() - pos).mag() < 1e-10) {
00615           hitInCommon = true;
00616           break;
00617         }
00618       }
00619 
00620       for (std::vector<SiStripRecHit2D>::const_iterator
00621              hiter = strippyiter->stereoRecHits().begin();
00622            hiter != strippyiter->stereoRecHits().end();
00623            ++hiter) {
00624         if (hiter->geographicalId().rawId() == id  &&
00625             (hiter->localPosition() - pos).mag() < 1e-10) {
00626           hitInCommon = true;
00627           break;
00628         }
00629       }
00630       if (hitInCommon) {  //this Electron belongs to this SiStripElectron.
00631         hasElectron_[icount] = true ;
00632         Electron_to_strippy[ecount]= icount ;
00633         ptDiff->Fill( std::abs(electronIter->track()->pt()) - std::abs(strippyiter->pt()) );
00634         pDiff->Fill( std::abs(electronIter->track()->p()) - std::abs(strippyiter->p()) );
00635 
00636       }
00637       icount++ ;
00638     } // Sistrip loop
00639     ecount++;
00640   } // Electrons
00641 
00642   LogDebug("") << " Done looping over Electrons " ;
00643 
00644 
00645   unsigned int counter = 0 ;
00646   for (reco::SiStripElectronCollection::const_iterator strippyIter = siStripElectronHandle->begin();  strippyIter != siStripElectronHandle->end();  ++strippyIter) {
00647 
00648 
00649     bool skipThis = !hasElectron_[counter] ;
00650     if( skipThis ) {
00651       // plot stuff for SIStripElectrons that don't have fits associated
00652 
00653       LogDebug("") << " SiStrip Failed Electron " << " \n " <<
00654         " p " << strippyIter->p() << " \n " <<
00655         " pt " << strippyIter->pt() << " \n " <<
00656         " SuperClust size " << strippyIter->superCluster()->clustersSize() ;
00657 
00658       pElectronFailed->Fill( std::abs(strippyIter->p()) );
00659       ptElectronFailed->Fill( std::abs(strippyIter->pt()) );
00660       sizeSuperClustersFailed->Fill(strippyIter->superCluster()->clustersSize());
00661       LogDebug("") << " done filling Failed histos " ;
00662       //      energySuperClustersFailed->Fill(strippyIter->superCluster()->energy());
00663       //       if(strippyIter->p()>0.) {
00664       //        eOverPFailed->Fill(strippyIter->superCluster()->energy()/strippyIter->p());
00665       //       }else {
00666       //        eOverPFailed->Fill(-1.0);
00667       //       }
00668 
00669     } else {
00670       LogDebug("") << " SiStrip Passed Electron " << " \n " <<
00671         " p " << strippyIter->p() << " \n " <<
00672         " pt " << strippyIter->pt() << " \n " <<
00673         " SuperClust size " << strippyIter->superCluster()->clustersSize() ;
00674       pElectronPassed->Fill( std::abs(strippyIter->p()) );
00675       ptElectronPassed->Fill( std::abs(strippyIter->pt()) );
00676       sizeSuperClustersPassed->Fill(strippyIter->superCluster()->clustersSize());
00677       LogDebug("") << " done filling passed histos " ;
00678       //      energySuperClustersPassed->Fill(strippyIter->superCluster()->energy());
00679       //       if(strippyIter->p()>0.) {
00680       //        eOverPPassed->Fill(strippyIter->superCluster()->energy()/strippyIter->p());
00681       //       }else {
00682       //        eOverPPassed->Fill(-1.0);
00683       //       }
00684 
00685     } // skipThis
00686     counter++;
00687   }
00688 
00689   LogDebug("")<< "Dump info for all electrons ";
00690 
00691   for (reco::ElectronCollection::const_iterator electronIter1 = electrons->begin();
00692        electronIter1 != electrons->end(); ++electronIter1 ){
00693     reco::TrackRef tr1 =(*electronIter1).track();
00694     // let's find its associated SiStripElectron and SuperCluster
00695     unsigned int ecount1= electronIter1-electrons->begin() ;
00696     unsigned int stripCount1 = 0 ;
00697     reco::SiStripElectronCollection::const_iterator strippyIter1 ;
00698     for (reco::SiStripElectronCollection::const_iterator strippyIter = siStripElectronHandle->begin();
00699          strippyIter != siStripElectronHandle->end();  ++strippyIter) {
00700       if(Electron_to_strippy[ecount1]==stripCount1 ) {
00701         strippyIter1 = strippyIter ;
00702         break ; }
00703       stripCount1++ ;
00704     } // strippy loop
00705     ecount1++;
00706 
00707     std::ostringstream str;
00708 
00709 
00710     str << " SiStripElect p , px, py, pz " << strippyIter1->p()
00711         << "  " << strippyIter1->px()
00712         << "  " << strippyIter1->py()
00713         << "  " << strippyIter1->pz()
00714         << "\n " << std::endl ;
00715 
00716 
00717     str  << " Electron p px, py, pz,  = " << tr1->p()
00718          << "  " << tr1->px()
00719          << "  " << tr1->py()
00720          << "  " << tr1->pz()
00721          << "\n" <<  std::endl ;
00722 
00723 
00724     double EClust1 = strippyIter1->superCluster()->energy() ;
00725     double XClust1 = strippyIter1->superCluster()->x();
00726     double YClust1 = strippyIter1->superCluster()->y();
00727     double ZClust1 = strippyIter1->superCluster()->z();
00728 
00729     double rho1 = sqrt(XClust1*XClust1+YClust1*YClust1+ZClust1*ZClust1) ;
00730     double costheta1 = ZClust1/rho1 ;
00731     double sintheta1 = sqrt(1-costheta1*costheta1);
00732     if(ZClust1<0 ) { sintheta1 = - sintheta1 ; }
00733     double cosphi1 = XClust1/sqrt(XClust1*XClust1+YClust1*YClust1);
00734     double sinphi1 = YClust1/sqrt(XClust1*XClust1+YClust1*YClust1);
00735 
00736     str << " Ecal for electron E, px, py, pz "
00737         << EClust1 << " "
00738         << EClust1*sintheta1*cosphi1 << " "
00739         << EClust1*sintheta1*sinphi1  << " "
00740         << EClust1*costheta1
00741         << "\n" << std::endl ;
00742 
00743     LogDebug("") << str.str() ;
00744 
00745   } // loop over electrons
00746  LogDebug("")<< "Done Dumping info for all electrons ";
00747 
00749   // LogDebug("")<< " Checking Electrons" ;
00750   //  LogDebug("")<< " PT is " << electronIter->track()->pt() ;
00751   //    reco::TrackRef tr =(*electronIter).track();
00753   if(electrons->end()-electrons->begin()> 1) {
00754     edm::LogInfo("") << " Two electrons in this event " << std::endl;
00755     for (reco::ElectronCollection::const_iterator electronIter1 = electrons->begin();
00756          electronIter1 != electrons->end()-1; ++electronIter1 ){
00757       reco::TrackRef tr1 =(*electronIter1).track();
00758 
00759       // let's find its associated SiStripElectron and SuperCluster
00760       // use the Electron_to_strippy[] array
00761       unsigned int ecount1= electronIter1-electrons->begin() ;
00762       // loop over strippies to find the corresponding one
00763       unsigned int stripCount1 = 0 ;
00764       reco::SiStripElectronCollection::const_iterator strippyIter1 ;
00765       for (reco::SiStripElectronCollection::const_iterator strippyIter = siStripElectronHandle->begin();  strippyIter != siStripElectronHandle->end();  ++strippyIter) {
00766         if(Electron_to_strippy[ecount1]==stripCount1 ) {
00767           strippyIter1 = strippyIter ;
00768           break ; }
00769         stripCount1++ ;
00770       } // strippy loop
00771 
00772       double EClust1 = strippyIter1->superCluster()->energy() ;
00773       double XClust1 = strippyIter1->superCluster()->x();
00774       double YClust1 = strippyIter1->superCluster()->y();
00775       double ZClust1 = strippyIter1->superCluster()->z();
00776 
00777       for (reco::ElectronCollection::const_iterator electronIter2 = electronIter1+1;
00778            electronIter2 != electrons->end(); ++electronIter2 ){
00779 
00780         reco::TrackRef tr2 =(*electronIter2).track();
00781 
00782         unsigned int ecount2= electronIter2-electrons->begin() ;
00783         unsigned int stripCount2 = 0 ;
00784         reco::SiStripElectronCollection::const_iterator strippyIter2 ;
00785         for (reco::SiStripElectronCollection::const_iterator strippyIter = siStripElectronHandle->begin();  strippyIter != siStripElectronHandle->end();  ++strippyIter) {
00786           if(Electron_to_strippy[ecount2]==stripCount2 ) {
00787             strippyIter2 = strippyIter ;
00788             break ; }
00789           stripCount2++ ;
00790         } // strippy loop
00791 
00792 
00793 
00794         double EClust2 = strippyIter2->superCluster()->energy() ;
00795         double XClust2 = strippyIter2->superCluster()->x();
00796         double YClust2 = strippyIter2->superCluster()->y();
00797         double ZClust2 = strippyIter2->superCluster()->z();
00798 
00799 
00800         // now get supercluster from this:
00801 
00802 
00803         edm::LogInfo("")  << " Electron p1 = " << tr1->p()
00804                           << " p1x " << tr1->px()
00805                           << " p1y " << tr1->py()
00806                           << " p1z " << tr1->pz()
00807                           << std::endl ;
00808 
00809 
00810         edm::LogInfo("")  << " Electron p2 = " << tr2->p()
00811                           << " p2x " << tr2->px()
00812                           << " p2y " << tr2->py()
00813                           << " p2z " << tr2->pz()
00814                           << std::endl ;
00815 
00816 
00817         // combine the two in an (e,e) pair
00818         double Zpx = tr1->px()+tr2->px() ;
00819         double Zpy = tr1->py()+tr2->py() ;
00820         double Zpz = tr1->pz()+tr2->pz() ;
00821         double Ze = std::abs(tr1->p())+std::abs(tr2->p()) ;
00822         edm::LogInfo("") << " Z mass " <<
00823           sqrt(Ze*Ze-Zpx*Zpx-Zpy*Zpy-Zpz*Zpz) << std::endl ;
00824 
00825         // combine the SuperClusts into a Z
00826         double rho1 = sqrt(XClust1*XClust1+YClust1*YClust1+ZClust1*ZClust1) ;
00827         double costheta1 = ZClust1/rho1 ;
00828         double sintheta1 = sqrt(1-costheta1*costheta1);
00829         if(ZClust1<0 ) { sintheta1 = - sintheta1 ; }
00830         double cosphi1 = XClust1/sqrt(XClust1*XClust1+YClust1*YClust1);
00831         double sinphi1 = YClust1/sqrt(XClust1*XClust1+YClust1*YClust1);
00832 
00833         double rho2 = sqrt(XClust2*XClust2+YClust2*YClust2+ZClust2*ZClust2) ;
00834         double costheta2 = ZClust2/rho2 ;
00835         double sintheta2 = sqrt(1-costheta2*costheta2);
00836         if(ZClust2<0 ) { sintheta2 = - sintheta2 ; }
00837         double cosphi2 = XClust2/sqrt(XClust2*XClust2+YClust2*YClust2);
00838         double sinphi2 = YClust2/sqrt(XClust2*XClust2+YClust2*YClust2);
00839 
00840         edm::LogInfo("") << "Energy of supercluster for 1st electron "
00841                          << EClust1 << " "
00842                          << EClust1*sintheta1*cosphi1 << " "
00843                          << EClust1*sintheta1*sinphi1  << " "
00844                          << EClust1*costheta1  << " "
00845                          << std::endl ;
00846 
00847         edm::LogInfo("") << "Energy of supercluster for 2nd electron "
00848                          << EClust2 << " "
00849                          << EClust2*sintheta2*cosphi2 << " "
00850                          << EClust2*sintheta2*sinphi2  << " "
00851                          << EClust2*costheta2  << " "
00852                          << std::endl ;
00853 
00854 
00855         // get the supercluster pair
00856         double Zgpx = EClust1*sintheta1*cosphi1+EClust2*sintheta2*cosphi2 ;
00857         double Zgpy = EClust1*sintheta1*sinphi1+EClust2*sintheta2*sinphi2 ;
00858         double Zgpz = EClust1*costheta1+EClust2*costheta2 ;
00859         double ZgE = EClust1+EClust2 ;
00860 
00861         edm::LogInfo("") << " Z mass from ECAL " <<
00862           sqrt(ZgE*ZgE-Zgpx*Zgpx-Zgpy*Zgpy-Zgpz*Zgpz) << std::endl ;
00863 
00864 
00865       } //inner loop
00866     } // outer loop
00867   }// m(ee) loop
00868 
00869   delete[] hasElectron_;
00870   delete[] Electron_to_strippy;
00871 
00875   LogDebug("") << " About to dump tracker info " ;
00876 
00877   edm::ESHandle<TrackerGeometry> trackerHandle;
00878   iSetup.get<TrackerDigiGeometryRecord>().get(trackerHandle);
00879 
00880   edm::Handle<SiStripRecHit2DCollection> rphiHitsHandle;
00881   iEvent.getByLabel(siHitProducer_, siRphiHitCollection_, rphiHitsHandle);
00882 
00883   edm::Handle<SiStripRecHit2DCollection> stereoHitsHandle;
00884   iEvent.getByLabel(siHitProducer_, siStereoHitCollection_, stereoHitsHandle);
00885 
00886   edm::Handle<SiStripMatchedRecHit2DCollection> matchedHitsHandle;
00887   iEvent.getByLabel(siHitProducer_, siMatchedHitCollection_, matchedHitsHandle);
00888 
00890 
00892   NShowers_=0 ;
00893   for (reco::SuperClusterCollection::const_iterator clusterIter = clusterHandle->begin();
00894        clusterIter != clusterHandle->end();
00895        ++clusterIter) {
00896     double energy = clusterIter->energy();
00897     math::XYZPoint position = clusterIter->position();
00898     if(NShowers_ < myMaxHits ) {
00899       EShower_[NShowers_] = energy ;
00900       XShower_[NShowers_] = position.x() ;
00901       YShower_[NShowers_] = position.y() ;
00902       ZShower_[NShowers_] = position.z() ;
00903       ++NShowers_ ;
00904     }
00905     // Loop over all crystals in this supercluster - see
00906     // RecoEcal/EgamaClusterProducers/src/EgammaSimpleAnalyzer.cc
00907     // Look also at DataFormats/EgammaReco/interface/SuperCluster.h
00908 
00909   }
00910   numSuperClusters_->Fill(NShowers_);
00912 
00913 
00914   LogDebug("") << " Looping over stereo hits " ;
00915 
00916 
00918   int myHits = 0 ;
00919   for (SiStripRecHit2DCollection::DataContainer::const_iterator hit = stereoHitsHandle->data().begin(), hitend = stereoHitsHandle->data().end();
00920           hit != hitend;  ++hit) {
00921       DetId id(hit->geographicalId());
00922       if( (hit->geographicalId()).subdetId() == StripSubdetector::TIB  ||
00923           (hit->geographicalId()).subdetId() == StripSubdetector::TOB    ) {
00924         GlobalPoint position = trackerHandle->idToDet(hit->geographicalId())->surface().toGlobal(hit->localPosition());
00925         //from RecoLocalTracker/SiStripClusterizer/test/TestCluster.cc
00926         // cf also TrackHitAssociator.cc SiStripRecHitMatcher.cc SiStrip1DMeasurementTransformator.cc (KalmanUpdators)
00927         SiStripRecHit2D const rechit = *hit ;
00928         //      LocalPoint myposition = rechit.localPosition() ;
00929         LocalError myerror = rechit.localPositionError();
00930 
00931         // Get layer and subdetector ID here for this hit
00932         // see SiStripRecHitConverter/test/ValHit.cc
00933         Int_t siLayerNum = 0 ;
00934         Int_t siDetNum = 0 ;
00935         string siDetName = "" ;
00936         if( (hit->geographicalId()).subdetId() == StripSubdetector::TIB ){
00937           //       siLayerNum = tTopo->tibLayer(rechit->geographicalID());
00938           siLayerNum = tTopo->tibLayer(id);
00939           siDetNum = 1 ;
00940           siDetName = "TIB" ;
00941         } else if ( (hit->geographicalId()).subdetId() == StripSubdetector::TOB ){
00942           siLayerNum = tTopo->tobLayer(id);
00943           siDetNum = 2 ;
00944           siDetName = "TOB" ;
00945           //            } else if ( (hit->geographicalId()).subdetId() == StripSubdetector::TID ){
00946           //      // should we use side/wheel/ring/module/stereo() ?
00947           //      siLayerNum = tTopo->tidWheel(id);
00948           //      siDetNum = 3 ;
00949           //      siDetName = "TID" ;
00950           //    }else if ( (hit->geographicalId()).subdetId() == StripSubdetector::TEC ){
00951           //      //choices are side/petal/wheel/ring/module/glued/stereo
00952           //      siLayerNum = tTopo->tecWheel(id);
00953           //      siDetNum = 4 ;
00954           //      siDetName = "TEC" ;
00955         }else {
00956           siLayerNum = -999 ;
00957           siDetNum = -999 ;
00958           siDetName = "NULL" ;
00959         }
00960         //      LogDebug("") << siDetName << " " << siLayerNum ;
00961 
00962         const SiStripRecHit2D::ClusterRef & clust=rechit.cluster();
00963         double Signal = 0 ;
00964         double Noise2 = 0 ;
00965         int StripCount = 0 ;
00966         if(clust.isNonnull()) {
00967           //      LogDebug("") << " barycenter " << clust->barycenter() ;
00968           //      const std::vector<uint16_t> amplitudes=clust->amplitudes();
00969           const std::vector<uint8_t> amplitudes=clust->amplitudes();
00970           for(size_t i = 0 ; i<amplitudes.size(); i++ ){
00971             Signal +=amplitudes[i] ;
00972             //ignore for now         Noise2 +=SiStripNoiseService_.getNoise(detid,clust->firstStrip()+i)*SiStripNoiseService_.getNoise(detid,clust->firstStrip()+i);
00973             StripCount++;
00974           }
00975         } else {
00976           LogDebug("") << " null cluster " ;
00977         }
00978         //      LogDebug("") << "Signal " << Signal << " Noise2 " << Noise2 << " StripCount " << StripCount ;
00979         // Dump position
00980         //      LogDebug("") << " Stereo "
00981         //                       << "local position: "<<myposition.x()<<" "
00982         //                       << myposition.y()<<" "<<myposition.z()<<"\n"
00983         //                       << "local error: "<<myerror.xx()<<" "
00984         //                       << myerror.xy()<<" "<<myerror.yy() << "\n"
00985         //                       << "global position: " << position.x() << " "
00986         //                       <<  position.y()<<" "<< position.z()<<"\n"
00987         //                       << " siDetNum " << siDetNum
00988         //                       << " siLayerNum " << siLayerNum ;
00989 
00990 
00991         if( myHits < myMaxHits ) {
00992           StereoHitX_[myHits] = position.x();
00993           StereoHitY_[myHits] = position.y();
00994           StereoHitZ_[myHits] = position.z();
00995 
00996           StereoHitR_[myHits]=position.perp();
00997           StereoHitPhi_[myHits]=position.phi();
00998           StereoHitTheta_[myHits]=position.theta();
00999 
01000           StereoHitSigX_[myHits]=sqrt(myerror.xx());
01001           StereoHitSigY_[myHits]=sqrt(myerror.yy());
01002           StereoHitCorr_[myHits]=myerror.xy()/sqrt(myerror.xx()*myerror.yy());
01003 
01004           StereoHitSignal_[myHits] = Signal ;
01005           StereoHitNoise_[myHits] = Noise2 ;
01006           StereoHitWidth_[myHits] = StripCount ;
01007 
01008           StereoDetector_[myHits] = siDetNum ;
01009           StereoLayer_[myHits] = siLayerNum ;
01010 
01011           ++myHits ;
01012         }
01013       } // end if this is the right subdetector
01014   } // end loop over hits
01015   NStereoHits_ = myHits ;
01016 
01017   numSiStereoHits_->Fill(NStereoHits_);
01018 
01021 
01022   LogDebug("") << " Looping over Mono Hits " ;
01024   myHits = 0 ;
01025   for (SiStripRecHit2DCollection::DataContainer::const_iterator hit = rphiHitsHandle->data().begin(), hitend = rphiHitsHandle->data().end();
01026           hit != hitend;  ++hit) {
01027       DetId id(hit->geographicalId());
01028 
01029       if ((hit->geographicalId()).subdetId() == StripSubdetector::TIB ||
01030           (hit->geographicalId()).subdetId() == StripSubdetector::TOB) {
01031 
01032         GlobalPoint position = trackerHandle->idToDet(hit->geographicalId())->surface().toGlobal(hit->localPosition());
01033         //from RecoLocalTracker/SiStripClusterizer/test/TestCluster.cc
01034         // cf also TrackHitAssociator.cc SiStripRecHitMatcher.cc SiStrip1DMeasurementTransformator.cc (KalmanUpdators)
01035         SiStripRecHit2D const rechit = *hit ;
01036         //      LocalPoint myposition = rechit.localPosition() ;
01037         LocalError myerror = rechit.localPositionError();
01038 
01039         // Get layer and subdetector ID here for this hit
01040         // see SiStripRecHitConverter/test/ValHit.cc
01041         Int_t siLayerNum = 0 ;
01042         Int_t siDetNum = 0 ;
01043         string siDetName = "" ;
01044         if( (hit->geographicalId()).subdetId() == StripSubdetector::TIB ){
01045           //       siLayerNum = tTopo->tibLayer(rechit->geographicalID());
01046           siLayerNum = tTopo->tibLayer(id);
01047           siDetNum = 1 ;
01048           siDetName = "TIB" ;
01049         } else if ( (hit->geographicalId()).subdetId() == StripSubdetector::TOB ){
01050           siLayerNum = tTopo->tobLayer(id);
01051           siDetNum = 2 ;
01052           siDetName = "TOB" ;
01053           //    } else if ( (hit->geographicalId()).subdetId() == StripSubdetector::TID ){
01054           //      // should we use side/wheel/ring/module/stereo() ?
01055           //      siLayerNum = tTopo->tidWheel(id);
01056           //      siDetNum = 3 ;
01057           //      siDetName = "TID" ;
01058           //    }else if ( (hit->geographicalId()).subdetId() == StripSubdetector::TEC ){
01059           //      //choices are side/petal/wheel/ring/module/glued/stereo
01060           //      siLayerNum = tTopo->tecWheel(id);
01061           //      siDetNum = 4 ;
01062           //      siDetName = "TEC"
01063           ;
01064         }else {
01065           siLayerNum = -999 ;
01066           siDetNum = -999 ;
01067           siDetName = "NULL" ;
01068         }
01069         //      LogDebug("") << siDetName << " " << siLayerNum ;
01070         const SiStripRecHit2D::ClusterRef & clust=rechit.cluster();
01071         double Signal = 0 ;
01072         double Noise2 = 0 ;
01073         int StripCount = 0 ;
01074         if(clust.isNonnull()) {
01075           //      LogDebug("") << " barycenter " << clust->barycenter() ;
01076           //      const std::vector<uint16_t> amplitudes=clust->amplitudes();
01077           const std::vector<uint8_t> amplitudes=clust->amplitudes();
01078           for(size_t i = 0 ; i<amplitudes.size(); i++ ){
01079             Signal +=amplitudes[i] ;
01080             //ignore for now         Noise2 +=SiStripNoiseService_.getNoise(detid,clust->firstStrip()+i)*SiStripNoiseService_.getNoise(detid,clust->firstStrip()+i);
01081             StripCount++;
01082           }
01083         } else {
01084           LogDebug("") << " null cluster " ;
01085         }
01086         //      LogDebug("") << "Signal " << Signal << " Noise2 " << Noise2 << " StripCount " << StripCount ;
01087 
01088         // Dump position info
01089         //      LogDebug("") << " Mono "
01090         //                       << "local position: "<<myposition.x()<<" "
01091         //                       << myposition.y()<<" "<<myposition.z()<<"\n"
01092         //                       <<"local error: "<<myerror.xx()<<" "
01093         //                       << myerror.xy()<<" "<<myerror.yy() << "\n"
01094         //                       << "global position: " << position.x() << " "
01095         //                       <<  position.y()<<" "<< position.z()<<"\n"
01096         //                       << " siDetNum " << siDetNum
01097         //                       << " siLayerNum " << siLayerNum ;
01098 
01099         if( myHits < myMaxHits ) {
01100           MonoHitX_[myHits] = position.x();
01101           MonoHitY_[myHits] = position.y();
01102           MonoHitZ_[myHits] = position.z();
01103 
01104           MonoHitR_[myHits]=position.perp();
01105           MonoHitPhi_[myHits]=position.phi();
01106           MonoHitTheta_[myHits]=position.theta();
01107 
01108           MonoHitSigX_[myHits]=sqrt(myerror.xx());
01109           MonoHitSigY_[myHits]=sqrt(myerror.yy());
01110           MonoHitCorr_[myHits]=myerror.xy()/sqrt(myerror.xx()*myerror.yy());
01111 
01112 
01113           MonoHitSignal_[myHits] = Signal ;
01114           MonoHitNoise_[myHits] = Noise2 ;
01115           MonoHitWidth_[myHits] = StripCount ;
01116 
01117           MonoDetector_[myHits] = siDetNum ;
01118           MonoLayer_[myHits] = siLayerNum ;
01119 
01120           ++myHits ;
01121         }  // of  if(myHits < myMaxHits)
01122         //      LogDebug("")<< "end of myHits < myMaxHits " ;
01123       } // end if this is the right subdetector
01124       //      LogDebug("")<< "end of TIB/TOB check " ;
01125   } // end loop over hits
01126   //    LogDebug("")<< " end of loop over hits  " ;
01127   NMonoHits_ = myHits ;
01128 
01129   numSiMonoHits_->Fill(NMonoHits_);
01130 
01131 
01134 
01135   LogDebug("") << "  Loop over Matched Hits " ;
01136 
01138   myHits = 0 ;
01139   for (SiStripMatchedRecHit2DCollection::DataContainer::const_iterator hit = matchedHitsHandle->data().begin(), hitend = matchedHitsHandle->data().end();
01140           hit != hitend;  ++hit) {
01141         DetId id(hit->geographicalId());
01142         if ((hit->geographicalId()).subdetId() == StripSubdetector::TIB  ||
01143           (hit->geographicalId()).subdetId() == StripSubdetector::TOB    ) {
01144         GlobalPoint position = trackerHandle->idToDet(hit->geographicalId())->surface().toGlobal(hit->localPosition());
01145         SiStripMatchedRecHit2D const rechit = *hit ;
01146         //      LocalPoint myposition = rechit.localPosition() ;
01147         LocalError myerror = rechit.localPositionError();
01148 
01149         // Get layer and subdetector ID here for this hit
01150         // see SiStripRecHitConverter/test/ValHit.cc
01151         Int_t siLayerNum = 0 ;
01152         Int_t siDetNum = 0 ;
01153         string siDetName = "" ;
01154         if( (hit->geographicalId()).subdetId() == StripSubdetector::TIB ){
01155           siLayerNum = tTopo->tibLayer(id);
01156           siDetNum = 1 ;
01157           siDetName = "TIB" ;
01158         } else if ( (hit->geographicalId()).subdetId() == StripSubdetector::TOB ){
01159           siLayerNum = tTopo->tobLayer(id);
01160           siDetNum = 2 ;
01161           siDetName = "TOB" ;
01162           //            } else if ( (hit->geographicalId()).subdetId() == StripSubdetector::TID ){
01163           //              // should we use side/wheel/ring/module/stereo() ?
01164           //              siLayerNum = tTopo->tidWheel(id);
01165           //              siDetNum = 3 ;
01166           //              siDetName = "TID" ;
01167           //            }else if ( (hit->geographicalId()).subdetId() == StripSubdetector::TEC ){
01168           //              //choices are side/petal/wheel/ring/module/glued/stereo
01169           //              siLayerNum = tTopo->tecWheel(id);
01170           //              siDetNum = 4 ;
01171           //              siDetName = "TEC" ;
01172         }else {
01173           siLayerNum = -999 ;
01174           siDetNum = -999 ;
01175           siDetName = "NULL" ;
01176         }
01177         //      const edm::Ref<edm::DetSetVector<SiStripCluster>, SiStripCluster, edm::refhelper::FindForDetSetVector<SiStripCluster> > clust=rechit.cluster();
01178         double Signal = 0 ;
01179         double Noise2 = 0 ;
01180         int StripCount = 0 ;
01181         //      if(clust.isNonnull()) {
01182         //        LogDebug("") << " barycenter " << clust->barycenter() ;
01183         //        const std::vector<uint16_t> amplitudes=clust->amplitudes();
01184         //        for(size_t i = 0 ; i<amplitudes.size(); i++ ){
01185         //          Signal +=amplitudes[i] ;
01186         //          //ignore for now         Noise2 +=SiStripNoiseService_.getNoise(detid,clust->firstStrip()+i)*SiStripNoiseService_.getNoise(detid,clust->firstStrip()+i);
01187         //          StripCount++;
01188         //        }
01189         //      } else {
01190         //        LogDebug("") << " null cluster " ;
01191         //      }
01192         //      LogDebug("") << "Signal " << Signal << " Noise2 " << Noise2 << " StripCount " << StripCount ;
01193 
01194         // Dump position info
01195         //      LogDebug("") << " Matched "
01196         //                       << "local position: "<<myposition.x()<<" "
01197         //                       << myposition.y()<<" "<<myposition.z()<<"\n"
01198         //                       << "local error: "<<myerror.xx()<<" "
01199         //                       << myerror.xy()<<" "<<myerror.yy() << "\n"
01200         //                       << "global position: " << position.x() << " "
01201         //                       <<  position.y()<<" "<< position.z()<<"\n"
01202         //                       << " siDetNum " << siDetNum
01203         //                       << " siLayerNum " << siLayerNum ;
01204 
01205         if( myHits < myMaxHits ) {
01206           MatchedHitX_[myHits] = position.x();
01207           MatchedHitY_[myHits] = position.y();
01208           MatchedHitZ_[myHits] = position.z();
01209 
01210 
01211           MatchedHitR_[myHits]=position.perp();
01212           MatchedHitPhi_[myHits]=position.phi();
01213           MatchedHitTheta_[myHits]=position.theta();
01214 
01215           MatchedHitSigX_[myHits]=sqrt(myerror.xx());
01216           MatchedHitSigY_[myHits]=sqrt(myerror.yy());
01217           MatchedHitCorr_[myHits]=myerror.xy()/sqrt(myerror.xx()*myerror.yy());
01218 
01219 
01220 
01221           MatchedHitSignal_[myHits] = Signal ;
01222           MatchedHitNoise_[myHits] = Noise2 ;
01223           MatchedHitWidth_[myHits] = StripCount ;
01224 
01225           MatchedDetector_[myHits] = siDetNum ;
01226           MatchedLayer_[myHits] = siLayerNum ;
01227 
01228           ++myHits ;
01229         }
01230       } // end if this is the right subdetector (TIB/TOB)
01231   } // end loop over hits
01232   NMatchedHits_ = myHits ;
01233 
01234   numSiMatchedHits_->Fill(NMatchedHits_);
01235 
01237 
01238 
01239 
01242   LogDebug("") << "Writing to myTree with " << NShowers_ << " Showers "
01243                << NStereoHits_ << " Si StereoHits "
01244                << NMonoHits_ << " Si MonoHits "
01245                << NMatchedHits_ << " Si MatchedHits " ;
01246 
01247   myTree_->Fill();
01248 
01249 
01250 
01251 
01252 
01253 } // end of Analyzer
01254 
01255 
01256 void SiStripElectronAnalyzer::endJob(){
01257   LogDebug("") << "Entering endJob " ;
01258   file_->cd() ;
01259   numCand_->Write();
01260   numElectrons_->Write();
01261   numSuperClusters_->Write();
01262 
01263   energySuperClusters_->Write();
01264   sizeSuperClusters_->Write();
01265   emaxSuperClusters_->Write();
01266   phiWidthSuperClusters_->Write();
01267 
01268   energySuperClustersEl_->Write();
01269   sizeSuperClustersEl_->Write();
01270   emaxSuperClustersEl_->Write();
01271   phiWidthSuperClustersEl_->Write();
01272 
01273   ptDiff->Write();
01274   pDiff->Write();
01275   pElectronFailed->Write();
01276   ptElectronFailed->Write();
01277   pElectronPassed->Write();
01278   ptElectronPassed->Write();
01279   sizeSuperClustersPassed->Write();
01280   sizeSuperClustersFailed->Write();
01281   //   energySuperClustersPassed->Write();
01282   //   energySuperClustersFailed->Write();
01283   //   eOverPPassed->Write();
01284   //   eOverPFailed->Write();
01285 
01286 
01287   numSiStereoHits_->Write();
01288   numSiMonoHits_->Write();
01289   numSiMatchedHits_->Write();
01290 
01291   // disable for large dataset
01292   LogDebug("") << " Writing out ntuple is disabled for now " ;
01293    myTree_->Write();
01294 
01295 
01296   file_->Close();
01297 }
01298 
01299 
01300 //
01301 // const member functions
01302 //
01303 
01304 //
01305 // static member functions
01306 //