CMS 3D CMS Logo

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