SC analysis working (needs 40G RAM)

This commit is contained in:
2022-05-12 12:27:52 +02:00
parent fad81adb39
commit 6c8c9e9635

View File

@ -21,6 +21,7 @@
#include "TPaveStats.h"
#include "TLegend.h"
#include "TPaveText.h"
#include "TObjArray.h"
#include <sys/stat.h>
#include <vector>
@ -74,8 +75,8 @@ int main(int argc, char* argv[]) {
//char savename[128];
char histoname[256]; // VH 210902
char savename[256]; // VH 210902
int filen = 16;
int pedefilen = 1;
int filen = 352;
int pedefilen = 5;
// create necessary directories with permissions drwxrwxr-x
// data/Mxxx
@ -110,10 +111,10 @@ int main(int argc, char* argv[]) {
TCanvas* c1 = new TCanvas("c1","");
/****************************************************************************************************************/
/* NOTE: Since arrays, as they were used before, tend to cause memory leaks if they grow too large on the heap, */
/*****************************************************************************************************************/
/* NOTE: Since arrays, as they were used before, tend to cause memory leaks if they grow too large on the stack, */
/* it might be smarter to realize all array objects with std::vector instead. */
/****************************************************************************************************************/
/*****************************************************************************************************************/
if (createHistoFile) {
@ -121,6 +122,11 @@ int main(int argc, char* argv[]) {
vector<jungfrauPedestal*> pedestalObject_SC; //( NSC, new jungfrauPedestal() ); //should call default constructor 16 times
pedestalObject_SC.reserve(NSC);
vector< vector<uint16_t> > pedestals16_G0_start( NSC, vector<uint16_t>(NCH) ); //I suppose, this is to track pedestal shifting over the course of data taking
vector< vector<double> > pedeRMS16_G0( NSC, vector<double>(NCH) );
{ //scope to limit the following 2 vectors
vector<TH2F*> pedestalsG0;
pedestalsG0.reserve(NSC);
vector<TH2F*> pedeRMSG0;
@ -135,8 +141,6 @@ int main(int argc, char* argv[]) {
snprintf( pedehistoname, 50, "pedeRMSG0_sc%d", sci );
pedeRMSG0.push_back( new TH2F( pedehistoname, "", NC, -0.5, NC-0.5, NR, -0.5, NR-0.5 ) );
}
vector< vector<uint16_t> > pedestals16_G0_start( NSC, vector<uint16_t>(NCH) ); //I suppose, this is to track pedestal shifting over the course of data taking
vector< vector<double> > pedeRMS16_G0( NSC, vector<double>(NCH) );
for (int pedefilei = 0; pedefilei < pedefilen; ++pedefilei) {
@ -191,6 +195,8 @@ int main(int argc, char* argv[]) {
sprintf(savename,"plots/M%s/CuFluo/%s/pedeG0_sc%d_%s_M%s.png", module_str.c_str(), gain_str.c_str(), sci, gain_str.c_str(), module_str.c_str());
mapcanvas->SaveAs((const char *)(savename));
pedestalsG0[sci]->Delete(); //not needed hereafter (try to save memory)
pedeRMSG0[sci]->GetXaxis()->SetTitle("Column");
pedeRMSG0[sci]->GetYaxis()->SetTitle("Row");
pedeRMSG0[sci]->GetYaxis()->SetTitleOffset(0.7);
@ -199,19 +205,26 @@ int main(int argc, char* argv[]) {
sprintf(savename,"plots/M%s/CuFluo/%s/pedeRMSG0_sc%d_%s_M%s.png", module_str.c_str(), gain_str.c_str(), sci, gain_str.c_str(), module_str.c_str());
mapcanvas->SaveAs((const char *)(savename));
pedeRMSG0[sci]->Delete(); //not needed hereafter (try to save memory)
}
//Make sure histograms are deleted
} // end of scope to limit pedestalsG0 and pedeRMSG0
int adc2d_nbin= 1200;
if (isJF11) adc2d_nbin= 1600;
vector <TH2I*> adc2d_1; //(8, vector <TH2I*>(16) ); //declare
vector <TH2I*> adc2d_2;
vector <TH2I*> adc2d_3;
vector <TH2I*> adc2d_4;
vector <TH2I*> adc2d_5;
vector <TH2I*> adc2d_6;
vector <TH2I*> adc2d_7;
vector <TH2I*> adc2d_8;
vector<TH2I*> adc2d_1; //(8, vector <TH2I*>(16) ); //declare
vector<TH2I*> adc2d_2;
vector<TH2I*> adc2d_3;
vector<TH2I*> adc2d_4;
vector<TH2I*> adc2d_5;
vector<TH2I*> adc2d_6;
vector<TH2I*> adc2d_7;
vector<TH2I*> adc2d_8;
//TObjArray *adc2d_8 = new TObjArray(NSC);
//adc2d.reserve(8);
/*
TH2I *adc2d_2[16]; = new TH2I("adc2d_2","",adc2d_nbin,-200-0.5,adc2d_nbin-200-0.5,65536,(65536*1-0.5),(65536*2-0.5));
@ -223,7 +236,7 @@ int main(int argc, char* argv[]) {
TH2I *adc2d_8[16]; = new TH2I("adc2d_8","",adc2d_nbin,-200-0.5,adc2d_nbin-200-0.5,65536,(65536*7-0.5),(65536*8-0.5));
*/
cout << "Initialize vector of vectors..." << endl;
cout << "Initialize adc2d vectors..." << endl;
//initialize
//for ( int adci = 0; adci < 8; ++adci ) {
@ -313,6 +326,7 @@ int main(int argc, char* argv[]) {
} else if (i < (65536*7)) {
adc2d_7[scnumber]->Fill(adcpc,i);
} else if (i < (65536*8)) {
//TH2I *adc2d_now = dynamic_cast<TH2I*>(adc2d_8->At(scnumber));
adc2d_8[scnumber]->Fill(adcpc,i);
}
}
@ -377,6 +391,21 @@ int main(int argc, char* argv[]) {
adc2d_6[sci]->Write();
adc2d_7[sci]->Write();
adc2d_8[sci]->Write();
//TH2I *adc2d_now = dynamic_cast<TH2I*>(adc2d_8->At(sci));
//All pede updates have been written, so they can be destroyed.
pede_updates[sci]->Delete();
pede_diff[sci]->Delete();
//In theory, I believe, adc2d can now also be destroyed since it has already been written to file
adc2d_1[sci]->Delete();
adc2d_2[sci]->Delete();
adc2d_3[sci]->Delete();
adc2d_4[sci]->Delete();
adc2d_5[sci]->Delete();
adc2d_6[sci]->Delete();
adc2d_7[sci]->Delete();
adc2d_8[sci]->Delete();
}
//}
saved_file->Close();
@ -407,7 +436,7 @@ int main(int argc, char* argv[]) {
}
} else if (gain_str == "G0") {
low_ADU_peak = 250;
low_ADU_peak = 200; // was 250
high_ADU_peak = 400;
}
@ -490,7 +519,7 @@ int main(int argc, char* argv[]) {
snprintf( fithistoname, 50, "fit_par5_sc%d", sci );
fit_par5.push_back( new TH1F( fithistoname, "", 100, 0, 0.5 ) );
snprintf( fithistoname, 50, "fit_par6_sc%d", sci );
fit_par6.push_back( new TH1F( fithistoname, "", 100, 1.05, 1.25 ) );
fit_par6.push_back( new TH1F( fithistoname, "", 100, 1.05, 1.3 ) ); // was 1.05, 1.25
snprintf( fithistoname, 50, "fit_par7_sc%d", sci );
fit_par7.push_back( new TH1F( fithistoname, "", 100, 0, 0.4 ) );
@ -517,7 +546,7 @@ int main(int argc, char* argv[]) {
snprintf( fithistoname, 50, "noise_fit_pos_sc%d", sci );
noise_fit_pos.push_back( new TH1F( fithistoname, "", 100, -10, 10 ) );
snprintf( fithistoname, 50, "noise_fit_poserr_sc%d", sci );
noise_fit_poserr.push_back( new TH1F( fithistoname, "", 100, 0, 0.1 ) );
noise_fit_poserr.push_back( new TH1F( fithistoname, "", 100, 0, 0.15 ) ); // was 0, 0.1
snprintf( fithistoname, 50, "noise_fit_pos_2d_sc%d", sci );
noise_fit_pos_2d.push_back( new TH2F( fithistoname, "", NC, -0.5, NC-0.5, NR, -0.5, NR-0.5 ) );
snprintf( fithistoname, 50, "noise_fit_poserr_2d_sc%d", sci );
@ -785,6 +814,8 @@ int main(int argc, char* argv[]) {
sprintf( savename, "plots/M%s/CuFluo/%s/fit_par3_2d_sc%d_%s_M%s.png", module_str.c_str(), gain_str.c_str(), sci, gain_str.c_str(), module_str.c_str() );
mapcanvas->SaveAs( (const char *)(savename) );
fit_par3_2d[sci]->Delete();
fit_par4_2d[sci]->GetXaxis()->SetTitle("Column");
fit_par4_2d[sci]->GetYaxis()->SetTitle("Row");
fit_par4_2d[sci]->GetYaxis()->SetTitleOffset(0.7);
@ -793,6 +824,8 @@ int main(int argc, char* argv[]) {
sprintf( savename, "plots/M%s/CuFluo/%s/fit_par4_2d_sc%d_%s_M%s.png", module_str.c_str(), gain_str.c_str(), sci, gain_str.c_str(), module_str.c_str() );
mapcanvas->SaveAs( (const char *)(savename) );
fit_par4_2d[sci]->Delete();
fit_par5_2d[sci]->GetXaxis()->SetTitle("Column");
fit_par5_2d[sci]->GetYaxis()->SetTitle("Row");
fit_par5_2d[sci]->GetYaxis()->SetTitleOffset(0.7);
@ -801,14 +834,18 @@ int main(int argc, char* argv[]) {
sprintf( savename, "plots/M%s/CuFluo/%s/fit_par5_2d_sc%d_%s_M%s.png", module_str.c_str(), gain_str.c_str(), sci, gain_str.c_str(), module_str.c_str() );
mapcanvas->SaveAs( (const char *)(savename) );
fit_par5_2d[sci]->Delete();
fit_par6_2d[sci]->GetXaxis()->SetTitle("Column");
fit_par6_2d[sci]->GetYaxis()->SetTitle("Row");
fit_par6_2d[sci]->GetYaxis()->SetTitleOffset(0.7);
fit_par6_2d[sci]->Draw("colz");
fit_par6_2d[sci]->GetZaxis()->SetRangeUser(1.0,1.25);
fit_par6_2d[sci]->GetZaxis()->SetRangeUser(1.0,1.3); //was (1.0,1.25)
sprintf( savename, "plots/M%s/CuFluo/%s/fit_par6_2d_sc%d_%s_M%s.png", module_str.c_str(), gain_str.c_str(), sci, gain_str.c_str(), module_str.c_str() );
mapcanvas->SaveAs( (const char *)(savename) );
fit_par6_2d[sci]->Delete();
fit_par7_2d[sci]->GetXaxis()->SetTitle("Column");
fit_par7_2d[sci]->GetYaxis()->SetTitle("Row");
fit_par7_2d[sci]->GetYaxis()->SetTitleOffset(0.7);
@ -825,6 +862,8 @@ int main(int argc, char* argv[]) {
sprintf( savename, "plots/M%s/CuFluo/%s/peak_fit_pos_2d_sc%d_%s_M%s.png", module_str.c_str(), gain_str.c_str(), sci, gain_str.c_str(), module_str.c_str() );
mapcanvas->SaveAs( (const char *)(savename) );
peak_fit_pos_2d[sci]->Delete();
peak_fit_poserr_2d[sci]->GetXaxis()->SetTitle("Column");
peak_fit_poserr_2d[sci]->GetYaxis()->SetTitle("Row");
peak_fit_poserr_2d[sci]->GetYaxis()->SetTitleOffset(0.7);
@ -833,6 +872,8 @@ int main(int argc, char* argv[]) {
sprintf( savename, "plots/M%s/CuFluo/%s/peak_fit_poserr_2d_sc%d_%s_M%s.png", module_str.c_str(), gain_str.c_str(), sci, gain_str.c_str(), module_str.c_str() );
mapcanvas->SaveAs( (const char *)(savename) );
peak_fit_poserr_2d[sci]->Delete();
noise_fit_pos_2d[sci]->GetXaxis()->SetTitle("Column");
noise_fit_pos_2d[sci]->GetYaxis()->SetTitle("Row");
noise_fit_pos_2d[sci]->GetYaxis()->SetTitleOffset(0.7);
@ -841,6 +882,8 @@ int main(int argc, char* argv[]) {
sprintf( savename, "plots/M%s/CuFluo/%s/noise_fit_pos_2d_sc%d_%s_M%s.png", module_str.c_str(), gain_str.c_str(), sci, gain_str.c_str(), module_str.c_str() );
mapcanvas->SaveAs( (const char *)(savename) );
noise_fit_pos_2d[sci]->Delete();
noise_fit_poserr_2d[sci]->GetXaxis()->SetTitle("Column");
noise_fit_poserr_2d[sci]->GetYaxis()->SetTitle("Row");
noise_fit_poserr_2d[sci]->GetYaxis()->SetTitleOffset(0.7);
@ -848,11 +891,13 @@ int main(int argc, char* argv[]) {
if (gain_str == "HG0") {
noise_fit_poserr_2d[sci]->GetZaxis()->SetRangeUser(0,0.1);
} else if (gain_str == "G0") {
noise_fit_poserr_2d[sci]->GetZaxis()->SetRangeUser(0,0.05);
noise_fit_poserr_2d[sci]->GetZaxis()->SetRangeUser(0,0.1); // was 0,0.05
}
sprintf( savename, "plots/M%s/CuFluo/%s/noise_fit_poserr_2d_sc%d_%s_M%s.png", module_str.c_str(), gain_str.c_str(), sci, gain_str.c_str(), module_str.c_str() );
mapcanvas->SaveAs( (const char *)(savename) );
noise_fit_poserr_2d[sci]->Delete();
gain_fit_2d[sci]->GetXaxis()->SetTitle("Column");
gain_fit_2d[sci]->GetYaxis()->SetTitle("Row");
gain_fit_2d[sci]->GetYaxis()->SetTitleOffset(0.7);
@ -864,6 +909,8 @@ int main(int argc, char* argv[]) {
sprintf( savename, "plots/M%s/CuFluo/%s/gain_fit_2d_sc%d_%s_M%s.png", module_str.c_str(), gain_str.c_str(), sci, gain_str.c_str(), module_str.c_str() );
mapcanvas->SaveAs( (const char *)(savename) );
gain_fit_2d[sci]->Delete();
gain_fiterr_2d[sci]->GetXaxis()->SetTitle("Column");
gain_fiterr_2d[sci]->GetYaxis()->SetTitle("Row");
gain_fiterr_2d[sci]->GetYaxis()->SetTitleOffset(0.7);
@ -872,6 +919,8 @@ int main(int argc, char* argv[]) {
sprintf( savename, "plots/M%s/CuFluo/%s/gain_fiterr_2d_sc%d_%s_M%s.png", module_str.c_str(), gain_str.c_str(), sci, gain_str.c_str(), module_str.c_str() );
mapcanvas->SaveAs( (const char *)(savename) );
gain_fiterr_2d[sci]->Delete();
gain_ADUper1keV_2d[sci]->GetXaxis()->SetTitle("Column");
gain_ADUper1keV_2d[sci]->GetYaxis()->SetTitle("Row");
gain_ADUper1keV_2d[sci]->GetYaxis()->SetTitleOffset(0.7);
@ -879,11 +928,13 @@ int main(int argc, char* argv[]) {
if (gain_str == "HG0") {
gain_ADUper1keV_2d[sci]->GetZaxis()->SetRangeUser(80,120);
} else if (gain_str == "G0") {
gain_ADUper1keV_2d[sci]->GetZaxis()->SetRangeUser(35,50);
gain_ADUper1keV_2d[sci]->GetZaxis()->SetRangeUser(25,45); //was 35,50
}
sprintf( savename, "plots/M%s/CuFluo/%s/gain_ADUper1keV_2d_sc%d_%s_M%s.png", module_str.c_str(), gain_str.c_str(), sci, gain_str.c_str(), module_str.c_str() );
mapcanvas->SaveAs( (const char *)(savename) );
//gain_ADUper1keV_2d[sci]->Delete();
gainerr_ADUper1keV_2d[sci]->GetXaxis()->SetTitle("Column");
gainerr_ADUper1keV_2d[sci]->GetYaxis()->SetTitle("Row");
gainerr_ADUper1keV_2d[sci]->GetYaxis()->SetTitleOffset(0.7);
@ -896,6 +947,8 @@ int main(int argc, char* argv[]) {
sprintf( savename, "plots/M%s/CuFluo/%s/gainerr_ADUper1keV_2d_sc%d_%s_M%s.png", module_str.c_str(), gain_str.c_str(), sci, gain_str.c_str(), module_str.c_str() );
mapcanvas->SaveAs( (const char *)(savename) );
//gainerr_ADUper1keV_2d[sci]->Delete();
c1->cd();
fit_par3[sci]->GetXaxis()->SetTitle("Fit par 3");
@ -903,21 +956,29 @@ int main(int argc, char* argv[]) {
sprintf( savename, "plots/M%s/CuFluo/%s/fit_par3_sc%d_%s_M%s.png", module_str.c_str(), gain_str.c_str(), sci, gain_str.c_str(), module_str.c_str() );
c1->SaveAs( (const char *)(savename) );
fit_par3[sci]->Delete();
fit_par4[sci]->GetXaxis()->SetTitle("Fit par 4");
fit_par4[sci]->Draw();
sprintf( savename, "plots/M%s/CuFluo/%s/fit_par4_sc%d_%s_M%s.png", module_str.c_str(), gain_str.c_str(), sci, gain_str.c_str(), module_str.c_str() );
c1->SaveAs( (const char *)(savename) );
fit_par4[sci]->Delete();
fit_par5[sci]->GetXaxis()->SetTitle("Fit par 5");
fit_par5[sci]->Draw();
sprintf( savename, "plots/M%s/CuFluo/%s/fit_par5_sc%d_%s_M%s.png", module_str.c_str(), gain_str.c_str(), sci, gain_str.c_str(), module_str.c_str() );
c1->SaveAs( (const char *)(savename) );
fit_par5[sci]->Delete();
fit_par6[sci]->GetXaxis()->SetTitle("Fit par 6");
fit_par6[sci]->Draw();
sprintf( savename, "plots/M%s/CuFluo/%s/fit_par6_sc%d_%s_M%s.png", module_str.c_str(), gain_str.c_str(), sci, gain_str.c_str(), module_str.c_str() );
c1->SaveAs( (const char *)(savename) );
fit_par6[sci]->Delete();
fit_par7[sci]->GetXaxis()->SetTitle("Fit par 7");
fit_par7[sci]->Draw();
sprintf( savename, "plots/M%s/CuFluo/%s/fit_par7_sc%d_%s_M%s.png", module_str.c_str(), gain_str.c_str(), sci, gain_str.c_str(), module_str.c_str() );
@ -928,27 +989,37 @@ int main(int argc, char* argv[]) {
sprintf( savename, "plots/M%s/CuFluo/%s/peak_fit_pos_sc%d_%s_M%s.png", module_str.c_str(), gain_str.c_str(), sci, gain_str.c_str(), module_str.c_str() );
c1->SaveAs( (const char *)(savename) );
peak_fit_pos[sci]->Delete();
peak_fit_poserr[sci]->GetXaxis()->SetTitle("Peak position uncert [ADU]");
peak_fit_poserr[sci]->Draw();
sprintf( savename, "plots/M%s/CuFluo/%s/peak_fit_poserr_sc%d_%s_M%s.png", module_str.c_str(), gain_str.c_str(), sci, gain_str.c_str(), module_str.c_str() );
c1->SaveAs( (const char *)(savename) );
peak_fit_poserr[sci]->Delete();
noise_fit_pos[sci]->GetXaxis()->SetTitle("Noise position [ADU]");
noise_fit_pos[sci]->Draw();
sprintf( savename, "plots/M%s/CuFluo/%s/noise_fit_pos_sc%d_%s_M%s.png", module_str.c_str(), gain_str.c_str(), sci, gain_str.c_str(), module_str.c_str() );
c1->SaveAs( (const char *)(savename) );
noise_fit_pos[sci]->Delete();
noise_fit_poserr[sci]->GetXaxis()->SetTitle("Noise position uncert [ADU]");
noise_fit_poserr[sci]->Draw();
sprintf( savename, "plots/M%s/CuFluo/%s/noise_fit_poserr_sc%d_%s_M%s.png", module_str.c_str(), gain_str.c_str(), sci, gain_str.c_str(), module_str.c_str() );
c1->SaveAs( (const char *)(savename) );
noise_fit_poserr[sci]->Delete();
sprintf( savename, "Gain %s [ADU / 8 keV]", gain_str.c_str() );
gain_fit[sci]->GetXaxis()->SetTitle( (const char *)(savename) );
gain_fit[sci]->Draw();
sprintf( savename, "plots/M%s/CuFluo/%s/gain_fit_sc%d_%s_M%s.png", module_str.c_str(), gain_str.c_str(), sci, gain_str.c_str(), module_str.c_str() );
c1->SaveAs( (const char *)(savename) );
//gain_fit[sci]->Delete();
gain_fit[sci]->GetXaxis()->SetRangeUser( low_ADU_peak+30, high_ADU_peak );
gain_fit[sci]->Fit("gaus");
gain_fit[sci]->Draw();
@ -968,11 +1039,15 @@ int main(int argc, char* argv[]) {
sprintf( savename, "plots/M%s/CuFluo/%s/gain_fit_fit_sc%d_%s_M%s.png", module_str.c_str(), gain_str.c_str(), sci, gain_str.c_str(), module_str.c_str() );
c1->SaveAs( (const char *)(savename) );
gain_fit[sci]->Delete();
gain_fiterr[sci]->GetXaxis()->SetTitle("Gain uncert [ADU / 8 keV]");
gain_fiterr[sci]->Draw();
sprintf( savename, "plots/M%s/CuFluo/%s/gain_fiterr_sc%d_%s_M%s.png", module_str.c_str(), gain_str.c_str(), sci, gain_str.c_str(), module_str.c_str() );
c1->SaveAs( (const char *)(savename) );
gain_fiterr[sci]->Delete();
gain_fit_isEdge[sci]->SetLineColor(kBlue);
gain_fit_isInnerEdge[sci]->SetLineColor(kCyan);
gain_fit_isDouble[sci]->SetLineColor(kGreen+2);
@ -1008,12 +1083,21 @@ int main(int argc, char* argv[]) {
sprintf( savename, "plots/M%s/CuFluo/%s/gain_fit_perType_sc%d_%s_M%s.png", module_str.c_str(), gain_str.c_str(), sci, gain_str.c_str(), module_str.c_str() );
c1->SaveAs( (const char *)(savename) );
gain_fit_isDouble[sci]->Delete();
gain_fit_isEdge[sci]->Delete();
gain_fit_isInnerEdge[sci]->Delete();
gain_fit_isNextToDouble[sci]->Delete();
gain_fit_isBulk[sci]->Delete();
sprintf( savename, "data/M%s/CuFluo_gain_sc%d_%s_M%s.root", module_str.c_str(), sci, gain_str.c_str(), module_str.c_str() );
TFile* saved_file = new TFile( (const char *)(savename), "RECREATE" );
gain_ADUper1keV_2d[sci]->Write();
gainerr_ADUper1keV_2d[sci]->Write();
saved_file->Close();
gain_ADUper1keV_2d[sci]->Delete();
gainerr_ADUper1keV_2d[sci]->Delete();
} // end of sc loop
}