DMEM.cc
1 /*
2  * MoMEMta: a modular implementation of the Matrix Element Method
3  * Copyright (C) 2016 Universite catholique de Louvain (UCL), Belgium
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #include <TH1D.h>
20 
21 #include <momemta/ParameterSet.h>
22 #include <momemta/Module.h>
23 #include <momemta/Types.h>
24 
25 /*
26  * \brief Module implementing the Differential MEM
27  *
28  * \ingroup modules
29  */
30 
31 class DMEM: public Module {
32  public:
33 
34  DMEM(PoolPtr pool, const ParameterSet& parameters): Module(pool, parameters.getModuleName()) {
35  x_start = parameters.get<double>("x_start");
36  x_end = parameters.get<double>("x_end");
37  n_bins = parameters.get<int64_t>("n_bins");
38 
39  m_hist = produce<TH1D>("hist", (name() + "_DMEM").c_str(), (name() + "_DMEM").c_str(), n_bins, x_start, x_end);
40  m_hist->SetDirectory(0);
41 
42  auto particle_tags = parameters.get<std::vector<InputTag>>("particles");
43  for (auto& t: particle_tags)
44  m_particles.push_back(get<LorentzVector>(t));
45 
46  psWeight = get<double>(parameters.get<InputTag>("ps_weight"));
47  meOutput = get<double>(parameters.get<InputTag>("me_output"));
48  }
49 
50  virtual void beginIntegration() override {
51  m_hist->Reset();
52  }
53 
54  virtual Status work() override {
55 
56  LorentzVector tot;
57  for (const auto& v: m_particles)
58  tot += *v;
59 
60  // Fill histogram
61  m_hist->Fill(tot.M(), *meOutput * (*psWeight));
62 
63  return Status::OK;
64  }
65 
66  private:
67 
68  double x_start, x_end;
69  int64_t n_bins;
70 
71  // Inputs
72  std::vector<Value<LorentzVector>> m_particles;
73  Value<double> psWeight;
74  Value<double> meOutput;
75 
76  // Outputs
77  std::shared_ptr<TH1D> m_hist;
78 };
79 
80 REGISTER_MODULE(DMEM)
81  .Inputs("particles")
82  .Input("ps_weight")
83  .Input("me_output")
84  .Output("hist")
85  .Attr("x_start:double")
86  .Attr("x_end:double")
87  .Attr("n_bins:int")
88  .Sticky();
virtual void beginIntegration() override
Called once at the beginning of the integration.
Definition: DMEM.cc:50
An identifier of a module&#39;s output.
Definition: InputTag_fwd.h:37
virtual Status work() override
Main function.
Definition: DMEM.cc:54
Parent class for all the modules.
Definition: Module.h:37
A class encapsulating a lua table.
Definition: ParameterSet.h:82
Module(PoolPtr pool, const std::string &name)
Constructor.
Definition: Module.h:61
Definition: DMEM.cc:31