CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/PhysicsTools/PatExamples/plugins/PatTriggerTagAndProbe.cc

Go to the documentation of this file.
00001 #include "TMath.h"
00002 #include "FWCore/ServiceRegistry/interface/Service.h"
00003 #include "CommonTools/UtilAlgos/interface/TFileService.h"
00004 #include "PhysicsTools/PatUtils/interface/TriggerHelper.h"
00005 #include "PhysicsTools/PatExamples/plugins/PatTriggerTagAndProbe.h"
00006 
00007 
00008 PatTriggerTagAndProbe::PatTriggerTagAndProbe( const edm::ParameterSet & iConfig ) :
00009   // pat::TriggerEvent
00010   triggerEvent_( iConfig.getParameter< edm::InputTag >( "triggerEvent" ) ),
00011   // muon input collection
00012   muons_( iConfig.getParameter< edm::InputTag >( "muons" ) ),
00013   // muon match objects
00014   muonMatch_( iConfig.getParameter< std::string >( "muonMatch" ) ),
00015   // histogram management
00016   histos1D_()
00017 {
00018 }
00019 
00020 PatTriggerTagAndProbe::~PatTriggerTagAndProbe()
00021 {
00022 }
00023 
00024 void PatTriggerTagAndProbe::beginJob()
00025 {
00026   edm::Service< TFileService > fileService;
00027 
00028   // mass plot around Z peak
00029   histos1D_[ "mass"    ] = fileService->make< TH1D >( "mass"  , "Mass_{Z} (GeV)",  90,   30., 120.);
00030   // pt for test candidate
00031   histos1D_[ "testPt"  ] = fileService->make< TH1D >( "testPt"  , "p_{T} (GeV)" , 100,    0., 100.);
00032   // pt for probe candidate
00033   histos1D_[ "probePt" ] = fileService->make< TH1D >( "probePt" , "p_{T} (GeV)" , 100,    0., 100.);
00034   // eta for test candidate
00035   histos1D_[ "testEta" ] = fileService->make< TH1D >( "testEta" , "#eta"        ,  48,  -2.4,  2.4);
00036   // eta for probe candidate
00037   histos1D_[ "probeEta"] = fileService->make< TH1D >( "probeEta", "#eta"        ,  48,  -2.4,  2.4);
00038 }
00039 
00040 void PatTriggerTagAndProbe::analyze( const edm::Event & iEvent, const edm::EventSetup & iSetup )
00041 {
00042   // trigger event
00043   edm::Handle< pat::TriggerEvent > triggerEvent;
00044   iEvent.getByLabel( triggerEvent_, triggerEvent );
00045   // pat candidate collection
00046   edm::Handle< pat::MuonCollection > muons;
00047   iEvent.getByLabel( muons_, muons );
00048 
00049   // pat trigger helper to recieve for trigger
00050   // matching information
00051   const pat::helper::TriggerMatchHelper matchHelper;
00052 
00053   // ask for trigger accept of HLT_Mu9; otherwise we don't even start
00054   if(!(triggerEvent->path("HLT_IsoMu17_v5")->wasRun() && triggerEvent->path("HLT_IsoMu17_v5")->wasAccept())){
00055     return;
00056   }
00057 
00058   // loop over muon references for the tag muon
00059   for( size_t idxTag=0; idxTag<muons->size(); ++idxTag){
00060     const pat::TriggerObjectRef trigRefTag( matchHelper.triggerMatchObject( muons, idxTag, muonMatch_, iEvent, *triggerEvent ) );
00061     if( trigRefTag.isAvailable() ){
00062       // loop over muon references for the probe/test muon
00063       for( size_t idxProbe=0; idxProbe<muons->size() && idxProbe!=idxTag; ++idxProbe){
00064         histos1D_[ "mass" ]->Fill( (muons->at(idxTag).p4()+muons->at(idxProbe).p4()).mass() );
00065         if(fabs((muons->at(idxTag).p4()+muons->at(idxProbe).p4()).mass()-90)<5){
00066           const pat::TriggerObjectRef trigRefProbe( matchHelper.triggerMatchObject( muons, idxProbe, muonMatch_, iEvent, *triggerEvent ) );
00067           histos1D_[ "probePt"  ]->Fill( muons->at(idxProbe).pt () );
00068           histos1D_[ "probeEta" ]->Fill( muons->at(idxProbe).eta() );
00069           if( trigRefProbe.isAvailable() ){
00070             histos1D_[ "testPt" ]->Fill( muons->at(idxProbe).pt () );
00071             histos1D_[ "testEta"]->Fill( muons->at(idxProbe).eta() );
00072           }
00073         }
00074       }
00075     }
00076   }
00077 }
00078 
00079 void PatTriggerTagAndProbe::endJob()
00080 {
00081   // normalize the entries of the histograms
00082   histos1D_[ "testPt"  ]->Divide(histos1D_  [ "probePt"  ]);
00083   setErrors(*histos1D_["testPt" ],*histos1D_[ "probePt"  ]);
00084   histos1D_[ "testEta" ]->Divide(histos1D_  [ "probeEta" ]);
00085   setErrors(*histos1D_["testEta"],*histos1D_[ "probeEta" ]);
00086 }
00087 
00088 void PatTriggerTagAndProbe::setErrors(TH1D& h, const TH1D& ref)
00089 {
00090   for(int bin=0; bin<h.GetNbinsX(); ++bin){
00091     if(ref.GetBinContent(bin+1)>0){
00092       h.SetBinError(bin+1, sqrt((h.GetBinContent(bin+1)*(1.-h.GetBinContent(bin+1)))/ref.GetBinContent(bin+1)));
00093     } else{ h.SetBinError(bin+1, 0.); }
00094   }
00095 }
00096 
00097 
00098 #include "FWCore/Framework/interface/MakerMacros.h"
00099 DEFINE_FWK_MODULE( PatTriggerTagAndProbe );