CMS 3D CMS Logo

MuonAnalyzer.cc
Go to the documentation of this file.
1 
8 
9 // Collaborating Class Header
16 
18 
19 #include "TH1I.h"
20 #include "TH1F.h"
21 #include "TH2F.h"
22 
23 using namespace std;
24 using namespace edm;
25 
28  theMuonToken = consumes<pat::MuonCollection>(pset.getParameter<InputTag>("MuonCollection"));
29 }
30 
33 
35  // Book histograms
37  hPtRec = fileService->make<TH1F>("pT", "p_{T}^{rec}", 250, 0, 120);
38  hPtReso = fileService->make<TH2F>("pT_Reso", "(p_{T}^{rec}-p_{T}^{sim})/p_{T}^{sim}", 250, 0, 120, 100, -0.2, 0.2);
39  hNMuons = fileService->make<TH1I>("NMuons", "Number of muons per event", 20, 0, 20);
40 
41  hEHcal = fileService->make<TH1F>("EHCal", "Energy deposit in HCAL", 100, 0, 10);
42 
43  // ID
44  hMuonType = fileService->make<TH1I>("MuonType", "Type of Muons", 5, 1, 6);
45  hPtSTATKDiff = fileService->make<TH1F>("DiffPt_STA_TK", "p^{TK}_{T}-p^{STA}_T", 200, -50, 50);
46  hMuCaloCompatibility = fileService->make<TH1F>("CaloCompatibility", "Muon HP using Calorimeters only", 100, 0, 1);
47  hMuSegCompatibility = fileService->make<TH1F>("SegmentCompatibility", "Muon HP using segments only", 100, 0, 1);
48  hChamberMatched = fileService->make<TH1I>("NumMatchedChamber", "Number of matched chambers", 7, 0, 7);
49  hMuIdAlgo = fileService->make<TH1I>("MuonIDSelectors", "Results of muon id selectors", 13, 0, 13);
50 
51  // Isolation
52  hMuIso03SumPt = fileService->make<TH1F>("MuIso03SumPt", "Isolation #Delta(R)=0.3: SumPt", 200, 0, 10);
53  hMuIso03CaloComb =
54  fileService->make<TH1F>("MuIso03CaloComb", "Isolation #Delta(R)=0.3: 1.2*ECAL+0.8HCAL", 200, 0, 10);
55 
56  // 4Mu invariant mass
57  h4MuInvMass = fileService->make<TH1F>("InvMass4MuSystem", "Invariant mass of the 4 muons system", 200, 0, 500);
58 }
59 
61 
62 void ExampleMuonAnalyzer::analyze(const Event& event, const EventSetup& eventSetup) {
63  // Get the Muon collection
65  event.getByToken(theMuonToken, muons);
66 
67  // How many muons in the event?
68  hNMuons->Fill(muons->size());
69 
71 
72  // Let's look inside the muon collection.
73  for (pat::MuonCollection::const_iterator muon = muons->begin(); muon != muons->end(); ++muon) {
74  // pT spectra of muons
75  hPtRec->Fill(muon->pt());
76 
77  // what is the resolution in pt? Easy! We have the association with generated information
78  // cout<<muon->pt()<<" "<<muon->genParticle()->pt()<<endl;
79  if (muon->genLepton() != nullptr) {
80  double reso = (muon->pt() - muon->genLepton()->pt()) / muon->genLepton()->pt();
81  hPtReso->Fill(muon->genLepton()->pt(), reso);
82  }
83 
84  // What is the energy deposit in HCal?
85  if (muon->isEnergyValid())
86  hEHcal->Fill(muon->calEnergy().had);
87 
88  // Which type of muons in the collection?
89  if (muon->isStandAloneMuon())
90  if (muon->isGlobalMuon())
91  if (muon->isTrackerMuon())
92  hMuonType->Fill(1); // STA + GLB + TM
93  else
94  hMuonType->Fill(2); // STA + GLB
95  else if (muon->isTrackerMuon())
96  hMuonType->Fill(3); // STA + TM
97  else
98  hMuonType->Fill(5); // STA
99  else if (muon->isTrackerMuon())
100  hMuonType->Fill(4); // TM
101 
102  // ...mmm I want to study the relative resolution of the STA track with respect to the Tracker track.
103  // or I want to look at a track stab
104  if (muon->isGlobalMuon()) {
105  double diff = muon->innerTrack()->pt() - muon->standAloneMuon()->pt();
106  hPtSTATKDiff->Fill(diff);
107  }
108 
109  // Muon ID quantities
110 
111  // Muon in CMS are usually MIP. What is the compatibility of a muon HP using only claorimeters?
112  if (muon->isCaloCompatibilityValid())
113  hMuCaloCompatibility->Fill(muon->caloCompatibility());
114 
115  // The muon system can also be used just as only for ID. What is the compatibility of a muon HP using only calorimeters?
116  hMuSegCompatibility->Fill(muon::segmentCompatibility(*muon));
117 
118  // How many chambers have been associated to a muon track?
119  hChamberMatched->Fill(muon->numberOfChambers());
120  // If you look at MuonSegmentMatcher class you will see a lot of interesting quantities to look at!
121  // you can get the list of matched info using matches()
122 
123  // Muon ID selection. As described in AN-2008/098
124  if (muon::isGoodMuon(*muon, muon::All)) // dummy options - always true
125  hMuIdAlgo->Fill(0);
126  if (muon::isGoodMuon(*muon, muon::AllStandAloneMuons)) // checks isStandAloneMuon flag
127  hMuIdAlgo->Fill(1);
128  if (muon::isGoodMuon(*muon, muon::AllTrackerMuons)) // checks isTrackerMuon flag
129  hMuIdAlgo->Fill(2);
130  if (muon::isGoodMuon(*muon, muon::TrackerMuonArbitrated)) // resolve ambiguity of sharing segments
131  hMuIdAlgo->Fill(3);
132  if (muon::isGoodMuon(*muon, muon::AllArbitrated)) // all muons with the tracker muon arbitrated
133  hMuIdAlgo->Fill(4);
134  if (muon::isGoodMuon(*muon, muon::GlobalMuonPromptTight)) // global muons with tighter fit requirements
135  hMuIdAlgo->Fill(5);
136  if (muon::isGoodMuon(*muon, muon::TMLastStationLoose)) // penetration depth loose selector
137  hMuIdAlgo->Fill(6);
138  if (muon::isGoodMuon(*muon, muon::TMLastStationTight)) // penetration depth tight selector
139  hMuIdAlgo->Fill(7);
140  if (muon::isGoodMuon(*muon, muon::TM2DCompatibilityLoose)) // likelihood based loose selector
141  hMuIdAlgo->Fill(8);
142  if (muon::isGoodMuon(*muon, muon::TM2DCompatibilityTight)) // likelihood based tight selector
143  hMuIdAlgo->Fill(9);
144  if (muon::isGoodMuon(*muon, muon::TMOneStationLoose)) // require one well matched segment
145  hMuIdAlgo->Fill(10);
146  if (muon::isGoodMuon(*muon, muon::TMOneStationTight)) // require one well matched segment
147  hMuIdAlgo->Fill(11);
148  if (muon::isGoodMuon(*muon,
149  muon::TMLastStationOptimizedLowPtLoose)) // combination of TMLastStation and TMOneStation
150  hMuIdAlgo->Fill(12);
151  if (muon::isGoodMuon(*muon,
152  muon::TMLastStationOptimizedLowPtTight)) // combination of TMLastStation and TMOneStation
153  hMuIdAlgo->Fill(13);
154 
155  // Isolation variables. There are many type of isolation. You can even build your own combining the output of
156  // muon->isolationR03(). E.g.: 1.2*muon->isolationR03().emEt + 0.8*muon->isolationR03().hadEt
157  // *** WARNING *** it is just an EXAMPLE!
158  if (muon->isIsolationValid()) {
159  hMuIso03CaloComb->Fill(1.2 * muon->isolationR03().emEt + 0.8 * muon->isolationR03().hadEt);
160  hMuIso03SumPt->Fill(muon->isolationR03().sumPt);
161  }
162 
163  // OK, let see if we understood everything.
164  // Suppose we are searching for H->ZZ->4mu.
165  // In mean the 4 muons have/are:
166  // high pt (but 1 out of 4 can be at quite low pt)
167  // isolated
168  // so, we can make some requirements
169  if (muon->isolationR03().sumPt < 0.2) {
170  if (muon->isGlobalMuon() || muon::isGoodMuon(*muon, muon::TM2DCompatibilityLoose) ||
172  selectedMuons.push_back(*muon);
173  }
174  }
175 
177  if (selectedMuons.size() == 4) {
179  for (pat::MuonCollection::const_iterator muon = selectedMuons.begin(); muon != selectedMuons.end(); ++muon) {
180  p4CM = p4CM + muon->p4();
181  }
182  h4MuInvMass->Fill(p4CM.mass());
183  }
184 }
ExampleMuonAnalyzer::~ExampleMuonAnalyzer
~ExampleMuonAnalyzer() override
Destructor.
Definition: MuonAnalyzer.cc:32
change_name.diff
diff
Definition: change_name.py:13
PDWG_BPHSkim_cff.muons
muons
Definition: PDWG_BPHSkim_cff.py:47
ESHandle.h
muon
Definition: MuonCocktails.h:17
fileService
edm::Service< TFileService > fileService
Definition: HSCPValidator.cc:91
muon::segmentCompatibility
float segmentCompatibility(const reco::Muon &muon, reco::Muon::ArbitrationType arbitrationType=reco::Muon::SegmentAndTrackArbitration)
Definition: MuonSelectors.cc:61
edm
HLT enums.
Definition: AlignableModifier.h:19
METSignificanceObjects_cfi.selectedMuons
selectedMuons
======================================
Definition: METSignificanceObjects_cfi.py:7
muon::GlobalMuonPromptTight
Definition: MuonSelectors.h:25
muon::TMLastStationTight
Definition: MuonSelectors.h:27
muon::TrackerMuonArbitrated
Definition: MuonSelectors.h:23
edm::Handle
Definition: AssociativeIterator.h:50
ExampleMuonAnalyzer::ExampleMuonAnalyzer
ExampleMuonAnalyzer(const edm::ParameterSet &pset)
Constructor.
Definition: MuonAnalyzer.cc:27
ExampleMuonAnalyzer
Definition: MuonAnalyzer.h:25
MakerMacros.h
ExampleMuonAnalyzer::endJob
void endJob() override
Definition: MuonAnalyzer.cc:60
muon::isGoodMuon
bool isGoodMuon(const reco::Muon &muon, SelectionType type, reco::Muon::ArbitrationType arbitrationType=reco::Muon::SegmentAndTrackArbitration)
main GoodMuon wrapper call
Definition: MuonSelectors.cc:649
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
HLT_FULL_cff.muon
muon
Definition: HLT_FULL_cff.py:11710
Service.h
muon::TMLastStationOptimizedLowPtLoose
Definition: MuonSelectors.h:32
pat::MuonCollection
std::vector< Muon > MuonCollection
Definition: Muon.h:35
TFileService.h
muon::TMOneStationTight
Definition: MuonSelectors.h:31
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
LorentzVector.h
edm::Service< TFileService >
edm::EventSetup
Definition: EventSetup.h:57
muon::TMOneStationLoose
Definition: MuonSelectors.h:30
muon::AllArbitrated
Definition: MuonSelectors.h:24
muon::TM2DCompatibilityTight
Definition: MuonSelectors.h:29
std
Definition: JetResolutionObject.h:76
muon::All
Definition: MuonSelectors.h:19
ExampleMuonAnalyzer::beginJob
void beginJob() override
Definition: MuonAnalyzer.cc:34
Frameworkfwd.h
muon::TMLastStationLoose
Definition: MuonSelectors.h:26
muon::TMLastStationOptimizedLowPtTight
Definition: MuonSelectors.h:33
muon::AllStandAloneMuons
Definition: MuonSelectors.h:21
MuonAnalyzer.h
reco::Candidate::LorentzVector
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:36
muon::AllTrackerMuons
Definition: MuonSelectors.h:22
event
Definition: event.py:1
edm::Event
Definition: Event.h:73
edm::InputTag
Definition: InputTag.h:15
TFileService::make
T * make(const Args &... args) const
make new ROOT object
Definition: TFileService.h:64
ExampleMuonAnalyzer::analyze
void analyze(const edm::Event &event, const edm::EventSetup &eventSetup) override
Definition: MuonAnalyzer.cc:62
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
muon::TM2DCompatibilityLoose
Definition: MuonSelectors.h:28