CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/DQM/Physics/src/EwkElecDQM.cc

Go to the documentation of this file.
00001 #include "DQM/Physics/src/EwkElecDQM.h"
00002 
00003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00005 #include "DataFormats/Common/interface/Handle.h"
00006 
00007 #include "FWCore/ServiceRegistry/interface/Service.h"
00008 #include "CommonTools/UtilAlgos/interface/TFileService.h"
00009 
00010 #include "DQMServices/Core/interface/DQMStore.h"
00011 #include "DQMServices/Core/interface/MonitorElement.h"
00012 
00013 #include "DataFormats/TrackReco/interface/Track.h"
00014 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
00015 #include "DataFormats/VertexReco/interface/Vertex.h"
00016 
00017 //#include "DataFormats/MuonReco/interface/Muon.h"
00018 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h" // I guess this is the right one??
00019 // also need Fwd.h file ???
00020 #include "DataFormats/METReco/interface/MET.h"
00021 #include "DataFormats/JetReco/interface/Jet.h"
00022 //#include "DataFormats/JetReco/interface/CaloJet.h"
00023 //#include "DataFormats/METReco/interface/CaloMET.h"
00024 //#include "DataFormats/METReco/interface/CaloMETCollection.h"
00025 //#include "DataFormats/METReco/interface/CaloMETFwd.h"
00026 
00027 #include "DataFormats/GeometryVector/interface/Phi.h"
00028 
00029 #include "FWCore/Common/interface/TriggerNames.h"
00030 #include "FWCore/Framework/interface/Event.h"
00031 #include "DataFormats/Common/interface/TriggerResults.h"
00032 
00033 #include "DataFormats/Common/interface/View.h"
00034   
00035 using namespace edm;
00036 using namespace std;
00037 using namespace reco;
00038 
00039 EwkElecDQM::EwkElecDQM( const ParameterSet & cfg ) :
00040       // Input collections
00041       trigTag_(cfg.getUntrackedParameter<edm::InputTag> ("TrigTag", edm::InputTag("TriggerResults::HLT"))),
00042       //      muonTag_(cfg.getUntrackedParameter<edm::InputTag> ("MuonTag", edm::InputTag("muons"))),
00043       elecTag_(cfg.getUntrackedParameter<edm::InputTag> ("ElecTag", edm::InputTag("gsfElectrons"))), 
00044       metTag_(cfg.getUntrackedParameter<edm::InputTag> ("METTag", edm::InputTag("met"))),
00045       //      metIncludesMuons_(cfg.getUntrackedParameter<bool> ("METIncludesMuons", false)),
00046       jetTag_(cfg.getUntrackedParameter<edm::InputTag> ("JetTag", edm::InputTag("sisCone5CaloJets"))),
00047       vertexTag_    (cfg.getUntrackedParameter<edm::InputTag> ("VertexTag", edm::InputTag("offlinePrimaryVertices"))),
00048 
00049       // Main cuts 
00050       //      muonTrig_(cfg.getUntrackedParameter<std::string> ("MuonTrig", "HLT_Mu9")),
00051       //elecTrig_(cfg.getUntrackedParameter<std::vector< std::string > >("ElecTrig", "HLT_Ele10_SW_L1R")), 
00052       elecTrig_(cfg.getUntrackedParameter<std::vector< std::string > >("ElecTrig")), 
00053       //      ptCut_(cfg.getUntrackedParameter<double>("PtCut", 25.)),
00054       ptCut_(cfg.getUntrackedParameter<double>("PtCut", 10.)),
00055       //      etaCut_(cfg.getUntrackedParameter<double>("EtaCut", 2.1)),
00056       etaCut_(cfg.getUntrackedParameter<double>("EtaCut", 2.4)),
00057       sieieCutBarrel_(cfg.getUntrackedParameter<double>("SieieBarrel", 0.01)),
00058       sieieCutEndcap_(cfg.getUntrackedParameter<double>("SieieEndcap", 0.028)),
00059       detainCutBarrel_(cfg.getUntrackedParameter<double>("DetainBarrel", 0.0071)),
00060       detainCutEndcap_(cfg.getUntrackedParameter<double>("DetainEndcap", 0.0066)),
00061       //      isRelativeIso_(cfg.getUntrackedParameter<bool>("IsRelativeIso", true)),
00062       //      isCombinedIso_(cfg.getUntrackedParameter<bool>("IsCombinedIso", false)),
00063       //      isoCut03_(cfg.getUntrackedParameter<double>("IsoCut03", 0.1)),
00064       ecalIsoCutBarrel_(cfg.getUntrackedParameter<double>("EcalIsoCutBarrel", 5.7)),
00065       ecalIsoCutEndcap_(cfg.getUntrackedParameter<double>("EcalIsoCutEndcap", 5.0)),
00066       hcalIsoCutBarrel_(cfg.getUntrackedParameter<double>("HcalIsoCutBarrel", 8.1)),
00067       hcalIsoCutEndcap_(cfg.getUntrackedParameter<double>("HcalIsoCutEndcap", 3.4)),
00068       trkIsoCutBarrel_(cfg.getUntrackedParameter<double>("TrkIsoCutBarrel", 7.2)),
00069       trkIsoCutEndcap_(cfg.getUntrackedParameter<double>("TrkIsoCutEndcap", 5.1)),
00070       mtMin_(cfg.getUntrackedParameter<double>("MtMin", -999999)),
00071       mtMax_(cfg.getUntrackedParameter<double>("MtMax", 999999.)),
00072       metMin_(cfg.getUntrackedParameter<double>("MetMin", -999999.)),
00073       metMax_(cfg.getUntrackedParameter<double>("MetMax", 999999.)),
00074       //      acopCut_(cfg.getUntrackedParameter<double>("AcopCut", 2.)),
00075 
00076       // Muon quality cuts
00077       //      dxyCut_(cfg.getUntrackedParameter<double>("DxyCut", 0.2)),
00078       //      normalizedChi2Cut_(cfg.getUntrackedParameter<double>("NormalizedChi2Cut", 10.)),
00079       //      trackerHitsCut_(cfg.getUntrackedParameter<int>("TrackerHitsCut", 11)),
00080       //      isAlsoTrackerMuon_(cfg.getUntrackedParameter<bool>("IsAlsoTrackerMuon", true)),
00081 
00082       // Z rejection
00083       //      ptThrForZ1_(cfg.getUntrackedParameter<double>("PtThrForZ1", 20.)),
00084       //      ptThrForZ2_(cfg.getUntrackedParameter<double>("PtThrForZ2", 10.)),
00085 
00086       // Top rejection
00087       eJetMin_(cfg.getUntrackedParameter<double>("EJetMin", 999999.)),
00088       nJetMax_(cfg.getUntrackedParameter<int>("NJetMax", 999999)),
00089       PUMax_(cfg.getUntrackedParameter<unsigned int>("PUMax", 60)),
00090       PUBinCount_(cfg.getUntrackedParameter<unsigned int>("PUBinCount", 12))
00091       
00092 //       caloJetCollection_(cfg.getUntrackedParameter<edm:InputTag>("CaloJetCollection","sisCone5CaloJets"))
00093 
00094 
00095 
00096 {
00097   isValidHltConfig_ = false;
00098 
00099   // access to dbe
00100   theDbe = Service<DQMStore>().operator->();
00101   theDbe->setCurrentFolder("Physics/EwkElecDQM");
00102   init_histograms();
00103 
00104 }
00105 
00106 void EwkElecDQM::beginRun(const Run& iRun, const EventSetup& iSet) {
00107       nall = 0;
00108       nsel = 0;
00109 
00110       nrec = 0; 
00111       neid = 0;
00112       niso = 0; 
00113 //       nhlt = 0; 
00114 //       nmet = 0;
00115 
00116      // passed as parameter to HLTConfigProvider::init(), not yet used
00117      bool isConfigChanged = false;
00118      // isValidHltConfig_ could be used to short-circuit analyze() in case of problems
00119      isValidHltConfig_ = hltConfigProvider_.init( iRun, iSet, "HLT", isConfigChanged );
00120 
00121      LogTrace("") << "isValidHltConfig_=" << isValidHltConfig_ << "\n";
00122 }
00123 
00124 
00125 void EwkElecDQM::beginJob() {
00126 
00127 }
00128 
00129 void EwkElecDQM::init_histograms() {
00130 
00131     char chtitle[256] = "";
00132     //             pt_before_ = theDbe->book1D("PT_BEFORECUTS","Muon transverse momentum (global muon) [GeV],100,0.,100.);
00133     //             pt_after_ = theDbe->book1D("PT_LASTCUT","Muon transverse momentum (global muon) [GeV],100,0.,100.);
00134     
00135     pt_before_ = theDbe->book1D("PT_BEFORECUTS","Electron transverse momentum [GeV]",100,0.,100.);
00136     pt_after_ = theDbe->book1D("PT_LASTCUT","Electron transverse momentum [GeV]",100,0.,100.);
00137 
00138     eta_before_ = theDbe->book1D("ETA_BEFORECUTS","Electron pseudo-rapidity",50,-2.5,2.5);
00139     eta_after_ = theDbe->book1D("ETA_LASTCUT","Electron pseudo-rapidity",50,-2.5,2.5);
00140 
00141     sieiebarrel_before_ = theDbe->book1D("SIEIEBARREL_BEFORECUTS","Electron #sigma_{i#etai#eta} (barrel)",70,0.,0.07);
00142     sieiebarrel_after_ = theDbe->book1D("SIEIEBARREL_LASTCUT","Electron #sigma_{i#etai#eta} (barrel)",70,0.,0.07);
00143 
00144     sieieendcap_before_ = theDbe->book1D("SIEIEENDCAP_BEFORECUTS","Electron #sigma_{i#etai#eta} (endcap)",70,0.,0.07);
00145     sieieendcap_after_ = theDbe->book1D("SIEIEENDCAP_LASTCUT","Electron #sigma_{i#etai#eta} (endcap)",70,0.,0.07);
00146     
00147     detainbarrel_before_ = theDbe->book1D("DETAINBARREL_BEFORECUTS","Electron #Delta#eta_{in} (barrel)",40,-0.02,0.02);
00148     detainbarrel_after_ = theDbe->book1D("DETAINBARREL_LASTCUT","Electron #Delta#eta_{in} (barrel)",40,-0.02,0.02);
00149 
00150     detainendcap_before_ = theDbe->book1D("DETAINENDCAP_BEFORECUTS","Electron #Delta#eta_{in} (endcap)",40,-0.02,0.02);
00151     detainendcap_after_ = theDbe->book1D("DETAINENDCAP_LASTCUT","Electron #Delta#eta_{in} (endcap)",40,-0.02,0.02);
00152     
00153     //             dxy_before_ = theDbe->book1D("DXY_BEFORECUTS","Muon transverse distance to beam spot [cm]",100,-0.5,0.5);
00154     //             dxy_after_ = theDbe->book1D("DXY_LASTCUT","Muon transverse distance to beam spot [cm]",100,-0.5,0.5);
00155 
00156     //             chi2_before_ = theDbe->book1D("CHI2_BEFORECUTS","Normalized Chi2, inner track fit",100,0.,100.);
00157     //             chi2_after_ = theDbe->book1D("CHI2_LASTCUT","Normalized Chi2, inner track fit",100,0.,100.);
00158 
00159     //             nhits_before_ = theDbe->book1D("NHITS_BEFORECUTS","Number of hits, inner track",40,-0.5,39.5);
00160     //             nhits_after_ = theDbe->book1D("NHITS_LASTCUT","Number of hits, inner track",40,-0.5,39.5);
00161 
00162     //             tkmu_before_ = theDbe->book1D("TKMU_BEFORECUTS","Tracker-muon flag (for global muons)",2,-0.5,1.5);
00163     //             tkmu_after_ = theDbe->book1D("TKMU_LASTCUT","Tracker-muon flag (for global muons)",2,-0.5,1.5);
00164 
00165     //             if (isRelativeIso_) {
00166     //               if (isCombinedIso_) {
00167     //                 snprintf(chtitle, 255, "Relative (combined) isolation variable");
00168     //                 iso_before_ = theDbe->book1D("ISO_BEFORECUTS","Relative (combined) isolation variable",100, 0., 1.);
00169     //                 iso_after_ = theDbe->book1D("ISO_LASTCUT","Relative (combined) isolation variable",100, 0., 1.);
00170     //               } else {
00171     //                 snprintf(chtitle, 255, "Relative (tracker) isolation variable");
00172     //                 iso_before_ = theDbe->book1D("ISO_BEFORECUTS","Relative (tracker) isolation variable",100, 0., 1.);
00173     //                 iso_after_ = theDbe->book1D("ISO_LASTCUT","Relative (tracker) isolation variable",100, 0., 1.);
00174     //               }
00175     //             } else {
00176     //               if (isCombinedIso_) {
00177     //                 iso_before_ = theDbe->book1D("ISO_BEFORECUTS","Absolute (combined) isolation variable [GeV]",100, 0., 20.);
00178     //                 iso_after_ = theDbe->book1D("ISO_LASTCUT","Absolute (combined) isolation variable [GeV]",100, 0., 20.);
00179     //               } else {
00180     //                 iso_before_ = theDbe->book1D("ISO_BEFORECUTS","Absolute (tracker) isolation variable [GeV]",100, 0., 20.);
00181     //                 iso_after_ = theDbe->book1D("ISO_LASTCUT","Absolute (tracker) isolation variable [GeV]",100, 0., 20.);
00182     //               }
00183     //             }
00184 
00185             ecalisobarrel_before_ = theDbe->book1D("ECALISOBARREL_BEFORECUTS","Absolute electron ECAL isolation variable (barrel) [GeV]",50,0.,50.);
00186             ecalisobarrel_after_ = theDbe->book1D("ECALISOBARREL_LASTCUT","Absolute electron ECAL isolation variable (barrel) [GeV]",50,0.,50.);
00187 
00188             ecalisoendcap_before_ = theDbe->book1D("ECALISOENDCAP_BEFORECUTS","Absolute electron ECAL isolation variable (endcap) [GeV]",50,0.,50.);
00189             ecalisoendcap_after_ = theDbe->book1D("ECALISOENDCAP_LASTCUT","Absolute electron ECAL isolation variable (endcap) [GeV]",50,0.,50.);
00190 
00191             hcalisobarrel_before_ = theDbe->book1D("HCALISOBARREL_BEFORECUTS","Absolute electron HCAL isolation variable (barrel) [GeV]",50,0.,50.);
00192             hcalisobarrel_after_ = theDbe->book1D("HCALISOBARREL_LASTCUT","Absolute electron HCAL isolation variable (barrel) [GeV]",50,0.,50.);
00193 
00194             hcalisoendcap_before_ = theDbe->book1D("HCALISOENDCAP_BEFORECUTS","Absolute electron HCAL isolation variable (endcap) [GeV]",50,0.,50.);
00195             hcalisoendcap_after_ = theDbe->book1D("HCALISOENDCAP_LASTCUT","Absolute electron HCAL isolation variable (endcap) [GeV]",50,0.,50.);
00196 
00197             trkisobarrel_before_ = theDbe->book1D("TRKISOBARREL_BEFORECUTS","Absolute electron track isolation variable (barrel) [GeV]",50,0.,50.);
00198             trkisobarrel_after_ = theDbe->book1D("TRKISOBARREL_LASTCUT","Absolute electron track isolation variable (barrel) [GeV]",50,0.,50.);
00199 
00200             trkisoendcap_before_ = theDbe->book1D("TRKISOENDCAP_BEFORECUTS","Absolute electron track isolation variable (endcap) [GeV]",50,0.,50.);
00201             trkisoendcap_after_ = theDbe->book1D("TRKISOENDCAP_LASTCUT","Absolute electron track isolation variable (endcap) [GeV]",50,0.,50.);
00202 
00203 //             snprintf(chtitle, 255, "Trigger response (bit %s)", muonTrig_.data());
00204 //             trig_before_ = theDbe->book1D("TRIG_BEFORECUTS",chtitle,2,-0.5,1.5);
00205 //             trig_after_ = theDbe->book1D("TRIG_LASTCUT",chtitle,2,-0.5,1.5);
00206 
00207             //snprintf(chtitle, 255, "Trigger response (bit %s)", elecTrig_.data());
00208             trig_before_ = theDbe->book1D("TRIG_BEFORECUTS","Trigger response",2,-0.5,1.5); // elecTrig_ is now a vector of strings!
00209             trig_after_ = theDbe->book1D("TRIG_LASTCUT","Trigger response",2,-0.5,1.5);
00210 
00211             invmass_before_ = theDbe->book1D("INVMASS_BEFORECUTS","Di-electron invariant mass [GeV]",100,0.,200.);
00212             invmass_after_ = theDbe->book1D("INVMASS_AFTERCUTS","Di-electron invariant mass [GeV]",100,0.,200.);
00213 
00214             invmassPU_before_ = theDbe->book2D("INVMASS_PU_BEFORECUTS","Di-electron invariant mass [GeV] vs PU; mass [GeV]; PU count",100,0.,200., PUBinCount_, -0.5, PUMax_+0.5);
00215             invmassPU_afterZ_ = theDbe->book2D("INVMASS_PU_AFTERZCUTS","Di-electron invariant mass [GeV] vs PU; mass [GeV]; PU count",100,0.,200., PUBinCount_, -0.5, PUMax_+0.5);
00216 
00217             npvs_before_ = theDbe->book1D("NPVs_BEFORECUTS","Number of Valid Primary Vertices; nGoodPVs",PUMax_+1,-0.5,PUMax_+0.5);
00218             //npvs_afterW_ = theDbe->book1D("NPVs_AFTERWCUTS","Number of Valid Primary Vertices",PUMax_+1,-0.5,PUMax_+0.5);
00219             npvs_afterZ_ = theDbe->book1D("NPVs_AFTERZCUTS","Number of Valid Primary Vertices; nGoodPVs",PUMax_+1,-0.5,PUMax_+0.5);
00220 
00221 
00222             nelectrons_before_ = theDbe->book1D("NELECTRONS_BEFORECUTS","Number of electrons in event",10,-0.5,9.5);
00223             nelectrons_after_ = theDbe->book1D("NELECTRONS_AFTERCUTS","Number of electrons in event",10,-0.5,9.5);
00224 
00225             snprintf(chtitle, 255, "Transverse mass (%s) [GeV]", metTag_.label().data());
00226             mt_before_ = theDbe->book1D("MT_BEFORECUTS",chtitle,150,0.,300.);
00227             mt_after_ = theDbe->book1D("MT_LASTCUT",chtitle,150,0.,300.);
00228 
00229 //             snprintf(chtitle, 255, "Transverse mass (%s) [GeV]", metTag_.label().data());
00230 //             mt_before_ = theDbe->book1D("MT_BEFORECUTS",chtitle,150,0.,300.);
00231 //             mt_after_ = theDbe->book1D("MT_LASTCUT",chtitle,150,0.,300.);
00232 
00233             snprintf(chtitle, 255, "Missing transverse energy (%s) [GeV]", metTag_.label().data());
00234             met_before_ = theDbe->book1D("MET_BEFORECUTS",chtitle,100,0.,200.);
00235             met_after_ = theDbe->book1D("MET_LASTCUT",chtitle,100,0.,200.);
00236 
00237 //             snprintf(chtitle, 255, "MU-MET (%s) acoplanarity", metTag_.label().data());
00238 //             acop_before_ = theDbe->book1D("ACOP_BEFORECUTS",chtitle,50,0.,M_PI);
00239 //             acop_after_ = theDbe->book1D("ACOP_LASTCUT",chtitle,50,0.,M_PI);
00240 
00241 //             snprintf(chtitle, 255, "Z rejection: number of muons above %.2f GeV", ptThrForZ1_);
00242 //             nz1_before_ = theDbe->book1D("NZ1_BEFORECUTS",chtitle,10,-0.5,9.5);
00243 //             nz1_after_ = theDbe->book1D("NZ1_LASTCUT",chtitle,10,-0.5,9.5);
00244 
00245 //             snprintf(chtitle, 255, "Z rejection: number of muons above %.2f GeV", ptThrForZ2_);
00246 //             nz2_before_ = theDbe->book1D("NZ2_BEFORECUTS",chtitle,10,-0.5,9.5);
00247 //             nz2_after_ = theDbe->book1D("NZ2_LASTCUT",chtitle,10,-0.5,9.5);
00248 
00249              snprintf(chtitle, 255, "Number of jets (%s) above %.2f GeV", jetTag_.label().data(), eJetMin_);
00250              njets_before_ = theDbe->book1D("NJETS_BEFORECUTS",chtitle,10,-0.5,9.5);
00251              njets_after_  = theDbe->book1D("NJETS_LASTCUT",chtitle,10,-0.5,9.5);
00252 
00253              snprintf(chtitle, 255, "Jet with highest E_{T} (%s)", jetTag_.label().data());
00254              jet_et_before_       = theDbe->book1D("JETET1_BEFORECUTS",chtitle, 20, 0., 200.0);
00255              jet_et_after_       = theDbe->book1D("JETET1_AFTERCUTS",chtitle, 20, 0., 200.0);
00256 
00257              snprintf(chtitle, 255, "Eta of Jet with highest E_{T} (%s)", jetTag_.label().data());
00258              jet_eta_before_       = theDbe->book1D("JETETA1_BEFORECUTS",chtitle, 20, -5, 5);
00259              jet_eta_after_       = theDbe->book1D("JETETA1_AFTERCUTS",chtitle, 20, -5, 5);
00260 
00261 //           snprintf(chtitle, 255, "Jet with 2nd highest E_{T} (%s)", jetTag_.label().data());
00262 //           jet2_et_before      = theDbe->book1D("JETET2_BEFORECUTS",chtitle, 20, 0., 200.0);
00263 //           jet2_et_after       = theDbe->book1D("JETET2_AFTERCUTS",chtitle, 20, 0., 200.0);
00264              
00265 
00266 
00267 }
00268 
00269 
00270 void EwkElecDQM::endJob() {
00271 }
00272 
00273 void EwkElecDQM::endRun(const Run& r, const EventSetup&) {
00274 
00275   // overall
00276   double all = nall;
00277   double esel = nsel/all;
00278   LogVerbatim("") << "\n>>>>>> SELECTION SUMMARY BEGIN >>>>>>>>>>>>>>>";
00279   LogVerbatim("") << "Total number of events analyzed: " << nall << " [events]";
00280   LogVerbatim("") << "Total number of events selected: " << nsel << " [events]";
00281   LogVerbatim("") << "Overall efficiency:             " << "(" << setprecision(4) << esel*100. <<" +/- "<< setprecision(2) << sqrt(esel*(1-esel)/all)*100. << ")%";
00282   
00283   double erec = nrec/all;
00284   double eeid = neid/all;
00285   double eiso = niso/all;
00286 //   double ehlt = nhlt/all;
00287 //   double emet = nmet/all;
00288   
00289   // general reconstruction step??
00290   double num = nrec;
00291   double eff = erec;
00292   double err = sqrt(eff*(1-eff)/all);
00293   LogVerbatim("") << "Passing Pt/Eta/Quality cuts:    " << num << " [events], (" << setprecision(4) << eff*100. <<" +/- "<< setprecision(2) << err*100. << ")%";
00294 
00295   // electron ID step  
00296   num = neid;
00297   eff = eeid;
00298   err = sqrt(eff*(1-eff)/all);
00299   double effstep = 0.;
00300   double errstep = 0.;
00301   if (nrec>0) effstep = eeid/erec;
00302   if (nrec>0) errstep = sqrt(effstep*(1-effstep)/nrec);
00303   LogVerbatim("") << "Passing eID cuts:         " << num << " [events], (" << setprecision(4) << eff*100. <<" +/- "<< setprecision(2) << err*100. << ")%, to previous step: (" <<  setprecision(4) << effstep*100. << " +/- "<< setprecision(2) << errstep*100. <<")%";
00304   
00305   // isolation step  
00306   num = niso;
00307   eff = eiso;
00308   err = sqrt(eff*(1-eff)/all);
00309   effstep = 0.;
00310   errstep = 0.;
00311   if (neid>0) effstep = eiso/eeid;
00312   if (neid>0) errstep = sqrt(effstep*(1-effstep)/neid);
00313   LogVerbatim("") << "Passing isolation cuts:         " << num << " [events], (" << setprecision(4) << eff*100. <<" +/- "<< setprecision(2) << err*100. << ")%, to previous step: (" <<  setprecision(4) << effstep*100. << " +/- "<< setprecision(2) << errstep*100. <<")%";
00314   
00315 //   // trigger step
00316 //   num = nhlt;
00317 //   eff = ehlt;
00318 //   err = sqrt(eff*(1-eff)/all);
00319 //   effstep = 0.;
00320 //   errstep = 0.;
00321 //   if (niso>0) effstep = ehlt/eiso;
00322 //   if (niso>0) errstep = sqrt(effstep*(1-effstep)/niso);
00323 //   LogVerbatim("") << "Passing HLT criteria:           " << num << " [events], (" << setprecision(4) << eff*100. <<" +/- "<< setprecision(2) << err*100. << ")%, to previous step: (" <<  setprecision(4) << effstep*100. << " +/- "<< setprecision(2) << errstep*100. <<")%";
00324   
00325   // trigger step
00326   num = nsel;
00327   eff = esel;
00328   err = sqrt(eff*(1-eff)/all);
00329   effstep = 0.;
00330   errstep = 0.;
00331   if (niso>0) effstep = esel/eiso;
00332   if (niso>0) errstep = sqrt(effstep*(1-effstep)/niso);
00333   LogVerbatim("") << "Passing HLT criteria:           " << num << " [events], (" << setprecision(4) << eff*100. <<" +/- "<< setprecision(2) << err*100. << ")%, to previous step: (" <<  setprecision(4) << effstep*100. << " +/- "<< setprecision(2) << errstep*100. <<")%";
00334   
00335 //   // met/acoplanarity cuts 
00336 //   num = nmet;
00337 //   eff = emet;
00338 //   err = sqrt(eff*(1-eff)/all);
00339 //   effstep = 0.;
00340 //   errstep = 0.;
00341 //   if (nhlt>0) effstep = emet/ehlt;
00342 //   if (nhlt>0) errstep = sqrt(effstep*(1-effstep)/nhlt);
00343 //   LogVerbatim("") << "Passing MET/acoplanarity cuts:  " << num << " [events], (" << setprecision(4) << eff*100. <<" +/- "<< setprecision(2) << err*100. << ")%, to previous step: (" <<  setprecision(4) << effstep*100. << " +/- "<< setprecision(2) << errstep*100. <<")%";
00344   
00345 //   // Z/top selection cuts ALSO LAST STEP so "sel" for "selection"
00346 //   num = nsel;
00347 //   eff = esel;
00348 //   err = sqrt(eff*(1-eff)/all);
00349 //   effstep = 0.;
00350 //   errstep = 0.;
00351 //   if (nmet>0) effstep = esel/emet;
00352 //   if (nmet>0) errstep = sqrt(effstep*(1-effstep)/nmet);
00353 //   LogVerbatim("") << "Passing Z/top rejection cuts:   " << num << " [events], (" << setprecision(4) << eff*100. <<" +/- "<< setprecision(2) << err*100. << ")%, to previous step: (" <<  setprecision(4) << effstep*100. << " +/- "<< setprecision(2) << errstep*100. <<")%";
00354   
00355   LogVerbatim("") << ">>>>>> SELECTION SUMMARY END   >>>>>>>>>>>>>>>\n";
00356 }
00357 
00358 void EwkElecDQM::analyze (const Event & ev, const EventSetup &) {
00359       
00360       // Reset global event selection flags
00361       bool rec_sel = false;
00362       bool eid_sel = false;
00363       bool iso_sel = false;
00364 //       bool hlt_sel = false;
00365       bool all_sel = false;
00366 
00367 //       // Muon collection
00368 //       Handle<View<Muon> > muonCollection;
00369 //       if (!ev.getByLabel(muonTag_, muonCollection)) {
00370 //             LogWarning("") << ">>> Muon collection does not exist !!!";
00371 //             return;
00372 //       }
00373 //       unsigned int muonCollectionSize = muonCollection->size();
00374 
00375       // Electron collection
00376       Handle<View<GsfElectron> > electronCollection;
00377       if (!ev.getByLabel(elecTag_, electronCollection)) {
00378         //LogWarning("") << ">>> Electron collection does not exist !!!";
00379         return;
00380       }
00381       unsigned int electronCollectionSize = electronCollection->size();
00382 
00383       // Beam spot
00384       Handle<reco::BeamSpot> beamSpotHandle;
00385       if (!ev.getByLabel(InputTag("offlineBeamSpot"), beamSpotHandle)) {
00386         //LogWarning("") << ">>> No beam spot found !!!";
00387         return;
00388       }
00389         // MET
00390       double met_px = 0.;
00391       double met_py = 0.;
00392       Handle<View<MET> > metCollection;
00393       if (!ev.getByLabel(metTag_, metCollection)) {
00394         //LogWarning("") << ">>> MET collection does not exist !!!";
00395         return;
00396       }
00397       const MET& met = metCollection->at(0);
00398       met_px = met.px();
00399       met_py = met.py();
00400 //       if (!metIncludesMuons_) {
00401 //             for (unsigned int i=0; i<muonCollectionSize; i++) {
00402 //                   const Muon& mu = muonCollection->at(i);
00403 //                   if (!mu.isGlobalMuon()) continue;
00404 //                   met_px -= mu.px();
00405 //                   met_py -= mu.py();
00406 //             }
00407 //       }
00408       double met_et = sqrt(met_px*met_px+met_py*met_py);
00409       LogTrace("") << ">>> MET, MET_px, MET_py: " << met_et << ", " << met_px << ", " << met_py << " [GeV]";
00410       met_before_->Fill(met_et);
00411 
00412 
00413       // Vertices in the event
00414       int npvCount = 0;
00415       Handle<View<reco::Vertex> > vertexCollection;
00416            if (!ev.getByLabel(vertexTag_, vertexCollection)) {
00417                  LogError("") << ">>> Vertex collection does not exist !!!";
00418                  return;
00419             }
00420       for (unsigned int i=0; i<vertexCollection->size(); i++) {
00421             const Vertex& vertex = vertexCollection->at(i);
00422             if (vertex.isValid()) npvCount++;
00423       }
00424       npvs_before_->Fill(npvCount);
00425 
00426 
00427       // Trigger
00428       Handle<TriggerResults> triggerResults;
00429       if (!ev.getByLabel(trigTag_, triggerResults)) {
00430         //LogWarning("") << ">>> TRIGGER collection does not exist !!!";
00431         return;
00432       }
00433       const edm::TriggerNames & trigNames = ev.triggerNames(*triggerResults);
00434       bool trigger_fired = false;
00435       /*
00436       for (unsigned int i=0; i<triggerResults->size(); i++) {
00437             if (triggerResults->accept(i)) {
00438                   LogTrace("") << "Accept by: " << i << ", Trigger: " << trigNames.triggerName(i);
00439             }
00440       }
00441       */
00442 
00443       // the following gives error on CRAFT08 data where itrig1=19 (vector index out of range)
00444       /*
00445       int itrig1 = trigNames.triggerIndex(muonTrig_);
00446       if (triggerResults->accept(itrig1)) trigger_fired = true;
00447       */
00448       //suggested replacement: lm250909
00449       for (unsigned int i=0; i<triggerResults->size(); i++) 
00450         {
00451           std::string trigName = trigNames.triggerName(i);        
00452           bool found=false; 
00453           
00454 //        for (unsigned int j = 0; j < elecTrig_.size(); j++)
00455 //          {
00456 //            if ( trigName == elecTrig_.at(j) && triggerResults->accept(i)) 
00457 //              {
00458 //                trigger_fired = true;
00459 //              }
00460 //          }
00461 
00462 
00463          for(unsigned int index=0; index<elecTrig_.size() && found==false; index++) {
00464            size_t trigPath = trigName.find(elecTrig_.at(index)); // 0 if found, pos if not
00465                    if (trigPath==0) found=true;
00466               }
00467               if(!found) continue;
00468               
00469               bool prescaled=false;    
00470               for (unsigned int ps= 0; ps<  hltConfigProvider_.prescaleSize(); ps++){
00471                   const unsigned int prescaleValue = hltConfigProvider_.prescaleValue(ps, trigName) ;
00472                   if (prescaleValue != 1) prescaled =true;
00473               }
00474                        
00475               if(triggerResults->accept(i) && !prescaled) trigger_fired=true;
00476 
00477         }
00478 
00479 
00480       LogTrace("") << ">>> Trigger bit: " << trigger_fired << " for one of ( " ;
00481       for (unsigned int k = 0; k < elecTrig_.size(); k++)
00482         {
00483           LogTrace("") << elecTrig_.at(k) << " ";
00484         }
00485       LogTrace("") << ")";
00486       trig_before_->Fill(trigger_fired);
00487 
00488 //       // Loop to reject/control Z->mumu is done separately
00489 //       unsigned int nmuonsForZ1 = 0;
00490 //       unsigned int nmuonsForZ2 = 0;
00491 //       for (unsigned int i=0; i<muonCollectionSize; i++) {
00492 //             const Muon& mu = muonCollection->at(i);
00493 //             if (!mu.isGlobalMuon()) continue;
00494 //             double pt = mu.pt();
00495 //             if (pt>ptThrForZ1_) nmuonsForZ1++;
00496 //             if (pt>ptThrForZ2_) nmuonsForZ2++;
00497 //       }
00498 //       LogTrace("") << "> Z rejection: muons above " << ptThrForZ1_ << " [GeV]: " << nmuonsForZ1;
00499 //       LogTrace("") << "> Z rejection: muons above " << ptThrForZ2_ << " [GeV]: " << nmuonsForZ2;
00500 //       nz1_before_->Fill(nmuonsForZ1);
00501 //       nz2_before_->Fill(nmuonsForZ2);
00502       
00503       // Jet collection
00504       Handle<View<Jet> > jetCollection;
00505       if (!ev.getByLabel(jetTag_, jetCollection)) {
00506         //LogError("") << ">>> JET collection does not exist !!!";
00507         return;
00508       }      
00509       float electron_et   = -8.0;
00510       float electron_eta  = -8.0;
00511       float electron_phi  = -8.0;
00512       float electron2_et  = -9.0;
00513       float electron2_eta = -9.0;
00514       float electron2_phi = -9.0;
00515       //need to get some electron info so jets can be cleaned of them
00516       for (unsigned int i=0; i<electronCollectionSize; i++) 
00517         {
00518           const GsfElectron& elec = electronCollection->at(i);   
00519 
00520           if (i < 1)
00521             {
00522                electron_et   = elec.pt();
00523                electron_eta  = elec.eta();
00524                electron_phi  = elec.phi();
00525             }
00526           if (i == 2)
00527             {
00528                electron2_et  = elec.pt();
00529                electron2_eta = elec.eta();
00530                electron2_phi = elec.phi();
00531             }       
00532         }
00533 
00534       float jet_et    = -8.0;
00535       float jet_eta   = -8.0;
00536       int   jet_count = 0;
00537       float jet2_et   = -9.0;
00538       unsigned int jetCollectionSize = jetCollection->size();
00539       int njets = 0;
00540       for (unsigned int i=0; i<jetCollectionSize; i++) {
00541         const Jet& jet = jetCollection->at(i);
00542         
00543         float jet_current_et = jet.et();
00544 //      cout << "jet_current_et " << jet_current_et << endl;
00545         // if it overlaps with electron, it is not a jet
00546         if ( electron_et>0.0 && fabs(jet.eta()-electron_eta ) < 0.2 
00547              && calcDeltaPhi(jet.phi(), electron_phi ) < 0.2)
00548           continue;
00549         if ( electron2_et>0.0&& fabs(jet.eta()-electron2_eta) < 0.2 
00550              && calcDeltaPhi(jet.phi(), electron2_phi) < 0.2) 
00551           continue;
00552 
00553         // if it has too low Et, throw away
00554 //      if (jet_current_et < eJetMin_) continue; //Keep if only want to plot above jet cut
00555 
00556         if (jet.et()>eJetMin_) 
00557           {
00558             njets++;
00559             jet_count++;
00560           }
00561         if (jet_current_et > jet_et) 
00562           {
00563             jet2_et  = jet_et;  // 2nd highest jet get's et from current highest
00564             jet_et   = jet.et(); // current highest jet gets et from the new highest
00565             jet_eta  = jet.eta();
00566           } 
00567         else if (jet_current_et > jet2_et) 
00568           {
00569             jet2_et  = jet.et();
00570           }
00571       }
00572 
00573       //Fill After all electron cuts (or both before and after)
00574       if (jet_et>10) //don't want low energy "jets"
00575         {
00576           jet_et_before_   ->Fill(jet_et);
00577 //        jet2_et_before_  ->Fill(jet2_et);
00578           jet_eta_before_  ->Fill(jet_eta);
00579         }
00580 
00581 
00582       LogTrace("") << ">>> Total number of jets: " << jetCollectionSize;
00583       LogTrace("") << ">>> Number of jets above " << eJetMin_ << " [GeV]: " << njets;
00584       njets_before_->Fill(njets);
00585 
00586 
00587       // Start counting
00588       nall++;
00589 
00590       // Histograms per event should be done only once, so keep track of them
00591       bool hlt_hist_done = false;
00592       //bool minv_hist_done = false;
00593        bool met_hist_done = false;
00594 //       bool nz1_hist_done = false;
00595 //       bool nz2_hist_done = false;
00596       bool njets_hist_done = false;
00597 
00598       // Central selection criteria
00599       //const int NFLAGS = 13; // number of individual selection criteria
00600       const int NFLAGS = 11; // number of individual selection criteria
00601       // 0: pt cut           | rec
00602       // 1: eta cut          | rec
00603       // 2: sieie            | eid
00604       // 3: detain           | eid
00605       // 4: ecal iso         | iso
00606       // 5: hcal iso         | iso
00607       // 6: trk iso          | iso
00608       // 7: trigger fired    | hlt/all
00609       bool electron_sel[NFLAGS];
00610 
00611       // for invariant mass calculation
00612       // keep track of highest-pt electrons for initial (RECO) electrons 
00613       // and "good" electrons (passing all cuts)
00614       // first array dimension is for first or second good electron
00615       // second array dimension is for relevant quantities of good electron
00616       //    [0]: 1 for electron found or 0 for not found (if 0, no other quantities filled)
00617       //    [1]: mSqr
00618       //    [2]: E
00619       //    [3]: px
00620       //    [4]: py
00621       //    [5]: pz
00622       // inv mass = sqrt(m_1^2 + m_2^2 + 2*(E_1*E_2 - (px1*px2 + py1*py2 + pz1+pz2) ) )
00623       double electron[2][6];
00624       double goodElectron[2][6];
00625       nGoodElectrons = 0;
00626       for (unsigned int i = 0; i < 2; i++)
00627         {
00628           for (unsigned int j = 0; j < 6; j++)
00629             {
00630               electron[i][j] = 0.;
00631               goodElectron[i][j] = 0.;
00632             }
00633         }
00634 
00635       for (unsigned int i=0; i<electronCollectionSize; i++) 
00636         {
00637           for (int j=0; j<NFLAGS; ++j) 
00638             {
00639               electron_sel[j] = false;
00640             }
00641           
00642           const GsfElectron& elec = electronCollection->at(i);
00643           //if (!mu.isGlobalMuon()) continue;
00644           //if (mu.globalTrack().isNull()) continue;
00645           //if (mu.innerTrack().isNull()) continue;
00646           
00647           LogTrace("") << "> elec: processing electron number " << i << "...";
00648           //reco::TrackRef gm = mu.globalTrack();
00649           //reco::TrackRef tk = mu.innerTrack();
00650           // should have stuff for electron track?
00651           
00652           if (i < 2)
00653             {
00654               electron[i][0] = 1.;
00655               electron[i][1] = elec.massSqr();
00656               electron[i][2] = elec.energy();
00657               electron[i][3] = elec.px();
00658               electron[i][4] = elec.py();
00659               electron[i][5] = elec.pz();
00660             }
00661 
00662           // Pt,eta cuts
00663           double pt = elec.pt();
00664           double px = elec.px();
00665           double py = elec.py();
00666           double eta = elec.eta();
00667           LogTrace("") << "\t... pt, eta: " << pt << " [GeV], " << eta;;
00668           if (pt>ptCut_) electron_sel[0] = true; 
00669           if (fabs(eta)<etaCut_) electron_sel[1] = true; 
00670           
00671           bool isBarrel = false;
00672           bool isEndcap = false;
00673           if (eta < 1.4442 && eta > -1.4442)
00674             {
00675               isBarrel = true;
00676             }
00677           else if ((eta > 1.56 && eta < 2.4) || (eta < -1.56 && eta > -2.4))
00678             {
00679               isEndcap = true;
00680             }
00681           
00682           //             // d0, chi2, nhits quality cuts
00683           //             double dxy = tk->dxy(beamSpotHandle->position());
00684           //             double normalizedChi2 = gm->normalizedChi2();
00685           //             double trackerHits = tk->numberOfValidHits();
00686           //             LogTrace("") << "\t... dxy, normalizedChi2, trackerHits, isTrackerMuon?: " << dxy << " [cm], " << normalizedChi2 << ", " << trackerHits << ", " << mu.isTrackerMuon();
00687           //             if (fabs(dxy)<dxyCut_) muon_sel[2] = true; 
00688           //             if (normalizedChi2<normalizedChi2Cut_) muon_sel[3] = true; 
00689           //             if (trackerHits>=trackerHitsCut_) muon_sel[4] = true; 
00690           //             if (mu.isTrackerMuon()) muon_sel[5] = true; 
00691           
00692           pt_before_->Fill(pt);
00693           eta_before_->Fill(eta);
00694           //             dxy_before_->Fill(dxy);
00695           //             chi2_before_->Fill(normalizedChi2);
00696           //             nhits_before_->Fill(trackerHits);
00697           //             tkmu_before_->Fill(mu.isTrackerMuon());
00698           
00699           
00700           // Electron ID cuts
00701           double sieie = (double) elec.sigmaIetaIeta();
00702           double detain = (double) elec.deltaEtaSuperClusterTrackAtVtx(); // think this is detain
00703           if (sieie < sieieCutBarrel_ && isBarrel) electron_sel[2] = true; 
00704           if (sieie < sieieCutEndcap_ && isEndcap) electron_sel[2] = true; 
00705           if (detain < detainCutBarrel_ && isBarrel) electron_sel[3] = true; 
00706           if (detain < detainCutEndcap_ && isEndcap) electron_sel[3] = true; 
00707           if (isBarrel)
00708             {
00709               LogTrace("") << "\t... sieie value " << sieie << " (barrel), pass? " << electron_sel[2]; 
00710               LogTrace("") << "\t... detain value " << detain << " (barrel), pass? " << electron_sel[3]; 
00711             }
00712           else if (isEndcap)
00713             {
00714               LogTrace("") << "\t... sieie value " << sieie << " (endcap), pass? " << electron_sel[2]; 
00715               LogTrace("") << "\t... detain value " << detain << " (endcap), pass? " << electron_sel[2]; 
00716             }
00717           
00718           if (isBarrel) 
00719             {
00720               sieiebarrel_before_->Fill(sieie);
00721               detainbarrel_before_->Fill(detain);
00722             }
00723           else if (isEndcap) 
00724             {
00725               sieieendcap_before_->Fill(sieie);
00726               detainendcap_before_->Fill(detain);
00727             }
00728           
00729           
00730           
00731           // Isolation cuts
00732           //double isovar = mu.isolationR03().sumPt;
00733           double ecalisovar = elec.dr03EcalRecHitSumEt();  // picked one set! 
00734           double hcalisovar = elec.dr03HcalTowerSumEt();   // try others if 
00735           double trkisovar = elec.dr04TkSumPt();           // doesn't work 
00736           //if (isCombinedIso_) {
00737           //isovar += mu.isolationR03().emEt;
00738           //isovar += mu.isolationR03().hadEt;
00739           //}
00740           //if (isRelativeIso_) isovar /= pt;
00741           if (ecalisovar<ecalIsoCutBarrel_ && isBarrel) electron_sel[4] = true; 
00742           if (ecalisovar<ecalIsoCutEndcap_ && isEndcap) electron_sel[4] = true; 
00743           if (hcalisovar<hcalIsoCutBarrel_ && isBarrel) electron_sel[5] = true; 
00744           if (hcalisovar<hcalIsoCutEndcap_ && isEndcap) electron_sel[5] = true; 
00745           if (trkisovar<trkIsoCutBarrel_ && isBarrel) electron_sel[6] = true;   
00746           if (trkisovar<trkIsoCutEndcap_ && isEndcap) electron_sel[6] = true;   
00747           if (isBarrel)
00748             {
00749               LogTrace("") << "\t... ecal isolation value " << ecalisovar << " (barrel), pass? " << electron_sel[4]; 
00750               LogTrace("") << "\t... hcal isolation value " << hcalisovar << " (barrel), pass? " << electron_sel[5];
00751               LogTrace("") << "\t... trk isolation value " << trkisovar << " (barrel), pass? " << electron_sel[6];
00752             }
00753           else if (isEndcap)
00754             {
00755               LogTrace("") << "\t... ecal isolation value " << ecalisovar << " (endcap), pass? " << electron_sel[4]; 
00756               LogTrace("") << "\t... hcal isolation value " << hcalisovar << " (endcap), pass? " << electron_sel[5];
00757               LogTrace("") << "\t... trk isolation value " << trkisovar << " (endcap), pass? " << electron_sel[6];
00758             }
00759           
00760           //iso_before_->Fill(isovar);
00761           if (isBarrel) 
00762             {
00763               ecalisobarrel_before_->Fill(ecalisovar);
00764               hcalisobarrel_before_->Fill(hcalisovar);
00765               trkisobarrel_before_->Fill(trkisovar);
00766             }
00767           else if (isEndcap) 
00768             {
00769               ecalisoendcap_before_->Fill(ecalisovar);
00770               hcalisoendcap_before_->Fill(hcalisovar);
00771               trkisoendcap_before_->Fill(trkisovar);
00772             }
00773           
00774           
00775           // HLT 
00776           if (trigger_fired) electron_sel[7] = true; 
00777           
00778           
00779           //             // MET/MT cuts
00780           double w_et = met_et+pt;
00781           double w_px = met_px+px;
00782           double w_py = met_py+py;
00783           
00784           double massT = w_et*w_et - w_px*w_px - w_py*w_py;
00785           massT = (massT>0) ? sqrt(massT) : 0;
00786           
00787           LogTrace("") << "\t... W mass, W_et, W_px, W_py: " << massT << ", " << w_et << ", " << w_px << ", " << w_py << " [GeV]";
00788           if (massT>mtMin_ && massT<mtMax_) electron_sel[8] = true; 
00789           mt_before_->Fill(massT);
00790           if (met_et>metMin_ && met_et<metMax_) electron_sel[9] = true; 
00791           
00792           //             // Acoplanarity cuts
00793           //             Geom::Phi<double> deltaphi(mu.phi()-atan2(met_py,met_px));
00794           //             double acop = deltaphi.value();
00795           //             if (acop<0) acop = - acop;
00796           //             acop = M_PI - acop;
00797           //             LogTrace("") << "\t... acoplanarity: " << acop;
00798           //             if (acop<acopCut_) muon_sel[10] = true; 
00799           //             acop_before_->Fill(acop);
00800           
00801           //             // Remaining flags (from global event information)
00802           //             if (nmuonsForZ1<1 || nmuonsForZ2<2) muon_sel[11] = true; 
00803           if (njets<=nJetMax_) electron_sel[10] = true; 
00804           
00805           // Collect necessary flags "per electron"
00806           int flags_passed = 0;
00807           bool rec_sel_this = true;
00808           bool eid_sel_this = true;
00809           bool iso_sel_this = true;
00810           bool all_sel_this = true;
00811           for (int j=0; j<NFLAGS; ++j) 
00812             {
00813               if (electron_sel[j]) flags_passed += 1;
00814               if (j<2  && !electron_sel[j]) rec_sel_this = false;
00815               if (j<4  && !electron_sel[j]) eid_sel_this = false;
00816               if (j<7  && !electron_sel[j]) iso_sel_this = false;
00817               if (!electron_sel[j]) all_sel_this = false;
00818             }
00819           
00820           if (all_sel_this)
00821             {
00822               if (nGoodElectrons < 2)
00823                 {
00824                   goodElectron[nGoodElectrons][0] = 1.;
00825                   goodElectron[nGoodElectrons][1] = elec.massSqr();
00826                   goodElectron[nGoodElectrons][2] = elec.energy();
00827                   goodElectron[nGoodElectrons][3] = elec.px();
00828                   goodElectron[nGoodElectrons][4] = elec.py();
00829                   goodElectron[nGoodElectrons][5] = elec.pz();
00830                 }
00831               nGoodElectrons++;
00832             }
00833 
00834           //             // "rec" => pt,eta and quality cuts are satisfied
00835           //             if (rec_sel_this) rec_sel = true;
00836           //             // "iso" => "rec" AND "muon is isolated"
00837           //             if (iso_sel_this) iso_sel = true;
00838           //             // "hlt" => "iso" AND "event is triggered"
00839           //             if (hlt_sel_this) hlt_sel = true;
00840           //             // "all" => "met" AND "Z/top rejection cuts"
00841           //             if (all_sel_this) all_sel = true;
00842           
00843           // "rec" => pt,eta cuts are satisfied
00844           if (rec_sel_this) rec_sel = true;
00845           // "eid" => "rec" AND "electron passes ID"
00846           if (eid_sel_this) iso_sel = true;
00847           // "iso" => "eid" AND "electron is isolated"
00848           if (iso_sel_this) iso_sel = true;
00849           // "met" => "iso" AND "MET/MT"
00850           // "all" => "met" AND "event is triggered"
00851           if (all_sel_this) all_sel = true;
00852 
00853           // Do N-1 histograms now (and only once for global event quantities)
00854           if (flags_passed >= (NFLAGS-1)) 
00855             {
00856               if (!electron_sel[0] || flags_passed==NFLAGS) 
00857                 {
00858                   pt_after_->Fill(pt);
00859                 }
00860               if (!electron_sel[1] || flags_passed==NFLAGS) 
00861                 {
00862                   eta_after_->Fill(eta);
00863                 }
00864               if (!electron_sel[2] || flags_passed==NFLAGS) 
00865                 {
00866                   if (isBarrel)
00867                     {
00868                       sieiebarrel_after_->Fill(sieie);
00869                     }
00870                   else if (isEndcap)
00871                     {
00872                       sieieendcap_after_->Fill(sieie);
00873                     }
00874                 }
00875               if (!electron_sel[3] || flags_passed==NFLAGS) 
00876                 {
00877                   if (isBarrel)
00878                     {
00879                       detainbarrel_after_->Fill(detain);
00880                     }
00881                   else if (isEndcap)
00882                     {
00883                       detainendcap_after_->Fill(detain);
00884                     }
00885                 }
00886               if (!electron_sel[4] || flags_passed==NFLAGS) 
00887                 {
00888                   if (isBarrel)
00889                     {
00890                       ecalisobarrel_after_->Fill(ecalisovar);
00891                     }
00892                   else if (isEndcap)
00893                     {
00894                       ecalisoendcap_after_->Fill(ecalisovar);
00895                     }
00896                 }
00897               if (!electron_sel[5] || flags_passed==NFLAGS) 
00898                 {
00899                   if (isBarrel)
00900                     {
00901                       hcalisobarrel_after_->Fill(hcalisovar);
00902                     }
00903                   else if (isEndcap)
00904                     {
00905                       hcalisoendcap_after_->Fill(hcalisovar);
00906                     }
00907                 }
00908               if (!electron_sel[6] || flags_passed==NFLAGS) 
00909                 {
00910                   if (isBarrel)
00911                     {
00912                       trkisobarrel_after_->Fill(trkisovar);
00913                     }
00914                   else if (isEndcap)
00915                     {
00916                       trkisoendcap_after_->Fill(trkisovar);
00917                     }
00918                 }
00919               //                if (!electron_sel[3] || flags_passed==NFLAGS) 
00920               //                  {
00921               //                    detain_after_->Fill(detain);
00922               //                  }
00923               //                if (!electron_sel[4] || flags_passed==NFLAGS) 
00924               //                  {
00925               //                    ecaliso_after_->Fill(trackerHits);
00926               //                  }
00927               //                if (!electron_sel[5] || flags_passed==NFLAGS) 
00928               //                  {
00929               //                    tkelectr_after_->Fill(electr.isTrackerElectron());
00930               //                  }
00931               //                if (!electron_sel[6] || flags_passed==NFLAGS) 
00932               //                  {
00933               //                    iso_after_->Fill(isovar);
00934               //                  }
00935               if (!electron_sel[7] || flags_passed==NFLAGS) 
00936                 {
00937                   if (!hlt_hist_done) 
00938                     {
00939                       trig_after_->Fill(trigger_fired);
00940                     }
00941                 }
00942               hlt_hist_done = true;
00943               if (!electron_sel[8] || flags_passed==NFLAGS) 
00944                 {
00945                   mt_after_->Fill(massT);
00946                 }
00947               if (!electron_sel[9] || flags_passed==NFLAGS) 
00948                 {
00949                   if (!met_hist_done) {
00950                     met_after_->Fill(met_et);
00951                   }
00952                 }
00953               met_hist_done = true;
00954               //                   if (!muon_sel[10] || flags_passed==NFLAGS) 
00955               //                         acop_after_->Fill(acop);
00956               //                   if (!muon_sel[11] || flags_passed==NFLAGS) 
00957               //                         if (!nz1_hist_done) nz1_after_->Fill(nmuonsForZ1);
00958               //                         nz1_hist_done = true;
00959               //                   if (!muon_sel[11] || flags_passed==NFLAGS) 
00960               //                         if (!nz2_hist_done) nz2_after_->Fill(nmuonsForZ2);
00961               //                         nz2_hist_done = true;
00962               if (!electron_sel[10] || flags_passed==NFLAGS) {
00963                 if (!njets_hist_done) 
00964                   {
00965                     njets_after_->Fill(njets);
00966                     if (jet_et>10) //don't want low energy "jets"
00967                       {
00968                         jet_et_after_   ->Fill(jet_et);
00969                         jet_eta_after_  ->Fill(jet_eta);
00970                       }
00971                   }
00972               }
00973               njets_hist_done = true;
00974 
00975             } // end N-1 histos block
00976           
00977         } // end loop through electrons
00978 
00979       // inv mass = sqrt(m_1^2 + m_2^2 + 2*(E_1*E_2 - (px1*px2 + py1*py2 + pz1+pz2) ) )
00980       double invMass=0;
00981 
00982       nelectrons_before_->Fill(electronCollectionSize);
00983       if (electronCollectionSize > 1)
00984         {
00985           invMass = sqrt(electron[0][1] + electron[1][1] + 2*(electron[0][2]*electron[1][2] - (electron[0][3]*electron[1][3] + electron[0][4]*electron[1][4] + electron[0][5]*electron[1][5]) ) );
00986           invmass_before_->Fill(invMass);
00987           invmassPU_before_->Fill(invMass,npvCount);
00988         }
00989 
00990       nelectrons_after_->Fill(nGoodElectrons);
00991       if (nGoodElectrons > 1)
00992         {
00993           invMass = sqrt(goodElectron[0][1] + goodElectron[1][1] + 2*(goodElectron[0][2]*goodElectron[1][2] - (goodElectron[0][3]*goodElectron[1][3] + goodElectron[0][4]*goodElectron[1][4] + goodElectron[0][5]*goodElectron[1][5]) ) );
00994           invmass_after_->Fill(invMass);
00995           invmassPU_afterZ_->Fill(invMass,npvCount);
00996           npvs_afterZ_->Fill(npvCount);
00997         }
00998 
00999       // Collect final flags
01000       if (rec_sel) nrec++;
01001       if (eid_sel) neid++;
01002       if (iso_sel) niso++;
01003       //      if (hlt_sel) nhlt++;
01004       //      if (met_sel) nmet++;
01005 
01006       if (all_sel) {
01007             nsel++;
01008             LogTrace("") << ">>>> Event ACCEPTED";
01009       } else {
01010             LogTrace("") << ">>>> Event REJECTED";
01011       }
01012 
01013 
01014 
01015       return;
01016 
01017 }
01018 
01019 // This always returns only a positive deltaPhi
01020 double EwkElecDQM::calcDeltaPhi(double phi1, double phi2) {
01021 
01022   double deltaPhi = phi1 - phi2;
01023 
01024   if (deltaPhi < 0) deltaPhi = -deltaPhi;
01025 
01026   if (deltaPhi > 3.1415926) {
01027     deltaPhi = 2 * 3.1415926 - deltaPhi;
01028   }
01029 
01030   return deltaPhi;
01031 }
01032