CMS 3D CMS Logo

PatZToMuMuAnalyzer.cc
Go to the documentation of this file.
1 #include <map>
2 #include <string>
3 
4 #include "TH1D.h"
5 #include "TH2D.h"
6 
13 
33 public:
37 
39  explicit PatZToMuMuAnalyzer(const edm::ParameterSet& cfg);
41  ~PatZToMuMuAnalyzer() override{};
42 
43 private:
45  void analyze(const edm::Event& event, const edm::EventSetup& setup) override;
46 
48  double mass(const math::XYZVector& t1, const math::XYZVector& t2) const;
50  bool booked(const std::string histName) const { return hists_.find(histName) != hists_.end(); };
52  void fill(const std::string histName, double value) const {
53  if (booked(histName))
54  hists_.find(histName)->second->Fill(value);
55  };
57  void fill(std::string hists, const reco::TrackRef& t1, const reco::TrackRef& t2) const;
58 
63  double shift_;
65  std::map<std::string, TH1D*> hists_;
66 };
67 
68 inline double PatZToMuMuAnalyzer::mass(const Vector& t1, const Vector& t2) const {
69  return (LorentzVector(shift_ * t1.x(), shift_ * t1.y(), t1.z(), sqrt((0.1057 * 0.1057) + t1.mag2())) +
70  LorentzVector(shift_ * t2.x(), shift_ * t2.y(), t2.z(), sqrt((0.1057 * 0.1057) + t2.mag2())))
71  .mass();
72 }
73 
76 
78  : muonsToken_(consumes<edm::View<pat::Muon> >(cfg.getParameter<edm::InputTag>("muons"))),
79  shift_(cfg.getParameter<double>("shift")) {
80  edm::Service<TFileService> fileService;
81 
82  // mass plot around Z peak from global tracks
83  hists_["globalMass"] = fileService->make<TH1D>("globalMass", "Mass_{Z} (global) (GeV)", 90, 30., 120.);
84  // eta from global tracks
85  hists_["globalEta"] = fileService->make<TH1D>("globalEta", "#eta (global)", 48, -2.4, 2.4);
86  // pt from global tracks
87  hists_["globalPt"] = fileService->make<TH1D>("globalPt", "p_{T} (global) (GeV)", 100, 0., 100.);
88  // mass plot around Z peak from inner tracks
89  hists_["innerMass"] = fileService->make<TH1D>("innerMass", "Mass_{Z} (inner) (GeV)", 90, 30., 120.);
90  // eta from inner tracks
91  hists_["innerEta"] = fileService->make<TH1D>("innerEta", "#eta (inner)", 48, -2.4, 2.4);
92  // pt from inner tracks
93  hists_["innerPt"] = fileService->make<TH1D>("innerPt", "p_{T} (inner) (GeV)", 100, 0., 100.);
94  // mass plot around Z peak from outer tracks
95  hists_["outerMass"] = fileService->make<TH1D>("outerMass", "Mass_{Z} (outer) (GeV)", 90, 30., 120.);
96  // eta from outer tracks
97  hists_["outerEta"] = fileService->make<TH1D>("outerEta", "#eta (outer)", 48, -2.4, 2.4);
98  // pt from outer tracks
99  hists_["outerPt"] = fileService->make<TH1D>("outerPt", "p_{T} (outer) (GeV)", 100, 0., 100.);
100  // delta pt between global and outer track
101  hists_["deltaPt"] = fileService->make<TH1D>("deltaPt", "#Delta p_{T} (GeV)", 100, -20., 20.);
102  // delta eta between global and outer track
103  hists_["deltaEta"] = fileService->make<TH1D>("deltaEta", "#Delta #eta", 100, -0.2, 0.2);
104  // delta phi between global and outer track
105  hists_["deltaPhi"] = fileService->make<TH1D>("deltaPhi", "#Delta #phi", 100, -0.2, 0.2);
106 }
107 
109  if (t1.isAvailable()) {
110  // fill pt from global track for first muon
111  fill(std::string(hists).append("Pt"), t1->pt());
112  // fill pt from global track for second muon
113  fill(std::string(hists).append("Eta"), t1->eta());
114  }
115  if (t2.isAvailable()) {
116  // fill eta from global track for first muon
117  fill(std::string(hists).append("Pt"), t2->pt());
118  // fill eta from global track for second muon
119  fill(std::string(hists).append("Eta"), t2->eta());
120  }
121  if (t1.isAvailable() && t2.isAvailable()) {
122  // fill invariant mass of the Z boson candidate
123  fill(std::string(hists).append("Mass"), mass(t1->momentum(), t2->momentum()));
124  }
125 }
126 
128  // pat candidate collection
130  event.getByToken(muonsToken_, muons);
131 
132  // Fill some basic muon quantities as
133  // reconstructed from inner and outer
134  // tack
135  for (edm::View<pat::Muon>::const_iterator mu1 = muons->begin(); mu1 != muons->end(); ++mu1) {
136  for (edm::View<pat::Muon>::const_iterator mu2 = muons->begin(); mu2 != muons->end(); ++mu2) {
137  if (mu2 > mu1) { // prevent double conting
138  if (mu1->charge() * mu2->charge() < 0) { // check only muon pairs of unequal charge
139  fill(std::string("inner"), mu1->innerTrack(), mu2->innerTrack());
140  fill(std::string("outer"), mu1->outerTrack(), mu2->outerTrack());
141  fill(std::string("global"), mu1->globalTrack(), mu2->globalTrack());
142 
143  if (mu1->isGlobalMuon()) {
144  fill("deltaPt", mu1->outerTrack()->pt() - mu1->globalTrack()->pt());
145  fill("deltaEta", mu1->outerTrack()->eta() - mu1->globalTrack()->eta());
146  fill("deltaPhi", mu1->outerTrack()->phi() - mu1->globalTrack()->phi());
147  }
148  if (mu2->isGlobalMuon()) {
149  fill("deltaPt", mu2->outerTrack()->pt() - mu2->globalTrack()->pt());
150  fill("deltaEta", mu2->outerTrack()->eta() - mu2->globalTrack()->eta());
151  fill("deltaPhi", mu2->outerTrack()->phi() - mu2->globalTrack()->phi());
152  }
153  }
154  }
155  }
156  }
157 }
158 
PDWG_BPHSkim_cff.muons
muons
Definition: PDWG_BPHSkim_cff.py:47
RandomServiceHelper.t2
t2
Definition: RandomServiceHelper.py:257
sistrip::View
View
Definition: ConstantsForView.h:26
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
Muon.h
PatZToMuMuAnalyzer::muonsToken_
edm::EDGetTokenT< edm::View< pat::Muon > > muonsToken_
input for muons
Definition: PatZToMuMuAnalyzer.cc:60
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89285
EDAnalyzer.h
compare.hists
hists
Definition: compare.py:319
PatZToMuMuAnalyzer::LorentzVector
math::XYZTLorentzVector LorentzVector
Definition: PatZToMuMuAnalyzer.cc:36
edm::Handle
Definition: AssociativeIterator.h:50
singleTopDQM_cfi.setup
setup
Definition: singleTopDQM_cfi.py:37
Muon
Definition: Muon.py:1
edm::Ref< TrackCollection >
edm::EDAnalyzer
Definition: EDAnalyzer.h:28
PatZToMuMuAnalyzer::mass
double mass(const math::XYZVector &t1, const math::XYZVector &t2) const
calculate the mass of the Z boson from the tracker momenta by hand
Definition: PatZToMuMuAnalyzer.cc:68
PatZToMuMuAnalyzer::Vector
math::XYZVector Vector
typedef's to simplify get functions
Definition: PatZToMuMuAnalyzer.cc:35
MakerMacros.h
RandomServiceHelper.t1
t1
Definition: RandomServiceHelper.py:256
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
PatZToMuMuAnalyzer::analyze
void analyze(const edm::Event &event, const edm::EventSetup &setup) override
everything that needs to be done during the event loop
Definition: PatZToMuMuAnalyzer.cc:127
PatZToMuMuAnalyzer::fill
void fill(const std::string histName, double value) const
fill histogram if it had been booked before
Definition: PatZToMuMuAnalyzer.cc:52
Service.h
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
TFileService.h
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
PatZToMuMuAnalyzer::shift_
double shift_
Definition: PatZToMuMuAnalyzer.cc:63
mps_setup.append
append
Definition: mps_setup.py:85
PatZToMuMuAnalyzer
Module to analyze the performance of muon reconstruction on the example of Z->mumu events.
Definition: PatZToMuMuAnalyzer.cc:32
math::XYZVector
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
edm::Service< TFileService >
value
Definition: value.py:1
edm::EventSetup
Definition: EventSetup.h:58
pat
Definition: HeavyIon.h:7
PatZToMuMuAnalyzer::hists_
std::map< std::string, TH1D * > hists_
management of 1d histograms
Definition: PatZToMuMuAnalyzer.cc:65
InputTag.h
looper.cfg
cfg
Definition: looper.py:297
Frameworkfwd.h
math::XYZTLorentzVector
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
edm::View::const_iterator
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
PatZToMuMuAnalyzer::~PatZToMuMuAnalyzer
~PatZToMuMuAnalyzer() override
default destructor
Definition: PatZToMuMuAnalyzer.cc:41
ParameterSet.h
event
Definition: event.py:1
PatZToMuMuAnalyzer::booked
bool booked(const std::string histName) const
check if histogram was booked
Definition: PatZToMuMuAnalyzer.cc:50
edm::Event
Definition: Event.h:73
PatZToMuMuAnalyzer::PatZToMuMuAnalyzer
PatZToMuMuAnalyzer(const edm::ParameterSet &cfg)
default constructor
Definition: PatZToMuMuAnalyzer.cc:77
TFileService::make
T * make(const Args &... args) const
make new ROOT object
Definition: TFileService.h:64