Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:26:02

0001 #include "FWCore/Framework/interface/EDAnalyzer.h"
0002 #include "FWCore/Framework/interface/Event.h"
0003 #include "FWCore/Framework/interface/EventSetup.h"
0004 #include "DataFormats/Common/interface/Handle.h"
0005 #include "DataFormats/Common/interface/View.h"
0006 #include "FWCore/Framework/interface/ESHandle.h"
0007 #include "FWCore/Framework/interface/MakerMacros.h"
0008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0010 
0011 #include "DataFormats/MuonReco/interface/Muon.h"
0012 #include "DataFormats/RecoCandidate/interface/IsoDeposit.h"
0013 #include "DataFormats/RecoCandidate/interface/IsoDepositFwd.h"
0014 #include "DataFormats/TrackReco/interface/Track.h"
0015 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0016 
0017 using namespace std;
0018 
0019 class IsolationExample : public edm::EDAnalyzer {
0020 public:
0021   IsolationExample(const edm::ParameterSet& conf);
0022   ~IsolationExample();
0023   virtual void beginJob();
0024   virtual void analyze(const edm::Event&, const edm::EventSetup&);
0025   virtual void endJob() {}
0026 
0027 private:
0028   edm::InputTag theMuonTag;
0029 
0030   edm::InputTag theTkDepMapTag;
0031   edm::InputTag theEcalDepMapTag;
0032   edm::InputTag theHcalDepMapTag;
0033 
0034   unsigned long theEventCount;
0035 };
0036 
0037 IsolationExample::IsolationExample(const edm::ParameterSet& conf)
0038     : theMuonTag(conf.getUntrackedParameter<edm::InputTag>("MuonCollection", edm::InputTag("muons"))),
0039       theTkDepMapTag(conf.getUntrackedParameter<edm::InputTag>("TkMapCollection", edm::InputTag("muIsoDepositTk"))),
0040       theEcalDepMapTag(conf.getUntrackedParameter<edm::InputTag>(
0041           "EcalMapCollection", edm::InputTag("muIsoDepositCalByAssociatorTowers:ecal"))),
0042       theHcalDepMapTag(conf.getUntrackedParameter<edm::InputTag>(
0043           "HcalMapCollection", edm::InputTag("muIsoDepositCalByAssociatorTowers:hcal"))),
0044       theEventCount(0) {
0045   LogDebug("IsolationExample") << " CTOR" << endl;
0046 }
0047 
0048 IsolationExample::~IsolationExample() {}
0049 
0050 void IsolationExample::beginJob() {}
0051 
0052 void IsolationExample::analyze(const edm::Event& ev, const edm::EventSetup& es) {
0053   static const std::string metname = "IsolationExample";
0054   LogDebug(metname) << " ============== analysis of event: " << ++theEventCount;
0055   edm::Handle<edm::View<reco::Muon> > trackCollection;
0056   ev.getByLabel(theMuonTag, trackCollection);
0057   const edm::View<reco::Muon>& muons = *trackCollection;
0058 
0059   //! take iso deposits for tracks (contains (eta,phi, pt) of tracks in R<X (1.0) around each muon)
0060   edm::Handle<reco::IsoDepositMap> tkMapH;
0061   ev.getByLabel(theTkDepMapTag, tkMapH);
0062 
0063   //! take iso deposits for ecal (contains (eta,phi, pt) of ecal in R<X (1.0) around each muon)
0064   edm::Handle<reco::IsoDepositMap> ecalMapH;
0065   ev.getByLabel(theEcalDepMapTag, ecalMapH);
0066 
0067   //! take iso deposits for hcal (contains (eta,phi, pt) of hcal in R<X (1.0) around each muon)
0068   edm::Handle<reco::IsoDepositMap> hcalMapH;
0069   ev.getByLabel(theHcalDepMapTag, hcalMapH);
0070   //! make a dummy veto list (used later)
0071   reco::IsoDeposit::Vetos dVetos;
0072 
0073   unsigned int nMuons = muons.size();
0074   for (unsigned int iMu = 0; iMu < nMuons; ++iMu) {
0075     LogTrace(metname) << "muon pt=" << muons[iMu].pt();
0076 
0077     //! let's look at sumPt in 5 different cones
0078     //! pick a deposit first (change to ..sit& when it works)
0079     const reco::IsoDeposit tkDep((*tkMapH)[muons.refAt(iMu)]);
0080     for (int i = 1; i < 6; ++i) {
0081       float coneSize = 0.1 * i;
0082       LogTrace(metname) << " iso sumPt in cone " << coneSize << " is " << tkDep.depositWithin(coneSize);
0083     }
0084     //! can count tracks too
0085     LogTrace(metname) << " N tracks in cone 0.5  is " << tkDep.depositAndCountWithin(0.5).second;
0086 
0087     //! now the same with pt>1.5 for each track
0088     LogTrace(metname) << " N tracks in cone 0.5  is " << tkDep.depositAndCountWithin(0.5, dVetos, 1.5).first;
0089 
0090     //! now the closest track
0091     LogTrace(metname) << " The closest track in dR is at " << tkDep.begin().dR() << " with pt "
0092                       << tkDep.begin().value();
0093   }
0094 }
0095 
0096 DEFINE_FWK_MODULE(IsolationExample);