CMS 3D CMS Logo

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:
50  ~ZMuMuMassConstraintParameterFinder() override = default;
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 
120 //
121 // member functions
122 //
123 
124 // ------------ method called for each event ------------
128 
129  for (const auto& particle : *(genParticles.product())) {
130  if (std::abs(particle.pdgId()) != muonPdg_ || particle.status() != 1)
131  continue;
132  if (particle.p() < pMin_)
133  continue;
134  if (particle.pt() < ptMin_)
135  continue;
136  if (particle.eta() < etaMin_ || particle.eta() > etaMax_)
137  continue;
138  if (particle.phi() < phiMin_ || particle.phi() > phiMax_)
139  continue;
140 
141  muonInfo_.muons().push_back(particle);
142  if (particle.mother()->pdgId() == zBosonPdg_) {
143  muonInfoFromZ_.muons().push_back(particle);
144  }
145  }
146 
147  muonInfo_.fill();
149 }
150 
151 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
154  desc.setComment("Extract information on 'Z -> mu mu' decays.");
155  desc.add<double>("pMin", 3.0);
156  desc.add<double>("ptMin", 15.0);
157  desc.add<double>("etaMin", -3.0);
158  desc.add<double>("etaMax", 3.0);
159  desc.add<double>("phiMin", -M_PI);
160  desc.add<double>("phiMax", M_PI);
161  desc.add<double>("minMassPair", 85.8);
162  desc.add<double>("maxMassPair", 95.8);
163  descriptions.add("zMuMuMassConstraintParameterFinder", desc);
164 }
165 
166 // ------------ helper class definition ------------
167 ZMuMuMassConstraintParameterFinder ::DiMuonInfo ::DiMuonInfo(double minMass, double maxMass)
168  : minMassPair_{minMass}, maxMassPair_{maxMass} {}
169 
170 void ZMuMuMassConstraintParameterFinder ::DiMuonInfo ::setupTree(const std::string& name,
172  tree_ = fs->make<TTree>(name.c_str(), name.c_str());
173  tree_->Branch("muons", &muons_);
174  tree_->Branch("di_muon_mass", &diMuonMass_);
175  tree_->Branch("pdg_mother", &pdgMother_);
176  tree_->Branch("in_mass_window", &passed_);
177 }
178 
180  if (muons_.size() == 2) {
181  diMuonMass_ = (muons_[0].p4() + muons_[1].p4()).M();
182  pdgMother_ = muons_[0].mother()->pdgId();
183  if (diMuonMass_ > minMassPair_ && diMuonMass_ < maxMassPair_)
184  passed_ = true;
185  tree_->Fill();
186  }
187  muons_.clear();
188  diMuonMass_ = -1.0;
189  pdgMother_ = 0;
190  passed_ = false;
191 }
192 
193 //define this as a plug-in
static const std::string kSharedResource
Definition: TFileService.h:76
std::vector< GenParticle > GenParticleCollection
collection of GenParticles
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
helper class containing information about a di-muon system
void setupTree(const std::string &, edm::Service< TFileService > &)
int iEvent
Definition: GenABIO.cc:224
void analyze(const edm::Event &, const edm::EventSetup &) override
edm::EDGetTokenT< reco::GenParticleCollection > genParticlesToken_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
~ZMuMuMassConstraintParameterFinder() override=default
#define M_PI
void add(std::string const &label, ParameterSetDescription const &psetDescription)
fixed size matrix
HLT enums.