CMS 3D CMS Logo

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