CMS 3D CMS Logo

ZMuMuAnalyzer.cc
Go to the documentation of this file.
1 /* \class ZMuMuAnalyzer
2  *
3  * Z->mu+m- standard analysis for cross section
4  * measurements. Take as input the output of the
5  * standard EWK skim: zToMuMu
6  *
7  * Produces mass spectra and other histograms for
8  * the samples in input:
9  *
10  * + Z -> mu+mu-, both muons are "global" muons
11  * + Z -> mu+mu-, one muons is "global" muons, one unmatched tracks
12  * + Z -> mu+mu-, one muons is "global" muons, one unmatched stand-alone muon
13  *
14  *
15  * \author Michele de Gruttola, INFN Naples
16  *
17  *
18  */
31 #include "TH1.h"
32 #include <iostream>
33 #include <iterator>
34 using namespace edm;
35 using namespace std;
36 using namespace reco;
37 
39 
41 public:
43 
44 private:
45  void analyze(const edm::Event& event, const edm::EventSetup& setup) override;
46  void endJob() override;
47 
58  double isocut_, etacut_, ptcut_, ptSTAcut_, minZmass_, maxZmass_;
59  TH1D *h_zMuMu_mass_, *h_zMuSingleTrack_mass_, *h_zMuSingleStandAlone_mass_, *h_zMuSingleStandAloneOverlap_mass_,
60  *h_zMuMuMatched_mass_, *h_zMuSingleTrackMatched_mass_, *h_zMuSingleStandAloneMatched_mass_,
61  *h_zMuSingleStandAloneOverlapMatched_mass_;
62 };
63 
65  : zMuMuToken_(consumes<CandidateCollection>(pset.getParameter<InputTag>("zMuMu"))),
66  zMuTrackToken_(consumes<CandidateCollection>(pset.getParameter<InputTag>("zMuTrack"))),
67  zMuStandAloneToken_(consumes<CandidateCollection>(pset.getParameter<InputTag>("zMuStandAlone"))),
68  muIsoToken_(consumes<IsolationCollection>(pset.getParameter<InputTag>("muIso"))),
69  trackIsoToken_(consumes<IsolationCollection>(pset.getParameter<InputTag>("trackIso"))),
70  standAloneIsoToken_(consumes<IsolationCollection>(pset.getParameter<InputTag>("standAloneIso"))),
71  zMuMuMapToken_(mayConsume<CandMatchMap>(pset.getParameter<InputTag>("zMuMuMap"))),
72  zMuTrackMapToken_(mayConsume<CandMatchMap>(pset.getParameter<InputTag>("zMuTrackMap"))),
73  zMuStandAloneMapToken_(mayConsume<CandMatchMap>(pset.getParameter<InputTag>("zMuStandAloneMap"))),
74  isocut_(pset.getParameter<double>("isocut")),
75  etacut_(pset.getParameter<double>("etacut")),
76  ptcut_(pset.getParameter<double>("ptcut")),
77  ptSTAcut_(pset.getParameter<double>("ptSTAcut")),
78 
79  minZmass_(pset.getParameter<double>("minZmass")),
80  maxZmass_(pset.getParameter<double>("maxZmass")) {
82  h_zMuMu_mass_ = fs->make<TH1D>("ZMuMumass", "ZMuMu mass(GeV)", 200, 0., 200.);
83  h_zMuSingleTrack_mass_ = fs->make<TH1D>("ZMuSingleTrackmass", "ZMuSingleTrack mass(GeV)", 100, 0., 200.);
85  fs->make<TH1D>("ZMuSingleStandAlonemass", "ZMuSingleStandAlone mass(GeV)", 50, 0., 200.);
87  fs->make<TH1D>("ZMuSingleStandAloneOverlapmass", "ZMuSingleStandAloneOverlap mass(GeV)", 50, 0., 200.);
88 
89  h_zMuMuMatched_mass_ = fs->make<TH1D>("ZMuMuMatchedmass", "ZMuMu Matched mass(GeV)", 200, 0., 200.);
91  fs->make<TH1D>("ZMuSingleTrackmassMatched", "ZMuSingleTrackMatched mass(GeV)", 100, 0., 200.);
93  fs->make<TH1D>("ZMuSingleStandAlonemassMatched", "ZMuSingleStandAloneMatched mass(GeV)", 50, 0., 200.);
95  "ZMuSingleStandAloneOverlapmassMatched", "ZMuSingleStandAloneMatched Overlap mass(GeV)", 50, 0., 200.);
96 }
97 
100  event.getByToken(zMuMuToken_, zMuMu);
102  event.getByToken(zMuTrackToken_, zMuTrack);
103  Handle<CandidateCollection> zMuStandAlone;
104  event.getByToken(zMuStandAloneToken_, zMuStandAlone);
105 
106  unsigned int nZMuMu = zMuMu->size();
107  unsigned int nZTrackMu = zMuTrack->size();
108  unsigned int nZStandAloneMu = zMuStandAlone->size();
109  static const double zMass = 91.1876; // PDG Z mass
110 
111  // cout << "nZMuMu = " << nZMuMu << endl;
112  // cout << "nZTrackMu = " << nZTrackMu << endl;
113  // cout << "nZStandAloneMu = " << nZStandAloneMu << endl;
114 
115  Handle<CandMatchMap> zMuMuMap;
116  if (nZMuMu > 0) {
117  event.getByToken(zMuMuMapToken_, zMuMuMap);
118  }
119 
120  Handle<CandMatchMap> zMuTrackMap;
121  if (nZTrackMu > 0) {
122  event.getByToken(zMuTrackMapToken_, zMuTrackMap);
123  }
124 
125  Handle<CandMatchMap> zMuStandAloneMap;
126  if (nZStandAloneMu > 0) {
127  event.getByToken(zMuStandAloneMapToken_, zMuStandAloneMap);
128  }
129 
131  event.getByToken(muIsoToken_, muIso);
132  ProductID muIsoId = muIso->keyProduct().id();
134  event.getByToken(trackIsoToken_, trackIso);
135  ProductID trackIsoId = trackIso->keyProduct().id();
136 
137  Handle<IsolationCollection> standAloneIso;
138  event.getByToken(standAloneIsoToken_, standAloneIso);
139  ProductID standAloneIsoId = standAloneIso->keyProduct().id();
140 
141  if (nZMuMu > 0) {
142  double mass = 1000000.;
143  for (unsigned int i = 0; i < nZMuMu; i++) {
144  const Candidate& zmmCand = (*zMuMu)[i];
145  CandidateRef CandRef(zMuMu, i);
148 
149  const double iso1 = muIso->value(lep1.key());
150  const double iso2 = muIso->value(lep2.key());
151 
152  double m = zmmCand.mass();
153  if (lep1->pt() > ptcut_ && lep2->pt() > ptcut_ && fabs(lep1->eta()) < etacut_ && fabs(lep2->eta()) < etacut_ &&
154  m > minZmass_ && m < maxZmass_ && iso1 < isocut_ && iso2 < isocut_) {
155  if (fabs(mass - zMass) > fabs(m - zMass)) {
156  mass = m;
157  }
158 
159  h_zMuMu_mass_->Fill(mass);
160  CandMatchMap::const_iterator m0 = zMuMuMap->find(CandRef);
161  if (m0 != zMuMuMap->end()) {
162  h_zMuMuMatched_mass_->Fill(mass);
163  }
164  }
165  }
166  }
167 
168  //ZmuSingleTRack
169  if (nZMuMu == 0 && nZTrackMu > 0) {
170  for (unsigned int j = 0; j < nZTrackMu; j++) {
171  const Candidate& ztmCand = (*zMuTrack)[j];
172  CandidateRef CandRef(zMuTrack, j);
175 
176  ProductID id1 = lep1.id();
177  ProductID id2 = lep2.id();
178  double iso1 = -1;
179  double iso2 = -1;
180 
181  if (id1 == muIsoId)
182  iso1 = muIso->value(lep1.key());
183  else if (id1 == trackIsoId)
184  iso1 = trackIso->value(lep1.key());
185 
186  if (id2 == muIsoId)
187  iso2 = muIso->value(lep2.key());
188  else if (id2 == trackIsoId)
189  iso2 = trackIso->value(lep2.key());
190 
191  double mt = ztmCand.mass();
192  if (lep1->pt() > ptcut_ && lep2->pt() > ptcut_ && fabs(lep1->eta()) < etacut_ && fabs(lep2->eta()) < etacut_ &&
193  mt > minZmass_ && mt < maxZmass_ && iso1 < isocut_ && iso2 < isocut_) {
194  h_zMuSingleTrack_mass_->Fill(mt);
195  CandMatchMap::const_iterator m0 = zMuTrackMap->find(CandRef);
196  if (m0 != zMuTrackMap->end()) {
198  }
199  }
200  }
201  }
202 
203  //ZmuSingleStandAlone
204  if (nZMuMu == 0 && nZStandAloneMu > 0) {
205  // unsigned int index = 1000;
206  for (unsigned int j = 0; j < nZStandAloneMu; j++) {
207  const Candidate& zsmCand = (*zMuStandAlone)[j];
208  CandidateRef CandRef(zMuStandAlone, j);
211 
212  ProductID id1 = lep1.id();
213  ProductID id2 = lep2.id();
214  double iso1 = -1;
215  double iso2 = -1;
216 
217  if (id1 == muIsoId)
218  iso1 = muIso->value(lep1.key());
219  else if (id1 == standAloneIsoId)
220  iso1 = standAloneIso->value(lep1.key());
221 
222  if (id2 == muIsoId)
223  iso2 = muIso->value(lep2.key());
224  else if (id2 == standAloneIsoId)
225  iso2 = standAloneIso->value(lep2.key());
226 
227  double ms = zsmCand.mass();
228  if (lep1->pt() > ptSTAcut_ && lep2->pt() > ptSTAcut_ && fabs(lep1->eta()) < etacut_ &&
229  fabs(lep2->eta()) < etacut_ && ms > minZmass_ && ms < maxZmass_ && iso1 < isocut_ && iso2 < isocut_) {
230  h_zMuSingleStandAlone_mass_->Fill(ms);
231  CandMatchMap::const_iterator m0 = zMuStandAloneMap->find(CandRef);
232  if (m0 != zMuStandAloneMap->end()) {
234  }
235 
236  bool noOverlap = true;
237  for (unsigned int j = 0; j < zMuTrack->size(); j++) {
238  const Candidate& ztmCand = (*zMuTrack)[j];
239  CandidateRef CandReft(zMuTrack, j);
240 
243 
244  ProductID id1 = lep1.id();
245  ProductID id2 = lep2.id();
246  double iso1 = -1;
247  double iso2 = -1;
248 
249  if (id1 == muIsoId)
250  iso1 = muIso->value(lep1.key());
251  else if (id1 == trackIsoId)
252  iso1 = trackIso->value(lep1.key());
253 
254  if (id2 == muIsoId)
255  iso2 = muIso->value(lep2.key());
256  else if (id2 == trackIsoId)
257  iso2 = trackIso->value(lep2.key());
258 
259  double mt = ztmCand.mass();
260  if (lep1->pt() > ptcut_ && lep2->pt() > ptcut_ && fabs(lep1->eta()) < etacut_ &&
261  fabs(lep2->eta()) < etacut_ && mt > minZmass_ && mt < maxZmass_ && iso1 < isocut_ && iso2 < isocut_) {
262  if (overlap_(ztmCand, zsmCand)) {
263  noOverlap = false;
264  break;
265  }
266  if (!noOverlap) {
268  CandMatchMap::const_iterator m1 = zMuTrackMap->find(CandReft);
269  CandMatchMap::const_iterator m2 = zMuStandAloneMap->find(CandRef);
270 
271  if (m1 != zMuTrackMap->end() && m2 != zMuStandAloneMap->end()) {
273  }
274  }
275  }
276  }
277  }
278  }
279  }
280 }
281 
283  double Nzmm = h_zMuMu_mass_->GetEntries();
284  double Nzsm = h_zMuSingleStandAlone_mass_->GetEntries();
285  double Nzsnom = h_zMuSingleStandAloneOverlap_mass_->GetEntries();
286  double Nztm = h_zMuSingleTrack_mass_->GetEntries();
287 
288  double NzmmMatch = h_zMuMuMatched_mass_->GetEntries();
289  double NzsmMatch = h_zMuSingleStandAloneMatched_mass_->GetEntries();
290  double NzsnomMatch = h_zMuSingleStandAloneOverlapMatched_mass_->GetEntries();
291  double NztmMatch = h_zMuSingleTrackMatched_mass_->GetEntries();
292 
293  cout << "-- N SingleTrackMu = " << Nztm << endl;
294  cout << "-----N SinglStandAloneMu = " << Nzsm << endl;
295  cout << "-----N SingleStandAloneOverlapMu = " << Nzsnom << endl;
296  cout << "------- N MuMu = " << Nzmm << endl;
297 
298  cout << "-- N SingleTrackMuMatched = " << NztmMatch << endl;
299  cout << "-----N SinglStandAloneMuMatched = " << NzsmMatch << endl;
300  cout << "-----N SingleStandAloneOverlapMuMatched = " << NzsnomMatch << endl;
301  cout << "------- N MuMu Matched = " << NzmmMatch << endl;
302 }
303 
305 
RazorAnalyzer.lep1
lep1
print 'MRbb(1b)',event.mr_bb
Definition: RazorAnalyzer.py:261
reco::Candidate::daughter
virtual const Candidate * daughter(size_type i) const =0
return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode)
OverlapChecker
Definition: OverlapChecker.h:17
Handle.h
edm::AssociationMap::find
const_iterator find(const key_type &k) const
find element with specified reference key
Definition: AssociationMap.h:173
mps_fire.i
i
Definition: mps_fire.py:355
ZMuMuAnalyzer::muIsoToken_
EDGetTokenT< IsolationCollection > muIsoToken_
Definition: ZMuMuAnalyzer.cc:52
ZMuMuAnalysisNtupler_cff.zMuMu
zMuMu
zMuMu vector of PSet is common to all categories except zMuTrk category
Definition: ZMuMuAnalysisNtupler_cff.py:340
ZMuMuAnalyzer::isocut_
double isocut_
Definition: ZMuMuAnalyzer.cc:58
ZMuMuAnalyzer::h_zMuSingleStandAloneMatched_mass_
TH1D * h_zMuSingleStandAloneMatched_mass_
Definition: ZMuMuAnalyzer.cc:59
ZMuMuAnalyzer::ZMuMuAnalyzer
ZMuMuAnalyzer(const edm::ParameterSet &pset)
Definition: ZMuMuAnalyzer.cc:64
reco::Candidate::mass
virtual double mass() const =0
mass
edm::EDGetTokenT< CandidateCollection >
edm
HLT enums.
Definition: AlignableModifier.h:19
globals_cff.id1
id1
Definition: globals_cff.py:32
gather_cfg.cout
cout
Definition: gather_cfg.py:144
ZMuMuAnalyzer::h_zMuSingleStandAlone_mass_
TH1D * h_zMuSingleStandAlone_mass_
Definition: ZMuMuAnalyzer.cc:59
EDAnalyzer.h
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
IsolationCollection
edm::AssociationVector< reco::CandidateRefProd, std::vector< double > > IsolationCollection
Definition: ZMuMuAnalyzer.cc:38
ZMuMuAnalyzer
Definition: ZMuMuAnalyzer.py:1
edm::Handle
Definition: AssociativeIterator.h:50
singleTopDQM_cfi.setup
setup
Definition: singleTopDQM_cfi.py:37
CandMatchMap.h
edm::Ref
Definition: AssociativeIterator.h:58
edm::EDAnalyzer
Definition: EDAnalyzer.h:29
ZMuMuAnalyzer::trackIsoToken_
EDGetTokenT< IsolationCollection > trackIsoToken_
Definition: ZMuMuAnalyzer.cc:53
ZMuMuAnalyzer::overlap_
OverlapChecker overlap_
Definition: ZMuMuAnalyzer.cc:48
edm::AssociationMap::end
const_iterator end() const
last iterator over the map (read only)
Definition: AssociationMap.h:171
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Service.h
visualization-live-secondInstance_cfg.m
m
Definition: visualization-live-secondInstance_cfg.py:72
ZMuMuAnalyzer::standAloneIsoToken_
EDGetTokenT< IsolationCollection > standAloneIsoToken_
Definition: ZMuMuAnalyzer.cc:54
Particle.h
ZMuMuAnalyzer::analyze
void analyze(const edm::Event &event, const edm::EventSetup &setup) override
Definition: ZMuMuAnalyzer.cc:98
ZMuMuAnalyzer::h_zMuSingleTrackMatched_mass_
TH1D * h_zMuSingleTrackMatched_mass_
Definition: ZMuMuAnalyzer.cc:59
ZMuMuAnalyzer::zMuMuMapToken_
EDGetTokenT< CandMatchMap > zMuMuMapToken_
Definition: ZMuMuAnalyzer.cc:55
edm::AssociationVector
Definition: AssociationVector.h:67
TFileService.h
ZMuMuAnalyzer::zMuStandAloneMapToken_
EDGetTokenT< CandMatchMap > zMuStandAloneMapToken_
Definition: ZMuMuAnalyzer.cc:57
edm::ParameterSet
Definition: ParameterSet.h:36
Event.h
ZMuMuAnalyzer::h_zMuMu_mass_
TH1D * h_zMuMu_mass_
Definition: ZMuMuAnalyzer.cc:59
edm::AssociationMap
Definition: AssociationMap.h:48
edm::Service< TFileService >
ZMuMuAnalyzer::ptSTAcut_
double ptSTAcut_
Definition: ZMuMuAnalyzer.cc:58
analyze
example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
edm::EventSetup
Definition: EventSetup.h:57
edm::RefToBase::castTo
REF castTo() const
Definition: RefToBase.h:257
ZMuMuAnalyzer::minZmass_
double minZmass_
Definition: ZMuMuAnalyzer.cc:58
InputTag.h
reco::Candidate
Definition: Candidate.h:27
ZMuMuAnalyzer::zMuStandAloneToken_
EDGetTokenT< CandidateCollection > zMuStandAloneToken_
Definition: ZMuMuAnalyzer.cc:51
std
Definition: JetResolutionObject.h:76
ZMuMuAnalyzer::maxZmass_
double maxZmass_
Definition: ZMuMuAnalyzer.cc:58
ZMuMuAnalyzer::h_zMuSingleStandAloneOverlap_mass_
TH1D * h_zMuSingleStandAloneOverlap_mass_
Definition: ZMuMuAnalyzer.cc:59
edm::ValueMap< float >
ZMuMuAnalyzer::zMuTrackMapToken_
EDGetTokenT< CandMatchMap > zMuTrackMapToken_
Definition: ZMuMuAnalyzer.cc:56
EgHLTOffHistBins_cfi.mass
mass
Definition: EgHLTOffHistBins_cfi.py:34
TtSemiLepEvtBuilder_cfi.mt
mt
Definition: TtSemiLepEvtBuilder_cfi.py:47
reco::Candidate::masterClone
virtual const CandidateBaseRef & masterClone() const =0
ZMuMuAnalyzer::zMuTrackToken_
EDGetTokenT< CandidateCollection > zMuTrackToken_
Definition: ZMuMuAnalyzer.cc:50
AssociationVector.h
OverlapChecker.h
ZMuMuAnalyzer::h_zMuSingleStandAloneOverlapMatched_mass_
TH1D * h_zMuSingleStandAloneOverlapMatched_mass_
Definition: ZMuMuAnalyzer.cc:59
ZMuMuAnalyzer::h_zMuMuMatched_mass_
TH1D * h_zMuMuMatched_mass_
Definition: ZMuMuAnalyzer.cc:59
Candidate.h
ParameterSet.h
globals_cff.id2
id2
Definition: globals_cff.py:33
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
event
Definition: event.py:1
ZMuMuAnalyzer::endJob
void endJob() override
Definition: ZMuMuAnalyzer.cc:282
edm::Event
Definition: Event.h:73
RazorAnalyzer.lep2
lep2
Definition: RazorAnalyzer.py:262
edm::AssociationMap::const_iterator
const iterator
Definition: AssociationMap.h:76
edm::OwnVector::size
size_type size() const
Definition: OwnVector.h:300
ZMuMuAnalyzer::ptcut_
double ptcut_
Definition: ZMuMuAnalyzer.cc:58
edm::InputTag
Definition: InputTag.h:15
ZMuMuAnalyzer::etacut_
double etacut_
Definition: ZMuMuAnalyzer.cc:58
HLTMuonOfflineAnalyzer_cfi.zMass
zMass
Definition: HLTMuonOfflineAnalyzer_cfi.py:101
edm::ProductID
Definition: ProductID.h:27
TFileService::make
T * make(const Args &... args) const
make new ROOT object
Definition: TFileService.h:64
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
ZMuMuAnalyzer::h_zMuSingleTrack_mass_
TH1D * h_zMuSingleTrack_mass_
Definition: ZMuMuAnalyzer.cc:59
ZMuMuAnalyzer::zMuMuToken_
EDGetTokenT< CandidateCollection > zMuMuToken_
Definition: ZMuMuAnalyzer.cc:49
edm::OwnVector
Definition: OwnVector.h:24