CMS 3D CMS Logo

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