CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/DQMOffline/EGamma/plugins/ZToMuMuGammaAnalyzer.cc

Go to the documentation of this file.
00001 #include <iostream>
00002 #include <iomanip>
00003 //
00004 
00005 #include "DQMOffline/EGamma/plugins/ZToMuMuGammaAnalyzer.h"
00006 #include "CommonTools/UtilAlgos/interface/DeltaR.h"
00007 
00008 
00019 using namespace std;
00020 
00021 
00022 ZToMuMuGammaAnalyzer::ZToMuMuGammaAnalyzer( const edm::ParameterSet& pset )
00023 {
00024 
00025     fName_                  = pset.getUntrackedParameter<string>("Name");
00026     verbosity_              = pset.getUntrackedParameter<int>("Verbosity");
00027     prescaleFactor_         = pset.getUntrackedParameter<int>("prescaleFactor",1);
00028     standAlone_             = pset.getParameter<bool>("standAlone");
00029     outputFileName_         = pset.getParameter<string>("OutputFileName");
00030     isHeavyIon_             = pset.getUntrackedParameter<bool>("isHeavyIon",false);
00031     triggerEvent_           = pset.getParameter<edm::InputTag>("triggerEvent");
00032     useTriggerFiltering_    = pset.getParameter<bool>("useTriggerFiltering");
00033     //
00034     photonProducer_         = pset.getParameter<string>("phoProducer");
00035     photonCollection_       = pset.getParameter<string>("photonCollection");
00036 
00037     barrelRecHitProducer_   = pset.getParameter<string>("barrelRecHitProducer");
00038     barrelRecHitCollection_ = pset.getParameter<string>("barrelRecHitCollection");
00039 
00040     endcapRecHitProducer_   = pset.getParameter<string>("endcapRecHitProducer");
00041     endcapRecHitCollection_ = pset.getParameter<string>("endcapRecHitCollection");
00042 
00043     muonProducer_         = pset.getParameter<string>("muonProducer");
00044     muonCollection_       = pset.getParameter<string>("muonCollection");
00045     // Muon selection
00046     muonMinPt_             = pset.getParameter<double>("muonMinPt");
00047     minPixStripHits_       = pset.getParameter<int>("minPixStripHits");
00048     muonMaxChi2_           = pset.getParameter<double>("muonMaxChi2");
00049     muonMaxDxy_            = pset.getParameter<double>("muonMaxDxy");
00050     muonMatches_           = pset.getParameter<int>("muonMatches");
00051     validPixHits_          = pset.getParameter<int>("validPixHits");
00052     validMuonHits_         = pset.getParameter<int>("validMuonHits");
00053     muonTrackIso_          = pset.getParameter<double>("muonTrackIso");
00054     muonTightEta_          = pset.getParameter<double>("muonTightEta");
00055     // Dimuon selection
00056     minMumuInvMass_       = pset.getParameter<double>("minMumuInvMass");
00057     maxMumuInvMass_       = pset.getParameter<double>("maxMumuInvMass");
00058     // Photon selection
00059     photonMinEt_             = pset.getParameter<double>("photonMinEt");
00060     photonMaxEta_            = pset.getParameter<double>("photonMaxEta");
00061     photonTrackIso_          = pset.getParameter<double>("photonTrackIso");
00062     // mumuGamma selection
00063     nearMuonDr_               = pset.getParameter<double>("nearMuonDr");
00064     nearMuonHcalIso_          = pset.getParameter<double>("nearMuonHcalIso");
00065     farMuonEcalIso_           = pset.getParameter<double>("farMuonEcalIso");
00066     farMuonTrackIso_          = pset.getParameter<double>("farMuonTrackIso");
00067     farMuonMinPt_             = pset.getParameter<double>("farMuonMinPt");
00068     minMumuGammaInvMass_  = pset.getParameter<double>("minMumuGammaInvMass");
00069     maxMumuGammaInvMass_  = pset.getParameter<double>("maxMumuGammaInvMass");
00070     //
00071     parameters_ = pset;
00072 
00073 }
00074 
00075 
00076 
00077 ZToMuMuGammaAnalyzer::~ZToMuMuGammaAnalyzer() {}
00078 
00079 
00080 void ZToMuMuGammaAnalyzer::beginJob()
00081 {
00082 
00083   nEvt_=0;
00084   nEntry_=0;
00085 
00086   dbe_ = 0;
00087   dbe_ = edm::Service<DQMStore>().operator->();
00088 
00089 
00090 
00091 //   double eMin = parameters_.getParameter<double>("eMin");
00092 //   double eMax = parameters_.getParameter<double>("eMax");
00093 //   int    eBin = parameters_.getParameter<int>("eBin");
00094 
00095   double etMin = parameters_.getParameter<double>("etMin");
00096   double etMax = parameters_.getParameter<double>("etMax");
00097   int    etBin = parameters_.getParameter<int>("etBin");
00098 
00099 //   double sumMin = parameters_.getParameter<double>("sumMin");
00100 //   double sumMax = parameters_.getParameter<double>("sumMax");
00101 //   int    sumBin = parameters_.getParameter<int>("sumBin");
00102 
00103 //   double etaMin = parameters_.getParameter<double>("etaMin");
00104 //   double etaMax = parameters_.getParameter<double>("etaMax");
00105 //   int    etaBin = parameters_.getParameter<int>("etaBin");
00106 
00107 //   double phiMin = parameters_.getParameter<double>("phiMin");
00108 //   double phiMax = parameters_.getParameter<double>("phiMax");
00109 //   int    phiBin = parameters_.getParameter<int>("phiBin");
00110 
00111 //   double r9Min = parameters_.getParameter<double>("r9Min");
00112 //   double r9Max = parameters_.getParameter<double>("r9Max");
00113 //   int    r9Bin = parameters_.getParameter<int>("r9Bin");
00114 
00115 //   double hOverEMin = parameters_.getParameter<double>("hOverEMin");
00116 //   double hOverEMax = parameters_.getParameter<double>("hOverEMax");
00117 //   int    hOverEBin = parameters_.getParameter<int>("hOverEBin");
00118 
00119 //   double xMin = parameters_.getParameter<double>("xMin");
00120 //   double xMax = parameters_.getParameter<double>("xMax");
00121 //   int    xBin = parameters_.getParameter<int>("xBin");
00122 
00123 //   double yMin = parameters_.getParameter<double>("yMin");
00124 //   double yMax = parameters_.getParameter<double>("yMax");
00125 //   int    yBin = parameters_.getParameter<int>("yBin");
00126 
00127 //   double numberMin = parameters_.getParameter<double>("numberMin");
00128 //   double numberMax = parameters_.getParameter<double>("numberMax");
00129 //   int    numberBin = parameters_.getParameter<int>("numberBin");
00130 
00131 //   double zMin = parameters_.getParameter<double>("zMin");
00132 //   double zMax = parameters_.getParameter<double>("zMax");
00133 //   int    zBin = parameters_.getParameter<int>("zBin");
00134 
00135 //   double rMin = parameters_.getParameter<double>("rMin");
00136 //   double rMax = parameters_.getParameter<double>("rMax");
00137 //   int    rBin = parameters_.getParameter<int>("rBin");
00138 
00139 //   double dPhiTracksMin = parameters_.getParameter<double>("dPhiTracksMin");
00140 //   double dPhiTracksMax = parameters_.getParameter<double>("dPhiTracksMax");
00141 //   int    dPhiTracksBin = parameters_.getParameter<int>("dPhiTracksBin");
00142 
00143 //   double dEtaTracksMin = parameters_.getParameter<double>("dEtaTracksMin");
00144 //   double dEtaTracksMax = parameters_.getParameter<double>("dEtaTracksMax");
00145 //   int    dEtaTracksBin = parameters_.getParameter<int>("dEtaTracksBin");
00146 
00147 //   double sigmaIetaMin = parameters_.getParameter<double>("sigmaIetaMin");
00148 //   double sigmaIetaMax = parameters_.getParameter<double>("sigmaIetaMax");
00149 //   int    sigmaIetaBin = parameters_.getParameter<int>("sigmaIetaBin");
00150 
00151 //   double eOverPMin = parameters_.getParameter<double>("eOverPMin");
00152 //   double eOverPMax = parameters_.getParameter<double>("eOverPMax");
00153 //   int    eOverPBin = parameters_.getParameter<int>("eOverPBin");
00154 
00155 //   double chi2Min = parameters_.getParameter<double>("chi2Min");
00156 //   double chi2Max = parameters_.getParameter<double>("chi2Max");
00157 //   int    chi2Bin = parameters_.getParameter<int>("chi2Bin");
00158 
00159 
00160 //   int reducedEtBin  = etBin/4;
00161 //   int reducedEtaBin = etaBin/4;
00162 //   int reducedSumBin = sumBin/4;
00163 //   int reducedR9Bin  = r9Bin/4;
00164 
00165 
00167 
00168   if (dbe_) {
00169 
00170 
00171     dbe_->setCurrentFolder("Egamma/PhotonAnalyzer/ZToMuMuGamma");
00172     h1_mumuInvMass_ = dbe_->book1D("mumuInvMass","Two muon invariant mass: M (GeV)",etBin/2,etMin,etMax/2);
00173     h1_mumuGammaInvMass_ = dbe_->book1D("mumuGammaInvMass","Two-muon plus gamma invariant mass: M (GeV)",etBin/2,etMin,etMax/2);
00174  
00175 
00176 
00177   }//end if(dbe_)
00178 
00179 
00180 }//end BeginJob
00181 
00182 
00183 
00184 void ZToMuMuGammaAnalyzer::analyze( const edm::Event& e, const edm::EventSetup& esup )
00185 {
00186   using namespace edm;
00187 
00188   if (nEvt_% prescaleFactor_ ) return;
00189   nEvt_++;
00190   LogInfo("ZToMuMuGammaAnalyzer") << "ZToMuMuGammaAnalyzer Analyzing event number: " << e.id() << " Global Counter " << nEvt_ <<"\n";
00191 
00192 
00193   // Get the trigger results
00194   bool validTriggerEvent=true;
00195   edm::Handle<trigger::TriggerEvent> triggerEventHandle;
00196   trigger::TriggerEvent triggerEvent;
00197   e.getByLabel(triggerEvent_,triggerEventHandle);
00198   if(!triggerEventHandle.isValid()) {
00199     edm::LogInfo("PhotonAnalyzer") << "Error! Can't get the product "<< triggerEvent_.label() << endl;
00200     validTriggerEvent=false;
00201   }
00202   if(validTriggerEvent) triggerEvent = *(triggerEventHandle.product());
00203 
00204 
00205   // Get the reconstructed photons
00206   bool validPhotons=true;
00207   Handle<reco::PhotonCollection> photonHandle;
00208   reco::PhotonCollection photonCollection;
00209   e.getByLabel(photonProducer_, photonCollection_ , photonHandle);
00210   if ( !photonHandle.isValid()) {
00211     edm::LogInfo("ZToMuMuGammaAnalyzer") << "Error! Can't get the product "<< photonCollection_ << endl;
00212     validPhotons=false;
00213   }
00214   if(validPhotons) photonCollection = *(photonHandle.product());
00215 
00216   // Get the PhotonId objects
00217   bool validloosePhotonID=true;
00218   Handle<edm::ValueMap<bool> > loosePhotonFlag;
00219   edm::ValueMap<bool> loosePhotonID;
00220   e.getByLabel("PhotonIDProd", "PhotonCutBasedIDLoose", loosePhotonFlag);
00221   if ( !loosePhotonFlag.isValid()) {
00222     edm::LogInfo("ZToMuMuGammaAnalyzer") << "Error! Can't get the product "<< "PhotonCutBasedIDLoose" << endl;
00223     validloosePhotonID=false;
00224   }
00225   if (validloosePhotonID) loosePhotonID = *(loosePhotonFlag.product());
00226 
00227   bool validtightPhotonID=true;
00228   Handle<edm::ValueMap<bool> > tightPhotonFlag;
00229   edm::ValueMap<bool> tightPhotonID;
00230   e.getByLabel("PhotonIDProd", "PhotonCutBasedIDTight", tightPhotonFlag);
00231   if ( !tightPhotonFlag.isValid()) {
00232     edm::LogInfo("ZToMuMuGammaAnalyzer") << "Error! Can't get the product "<< "PhotonCutBasedIDTight" << endl;
00233     validtightPhotonID=false;
00234   }
00235   if (validtightPhotonID) tightPhotonID = *(tightPhotonFlag.product());
00236 
00237   // Get the reconstructed muons
00238   bool validMuons=true;
00239   Handle<reco::MuonCollection> muonHandle;
00240   reco::MuonCollection muonCollection;
00241   e.getByLabel(muonProducer_, muonCollection_ , muonHandle);
00242   if ( !muonHandle.isValid()) {
00243     edm::LogInfo("ZToMuMuGammaAnalyzer") << "Error! Can't get the product "<< muonCollection_ << endl;
00244     validMuons=false;
00245   }
00246   if(validMuons) muonCollection = *(muonHandle.product());
00247 
00248   // Get the beam spot
00249   edm::Handle<reco::BeamSpot> bsHandle;
00250   e.getByLabel("offlineBeamSpot", bsHandle);
00251   if (!bsHandle.isValid()) {
00252       edm::LogError("TrackerOnlyConversionProducer") << "Error! Can't get the product primary Vertex Collection "<< "\n";
00253       return;
00254   }
00255   const reco::BeamSpot &thebs = *bsHandle.product();
00256 
00257 
00258 
00259 
00260   //Prepare list of photon-related HLT filter names
00261   vector<int> Keys;
00262   for(uint filterIndex=0;filterIndex<triggerEvent.sizeFilters();++filterIndex){  //loop over all trigger filters in event (i.e. filters passed)
00263     string label = triggerEvent.filterTag(filterIndex).label();
00264     if(label.find( "Photon" ) != string::npos ) {  //get photon-related filters
00265       for(uint filterKeyIndex=0;filterKeyIndex<triggerEvent.filterKeys(filterIndex).size();++filterKeyIndex){  //loop over keys to objects passing this filter
00266         Keys.push_back(triggerEvent.filterKeys(filterIndex)[filterKeyIndex]);  //add keys to a vector for later reference
00267       }
00268     }
00269   }
00270 
00271   // sort Keys vector in ascending order
00272   // and erases duplicate entries from the vector
00273   sort(Keys.begin(),Keys.end());
00274   for ( uint i=0 ; i<Keys.size() ; )
00275    {
00276     if (i!=(Keys.size()-1))
00277      {
00278       if (Keys[i]==Keys[i+1]) Keys.erase(Keys.begin()+i+1) ;
00279       else ++i ;
00280      }
00281     else ++i ;
00282    }
00283 
00284 
00285 
00287   if ( muonCollection.size() < 2 ) return;
00288 
00289   for( reco::MuonCollection::const_iterator  iMu = muonCollection.begin(); iMu != muonCollection.end(); iMu++) {
00290     if ( !basicMuonSelection (*iMu) ) continue;
00291  
00292     for( reco::MuonCollection::const_iterator  iMu2 = iMu+1; iMu2 != muonCollection.end(); iMu2++) {
00293       if ( !basicMuonSelection (*iMu2) ) continue;
00294       if ( iMu->charge()*iMu2->charge() > 0) continue;
00295 
00296       if ( !muonSelection(*iMu,thebs) && !muonSelection(*iMu2,thebs) ) continue;
00297 
00298  
00299      
00300       float mumuMass = mumuInvMass(*iMu,*iMu2) ;
00301       if ( mumuMass <  minMumuInvMass_  ||  mumuMass >  maxMumuInvMass_ ) continue;
00302 
00303       h1_mumuInvMass_ -> Fill (mumuMass);      
00304 
00305       if (  photonCollection.size() < 1 ) continue;
00306 
00307       reco::Muon nearMuon;
00308       reco::Muon farMuon;
00309       for( reco::PhotonCollection::const_iterator  iPho = photonCollection.begin(); iPho != photonCollection.end(); iPho++) {
00310         if ( !photonSelection (*iPho) ) continue;
00311 
00312 
00313         DeltaR<reco::Muon, reco::Photon> deltaR;
00314         double dr1 = deltaR(*iMu, *iPho);
00315         double dr2 = deltaR(*iMu2,*iPho);
00316         double drNear = dr1;
00317         if (dr1 < dr2) {
00318           nearMuon =*iMu ; farMuon  = *iMu2; drNear = dr1;
00319         } else {
00320           nearMuon = *iMu2; farMuon  = *iMu; drNear = dr2;
00321         }
00322 
00323         if ( nearMuon.isolationR03().hadEt > nearMuonHcalIso_ )  continue;
00324         if ( farMuon.isolationR03().sumPt > farMuonTrackIso_ )  continue;
00325         if ( farMuon.isolationR03().emEt  > farMuonEcalIso_ )  continue;
00326         if ( farMuon.pt() < farMuonMinPt_ )       continue;
00327         if ( drNear > nearMuonDr_)                continue;
00328         
00329 
00330         float mumuGammaMass = mumuGammaInvMass(*iMu,*iMu2,*iPho) ;
00331         if ( mumuGammaMass < minMumuGammaInvMass_ || mumuGammaMass > maxMumuGammaInvMass_ ) continue;
00332             
00333         h1_mumuGammaInvMass_ ->Fill (mumuGammaMass);
00334 
00335 
00336       } 
00337       
00338     }
00339 
00340   }
00341 
00342 
00343 }//End of Analyze method
00344 
00345 void ZToMuMuGammaAnalyzer::endRun(const edm::Run& run, const edm::EventSetup& setup)
00346 {
00347   if(!standAlone_){
00348 
00349     dbe_->setCurrentFolder("Egamma/PhotonAnalyzer/ZToMuMuGamma");
00350 
00351 
00352   }
00353 
00354 }
00355 
00356 
00357 void ZToMuMuGammaAnalyzer::endJob()
00358 {
00359   //dbe_->showDirStructure();
00360   if(standAlone_){
00361     dbe_->setCurrentFolder("Egamma/PhotonAnalyzer/ZToMuMuGamma");
00362 
00363     dbe_->save(outputFileName_);
00364   }
00365 
00366 
00367 }
00368 
00369 bool ZToMuMuGammaAnalyzer::basicMuonSelection ( const reco::Muon & mu) {
00370   bool result=true;
00371   if (!mu.innerTrack().isNonnull())    result=false;
00372   if (!mu.globalTrack().isNonnull())   result=false;
00373   if ( !mu.isGlobalMuon() )            result=false; 
00374   if ( mu.pt() < muonMinPt_ )                  result=false;
00375   if ( fabs(mu.eta())>2.4 )            result=false;
00376 
00377   int pixHits=0;
00378   int tkHits=0;
00379   if ( mu.innerTrack().isNonnull() ) {
00380     pixHits=mu.innerTrack()->hitPattern().numberOfValidPixelHits();
00381     tkHits=mu.innerTrack()->hitPattern().numberOfValidStripHits();
00382   }
00383 
00384   if ( pixHits+tkHits < minPixStripHits_ ) result=false;
00385   
00386 
00387   return result;  
00388 }
00389 
00390 bool ZToMuMuGammaAnalyzer::muonSelection ( const reco::Muon & mu,  const reco::BeamSpot& beamSpot) {
00391   bool result=true;
00392   if ( mu.globalTrack()->normalizedChi2() > muonMaxChi2_ )          result=false;
00393   if ( fabs( mu.globalTrack()->dxy(beamSpot)) > muonMaxDxy_ )       result=false;
00394   if ( mu.numberOfMatches() < muonMatches_ )                                   result=false;
00395 
00396   if ( mu.track()-> hitPattern().numberOfValidPixelHits() <  validPixHits_ )     result=false;
00397   if ( mu.globalTrack()->hitPattern().numberOfValidMuonHits() < validMuonHits_ ) result=false;
00398   if ( !mu.isTrackerMuon() )                                        result=false;
00399   // track isolation 
00400   if ( mu.isolationR03().sumPt > muonTrackIso_ )                                result=false;
00401   if ( fabs(mu.eta())>  muonTightEta_ )                                         result=false;
00402  
00403 
00404   return result;  
00405 }
00406 
00407 
00408 bool ZToMuMuGammaAnalyzer::photonSelection ( const reco::Photon & pho) {
00409   bool result=true;
00410   if ( pho.pt() < photonMinEt_ )          result=false;
00411   if ( fabs(pho.eta())> photonMaxEta_ )   result=false;
00412   if ( pho.isEBEEGap() )       result=false;
00413   //  if ( pho.trkSumPtHollowConeDR04() >   photonTrackIso_ )   result=false; // check how to exclude the muon track (which muon track).
00414 
00415 
00416   return result;  
00417 }
00418 
00419 
00420 
00421 float ZToMuMuGammaAnalyzer::mumuInvMass(const reco::Muon & mu1,const reco::Muon & mu2 )
00422  {
00423   math::XYZTLorentzVector p12 = mu1.p4()+mu2.p4() ;
00424   float mumuMass2 = p12.Dot(p12) ;
00425   float invMass = sqrt(mumuMass2) ;
00426   return invMass ;
00427  }
00428 
00429 float ZToMuMuGammaAnalyzer::mumuGammaInvMass(const reco::Muon & mu1,const reco::Muon & mu2, const reco::Photon& pho )
00430  {
00431    math::XYZTLorentzVector p12 = mu1.p4()+mu2.p4()+pho.p4() ;
00432    float Mass2 = p12.Dot(p12) ;
00433    float invMass = sqrt(Mass2) ;
00434    return invMass ;
00435  }
00436