Belle II Software  release-08-01-10
TOPChannelT0MCModule.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 
9 // Own header.
10 #include <top/modules/TOPChannelT0MC/TOPChannelT0MCModule.h>
11 
12 // framework - DataStore
13 #include <framework/datastore/StoreArray.h>
14 
15 // database classes
16 #include <framework/database/DBStore.h>
17 
18 #include <TFile.h>
19 #include <TH1F.h>
20 #include <TTree.h>
21 #include <sstream>
22 
23 using namespace std;
24 
25 namespace Belle2 {
30  //-----------------------------------------------------------------
32  //-----------------------------------------------------------------
33 
34  REG_MODULE(TOPChannelT0MC);
35 
36  //-----------------------------------------------------------------
37  // Implementation
38  //-----------------------------------------------------------------
39 
40  TOPChannelT0MCModule::TOPChannelT0MCModule() : Module()
41  {
42  std::vector<double> frange = {100, 0., 1.};
43  // set module description (e.g. insert text)
44  setDescription("TOP channel T0 Calibration of MC extraction");
45  // Add parameters
46  addParam("outputFile", m_outputFile, "Output root file name",
47  string(""));
48  addParam("fitRange", m_fitRange, "fit range[nbins, xmin, xmax]", frange);
49 
50  }
51 
53  {
54  }
55 
57  {
58 
59  m_digits.isRequired();
60 
61  }
62 
64  {
65  }
66 
68  {
69 
70  for (auto& digit : m_digits) {
71  unsigned channel = digit.getChannel();
72  if (channel < c_NumChannels) {
73  auto histo = m_histo[channel];
74  if (!histo) {
75  stringstream ss;
76  ss << "chan" << channel ;
77  string name;
78  ss >> name;
79  string title = "Times " + name;
80  histo = new TH1F(name.c_str(), title.c_str(), (int)m_fitRange[0], m_fitRange[1], m_fitRange[2]);
81  m_histo[channel] = histo;
82  }
83  if (digit.getTime() < m_fitRange[1] || digit.getTime() > m_fitRange[2]) continue;
84  histo->Fill(digit.getTime());
85  }
86  }
87  }
88 
90  {
91  }
92 
94  {
95  auto file = new TFile(m_outputFile.c_str(), "RECREATE");
96  auto otree = new TTree("t0MC", "extract channel t0 info. from MC");
97 
98  unsigned channel = 0;
99  double maxpos = 0;
100 
101  otree->Branch("maxpos", &maxpos, "maxpos/D");
102  otree->Branch("channel", &channel, "channel/I");
103 
104  for (int i = 0; i < c_NumChannels; i++) {
105  channel = i;
106  maxpos = m_histo[i]->GetXaxis()->GetBinCenter(m_histo[i]->GetMaximumBin());
107  otree->Fill();
108  }
109  otree->Write();
110  delete otree;
111  file->Close();
112  delete file;
113  }
115 } // end Belle2 namespace
116 
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
std::vector< double > m_fitRange
fit range [nbins, xmin, xmax]
std::string m_outputFile
output root file name
StoreArray< TOPDigit > m_digits
collection of digits
TH1F * m_histo[c_NumChannels]
profile histograms
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:560
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
virtual void initialize() override
Initialize the Module.
virtual void event() override
Event processor.
virtual void endRun() override
End-of-run action.
virtual void terminate() override
Termination action.
virtual void beginRun() override
Called when entering a new run.
virtual ~TOPChannelT0MCModule()
Destructor.
Abstract base class for different kinds of events.