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 
25 // system include files
26 #include <cmath>
27 #include <cstdlib>
28 #include <vector>
29 
30 // ROOT include files
31 #include "TTree.h"
32 
33 // user include files
43 
44 
45 //
46 // class declaration
47 //
48 
50  public edm::one::EDAnalyzer<edm::one::SharedResources> {
51 public:
54 
55  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
56 
57 
58 private:
60  class DiMuonInfo {
61  public:
62  DiMuonInfo(double, double);
64  void fill();
65  std::vector<reco::GenParticle>& muons() { return muons_; }
66 
67  private:
68  TTree* tree_{nullptr};
69  std::vector<reco::GenParticle> muons_;
70  double diMuonMass_{-1.0};
71  int pdgMother_{0};
72  bool passed_{false};
73 
74  const double minMassPair_;
75  const double maxMassPair_;
76  };
77 
78  void analyze(const edm::Event&, const edm::EventSetup&) override;
79 
80  // ----------member data ---------------------------
82 
83  // particle IDs
84  const int muonPdg_{13};
85  const int zBosonPdg_{23};
86 
87  // muon cuts
88  const double pMin_;
89  const double ptMin_;
90  const double etaMin_;
91  const double etaMax_;
92  const double phiMin_;
93  const double phiMax_;
94 
95  // di-muon cuts
96  const double minMassPair_;
97  const double maxMassPair_;
98 
101 };
102 
103 
104 //
105 // constructors and destructor
106 //
109  genParticlesToken_(consumes<reco::GenParticleCollection>(edm::InputTag{"genParticles"})),
110  pMin_(iConfig.getParameter<double>("pMin")),
111  ptMin_(iConfig.getParameter<double>("ptMin")),
112  etaMin_(iConfig.getParameter<double>("etaMin")),
113  etaMax_(iConfig.getParameter<double>("etaMax")),
114  phiMin_(iConfig.getParameter<double>("phiMin")),
115  phiMax_(iConfig.getParameter<double>("phiMax")),
116  minMassPair_(iConfig.getParameter<double>("minMassPair")),
117  maxMassPair_(iConfig.getParameter<double>("maxMassPair")),
120 {
121  usesResource(TFileService::kSharedResource);
123  muonInfo_.setupTree("di_muon", fs);
124  muonInfoFromZ_.setupTree("di_muon_from_Z", fs);
125 }
126 
127 
130 {
131 }
132 
133 
134 //
135 // member functions
136 //
137 
138 // ------------ method called for each event ------------
139 void
142 {
144  iEvent.getByToken(genParticlesToken_, genParticles);
145 
146  for (const auto& particle: *(genParticles.product())) {
147  if (std::abs(particle.pdgId()) != muonPdg_ || particle.status() != 1) continue;
148  if (particle.p() < pMin_) continue;
149  if (particle.pt() < ptMin_) continue;
150  if (particle.eta() < etaMin_ || particle.eta() > etaMax_) continue;
151  if (particle.phi() < phiMin_ || particle.phi() > phiMax_) continue;
152 
153  muonInfo_.muons().push_back(particle);
154  if (particle.mother()->pdgId() == zBosonPdg_) {
155  muonInfoFromZ_.muons().push_back(particle);
156  }
157  }
158 
159  muonInfo_.fill();
161 }
162 
163 
164 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
165 void
169  desc.setComment("Extract information on 'Z -> mu mu' decays.");
170  desc.add<double>("pMin", 3.0);
171  desc.add<double>("ptMin", 15.0);
172  desc.add<double>("etaMin", -3.0);
173  desc.add<double>("etaMax", 3.0);
174  desc.add<double>("phiMin", -3.1416);
175  desc.add<double>("phiMax", 3.1416);
176  desc.add<double>("minMassPair", 85.8);
177  desc.add<double>("maxMassPair", 95.8);
178  descriptions.add("zMuMuMassConstraintParameterFinder", desc);
179 }
180 
181 
182 // ------------ helper class definition ------------
185 ::DiMuonInfo(double minMass, double maxMass) :
186  minMassPair_{minMass},
188 {
189 }
190 
191 
192 void
196 {
197  tree_ = fs->make<TTree>(name.c_str(), name.c_str());
198  tree_->Branch("muons", &muons_);
199  tree_->Branch("di_muon_mass", &diMuonMass_);
200  tree_->Branch("pdg_mother", &pdgMother_);
201  tree_->Branch("in_mass_window", &passed_);
202 }
203 
204 
205 void
209 {
210  if (muons_.size() == 2) {
211  diMuonMass_ = (muons_[0].p4() + muons_[1].p4()).M();
212  pdgMother_ = muons_[0].mother()->pdgId();
214  tree_->Fill();
215  }
216  muons_.clear();
217  diMuonMass_ = -1.0;
218  pdgMother_ = 0;
219  passed_ = false;
220 }
221 
222 //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:517
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
helper class containing information about a di-muon system
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
void setupTree(const std::string &, edm::Service< TFileService > &)
void setComment(std::string const &value)
int iEvent
Definition: GenABIO.cc:224
void analyze(const edm::Event &, const edm::EventSetup &) override
edm::EDGetTokenT< reco::GenParticleCollection > genParticlesToken_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
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:74
void add(std::string const &label, ParameterSetDescription const &psetDescription)
fixed size matrix
HLT enums.