9 void writeTimeOrderedDistortions(
bool subtractFirst=
false,
char *
filename=
"/sphenix/user/rcorliss/distortion_maps/2022.07/TimeOrderedDistortions.root",
char *inputpattern=
"/sphenix/user/rcorliss/distortion_maps/2022.07/*.distortion_map.hist.root",
bool debug=
false){
11 TFile *treefile=TFile::Open(
filename,
"RECREATE");
15 TH3F *basehist[nhists];
16 TH3F *temphist[nhists];
20 "hIntDistortionPhi_negz",
21 "hIntDistortionR_negz",
22 "hIntDistortionZ_negz",
23 "hIntDistortionP_posz",
24 "hIntDistortionPhi_posz",
25 "hIntDistortionR_posz",
26 "hIntDistortionZ_posz"};
28 "hIntDistortionP_negz",
29 "hIntDistortionR_negz",
30 "hIntDistortionZ_negz",
31 "hIntDistortionRPhi_posz",
32 "hIntDistortionP_posz",
33 "hIntDistortionR_posz",
34 "hIntDistortionZ_posz"};
35 TTree *
tree=
new TTree(
"TimeDists",
"TimeDists");
36 tree->Branch(
"xingnum",&xingnum);
37 for (
int i=0;
i<nhists;
i++){
38 temphist[
i]=
new TH3F(Form(
"temphist%d",
i),Form(
"temphist%d",
i),10,0,10,20,0,20,30,0,30);
39 basehist[
i]=
new TH3F(Form(
"basehist%d",
i),Form(
"basehist%d",
i),10,0,10,20,0,20,30,0,30);
40 tree->Branch(branchname[
i].c_str(),&(temphist[
i]));
42 if (
debug)
printf(
"histograms built and branched.\n");
45 TFileCollection *filelist=
new TFileCollection();
46 filelist->Add(inputpattern);
48 printf(
"found %d files like: %s\n",filelist->GetNFiles(),((TFileInfo*)(filelist->GetList()->At(0)))->GetCurrentUrl()->GetFile());
52 bool fileIsValid=
true;
57 for (
int i=0;
i<filelist->GetNFiles() &&
i<100;
i++){
59 infile=TFile::Open(((TFileInfo*)(filelist->GetList()->At(
i)))->GetCurrentUrl()->GetUrl(),
"READ");
62 if (!infile->IsOpen()) {
63 printf(
"=====> File %d is NOT openable <=======\n",
i);
67 for (
int j=0;
j<nhists;
j++){
69 temphist[
j]=infile->Get<TH3F>(histname[
j].c_str());
74 int nbins=temphist[
j]->GetNcells();
75 if (
debug)
printf(
"=======> \"%s\" has %d cells\n",histname[j].c_str(),nbins);
80 printf(
"=====> File %d is NOT valid <=======\n",
i);
88 for (
int j=0;
j<nhists;
j++){
90 basehist[
j]=(TH3F*)(temphist[
j]->Clone());
95 for (
int j=0;
j<nhists;
j++){
96 printf(
"ptr j=%d: b:%p\tt:%p\n",
j,basehist[
j],temphist[j]);
97 int nbins=temphist[
j]->GetNcells();
99 double b=basehist[
j]->GetBinContent(
k);
100 double t=temphist[
j]->GetBinContent(
k);
102 temphist[
j]->SetBinContent(
k,diff);
105 if (
debug)
printf(
"=======> \"%s\" has %d cells when writing diff\n",histname[j].c_str(),nbins);