Belle II Software  release-05-02-19
BgoStudyModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2013 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Igal Jaegle *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <beast/bgo/modules/BgoStudyModule.h>
12 #include <beast/bgo/dataobjects/BgoSimHit.h>
13 #include <beast/bgo/dataobjects/BgoHit.h>
14 #include <framework/datastore/StoreArray.h>
15 #include <framework/logging/Logger.h>
16 #include <cmath>
17 
18 #include <fstream>
19 #include <string>
20 
21 // ROOT
22 #include <TH1.h>
23 #include <TH2.h>
24 
25 #include <generators/SAD/dataobjects/SADMetaHit.h>
26 
27 using namespace std;
28 
29 using namespace Belle2;
30 using namespace bgo;
31 
32 //-----------------------------------------------------------------
33 // Register the Module
34 //-----------------------------------------------------------------
35 REG_MODULE(BgoStudy)
36 
37 //-----------------------------------------------------------------
38 // Implementation
39 //-----------------------------------------------------------------
40 
42 {
43  // Set module properties
44  setDescription("Study module for Bgos (BEAST)");
45 
46  addParam("Ethres", m_Ethres, "Energy threshold in MeV");
47 }
48 
49 BgoStudyModule::~BgoStudyModule()
50 {
51 }
52 
53 //This module is a histomodule. Any histogram created here will be saved by the HistoManager module
54 void BgoStudyModule::defineHisto()
55 {
56  for (int i = 0; i < 2; i++) {
57  h_bgo_rate[i] = new TH1F(TString::Format("bgo_rate_%d", i), "count", 18, 0., 18.);
58  h_bgo_rate[i]->Sumw2();
59 
60  h_bgo_rs_rate[i] = new TH2F(TString::Format("bgo_rs_rate_%d", i), "count v. ring section", 18, 0., 18., 12, 0., 12.);
61  h_bgo_rs_rate[i]->Sumw2();
62  }
63  for (int i = 0; i < 18; i++) {
64  h_bgo_Evtof[i] = new TH2F(TString::Format("bgo_Evtof_%d", i), "Energy deposited [MeV] vs TOF [ns] - all", 5000, 0., 1000.,
65  1000, 0., 400.);
66  h_bgo_Evtof1[i] = new TH2F(TString::Format("bgo_Evtof1_%d", i), "Energy deposited [MeV] vs TOF [ns] - all", 5000, 0., 1000.,
67  1000, 0., 400.);
68  h_bgo_Evtof2[i] = new TH2F(TString::Format("bgo_Evtof2_%d", i), "Energy deposited [MeV] vs TOF [ns] - only photons", 5000, 0.,
69  1000., 1000, 0., 400.);
70  h_bgo_Evtof3[i] = new TH2F(TString::Format("bgo_Evtof3_%d", i), "Energy deposited [MeV] vs TOF [ns] - only e+/e-", 5000, 0.,
71  1000., 1000, 0., 400.);
72 
73  h_bgo_edep[i] = new TH1F(TString::Format("bgo_edep_%d", i), "Energy deposited [MeV]", 5000, 0., 400.);
74  h_bgo_edep1[i] = new TH1F(TString::Format("bgo_edep1_%d", i), "Energy deposited [MeV]", 5000, 0., 400.);
75  h_bgo_edep2[i] = new TH1F(TString::Format("bgo_edep2_%d", i), "Energy deposited [MeV]", 5000, 0., 400.);
76  h_bgo_edep1Weight[i] = new TH1F(TString::Format("bgo_edep1Weight_%d", i), "Energy deposited [MeV]", 5000, 0., 400.);
77  h_bgo_edep2Weight[i] = new TH1F(TString::Format("bgo_edep2Weight_%d", i), "Energy deposited [MeV]", 5000, 0., 400.);
78 
79  h_bgo_rs_edep1[i] = new TH2F(TString::Format("bgo_rs_edep1_%d", i), "Energy deposited [MeV]", 5000, 0., 400., 12, 0., 12.);
80  h_bgo_rs_edep2[i] = new TH2F(TString::Format("bgo_rs_edep2_%d", i), "Energy deposited [MeV]", 5000, 0., 400., 12, 0., 12.);
81  h_bgo_rs_edep1Weight[i] = new TH2F(TString::Format("bgo_rs_edep1Weight_%d", i), "Energy deposited [MeV]", 5000, 0., 400., 12, 0.,
82  12.);
83  h_bgo_rs_edep2Weight[i] = new TH2F(TString::Format("bgo_rs_edep2Weight_%d", i), "Energy deposited [MeV]", 5000, 0., 400., 12, 0.,
84  12.);
85 
86  h_bgo_edep[i]->Sumw2();
87  h_bgo_edep1[i]->Sumw2();
88  h_bgo_edep2[i]->Sumw2();
89  h_bgo_edep1Weight[i]->Sumw2();
90  h_bgo_edep2Weight[i]->Sumw2();
91  h_bgo_rs_edep1[i]->Sumw2();
92  h_bgo_rs_edep2[i]->Sumw2();
93  h_bgo_rs_edep1Weight[i]->Sumw2();
94  h_bgo_rs_edep2Weight[i]->Sumw2();
95  }
96 
97 }
98 
99 
100 void BgoStudyModule::initialize()
101 {
102  B2INFO("BgoStudyModule: Initialize");
103 
104  //read bgo xml file
105  //getXMLData();
106 
107  REG_HISTOGRAM
108 
109 }
110 
111 void BgoStudyModule::beginRun()
112 {
113 }
114 
115 void BgoStudyModule::event()
116 {
117  //Here comes the actual event processing
118  StoreArray<BgoSimHit> SimHits;
119  StoreArray<BgoHit> Hits;
120  StoreArray<SADMetaHit> MetaHits;
121 
122  //Skip events with no Hits
123  if (SimHits.getEntries() == 0) {
124  return;
125  }
126 
127  //Look at the meta data to extract IR rate and scattering ring section
128  double rate = 0;
129  int ring_section = -1;
130  int section_ordering[12] = {1, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2};
131  for (const auto& MetaHit : MetaHits) {
132  rate = MetaHit.getrate();
133  double sad_ssraw = MetaHit.getssraw();
134  double ssraw = 0;
135  if (sad_ssraw >= 0) ssraw = sad_ssraw / 100.;
136  else if (sad_ssraw < 0) ssraw = 3000. + sad_ssraw / 100.;
137  ring_section = section_ordering[(int)((ssraw) / 250.)] - 1;
138  //ring_section = MetaHit.getring_section() - 1;
139  }
140  //Loop over SimHit
141  for (const auto& SimHit : SimHits) {
142  int detNB = SimHit.getCellId();
143  int pdg = SimHit.getPDGCode();
144  double Edep = SimHit.getEnergyDep() * 1e3; //GeV -> MeV
145  double tof = SimHit.getFlightTime(); //ns
146 
147  h_bgo_edep[detNB]->Fill(Edep);
148  h_bgo_Evtof[detNB]->Fill(tof, Edep);
149  if (pdg == 22) h_bgo_Evtof1[detNB]->Fill(tof, Edep);
150  else if (fabs(pdg) == 11) h_bgo_Evtof2[detNB]->Fill(tof, Edep);
151  double RecEdep = Edep;
152  h_bgo_rate[0]->Fill(detNB);
153  h_bgo_rate[1]->Fill(detNB, rate);
154  h_bgo_edep1[detNB]->Fill(Edep);
155  h_bgo_edep2[detNB]->Fill(RecEdep);
156  h_bgo_edep1Weight[detNB]->Fill(Edep, rate);
157  h_bgo_edep2Weight[detNB]->Fill(RecEdep, rate);
158  h_bgo_Evtof3[detNB]->Fill(tof, RecEdep);
159  h_bgo_rs_rate[0]->Fill(detNB, ring_section);
160  h_bgo_rs_rate[1]->Fill(detNB, ring_section, rate);
161  h_bgo_rs_edep1[detNB]->Fill(Edep, ring_section);
162  h_bgo_rs_edep2[detNB]->Fill(RecEdep, ring_section);
163  h_bgo_rs_edep1Weight[detNB]->Fill(Edep, ring_section, rate);
164  h_bgo_rs_edep2Weight[detNB]->Fill(RecEdep, ring_section, rate);
165  }
166  /*
167  //Loop over DigiHit
168  for (const auto& Hit : Hits) {
169  int detNB = Hit.getCellId();
170  double Edep = Hit.getEnergyDep() * 1e3; //GeV -> MeV
171  double RecEdep = Hit.getEnergyRecDep() * 1e3; //GeV -> MeV
172  double tof = Hit.getFlightTime(); //ns
173  h_bgo_rate[0]->Fill(detNB);
174  h_bgo_rate[1]->Fill(detNB, rate);
175  h_bgo_edep1[detNB]->Fill(Edep);
176  h_bgo_edep2[detNB]->Fill(RecEdep);
177  h_bgo_edep1Weight[detNB]->Fill(Edep, rate);
178  h_bgo_edep2Weight[detNB]->Fill(RecEdep, rate);
179  h_bgo_Evtof3[detNB]->Fill(tof, RecEdep);
180  h_bgo_rs_rate[0]->Fill(detNB, ring_section);
181  h_bgo_rs_rate[1]->Fill(detNB, ring_section, rate);
182  h_bgo_rs_edep1[detNB]->Fill(Edep, ring_section);
183  h_bgo_rs_edep2[detNB]->Fill(RecEdep, ring_section);
184  h_bgo_rs_edep1Weight[detNB]->Fill(Edep, ring_section, rate);
185  h_bgo_rs_edep2Weight[detNB]->Fill(RecEdep, ring_section, rate);
186  }
187  */
188 }
189 /*
190 //read tube centers, impulse response, and garfield drift data filename from BGO.xml
191 void BgoStudyModule::getXMLData()
192 {
193  GearDir content = GearDir("/Detector/DetectorComponent[@name=\"BGO\"]/Content/");
194  m_Ethres = content.getDouble("Ethres");
195 
196  B2INFO("BgoStudy");
197 
198 }
199 */
200 void BgoStudyModule::endRun()
201 {
202 
203 
204 }
205 
206 void BgoStudyModule::terminate()
207 {
208 }
209 
210 
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::bgo::BgoStudyModule
Study module for Bgos (BEAST)
Definition: BgoStudyModule.h:43
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::StoreArray
Accessor to arrays stored in the data store.
Definition: ECLMatchingPerformanceExpertModule.h:33
Belle2::StoreArray::getEntries
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:226
Belle2::HistoModule
HistoModule.h is supposed to be used instead of Module.h for the modules with histogram definitions t...
Definition: HistoModule.h:29