Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:27:06

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