Belle II Software  release-05-02-19
PindiodeStudyModule.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/pindiode/modules/PindiodeStudyModule.h>
12 #include <beast/pindiode/dataobjects/PindiodeSimHit.h>
13 #include <beast/pindiode/dataobjects/PindiodeHit.h>
14 #include <generators/SAD/dataobjects/SADMetaHit.h>
15 #include <framework/datastore/StoreArray.h>
16 #include <framework/logging/Logger.h>
17 #include <framework/gearbox/GearDir.h>
18 #include <cmath>
19 
20 #include <fstream>
21 #include <string>
22 
23 // ROOT
24 #include <TRandom.h>
25 #include <TH1.h>
26 #include <TH2.h>
27 
28 using namespace std;
29 
30 using namespace Belle2;
31 using namespace pindiode;
32 
33 //-----------------------------------------------------------------
34 // Register the Module
35 //-----------------------------------------------------------------
36 REG_MODULE(PindiodeStudy)
37 
38 //-----------------------------------------------------------------
39 // Implementation
40 //-----------------------------------------------------------------
41 
43 {
44  // Set module properties
45  setDescription("Study module for Pindiodes (BEAST)");
46 
47  //Default values are set here. New values can be in PINDIODE.xml.
48  addParam("CrematGain", m_CrematGain, "Charge sensitive preamplifier gain [volts/C] ", 1.4);
49  addParam("WorkFunction", m_WorkFunction, "Convert eV to e [e/eV] ", 1.12);
50  addParam("FanoFactor", m_FanoFactor, "e resolution ", 0.1);
51 }
52 
53 PindiodeStudyModule::~PindiodeStudyModule()
54 {
55 }
56 
57 //This module is a histomodule. Any histogram created here will be saved by the HistoManager module
58 void PindiodeStudyModule::defineHisto()
59 {
60  //Default values are set here. New values can be in PINDIODE.xml.
61  for (int i = 0; i < 4; i++) {
62  h_pin_rate[i] = new TH1F(TString::Format("pin_rate_%d", i), "Count", 64, 0., 64.);
63  h_pin_rate[i]->Sumw2();
64  }
65  for (int i = 0; i < 2; i++) {
66  h_pin_rs_rate[i] = new TH2F(TString::Format("pin_rs_rate_%d", i), "Count vs. ring section", 64, 0., 64., 12, 0., 12.);
67  h_pin_rs_rate[i]->Sumw2();
68  }
69  for (int i = 0; i < 64; i++) {
70  h_pin_dose1[i] = new TH1F(TString::Format("pin_dose1_%d", i), "", 10000, 0., 10000.);
71  h_pin_dose2[i] = new TH1F(TString::Format("pin_dose2_%d", i), "", 10000, 0., 10000.);
72  h_pin_dose1Weight[i] = new TH1F(TString::Format("pin_dose1Weight_%d", i), "", 10000, 0., 10000.);
73  h_pin_dose2Weight[i] = new TH1F(TString::Format("pin_dose2Weight_%d", i), "", 10000, 0., 10000.);
74  h_pin_volt[i] = new TH1F(TString::Format("pin_volt_%d", i), "", 10000, 0., 100.);
75  h_pin_time[i] = new TH1F(TString::Format("pin_time_%d", i), "", 1000, 0., 100.);
76  h_pin_vtime[i] = new TH1F(TString::Format("pin_vtime_%d", i), "", 1000, 0., 100.);
77 
78  h_pin_idose[i] = new TH1F(TString::Format("pin_idose_%d", i), "", 10000, 0., 10000.);
79  h_pin_idoseWeight[i] = new TH1F(TString::Format("pin_idoseWeight_%d", i), "", 10000, 0., 10000.);
80 
81  h_pin_rs_idose[i] = new TH2F(TString::Format("pin_rs_idose_%d", i), "", 10000, 0., 10000., 12, 0., 12.);
82  h_pin_rs_idoseWeight[i] = new TH2F(TString::Format("pin_rs_idoseWeight_%d", i), "", 10000, 0., 10000., 12, 0., 12.);
83 
84  h_pin_ivolt[i] = new TH1F(TString::Format("pin_ivolt_%d", i), "", 10000, 0., 100.);
85  h_pin_itime[i] = new TH1F(TString::Format("pin_itime_%d", i), "", 1000, 0., 100.);
86  h_pin_ivtime[i] = new TH1F(TString::Format("pin_ivtime_%d", i), "", 1000, 0., 100.);
87 
88  h_pin_dose1[i]->Sumw2();
89  h_pin_dose2[i]->Sumw2();
90  h_pin_dose1Weight[i]->Sumw2();
91  h_pin_dose2Weight[i]->Sumw2();
92  h_pin_idose[i]->Sumw2();
93  h_pin_idoseWeight[i]->Sumw2();
94  h_pin_rs_idose[i]->Sumw2();
95  h_pin_rs_idoseWeight[i]->Sumw2();
96  }
97 
98 }
99 
100 
101 void PindiodeStudyModule::initialize()
102 {
103  B2INFO("PindiodeStudyModule: Initialize");
104 
105  //read pindiode xml file
106  getXMLData();
107 
108  REG_HISTOGRAM
109 
110 }
111 
112 void PindiodeStudyModule::beginRun()
113 {
114 }
115 
116 void PindiodeStudyModule::event()
117 {
118  //Here comes the actual event processing
119 
122  StoreArray<SADMetaHit> MetaHits;
123 
124  //Look at the meta data to extract IR rate and scattering ring section
125  double rate = 0;
126  int ring_section = -1;
127  int section_ordering[12] = {1, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2};
128  for (const auto& MetaHit : MetaHits) {
129  rate = MetaHit.getrate();
130  double sad_ssraw = MetaHit.getssraw();
131  double ssraw = 0;
132  if (sad_ssraw >= 0) ssraw = sad_ssraw / 100.;
133  else if (sad_ssraw < 0) ssraw = 3000. + sad_ssraw / 100.;
134  ring_section = section_ordering[(int)((ssraw) / 250.)] - 1;
135  //ring_section = MetaHit.getring_section() - 1;
136  }
137 
138  //Skip events with no Hits
139  if (SimHits.getEntries() == 0) {
140  return;
141  }
142 
143  for (const auto& SimHit : SimHits) {
144  int detNb = SimHit.getCellId();
145  if (detNb < 64) {
146  double edep = SimHit.getEnergyDep();
147  double time = SimHit.getFlightTime();
148  //int PDG = aHit->getPDGCode();
149  const double meanEl = edep / m_WorkFunction * 1e9; //GeV to eV
150  const double sigma = sqrt(m_FanoFactor * meanEl); //sigma in electron
151  const int NbEle = (int)gRandom->Gaus(meanEl, sigma); //electron number
152  double volt = NbEle * 1.602176565e-19 * m_CrematGain * 1e12; // volt
153  h_pin_dose1[detNb]->Fill(edep * 1e6); //GeV to keV
154  h_pin_dose1Weight[detNb]->Fill(edep * 1e6, rate); //GeV to keV
155  if ((edep * 1e9) > m_WorkFunction) {
156  h_pin_dose2[detNb]->Fill(edep * 1e6); //GeV to keV
157  h_pin_dose2Weight[detNb]->Fill(edep * 1e6, rate); //GeV to keV
158  h_pin_volt[detNb]->Fill(volt * 1e3); //V to mV
159  h_pin_time[detNb]->Fill(time);
160  h_pin_vtime[detNb]->Fill(time, volt);
161  h_pin_rate[0]->Fill(detNb);
162  h_pin_rate[1]->Fill(detNb, rate);
163  }
164  }
165  }
166 
167  for (const auto& Hit : Hits) {
168  int detNb = Hit.getdetNb();
169  if (detNb < 64) {
170  double edep = Hit.getedep();
171  double volt = Hit.getV();
172  double time = Hit.gettime();
173  h_pin_idose[detNb]->Fill(edep); //keV
174  h_pin_idoseWeight[detNb]->Fill(edep, rate); //keV
175  h_pin_ivolt[detNb]->Fill(volt * 1e3); //V to mV
176  h_pin_itime[detNb]->Fill(time);
177  h_pin_ivtime[detNb]->Fill(time, volt);
178  h_pin_rate[2]->Fill(detNb);
179  h_pin_rate[3]->Fill(detNb, rate);
180 
181  h_pin_rs_rate[0]->Fill(detNb, ring_section);
182  h_pin_rs_rate[1]->Fill(detNb, ring_section, rate);
183  h_pin_rs_idose[detNb]->Fill(edep, ring_section); //keV
184  h_pin_rs_idoseWeight[detNb]->Fill(edep, ring_section, rate); //keV
185  }
186  }
187 
188 
189 }
190 //read tube centers, impulse response, and garfield drift data filename from PINDIODE.xml
191 void PindiodeStudyModule::getXMLData()
192 {
193  GearDir content = GearDir("/Detector/DetectorComponent[@name=\"PINDIODE\"]/Content/");
194  /*
195  //get the location of the tubes
196  BOOST_FOREACH(const GearDir & activeParams, content.getNodes("Active")) {
197 
198  PINCenter.push_back(TVector3(activeParams.getLength("z_pindiode"), activeParams.getLength("r_pindiode"),
199  activeParams.getLength("Phi")));
200  nPIN++;
201  }
202  */
203  m_CrematGain = content.getDouble("CrematGain");
204  m_WorkFunction = content.getDouble("WorkFunction");
205  m_FanoFactor = content.getDouble("FanoFactor");
206 
207  B2INFO("PinDigitizer");
208 
209 }
210 void PindiodeStudyModule::endRun()
211 {
212 
213 
214 }
215 
216 void PindiodeStudyModule::terminate()
217 {
218 }
219 
220 
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::GearDir
GearDir is the basic class used for accessing the parameter store.
Definition: GearDir.h:41
Belle2::pindiode::PindiodeStudyModule
Study module for Pindiodes (BEAST)
Definition: PindiodeStudyModule.h:39
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
Belle2::Hit
Structure to hold some of the calpulse data.
Definition: TOPTimeBaseCalibratorModule.h:40