CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/src/DQM/Physics/src/EwkMuLumiMonitorDQM.cc

Go to the documentation of this file.
00001 #include "DQM/Physics/src/EwkMuLumiMonitorDQM.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 
00014 
00015 #include "DataFormats/Common/interface/View.h"
00016 #include "DataFormats/Common/interface/Handle.h"
00017 
00018 #include "DataFormats/RecoCandidate/interface/IsoDepositVetos.h"
00019 #include "DataFormats/RecoCandidate/interface/IsoDepositDirection.h"
00020 
00021 #include "FWCore/Common/interface/TriggerNames.h"
00022 #include "FWCore/Framework/interface/Event.h"
00023 #include "DataFormats/Common/interface/TriggerResults.h"
00024 #include "DataFormats/HLTReco/interface/TriggerObject.h"
00025 #include "DataFormats/HLTReco/interface/TriggerEvent.h"
00026 #include "DataFormats/Math/interface/deltaR.h"
00027 
00028 #include "DataFormats/METReco/interface/MET.h"
00029 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
00030 
00031 #include "DataFormats/Math/interface/LorentzVector.h"
00032 
00033   
00034 using namespace edm;
00035 using namespace std;
00036 using namespace reco;
00037 using namespace isodeposit;
00038 
00039 EwkMuLumiMonitorDQM::EwkMuLumiMonitorDQM( const ParameterSet & cfg ) :
00040   // Input collections
00041    trigTag_(cfg.getUntrackedParameter<edm::InputTag> ("TrigTag", edm::InputTag("TriggerResults::HLT"))),
00042   trigEv_(cfg.getUntrackedParameter<edm::InputTag> ("triggerEvent")),
00043   muonTag_(cfg.getUntrackedParameter<edm::InputTag>("muons")),
00044   trackTag_(cfg.getUntrackedParameter<edm::InputTag>("tracks")),
00045   caloTowerTag_(cfg.getUntrackedParameter<edm::InputTag>("calotower")),
00046   metTag_(cfg.getUntrackedParameter<edm::InputTag> ("metTag")),
00047   metIncludesMuons_(cfg.getUntrackedParameter<bool> ("METIncludesMuons")),
00048  // Main cuts 
00049   // massMin_(cfg.getUntrackedParameter<double>("MtMin", 20.)),
00050   //   massMax_(cfg.getUntrackedParameter<double>("MtMax", 2000.)) 
00051    //  hltPath_(cfg.getUntrackedParameter<std::string> ("hltPath")) ,
00052    //  L3FilterName_(cfg.getUntrackedParameter<std::string> ("L3FilterName")),           
00053   ptMuCut_(cfg.getUntrackedParameter<double>("ptMuCut")),
00054   etaMuCut_(cfg.getUntrackedParameter<double>("etaMuCut")),
00055   isRelativeIso_(cfg.getUntrackedParameter<bool>("IsRelativeIso")),
00056   isCombinedIso_(cfg.getUntrackedParameter<bool>("IsCombinedIso")),
00057   isoCut03_(cfg.getUntrackedParameter<double>("IsoCut03")),
00058   //  deltaRTrk_(cfg.getUntrackedParameter<double>("deltaRTrk")),
00059   ptThreshold_(cfg.getUntrackedParameter<double>("ptThreshold")),
00060   //deltaRVetoTrk_(cfg.getUntrackedParameter<double>("deltaRVetoTrk")), 
00061   maxDPtRel_(cfg.getUntrackedParameter<double>("maxDPtRel")),
00062   maxDeltaR_(cfg.getUntrackedParameter<double>("maxDeltaR")),
00063   mtMin_(cfg.getUntrackedParameter<double>("mtMin")),
00064   mtMax_(cfg.getUntrackedParameter<double>("mtMax")),
00065   acopCut_(cfg.getUntrackedParameter<double>("acopCut")), 
00066   dxyCut_(cfg.getUntrackedParameter<double>("DxyCut")) {
00067  // just to initialize
00068   isValidHltConfig_ = false;
00069 
00070   // dqm service & histograms
00071   theDbe = Service<DQMStore>().operator->();
00072   theDbe->setCurrentFolder("Physics/EwkMuLumiMonitorDQM");
00073   init_histograms();
00074 
00075 }
00076 
00077 
00078 
00079 void EwkMuLumiMonitorDQM::beginRun(const Run& r, const EventSetup&iSetup) {
00080       nall =  0;
00081       nEvWithHighPtMu=0; 
00082       nInKinRange=  0;
00083       nsel = 0;
00084       niso = 0;
00085       nhlt =0;
00086       n1hlt =0;
00087       n2hlt =0;
00088       nNotIso =0;
00089       nGlbSta =0;
00090       nGlbTrk =0;
00091       nTMass =0;
00092       nW=0;
00093 
00094   // passed as parameter to HLTConfigProvider::init(), not yet used
00095   bool isConfigChanged = false;
00096 
00097   // isValidHltConfig_ used to short-circuit analyze() in case of problems
00098   isValidHltConfig_ = hltConfigProvider_.init( r, iSetup, trigTag_.process(), isConfigChanged );
00099   //std::cout << "hlt config trigger is valid??" << isValidHltConfig_ << std::endl; 
00100 
00101   }
00102 
00103 
00104 void EwkMuLumiMonitorDQM::beginJob() {
00105 
00106 }
00107 
00108 void EwkMuLumiMonitorDQM::init_histograms() {
00109 
00110   mass2HLT_ = theDbe->book1D("Z_2HLT_MASS","Z mass [GeV/c^{2}]",200,0.,200.);
00111   mass1HLT_ = theDbe->book1D("Z_1HLT_MASS","Z mass [GeV/c^{2}]",200,0.,200.);
00112   massNotIso_ = theDbe->book1D("Z_NOTISO_MASS","Z mass [GeV/c^{2}]",200,0.,200.);
00113   massGlbSta_ = theDbe->book1D("Z_GLBSTA_MASS","Z mass [GeV/c^{2}]",200,0.,200.);
00114   massGlbTrk_ = theDbe->book1D("Z_GLBTRK_MASS","Z mass [GeV/c^{2}]",200,0.,200.);
00115   massIsBothGlbTrkThanW_ = theDbe->book1D("Z_ISBOTHGLBTRKTHANW_MASS","Z mass [GeV/c^{2}]",200,0.,200.);
00116   
00117   highMass2HLT_ = theDbe->book1D("Z_2HLT_HIGHMASS","Z high mass [GeV/c^{2}]",2000,0.,2000.);
00118   highMass1HLT_ = theDbe->book1D("Z_1HLT_HIGHMASS","Z high mass [GeV/c^{2}]",2000,0.,2000.);              
00119   highMassNotIso_ = theDbe->book1D("Z_NOTISO_HIGHMASS","Z high mass [GeV/c^{2}]",2000,0.,2000.);              
00120   highMassGlbSta_ = theDbe->book1D("Z_GLBSTA_HIGHMASS","Z high mass [GeV/c^{2}]",2000,0.,2000.);              
00121   highMassGlbTrk_ = theDbe->book1D("Z_GLBTRK_HIGHMASS","Z high mass [GeV/c^{2}]",2000,0.,2000.);              
00122   highMassIsBothGlbTrkThanW_ = theDbe->book1D("Z_ISBOTHGLBTRKTHANW_HIGHMASS","Z high mass [GeV/c^{2}]",2000,0.,2000.);  
00123   
00124   /*
00125     highest_mupt2HLT_ = theDbe->book1D("HIGHEST_MU_PT_2HLT","Highest muon p_{t}[GeV/c]",200,0.,200.);
00126     highest_mupt1HLT_ = theDbe->book1D("HIGHEST_MU_PT_1HLT","Highest muon p_{t}[GeV/c]",200,0.,200.);
00127     highest_muptNotIso_ = theDbe->book1D("HIGHEST_MU_PT_NOTISO","Highest muon p_{t}[GeV/c]",200,0.,200.);
00128     highest_muptGlbSta_ = theDbe->book1D("HIGHEST_MU_PT_GLBSTA","Highest muon p_{t}[GeV/c]",200,0.,200.);
00129     highest_muptGlbTrk_ = theDbe->book1D("HIGHEST_MU_PT_GLBTRK","Highest muon p_{t}[GeV/c]",200,0.,200.);
00130     
00131     lowest_mupt2HLT_ = theDbe->book1D("LOWEST_MU_PT_2HLT","Lowest muon p_{t} [GeV/c]",200,0.,200.);
00132     lowest_mupt1HLT_ = theDbe->book1D("LOWEST_MU_PT_1HLT","Lowest muon p_{t} [GeV/c]",200,0.,200.);
00133     lowest_muptNotIso_ = theDbe->book1D("LOWEST_MU_PT_NOTISO","Lowest muon p_{t} [GeV/c]",200,0.,200.);
00134     lowest_muptGlbSta_ = theDbe->book1D("LOWEST_MU_PT_GLBSTA","Lowest muon p_{t} [GeV/c]",200,0.,200.);
00135     lowest_muptGlbTrk_ = theDbe->book1D("LOWEST_MU_PT_GLBTRK","Lowest muon p_{t} [GeV/c]",200,0.,200.);
00136   */
00137   
00138   TMass_ = theDbe->book1D("TMASS","Transverse mass [GeV]",300,0.,300.);
00139     
00140 }
00141 
00142 
00143 
00144 double EwkMuLumiMonitorDQM::muIso( const reco::Muon & mu )  {        
00145     double isovar = mu.isolationR03().sumPt;
00146     if (isCombinedIso_) {
00147       isovar += mu.isolationR03().emEt;
00148       isovar += mu.isolationR03().hadEt;
00149     }
00150     if (isRelativeIso_) isovar /= mu.pt();
00151     return isovar;
00152 }
00153 
00154 double EwkMuLumiMonitorDQM::tkIso( const reco::Track tk,  Handle< TrackCollection > tracks , Handle<CaloTowerCollection> calotower  )  {        
00155       double ptSum = 0;
00156       for (size_t i=0; i< tracks->size(); ++i){ 
00157         const reco::Track & elem = tracks->at(i);
00158         double elemPt = elem.pt();
00159         // same parameter used for muIsolation: dR [0.01, IsoCut03_], |dZ|<0.2, |d_r(xy)|<0.1
00160        double elemVx = elem.vx();
00161        double elemVy = elem.vy();
00162        double elemD0 = sqrt( elemVx * elemVx + elemVy * elemVy );
00163        if ( elemD0 > 0.2 ) continue;
00164        double dz = fabs( elem.vz() - tk.vz()); 
00165        if ( dz > 0.1) continue;
00166         // evaluate only for tracks with pt>ptTreshold
00167         if ( elemPt <  ptThreshold_ ) continue;
00168         double dR = deltaR( elem.eta(), elem.phi(), tk.eta(), tk.phi() );
00169         // isolation in a cone with dR=0.3, and vetoing the track itself 
00170         if ( (dR < 0.01) || (dR > 0.3)  )  continue;
00171         ptSum += elemPt;
00172       }
00173       if (isCombinedIso_) {
00174         // loop on clusters....
00175         for (CaloTowerCollection::const_iterator it=calotower->begin();  it!=calotower->end();++it ){
00176           double dR = deltaR( it->eta(), it->phi(),tk.outerEta(), tk.outerPhi() );
00177           // veto value is 0.1 for towers....
00178           if ( (dR < 0.1) || (dR > 0.3)  )  continue;
00179           ptSum += it->emEnergy();
00180           ptSum += it->hadEnergy();
00181         }
00182       }
00183     if (isRelativeIso_) ptSum /= tk.pt();
00184     return ptSum;
00185 }
00186 
00187 
00188 
00189 bool EwkMuLumiMonitorDQM::IsMuMatchedToHLTMu ( const reco::Muon & mu, std::vector<reco::Particle> HLTMu , double DR, double DPtRel ) {
00190   size_t dim =  HLTMu.size();
00191   size_t nPass=0;
00192   if (dim==0) return false;
00193   for (size_t k =0; k< dim; k++ ) {
00194     if (  (deltaR(HLTMu[k], mu) < DR)   && (fabs(HLTMu[k].pt() - mu.pt())/ HLTMu[k].pt()<DPtRel)){     
00195       nPass++ ;
00196     }
00197   }
00198   return (nPass>0);
00199 }
00200 
00201 
00202 
00203 void EwkMuLumiMonitorDQM::endJob() {
00204 }
00205 
00206 void EwkMuLumiMonitorDQM::endRun(const Run& r, const EventSetup&) {
00207   
00208   LogVerbatim("") << "\n>>>>>> Z/W SELECTION SUMMARY BEGIN >>>>>>>>>>>>>>>";
00209   LogVerbatim("") << "Total numer of events analyzed: " << nall << " [events]";
00210   LogVerbatim("") << "Total numer of events selected: " << nsel << " [events]";
00211   
00212   LogVerbatim("") << "Passing HLT criteria:           " << nhlt << " [events] " ; 
00213   LogVerbatim("") << "Passing 2 HLT match criteria:           " << n2hlt << " [events] " ;
00214   LogVerbatim("") << "Passing 1 HLT match criteria:           " << n1hlt << " [events] " ;
00215   LogVerbatim("") << "Passing Not Iso criteria:           " << nNotIso << " [events] " ;
00216   LogVerbatim("") << "Passing GlbSta criteria:           " << nGlbSta << " [events] " ;
00217   LogVerbatim("") << "Passing W criteria:           " << nTMass << " [events] " ;
00218   LogVerbatim("") << ">>>>>> Z/W SELECTION SUMMARY END   >>>>>>>>>>>>>>>\n";
00219 }
00220 
00221 void EwkMuLumiMonitorDQM::analyze (const Event & ev, const EventSetup &) {
00222       nall++;  
00223       bool hlt_sel = false;
00224       double iso1=-1;
00225       double iso2=-1;
00226       bool isMu1Iso = false;
00227       bool isMu2Iso = false;
00228       bool singleTrigFlag1 = false;
00229       bool singleTrigFlag2 = false; 
00230       isZGolden1HLT_=false;  
00231       isZGolden2HLT_=false; 
00232       isZGoldenNoIso_=false;
00233       isZGlbSta_=false;
00234       isZGlbTrk_=false;      
00235       isW_=false;
00236       // Trigger
00237       bool trigger_fired = false;
00238       
00239       Handle<TriggerResults> triggerResults;
00240       if (!ev.getByLabel(trigTag_, triggerResults)) {
00241         //LogWarning("") << ">>> TRIGGER collection does not exist !!!";
00242         return;
00243       }
00244       
00245       ev.getByLabel(trigTag_, triggerResults); 
00246       /*
00247         const edm::TriggerNames & trigNames = ev.triggerNames(*triggerResults);
00248 
00249         
00250       for (size_t i=0; i<triggerResults->size(); i++) {
00251       std::string trigName = trigNames.triggerName(i);
00252       //std::cout << " trigName == " << trigName << std::endl;
00253         if ( trigName == hltPath_ && triggerResults->accept(i)) {
00254         trigger_fired = true;
00255         hlt_sel=true;
00256         nhlt++;
00257         }
00258         } 
00259       */
00260       // see the trigger single muon which are present
00261       string lowestMuonUnprescaledTrig = "";
00262       bool lowestMuonUnprescaledTrigFound = false;
00263       const std::vector<std::string>& triggerNames = hltConfigProvider_.triggerNames();
00264       for (size_t ts = 0; ts< triggerNames.size() ; ts++){
00265         string trig = triggerNames[ts];
00266         size_t f = trig.find("HLT_Mu");
00267         if ( (f != std::string::npos)  ) {
00268           // std::cout << "single muon trigger present: " << trig << std::endl; 
00269           // See if the trigger is prescaled; 
00271           bool prescaled = false;
00272           const unsigned int prescaleSize = hltConfigProvider_.prescaleSize() ;
00273           for (unsigned int ps= 0; ps<  prescaleSize; ps++){
00274             const unsigned int prescaleValue = hltConfigProvider_.prescaleValue(ps, trig) ;
00275             if (prescaleValue != 1) prescaled =true;
00276             //  std::cout<< " prescaleValue[" << ps << "] =" << prescaleValue <<std::endl;
00277           }
00278           if (!prescaled){
00279             //looking now for the lowest hlt path not prescaled, with name of the form HLT_MuX or HLTMuX_vY
00280             for (unsigned int n=9; n<100 ; n++ ){
00281               string lowestTrig= "HLT_Mu";
00282               string lowestTrigv0 = "copy";
00283               std::stringstream out;
00284               out << n;
00285               std::string s = out.str(); 
00286               lowestTrig.append(s);
00287               lowestTrigv0 = lowestTrig;  
00288               for (unsigned int v = 1; v<10 ; v++ ){
00289                 lowestTrig.append("_v");
00290                 std::stringstream oout;
00291                 oout << v;
00292                 std::string ss = oout.str(); 
00293                 lowestTrig.append(ss);
00294                 if (trig==lowestTrig) lowestMuonUnprescaledTrig = trig ;
00295                 if (trig==lowestTrig) lowestMuonUnprescaledTrigFound = true ;
00296                 if (trig==lowestTrig) break ;
00297               } 
00298               if (lowestMuonUnprescaledTrigFound) break; 
00299              
00300               lowestTrig = lowestTrigv0;
00301               if (trig==lowestTrig) lowestMuonUnprescaledTrig = trig ;
00302               //      if (trig==lowestTrig) {std::cout << " before break, lowestTrig lowest single muon trigger present unprescaled: " << lowestTrig << std::endl; }
00303               if (trig==lowestTrig) lowestMuonUnprescaledTrigFound = true ;
00304               if (trig==lowestTrig) break ;
00305             }
00306             if (lowestMuonUnprescaledTrigFound) break; 
00307           }
00308         }
00309       }
00310       //  std::cout << "after break, lowest single muon trigger present unprescaled: " << lowestMuonUnprescaledTrig << std::endl; 
00311       unsigned int triggerIndex; // index of trigger path
00312       
00313       // See if event passed trigger paths
00314       std::string hltPath_ = lowestMuonUnprescaledTrig;
00315  
00316       triggerIndex = hltConfigProvider_.triggerIndex(hltPath_);
00317       if (triggerIndex < triggerResults->size()) trigger_fired = triggerResults->accept(triggerIndex);
00318       std::string L3FilterName_="";
00319       if (trigger_fired){
00320         const std::vector<std::string>& moduleLabs = hltConfigProvider_.moduleLabels(hltPath_); 
00321       /*for (size_t k =0; k < moduleLabs.size()-1 ; k++){
00322         std::cout << "moduleLabs[" << k << "] == " << moduleLabs[k] << std::endl;
00323       }
00324       */
00325       // the l3 filter name is just the last module.... 
00326         size_t moduleLabsSizeMinus2 = moduleLabs.size() - 2 ;
00327         //      std::cout<<"moduleLabs[" << moduleLabsSizeMinus2 << "]== "<< moduleLabs[moduleLabsSizeMinus2] << std::endl;        
00328          
00329         L3FilterName_ = moduleLabs[moduleLabsSizeMinus2];
00330        
00331       }
00332 
00333       
00334       edm::Handle< trigger::TriggerEvent > handleTriggerEvent;
00335       LogTrace("") << ">>> Trigger bit: " << trigger_fired << " (" << hltPath_ << ")";
00336       if ( ! ev.getByLabel( trigEv_, handleTriggerEvent ))  {
00337         //LogWarning( "errorTriggerEventValid" ) << "trigger::TriggerEvent product with InputTag " << trigEv_.encode() << " not in event";
00338         return;
00339       }
00340       ev.getByLabel( trigEv_, handleTriggerEvent );
00341       const trigger::TriggerObjectCollection & toc(handleTriggerEvent->getObjects());
00342       size_t nMuHLT =0;
00343       std::vector<reco::Particle>  HLTMuMatched; 
00344       for ( size_t ia = 0; ia < handleTriggerEvent->sizeFilters(); ++ ia) {
00345         std::string fullname = handleTriggerEvent->filterTag(ia).encode();
00346         //std::cout<< "fullname::== " << fullname<< std::endl;
00347         std::string name;
00348         size_t p = fullname.find_first_of(':');
00349         if ( p != std::string::npos) {
00350           name = fullname.substr(0, p);
00351         }
00352         else {
00353           name = fullname;
00354         }
00355         if ( &toc !=0 ) {
00356           const trigger::Keys & k = handleTriggerEvent->filterKeys(ia);
00357           for (trigger::Keys::const_iterator ki = k.begin(); ki !=k.end(); ++ki ) {
00358             // looking at all the single muon l3 trigger present, for example hltSingleMu15L3Filtered15.....
00359             if (name == L3FilterName_  ) {
00360               // trigger_fired = true;
00361               hlt_sel=true;
00362               nhlt++; 
00363               HLTMuMatched.push_back(toc[*ki].particle());
00364               nMuHLT++;     
00365             }
00366           }    
00367         }
00368       }
00369       
00370       // Beam spot
00371       Handle<reco::BeamSpot> beamSpotHandle;
00372       if (!ev.getByLabel(InputTag("offlineBeamSpot"), beamSpotHandle)) {
00373         //LogWarning("") << ">>> No beam spot found !!!";
00374         return;
00375       }
00376 
00377       
00378         //  looping on muon....
00379       Handle<View<Muon> >   muons;     
00380       if (!ev.getByLabel(muonTag_, muons)) {           
00381         //LogError("") << ">>> muon collection does not exist !!!";     
00382         return;     
00383       }
00384       
00385       ev.getByLabel(muonTag_, muons);  
00386       //saving only muons with pt> ptMuCut and eta<etaMuCut, and dxy<dxyCut  
00387       std::vector<reco::Muon>  highPtGlbMuons; 
00388       std::vector<reco::Muon>  highPtStaMuons; 
00389 
00390       for (size_t i=0; i<muons->size(); i++ ){  
00391         const reco::Muon & mu = muons->at(i);
00392         double pt = mu.pt();
00393         double eta = mu.eta();
00394         if (pt> ptMuCut_ && fabs(eta)< etaMuCut_ ) {
00395           if (mu.isGlobalMuon()) { 
00396             //check the dxy....
00397             double dxy = mu.innerTrack()->dxy(beamSpotHandle->position()); 
00398             if (fabs(dxy)>dxyCut_) continue;       
00399             highPtGlbMuons.push_back(mu);
00400           }
00401           if (mu.isGlobalMuon()) continue;
00402           // if is not, look if it is a standalone.... 
00403           if(mu.isStandAloneMuon()) highPtStaMuons.push_back(mu); 
00404           nEvWithHighPtMu++;     
00405         }
00406       }
00407       size_t nHighPtGlbMu = highPtGlbMuons.size();
00408       size_t nHighPtStaMu = highPtStaMuons.size();
00409       if ( hlt_sel &&  (nHighPtGlbMu> 0) ) {
00410         // loop on high pt muons if there's at least two with opposite charge build a Z, more then one z candidate is foreseen.........
00411         // stop the loop after 10 cicles....  
00412         (nHighPtGlbMu> 10)?   nHighPtGlbMu=10 : 1; 
00413         // Z selection
00414         if (nHighPtGlbMu>1 ){
00415           for(unsigned int i =0 ; i < nHighPtGlbMu ; i++) {
00416             reco::Muon muon1 = highPtGlbMuons[i];
00417             math::XYZTLorentzVector mu1(muon1.p4());
00418             //double pt1= muon1.pt();
00419             for (unsigned int j =i+1; j <nHighPtGlbMu ; ++j ){
00420               reco::Muon muon2 = highPtGlbMuons[j];
00421               math::XYZTLorentzVector mu2(muon2.p4());
00422               //double pt2= muon2.pt();
00423               if (muon1.charge() == muon2.charge()) continue; 
00424               math::XYZTLorentzVector pair = mu1 + mu2;
00425               double mass = pair.M();
00426                 // checking isolation and hlt maching
00427               iso1 = muIso ( muon1 );
00428               iso2 = muIso ( muon2 );
00429               isMu1Iso = (iso1 < isoCut03_);
00430               isMu2Iso = (iso2 < isoCut03_);
00431               singleTrigFlag1 = IsMuMatchedToHLTMu ( muon1,  HLTMuMatched ,maxDeltaR_, maxDPtRel_ );
00432               singleTrigFlag2 = IsMuMatchedToHLTMu ( muon2,  HLTMuMatched ,maxDeltaR_, maxDPtRel_ );
00433               if (singleTrigFlag1 && singleTrigFlag2)  isZGolden2HLT_ = true; 
00434               if ( (singleTrigFlag1 && !singleTrigFlag2) || (!singleTrigFlag1 && singleTrigFlag2) )  isZGolden1HLT_ = true;  
00435               // Z Golden passing all criteria, with 2 or 1 muon matched to an HLT muon. Using the two cathegories as a control sample for the HLT matching efficiency 
00436               if (isZGolden2HLT_ || isZGolden1HLT_){
00437                 // a Z golden has been found, let's remove the two muons from the list, dome for avoiding resolution effect enter muons in the standalone and tracker collections.........
00438                 highPtGlbMuons.erase(highPtGlbMuons.begin() + i );
00439                 highPtGlbMuons.erase(highPtGlbMuons.begin() + j );
00440                 // and updating the number of high pt muons....
00441                 nHighPtGlbMu = highPtGlbMuons.size();
00442 
00443                 if (  isMu1Iso &&  isMu2Iso  ){
00444                   niso++;
00445                   if (isZGolden2HLT_) {
00446                     n2hlt++; 
00447                     mass2HLT_->Fill(mass);
00448                     highMass2HLT_->Fill(mass);
00449                     /*
00450                       if (pt1 > pt2) {
00451                       highest_mupt2HLT_ -> Fill (pt1);
00452                       lowest_mupt2HLT_ -> Fill (pt2);
00453                       } else {
00454                       highest_mupt2HLT_ -> Fill (pt2);
00455                       lowest_mupt2HLT_ -> Fill (pt1);
00456                       } 
00457                     */  
00458                   }
00459                   if (isZGolden1HLT_) {
00460                     n1hlt++; 
00461                     mass1HLT_->Fill(mass);
00462                     highMass1HLT_->Fill(mass);
00463                     /*
00464                       if (pt1 >pt2) {
00465                       highest_mupt1HLT_ -> Fill (pt1);
00466                       lowest_mupt1HLT_ -> Fill (pt2);
00467                     } else {
00468                       highest_mupt1HLT_ -> Fill (pt2);
00469                       lowest_mupt1HLT_ -> Fill (pt1);
00470                     }
00471                     */
00472                   } 
00473                 } else {
00474                   // ZGlbGlb when at least one of the two muon is not isolated and at least one HLT matched, used as control sample for the isolation efficiency
00475                   // filling events with one muon not isolated and both hlt mathced  
00476                   if (((isMu1Iso &&  !isMu2Iso) || (!isMu1Iso &&  isMu2Iso )) && (isZGolden2HLT_ && isZGolden1HLT_)  ) {
00477                     isZGoldenNoIso_=true;
00478                     nNotIso++;
00479                     massNotIso_->Fill(mass);
00480                     highMassNotIso_->Fill(mass);
00481                   }
00482                   /*
00483                     if (pt1 > pt2) {
00484                     highest_muptNotIso_ -> Fill (pt1);
00485                     lowest_muptNotIso_ -> Fill (pt2);
00486                     } else {
00487                     highest_muptNotIso_ -> Fill (pt2);
00488                     lowest_muptNotIso_ -> Fill (pt1);
00489                     } 
00490                   */ 
00491                 }
00492               }
00493             }
00494           }
00495         }
00496 // W->MuNu selection (if at least one muon has been selected)
00497         // looking for a W if a Z is not found.... let's think if we prefer to exclude zMuMuNotIso or zMuSta....
00498         if ( !(isZGolden2HLT_ || isZGolden1HLT_ )){
00499           Handle<View<MET> > metCollection;     
00500           if (!ev.getByLabel(metTag_, metCollection)) {           
00501             //LogError("") << ">>> MET collection does not exist !!!";           
00502             return;     
00503           }     
00504           const MET& met = metCollection->at(0);   
00505           nW=0;
00506           for(unsigned int i =0 ; i < nHighPtGlbMu ; i++) {
00507             reco::Muon muon1 = highPtGlbMuons[i];
00508             /*      
00509                    quality cut not implemented
00510                 Quality Cuts           double dxy = gm->dxy(beamSpotHandle->position()); 
00511                 Cut in 0.2           double trackerHits = gm->hitPattern().numberOfValidTrackerHits(); 
00512                 Cut in 11           bool quality = fabs(dxy)<dxyCut_  && muon::isGoodMuon(mu,muon::GlobalMuonPromptTight) && trackerHits>=trackerHitsCut_ && mu.isTrackerMuon() ;  
00513   if (!quality) continue;          
00514             */
00515             // isolation cut and hlt maching
00516             iso1 = muIso ( muon1 );
00517             isMu1Iso = (iso1 < isoCut03_);
00518             if (!isMu1Iso) continue;
00519             // checking if muon is matched to any HLT muon....
00520             singleTrigFlag1 = IsMuMatchedToHLTMu ( muon1,  HLTMuMatched ,maxDeltaR_, maxDPtRel_ );
00521             if (!singleTrigFlag1) continue;
00522             //std::cout << " is GlobMu macthecd to HLT: " << singleTrigFlag1 << std::endl; 
00523             // MT cuts        
00524             double met_px = met.px();
00525             double met_py = met.py();
00526             
00527             if (!metIncludesMuons_) {
00528               for(unsigned int i =0 ; i < nHighPtGlbMu ; i++) {
00529                 reco::Muon muon1 = highPtGlbMuons[i];
00530                 met_px -= muon1.px();
00531                 met_py -= muon1.py();
00532               }
00533             }
00534             double met_et = met.pt() ; //sqrt(met_px*met_px+met_py*met_py);
00535             LogTrace("") << ">>> MET, MET_px, MET_py: " << met_et << ", " << met_px << ", " << met_py << " [GeV]";
00536             double w_et = met_et+ muon1.pt();           
00537             double w_px = met_px+ muon1.px();           
00538             double w_py = met_py+muon1.py();           
00539             double massT = w_et*w_et - w_px*w_px - w_py*w_py;           
00540             massT = (massT>0) ? sqrt(massT) : 0;
00541             // Acoplanarity cuts           
00542             Geom::Phi<double> deltaphi(muon1.phi()-atan2(met_py,met_px));           
00543             double acop = M_PI - fabs(deltaphi.value());  
00544             //std::cout << " is acp of W candidate less then cut: " << (acop< acopCut_) << std::endl; 
00545             if (acop > acopCut_) continue ; // Cut in 2.0    
00546             TMass_->Fill(massT);
00547             if (massT<mtMin_ || massT>mtMax_) continue;    // Cut in (50,200) GeV           
00548             // we give the number of W only in the tMass selected but we have a look at mass tails to check the QCD background 
00549             isW_=true;
00550             nW++;
00551             nTMass++;     
00552           }
00553         }
00554 // if a zGlobal is not selected, look at the dimuonGlobalOneStandAlone and dimuonGlobalOneTrack...., used as a control sample for the tracking efficiency  and muon system efficiency
00555         if ( !(isZGolden2HLT_ || isZGolden1HLT_ || isZGoldenNoIso_ )){
00556           for(unsigned int i =0 ; i < nHighPtGlbMu ; ++i) {
00557             reco::Muon glbMuon = highPtGlbMuons[i];
00558             math::XYZTLorentzVector mu1(glbMuon.p4());
00559             //double pt1= glbMuon.pt();
00560             // checking that the global muon is hlt matched otherwise skip the event
00561             singleTrigFlag1 = IsMuMatchedToHLTMu ( glbMuon,  HLTMuMatched ,maxDeltaR_, maxDPtRel_ );
00562             if (!singleTrigFlag1) continue;
00563             // checking that the global muon is isolated matched otherwise skip the event
00564             iso1 = muIso ( glbMuon );
00565             isMu1Iso = (iso1 < isoCut03_);
00566             if (!isMu1Iso) continue;
00567             // look at the standalone muon ....
00568             // stop the loop after 10 cicles....  
00569             (nHighPtStaMu> 10)?   nHighPtStaMu=10 : 1; 
00570             for (unsigned int j =0; j <nHighPtStaMu ; ++j ){
00571               reco::Muon staMuon = highPtStaMuons[j];
00572               math::XYZTLorentzVector mu2(staMuon.p4());
00573               //double pt2= staMuon.pt();
00574               if (glbMuon.charge() == staMuon.charge()) continue; 
00575               math::XYZTLorentzVector pair = mu1 + mu2;
00576               double mass = pair.M();
00577               iso2 = muIso ( staMuon);
00578               isMu2Iso = (iso2 < isoCut03_);
00579               LogTrace("") << "\t... isolation value" << iso1 <<", isolated? " << isMu1Iso ;
00580               LogTrace("") << "\t... isolation value" << iso2 <<", isolated? " << isMu2Iso ;
00581               // requiring theat the global mu is mathed to the HLT  and both are isolated 
00582               if (isMu2Iso ) {    
00583                 isZGlbSta_=true;
00584                 nGlbSta++; 
00585                 massGlbSta_->Fill(mass);
00586                 highMassGlbSta_->Fill(mass);
00587                 /*
00588                   if (pt1 > pt2) {
00589                   highest_muptGlbSta_ -> Fill (pt1);
00590                   lowest_muptGlbSta_ -> Fill (pt2);
00591                 } else {
00592                   highest_muptGlbSta_ -> Fill (pt2);
00593                   lowest_muptGlbSta_ -> Fill (pt1);
00594                 }
00595                 */
00596               }
00597             }
00598             // look at the tracks....
00599             Handle< TrackCollection >   tracks;     
00600             if (!ev.getByLabel(trackTag_, tracks)) {           
00601               //LogError("") << ">>> track collection does not exist !!!";     
00602               return;     
00603             }
00604             ev.getByLabel(trackTag_, tracks);        
00605             Handle< CaloTowerCollection >   calotower;     
00606             if (!ev.getByLabel(caloTowerTag_, calotower)) {           
00607               //LogError("") << ">>> calotower collection does not exist !!!";     
00608               return;     
00609             } 
00610             ev.getByLabel(caloTowerTag_, calotower);
00611             // avoid to loop on more than 5000 trks
00612             size_t nTrk = tracks->size();
00613             (nTrk> 5000)?   nTrk=5000 : 1; 
00614             for (unsigned int j=0; j<nTrk; j++ ){       
00615               const reco::Track & tk = tracks->at(j);
00616               if (glbMuon.charge() == tk.charge()) continue; 
00617               double pt2 = tk.pt();
00618               double eta = tk.eta();
00619               double dxy = tk.dxy(beamSpotHandle->position());
00620               if (pt2< ptMuCut_ || fabs(eta) > etaMuCut_ || fabs(dxy)>dxyCut_) continue;
00621               //assuming that the track is a mu....
00622               math::XYZTLorentzVector mu2(tk.px(),tk.py(), tk.pz(), sqrt( (tk.p() * tk.p())  + ( 0.10566 * 0.10566))) ;
00623               math::XYZTLorentzVector pair = mu1 + mu2;
00624               double mass = pair.M();
00625               // now requiring that the tracks is isolated....... 
00626               iso2 = tkIso( tk, tracks, calotower);
00627               isMu2Iso = (iso2 < isoCut03_);
00628               //              std::cout << "found a track with rel/comb iso: " << iso2 << std::endl; 
00629               if (isMu2Iso) {    
00630                 isZGlbTrk_=true;
00631                 nGlbTrk++; 
00632                 massGlbTrk_->Fill(mass);
00633                 highMassGlbTrk_->Fill(mass);
00634                 if (!isW_) continue;
00635                 massIsBothGlbTrkThanW_->Fill(mass);
00636                 highMassIsBothGlbTrkThanW_->Fill(mass);
00637                 /*
00638                   if (pt1 > pt2) {
00639                   highest_muptGlbTrk_ -> Fill (pt1);
00640                   lowest_muptGlbTrk_ -> Fill (pt2);
00641                   } else {
00642                   highest_muptGlbTrk_ -> Fill (pt2);
00643                   lowest_muptGlbTrk_ -> Fill (pt1);
00644                 } 
00645                 */
00646               }
00647             }
00648           }
00649         }
00650       }
00651       if ( (hlt_sel || isZGolden2HLT_ || isZGolden1HLT_ || isZGoldenNoIso_ || isZGlbSta_ || isZGlbTrk_ || isW_) ) {   
00652         nsel++;  
00653         LogTrace("") << ">>>> Event ACCEPTED";
00654       } else {
00655         LogTrace("") << ">>>> Event REJECTED";
00656       }
00657       return;
00658 }