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".
90 std::cout <<
"Syntax: " <<
argv[0] <<
" GoodRunList.xml /path/to/input/files/first.part. [.second.part [...]]" << std::endl;
104 if (grlMap.size() == 0) {
105 std::cout <<
"No runs found, is the GRL file (" <<
argv[1] <<
") correct?" << std::endl;
109 std::vector<int>
runs;
110 for (
auto &
run : grlMap) {
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));
122 std::string fileNameTemplate=
"";
123 for(
int a = 2;
a <
argc; ++
a) {
124 fileNameTemplate += std::string(
argv[
a]);
127 fileNameTemplate += std::string(
"%d");
132 std::unique_ptr<TH3F>
offset;
134 std::unique_ptr<TH2F> etaPhiMap;
137 for (
unsigned int r = 0;
r <
runs.size();
r++) {
142 std::unique_ptr<TChain> filesChain = std::make_unique<TChain>(
"");
144 filesChain->Add(fileNamePattern.c_str());
145 TObjArray *
files = filesChain->GetListOfFiles();
147 if (
files->IsEmpty()) {
148 std::cout <<
"Could not open any file with pattern " << fileNamePattern <<
", skipping the run " <<
run << std::endl;
152 int filesNum =
files->GetEntries();
153 std::cout <<
"Opened " << filesNum <<
" file" << (filesNum > 1 ?
"s" :
"") <<
" with pattern " << fileNamePattern
154 <<
", processing the run " <<
run << std::endl;
156 std::unique_ptr<TH2F> sums;
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;
167 etaPhiMap = std::make_unique<TH2F>(*(
TH2F*)
file->Get<
TH2F>(
"h_etaPhiMapping"));
168 etaPhiMap->SetDirectory(
nullptr);
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);
186 for (
auto &
lbs : grlMap[
run]) {
189 std::unique_ptr<TH2F>
tmp(
file->Get<
TH2F>(Form(
"h_clusterET_fcalET_%d_%d",
run,
lb)));
191 std::cout <<
"Could not get h_clusterET_fcalET_" <<
run <<
"_" <<
lb <<
", skipping this LB, r = "<<
r << std::endl;
197 sums = std::make_unique<TH2F>(*(
TH2F*)
tmp->Clone(
"h_clusterET_fcalET_sum"));
198 sums->SetDirectory(
nullptr);
201 sums->Add(
tmp.get());
209 std::cout <<
"Could not get any LB, skipping the run " <<
run <<std::endl;
214 for (
int binID = 1; binID <= sums->GetNbinsX(); binID++) {
215 float numEntries = sums->GetBinContent(binID, 6);
216 if (numEntries == 0) {
224 float sumFCalET = sums->GetBinContent(binID, 1);
225 float sumClusterET = sums->GetBinContent(binID, 2);
226 float sumFCalET2 = sums->GetBinContent(binID, 3);
228 float sumFCalET_clusterET = sums->GetBinContent(binID, 5);
230 float avgFCalET = sumFCalET / numEntries;
231 float avgClusterET = sumClusterET / numEntries;
232 float delta = sumFCalET2 - 2 * sumFCalET * avgFCalET + numEntries * avgFCalET * avgFCalET;
238 float resp = (sumFCalET_clusterET - sumClusterET * avgFCalET) / delta;
239 float offs = avgClusterET - avgFCalET * resp;
252 std::cout <<
"Could not create response or offset" << std::endl;
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);
265 float limitEntries = 0.1 * avgEntries->GetBinContent(
r);
293 if(std::isnan(resp) || resp<=0.) {
305 std::unique_ptr<TFile>
outFile(TFile::Open(
"cluster.geo.RESPONSE_OFFSET_RUNINDEX.root",
"RECREATE"));
310 std::cout <<
"Created output file cluster.geo.RESPONSE_OFFSET_RUNINDEX.root" << std::endl;