43int main(
int argc,
char** argv)
46 const char *mcFilename = argv[1];
47 const char *sipmFilename = argv[2];
49 bool isMultithreading =
false;
53 for (
int i = 3; i < argc; ++i) {
54 if (std::strcmp(argv[i],
"-t") == 0 || std::strcmp(argv[i],
"-T") == 0) {
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";
63 std::cerr <<
"Errore: specificare il numero di eventi dopo -t o -T\n";
66 }
else if (threadID == -1) {
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";
79 cout <<
"BarST>> Start" << endl;
81 cout <<
"BarWT" << threadID <<
">> Start" << endl;
90 unique_ptr<TFile> mcFile(TFile::Open(mcFilename,
"READ"));
91 TTree *lyso = mcFile->Get<TTree>(
"lyso");
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);
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;
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);
116 Int_t nEntries = lyso->GetEntries();
117 if(maxEvents > 0 && maxEvents < nEntries)
118 nEntries = maxEvents;
119 bar->SetEvents(nEntries);
121 if(!isMultithreading)
122 cout <<
"BarST>> Trees loaded. Starting Bartender for " << nEntries <<
" events" << endl;
124 cout <<
"BarWT" << threadID <<
">> Trees loaded. Starting Bartender for " << nEntries <<
" events" << endl;
127 auto start_chrono = chrono::high_resolution_clock::now();
130 bar->SetSamplingTimes();
133 for(Int_t k = 0; k < nEntries; k++)
139 for(Int_t j = 0; j < fNHits_F; j++)
140 bar->SetFrontWaveform(fCh_F->data()[j], fT_F->data()[j]);
142 for(Int_t j = 0; j < fNHits_B; j++)
148 if(nEntries < 10 || k % (nEntries / 10) == 0)
150 if(!isMultithreading)
151 cout <<
"\rBarST>> Processed " << k + 1 <<
" events" << flush;
153 cout <<
"\rBarWT" << threadID <<
">> Processed " << k + 1 <<
" events" << flush;
161 auto end_chrono = chrono::high_resolution_clock::now();
162 chrono::duration<double> duration = end_chrono - start_chrono;
165 if(!isMultithreading)
167 Bartender_Summary(sipmFilename, bar->
GetID(), duration.count());
171 lyso->ResetBranchAddresses();
172 delete fT_F, fT_B, fCh_F, fCh_B;