CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch1/src/ElectroWeakAnalysis/ZMuMu/plugins/ZMuMuAnalyzer.cc

Go to the documentation of this file.
00001 /* \class ZMuMuAnalyzer
00002  *
00003  * Z->mu+m- standard analysis for cross section 
00004  * measurements. Take as input the output of the
00005  * standard EWK skim: zToMuMu
00006  * 
00007  * Produces mass spectra and other histograms for
00008  * the samples in input:
00009  *
00010  *  + Z -> mu+mu-, both muons are "global" muons
00011  *  + Z -> mu+mu-, one muons is "global" muons, one unmatched tracks
00012  *  + Z -> mu+mu-, one muons is "global" muons, one unmatched stand-alone muon
00013  * 
00014  *
00015  * \author Michele de Gruttola, INFN Naples
00016  *
00017  * \id $Id: ZMuMuAnalyzer.cc,v 1.7 2010/02/19 02:46:28 wmtan Exp $
00018  *
00019  */
00020 #include "FWCore/Framework/interface/EDAnalyzer.h"
00021 #include "FWCore/Utilities/interface/InputTag.h"
00022 #include "FWCore/Framework/interface/Event.h"
00023 #include "DataFormats/Common/interface/Handle.h"
00024 #include "DataFormats/Candidate/interface/OverlapChecker.h"
00025 #include "DataFormats/Candidate/interface/Particle.h"
00026 #include "DataFormats/Candidate/interface/Candidate.h"
00027 #include "DataFormats/Candidate/interface/CandMatchMap.h"
00028 #include "FWCore/ServiceRegistry/interface/Service.h"
00029 #include "CommonTools/UtilAlgos/interface/TFileService.h"
00030 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00031 #include "DataFormats/Common/interface/AssociationVector.h"
00032 #include "TH1.h"
00033 #include <iostream>
00034 #include <iterator>
00035 using namespace edm;
00036 using namespace std;
00037 using namespace reco;
00038 
00039 typedef edm::AssociationVector<reco::CandidateRefProd, std::vector<double> > IsolationCollection;
00040 
00041 class ZMuMuAnalyzer : public edm::EDAnalyzer {
00042 public:
00043   ZMuMuAnalyzer(const edm::ParameterSet& pset);
00044 private:
00045   virtual void analyze(const edm::Event& event, const edm::EventSetup& setup);
00046   virtual void endJob();
00047   
00048   OverlapChecker overlap_;
00049   InputTag zMuMu_;
00050   InputTag zMuTrack_;
00051   InputTag zMuStandAlone_;
00052   InputTag  muIso_, trackIso_, standAloneIso_;
00053   InputTag  zMuMuMap_ ,zMuTrackMap_, zMuStandAloneMap_;
00054   double isocut_, etacut_, ptcut_,ptSTAcut_,  minZmass_, maxZmass_;
00055   TH1D * h_zMuMu_mass_, * h_zMuSingleTrack_mass_, * h_zMuSingleStandAlone_mass_,* h_zMuSingleStandAloneOverlap_mass_,
00056     * h_zMuMuMatched_mass_,
00057  *h_zMuSingleTrackMatched_mass_,
00058     * h_zMuSingleStandAloneMatched_mass_, 
00059     * h_zMuSingleStandAloneOverlapMatched_mass_;
00060 };
00061 
00062 ZMuMuAnalyzer::ZMuMuAnalyzer(const edm::ParameterSet& pset) : 
00063   zMuMu_( pset.getParameter<InputTag>( "zMuMu" ) ),
00064   zMuTrack_( pset.getParameter<InputTag>( "zMuTrack" ) ),
00065   zMuStandAlone_( pset.getParameter<InputTag>( "zMuStandAlone" ) ),
00066   muIso_( pset.getParameter<InputTag>( "muIso" ) ),
00067   trackIso_( pset.getParameter<InputTag>( "trackIso" ) ),
00068   standAloneIso_( pset.getParameter<InputTag>( "standAloneIso" ) ),
00069   zMuMuMap_( pset.getParameter<InputTag>( "zMuMuMap" ) ),
00070   zMuTrackMap_( pset.getParameter<InputTag>( "zMuTrackMap" ) ),
00071   zMuStandAloneMap_( pset.getParameter<InputTag>( "zMuStandAloneMap" ) ),
00072   isocut_( pset.getParameter<double>( "isocut" ) ),
00073   etacut_( pset.getParameter<double>( "etacut" ) ),
00074   ptcut_( pset.getParameter<double>( "ptcut" ) ),
00075   ptSTAcut_( pset.getParameter<double>( "ptSTAcut" ) ),
00076   
00077   minZmass_( pset.getParameter<double>( "minZmass" )),
00078   maxZmass_( pset.getParameter<double>( "maxZmass" )) {
00079   
00080   Service<TFileService> fs;
00081   h_zMuMu_mass_ = fs->make<TH1D>( "ZMuMumass", "ZMuMu mass(GeV)", 200,  0., 200. );
00082   h_zMuSingleTrack_mass_ = fs->make<TH1D>( "ZMuSingleTrackmass", "ZMuSingleTrack mass(GeV)", 100,  0., 200. );
00083   h_zMuSingleStandAlone_mass_ = fs->make<TH1D>( "ZMuSingleStandAlonemass", "ZMuSingleStandAlone mass(GeV)", 50,  0., 200. );
00084   h_zMuSingleStandAloneOverlap_mass_ = fs->make<TH1D>( "ZMuSingleStandAloneOverlapmass", "ZMuSingleStandAloneOverlap  mass(GeV)", 50,  0., 200. );
00085   
00086   
00087   h_zMuMuMatched_mass_ = fs->make<TH1D>( "ZMuMuMatchedmass", "ZMuMu Matched  mass(GeV)", 200,  0., 200. );
00088   h_zMuSingleTrackMatched_mass_ = fs->make<TH1D>( "ZMuSingleTrackmassMatched", "ZMuSingleTrackMatched mass(GeV)", 100,  0., 200. );
00089   h_zMuSingleStandAloneMatched_mass_ = fs->make<TH1D>( "ZMuSingleStandAlonemassMatched", "ZMuSingleStandAloneMatched mass(GeV)", 50,  0., 200. );
00090   h_zMuSingleStandAloneOverlapMatched_mass_ = fs->make<TH1D>( "ZMuSingleStandAloneOverlapmassMatched", "ZMuSingleStandAloneMatched Overlap  mass(GeV)", 50,  0., 200. );
00091 }
00092 
00093 void ZMuMuAnalyzer::analyze(const edm::Event& event, const edm::EventSetup& setup) {
00094   Handle<CandidateCollection> zMuMu;
00095   event.getByLabel(zMuMu_, zMuMu);
00096   Handle<CandidateCollection> zMuTrack;
00097   event.getByLabel( zMuTrack_, zMuTrack );
00098   Handle<CandidateCollection> zMuStandAlone;
00099   event.getByLabel( zMuStandAlone_, zMuStandAlone );  
00100 
00101   unsigned int nZMuMu = zMuMu->size();
00102   unsigned int nZTrackMu = zMuTrack->size();
00103   unsigned int nZStandAloneMu = zMuStandAlone->size();
00104   static const double zMass = 91.1876; // PDG Z mass
00105 
00106   //  cout << "nZMuMu = " << nZMuMu << endl;
00107   //  cout << "nZTrackMu = " << nZTrackMu << endl;
00108   //  cout << "nZStandAloneMu = " << nZStandAloneMu << endl;
00109  
00110   Handle<CandMatchMap> zMuMuMap;
00111   if( nZMuMu > 0 ) {
00112     event.getByLabel(zMuMuMap_, zMuMuMap);
00113   }
00114 
00115   Handle<CandMatchMap> zMuTrackMap;
00116   if( nZTrackMu > 0 ) {
00117     event.getByLabel( zMuTrackMap_, zMuTrackMap );
00118   }
00119 
00120   Handle<CandMatchMap> zMuStandAloneMap;
00121   if( nZStandAloneMu > 0 ) {
00122     event.getByLabel( zMuStandAloneMap_, zMuStandAloneMap );  
00123   }    
00124 
00125   Handle<IsolationCollection> muIso;
00126   event.getByLabel(muIso_, muIso);
00127   ProductID muIsoId = muIso->keyProduct().id();
00128   Handle<IsolationCollection> trackIso;
00129   event.getByLabel(trackIso_, trackIso);
00130   ProductID trackIsoId = trackIso->keyProduct().id();
00131   
00132   Handle<IsolationCollection> standAloneIso;
00133   event.getByLabel(standAloneIso_, standAloneIso);
00134   ProductID standAloneIsoId = standAloneIso->keyProduct().id();
00135   
00136   if (nZMuMu > 0) {
00137     double mass = 1000000.;
00138     for( unsigned int i = 0; i < nZMuMu; i++ ) {
00139       const Candidate & zmmCand = (*zMuMu)[ i ];
00140       CandidateRef CandRef(zMuMu,i);
00141       CandidateRef lep1 = zmmCand.daughter( 0 )->masterClone().castTo<CandidateRef>();
00142       CandidateRef lep2 = zmmCand.daughter( 1 )->masterClone().castTo<CandidateRef>();
00143       
00144       const  double iso1 = muIso->value( lep1.key() );  
00145       const  double iso2 = muIso->value( lep2.key() );  
00146       
00147       double m = zmmCand.mass();
00148       if (lep1->pt()>ptcut_ && lep2->pt()>ptcut_ &&    
00149           fabs(lep1->eta())<etacut_ && fabs(lep2->eta())<etacut_ &&
00150           m>minZmass_ && m<maxZmass_ && iso1 < isocut_ && iso2 <isocut_) {
00151         if ( fabs( mass - zMass ) > fabs( m - zMass ) ) {
00152           mass = m;
00153         }
00154         
00155         h_zMuMu_mass_->Fill( mass );      
00156         CandMatchMap::const_iterator m0 = zMuMuMap->find(CandRef);
00157         if( m0 != zMuMuMap->end()) {
00158             h_zMuMuMatched_mass_->Fill( mass );
00159         }
00160       }
00161     }
00162   }
00163   
00164   //ZmuSingleTRack
00165   if (nZMuMu ==0 && nZTrackMu>0) {
00166     for( unsigned int j = 0; j < nZTrackMu; j++ ) {
00167       const Candidate & ztmCand = (*zMuTrack)[ j ];
00168       CandidateRef CandRef(zMuTrack,j);
00169       CandidateRef lep1 = ztmCand.daughter( 0 )->masterClone().castTo<CandidateRef>();
00170       CandidateRef lep2 = ztmCand.daughter( 1 )->masterClone().castTo<CandidateRef>();
00171       
00172       ProductID id1 = lep1.id();
00173       ProductID id2 = lep2.id();
00174       double iso1 = -1;
00175       double iso2 = -1;
00176       
00177       if( id1 == muIsoId ) 
00178         iso1 = muIso->value( lep1.key() );      
00179       else if ( id1 == trackIsoId )
00180         iso1 = trackIso->value( lep1.key() );   
00181       
00182       if( id2 == muIsoId ) 
00183               iso2 = muIso->value( lep2.key() );        
00184       else if ( id2 == trackIsoId )
00185         iso2 = trackIso->value( lep2.key() );   
00186  
00187       double mt = ztmCand.mass();
00188       if (lep1->pt()>ptcut_ && lep2->pt()>ptcut_ &&    
00189           fabs(lep1->eta())<etacut_ && fabs(lep2->eta())<etacut_ &&
00190           mt>minZmass_ && mt<maxZmass_ && iso1<isocut_ && iso2 <isocut_) {
00191         h_zMuSingleTrack_mass_->Fill( mt );
00192         CandMatchMap::const_iterator m0 = zMuTrackMap->find(CandRef);
00193         if( m0 != zMuTrackMap->end()) {
00194           h_zMuSingleTrackMatched_mass_->Fill( mt );
00195         }
00196       }
00197     }
00198   }   
00199   
00200   //ZmuSingleStandAlone
00201   if (nZMuMu ==0 && nZStandAloneMu>0) {
00202     //      unsigned int index = 1000;
00203     for( unsigned int j = 0; j < nZStandAloneMu; j++ ) {
00204       const Candidate & zsmCand = (*zMuStandAlone)[ j ];
00205       CandidateRef CandRef(zMuStandAlone,j);
00206       CandidateRef lep1 = zsmCand.daughter( 0 )->masterClone().castTo<CandidateRef>();
00207       CandidateRef lep2 = zsmCand.daughter( 1 )->masterClone().castTo<CandidateRef>();
00208       
00209       ProductID id1 = lep1.id();
00210       ProductID id2 = lep2.id();
00211       double iso1 = -1;
00212       double iso2 = -1;
00213       
00214       if( id1 == muIsoId ) 
00215         iso1 = muIso->value( lep1.key() );      
00216       else if ( id1 == standAloneIsoId )
00217         iso1 = standAloneIso->value( lep1.key() );      
00218       
00219       if( id2 == muIsoId ) 
00220         iso2 = muIso->value( lep2.key() );      
00221       else if ( id2 == standAloneIsoId )
00222         iso2 = standAloneIso->value( lep2.key() );      
00223       
00224       double ms = zsmCand.mass();
00225       if (lep1->pt()>ptSTAcut_ && lep2->pt()>ptSTAcut_ &&    
00226           fabs(lep1->eta())<etacut_ && fabs(lep2->eta())<etacut_ &&
00227           ms>minZmass_ && ms<maxZmass_ && iso1<isocut_ && iso2 <isocut_) {
00228         h_zMuSingleStandAlone_mass_->Fill( ms );
00229         CandMatchMap::const_iterator m0 = zMuStandAloneMap->find(CandRef);
00230         if( m0 != zMuStandAloneMap->end()) {
00231           h_zMuSingleStandAloneMatched_mass_->Fill( ms );
00232         }
00233         
00234         bool noOverlap = true;
00235         for( unsigned int j = 0; j < zMuTrack->size(); j++ ) {
00236           const Candidate & ztmCand = (*zMuTrack)[ j ];
00237           CandidateRef CandReft(zMuTrack,j);
00238           
00239           CandidateRef lep1 = ztmCand.daughter( 0 )->masterClone().castTo<CandidateRef>();
00240           CandidateRef lep2 = ztmCand.daughter( 1 )->masterClone().castTo<CandidateRef>();
00241           
00242           ProductID id1 = lep1.id();
00243           ProductID id2 = lep2.id();
00244           double iso1 = -1;
00245           double iso2 = -1;
00246           
00247           if( id1 == muIsoId ) 
00248             iso1 = muIso->value( lep1.key() );  
00249           else if ( id1 == trackIsoId )
00250             iso1 = trackIso->value( lep1.key() );       
00251           
00252           if( id2 == muIsoId ) 
00253             iso2 = muIso->value( lep2.key() );  
00254           else if ( id2 == trackIsoId )
00255             iso2 = trackIso->value( lep2.key() );       
00256           
00257           double mt = ztmCand.mass();
00258           if (lep1->pt()>ptcut_ && lep2->pt()>ptcut_ &&    
00259               fabs(lep1->eta())<etacut_ && fabs(lep2->eta())<etacut_ &&
00260               mt>minZmass_ && mt<maxZmass_ && iso1<isocut_ && iso2 <isocut_) {
00261             
00262             if ( overlap_( ztmCand, zsmCand ) ) {
00263               noOverlap = false; 
00264               break;
00265             }
00266             if (!noOverlap ) {
00267               h_zMuSingleStandAloneOverlap_mass_->Fill( ms ); 
00268               CandMatchMap::const_iterator m1 = zMuTrackMap->find(CandReft);
00269               CandMatchMap::const_iterator m2 = zMuStandAloneMap->find(CandRef);
00270               
00271               if( m1 != zMuTrackMap->end()  && m2 != zMuStandAloneMap->end()  ) {
00272                 h_zMuSingleStandAloneOverlapMatched_mass_->Fill( ms );
00273               }
00274             }
00275           }         
00276         }
00277       }
00278     }
00279   }
00280 }  
00281    
00282 void ZMuMuAnalyzer::endJob() {
00283   double Nzmm = h_zMuMu_mass_->GetEntries() ;
00284   double Nzsm = h_zMuSingleStandAlone_mass_->GetEntries()  ;
00285   double Nzsnom = h_zMuSingleStandAloneOverlap_mass_->GetEntries()  ;
00286   double Nztm = h_zMuSingleTrack_mass_->GetEntries();
00287   
00288   double NzmmMatch = h_zMuMuMatched_mass_->GetEntries() ;
00289   double NzsmMatch = h_zMuSingleStandAloneMatched_mass_->GetEntries()  ;
00290   double NzsnomMatch = h_zMuSingleStandAloneOverlapMatched_mass_->GetEntries()  ;
00291   double NztmMatch = h_zMuSingleTrackMatched_mass_->GetEntries();
00292 
00293   cout<<"-- N SingleTrackMu = "<<Nztm<<endl;
00294   cout<<"-----N SinglStandAloneMu = "<<Nzsm<<endl;
00295   cout<<"-----N SingleStandAloneOverlapMu = "<<Nzsnom<<endl;
00296   cout<<"------- N MuMu = "<<Nzmm<<endl;
00297   
00298   cout<<"-- N SingleTrackMuMatched = "<<NztmMatch<<endl;
00299   cout<<"-----N SinglStandAloneMuMatched = "<<NzsmMatch<<endl;
00300   cout<<"-----N SingleStandAloneOverlapMuMatched  = "<<NzsnomMatch<<endl;
00301   cout<<"------- N MuMu Matched  = "<<NzmmMatch<<endl;
00302 }
00303   
00304 #include "FWCore/Framework/interface/MakerMacros.h"
00305 
00306 DEFINE_FWK_MODULE(ZMuMuAnalyzer);
00307