CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/Calibration/EcalCalibAlgos/src/ZeePlots.cc

Go to the documentation of this file.
00001 
00002 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00003 
00004 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00005 #include "DataFormats/EcalDetId/interface/EBDetId.h"
00006 #include "DataFormats/DetId/interface/DetId.h"
00007 #include "CondFormats/EcalObjects/interface/EcalIntercalibConstants.h"
00008 #include "CondFormats/DataRecord/interface/EcalIntercalibConstantsRcd.h"
00009 #include "Calibration/Tools/interface/calibXMLwriter.h"
00010 #include "Calibration/Tools/interface/CalibrationCluster.h"
00011 #include "Calibration/Tools/interface/CalibElectron.h"
00012 #include "Calibration/Tools/interface/HouseholderDecomposition.h"
00013 #include "Calibration/Tools/interface/MinL3Algorithm.h"
00014 #include "Calibration/EcalCalibAlgos/interface/ZeePlots.h"
00015 #include "Calibration/EcalCalibAlgos/interface/ZeeKinematicTools.h"
00016 #include "DataFormats/EgammaCandidates/interface/Electron.h"
00017 #include "DataFormats/EgammaReco/interface/SuperCluster.h"
00018 #include "DataFormats/TrackReco/interface/Track.h"
00019 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00020 #include "DataFormats/TrackReco/interface/TrackExtraFwd.h"
00021 #include "TFile.h"
00022 #include "TH1.h"
00023 #include "TH2.h"
00024 #include "TF1.h"
00025 #include "TRandom.h"
00026 
00027 
00028 #include <iostream>
00029 #include <string>
00030 #include <stdexcept>
00031 #include <vector>
00032 
00033 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
00034 
00035 ZeePlots::ZeePlots( const char* fileName )
00036 {
00037 
00038   fileName_ = fileName;
00039   file_ = new TFile(fileName_, "RECREATE");
00040 }
00041 
00042 
00043 ZeePlots::~ZeePlots()
00044 {
00045   
00046   file_->Close();
00047   
00048   delete file_;
00049 
00050 }
00051 
00052 //========================================================================
00053 
00054 void ZeePlots::openFile(){
00055 
00056 
00057   file_ -> cd();
00058 
00059 }
00060 //========================================================================
00061 
00062 void ZeePlots::bookZMCHistograms(){
00063 
00064   file_ -> cd();
00065 
00066   h1_gen_ZMass_ = new TH1F("gen_ZMass","Generated Z mass",200,0.,150.);
00067   h1_gen_ZMass_->SetXTitle("gen_ZMass (GeV)");
00068   h1_gen_ZMass_->SetYTitle("events");
00069 
00070   h1_gen_ZEta_ = new TH1F("gen_ZEta","Eta of gen Z",200,-6.,6.);
00071   h1_gen_ZEta_->SetXTitle("#eta");
00072   h1_gen_ZEta_->SetYTitle("events");
00073 
00074   h1_gen_ZPhi_ = new TH1F("gen_ZPhi","Phi of gen Z",200,-4.,4.);
00075   h1_gen_ZPhi_->SetXTitle("#phi");
00076   h1_gen_ZPhi_->SetYTitle("events");
00077 
00078   h1_gen_ZRapidity_ = new TH1F("gen_ZRapidity","Rapidity of gen Z",200,-6.,6.);
00079   h1_gen_ZRapidity_->SetXTitle("Y");
00080   h1_gen_ZRapidity_->SetYTitle("events");
00081 
00082   h1_gen_ZPt_ = new TH1F("gen_ZPt","Pt of gen Z",200, 0.,100.);
00083   h1_gen_ZPt_->SetXTitle("p_{T} (GeV/c)");
00084   h1_gen_ZPt_->SetYTitle("events");
00085 
00086 
00087 }
00088 
00089 void ZeePlots::bookZHistograms(){
00090 
00091   file_ -> cd();
00092 
00093   h1_reco_ZEta_ = new TH1F("reco_ZEta","Eta of reco Z",200,-6.,6.);
00094   h1_reco_ZEta_->SetXTitle("#eta");
00095   h1_reco_ZEta_->SetYTitle("events");
00096   
00097   h1_reco_ZTheta_ = new TH1F("reco_ZTheta","Theta of reco Z",200, 0., 4.);
00098   h1_reco_ZTheta_->SetXTitle("#theta");
00099   h1_reco_ZTheta_->SetYTitle("events");
00100   
00101   h1_reco_ZRapidity_ = new TH1F("reco_ZRapidity","Rapidity of reco Z",200,-6.,6.);
00102   h1_reco_ZRapidity_->SetXTitle("Y");
00103   h1_reco_ZRapidity_->SetYTitle("events");
00104   
00105   h1_reco_ZPhi_ = new TH1F("reco_ZPhi","Phi of reco Z",100,-4.,4.);
00106   h1_reco_ZPhi_->SetXTitle("#phi");
00107   h1_reco_ZPhi_->SetYTitle("events");
00108   
00109   h1_reco_ZPt_ = new TH1F("reco_ZPt","Pt of reco Z",200,0.,100.);
00110   h1_reco_ZPt_->SetXTitle("p_{T} (GeV/c)");
00111   h1_reco_ZPt_->SetYTitle("events");
00112   
00113   
00114 }
00115 
00116 //========================================================================
00117 
00118 void ZeePlots::fillZInfo( std::pair<calib::CalibElectron*,calib::CalibElectron*> myZeeCandidate ) {
00119 
00120   h1_reco_ZEta_->Fill( ZeeKinematicTools::calculateZEta(myZeeCandidate) );
00121   h1_reco_ZTheta_->Fill( ZeeKinematicTools::calculateZTheta(myZeeCandidate) );
00122   h1_reco_ZRapidity_->Fill( ZeeKinematicTools::calculateZRapidity(myZeeCandidate) );
00123   h1_reco_ZPhi_->Fill( ZeeKinematicTools::calculateZPhi(myZeeCandidate) );
00124   h1_reco_ZPt_->Fill( ZeeKinematicTools::calculateZPt(myZeeCandidate) );
00125 
00126 }
00127 
00128 
00129 
00130 //========================================================================
00131 
00132 void ZeePlots::writeZHistograms() {
00133 
00134   file_->cd();
00135 
00136   h1_reco_ZEta_->Write();
00137   h1_reco_ZTheta_->Write();
00138   h1_reco_ZRapidity_->Write();
00139   h1_reco_ZPhi_->Write();
00140   h1_reco_ZPt_->Write();
00141   
00142 }
00143 
00144 //========================================================================
00145 
00146 void ZeePlots::writeMCZHistograms() {
00147 
00148   file_->cd();
00149   
00150   h1_gen_ZRapidity_->Write();
00151   h1_gen_ZPt_->Write();
00152   h1_gen_ZPhi_->Write();
00153 
00154 }
00155 
00156 //========================================================================
00157 
00158 void ZeePlots::fillZMCInfo( const HepMC::GenEvent* myGenEvent ) {
00159 
00160   file_->cd();
00161 
00162   for ( HepMC::GenEvent::particle_const_iterator p = myGenEvent->particles_begin();
00163         p != myGenEvent->particles_end(); ++p ) {//loop over MC particles
00164  
00165     if ( (*p)->pdg_id() == 23 && (*p)->status() == 2 ){
00166       
00167       h1_gen_ZMass_->Fill( (*p)->momentum().m() );
00168       h1_gen_ZEta_->Fill( (*p)->momentum().eta() );
00169       
00170       float genZ_Y = 0.5 * log ( ( (*p)->momentum().e() + (*p)->momentum().pz() ) /  ( (*p)->momentum().e() - (*p)->momentum().pz() ) )   ;
00171       
00172       h1_gen_ZRapidity_->Fill( genZ_Y );
00173       h1_gen_ZPt_->Fill((*p)->momentum().perp());
00174       h1_gen_ZPhi_->Fill((*p)->momentum().phi());
00175 
00176       
00177 
00178     }
00179   }//end loop over MC particles
00180 
00181   return;  
00182 }
00183 
00184 //========================================================================
00185 
00186 void ZeePlots::bookEleMCHistograms(){
00187 
00188   file_->cd();
00189 
00190   h1_mcEle_Energy_ = new TH1F("mcEleEnergy","mc EleEnergy",300,0.,300.);
00191   h1_mcEle_Energy_->SetXTitle("E (GeV)");
00192   h1_mcEle_Energy_->SetYTitle("events");
00193 
00194   h1_mcElePt_ = new TH1F("mcElePt","p_{T} of MC electrons",300,0.,300.);
00195   h1_mcElePt_->SetXTitle("p_{T}(GeV/c)");
00196   h1_mcElePt_->SetYTitle("events");
00197   
00198   h1_mcEleEta_ = new TH1F("mcEleEta","Eta of MC electrons",100,-4.,4.);
00199   h1_mcEleEta_->SetXTitle("#eta");
00200   h1_mcEleEta_->SetYTitle("events");
00201 
00202   h1_mcElePhi_ = new TH1F("mcElePhi","Phi of MC electrons",100,-4.,4.);
00203   h1_mcElePhi_->SetXTitle("#phi");
00204   h1_mcElePhi_->SetYTitle("events");
00205 
00206 }
00207 
00208 //========================================================================
00209 
00210 void ZeePlots::fillEleMCInfo( const HepMC::GenEvent* myGenEvent ) {
00211 
00212   file_->cd();
00213   
00214   for ( HepMC::GenEvent::particle_const_iterator p = myGenEvent->particles_begin();
00215         p != myGenEvent->particles_end(); ++p ) {
00216     
00217     if (  abs( (*p)->pdg_id() ) == 11 )
00218       {
00219         h1_mcEle_Energy_->Fill( (*p)->momentum().e() );
00220         h1_mcElePt_->Fill( (*p)->momentum().perp() );
00221         h1_mcEleEta_->Fill( (*p)->momentum().eta() );
00222         h1_mcElePhi_->Fill( (*p)->momentum().phi() );
00223         
00224       }//matches if (  abs( (*p)->pdg_id() ) == 11 )
00225 
00226   }//end loop over MC particles
00227   
00228 }
00229 
00230 //========================================================================
00231 void ZeePlots::bookEleHistograms(){
00232 
00233   file_->cd();
00234 
00235   h1_nEleReco_ = new TH1F("h1_nEleReco", "h1_nEleReco", 20, 0, 20 );
00236   h1_nEleReco_->SetXTitle("Num. of reco electrons");
00237   
00238   h1_recoEleEnergy_ = new TH1F("recoEleEnergy","EleEnergy from SC",300,0.,300.);
00239   h1_recoEleEnergy_->SetXTitle("eleSCEnergy(GeV)");
00240   h1_recoEleEnergy_->SetYTitle("events");
00241   
00242   h1_recoElePt_ = new TH1F("recoElePt","p_{T} of reco electrons",300,0.,300.);
00243   h1_recoElePt_->SetXTitle("p_{T}(GeV/c)");
00244   h1_recoElePt_->SetYTitle("events");
00245 
00246   h1_recoEleEta_ = new TH1F("recoEleEta","Eta of reco electrons",100,-4.,4.);
00247   h1_recoEleEta_->SetXTitle("#eta");
00248   h1_recoEleEta_->SetYTitle("events");
00249 
00250    
00251   h1_recoElePhi_ = new TH1F("recoElePhi","Phi of reco electrons",100,-4.,4.);
00252   h1_recoElePhi_->SetXTitle("#phi");
00253   h1_recoElePhi_->SetYTitle("events");
00254 
00255 
00256 
00257 }
00258 
00259 //========================================================================
00260 
00261 void ZeePlots::fillEleInfo(const reco::GsfElectronCollection* electronCollection) {
00262 
00263   file_->cd();
00264 
00265   h1_nEleReco_->Fill(electronCollection->size());
00266   
00267   for(reco::GsfElectronCollection::const_iterator eleIt = electronCollection->begin();   eleIt != electronCollection->end(); eleIt++)
00268     {
00269       
00270   file_->cd();
00271 
00272       h1_recoEleEnergy_->Fill( eleIt->superCluster()->energy() );
00273       h1_recoElePt_->Fill( eleIt->pt() );
00274       h1_recoEleEta_->Fill( eleIt->eta() );
00275       h1_recoElePhi_->Fill( eleIt->phi() );
00276       
00277     }//end loop on electrons   
00278 
00279 }
00280 
00281 //========================================================================
00282 
00283 void ZeePlots::writeEleHistograms(){
00284 
00285   file_->cd();
00286 
00287   std::cout << "Start with ZeePlots::writeEleHistograms(), done file_->cd(); " << std::endl;
00288  
00289   h1_recoEleEnergy_->Write();
00290   h1_recoElePt_->Write();
00291   h1_recoEleEta_->Write();
00292   h1_recoElePhi_->Write();
00293 
00294   std::cout << "Done with ZeePlots::writeEleHistograms() " << std::endl;
00295 
00296 }
00297 
00298 //========================================================================
00299 
00300 void ZeePlots::writeMCEleHistograms(){
00301 
00302   file_->cd();
00303 
00304   std::cout << "Start with ZeePlots::writeMCEleHistograms(), done file_->cd(); " << std::endl;
00305 
00306   h1_mcEle_Energy_->Write();
00307   h1_mcElePt_->Write();
00308   h1_mcEleEta_->Write();
00309   h1_mcElePhi_->Write();
00310 
00311   std::cout << "Done with ZeePlots::writeMCEleHistograms() " << std::endl;
00312 
00313 }
00314 
00315 //========================================================================
00316 
00317 void ZeePlots::bookHLTHistograms(){
00318 
00319   file_->cd();
00320 
00321   h1_FiredTriggers_= new TH1F("h1_FiredTriggers", "h1_FiredTriggers", 5,0,5);
00322  
00323   h1_HLTVisitedEvents_ = new TH1F("h1_HLTVisitedEvents", "h1_HLTVisitedEvents", 5,0,5);
00324 
00325   h1_HLT1Electron_FiredEvents_ =  new TH1F("h1_HLT1Electron_FiredEvents", "h1_HLT1Electron_FiredEvents", 5,0,5);
00326   h1_HLT2Electron_FiredEvents_ =  new TH1F("h1_HLT2Electron_FiredEvents", "h1_HLT2Electron_FiredEvents", 5,0,5);
00327   h1_HLT2ElectronRelaxed_FiredEvents_ =  new TH1F("h1_HLT2ElectronRelaxed_FiredEvents", "h1_HLT2ElectronRelaxed_FiredEvents", 5,0,5);
00328 
00329   h1_HLT1Electron_HLT2Electron_FiredEvents_ =  new TH1F("h1_HLT1Electron_HLT2Electron_FiredEvents", "h1_HLT1Electron_HLT2Electron_FiredEvents", 5,0,5);
00330   h1_HLT1Electron_HLT2ElectronRelaxed_FiredEvents_ =  new TH1F("h1_HLT1Electron_HLT2ElectronRelaxed_FiredEvents", "h1_HLT1Electron_HLT2ElectronRelaxed_FiredEvents", 5,0,5);
00331   h1_HLT2Electron_HLT2ElectronRelaxed_FiredEvents_ =  new TH1F("h1_HLT2Electron_HLT2ElectronRelaxed_FiredEvents", "h1_HLT2Electron_HLT2ElectronRelaxed_FiredEvents", 5,0,5);
00332 
00333   h1_HLT1Electron_HLT2Electron_HLT2ElectronRelaxed_FiredEvents_ =  new TH1F("h1_HLT1Electron_HLT2Electron_HLT2ElectronRelaxed_FiredEvents", "h1_HLT1Electron_HLT2Electron_HLT2ElectronRelaxed_FiredEvents", 5,0,5);
00334 
00335 
00336 }
00337 
00338 
00339 //========================================================================
00340 
00341 void ZeePlots::fillHLTInfo( edm::Handle<edm::TriggerResults> hltTriggerResultHandle ){
00342 
00343   file_->cd();
00344   
00345   int hltCount = hltTriggerResultHandle->size();
00346 
00347   bool aHLTResults[200] = { false };
00348     
00349   for(int i = 0 ; i < hltCount ; i++) {
00350 
00351     aHLTResults[i] = hltTriggerResultHandle->accept(i);
00352     if(aHLTResults[i])
00353       h1_FiredTriggers_->Fill(i);
00354 
00355     //HLT bit 32 = HLT1Electron
00356     //HLT bit 34 = HLT2Electron
00357     //HLT bit 35 = HLT2ElectronRelaxed
00358 
00359   }
00360 
00361   h1_HLTVisitedEvents_->Fill(1);
00362     
00363   if(aHLTResults[32] && !aHLTResults[34] && !aHLTResults[35])
00364     h1_HLT1Electron_FiredEvents_->Fill(1);
00365 
00366   if(aHLTResults[34] && !aHLTResults[32] && !aHLTResults[35])
00367     h1_HLT2Electron_FiredEvents_->Fill(1);
00368 
00369   if(aHLTResults[35] && !aHLTResults[32] && !aHLTResults[34])
00370     h1_HLT2ElectronRelaxed_FiredEvents_->Fill(1);
00371 
00372   if(aHLTResults[32] && aHLTResults[34] && !aHLTResults[35])
00373     h1_HLT1Electron_HLT2Electron_FiredEvents_->Fill(1);
00374 
00375   if(aHLTResults[32] && aHLTResults[35] && !aHLTResults[34])
00376     h1_HLT1Electron_HLT2ElectronRelaxed_FiredEvents_->Fill(1);
00377 
00378   if(aHLTResults[34] && aHLTResults[35] && !aHLTResults[32])
00379     h1_HLT2Electron_HLT2ElectronRelaxed_FiredEvents_->Fill(1);
00380 
00381   if(aHLTResults[32] && aHLTResults[34] && aHLTResults[35])
00382     h1_HLT1Electron_HLT2Electron_HLT2ElectronRelaxed_FiredEvents_->Fill(1);
00383 
00384 
00385 
00386 }
00387 
00388 
00389 void ZeePlots::fillEleClassesPlots( calib::CalibElectron* myEle ){
00390 
00391   int myClass = myEle->getRecoElectron()->classification();
00392 
00393   float myEta = myEle->getRecoElectron()->eta();
00394   
00395   if(myClass==0 || myClass==100)
00396     h1_occupancyVsEtaGold_->Fill(myEta);
00397   
00398   std::cout<< "[ZeePlots::fillEleClassesPlots]Done gold"<< std::endl;
00399   
00400   if(myClass==40 || myClass==140)
00401     h1_occupancyVsEtaCrack_->Fill(myEta);
00402   
00403   std::cout<< "[ZeePlots::fillEleClassesPlots]Done crack"<< std::endl;
00404   
00405   if( (myClass>=30 && myClass<=34) || (myClass>=130 && myClass<=134) )
00406     h1_occupancyVsEtaShower_->Fill(myEta);
00407   
00408   std::cout<< "[ZeePlots::fillEleClassesPlots]Done shower"<< std::endl;
00409   
00410   if( myClass==10 || myClass==20 || myClass==110 || myClass ==120)
00411     h1_occupancyVsEtaSilver_->Fill(myEta);
00412   
00413   std::cout<< "[ZeePlots::fillEleClassesPlots]Done"<< std::endl;
00414   
00415 }
00416 
00417 
00418 void ZeePlots::bookEleClassesPlots(){
00419 
00420   file_->cd();
00421 
00422   h1_occupancyVsEtaGold_ = new TH1F("occupancyVsEtaGold","occupancyVsEtaGold", 200, -4.,4.);
00423   h1_occupancyVsEtaGold_->SetYTitle("Electron statistics");
00424   h1_occupancyVsEtaGold_->SetXTitle("Eta channel");
00425 
00426   h1_occupancyVsEtaSilver_ = new TH1F("occupancyVsEtaSilver","occupancyVsEtaSilver", 200, -4.,4.);
00427   h1_occupancyVsEtaSilver_->SetYTitle("Electron statistics");
00428   h1_occupancyVsEtaSilver_->SetXTitle("Eta channel");
00429 
00430   h1_occupancyVsEtaShower_ = new TH1F("occupancyVsEtaShower","occupancyVsEtaShower", 200, -4.,4.);
00431   h1_occupancyVsEtaShower_->SetYTitle("Electron statistics");
00432   h1_occupancyVsEtaShower_->SetXTitle("Eta channel");
00433 
00434   h1_occupancyVsEtaCrack_ = new TH1F("occupancyVsEtaCrack","occupancyVsEtaCrack", 200, -4.,4.);
00435   h1_occupancyVsEtaCrack_->SetYTitle("Electron statistics");
00436   h1_occupancyVsEtaCrack_->SetXTitle("Eta channel");
00437 
00438 }
00439 
00440 void ZeePlots::writeEleClassesPlots(){
00441 
00442   file_->cd();
00443 
00444   h1_occupancyVsEtaGold_->Write();
00445   h1_occupancyVsEtaSilver_->Write();
00446   h1_occupancyVsEtaShower_->Write();
00447   h1_occupancyVsEtaCrack_->Write();
00448 
00449 }