CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ZMuMuMassConstraintParameterFinder.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Alignment/MillePedeAlignmentAlgorithm
4 // Class: ZMuMuMassConstraintParameterFinder
5 //
18 //
19 // Original Author: Gregor Mittag
20 // Created: Fri, 17 Jun 2016 09:42:56 GMT
21 //
22 //
23 
24 // system include files
25 #include <cmath>
26 #include <cstdlib>
27 #include <vector>
28 
29 // ROOT include files
30 #include "TTree.h"
31 
32 // user include files
42 
43 //
44 // class declaration
45 //
46 
47 class ZMuMuMassConstraintParameterFinder : public edm::one::EDAnalyzer<edm::one::SharedResources> {
48 public:
51 
52  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
53 
54 private:
56  class DiMuonInfo {
57  public:
58  DiMuonInfo(double, double);
60  void fill();
61  std::vector<reco::GenParticle>& muons() { return muons_; }
62 
63  private:
64  TTree* tree_{nullptr};
65  std::vector<reco::GenParticle> muons_;
66  double diMuonMass_{-1.0};
67  int pdgMother_{0};
68  bool passed_{false};
69 
70  const double minMassPair_;
71  const double maxMassPair_;
72  };
73 
74  void analyze(const edm::Event&, const edm::EventSetup&) override;
75 
76  // ----------member data ---------------------------
78 
79  // particle IDs
80  const int muonPdg_{13};
81  const int zBosonPdg_{23};
82 
83  // muon cuts
84  const double pMin_;
85  const double ptMin_;
86  const double etaMin_;
87  const double etaMax_;
88  const double phiMin_;
89  const double phiMax_;
90 
91  // di-muon cuts
92  const double minMassPair_;
93  const double maxMassPair_;
94 
97 };
98 
99 //
100 // constructors and destructor
101 //
103  : genParticlesToken_(consumes<reco::GenParticleCollection>(edm::InputTag{"genParticles"})),
104  pMin_(iConfig.getParameter<double>("pMin")),
105  ptMin_(iConfig.getParameter<double>("ptMin")),
106  etaMin_(iConfig.getParameter<double>("etaMin")),
107  etaMax_(iConfig.getParameter<double>("etaMax")),
108  phiMin_(iConfig.getParameter<double>("phiMin")),
109  phiMax_(iConfig.getParameter<double>("phiMax")),
110  minMassPair_(iConfig.getParameter<double>("minMassPair")),
111  maxMassPair_(iConfig.getParameter<double>("maxMassPair")),
112  muonInfo_(minMassPair_, maxMassPair_),
113  muonInfoFromZ_(minMassPair_, maxMassPair_) {
114  usesResource(TFileService::kSharedResource);
116  muonInfo_.setupTree("di_muon", fs);
117  muonInfoFromZ_.setupTree("di_muon_from_Z", fs);
118 }
119 
121 
122 //
123 // member functions
124 //
125 
126 // ------------ method called for each event ------------
129  iEvent.getByToken(genParticlesToken_, genParticles);
130 
131  for (const auto& particle : *(genParticles.product())) {
132  if (std::abs(particle.pdgId()) != muonPdg_ || particle.status() != 1)
133  continue;
134  if (particle.p() < pMin_)
135  continue;
136  if (particle.pt() < ptMin_)
137  continue;
138  if (particle.eta() < etaMin_ || particle.eta() > etaMax_)
139  continue;
140  if (particle.phi() < phiMin_ || particle.phi() > phiMax_)
141  continue;
142 
143  muonInfo_.muons().push_back(particle);
144  if (particle.mother()->pdgId() == zBosonPdg_) {
145  muonInfoFromZ_.muons().push_back(particle);
146  }
147  }
148 
149  muonInfo_.fill();
151 }
152 
153 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
156  desc.setComment("Extract information on 'Z -> mu mu' decays.");
157  desc.add<double>("pMin", 3.0);
158  desc.add<double>("ptMin", 15.0);
159  desc.add<double>("etaMin", -3.0);
160  desc.add<double>("etaMax", 3.0);
161  desc.add<double>("phiMin", -3.1416);
162  desc.add<double>("phiMax", 3.1416);
163  desc.add<double>("minMassPair", 85.8);
164  desc.add<double>("maxMassPair", 95.8);
165  descriptions.add("zMuMuMassConstraintParameterFinder", desc);
166 }
167 
168 // ------------ helper class definition ------------
170  : minMassPair_{minMass}, maxMassPair_{maxMass} {}
171 
174  tree_ = fs->make<TTree>(name.c_str(), name.c_str());
175  tree_->Branch("muons", &muons_);
176  tree_->Branch("di_muon_mass", &diMuonMass_);
177  tree_->Branch("pdg_mother", &pdgMother_);
178  tree_->Branch("in_mass_window", &passed_);
179 }
180 
182  if (muons_.size() == 2) {
183  diMuonMass_ = (muons_[0].p4() + muons_[1].p4()).M();
184  pdgMother_ = muons_[0].mother()->pdgId();
185  if (diMuonMass_ > minMassPair_ && diMuonMass_ < maxMassPair_)
186  passed_ = true;
187  tree_->Fill();
188  }
189  muons_.clear();
190  diMuonMass_ = -1.0;
191  pdgMother_ = 0;
192  passed_ = false;
193 }
194 
195 //define this as a plug-in
static const std::string kSharedResource
Definition: TFileService.h:76
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
etaMax_(conf.getParameter< double >("etaMax"))
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
helper class containing information about a di-muon system
void setupTree(const std::string &, edm::Service< TFileService > &)
void setComment(std::string const &value)
ptMin_(conf.getParameter< double >("ptMin"))
int iEvent
Definition: GenABIO.cc:224
void analyze(const edm::Event &, const edm::EventSetup &) override
edm::EDGetTokenT< reco::GenParticleCollection > genParticlesToken_
pMin_(conf.getParameter< double >("pMin"))
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ParameterDescriptionBase * add(U const &iLabel, T const &value)
T const * product() const
Definition: Handle.h:70
void add(std::string const &label, ParameterSetDescription const &psetDescription)
etaMin_(conf.getParameter< double >("etaMin"))