CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/ElectroWeakAnalysis/WENu/src/WenuPlots.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    WenuPlots
00004 // Class:      WenuPlots
00005 // 
00006 /*
00007 
00008  Description: 
00009     this is an analyzer that reads pat::CompositeCandidate WenuCandidates
00010     and creates some plots
00011  Implementation:
00012     The code takes the output of the WenuCandidateFilter and
00013     * implements on them  a user defined selection 
00014     * implements the selection with one cut (configurable which cut) inverted
00015     * creates a set of basic plots with the Wenu Candidate distribution
00016       vs MET, MT etc. These plots are stored in a root file
00017     If you have several root files from different runs you have to run a macro
00018     to combine the output and have the final plots
00019 
00020     This analyser is PAT based in the sense that it reads CompositeCandidates,
00021     which are composed of a pat::MET plus a pat::Electron. You normally
00022     don't have to change this file when the CMSSW version changes because it
00023     contains only methods from the stable core of pat Objects. Most
00024     version dependent changes should be in WenuCandidateFilter.cc
00025  TO DO LIST:
00026     * more plots to be added
00027     * there should be an base Plots class from which WenuPlots and ZeePlots
00028       inherit. this makes sense since they have so many common methods
00029 
00030   Changes Log:
00031   12Feb09  First Release of the code for CMSSW_2_2_X
00032   16Sep09  tested that it works with 3_1_2 as well 
00033   09Sep09  added one extra iso with the name userIso_XX_
00034            
00035   Contact: 
00036   Nikolaos Rompotis  -  Nikolaos.Rompotis@Cern.ch
00037   Imperial College London
00038 
00039 
00040 */
00041 //
00042 // Original Author:  Nikolaos Rompotis
00043 
00044 
00045 #include "ElectroWeakAnalysis/WENu/interface/WenuPlots.h"
00046 
00047 WenuPlots::WenuPlots(const edm::ParameterSet& iConfig)
00048 
00049 {
00051 //                   I N P U T      P A R A M E T E R S
00053 //
00055 //  WENU COLLECTION   //////////////////////////////////////////////////////
00056 //
00057   
00058   wenuCollectionTag_ = iConfig.getUntrackedParameter<edm::InputTag>
00059     ("wenuCollectionTag");
00060   //
00061   // code parameters
00062   //
00063   std::string outputFile_D = "histos.root";
00064   outputFile_ = iConfig.getUntrackedParameter<std::string>("outputFile",
00065                                                            outputFile_D);
00066   //
00067   //
00068   // the selection cuts:
00069   trackIso_EB_ = iConfig.getUntrackedParameter<Double_t>("trackIso_EB");
00070   ecalIso_EB_ = iConfig.getUntrackedParameter<Double_t>("ecalIso_EB");
00071   hcalIso_EB_ = iConfig.getUntrackedParameter<Double_t>("hcalIso_EB");
00072   //
00073   trackIso_EE_ = iConfig.getUntrackedParameter<Double_t>("trackIso_EE");
00074   ecalIso_EE_ = iConfig.getUntrackedParameter<Double_t>("ecalIso_EE");
00075   hcalIso_EE_ = iConfig.getUntrackedParameter<Double_t>("hcalIso_EE");
00076   //
00077   sihih_EB_ = iConfig.getUntrackedParameter<Double_t>("sihih_EB");
00078   dphi_EB_ = iConfig.getUntrackedParameter<Double_t>("dphi_EB");
00079   deta_EB_ = iConfig.getUntrackedParameter<Double_t>("deta_EB");
00080   hoe_EB_ = iConfig.getUntrackedParameter<Double_t>("hoe_EB");
00081   userIso_EB_ = iConfig.getUntrackedParameter<Double_t>("userIso_EB", 1000.);
00082   //
00083   sihih_EE_ = iConfig.getUntrackedParameter<Double_t>("sihih_EE");
00084   dphi_EE_ = iConfig.getUntrackedParameter<Double_t>("dphi_EE");
00085   deta_EE_ = iConfig.getUntrackedParameter<Double_t>("deta_EE");
00086   hoe_EE_ = iConfig.getUntrackedParameter<Double_t>("hoe_EE");
00087   userIso_EE_ = iConfig.getUntrackedParameter<Double_t>("userIso_EE", 1000.);
00088   //
00089   trackIso_EB_inv = iConfig.getUntrackedParameter<Bool_t>("trackIso_EB_inv", 
00090                                                             false);
00091   ecalIso_EB_inv = iConfig.getUntrackedParameter<Bool_t>("ecalIso_EB_inv",
00092                                                            false);
00093   hcalIso_EB_inv = iConfig.getUntrackedParameter<Bool_t>("hcalIso_EB_inv",
00094                                                            false);
00095   //
00096   trackIso_EE_inv = iConfig.getUntrackedParameter<Bool_t>("trackIso_EE_inv",
00097                                                             false);
00098   ecalIso_EE_inv = iConfig.getUntrackedParameter<Bool_t>("ecalIso_EE_inv",
00099                                                            false);
00100   hcalIso_EE_inv = iConfig.getUntrackedParameter<Bool_t>("hcalIso_EE_inv",
00101                                                            false);
00102 
00103   //
00104   sihih_EB_inv = iConfig.getUntrackedParameter<Bool_t>("sihih_EB_inv",
00105                                                          false);
00106   dphi_EB_inv = iConfig.getUntrackedParameter<Bool_t>("dphi_EB_inv",
00107                                                         false);
00108   deta_EB_inv = iConfig.getUntrackedParameter<Bool_t>("deta_EB_inv",
00109                                                         false);
00110   hoe_EB_inv = iConfig.getUntrackedParameter<Bool_t>("hoe_EB_inv",
00111                                                         false);
00112   userIso_EB_inv = iConfig.getUntrackedParameter<Bool_t>("userIso_EB_inv",
00113                                                          false);
00114   //
00115   sihih_EE_inv = iConfig.getUntrackedParameter<Bool_t>("sihih_EE_inv",
00116                                                          false);
00117   dphi_EE_inv = iConfig.getUntrackedParameter<Bool_t>("dphi_EE_inv",
00118                                                         false);
00119   deta_EE_inv = iConfig.getUntrackedParameter<Bool_t>("deta_EE_inv",
00120                                                         false);
00121   hoe_EE_inv = iConfig.getUntrackedParameter<Bool_t>("hoe_EE_inv",
00122                                                         false);
00123   userIso_EE_inv = iConfig.getUntrackedParameter<Bool_t>("userIso_EE_inv",
00124                                                          false);
00125 
00126 }
00127 
00128 
00129 
00130 WenuPlots::~WenuPlots()
00131 {
00132  
00133    // do anything here that needs to be done at desctruction time
00134    // (e.g. close files, deallocate resources etc.)
00135 
00136 }
00137 
00138 
00139 //
00140 // member functions
00141 //
00142 
00143 // ------------ method called to for each event  ------------
00144 void
00145 WenuPlots::analyze(const edm::Event& iEvent, const edm::EventSetup& es)
00146 {
00147   using namespace std;
00148   //
00149   //  Get the collections here
00150   //
00151   edm::Handle<pat::CompositeCandidateCollection> WenuCands;
00152   iEvent.getByLabel(wenuCollectionTag_, WenuCands);
00153 
00154   if (not WenuCands.isValid()) {
00155     cout << "Warning: no wenu candidates in this event..." << endl;
00156     return;
00157   }
00158   //
00159   //
00160   const pat::CompositeCandidateCollection *wcands = WenuCands.product();
00161   const pat::CompositeCandidateCollection::const_iterator 
00162     wenuIter = wcands->begin();
00163   const pat::CompositeCandidate wenu = *wenuIter;
00164   //
00165   // get the parts of the composite candidate:
00166   const pat::Electron * myElec=
00167     dynamic_cast<const pat::Electron*> (wenu.daughter("electron"));
00168   const pat::MET * myMet=
00169     dynamic_cast<const pat::MET*> (wenu.daughter("met"));
00170   // some variables here
00171   double scEta = myElec->superCluster()->eta();
00172   double scPhi = myElec->superCluster()->phi();
00173   double scEt = myElec->superCluster()->energy()/cosh(scEta);
00174   double met    = myMet->et();
00175   double metPhi = myMet->phi();
00176   double mt  = sqrt(2.0*scEt*met*(1.0-(cos(scPhi)*cos(metPhi)+sin(scPhi)*sin(metPhi))));
00177 
00178   double trackIso = myElec->userIsolation(pat::TrackIso);
00179   double ecalIso = myElec->userIsolation(pat::EcalIso);
00180   double hcalIso = myElec->userIsolation(pat::HcalIso);
00181   double sihih = myElec->scSigmaIEtaIEta();
00182   double dphi = myElec->deltaPhiSuperClusterTrackAtVtx();
00183   double deta = myElec->deltaEtaSuperClusterTrackAtVtx();
00184   double HoE = myElec->hadronicOverEm();
00185 
00186 
00187 
00188 
00189   //
00190   //
00191   //
00192   // the inverted selection plots:
00193   if (CheckCutsInverse(myElec)){
00194     //std::cout << "-----------------INVERSION-----------passed" << std::endl;
00195     h_met_inverse->Fill(met);
00196     h_mt_inverse->Fill(mt);
00197     if(fabs(scEta)<1.479){
00198       h_met_inverse_EB->Fill(met);
00199       h_mt_inverse_EB->Fill(mt);
00200     }
00201     if(fabs(scEta)>1.479){
00202       h_met_inverse_EE->Fill(met);
00203       h_mt_inverse_EE->Fill(mt);
00204     }
00205   }
00206 
00207 
00209   //
00210   // N-1 plots: plot some variable so that all the other cuts are satisfied
00211   if ( fabs(scEta) < 1.479) { // reminder: the precise fiducial cuts are in
00212                               // in the filter
00213     if (CheckCutsNminusOne(myElec, 0)) 
00214       h_trackIso_eb_NmOne->Fill(trackIso);
00215   }
00216   else {
00217     if (CheckCutsNminusOne(myElec, 0)) 
00218       h_trackIso_ee_NmOne->Fill(trackIso);
00219   }
00220   // from here on you have only events that pass the full selection
00221   if (not CheckCuts(myElec)) return;
00223 
00224   h_met->Fill(met);
00225   h_mt->Fill(mt);
00226   if(fabs(scEta)<1.479){
00227     h_met_EB->Fill(met);
00228     h_mt_EB->Fill(mt);
00229 
00230     h_EB_trkiso->Fill( trackIso );
00231     h_EB_ecaliso->Fill( ecalIso );
00232     h_EB_hcaliso->Fill( hcalIso );
00233     h_EB_sIetaIeta->Fill( sihih );
00234     h_EB_dphi->Fill( dphi );
00235     h_EB_deta->Fill( deta );
00236     h_EB_HoE->Fill( HoE );
00237 
00238   }
00239   if(fabs(scEta)>1.479){
00240     h_met_EE->Fill(met);
00241     h_mt_EE->Fill(mt);
00242 
00243     h_EE_trkiso->Fill( trackIso );
00244     h_EE_ecaliso->Fill( ecalIso );
00245     h_EE_hcaliso->Fill( hcalIso );
00246     h_EE_sIetaIeta->Fill( sihih );
00247     h_EE_dphi->Fill( dphi );
00248     h_EE_deta->Fill( deta );
00249     h_EE_HoE->Fill( HoE );
00250 
00251   }
00252   // uncomment for debugging purposes
00253   //std::cout << "tracIso: " <<  trackIso << ", " << myElec->trackIso() << ", ecaliso: " << ecalIso << ", " << myElec->ecalIso() << ", hcaliso: " << hcalIso << ", "  << myElec->hcalIso() << std::endl;
00254 
00255   h_scEt->Fill(scEt);
00256   h_scEta->Fill(scEta);
00257   h_scPhi->Fill(scPhi);
00258 
00259 }
00260 
00261 /***********************************************************************
00262  *
00263  *  Checking Cuts and making selections:
00264  *  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
00265  *  all the available methods take input a pointer to a  pat::Electron
00266  *
00267  *  bool  CheckCuts(const pat::Electron *): 
00268  *                               true if the input selection is satisfied
00269  *  bool  CheckCutsInverse(const pat::Electron *ele):
00270  *               true if the cuts with inverted the ones specified in the
00271  *               cfg are satisfied
00272  *  bool  CheckCutsNminusOne(const pat::Electron *ele, int jj):
00273  *               true if all the cuts with cut #jj ignored are satisfied
00274  *
00275  ***********************************************************************/
00276 bool WenuPlots::CheckCuts( const pat::Electron *ele)
00277 {
00278   for (int i=0; i<nBarrelVars_; ++i) {
00279     if (not CheckCut(ele, i)) return false;
00280   }
00281   return true;
00282 }
00284 
00285 bool WenuPlots::CheckCutsInverse(const pat::Electron *ele)
00286 {
00287   for (int i=0; i<nBarrelVars_; ++i){
00288     if ( CheckCutInv(ele, i) == false) return false;
00289   }
00290   return true;
00291 
00292 }
00294 bool WenuPlots::CheckCutsNminusOne(const pat::Electron *ele, int jj)
00295 {
00296   for (int i=0; i<nBarrelVars_; ++i){
00297     if (i==jj) continue;
00298     if ( CheckCut(ele, i) == false) return false;
00299   }
00300   return true;
00301 }
00303 bool WenuPlots::CheckCut(const pat::Electron *ele, int i) {
00304   double fabseta = fabs(ele->superCluster()->eta());
00305   if ( fabseta<1.479) {
00306     return fabs(ReturnCandVar(ele, i)) < CutVars_[i];
00307   }
00308   return fabs(ReturnCandVar(ele, i)) < CutVars_[i+nBarrelVars_];
00309 }
00311 bool WenuPlots::CheckCutInv(const pat::Electron *ele, int i) {
00312   double fabseta = fabs(ele->superCluster()->eta());
00313   if ( fabseta<1.479) {
00314     if (InvVars_[i]) 
00315     return fabs(ReturnCandVar(ele, i))>CutVars_[i];
00316     return fabs(ReturnCandVar(ele, i)) < CutVars_[i];
00317   }
00318   if (InvVars_[i+nBarrelVars_]) {
00319     if (InvVars_[i])
00320       return fabs(ReturnCandVar(ele, i))>CutVars_[i+nBarrelVars_];    
00321   }
00322   return fabs(ReturnCandVar(ele, i)) < CutVars_[i+nBarrelVars_];
00323 }
00325 double WenuPlots::ReturnCandVar(const pat::Electron *ele, int i) {
00326   if (i==0) return ele->userIsolation(pat::TrackIso);
00327   else if (i==1) return ele->userIsolation(pat::EcalIso);
00328   else if (i==2) return ele->userIsolation(pat::HcalIso);
00329   else if (i==3) return ele->scSigmaIEtaIEta();
00330   else if (i==4) return ele->deltaPhiSuperClusterTrackAtVtx();
00331   else if (i==5) return ele->deltaEtaSuperClusterTrackAtVtx();
00332   else if (i==6) return ele->hadronicOverEm();
00333   else if (i==7) return ele->userIsolation(pat::User1Iso);
00334   std::cout << "Error in WenuPlots::ReturnCandVar" << std::endl;
00335   return -1.;
00336 
00337 }
00339 
00340 // ------------ method called once each job just before starting event loop  --
00341 void 
00342 WenuPlots::beginJob()
00343 {
00344   //std::cout << "In beginJob()" << std::endl;
00345   //  Double_t Pi = TMath::Pi();
00346   //  TString histo_file = outputFile_;
00347   //  histofile = new TFile( histo_file,"RECREATE");
00348 
00349   h_met         = new TH1F("h_met",         "h_met",         200, 0, 200);
00350   h_met_inverse = new TH1F("h_met_inverse", "h_met_inverse", 200, 0, 200);
00351 
00352   h_mt         = new TH1F("h_mt",         "h_mt",         200, 0, 200);
00353   h_mt_inverse = new TH1F("h_mt_inverse", "h_mt_inverse", 200, 0, 200);
00354 
00355 
00356   h_met_EB         = new TH1F("h_met_EB",         "h_met_EB",         200, 0, 200);
00357   h_met_inverse_EB = new TH1F("h_met_inverse_EB", "h_met_inverse_EB", 200, 0, 200);
00358 
00359   h_mt_EB         = new TH1F("h_mt_EB",         "h_mt_EB",         200, 0, 200);
00360   h_mt_inverse_EB = new TH1F("h_mt_inverse_EB", "h_mt_inverse_EB", 200, 0, 200);
00361 
00362 
00363   h_met_EE         = new TH1F("h_met_EE",         "h_met_EE",         200, 0, 200);
00364   h_met_inverse_EE = new TH1F("h_met_inverse_EE", "h_met_inverse_EE", 200, 0, 200);
00365 
00366   h_mt_EE         = new TH1F("h_mt_EE",         "h_mt_EE",         200, 0, 200);
00367   h_mt_inverse_EE = new TH1F("h_mt_inverse_EE", "h_mt_inverse_EE", 200, 0, 200);
00368 
00369 
00370   h_scEt  = new TH1F("h_scEt",  "h_scEt",  200,  0, 100);
00371   h_scEta = new TH1F("h_scEta", "h_scEta", 200, -3, 3);
00372   h_scPhi = new TH1F("h_scPhi", "h_scPhi", 200, -4, 4);
00373 
00374 
00375   //VALIDATION PLOTS
00376   //EB
00377   h_EB_trkiso = new TH1F("h_EB_trkiso","h_EB_trkiso",200 , 0.0, 9.0);
00378   h_EB_ecaliso = new TH1F("h_EB_ecaliso","h_EB_ecaliso",200, 0.0 , 9.0);
00379   h_EB_hcaliso = new TH1F("h_EB_hcaliso","h_EB_hcaliso",200, 0.0 , 9.0);
00380   h_EB_sIetaIeta = new TH1F("h_EB_sIetaIeta","h_EB_sIetaIeta",200, 0.0 , 0.02 );
00381   h_EB_dphi = new TH1F("h_EB_dphi","h_EB_dphi",200, -0.03 , 0.03 );
00382   h_EB_deta = new TH1F("h_EB_deta","h_EB_deta",200, -0.01 , 0.01) ;
00383   h_EB_HoE = new TH1F("h_EB_HoE","h_EB_HoE",200, 0.0 , 0.2 );
00384   //EE
00385   h_EE_trkiso = new TH1F("h_EE_trkiso","h_EE_trkiso",200 , 0.0, 9.0);
00386   h_EE_ecaliso = new TH1F("h_EE_ecaliso","h_EE_ecaliso",200, 0.0 , 9.0);
00387   h_EE_hcaliso = new TH1F("h_EE_hcaliso","h_EE_hcaliso",200, 0.0 , 9.0);
00388   h_EE_sIetaIeta = new TH1F("h_EE_sIetaIeta","h_EE_sIetaIeta",200, 0.0 , 0.1 );
00389   h_EE_dphi = new TH1F("h_EE_dphi","h_EE_dphi",200, -0.03 , 0.03 );
00390   h_EE_deta = new TH1F("h_EE_deta","h_EE_deta",200, -0.01 , 0.01) ;
00391   h_EE_HoE = new TH1F("h_EE_HoE","h_EE_HoE",200, 0.0 , 0.2 );
00392 
00393 
00394   //
00395   //
00396   h_trackIso_eb_NmOne = 
00397     new TH1F("h_trackIso_eb_NmOne","trackIso EB N-1 plot",80,0,8);
00398   h_trackIso_ee_NmOne = 
00399     new TH1F("h_trackIso_ee_NmOne","trackIso EE N-1 plot",80,0,8);
00400 
00401   
00402   // if you add some new variable change the nBarrelVars_ accordingly
00403   nBarrelVars_ = 8;
00404   //
00405   // Put EB variables together and EE variables together
00406   // number of barrel variables = number of endcap variable
00407   // if you don't want to use some variable put a very high cut
00408   CutVars_.push_back( trackIso_EB_ );//0
00409   CutVars_.push_back( ecalIso_EB_ ); //1
00410   CutVars_.push_back( hcalIso_EB_ ); //2
00411   CutVars_.push_back( sihih_EB_ );   //3
00412   CutVars_.push_back( dphi_EB_ );    //4
00413   CutVars_.push_back( deta_EB_ );    //5
00414   CutVars_.push_back( hoe_EB_ );     //6
00415   CutVars_.push_back( userIso_EB_ ); //7
00416   
00417   CutVars_.push_back( trackIso_EE_);//0
00418   CutVars_.push_back( ecalIso_EE_); //1
00419   CutVars_.push_back( hcalIso_EE_); //2
00420   CutVars_.push_back( sihih_EE_);   //3
00421   CutVars_.push_back( dphi_EE_);    //4
00422   CutVars_.push_back( deta_EE_);    //5
00423   CutVars_.push_back( hoe_EE_ );    //6 
00424   CutVars_.push_back( userIso_EE_ );//7 
00425   //
00426   InvVars_.push_back( trackIso_EB_inv);//0
00427   InvVars_.push_back( ecalIso_EB_inv); //1
00428   InvVars_.push_back( hcalIso_EB_inv); //2
00429   InvVars_.push_back( sihih_EB_inv);   //3
00430   InvVars_.push_back( dphi_EB_inv);    //4
00431   InvVars_.push_back( deta_EB_inv);    //5
00432   InvVars_.push_back( hoe_EB_inv);     //6
00433   InvVars_.push_back( userIso_EB_inv); //7
00434   //
00435   InvVars_.push_back( trackIso_EE_inv);//0
00436   InvVars_.push_back( ecalIso_EE_inv); //1
00437   InvVars_.push_back( hcalIso_EE_inv); //2
00438   InvVars_.push_back( sihih_EE_inv);   //3
00439   InvVars_.push_back( dphi_EE_inv);    //4
00440   InvVars_.push_back( deta_EE_inv);    //5
00441   InvVars_.push_back( hoe_EE_inv);     //6
00442   InvVars_.push_back( userIso_EE_inv); //7
00443   //
00444 
00445 
00446 }
00447 
00448 // ------------ method called once each job just after ending the event loop  -
00449 void 
00450 WenuPlots::endJob() {
00451   TFile * newfile = new TFile(TString(outputFile_),"RECREATE");
00452   h_met->Write();
00453   h_met_inverse->Write();
00454   h_mt->Write();
00455   h_mt_inverse->Write();
00456 
00457   h_met_EB->Write();
00458   h_met_inverse_EB->Write();
00459   h_mt_EB->Write();
00460   h_mt_inverse_EB->Write();
00461 
00462   h_met_EE->Write();
00463   h_met_inverse_EE->Write();
00464   h_mt_EE->Write();
00465   h_mt_inverse_EE->Write();
00466 
00467   h_scEt->Write();
00468   h_scEta->Write();
00469   h_scPhi->Write();
00470 
00471   h_EB_trkiso->Write();
00472   h_EB_ecaliso->Write();
00473   h_EB_hcaliso->Write();
00474   h_EB_sIetaIeta->Write();
00475   h_EB_dphi->Write();
00476   h_EB_deta->Write();
00477   h_EB_HoE->Write();
00478 
00479   h_EE_trkiso->Write();
00480   h_EE_ecaliso->Write();
00481   h_EE_hcaliso->Write();
00482   h_EE_sIetaIeta->Write();
00483   h_EE_dphi->Write();
00484   h_EE_deta->Write();
00485   h_EE_HoE->Write();
00486 
00487   //
00488   h_trackIso_eb_NmOne->Write();
00489   h_trackIso_ee_NmOne->Write();
00490   //
00491   newfile->Close();
00492 
00493 }
00494 
00495 
00496 //define this as a plug-in
00497 DEFINE_FWK_MODULE(WenuPlots);