#include <iostream>
#include <fstream>
void tprofile2polyRealistic(
Int_t numEvents=100000)
{
int NUM_LS = 8;
TCanvas *c2 =
new TCanvas(
"c2",
"Merge Individual moving charge plots", 800, 400);
float minx = -15;
float maxx = 15;
float miny = -15;
float maxy = 15;
float binsz = 0.5;
for (float i = minx; i < maxx; i += binsz) {
for (float j = miny; j < maxy; j += binsz) {
tot_merge->AddBin(i, j, i + binsz, j + binsz);
for (
int l=0; l<NUM_LS; ++
l) {
tot_avg_ls[
l].AddBin(i, j, i + binsz, j + binsz);
}
}
}
ifstream infile;
TString dir =
gROOT->GetTutorialDir();
dir.Append("/hist/data/tprofile2poly_tutorial.data");
infile.open(dir.Data());
if (!infile)
{
std::cerr << dir.Data() << std::endl;
std::cerr << "Error code: " << strerror(errno) << std::endl;
return;
}
std::cout << " WE ARE AFTER LOADING DATA " << std::endl;
vector<pair<Double_t, Double_t>> allCoords;
while (infile >> a >> b) {
pair<Double_t, Double_t> coord(a, b);
allCoords.push_back(coord);
}
if (allCoords.size() % 3 != 0) {
cout << "[ERROR] Bad file" << endl;
return;
}
for (
Int_t i = 0; i < allCoords.size(); i += 3) {
x[0] = allCoords[i + 0].first;
y[0] = allCoords[i + 0].second;
x[1] = allCoords[i + 1].first;
y[1] = allCoords[i + 1].second;
x[2] = allCoords[i + 2].first;
y[2] = allCoords[i + 2].second;
det_avg_merge->AddBin(3, x, y);
det_err_merge->AddBin(3, x, y);
for (
int l=0; l<NUM_LS; ++
l) {
det_avg_ls[
l].AddBin(3, x, y);
}
}
std::cout << " WE ARE AFTER ADDING BINS " << std::endl;
for (int i = 0; i <= NUM_LS-1; ++i) {
std::cout << "[In Progress] LumiSection " << i << std::endl;
for (int j = 0; j < numEvents; ++j) {
xoffset1 += 0.00002;
yoffset1 += 0.00002;
xoffset2 += 0.00003;
yoffset2 += 0.00004;
if (r2 > 3. - yoffset1 && r2 < 8. - yoffset1 &&
r1 > 1. + xoffset1 && r1 < 5. + xoffset1 ) {
val -= rbad1;
}
if (r2 > -10 + yoffset2 && r2 < -8 + yoffset2 &&
r1 > -6 + xoffset2 && r1 < 8 + xoffset2 ) {
val -= rbad2;
}
tot_avg_ls[i].Fill(r1, r2, val);
det_avg_ls[i].Fill(r1, r2, val);
}
std::string title;
title = "Global View: Avg in LS " + to_string(i);
tot_avg_ls[i].SetTitle(title.c_str());
tot_avg_ls[i].SetStats(false);
tot_avg_ls[i].Draw("COLZ");
title = "Detector View: Avg in LS " + to_string(i);
det_avg_ls[i].SetTitle(title.c_str());
det_avg_ls[i].SetStats(false);
det_avg_ls[i].Draw("COLZ");
c1->
cd((i+1)+(NUM_LS*2));
title = "Detector View: Error in LS " + to_string(i);
det_avg_ls[i].SetTitle(title.c_str());
det_avg_ls[i].SetStats(false);
det_avg_ls[i].SetContentToError();
det_avg_ls[i].Draw("COLZ");
}
std::vector<TProfile2Poly*> tot_avg_v;
std::vector<TProfile2Poly*> det_avg_v;
for (
Int_t t=0; t<NUM_LS; t++){
tot_avg_v.push_back(&tot_avg_ls[t]);
det_avg_v.push_back(&det_avg_ls[t]);
}
std::cout << "[In Progress] Merging" << std::endl;
std::string title;
tot_merge->Merge(tot_avg_v);
title = "Total average merge";
tot_merge->Draw("COLZ");
det_avg_merge->Merge(det_avg_v);
title = "Detector average merge";
det_avg_merge->SetContentToAverage();
det_avg_merge->Draw("COLZ");
det_err_merge->Merge(det_avg_v);
title = "Detector error merge";
det_err_merge->SetContentToError();
det_err_merge->Draw("COLZ");
}