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
16#include <TFile.h>
17#include <TTree.h>
18
19#include "globals.hh"
20#include "configure.hh"
21#include "bar.hh"
22#include "SiPM.hh"
23#include "summary.hh"
24
25
26using namespace std;
27
42int main(int argc, char** argv)
43{
44 // Get input files
45 const char *mcFilename = argv[1];
46 const char *sipmFilename = argv[2];
47 Int_t threadID = -1;
48 bool isMultithreading = false;
49
50 if(argc == 4)
51 {
52 threadID = std::stoi(argv[3]);
53 isMultithreading = true;
54 }
55
56 if(!isMultithreading)
57 cout << "BarST>> Start" << endl;
58 else
59 cout << "BarWT" << threadID << ">> Start" << endl;
60
61 // Instances and configuration of SiPM and BarLYSO
62 SiPM *sipm = new SiPM();
63 BarLYSO *bar = new BarLYSO(mcFilename, threadID);
64 Bartender_Configure(sipmFilename, bar, sipm);
65
66 // Set parameters and load TTree
67 bar->SetParsDistro();
68 unique_ptr<TFile> mcFile(TFile::Open(mcFilename, "READ"));
69 TTree *lyso = mcFile->Get<TTree>("lyso");
70
71 lyso->SetBranchStatus("*", false);
72
73 lyso->SetBranchStatus("Event", true);
74 lyso->SetBranchStatus("NHits_F", true);
75 lyso->SetBranchStatus("NHits_B", true);
76 lyso->SetBranchStatus("T_F", true);
77 lyso->SetBranchStatus("Ch_F", true);
78 lyso->SetBranchStatus("T_B", true);
79 lyso->SetBranchStatus("Ch_B", true);
80
81 Int_t fEvent;
82 Int_t fNHits_F, fNHits_B;
83 vector<Double_t> *fT_F = 0, *fT_B = 0;
84 vector<Int_t> *fCh_F = 0, *fCh_B = 0;
85
86 lyso->SetBranchAddress("Event", &fEvent);
87 lyso->SetBranchAddress("NHits_F", &fNHits_F);
88 lyso->SetBranchAddress("NHits_B", &fNHits_B);
89 lyso->SetBranchAddress("Ch_F", &fCh_F);
90 lyso->SetBranchAddress("Ch_B", &fCh_B);
91 lyso->SetBranchAddress("T_F", &fT_F);
92 lyso->SetBranchAddress("T_B", &fT_B);
93
94 // Number of events and initialize containers
95 Int_t nEntries = lyso->GetEntries();
96 bar->SetEvents(nEntries);
97
98 if(!isMultithreading)
99 cout << "BarST>> Trees loaded. Starting Bartender for " << nEntries << " events" << endl;
100 else
101 cout << "BarWT" << threadID << ">> Trees loaded. Starting Bartender for " << nEntries << " events" << endl;
102
103 // Start with the Bartender
104 auto start_chrono = chrono::high_resolution_clock::now();
105
106 // Sampling times
107 bar->SetSamplingTimes();
108
109 // Event loop
110 for(Int_t k = 0; k < nEntries; k++)
111 {
112 lyso->GetEntry(k);
113
114 bar->InitializeBaselines(fEvent);
115
116 for(Int_t j = 0; j < fNHits_F; j++)
117 bar->SetFrontWaveform(fCh_F->data()[j], fT_F->data()[j]);
118
119 for(Int_t j = 0; j < fNHits_B; j++)
120 bar->SetBackWaveform(fCh_B->data()[j], fT_B->data()[j]);
121
122 bar->SaveEvent();
123 bar->ClearContainers();
124
125
126 if(nEntries < 10 || k % (nEntries / 10) == 0)
127 {
128 if(!isMultithreading)
129 cout << "\rBarST>> Processed " << k + 1 << " events" << flush;
130 else
131 cout << "\rBarWT" << threadID << ">> Processed " << k + 1 << " events" << flush;
132 }
133 }
134
135 // Save data
136 bar->SaveBar();
137
138 auto end_chrono = chrono::high_resolution_clock::now();
139 chrono::duration<double> duration = end_chrono - start_chrono;
140
141 // Single-thread summary
142 if(!isMultithreading)
143 {
144 Bartender_Summary(sipmFilename, bar->GetID(), duration.count());
145 }
146
147 // Free memory
148 lyso->ResetBranchAddresses();
149 delete fT_F, fT_B, fCh_F, fCh_B;
150 delete sipm;
151 delete bar;
152
153 // Finally
154 return 0;
155}
Definition of the struct SiPM.
Declaration of the class BarLYSO.
int main(int argc, char **argv)
Main of the application.
Definition bartender.cc:42
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:263
void InitializeBaselines(Int_t event)
Method to initialize the entire fFront and fBack with a noise baseline.
Definition bar.cc:210
void SetParsDistro()
Sets the 3D histogram hPars.
Definition bar.cc:157
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:248
void ClearContainers()
Method to add a I-Phel waveform to the corresponding event and channel of the Front-Detector.
Definition bar.cc:219
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