tested with Process_Run, smooth. Next: need Calibrations, export new root

This commit is contained in:
Ryan Tang 2024-07-10 17:34:20 -04:00
parent 08577871ee
commit 34ecf9be1d
6 changed files with 85 additions and 132 deletions

View File

@ -339,6 +339,31 @@ std::vector<std::vector<double>> FindMatchingPair(std::vector<double> enX, std::
} }
std::string create_range_string(const std::vector<int>& nums) {
std::string range_str;
int lastNum = nums[0];
int rangeStart = lastNum;
for (int i = 1; i < (int) nums.size(); i++) {
if (nums[i] == lastNum + 1) {
lastNum = nums[i];
} else {
if (rangeStart == lastNum) {
range_str += std::to_string(rangeStart) + "_";
} else {
range_str += std::to_string(rangeStart) + "-" + std::to_string(lastNum) + "_";
}
rangeStart = lastNum = nums[i];
}
}
// Add the last range
if (rangeStart == lastNum) {
range_str += std::to_string(rangeStart);
} else {
range_str += std::to_string(rangeStart) + "-" + std::to_string(lastNum);
}
return range_str;
}
} }

View File

@ -24,6 +24,9 @@ if [ $# -eq 0 ] || [ $1 == "-help" ]; then
echo " = 2 WS fit" echo " = 2 WS fit"
echo " = 3 trapezoid(not implemented)" echo " = 3 trapezoid(not implemented)"
echo " e.g. 208 = WS trace with 8 workers" echo " e.g. 208 = WS trace with 8 workers"
#======== change Monitor to Action.
echo " Monitor = 2/1/0 || 1 = single run, 2 = using the list in ChainMonitors.C" echo " Monitor = 2/1/0 || 1 = single run, 2 = using the list in ChainMonitors.C"
echo "" echo ""
echo " * negative option = force." echo " * negative option = force."
@ -51,12 +54,8 @@ fi
nWorker=$((nWorker % 100 )); nWorker=$((nWorker % 100 ));
if [ "$RUN" == "lastRun" ]; then runNum=${RUN#0} #remove zero
RUN=$runID RUN=$(printf '%03d' $runNum) ##add back the zero
fi
RUN=${RUN##*(0)} #remove zero
RUN=$(printf '%03d' $RUN) ##add back the zero
################################### Setting display ################################### Setting display
echo "#################################################" echo "#################################################"
@ -92,7 +91,7 @@ fi
if [ $isMonitor -eq 0 ]; then if [ $isMonitor -eq 0 ]; then
echo -e "${LRED}>>>>>>>>>>>>>>>>>>>>> Monitor Skipped by user. ${NC}" echo -e "${LRED}>>>>>>>>>>>>>>>>>>>>> Monitor Skipped by user. ${NC}"
elif [ $isMonitor -eq 1 ]; then elif [ $isMonitor -eq 1 ]; then
root -l "ChainMonitors.C($RUN)" root -l "ChainMonitors.C($runNum)"
elif [ $isMonitor -eq 2 ]; then elif [ $isMonitor -eq 2 ]; then
root -l "ChainMonitors.C" root -l "ChainMonitors.C"
fi fi

View File

@ -2,107 +2,36 @@
#include "TObjArray.h" #include "TObjArray.h"
#include "TFile.h" #include "TFile.h"
#include "TMacro.h" #include "TMacro.h"
std::string create_range_string(const std::vector<int>& nums); #include "TChain.h"
TChain *gen_tree = nullptr;
void ChainMonitors(int RUNNUM = -1, int RUNNUM2 = -1) { void ChainMonitors(int RUNNUM = -1, int RUNNUM2 = -1) {
///default saveCanvas = false, no save Cavas ///default saveCanvas = false, no save Cavas
/// = true, save Canvas /// = true, save Canvas
TChain * chain = new TChain("gen_tree"); gen_tree = new TChain("gen_tree");
if( RUNNUM == -1){ if( RUNNUM == -1){
/// this list only for manual Chain sort /// this list only for manual Chain sort
///********** start Marker for AutoCalibration. ///********** start Marker for AutoCalibration.
chain->Add("../root_data/gen_run005.root"); gen_tree->Add("../root_data/trace_run033.root");
chain->Add("../root_data/gen_run003.root");
///chain->Add("../root_data/trace_run135.root");
///********** end Marker for AutoCalibration. ///********** end Marker for AutoCalibration.
}else{ }else{
TString fileName; TString fileName;
int endRUNNUM = RUNNUM2; int endRUNNUM = RUNNUM2;
if( RUNNUM2 == -1) endRUNNUM = RUNNUM; if( RUNNUM2 == -1) endRUNNUM = RUNNUM;
for( int i = RUNNUM ; i <= endRUNNUM ; i++){ for( int i = RUNNUM ; i <= endRUNNUM ; i++){
fileName.Form("../root_data/gen_run%03d.root", i); fileName.Form("../root_data/gen_run%03d.root", i);
chain->Add(fileName); gen_tree->Add(fileName);
} }
} }
TObjArray * fileList = chain->GetListOfFiles(); //^============== should have other things, like calibrations.
Monitor(gen_tree);
printf("\033[0;31m========================================== Number of Files : %2d\n",fileList->GetEntries());
fileList->Print();
printf("========================================== Number of Files : %2d\033[0m\n",fileList->GetEntries());
printf("---------------------------------- Total Number of entries : %llu \n", chain->GetEntries());
double totDuration = 0;
std::vector<ULong64_t> startTime;
std::vector<ULong64_t> stopTime;
std::vector<int> runList;
for( int i = 0; i < fileList->GetEntries(); i++){
TString fileName = fileList->At(i)->GetTitle();
TFile file(fileName);
TMacro * timeStamp = (TMacro*) file.FindObjectAny("timeStamp");
//timeStamp->Print();
TString haha = timeStamp->GetListOfLines()->At(0)->GetName();
ULong64_t t1 = haha.Atoll();
haha = timeStamp->GetListOfLines()->At(1)->GetName();
ULong64_t t2 = haha.Atoll();
haha = timeStamp->GetListOfLines()->At(2)->GetName();
int RunID = haha.Atoi();
totDuration += (t2-t1)*8./1e9;
startTime.push_back(t1);
stopTime.push_back(t2);
runList.push_back(RunID);
}
//======== format CanvasTitle
std::sort(runList.begin(), runList.end());
TString title = "Run:" + create_range_string(runList);
title += Form(" | %.0f min", totDuration/60.) ;
//Some input to TSelector
Monitor * selector = new Monitor();
selector->SetCanvasTitle(title);
selector->SetStartStopTimes(startTime, stopTime);
chain->Process(selector, "");
delete chain;
delete selector;
} }
std::string create_range_string(const std::vector<int>& nums) {
std::string range_str;
int lastNum = nums[0];
int rangeStart = lastNum;
for (int i = 1; i < nums.size(); i++) {
if (nums[i] == lastNum + 1) {
lastNum = nums[i];
} else {
if (rangeStart == lastNum) {
range_str += std::to_string(rangeStart) + "_";
} else {
range_str += std::to_string(rangeStart) + "-" + std::to_string(lastNum) + "_";
}
rangeStart = lastNum = nums[i];
}
}
// Add the last range
if (rangeStart == lastNum) {
range_str += std::to_string(rangeStart);
} else {
range_str += std::to_string(rangeStart) + "-" + std::to_string(lastNum);
}
return range_str;
}

View File

@ -347,6 +347,7 @@ void MonPlotter::SetUpHistograms(int * rawEnergyRange,
} }
//^####################################################### Plot
void MonPlotter::Plot(){ void MonPlotter::Plot(){
//TODO a more user-friendly way. //TODO a more user-friendly way.
@ -367,6 +368,7 @@ void MonPlotter::Plot(){
} }
} }
//^#######################################################
void MonPlotter::LoadRDTGate(TString rdtCutFile){ void MonPlotter::LoadRDTGate(TString rdtCutFile){
if( rdtCutFile == "" ) return ; if( rdtCutFile == "" ) return ;

View File

@ -51,18 +51,13 @@ std::vector<TString> rdtCutFile1 = {"", ""}; /// {reaction-0, reaction-1}, can a
MonPlotter ** plotter = nullptr; MonPlotter ** plotter = nullptr;
int numGeo = 1; int numGeo = 1;
TChain *gen_tree = nullptr;
void MonAnalyzer(){ void Monitor(TChain *gen_tree){
printf("#####################################################################\n"); printf("#####################################################################\n");
printf("####################### MonAnalyzer.C #######################\n"); printf("####################### Monitor.C #######################\n");
printf("#####################################################################\n"); printf("#####################################################################\n");
gen_tree = new TChain("gen_tree");
//gen_tree->Add("../root_data/gen_run043.root");
gen_tree->Add("../root_data/trace_run033.root");
TObjArray * fileList = gen_tree->GetListOfFiles(); TObjArray * fileList = gen_tree->GetListOfFiles();
printf("\033[0;31m========================================== Number of Files : %2d\n",fileList->GetEntries()); printf("\033[0;31m========================================== Number of Files : %2d\n",fileList->GetEntries());
fileList->Print(); fileList->Print();
@ -71,7 +66,44 @@ void MonAnalyzer(){
printf("///////////////////////////////////////////////////////////////////\n"); printf("///////////////////////////////////////////////////////////////////\n");
printf(" Total Number of entries : %llu \n", gen_tree->GetEntries()); printf(" Total Number of entries : %llu \n", gen_tree->GetEntries());
printf("///////////////////////////////////////////////////////////////////\n"); printf("///////////////////////////////////////////////////////////////////\n");
if( gen_tree->GetEntries() == 0 ) {
printf("========= no events. Abort.\n");
return;
}
double totDuration = 0;
std::vector<ULong64_t> startTime;
std::vector<ULong64_t> stopTime;
std::vector<int> runList;
for( int i = 0; i < fileList->GetEntries(); i++){
TString fileName = fileList->At(i)->GetTitle();
TFile file(fileName);
TMacro * timeStamp = (TMacro*) file.FindObjectAny("timeStamp");
//timeStamp->Print();
TString haha = timeStamp->GetListOfLines()->At(0)->GetName();
ULong64_t t1 = haha.Atoll();
haha = timeStamp->GetListOfLines()->At(1)->GetName();
ULong64_t t2 = haha.Atoll();
haha = timeStamp->GetListOfLines()->At(2)->GetName();
int RunID = haha.Atoi();
totDuration += (t2-t1)*8./1e9;
startTime.push_back(t1);
stopTime.push_back(t2);
runList.push_back(RunID);
}
//======== format CanvasTitle
std::sort(runList.begin(), runList.end());
TString title = "Run:" + AnalysisLib::create_range_string(runList);
title += Form(" | %.0f min", totDuration/60.) ;
//*===========================================================
TTreeReader reader(gen_tree); TTreeReader reader(gen_tree);
TTreeReaderValue<ULong64_t> evID = {reader, "evID"}; TTreeReaderValue<ULong64_t> evID = {reader, "evID"};
@ -115,7 +147,7 @@ void MonAnalyzer(){
plotter = new MonPlotter *[numGeo]; plotter = new MonPlotter *[numGeo];
for( int i = 0; i < numGeo; i++ ) { for( int i = 0; i < numGeo; i++ ) {
plotter[i] = new MonPlotter(i, detGeo, mapping::NRDT); plotter[i] = new MonPlotter(i, detGeo, mapping::NRDT);
plotter[i]->SetUpCanvas("haha", 500, 3, 2); //TODO canvaseTitle plotter[i]->SetUpCanvas(title, 500, 3, 2);
plotter[i]->SetUpHistograms(rawEnergyRange, energyRange, exRange, thetaCMRange, rdtDERange, rdtERange, coinTimeRange); plotter[i]->SetUpHistograms(rawEnergyRange, energyRange, exRange, thetaCMRange, rdtDERange, rdtERange, coinTimeRange);
} }
@ -398,15 +430,11 @@ void MonAnalyzer(){
printf(" raw() - Raw data\n"); printf(" raw() - Raw data\n");
printf(" cal() - Calibrated data\n"); printf(" cal() - Calibrated data\n");
printf(" rdt() - Raw RDT data\n"); printf(" rdt() - Raw RDT data\n");
//printf(" elum() - Luminosity Energy Spectra\n");
printf("-----------------------------------------------------\n"); printf("-----------------------------------------------------\n");
printf(" ez() - Energy vs. Z\n"); printf(" ez() - Energy vs. Z\n");
printf("-----------------------------------------------------\n"); printf("-----------------------------------------------------\n");
printf(" excite() - Excitation Energy\n"); printf(" excite() - Excitation Energy\n");
//printf(" elum() - Luminosity Energy Spectra\n");
//printf(" ic() - Ionization Chamber Spectra\n");
// printf(" eCalVzRow() - Energy vs. Z for each row\n");
// printf(" ExThetaCM() - Ex vs ThetaCM\n");
// printf(" ExVxCal() - Ex vs X for all %d detectors\n", numDet);
// printf("-----------------------------------------------------\n"); // printf("-----------------------------------------------------\n");
// printf(" ShowFitMethod() - Shows various fitting methods \n"); // printf(" ShowFitMethod() - Shows various fitting methods \n");
// printf(" RDTCutCreator() - Create RDT Cuts [May need to edit]\n"); // printf(" RDTCutCreator() - Create RDT Cuts [May need to edit]\n");
@ -414,8 +442,8 @@ void MonAnalyzer(){
// printf(" readTrace() - read trace from gen_runXXX.root \n"); // printf(" readTrace() - read trace from gen_runXXX.root \n");
// printf(" readRawTrace() - read trace from runXXX.root \n"); // printf(" readRawTrace() - read trace from runXXX.root \n");
// printf(" Check1D() - Count Integral within a range\n"); // printf(" Check1D() - Count Integral within a range\n");
// printf("-----------------------------------------------------\n"); printf("-----------------------------------------------------\n");
// printf(" %s\n", canvasTitle.Data()); printf(" %s\n", title.Data());
printf("-----------------------------------------------------\n"); printf("-----------------------------------------------------\n");
} }

View File

@ -1,30 +0,0 @@
//enum plotID { pEZ, /// 0
// pRecoilXY, /// 1
// pThetaCM, /// 2
// pExCal, /// 3
// pArrayXY, /// 4
// pInfo, /// 5
// pElum1XY, /// 6
// pRecoilXY1, /// 7
// pRecoilXY2, /// 8
// pTDiffZ, /// 9
// pRecoilRThetaCM, /// 10
// pRecoilRZ, /// 11
// pEElum1R, /// 12
// pRecoilRTR, /// 13
// pThetaCM_Z, /// 14
// pElum1RThetaCM, /// 15
// pEmpty }; /// 16
//============================================== User Config
//*============================ Canvas Setting, take the shape of the Canvas
pEZ, pExCal, pArrayXY, pTDiffZ
pThetaCM, pRecoilXY, pInfo, pThetaCM_Z
//^============================= Gate Setting
hit == 1 && loop <= 1 && thetaCM > 10
//@============================= Other Settings
elum_Max : 60 //mm
thetaCM_Max : 50 //deg
//#============================== example of gate
hit == 1 && loop <= 1 && thetaCM > 10 && detRowID == 0
hit == 1 && loop <= 1
15 < rhoElum1 && rhoElum1 < 50 && rhoElum2 > 60