This macro reads outputs from "HIClusterGeoFiller.py" and performs a linear regression with prepared values.
The input file names shall contain the run number. There has to be one file per run; ideally, every run mentioned in the GRL has its corresponding file and every LB mentioned in the GRL has its corresponding histogram in that file. The slope and intercept of the linear regression are written to an output files as response and offset. Response values are normalized to unity along the phi angle, i.e. in each eta slice. In the final root weight file, there are also histograms "h3_w", "h3_eta", "h3_phi", and "h3_R". These are produced by "HICaloGeoExtract.py".
88 {
89 if (argc <= 2) {
90 std::cout <<
"Syntax: " <<
argv[0] <<
" GoodRunList.xml /path/to/input/files/first.part. [.second.part [...]]" << std::endl;
91 return -1;
92 }
93
96
97
98
99
100
101
102
103
104 if (grlMap.size() == 0) {
105 std::cout <<
"No runs found, is the GRL file (" <<
argv[1] <<
") correct?" << std::endl;
106 return -1;
107 }
108
109 std::vector<int>
runs;
110 for (
auto &
run : grlMap) {
112 }
114
115
116 auto runIndex=std::make_unique<TH1I>(
"h1_run_index",
"h1_run_index",
runs.size(), 0,
runs.size());
117 for (
unsigned int r = 0;
r <
runs.size();
r++) {
118 runIndex->SetBinContent(
r + 1,
runs.at(
r));
119 }
120
121
122 std::string fileNameTemplate="";
123 for(
int a = 2;
a <
argc; ++
a) {
124 fileNameTemplate += std::string(argv[
a]);
126
127 fileNameTemplate += std::string("%d");
128 }
129 }
130
132 std::unique_ptr<TH3F>
offset;
134 std::unique_ptr<TH2F> etaPhiMap;
135
136
137 for (
unsigned int r = 0;
r <
runs.size();
r++) {
139
141
142 std::unique_ptr<TChain> filesChain = std::make_unique<TChain>("");
143
144 filesChain->Add(fileNamePattern.c_str());
145 TObjArray *
files = filesChain->GetListOfFiles();
146
147 if (
files->IsEmpty()) {
148 std::cout <<
"Could not open any file with pattern " << fileNamePattern <<
", skipping the run " <<
run << std::endl;
149 continue;
150 }
151
152 int filesNum =
files->GetEntries();
153 std::cout << "Opened " << filesNum << " file" << (filesNum > 1 ? "s" : "") << " with pattern " << fileNamePattern
154 <<
", processing the run " <<
run << std::endl;
155
156 std::unique_ptr<TH2F> sums;
157
158
160 TChainElement * fileEl = 0;
161 while (( fileEl = (TChainElement*)
next() )) {
162 std::unique_ptr<TFile>
file = std::make_unique<TFile>(fileEl->GetTitle());
163 std::cout <<
"Processing file " <<
file->GetName() << std::endl;
164
165 if (!etaPhiMap) {
166
167 etaPhiMap = std::make_unique<TH2F>(*(TH2F*)
file->Get<TH2F>(
"h_etaPhiMapping"));
168 etaPhiMap->SetDirectory(nullptr);
169
170
172 std::make_unique<TH3F>("h3_eta_phi_response", "h3_eta_phi_response",
173 etaPhiMap->GetNbinsX(), etaPhiMap->GetXaxis()->GetXmin(), etaPhiMap->GetXaxis()->GetXmax(),
174 etaPhiMap->GetNbinsY(), etaPhiMap->GetYaxis()->GetXmin(), etaPhiMap->GetYaxis()->GetXmax(),
177 offset = std::make_unique<TH3F>(*(TH3F*)
response->Clone(
"h3_eta_phi_offset"));
178 offset->SetTitle(
"h3_eta_phi_offset");
179 offset->SetDirectory(
nullptr);
180 entries = std::make_unique<TH3F>(*(TH3F*)
response->Clone(
"h3_eta_phi_entries"));
181 entries->SetTitle(
"h3_eta_phi_entries");
182 entries->SetDirectory(
nullptr);
183 }
184
185
186 for (
auto &lbs : grlMap[
run]) {
187
189 std::unique_ptr<TH2F>
tmp(
file->Get<TH2F>(Form(
"h_clusterET_fcalET_%d_%d",
run,
lb)));
190 if (!tmp) {
191 std::cout <<
"Could not get h_clusterET_fcalET_" <<
run <<
"_" <<
lb <<
", skipping this LB, r = "<<
r << std::endl;
192 continue;
193 }
194
195
196 if (!sums) {
197 sums = std::make_unique<TH2F>(*(TH2F*)
tmp->Clone(
"h_clusterET_fcalET_sum"));
198 sums->SetDirectory(nullptr);
199 }
200 else {
201 sums->Add(
tmp.get());
202 }
203 }
204 }
205 }
206
207 if(!sums)
208 {
209 std::cout <<
"Could not get any LB, skipping the run " <<
run <<std::endl;
210 continue;
211 }
212
213
214 for (int binID = 1; binID <= sums->GetNbinsX(); binID++) {
215 float numEntries = sums->GetBinContent(binID, 6);
216 if (numEntries == 0) {
217
218 continue;
219 }
220
222 etaPhiMap->GetBinXYZ(binID - 1,
eta,
phi, dummy);
223
224 float sumFCalET = sums->GetBinContent(binID, 1);
225 float sumClusterET = sums->GetBinContent(binID, 2);
226 float sumFCalET2 = sums->GetBinContent(binID, 3);
227
228 float sumFCalET_clusterET = sums->GetBinContent(binID, 5);
229
230 float avgFCalET = sumFCalET / numEntries;
231 float avgClusterET = sumClusterET / numEntries;
232 float delta = sumFCalET2 - 2 * sumFCalET * avgFCalET + numEntries * avgFCalET * avgFCalET;
233 if (delta == 0) {
234 continue;
235 }
236
237
238 float resp = (sumFCalET_clusterET - sumClusterET * avgFCalET) / delta;
239 float offs = avgClusterET - avgFCalET * resp;
240
241 if (resp < 0) {
242 resp = 0;
243 }
244
248 }
249 }
250
252 std::cout << "Could not create response or offset" << std::endl;
253 return -1;
254 }
255
256 entries->GetXaxis()->SetRangeUser(-1.99,1.99);
257 std::unique_ptr<TH1F> avgEntries((TH1F *)
entries->Project3D(
"z"));
258 avgEntries->Scale(1.0 / ((
entries->GetXaxis()->GetLast() -
entries->GetXaxis()->GetFirst()+1) *
entries->GetNbinsY()));
259 entries->GetXaxis()->SetRange(0,0);
260
261
263
264
265 float limitEntries = 0.1 * avgEntries->GetBinContent(
r);
266
268 int entr = 0;
270
273
274 continue;
275 }
277 ++entr;
278 }
279
280 if(entr > 0) {
282 }
283 else {
285 }
286
291 } else {
293 if(std::isnan(resp) || resp<=0.) {
294 resp = 1.0;
295 }
296
298 }
299 }
300 }
301 }
302
303
304
305 std::unique_ptr<TFile>
outFile(TFile::Open(
"cluster.geo.RESPONSE_OFFSET_RUNINDEX.root",
"RECREATE"));
306 runIndex->Write();
309
310 std::cout << "Created output file cluster.geo.RESPONSE_OFFSET_RUNINDEX.root" << std::endl;
311 return 0;
312}
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
std::vector< std::string > files
file names and file pointers
std::unordered_map< int, std::vector< std::pair< int, int > > > getGRLMap(char *grl)
Reads the GRL .xml file and creates an unordered map of run numbers and associated LB ranges.
std::string getFileNamePattern(std::string name, int runNr)
Gets a string with "%d" and replaces them with the same run number.
outFile
Comment Out Those You do not wish to run.
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.