Skip to content
Snippets Groups Projects
Commit c15041fd authored by Theodore Efremov's avatar Theodore Efremov :hibiscus:
Browse files

Finalised ToffMacro

parent 12084ddd
No related branches found
No related tags found
1 merge request!27Draft: [Epic] Preparation of the environement for the new GaseousDetectorScorers...
Pipeline #371158 passed
...@@ -9,8 +9,9 @@ ...@@ -9,8 +9,9 @@
using namespace std; using namespace std;
vector<int> SortSection(UShort_t STargFocal[2]); vector<int> SortSection(UShort_t STargFocal[2]);
vector<double> ToffCalc(vector<double> ToffP2P);
void ToffGenerator(bool Create = true ){ void ToffGenerator(bool Create = true ){
//=========================================================================================================== //===========================================================================================================
// Setters // Setters
...@@ -22,7 +23,7 @@ vector<int> SortSection(UShort_t STargFocal[2]); ...@@ -22,7 +23,7 @@ vector<int> SortSection(UShort_t STargFocal[2]);
Int_t M13 , M14, M23, M24 ;// we will fetch multiplicity during Int_t M13 , M14, M23, M24 ;// we will fetch multiplicity during
// the getentry // the getentry
UShort_t S13[20] , S14[20] , S23[20] , S24[20]; UShort_t S13[20] , S14[20] , S23[20] , S24[20];
TTimeData *Time = new TTimeData(); TTimeData *Time = new TTimeData();
...@@ -37,104 +38,112 @@ vector<int> SortSection(UShort_t STargFocal[2]); ...@@ -37,104 +38,112 @@ vector<int> SortSection(UShort_t STargFocal[2]);
chain->SetBranchStatus("MTOF_FP1_T0VN", true); chain->SetBranchStatus("MTOF_FP1_T0VN", true);
chain->SetBranchAddress("MTOF_FP1_T0VN", &S23); chain->SetBranchAddress("MTOF_FP1_T0VN", &S23);
chain->SetBranchStatus("MTOF_FP1_T1VN", true); chain->SetBranchStatus("MTOF_FP1_T1VN", true);
chain->SetBranchAddress("MTOF_FP1_T1VN", &S24); chain->SetBranchAddress("MTOF_FP1_T1VN", &S24);
chain->SetBranchStatus("Time", true); chain->SetBranchStatus("Time", true);
chain->SetBranchAddress("Time", &Time); chain->SetBranchAddress("Time", &Time);
//=========================================================================================================== //===========================================================================================================
// Histograms // Histograms
//=========================================================================================================== //===========================================================================================================
TH2F *hToff13; TH2F *hToff13;
TH2F *hToff14; TH2F *hToff14;
TH2F *hToff23; TH2F *hToff23;
TH2F *hToff24; TH2F *hToff24;
double xmin[4], xmax[4];
double ymin[4], ymax[4];
int binx = 20 , biny = 400;
xmin[0] = 0 ; xmax[0] = 20 ; ymin[0] = -10 ; ymax[0] = 10 ;
xmin[1] = 0 ; xmax[1] = 20 ; ymin[1] = -10 ; ymax[1] = 10 ;
xmin[2] = 0 ; xmax[2] = 20 ; ymin[2] = -10 ; ymax[2] = 10 ;
xmin[3] = 0 ; xmax[3] = 20 ; ymin[3] = -10 ; ymax[3] = 10 ;
if (Create == true){ if (Create == true){
hToff13 = new TH2F("Toff13","Toff13", 20, 0, 20, 100, -10, 10); hToff13 = new TH2F("Toff13","Toff13",binx ,xmin[0] , xmax[0], biny, ymin[0], ymax[0]);
hToff14 = new TH2F("Toff14","Toff14", 20, 0, 20, 200, -10, 10); hToff14 = new TH2F("Toff14","Toff14",binx ,xmin[1] , xmax[1], biny, ymin[1], ymax[1]);
hToff23 = new TH2F("Toff23","Toff23", 20, 0, 20, 200, -10, 10); hToff23 = new TH2F("Toff23","Toff23",binx ,xmin[2] , xmax[2], biny, ymin[2], ymax[2]);
hToff24 = new TH2F("Toff24","Toff24", 20, 0, 20, 200, -10, 10); hToff24 = new TH2F("Toff24","Toff24",binx ,xmin[3] , xmax[3], biny, ymin[3], ymax[3]);
//=========================================================================================================== //===========================================================================================================
// Loop on entries // Loop on entries
//=========================================================================================================== //===========================================================================================================
//int Nentries = chain->GetEntries(); int Nentries = chain->GetEntries();
int Nentries = 1000000; //int Nentries = 1000000;
auto start = std::chrono::high_resolution_clock::now(); auto start = std::chrono::high_resolution_clock::now();
for (int e = 0; e < Nentries; e++) { for (int e = 0; e < Nentries; e++) {
chain->GetEntry(e); chain->GetEntry(e);
if (e % 100000 == 0 && e > 0 ) { if (e % 100000 == 0 && e > 0 ) {
auto now = std::chrono::high_resolution_clock::now(); auto now = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> elapsed = now - start; std::chrono::duration<double> elapsed = now - start;
double avgTimePerIteration = elapsed.count() / e; double avgTimePerIteration = elapsed.count() / e;
double timeLeft = avgTimePerIteration * (Nentries - e); double timeLeft = avgTimePerIteration * (Nentries - e);
std::cout << "********** Estimated time left: " << int(timeLeft) << " seconds **********" << "\r" << flush; std::cout << "********** Estimated time left: " << int(timeLeft) << " seconds **********" << "\r" << flush;
} }
// Get Multiplicity // Get Multiplicity
M13 = Time->GetMWPC13Mult(); M13 = Time->GetMWPC13Mult();
M14 = Time->GetMWPC14Mult(); M14 = Time->GetMWPC14Mult();
M23 = Time->GetMWPC23Mult(); M23 = Time->GetMWPC23Mult();
M24 = Time->GetMWPC24Mult(); M24 = Time->GetMWPC24Mult();
if (M13 == 2 && (abs(S13[0]-S13[1]) == 1)){ if (M13 == 2 && (abs(S13[0]-S13[1]) == 1)){
vector<int> Pos = SortSection(S13); vector<int> Pos = SortSection(S13);
hToff13->Fill(S13[0],Time->GetTime_MWPC13(Pos[0]) - Time->GetTime_MWPC13(Pos[1])); hToff13->Fill(S13[0],Time->GetTime_MWPC13(Pos[0]) - Time->GetTime_MWPC13(Pos[1]));
} }
if (M23 == 2 && (abs(S23[0]-S23[1]) == 1)){ if (M23 == 2 && (abs(S23[0]-S23[1]) == 1)){
vector<int> Pos = SortSection(S23); vector<int> Pos = SortSection(S23);
hToff23->Fill(S23[0],Time->GetTime_MWPC23(Pos[0]) - Time->GetTime_MWPC23(Pos[1])); hToff23->Fill(S23[0],Time->GetTime_MWPC23(Pos[0]) - Time->GetTime_MWPC23(Pos[1]));
} }
if (M14 == 2 && (abs(S14[0]-S14[1]) == 1)){ if (M14 == 2 && (abs(S14[0]-S14[1]) == 1)){
vector<int> Pos = SortSection(S14); vector<int> Pos = SortSection(S14);
hToff14->Fill(S14[0],Time->GetTime_MWPC14(Pos[0]) - Time->GetTime_MWPC14(Pos[1])); hToff14->Fill(S14[0],Time->GetTime_MWPC14(Pos[0]) - Time->GetTime_MWPC14(Pos[1]));
} }
if (M24 == 2 && (abs(S24[0]-S24[1]) == 1)){ if (M24 == 2 && (abs(S24[0]-S24[1]) == 1)){
vector<int> Pos = SortSection(S24); vector<int> Pos = SortSection(S24);
hToff24->Fill(S24[0],Time->GetTime_MWPC24(Pos[0]) - Time->GetTime_MWPC24(Pos[1])); hToff24->Fill(S24[0],Time->GetTime_MWPC24(Pos[0]) - Time->GetTime_MWPC24(Pos[1]));
} }
} // End loop event } // End loop event
TFile *out = new TFile("output/ToffHisto.root","recreate"); TFile *out = new TFile("output/ToffHisto.root","recreate");
hToff13->Write(); hToff13->Write();
hToff14->Write(); hToff14->Write();
hToff23->Write(); hToff23->Write();
hToff24->Write(); hToff24->Write();
}// end if create }// end if create
else { else {
TFile *in = new TFile("output/ToffHisto.root","open"); TFile *in = new TFile("output/ToffHisto.root","open");
hToff13 = (TH2F*)in->Get("Toff13"); hToff13 = (TH2F*)in->Get("Toff13");
hToff14 = (TH2F*)in->Get("Toff14"); hToff14 = (TH2F*)in->Get("Toff14");
hToff23 = (TH2F*)in->Get("Toff23"); hToff23 = (TH2F*)in->Get("Toff23");
hToff24 = (TH2F*)in->Get("Toff24"); hToff24 = (TH2F*)in->Get("Toff24");
} }
int MinX = 2; int MinX = 2;
hToff13->SetMinimum(MinX); hToff13->SetMinimum(MinX);
hToff14->SetMinimum(MinX); hToff14->SetMinimum(MinX);
hToff23->SetMinimum(MinX); hToff23->SetMinimum(MinX);
hToff24->SetMinimum(MinX); hToff24->SetMinimum(MinX);
//=========================================================================================================== //===========================================================================================================
// Proj fit // Proj fit
//=========================================================================================================== //===========================================================================================================
TCanvas* c13 = new TCanvas("c13", "Toff13", 1800, 1600); TCanvas* c13 = new TCanvas("c13", "Toff13", 1800, 1600);
c13->Divide(5, 4); // Adjust rows/columns to fit the number of bins (e.g., 20 bins here) c13->Divide(5, 4); // Adjust rows/columns to fit the number of bins (e.g., 20 bins here)
TCanvas* c14 = new TCanvas("c14", "Toff14", 1800, 1600); TCanvas* c14 = new TCanvas("c14", "Toff14", 1800, 1600);
c14->Divide(5, 4); // Adjust rows/columns to fit the number of bins (e.g., 20 bins here) c14->Divide(5, 4); // Adjust rows/columns to fit the number of bins (e.g., 20 bins here)
...@@ -299,26 +308,151 @@ vector<int> SortSection(UShort_t STargFocal[2]); ...@@ -299,26 +308,151 @@ vector<int> SortSection(UShort_t STargFocal[2]);
} }
// Display the canvas // Display the canvas
c24->Update(); c24->Update();
//===========================================================================================================
// Saving correction
//===========================================================================================================
//First we get the absolute correction to use on each section
vector<double> Toff13, Toff14, Toff23, Toff24;
Toff13 = ToffCalc(P2PToff13);
Toff23 = ToffCalc(P2PToff23);
Toff14 = ToffCalc(P2PToff14);
Toff24 = ToffCalc(P2PToff24);
//Save it in a txt file
ofstream o13("output/Toff13.txt");
ofstream o23("output/Toff23.txt");
ofstream o14("output/Toff14.txt");
ofstream o24("output/Toff24.txt");
for (auto &elem : Toff13) o13 << elem << endl;
for (auto &elem : Toff14) o14 << elem << endl;
for (auto &elem : Toff23) o23 << elem << endl;
for (auto &elem : Toff24) o24 << elem << endl;
//===========================================================================================================
// Testing correction
//===========================================================================================================
TH2F* hCorrToff13 = new TH2F("CorrToff13","CorrToff13",binx ,xmin[0] , xmax[0], biny, ymin[0], ymax[0]);
TH2F* hCorrToff14 = new TH2F("CorrToff14","CorrToff14",binx ,xmin[1] , xmax[1], biny, ymin[1], ymax[1]);
TH2F* hCorrToff23 = new TH2F("CorrToff23","CorrToff23",binx ,xmin[2] , xmax[2], biny, ymin[2], ymax[2]);
TH2F* hCorrToff24 = new TH2F("CorrToff24","CorrToff24",binx ,xmin[3] , xmax[3], biny, ymin[3], ymax[3]);
int Nentries = chain->GetEntries();
//int Nentries = 1000000;
auto start = std::chrono::high_resolution_clock::now();
for (int e = 0; e < Nentries; e++) {
chain->GetEntry(e);
if (e % 100000 == 0 && e > 0 ) {
auto now = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> elapsed = now - start;
double avgTimePerIteration = elapsed.count() / e;
double timeLeft = avgTimePerIteration * (Nentries - e);
std::cout << "********** Estimated time left: " << int(timeLeft) << " seconds **********" << "\r" << flush;
}
// Get Multiplicity
M13 = Time->GetMWPC13Mult();
M14 = Time->GetMWPC14Mult();
M23 = Time->GetMWPC23Mult();
M24 = Time->GetMWPC24Mult();
if (M13 == 2 && (abs(S13[0]-S13[1]) == 1)){
vector<int> Pos = SortSection(S13);
if (S13[0] == 0) hCorrToff13->Fill(S13[0],Time->GetTime_MWPC13(Pos[0]) - (Time->GetTime_MWPC13(Pos[1]) + Toff13.at(0) ));
else{
hCorrToff13->Fill(S13[0],(Time->GetTime_MWPC13(Pos[0]) + Toff13.at(S13[0]-1)) - (Time->GetTime_MWPC13(Pos[1]) + Toff13.at(S13[1]-1)));
}
}
if (M23 == 2 && (abs(S23[0]-S23[1]) == 1)){
vector<int> Pos = SortSection(S23);
if (S23[0] == 0) hCorrToff23->Fill(S23[0],Time->GetTime_MWPC23(Pos[0]) - (Time->GetTime_MWPC23(Pos[1]) + Toff23.at(0) ));
else{
hCorrToff23->Fill(S23[0],(Time->GetTime_MWPC23(Pos[0]) + Toff23.at(S23[0]-1)) - (Time->GetTime_MWPC23(Pos[1]) + Toff23.at(S23[1]-1)));
}
}
if (M14 == 2 && (abs(S14[0]-S14[1]) == 1)){
vector<int> Pos = SortSection(S14);
if (S14[0] == 0) hCorrToff14->Fill(S14[0],Time->GetTime_MWPC14(Pos[0]) - (Time->GetTime_MWPC14(Pos[1]) + Toff14.at(0) ));
else{
hCorrToff14->Fill(S14[0],(Time->GetTime_MWPC14(Pos[0]) + Toff14.at(S14[0]-1)) - (Time->GetTime_MWPC14(Pos[1]) + Toff14.at(S14[1]-1)));
}
}
if (M24 == 2 && (abs(S24[0]-S24[1]) == 1)){
vector<int> Pos = SortSection(S24);
if (S24[0] == 0) hCorrToff24->Fill(S24[0],Time->GetTime_MWPC24(Pos[0]) - (Time->GetTime_MWPC24(Pos[1]) + Toff24.at(0) ));
else{
hCorrToff24->Fill(S24[0],(Time->GetTime_MWPC24(Pos[0]) + Toff24.at(S24[0]-1)) - (Time->GetTime_MWPC24(Pos[1]) + Toff24.at(S24[1]-1)));
}
}
} // End loop event
//=========================================================================================================== //===========================================================================================================
// Drawing canvas // Drawing canvas
//=========================================================================================================== //===========================================================================================================
TCanvas *c1 = new TCanvas("c1","c1"); TCanvas *c1 = new TCanvas("c1","c1");
c1->Divide(2);
c1->cd(1);
hToff13->Draw("colz"); hToff13->Draw("colz");
c1->cd(2);
hCorrToff13->Draw("colz");
TCanvas *c2 = new TCanvas("c2","c2"); TCanvas *c2 = new TCanvas("c2","c2");
hToff23->Draw(); c2->Divide(2);
c2->cd(1);
hToff23->Draw("colz");
c2->cd(2);
hCorrToff23->Draw("colz");
TCanvas *c3 = new TCanvas("c3","c3"); TCanvas *c3 = new TCanvas("c3","c3");
hToff14->Draw(); c3->Divide(2);
c3->cd(1);
hToff14->Draw("colz");
c3->cd(2);
hCorrToff14->Draw("colz");
TCanvas *c4 = new TCanvas("c4","c4"); TCanvas *c4 = new TCanvas("c4","c4");
hToff24->Draw(); c4->Divide(2);
}
c4->cd(1);
hToff24->Draw("colz");
c4->cd(2);
hCorrToff24->Draw("colz");
}
vector<int> SortSection(UShort_t STargFocal[2]){ vector<int> SortSection(UShort_t STargFocal[2]){
UShort_t FSection ,LSection ; UShort_t FSection ,LSection ;
...@@ -340,3 +474,14 @@ vector<int> SortSection(UShort_t STargFocal[2]){ ...@@ -340,3 +474,14 @@ vector<int> SortSection(UShort_t STargFocal[2]){
STargFocal[1] = LSection; STargFocal[1] = LSection;
return Pos; return Pos;
} }
vector<double> ToffCalc(vector<double> ToffP2P){
vector<double> res;
double Sum = 0;
for (int i=0; i<ToffP2P.size() ; i++){
Sum += ToffP2P.at(i);
res.push_back(Sum);
}
return res;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment