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
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
00056 minMumuInvMass_ = pset.getParameter<double>("minMumuInvMass");
00057 maxMumuInvMass_ = pset.getParameter<double>("maxMumuInvMass");
00058
00059 photonMinEt_ = pset.getParameter<double>("photonMinEt");
00060 photonMaxEta_ = pset.getParameter<double>("photonMaxEta");
00061 photonTrackIso_ = pset.getParameter<double>("photonTrackIso");
00062
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
00092
00093
00094
00095 double etMin = parameters_.getParameter<double>("etMin");
00096 double etMax = parameters_.getParameter<double>("etMax");
00097 int etBin = parameters_.getParameter<int>("etBin");
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
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 }
00178
00179
00180 }
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
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
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
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
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
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
00261 vector<int> Keys;
00262 for(uint filterIndex=0;filterIndex<triggerEvent.sizeFilters();++filterIndex){
00263 string label = triggerEvent.filterTag(filterIndex).label();
00264 if(label.find( "Photon" ) != string::npos ) {
00265 for(uint filterKeyIndex=0;filterKeyIndex<triggerEvent.filterKeys(filterIndex).size();++filterKeyIndex){
00266 Keys.push_back(triggerEvent.filterKeys(filterIndex)[filterKeyIndex]);
00267 }
00268 }
00269 }
00270
00271
00272
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 }
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
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
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
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