diff --git a/Armory/AnalysisLib.h b/Armory/AnalysisLib.h index c739d55..b2c5a40 100644 --- a/Armory/AnalysisLib.h +++ b/Armory/AnalysisLib.h @@ -339,6 +339,31 @@ std::vector> FindMatchingPair(std::vector enX, std:: } +std::string create_range_string(const std::vector& 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; +} + } diff --git a/Armory/Process_Run b/Armory/Process_Run index f66144a..b9d570f 100755 --- a/Armory/Process_Run +++ b/Armory/Process_Run @@ -24,6 +24,9 @@ if [ $# -eq 0 ] || [ $1 == "-help" ]; then echo " = 2 WS fit" echo " = 3 trapezoid(not implemented)" 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 "" echo " * negative option = force." @@ -51,12 +54,8 @@ fi nWorker=$((nWorker % 100 )); -if [ "$RUN" == "lastRun" ]; then - RUN=$runID -fi - -RUN=${RUN##*(0)} #remove zero -RUN=$(printf '%03d' $RUN) ##add back the zero +runNum=${RUN#0} #remove zero +RUN=$(printf '%03d' $runNum) ##add back the zero ################################### Setting display echo "#################################################" @@ -92,7 +91,7 @@ fi if [ $isMonitor -eq 0 ]; then echo -e "${LRED}>>>>>>>>>>>>>>>>>>>>> Monitor Skipped by user. ${NC}" elif [ $isMonitor -eq 1 ]; then - root -l "ChainMonitors.C($RUN)" + root -l "ChainMonitors.C($runNum)" elif [ $isMonitor -eq 2 ]; then root -l "ChainMonitors.C" fi diff --git a/working/ChainMonitors.C b/working/ChainMonitors.C index c53b661..83255a9 100644 --- a/working/ChainMonitors.C +++ b/working/ChainMonitors.C @@ -2,107 +2,36 @@ #include "TObjArray.h" #include "TFile.h" #include "TMacro.h" -std::string create_range_string(const std::vector& nums); +#include "TChain.h" + +TChain *gen_tree = nullptr; void ChainMonitors(int RUNNUM = -1, int RUNNUM2 = -1) { ///default saveCanvas = false, no save Cavas /// = true, save Canvas - TChain * chain = new TChain("gen_tree"); + gen_tree = new TChain("gen_tree"); if( RUNNUM == -1){ /// this list only for manual Chain sort ///********** start Marker for AutoCalibration. - chain->Add("../root_data/gen_run005.root"); - chain->Add("../root_data/gen_run003.root"); - ///chain->Add("../root_data/trace_run135.root"); + gen_tree->Add("../root_data/trace_run033.root"); ///********** end Marker for AutoCalibration. - }else{ TString fileName; int endRUNNUM = RUNNUM2; if( RUNNUM2 == -1) endRUNNUM = RUNNUM; - + for( int i = RUNNUM ; i <= endRUNNUM ; i++){ fileName.Form("../root_data/gen_run%03d.root", i); - chain->Add(fileName); + gen_tree->Add(fileName); } } - TObjArray * fileList = chain->GetListOfFiles(); - - 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()); + //^============== should have other things, like calibrations. + Monitor(gen_tree); - double totDuration = 0; - std::vector startTime; - std::vector stopTime; - std::vector 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& 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; -} \ No newline at end of file diff --git a/working/ClassMonPlotter.h b/working/ClassMonPlotter.h index c002088..9f40f4d 100644 --- a/working/ClassMonPlotter.h +++ b/working/ClassMonPlotter.h @@ -347,6 +347,7 @@ void MonPlotter::SetUpHistograms(int * rawEnergyRange, } +//^####################################################### Plot void MonPlotter::Plot(){ //TODO a more user-friendly way. @@ -367,6 +368,7 @@ void MonPlotter::Plot(){ } } +//^####################################################### void MonPlotter::LoadRDTGate(TString rdtCutFile){ if( rdtCutFile == "" ) return ; diff --git a/working/MonAnalyzer.C b/working/Monitor.C similarity index 92% rename from working/MonAnalyzer.C rename to working/Monitor.C index 1996482..a1a8a61 100644 --- a/working/MonAnalyzer.C +++ b/working/Monitor.C @@ -51,18 +51,13 @@ std::vector rdtCutFile1 = {"", ""}; /// {reaction-0, reaction-1}, can a MonPlotter ** plotter = nullptr; int numGeo = 1; -TChain *gen_tree = nullptr; -void MonAnalyzer(){ +void Monitor(TChain *gen_tree){ printf("#####################################################################\n"); - printf("####################### MonAnalyzer.C #######################\n"); + printf("####################### Monitor.C #######################\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(); printf("\033[0;31m========================================== Number of Files : %2d\n",fileList->GetEntries()); fileList->Print(); @@ -71,7 +66,44 @@ void MonAnalyzer(){ printf("///////////////////////////////////////////////////////////////////\n"); printf(" Total Number of entries : %llu \n", gen_tree->GetEntries()); printf("///////////////////////////////////////////////////////////////////\n"); + + if( gen_tree->GetEntries() == 0 ) { + printf("========= no events. Abort.\n"); + return; + } + double totDuration = 0; + std::vector startTime; + std::vector stopTime; + std::vector 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); TTreeReaderValue evID = {reader, "evID"}; @@ -115,7 +147,7 @@ void MonAnalyzer(){ plotter = new MonPlotter *[numGeo]; for( int i = 0; i < numGeo; i++ ) { 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); } @@ -398,15 +430,11 @@ void MonAnalyzer(){ printf(" raw() - Raw data\n"); printf(" cal() - Calibrated data\n"); printf(" rdt() - Raw RDT data\n"); + //printf(" elum() - Luminosity Energy Spectra\n"); printf("-----------------------------------------------------\n"); printf(" ez() - Energy vs. Z\n"); printf("-----------------------------------------------------\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(" ShowFitMethod() - Shows various fitting methods \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(" readRawTrace() - read trace from runXXX.root \n"); // printf(" Check1D() - Count Integral within a range\n"); - // printf("-----------------------------------------------------\n"); - // printf(" %s\n", canvasTitle.Data()); + printf("-----------------------------------------------------\n"); + printf(" %s\n", title.Data()); printf("-----------------------------------------------------\n"); } diff --git a/working/SimChecker_Config.txt b/working/SimChecker_Config.txt deleted file mode 100644 index c51ed69..0000000 --- a/working/SimChecker_Config.txt +++ /dev/null @@ -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