Newer
Older
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
#include <TFile.h>
#include <TTree.h>
#include "ScalerCalib.h"
using namespace std;
ofstream outfile;
//_________________________________
ScalerCalib::ScalerCalib(string name) :
fName(name), fPrintFlag(DEFAULT)
{
filename = "dummyname";
}
//_________________________________
ScalerCalib::~ScalerCalib()
{
}
//_________________________________
int ScalerCalib::Run()
{
FillContainer();
if(evnum.size() < 1)
{
cout << "ERROR: empty container! Check the input file" << endl;
return -1;
}
int pos = filename.find("scalers_");
runstr = (filename.substr(pos+8)).substr(0,4);
ofilename = "bcmcurrent_" + runstr + ".param";
outfile.open(ofilename.c_str());
outfile << "num_scal_reads = " << evnum.size();
outfile << "\n" << "\n";
outfile << "scal_read_bcm1_current = ";
PrintContainer(bcm1);
outfile << "\n" << "\n";
outfile << "scal_read_bcm2_current = ";
PrintContainer(bcm2);
if(fPrintFlag == ALL)
{
outfile << "\n" << "\n";
outfile << "scal_read_bcm4a_current = ";
PrintContainer(bcm4a);
outfile << "\n" << "\n";
outfile << "scal_read_bcm4b_current = ";
PrintContainer(bcm4b);
outfile << "\n" << "\n";
outfile << "scal_read_bcm17_current = ";
PrintContainer(bcm17);
}
// outfile.close();
return 0;
}
//_________________________________
int ScalerCalib::PrintContainer(ScalerContainer sc)
{
if(sc.size() < 1)
if(evnum.size() < 1)
{
cout << "ERROR: empty container!" << endl;
return -1;
}
for(SCIterator i = sc.begin(); i != sc.end()-1; ++i)
{
outfile << *i << ", ";
}
outfile << sc.back();
/*
stringstream sstr;
string result;
std::copy(sc.begin(), sc.end()-1, ofstream_iterator<double>(sstr, ", "));
sstr << sc.end();
result = sstr.str();
outfile << result;
result = "";
sstr.str("");
sstr.clear();
*/
return 0;
}
//_________________________________
int ScalerCalib::FillContainer()
{
ClearContainers();
TFile* file = new TFile(filename.c_str());
if(!file->IsOpen())
{
cout << "ERROR: " << filename.c_str() << " is not open!" << endl;
return -1;
}
if(! file->GetListOfKeys()->Contains("TSH") )
{
cout << "ERROR: Couldn't find the Scaler Tree" << endl;
return -1;
}
TTree* T = (TTree*)file->Get("TSH");
double evnumber;
double bcm1_current;
double bcm2_current;
double bcm4a_current;
double bcm4b_current;
double bcm17_current;
string bname[5];
string sarray[5] = {".BCM1.scalerCurrent",
".BCM2.scalerCurrent",
".BCM4A.scalerCurrent",
".BCM4B.scalerCurrent",
".BCM17.scalerCurrent"};
for(int i=0; i<5; i++)
{
bname[i] = "";
bname[i] += fName;
bname[i] += sarray[i];
}
T->SetBranchAddress("evNumber", &evnumber);
T->SetBranchAddress(bname[0].c_str(), &bcm1_current);
T->SetBranchAddress(bname[1].c_str(), &bcm2_current);
T->SetBranchAddress(bname[2].c_str(), &bcm4a_current);
T->SetBranchAddress(bname[3].c_str(), &bcm4b_current);
T->SetBranchAddress(bname[4].c_str(), &bcm17_current);
Long64_t nentries = T->GetEntries();
for(Long64_t ientry=0; ientry<nentries; ientry++)
{
T->GetEntry(ientry);
evnum.push_back(evnumber);
bcm1.push_back(bcm1_current);
bcm2.push_back(bcm2_current);
bcm4a.push_back(bcm4a_current);
bcm4b.push_back(bcm4b_current);
bcm17.push_back(bcm17_current);
}
file->Close();
return 0;
}
//_________________________________
void ScalerCalib::ClearContainers()
{
evnum.clear();
bcm1.clear();
bcm2.clear();
bcm4a.clear();
bcm4b.clear();
bcm17.clear();
}
ClassImp(ScalerCalib)