CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/DQM/Physics/src/EwkMuDQM.cc

Go to the documentation of this file.
00001 #include "DQM/Physics/src/EwkMuDQM.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/MuonReco/interface/MuonSelectors.h"
00019 #include "DataFormats/METReco/interface/MET.h"
00020 #include "DataFormats/JetReco/interface/Jet.h"
00021 
00022 #include "DataFormats/GeometryVector/interface/Phi.h"
00023 
00024 #include "FWCore/Common/interface/TriggerNames.h"
00025 #include "FWCore/Framework/interface/Event.h"
00026 #include "DataFormats/Common/interface/TriggerResults.h"
00027 
00028 #include "DataFormats/Common/interface/View.h"
00029  
00030 #include "HLTrigger/HLTcore/interface/HLTConfigProvider.h"
00031  
00032 using namespace edm;
00033 using namespace std;
00034 using namespace reco;
00035 
00036 EwkMuDQM::EwkMuDQM( const ParameterSet & cfg ) :
00037       // Input collections
00038       trigTag_(cfg.getUntrackedParameter<edm::InputTag> ("TrigTag", edm::InputTag("TriggerResults::HLT"))),
00039       muonTag_(cfg.getUntrackedParameter<edm::InputTag> ("MuonTag", edm::InputTag("muons"))),
00040       metTag_(cfg.getUntrackedParameter<edm::InputTag> ("METTag", edm::InputTag("pfmet"))),
00041       jetTag_(cfg.getUntrackedParameter<edm::InputTag> ("JetTag", edm::InputTag("ak5PFJets"))),
00042       vertexTag_(cfg.getUntrackedParameter<edm::InputTag> ("VertexTag", edm::InputTag("offlinePrimaryVertices"))),
00043 
00044       // Main cuts 
00045       ptCut_(cfg.getUntrackedParameter<double>("PtCut", 25.)),
00046       etaCut_(cfg.getUntrackedParameter<double>("EtaCut", 2.1)),
00047       isRelativeIso_(cfg.getUntrackedParameter<bool>("IsRelativeIso", true)),
00048       isCombinedIso_(cfg.getUntrackedParameter<bool>("IsCombinedIso", false)),
00049       isoCut03_(cfg.getUntrackedParameter<double>("IsoCut03", 0.1)),
00050       mtMin_(cfg.getUntrackedParameter<double>("MtMin", 50.)),
00051       mtMax_(cfg.getUntrackedParameter<double>("MtMax", 200.)),
00052       metMin_(cfg.getUntrackedParameter<double>("MetMin", -999999.)),
00053       metMax_(cfg.getUntrackedParameter<double>("MetMax", 999999.)),
00054       acopCut_(cfg.getUntrackedParameter<double>("AcopCut", 999.)),
00055 
00056       // Muon quality cuts
00057       dxyCut_(cfg.getUntrackedParameter<double>("DxyCut", 0.2)),   // dxy < 0.2 cm 
00058       normalizedChi2Cut_(cfg.getUntrackedParameter<double>("NormalizedChi2Cut", 10.)), // chi2/ndof (of global fit) <10.0
00059       trackerHitsCut_(cfg.getUntrackedParameter<int>("TrackerHitsCut", 11)),  // Tracker Hits >10 
00060       pixelHitsCut_(cfg.getUntrackedParameter<int>("PixelHitsCut", 1)), // Pixel Hits >0
00061       muonHitsCut_(cfg.getUntrackedParameter<int>("MuonHitsCut", 1)),  // Valid Muon Hits >0 
00062       isAlsoTrackerMuon_(cfg.getUntrackedParameter<bool>("IsAlsoTrackerMuon", true)),
00063       nMatchesCut_(cfg.getUntrackedParameter<int>("NMatchesCut", 2)), // At least 2 Chambers with matches 
00064 
00065       // Z rejection
00066       ptThrForZ1_(cfg.getUntrackedParameter<double>("PtThrForZ1", 20.)),
00067       ptThrForZ2_(cfg.getUntrackedParameter<double>("PtThrForZ2", 10.)),
00068 
00069       // Top rejection
00070       eJetMin_(cfg.getUntrackedParameter<double>("EJetMin", 999999.)),
00071       nJetMax_(cfg.getUntrackedParameter<int>("NJetMax", 999999))
00072 {
00073   isValidHltConfig_ = false;
00074 }
00075 
00076 void EwkMuDQM::beginRun(const Run& r, const EventSetup& iSet) {
00077       nall = 0;
00078       nsel = 0;
00079 
00080       nrec = 0; 
00081       niso = 0; 
00082       nhlt = 0; 
00083       nmet = 0;
00084 
00085 
00086      // passed as parameter to HLTConfigProvider::init(), not yet used
00087      bool isConfigChanged = false;
00088      // isValidHltConfig_ used to short-circuit analyze() in case of problems
00089      isValidHltConfig_ = hltConfigProvider_.init( r, iSet, "HLT", isConfigChanged );
00090 
00091 }
00092 
00093 
00094 void EwkMuDQM::beginJob() {
00095       theDbe = Service<DQMStore>().operator->();
00096       theDbe->setCurrentFolder("Physics/EwkMuDQM");
00097       init_histograms();
00098 }
00099 
00100 void EwkMuDQM::init_histograms() {
00101 
00102       char chtitle[256] = "";
00103       for (int i=0; i<2; ++i) {
00104             snprintf(chtitle, 255, "Muon transverse momentum (global muon) [GeV]");
00105             pt_before_ = theDbe->book1D("PT_BEFORECUTS",chtitle,100,0.,100.);
00106             pt_after_ = theDbe->book1D("PT_LASTCUT",chtitle,100,0.,100.);
00107 
00108             snprintf(chtitle, 255, "Muon pseudo-rapidity");
00109             eta_before_ = theDbe->book1D("ETA_BEFORECUTS",chtitle,50,-2.5,2.5);
00110             eta_after_ = theDbe->book1D("ETA_LASTCUT",chtitle,50,-2.5,2.5);
00111 
00112             snprintf(chtitle, 255, "Muon transverse distance to beam spot [cm]");
00113             dxy_before_ = theDbe->book1D("DXY_BEFORECUTS",chtitle,100,-0.5,0.5);
00114             dxy_after_ = theDbe->book1D("DXY_LASTCUT",chtitle,100,-0.5,0.5);
00115 
00116             snprintf(chtitle, 255, "Quality-muon flag");
00117             goodewkmuon_before_ = theDbe->book1D("GOODEWKMUON_BEFORECUTS",chtitle,2,-0.5,1.5);
00118             goodewkmuon_after_ = theDbe->book1D("GOODEWKMUON_LASTCUT",chtitle,2,-0.5,1.5);
00119 
00120             if (isRelativeIso_) {
00121                   if (isCombinedIso_) {
00122                         snprintf(chtitle, 255, "Relative (combined) isolation variable");
00123                   } else {
00124                         snprintf(chtitle, 255, "Relative (tracker) isolation variable");
00125                   }
00126                   iso_before_ = theDbe->book1D("ISO_BEFORECUTS",chtitle,100, 0., 1.);
00127                   iso_after_ = theDbe->book1D("ISO_LASTCUT",chtitle,100, 0., 1.);
00128             } else {
00129                   if (isCombinedIso_) {
00130                         snprintf(chtitle, 255, "Absolute (combined) isolation variable [GeV]");
00131                   } else {
00132                         snprintf(chtitle, 255, "Absolute (tracker) isolation variable [GeV]");
00133                   }
00134                   iso_before_ = theDbe->book1D("ISO_BEFORECUTS",chtitle,100, 0., 20.);
00135                   iso_after_ = theDbe->book1D("ISO_LASTCUT",chtitle,100, 0., 20.);
00136             }
00137 
00138             snprintf(chtitle, 255, "HLT_Mu* Trigger response");
00139             trig_before_ = theDbe->book1D("TRIG_BEFORECUTS",chtitle,2,-0.5,1.5);
00140             trig_after_ = theDbe->book1D("TRIG_LASTCUT",chtitle,2,-0.5,1.5);
00141 
00142             snprintf(chtitle, 255, "Transverse mass (%s) [GeV]", metTag_.label().data());
00143             mt_before_ = theDbe->book1D("MT_BEFORECUTS",chtitle,150,0.,300.);
00144             mt_after_ = theDbe->book1D("MT_LASTCUT",chtitle,150,0.,300.);
00145 
00146             snprintf(chtitle, 255, "Missing transverse energy (%s) [GeV]", metTag_.label().data());
00147             met_before_ = theDbe->book1D("MET_BEFORECUTS",chtitle,100,0.,200.);
00148             met_after_ = theDbe->book1D("MET_LASTCUT",chtitle,100,0.,200.);
00149 
00150             snprintf(chtitle, 255, "MU-MET (%s) acoplanarity", metTag_.label().data());
00151             acop_before_ = theDbe->book1D("ACOP_BEFORECUTS",chtitle,50,0.,M_PI);
00152             acop_after_ = theDbe->book1D("ACOP_LASTCUT",chtitle,50,0.,M_PI);
00153 
00154             snprintf(chtitle, 255, "Z rejection: number of muons above %.2f GeV", ptThrForZ1_);
00155             nz1_before_ = theDbe->book1D("NZ1_BEFORECUTS",chtitle,10,-0.5,9.5);
00156             nz1_after_ = theDbe->book1D("NZ1_LASTCUT",chtitle,10,-0.5,9.5);
00157 
00158             snprintf(chtitle, 255, "Z rejection: number of muons above %.2f GeV", ptThrForZ2_);
00159             nz2_before_ = theDbe->book1D("NZ2_BEFORECUTS",chtitle,10,-0.5,9.5);
00160             nz2_after_ = theDbe->book1D("NZ2_LASTCUT",chtitle,10,-0.5,9.5);
00161 
00162             snprintf(chtitle, 255, "Number of jets (%s) above %.2f GeV", jetTag_.label().data(), eJetMin_);
00163             njets_before_ = theDbe->book1D("NJETS_BEFORECUTS",chtitle,10,-0.5,9.5);
00164             njets_after_ = theDbe->book1D("NJETS_LASTCUT",chtitle,10,-0.5,9.5);
00165 
00166             snprintf(chtitle, 255, "DiMuonMass (2 globals)");
00167             dimuonmass_before_= theDbe->book1D("DIMUONMASS_BEFORECUTS",chtitle,100,0,200);
00168             dimuonmass_after_= theDbe->book1D("DIMUONMASS_AFTERZCUTS",chtitle,100,0,200);
00169 
00170             snprintf(chtitle, 255, "Global pt for Muons in Z");
00171             ptmuonZ_after_= theDbe->book1D("PT_AFTERZCUT",chtitle,100,0.,100.);
00172 
00173             snprintf(chtitle, 255, "Number of Valid Primary Vertices");
00174             npvs_before_ = theDbe->book1D("NPVs_BEFORECUTS",chtitle,10,-0.5,9.5);
00175             npvs_after_ = theDbe->book1D("NPVs_LASTCUT",chtitle,10,-0.5,9.5);
00176 
00177             snprintf(chtitle, 255, "Muon Charge");
00178             muoncharge_before_ = theDbe->book1D("MUONCHARGE_BEFORECUTS",chtitle,3,-1.5,1.5);
00179             muoncharge_after_ = theDbe->book1D("MUONCHARGE_LASTCUT",chtitle,3,-1.5,1.5);
00180 
00181       }
00182 }
00183 
00184 
00185 void EwkMuDQM::endJob() {
00186 }
00187 
00188 void EwkMuDQM::endRun(const Run& r, const EventSetup& iSet) {
00189 
00190 }
00191 
00192 void EwkMuDQM::analyze (const Event & ev, const EventSetup & iSet) {
00193       
00194       // Reset global event selection flags
00195       bool rec_sel = false;
00196       bool iso_sel = false;
00197       bool hlt_sel = false;
00198       bool met_sel = false;
00199       bool all_sel = false;
00200 
00201       // Muon collection
00202       Handle<View<Muon> > muonCollection;
00203       if (!ev.getByLabel(muonTag_, muonCollection)) {
00204         //LogWarning("") << ">>> Muon collection does not exist !!!";
00205         return;
00206       }
00207       unsigned int muonCollectionSize = muonCollection->size();
00208 
00209       // Beam spot
00210       Handle<reco::BeamSpot> beamSpotHandle;
00211       if (!ev.getByLabel(InputTag("offlineBeamSpot"), beamSpotHandle)) {
00212         //LogWarning("") << ">>> No beam spot found !!!";
00213         return;
00214       }
00215 
00216 
00217       // Loop to reject/control Z->mumu is done separately
00218       unsigned int nmuonsForZ1 = 0;
00219       unsigned int nmuonsForZ2 = 0;
00220       bool cosmic = false;
00221       for (unsigned int i=0; i<muonCollectionSize; i++) {
00222             const Muon& mu = muonCollection->at(i);
00223             if (!mu.isGlobalMuon()) continue;
00224             double pt = mu.pt();
00225             double dxy = mu.innerTrack()->dxy(beamSpotHandle->position());
00226 
00227             if (fabs(dxy)>1) { cosmic=true; break;} 
00228 
00229             if (pt>ptThrForZ1_) nmuonsForZ1++;
00230             if (pt>ptThrForZ2_) nmuonsForZ2++;
00231 
00232             for (unsigned int j=i+1; j<muonCollectionSize; j++) {
00233                  const Muon& mu2 = muonCollection->at(j);
00234                  if (mu2.isGlobalMuon() && (mu.charge()*mu2.charge()==-1) ){
00235                          const math::XYZTLorentzVector ZRecoGlb (mu.px()+mu2.px(), mu.py()+mu2.py() , mu.pz()+mu2.pz(), mu.p()+mu2.p());
00236                          dimuonmass_before_->Fill(ZRecoGlb.mass());
00237                  }
00238             }
00239       }
00240      if(cosmic) return;
00241 
00242       LogTrace("") << "> Z rejection: muons above " << ptThrForZ1_ << " [GeV]: " << nmuonsForZ1;
00243       LogTrace("") << "> Z rejection: muons above " << ptThrForZ2_ << " [GeV]: " << nmuonsForZ2;
00244       nz1_before_->Fill(nmuonsForZ1);
00245       nz2_before_->Fill(nmuonsForZ2);
00246   
00247       // MET
00248       Handle<View<MET> > metCollection;
00249       if (!ev.getByLabel(metTag_, metCollection)) {
00250         //LogWarning("") << ">>> MET collection does not exist !!!";
00251         return;
00252       }
00253       const MET& met = metCollection->at(0);
00254       double met_et = met.pt();
00255       LogTrace("") << ">>> MET, MET_px, MET_py: " << met_et << ", " << met.px() << ", " << met.py() << " [GeV]";
00256       met_before_->Fill(met_et);
00257 
00258       // Vertices in the event
00259       Handle<View<reco::Vertex> > vertexCollection;
00260            if (!ev.getByLabel(vertexTag_, vertexCollection)) {
00261                  LogError("") << ">>> Vertex collection does not exist !!!";
00262                  return;
00263             }
00264       unsigned int vertexCollectionSize = vertexCollection->size();
00265 
00266       
00267 
00268       int nvvertex = 0;
00269       for (unsigned int i=0; i<vertexCollectionSize; i++) {
00270             const Vertex& vertex = vertexCollection->at(i);
00271             if (vertex.isValid()) nvvertex++;
00272       }
00273 
00274       npvs_before_->Fill(nvvertex);
00275 
00276       bool trigger_fired = false;
00277       Handle<TriggerResults> triggerResults;
00278       if (!ev.getByLabel(trigTag_, triggerResults)) {
00279         //LogWarning("") << ">>> TRIGGER collection does not exist !!!";
00280         return;
00281       }
00282       const edm::TriggerNames & trigNames = ev.triggerNames(*triggerResults);
00283 
00284       for (unsigned int i=0; i<triggerResults->size(); i++)
00285       {
00286               const std::string trigName = trigNames.triggerName(i);
00287               size_t found = trigName.find("HLT_Mu");
00288               if ( found == std::string::npos) continue;
00289 
00290               bool prescaled=false;    
00291               for (unsigned int ps= 0; ps<  hltConfigProvider_.prescaleSize(); ps++){
00292                   const unsigned int prescaleValue = hltConfigProvider_.prescaleValue(ps, trigName) ;
00293                   if (prescaleValue != 1) prescaled =true;
00294               }
00295               if(prescaled) continue;    
00296 
00297               if( triggerResults->accept(i) )   trigger_fired=true;
00298       }     
00299       trig_before_->Fill(trigger_fired);
00300 
00301 
00302 
00303 
00304 
00305 
00306       // Jet collection
00307       Handle<View<Jet> > jetCollection;
00308       if (!ev.getByLabel(jetTag_, jetCollection)) {
00309         //LogError("") << ">>> JET collection does not exist !!!";
00310         return;
00311       }
00312       unsigned int jetCollectionSize = jetCollection->size();
00313       int njets = 0;
00314       for (unsigned int i=0; i<jetCollectionSize; i++) {
00315             const Jet& jet = jetCollection->at(i);
00316                   double minDistance=99999; // This is in order to use PFJets
00317                   for (unsigned int i=0; i<muonCollectionSize; i++) {
00318                         const Muon& mu = muonCollection->at(i);
00319                         double distance = sqrt( (mu.eta()-jet.eta())*(mu.eta()-jet.eta()) +(mu.phi()-jet.phi())*(mu.phi()-jet.phi()) );      
00320                         if (minDistance>distance) minDistance=distance;
00321                   }
00322                   if (minDistance<0.3) continue; // 0.3 is the isolation cone around the muon
00323             if (jet.et()>eJetMin_) njets++;
00324       }
00325       LogTrace("") << ">>> Total number of jets: " << jetCollectionSize;
00326       LogTrace("") << ">>> Number of jets above " << eJetMin_ << " [GeV]: " << njets;
00327       njets_before_->Fill(njets);
00328 
00329       // Start counting
00330       nall++;
00331 
00332       // Histograms per event shouldbe done only once, so keep track of them
00333       bool hlt_hist_done = false;
00334       bool met_hist_done = false;
00335       bool nz1_hist_done = false;
00336       bool nz2_hist_done = false;
00337       bool njets_hist_done = false;
00338       bool pv_hist_done = false;
00339       bool charge_hist_done = false;
00340 
00341       // Central W->mu nu selection criteria
00342       const int NFLAGS = 11;
00343       bool muon_sel[NFLAGS];
00344       bool muon4Z=false;
00345 
00346       for (unsigned int i=0; i<muonCollectionSize; i++) {
00347             for (int j=0; j<NFLAGS; ++j) {
00348                   muon_sel[j] = false;
00349             }
00350 
00351             const Muon& mu = muonCollection->at(i);
00352             if (!mu.isGlobalMuon()) continue;
00353             if (mu.globalTrack().isNull()) continue;
00354             if (mu.innerTrack().isNull()) continue;
00355 
00356             LogTrace("") << "> Wsel: processing muon number " << i << "...";
00357             reco::TrackRef gm = mu.globalTrack();
00358             reco::TrackRef tk = mu.innerTrack();
00359 
00360             // Pt,eta cuts
00361             double pt = mu.pt();
00362             double eta = mu.eta();
00363             LogTrace("") << "\t... pt, eta: " << pt << " [GeV], " << eta;;
00364             if (pt>ptCut_) muon_sel[0] = true; 
00365             if (fabs(eta)<etaCut_) muon_sel[1] = true; 
00366 
00367             double charge=mu.charge();
00368 
00369             // d0, chi2, nhits quality cuts
00370             double dxy = gm->dxy(beamSpotHandle->position());
00371             double normalizedChi2 = gm->normalizedChi2();
00372             double trackerHits = tk->hitPattern().numberOfValidTrackerHits();
00373             int pixelHits = tk->hitPattern().numberOfValidPixelHits();
00374             int muonHits = gm->hitPattern().numberOfValidMuonHits();
00375             int nMatches = mu.numberOfMatches();
00376 
00377             LogTrace("") << "\t... dxy, normalizedChi2, trackerHits, isTrackerMuon?: " << dxy << " [cm], " << normalizedChi2 << ", " << trackerHits << ", " << mu.isTrackerMuon();
00378             if (fabs(dxy)<dxyCut_) muon_sel[2] = true; 
00379 
00380             bool quality=true;
00381             
00382             if (normalizedChi2>normalizedChi2Cut_) quality =false; 
00383             if (trackerHits<trackerHitsCut_) quality =false;
00384             if (pixelHits<pixelHitsCut_) quality =false;
00385             if (muonHits<muonHitsCut_) quality=false;;
00386             if (!mu.isTrackerMuon()) quality=false;
00387             if (nMatches<nMatchesCut_) quality=false;
00388             muon_sel[3]=quality;
00389 
00390 
00391             pt_before_->Fill(pt);
00392             eta_before_->Fill(eta);
00393             dxy_before_->Fill(dxy);
00394             muoncharge_before_->Fill(charge);
00395             goodewkmuon_before_->Fill(quality);
00396 
00397             // Isolation cuts
00398             double isovar = mu.isolationR03().sumPt;
00399             if (isCombinedIso_) {
00400                   isovar += mu.isolationR03().emEt;
00401                   isovar += mu.isolationR03().hadEt;
00402             }
00403             if (isRelativeIso_) isovar /= pt;
00404             if (isovar<isoCut03_) muon_sel[4] = true; 
00405 
00406             LogTrace("") << "\t... isolation value" << isovar <<", isolated? " << muon_sel[6];
00407             iso_before_->Fill(isovar);
00408 
00409 
00410             // HLT (not mtched to muon for the time being)
00411             if (trigger_fired) muon_sel[5] = true; 
00412 
00413             // For Z:
00414             if (pt>ptThrForZ1_ && fabs(eta)<etaCut_ && fabs(dxy)<dxyCut_ && quality && trigger_fired && isovar<isoCut03_) { muon4Z = true;}
00415 
00416 
00417             // MET/MT cuts
00418             double w_et = met_et+mu.pt();
00419             double w_px = met.px()+mu.px();
00420             double w_py = met.py()+mu.py();
00421             
00422             double massT = w_et*w_et - w_px*w_px - w_py*w_py;
00423             massT = (massT>0) ? sqrt(massT) : 0;
00424 
00425             LogTrace("") << "\t... W mass, W_et, W_px, W_py: " << massT << ", " << w_et << ", " << w_px << ", " << w_py << " [GeV]";
00426             if (massT>mtMin_ && massT<mtMax_) muon_sel[6] = true; 
00427             mt_before_->Fill(massT);
00428             if (met_et>metMin_ && met_et<metMax_) muon_sel[7] = true; 
00429 
00430             // Acoplanarity cuts
00431             Geom::Phi<double> deltaphi(mu.phi()-atan2(met.py(),met.px()));
00432             double acop = deltaphi.value();
00433             if (acop<0) acop = - acop;
00434             acop = M_PI - acop;
00435             LogTrace("") << "\t... acoplanarity: " << acop;
00436             if (acop<acopCut_) muon_sel[8] = true; 
00437             acop_before_->Fill(acop);
00438 
00439             // Remaining flags (from global event information)
00440             if (nmuonsForZ1<1 || nmuonsForZ2<2) muon_sel[9] = true; 
00441             if (njets<=nJetMax_) muon_sel[10] = true; 
00442 
00443             // Collect necessary flags "per muon"
00444             int flags_passed = 0;
00445             bool rec_sel_this = true;
00446             bool iso_sel_this = true;
00447             bool hlt_sel_this = true;
00448             bool met_sel_this = true;
00449             bool all_sel_this = true;
00450             for (int j=0; j<NFLAGS; ++j) {
00451                   if (muon_sel[j]) flags_passed += 1;
00452                   if (j<4 && !muon_sel[j]) rec_sel_this = false;
00453                   if (j<5 && !muon_sel[j]) iso_sel_this = false;
00454                   if (j<6 && !muon_sel[j]) hlt_sel_this = false;
00455                   if (j<8 && !muon_sel[j]) met_sel_this = false;
00456                   if (!muon_sel[j]) all_sel_this = false;
00457             }
00458 
00459             // "rec" => pt,eta and quality cuts are satisfied
00460             if (rec_sel_this) rec_sel = true;
00461             // "iso" => "rec" AND "muon is isolated"
00462             if (iso_sel_this) iso_sel = true;
00463             // "hlt" => "iso" AND "event is triggered"
00464             if (hlt_sel_this) hlt_sel = true;
00465             // "met" => "hlt" AND "MET/MT and acoplanarity cuts"
00466             if (met_sel_this) met_sel = true;
00467             // "all" => "met" AND "Z/top rejection cuts"
00468             if (all_sel_this) all_sel = true;
00469 
00470             // Do N-1 histograms now (and only once for global event quantities)
00471             if (flags_passed >= (NFLAGS-1)) {
00472                   if (!muon_sel[0] || flags_passed==NFLAGS) 
00473                         pt_after_->Fill(pt);
00474                   if (!muon_sel[1] || flags_passed==NFLAGS) 
00475                         eta_after_->Fill(eta);
00476                   if (!muon_sel[2] || flags_passed==NFLAGS) 
00477                         dxy_after_->Fill(dxy);
00478                   if (!muon_sel[3] || flags_passed==NFLAGS)
00479                         goodewkmuon_after_->Fill(quality);
00480                   if (!muon_sel[4] || flags_passed==NFLAGS) 
00481                         iso_after_->Fill(isovar);
00482                   if (!muon_sel[5] || flags_passed==NFLAGS) 
00483                         if (!hlt_hist_done) trig_after_->Fill(trigger_fired);
00484                         hlt_hist_done = true;
00485                   if (!muon_sel[6] || flags_passed==NFLAGS) 
00486                         mt_after_->Fill(massT);
00487                   if (!muon_sel[7] || flags_passed==NFLAGS) 
00488                         if (!met_hist_done) met_after_->Fill(met_et);
00489                         met_hist_done = true;
00490                   if (!muon_sel[8] || flags_passed==NFLAGS) 
00491                         acop_after_->Fill(acop);
00492                   if (!muon_sel[9] || flags_passed==NFLAGS) 
00493                         if (!nz1_hist_done) nz1_after_->Fill(nmuonsForZ1);
00494                         nz1_hist_done = true;
00495                   if (!muon_sel[9] || flags_passed==NFLAGS) 
00496                         if (!nz2_hist_done) nz2_after_->Fill(nmuonsForZ2);
00497                         nz2_hist_done = true;
00498                   if (!muon_sel[10] || flags_passed==NFLAGS) { 
00499                         if (!njets_hist_done) njets_after_->Fill(njets);
00500                         njets_hist_done = true;
00501                   if( flags_passed==NFLAGS ) {
00502                         if (!pv_hist_done) npvs_after_->Fill(nvvertex);
00503                         if (!charge_hist_done) muoncharge_after_->Fill(charge);
00504                      }
00505                         pv_hist_done=true; charge_hist_done=true;   
00506                   }  
00507             }
00508 
00509 
00510             // The cases in which the event is rejected as a Z are considered independently:
00511             if ( muon4Z &&  !muon_sel[9]){
00512                    // Plots for 2 muons       
00513                    bool usedMuon=false;
00514                    for (unsigned int j=i+1; j<muonCollectionSize; j++) {
00515                          const Muon& mu2 = muonCollection->at(j);
00516                               if (!mu2.isGlobalMuon()) continue;
00517                               if (mu2.charge() * charge != -1 ) continue;
00518                                     double pt2 = mu2.pt(); if (pt2<=ptThrForZ1_) continue;
00519                                     double eta2=mu2.eta(); if (fabs(eta2)>etaCut_) continue;
00520                                     double isovar2 = mu2.isolationR03().sumPt; 
00521                                     if (isCombinedIso_) {
00522                                           isovar2 += mu2.isolationR03().emEt;
00523                                           isovar2 += mu2.isolationR03().hadEt;
00524                                     }
00525                                     if (isRelativeIso_) isovar2 /= pt2;
00526                                     if (isovar2>=isoCut03_) continue;
00527                                const math::XYZTLorentzVector ZRecoGlb (mu.px()+mu2.px(), mu.py()+mu2.py() , mu.pz()+mu2.pz(), mu.p()+mu2.p());
00528                                dimuonmass_after_->Fill(ZRecoGlb.mass());
00529                                if(!usedMuon){ptmuonZ_after_->Fill(mu.pt()); usedMuon=true;}
00530                   }
00531             }
00532 
00533 
00534 
00535       }
00536 
00537 
00538 
00539 
00540       
00541 
00542       return;
00543 
00544 }
00545