Bartender LYSO
Digitizer simulation for the LYSO calorimeter prototype
Loading...
Searching...
No Matches
bartender.cc
Go to the documentation of this file.
1//****************************************************************************//
2// Lorenzo Bianco 13/11/2023 //
3// //
4// My 'Bartender' for the LYSO calorimeter prototype //
5// //
6//****************************************************************************//
7
12#include <iostream>
13#include <vector>
14#include <chrono>
15#include <cstring>
16
17#include <TFile.h>
18#include <TTree.h>
19
20#include "globals.hh"
21#include "configure.hh"
22#include "bar.hh"
23#include "SiPM.hh"
24#include "summary.hh"
25
26
27using namespace std;
28
43int main(int argc, char** argv)
44{
45 // Get input files
46 const char *mcFilename = argv[1];
47 const char *sipmFilename = argv[2];
48 Int_t threadID = -1;
49 bool isMultithreading = false;
50 Int_t maxEvents = -1;
51
52 // Control for multithreading and max events
53 for (int i = 3; i < argc; ++i) {
54 if (std::strcmp(argv[i], "-t") == 0 || std::strcmp(argv[i], "-T") == 0) {
55 if (i + 1 < argc) {
56 try {
57 maxEvents = std::stoi(argv[++i]);
58 } catch (const std::invalid_argument& e) {
59 std::cerr << "Errore: il valore dopo -t o -T non è un numero valido\n";
60 return 1;
61 }
62 } else {
63 std::cerr << "Errore: specificare il numero di eventi dopo -t o -T\n";
64 return 1;
65 }
66 } else if (threadID == -1) {
67 try {
68 threadID = std::stoi(argv[i]);
69 isMultithreading = true;
70 } catch (const std::invalid_argument& e) {
71 std::cerr << "Errore: il valore del threadID non è un numero valido\n";
72 return 1;
73 }
74 }
75}
76
77
78 if(!isMultithreading)
79 cout << "BarST>> Start" << endl;
80 else
81 cout << "BarWT" << threadID << ">> Start" << endl;
82
83 // Instances and configuration of SiPM and BarLYSO
84 SiPM *sipm = new SiPM();
85 BarLYSO *bar = new BarLYSO(mcFilename, threadID);
86 Bartender_Configure(sipmFilename, bar, sipm);
87
88 // Set parameters and load TTree
89 bar->SetParsDistro();
90 unique_ptr<TFile> mcFile(TFile::Open(mcFilename, "READ"));
91 TTree *lyso = mcFile->Get<TTree>("lyso");
92
93 lyso->SetBranchStatus("*", false);
94 lyso->SetBranchStatus("Event", true);
95 lyso->SetBranchStatus("NHits_F", true);
96 lyso->SetBranchStatus("NHits_B", true);
97 lyso->SetBranchStatus("T_F", true);
98 lyso->SetBranchStatus("Ch_F", true);
99 lyso->SetBranchStatus("T_B", true);
100 lyso->SetBranchStatus("Ch_B", true);
101
102 Int_t fEvent;
103 Int_t fNHits_F, fNHits_B;
104 vector<Double_t> *fT_F = 0, *fT_B = 0;
105 vector<Int_t> *fCh_F = 0, *fCh_B = 0;
106
107 lyso->SetBranchAddress("Event", &fEvent);
108 lyso->SetBranchAddress("NHits_F", &fNHits_F);
109 lyso->SetBranchAddress("NHits_B", &fNHits_B);
110 lyso->SetBranchAddress("Ch_F", &fCh_F);
111 lyso->SetBranchAddress("Ch_B", &fCh_B);
112 lyso->SetBranchAddress("T_F", &fT_F);
113 lyso->SetBranchAddress("T_B", &fT_B);
114
115 // Number of events and initialize containers
116 Int_t nEntries = lyso->GetEntries();
117 if(maxEvents > 0 && maxEvents < nEntries)
118 nEntries = maxEvents;
119 bar->SetEvents(nEntries);
120
121 if(!isMultithreading)
122 cout << "BarST>> Trees loaded. Starting Bartender for " << nEntries << " events" << endl;
123 else
124 cout << "BarWT" << threadID << ">> Trees loaded. Starting Bartender for " << nEntries << " events" << endl;
125
126 // Start with the Bartender
127 auto start_chrono = chrono::high_resolution_clock::now();
128
129 // Sampling times
130 bar->SetSamplingTimes();
131
132 // Event loop
133 for(Int_t k = 0; k < nEntries; k++)
134 {
135 lyso->GetEntry(k);
136
137 bar->InitializeBaselines(fEvent);
138
139 for(Int_t j = 0; j < fNHits_F; j++)
140 bar->SetFrontWaveform(fCh_F->data()[j], fT_F->data()[j]);
141
142 for(Int_t j = 0; j < fNHits_B; j++)
143 bar->SetBackWaveform(fCh_B->data()[j], fT_B->data()[j]);
144
145 bar->SaveEvent();
146 bar->ClearContainers();
147
148 if(nEntries < 10 || k % (nEntries / 10) == 0)
149 {
150 if(!isMultithreading)
151 cout << "\rBarST>> Processed " << k + 1 << " events" << flush;
152 else
153 cout << "\rBarWT" << threadID << ">> Processed " << k + 1 << " events" << flush;
154 }
155 }
156 cout << endl;
157
158 // Save data
159 bar->SaveBar();
160
161 auto end_chrono = chrono::high_resolution_clock::now();
162 chrono::duration<double> duration = end_chrono - start_chrono;
163
164 // Single-thread summary
165 if(!isMultithreading)
166 {
167 Bartender_Summary(sipmFilename, bar->GetID(), duration.count());
168 }
169
170 // Free memory
171 lyso->ResetBranchAddresses();
172 delete fT_F, fT_B, fCh_F, fCh_B;
173 delete sipm;
174 delete bar;
175
176 // Finally
177 return 0;
178}
Definition of the struct SiPM.
Declaration of the class BarLYSO.
int main(int argc, char **argv)
Main of the application.
Definition bartender.cc:43
Class for managing waveform construction for all events and channels.
Definition bar.hh:28
void SaveEvent()
Saves all the samples from fFront and fBack into a text file.
Definition bar.cc:273
void InitializeBaselines(Int_t event)
Method to initialize the entire fFront and fBack with a noise baseline.
Definition bar.cc:220
void SetParsDistro()
Sets the 3D histogram hPars.
Definition bar.cc:167
void SetBackWaveform(Int_t channel, Double_t start)
Method to add a I-Phel waveform to the corresponding event and channel of the Back-Detector.
Definition bar.cc:258
void ClearContainers()
Method to add a I-Phel waveform to the corresponding event and channel of the Front-Detector.
Definition bar.cc:229
Int_t GetID() const
Returns the ID of the Monte Carlo.
Definition bar.hh:155
void Bartender_Configure(const char *filename, BarLYSO *bar, SiPM *sipm)
Reads and processes a specific file to populate members of the BarLYSO class and SiPM struct.
Definition configure.cc:44
Declaration of the function Bartender_Configure() (and the auxiliary function extract_value())
Definition of global constant values for the simulation.
Struct for storing MPPC/SiPM settings for waveform generation.
Definition SiPM.hh:14