Repository navigation
Expand file tree
/
Copy pathMBReader.cpp
More file actions
219 lines (192 loc) · 6.5 KB
/
Copy pathMBReader.cpp
File metadata and controls
219 lines (192 loc) · 6.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#include "include/MBReader.h"
//____________________________________________________
MBReader::MBReader(TChain *Chain, bool IsDataCalibrated, const char * DataType) :
fChain(Chain),
fDegToRad(TMath::Pi()/180.),
fRadToDeg(180./TMath::Pi()),
fSpeedOfLight(29.9792),
fIsMB(false),
fIsDataCalibrated(IsDataCalibrated),
fMBGeometryLoaded(false),
fMBStatusLoaded(false),
fMBHitConditionLoaded(false),
fMBCentralityLoaded(false),
fMicroballStatus(new MBDetectorStatus()),
fMicroballGeometry(new MBGeometry()),
fMicroballHitCondition(new MBHitCondition()),
fMicroballCentrality(new MBImpactParameter())
{
//Parsing DataType string to allocate specific detectors
std::string DetectorsIncluded(DataType);
std::istringstream StreamDetectorsIncluded(DetectorsIncluded);
std::string DetectorToAdd;
while (StreamDetectorsIncluded>>DetectorToAdd) {
if(DetectorToAdd.compare("MB")==0) fIsMB=true;
}
if(fChain!=0) {
fMBReader = new TTreeReader(fChain);
if(!fIsDataCalibrated) {
if(fIsMB) fMicroball = new TTreeReaderValue<HTMicroballData>(*fMBReader, "uBall.");
} else {
if(fIsMB) fMicroballCal = new TTreeReaderValue<MicroballCalibratedData>(*fMBReader, "uBall.");
}
}
}
//____________________________________________________
MBReader::~MBReader()
{
if(fChain!=0) {
delete fMBReader;
if(!fIsDataCalibrated) {
if (fIsMB) delete fMicroball;
} else {
if (fIsMB) delete fMicroballCal;
}
}
}
//____________________________________________________
int MBReader::LoadMBGeometry(const char * file_name)
{
int NLines=fMicroballGeometry->LoadGeometry(file_name);
if(NLines>0) {
fMBGeometryLoaded=true;
printf("Loaded Microball geometry from file %s\n", file_name);
return NLines;
} else {
fMBGeometryLoaded=false;
printf("Error: Error while loading Microball geometry %s\n", file_name);
return -1;
}
}
//____________________________________________________
int MBReader::LoadMBDetectorStatus(const char * file_name)
{
int NLines=fMicroballStatus->LoadBadDetectors(file_name);
if(NLines>0) {
fMBStatusLoaded=true;
printf("Loaded Microball status from file %s\n", file_name);
return NLines;
} else {
fMBStatusLoaded=false;
printf("Error: Error while loading Microball status %s\n", file_name);
return -1;
}
}
//____________________________________________________
int MBReader::LoadMBFastSlowHitCondition(const char * file_name)
{
int NLines=fMicroballHitCondition->LoadFastSlowCuts(file_name);
if(NLines>0) {
fMBHitConditionLoaded=true;
printf("Loaded Microball Fast Slow Hit conditions from file %s\n", file_name);
return NLines;
} else {
fMBHitConditionLoaded=false;
printf("Error: Error while loading Microball Fast Slow Hit conditions %s\n", file_name);
return -1;
}
}
//____________________________________________________
int MBReader::LoadMBCentrality(const char * file_name)
{
int NLines=fMicroballCentrality->LoadImpactParameter(file_name);
if(NLines>0) {
fMBCentralityLoaded=true;
printf("Loaded Microball centrality conditions from file %s\n", file_name);
return NLines;
} else {
fMBCentralityLoaded=false;
printf("Error: Error while loading Microball centrality conditions %s\n", file_name);
return -1;
}
}
//____________________________________________________
double MBReader::GetTheta(int num_ring, int num_det) const
{
return fMBGeometryLoaded ? fMicroballGeometry->GetTheta(num_ring, num_det) : -9999;
}
//____________________________________________________
double MBReader::GetPhi(int num_ring, int num_det) const
{
return fMBGeometryLoaded ? fMicroballGeometry->GetPhi(num_ring, num_det) : -9999;
}
//____________________________________________________
double MBReader::GetThetaRandom(int num_ring, int num_det) const
{
return fMBGeometryLoaded ? fMicroballGeometry->GetThetaRandom(num_ring, num_det) : -9999;
}
//____________________________________________________
double MBReader::GetPhiRandom(int num_ring, int num_det) const
{
return fMBGeometryLoaded ? fMicroballGeometry->GetPhiRandom(num_ring, num_det) : -9999;
}
//____________________________________________________
double MBReader::GetImpactParameter(int multiplicity) const
{
return fMBCentralityLoaded ? fMicroballCentrality->GetImpactParameter(multiplicity) : -9999;
}
//____________________________________________________
double MBReader::Getbhat(int multiplicity) const
{
return fMBCentralityLoaded ? fMicroballCentrality->Getbhat(multiplicity) : -9999;
}
//____________________________________________________
bool MBReader::IsBad (int num_ring, int num_det) const
{
return fMBStatusLoaded ? fMicroballStatus->IsBad(num_ring,num_det) : false;
}
//____________________________________________________
bool MBReader::IsHit (int num_ring, int num_det, double fast, double tail, double time) const
{
return fMBHitConditionLoaded ? fMicroballHitCondition->IsHit(num_ring,num_det,fast,tail,time) : false;
}
//____________________________________________________
void MBReader::Loop(const char * file_name, Long64_t evt_amount)
{
// this method loops on the first "evt_amount" data entries
// and creates a ROOT otput file named "file_name"
// where the user can write some ROOT output
TFile * FileOut = new TFile(file_name, "RECREATE");
Long64_t nentries=fChain->GetEntries();
if(evt_amount!=0) {
nentries=evt_amount;
}
Long64_t jentry=0;
std::cout << "found " << nentries << " entries\n";
for(;fMBReader->Next() && jentry<nentries; jentry++)
{
if(jentry%100000==0) {
printf("Percentage = %.2f %%\n", 100*double(jentry)/nentries);
}
HTMicroballData * Microball = fMicroball->Get();
// Insert here code
jentry++;
}
// closing output file
FileOut->Close();
}
//____________________________________________________
void MBReader::LoopOnCalibratedData(const char * file_name, Long64_t evt_amount)
{
// this method loops on the first "evt_amount" data entries
// and creates a ROOT otput file named "file_name"
// where the user can write some ROOT output
TFile * FileOut = new TFile(file_name, "RECREATE");
Long64_t nentries=fChain->GetEntries();
if(evt_amount!=0) {
nentries=evt_amount;
}
Long64_t jentry=0;
std::cout << "found " << nentries << " entries\n";
for(;fMBReader->Next() && jentry<nentries; jentry++)
{
if(jentry%100000==0) {
printf("Percentage = %.2f %%\n", 100*double(jentry)/nentries);
}
MicroballCalibratedData * Microball = fMicroballCal->Get();
// Insert here code
jentry++;
}
// closing output file
FileOut->Close();
}