diff --git a/.gitignore b/.gitignore index f039f32..dd44c24 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,9 @@ working/Settings EventBuilder *.root +*.pcm +*.d +*.so data_raw root_data \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index a56a955..32b967d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -70,7 +70,12 @@ "qdatetime": "cpp", "fstream": "cpp", "allocator": "cpp", - "qsignalmapper": "cpp" + "qsignalmapper": "cpp", + "GeneralSort.C": "cpp", + "forward_list": "cpp", + "ChainMonitors.C": "cpp", + "GeneralSortAgent.C": "cpp", + "kaka.C": "cpp" }, "better-comments.multilineComments": true, diff --git a/SOLARIS.sh b/SOLARIS.sh index 9d66d49..5e9bcd8 100644 --- a/SOLARIS.sh +++ b/SOLARIS.sh @@ -1,23 +1,36 @@ -#=================== Main -unset SOLARISSYS + +#========== this script define the SOLARISANADIR as global env. + +unset SOLARISANADIR SOURCE=${BASH_ARGV[0]} PCName=$(uname -n) if [ $(uname -n) == "solaris-daq" ]; then - SOLARISSYS=~/Analysis + SOLARISANADIR=~/Analysis else if [ $(pwd) == $HOME ]; then - SOLARISSYS=$(dirname ${SOURCE}) + SOLARISANADIR=$(dirname ${SOURCE}) - if [[ ${SOLARISSYS} == *"$HOME"* ]]; then + if [[ ${SOLARISANADIR} == *"$HOME"* ]]; then dummpy=0 else - SOLARISSYS=${HOME}/$SOLARISSYS + SOLARISANADIR=${HOME}/$SOLARISANADIR fi else - SOLARISSYS=$(pwd) + SOLARISANADIR=$(pwd) fi fi -export SOLARISSYS \ No newline at end of file +export SOLARISANADIR + +echo "####### set global variable SOLARISANADIR = ${SOLARISANADIR}" + +export PATH=$PATH:$SOLARISANADIR/armory + +echo "####### add ${SOLARISANADIR}/armory into PATH" + + +########################### + +alias 2Working='cd ${SOLARISANADIR}/working' diff --git a/SetupNewExp b/SetupNewExp index 17512aa..50a0ffc 100755 --- a/SetupNewExp +++ b/SetupNewExp @@ -9,70 +9,7 @@ ## #################################################### - -RED='\033[1;31m' -YELLOW='\033[1;33m' -ORANGE='\033[0;33m' -GREEN='\033[1;32m' -BLUE='\033[0;34m' -Cyan='\033[0;36m' -NC='\033[0m' #no color - - -############## need to distingish mac and daq -Arch="$(uname -s)" -PCName="$(hostname)" -PCID=-1 #if PCID == 1 (DAQ), 2 (MAC), -1(OTHER) - -#------ Set up data folder, check disk space -echo -e "${YELLOW} 0) ################## Check computer name and arch. ${NC}" -echo "PC name : ${PCName}" -echo "Archetech: ${Arch}" - -if [ ${Arch} == "Linux" ] && [ ${PCName} == "solaris-daq" ]; then - - PCID=1 - - pathsSetting=${HOME}/SOLARIS_QT6_DAQ/programSettings.txt - if [ -e ${pathsSetting} ]; then - echo "Found DAQ programSettings.txt for paths settings" - - analysisPath=$(cat ${pathsSetting} | head -n 2 | tail -n 1) - - if [ "${analysisPath}" = "$(pwd)" ]; then - echo "The analysisPath from ${analysisPath} is same as the present folder $(pwd)" - else - echo "The analysisPath from ${analysisPath} is different from present folder $(pwd). Abort." - exit - fi - - rawDataPathParent=$(cat ${pathsSetting} | head -n 3 | tail -n 1) - rootDataPathParent=$(cat ${pathsSetting} | head -n 4 | tail -n 1) - - databaseIP=$(cat ${pathsSetting} | head -n 6 | tail -n 1) - databaseName=$(cat ${pathsSetting} | head -n 7 | tail -n 1) - - #echo ${rawDataPathParent} - #echo ${rootDataPathParent} - #echo ${databaseIP} - #echo ${databaseName} - - else - - echo "${RED} Cannot found DAQ programSettings.txt for path settings ${NC}" - echo "Seek Ryan for help" - exit - - fi - -fi - - -if [ ${Arch} == "Darwin" ] && [ ${PCName} == "SOLARISs-Mac-Studio.local" ]; then - PCID=2 - rawDataPathParent=${HOME}/experimentalData/ - rootDataPathParent=${HOME}/experimentalData/ -fi +source armory/Process_BasicConfig ############### Check is git exist isGitExist=0 @@ -105,11 +42,10 @@ echo " 6) Tell Database SetupNewExp change exp. (only from the DAQ)" echo " 7) git push (if new exp.)" echo "=============================================================" - expName=$1 ############### this will define global enviroment varibales, like the analysis path, export armory -#source SOLARIS.sh +source SOLARIS.sh ############### Check git echo -e "${YELLOW} 1) ################## Git Fetch ${NC}" @@ -146,7 +82,7 @@ else if [ ${PCID} -eq 1 ]; then - echo -e "You are going to create a${GREEN} NEW ${NC}branch ${Cyan}${expName}${NC} from branch : $(git branch --show-current)" + echo -e "You are going to create a${GREEN} NEW ${NC}branch ${CYAN}${expName}${NC} from branch : $(git branch --show-current)" read -p "Are you sure? (Y/N) " createNewBranch if [ ${createNewBranch} == "Y" ]; then git checkout -b ${expName} @@ -156,7 +92,7 @@ else else - echo -e "${Cyan} ONLY the DAQ machines can create branch ${NC}" + echo -e "${CYAN} ONLY the DAQ machines can create branch ${NC}" fi @@ -190,6 +126,7 @@ if [ ${isBranchExist} -eq 0 ]; then echo "rootDataPath=${rootDataPathParent}"/${expName} >> ${expNamePath} echo "runID=0" >> ${expNamePath} echo "elogID=0" >> ${expNamePath} + echo "#------------end of file." >> ${expNamePath} fi echo -e "${YELLOW} 4) ################## making new folders in ${rawDataPathParent} ${NC}" @@ -231,11 +168,14 @@ if [ ${PCID} -eq 1 ]; then echo -e "=================== Tell the database" haha1=${databaseIP}"/write?db="${databaseName} - haha2="RunID,start=0 value=0,expName=\"${expName}\",comment=\"New_experiment_[${expName}]_was_created\"" + if [ ${isBranchExist} -eq 0 ]; then + haha2="RunID,start=0 value=0,expName=\"${expName}\",comment=\"New_experiment_[${expName}]_was_created.\"" + else + haha2="RunID,start=0 value=0,expName=\"${expName}\",comment=\"New_experiment_[${expName}]_was_switched.\"" + fi #echo $haha1 #echo $haha2 - curl -s -v -XPOST "$haha1" --data-binary "$haha2" --max-time 1 --connect-timeout 1 #===== clean up working if it is new diff --git a/armory/AnalysisLib.h b/armory/AnalysisLib.h new file mode 100644 index 0000000..8fe5e63 --- /dev/null +++ b/armory/AnalysisLib.h @@ -0,0 +1,65 @@ +#ifndef ANALYSIS_LIB_H +#define ANALYSIS_LIB_H + +#include +#include +#include + +std::vector ExtractDetNum(std::vector> mapping, std::vector detName, std::vector detMaxID){ + std::vector detNum; + for( int i = 0; i < (int) detName.size(); i ++) detNum.push_back(0); + for( int i = 0; i < (int) mapping.size(); i ++){ + for( int j = 0; j < (int) mapping[i].size(); j++){ + if( mapping[i][j] < 0) continue; + for( int k = 0; k < (int) detName.size() ; k ++ ){ + int low = (k == 0 ? 0 : detMaxID[k-1]); + int high = detMaxID[k]; + if( low <= mapping[i][j] && mapping[i][j] < high ) { + detNum[k]++; + } + } + } + } + return detNum; +} + +void PrintMapping(std::vector> mapping, std::vector detName, std::vector detMaxID){ + + //------------ Red Green Yellow Cyan + std::vector Color = {"\033[31m", "\033[32m", "\033[33m", "\033[36m"}; + + printf("==================================== Mapping ===================================\n"); + std::vector detNum = ExtractDetNum(mapping, detName, detMaxID); + for(int i = 0 ; i < (int) detName.size(); i++) { + printf(" %2d | %7s | %3d | %3d - %3d\n", i, detName[i].c_str(), detNum[i], (i == 0 ? 0 : detMaxID[i-1]), detMaxID[i]); + } + for( int i = 0; i < (int) mapping.size(); i++){ + printf("Digi-%d ------------------------------------------------------------------------ \n", i); + int colorIndex = -1; + for( int j = 0; j < (int) mapping[i].size(); j++){ + if( mapping[i][j] < 0 ){ + printf("%4d,", mapping[i][j]); + }else{ + for( int k = 0; k < (int) detName.size() ; k ++ ){ + int low = (k == 0 ? 0 : detMaxID[k-1]); + int high = detMaxID[k]; + if( low <= mapping[i][j] && mapping[i][j] < high ) { + if( k == 0 ) { + colorIndex = (colorIndex + 1) % 3; + }else{ + colorIndex = 3; + } + printf("%s%4d\033[0m,", Color[colorIndex], mapping[i][j]); + } + } + } + if( j % 16 == 15 ) printf("\n"); + } + } + printf("================================================================================\n"); +} + + + + +#endif \ No newline at end of file diff --git a/armory/EventBuilder.cpp b/armory/EventBuilder.cpp index 9f0e4c2..9af05be 100644 --- a/armory/EventBuilder.cpp +++ b/armory/EventBuilder.cpp @@ -6,8 +6,9 @@ #include "TTree.h" #include "TMath.h" #include "TString.h" -#include "TClonesArray.h" -#include "TVector.h" +#include "TMacro.h" +//#include "TClonesArray.h" // plan to save trace as TVector with TClonesArray +//#include "TVector.h" #define MAX_ID 64 #define MAX_TRACE_LEN 2500 @@ -41,14 +42,18 @@ int bd[MAX_ID] = {0}; int ch[MAX_ID] = {0}; int e[MAX_ID] = {0}; unsigned long long e_t[MAX_ID] = {0}; +unsigned short lowFlag[MAX_ID] = {0}; +unsigned short highFlag[MAX_ID] = {0}; int traceLen[MAX_ID] = {0}; -int trace[MAX_ID][MAX_TRACE_LEN] = {0}; +int trace[MAX_ID][MAX_TRACE_LEN] = {0}; void fillData(int &fileID, const bool &saveTrace){ bd[multi] = fileID; ch[multi] = evt[fileID]->channel; e[multi] = evt[fileID]->energy; e_t[multi] = evt[fileID]->timestamp; + lowFlag[multi] = evt[fileID]->flags_low_priority; + highFlag[multi] = evt[fileID]->flags_high_priority; if( saveTrace ){ traceLen[multi] = evt[fileID]->traceLenght; @@ -108,19 +113,20 @@ int main(int argc, char ** argv){ TTree * tree = new TTree("tree", outFileName); - tree->Branch("evID", &evID, "event_ID/l"); - tree->Branch("multi", &multi, "multi/I"); - tree->Branch("bd", bd, "board[multi]/I"); - tree->Branch("ch", ch, "channel[multi]/I"); - tree->Branch("e", e, "energy[multi]/I"); - tree->Branch("e_t", e_t, "energy_timestamp[multi]/l"); + tree->Branch("evID", &evID, "event_ID/l"); + tree->Branch("multi", &multi, "multi/I"); + tree->Branch("bd", bd, "board[multi]/I"); + tree->Branch("ch", ch, "channel[multi]/I"); + tree->Branch("e", e, "energy[multi]/I"); + tree->Branch("e_t", e_t, "energy_timestamp[multi]/l"); + tree->Branch("lowFlag", lowFlag, "lowFlag[multi]/s"); + tree->Branch("highFlag", highFlag, "highFlag[multi]/s"); if( saveTrace){ tree->Branch("tl", traceLen, "traceLen[multi]/I"); tree->Branch("trace", trace, Form("trace[multi][%d]/I", MAX_TRACE_LEN)); } - reader = new SolReader*[nFile]; evt = new Event *[nFile]; @@ -141,6 +147,9 @@ int main(int argc, char ** argv){ findEarliestTime(nFile, fileID); fillData(fileID, saveTrace); + unsigned long firstTimeStamp = evt[fileID]->timestamp; + unsigned long lastTimeStamp = 0; + int last_precentage = 0; unsigned count = 1; @@ -163,6 +172,9 @@ int main(int argc, char ** argv){ } count ++; + + if( count == totNumEvent ) lastTimeStamp = evt[fileID]->timestamp; + int percentage = count * 100/totNumEvent; if( percentage > last_precentage ) { @@ -175,8 +187,24 @@ int main(int argc, char ** argv){ outRootFile->cd(); tree->Write(); - printf("===================================== done. "); - printf("Number of Event Built is %lld .\n", evID); + + //======== Save timestamp as TMacro + TMacro timeStamp; + TString str; + str.Form("%lu", firstTimeStamp); timeStamp.AddLine( str.Data() ); + str.Form("%lu", lastTimeStamp); timeStamp.AddLine( str.Data() ); + + timeStamp.Write("timeStamp"); + + + printf("===================================== done. \n"); + printf("Number of Event Built : %lld\n", evID); + printf(" first timestamp : %lu \n", firstTimeStamp); + printf(" last timestamp : %lu \n", lastTimeStamp); + unsigned long duration = lastTimeStamp - firstTimeStamp; + printf(" total duration : %lu = %.2f sec \n", duration, duration * tick2ns * 1.0 / 1e9 ); + printf("===================================== end of summary. \n"); + //^############## delete new for( int i = 0; i < nFile; i++) delete reader[i]; diff --git a/armory/GeneralSort.C b/armory/GeneralSort.C new file mode 100644 index 0000000..27a5a1f --- /dev/null +++ b/armory/GeneralSort.C @@ -0,0 +1,152 @@ +#define GeneralSort_cxx + +#include +#include +#include + +#include "GeneralSort.h" + +#include +#include +#include +#include + +//^############################################################## +Bool_t GeneralSort::Process(Long64_t entry){ + + if( entry < 2 ) printf("%s %lld\n", __func__, entry); + + ///initialization + for( int i = 0; i < detNum[0]; i++){ + eE[i] = TMath::QuietNaN(); + xf[i] = TMath::QuietNaN(); + xn[i] = TMath::QuietNaN(); + eT [i] = 0; + xfT[i] = 0; + xnT[i] = 0; + + if( isTraceExist && traceMethod > 0 ){ + teE[i] = TMath::QuietNaN(); + teT[i] = TMath::QuietNaN(); + teR[i] = TMath::QuietNaN(); + } + } + + for( int i = 0; i < detNum[1]; i++){ + rdt[i] = TMath::QuietNaN(); + rdtT[i] = 0; + if( isTraceExist && traceMethod > 0 ){ + trdt[i] = TMath::QuietNaN(); + trdtT[i] = TMath::QuietNaN(); + trdtR[i] = TMath::QuietNaN(); + } + } + + multi = 0; + b_event_ID->GetEntry(entry); + b_multi->GetEntry(entry); + b_bd->GetEntry(entry); + b_ch->GetEntry(entry); + b_e->GetEntry(entry); + b_e_t->GetEntry(entry); + + + for( int i = 0 ; i < multi; i++){ + int detID = mapping[bd[i]][ch[i]]; + int kindIndex = -1; + + for( int g = 0; g < (int) detMaxID.size(); g ++){ + int low = ( g == 0 ? 0 : detMaxID[g-1]); + int high = detMaxID[g]; + + if( low <= detID && detID < high ){ + + //************** array + if( g == 0 ){ + kindIndex = (kindIndex + 1) % 3; + switch (kindIndex){ + case 0 : { eE[detID] = e[i] * detParity[g]; eT[detID] = e_t[i]; } break; + case 1 : { xf[detID] = e[i] * detParity[g]; xfT[detID] = e_t[i]; } break; + case 2 : { xn[detID] = e[i] * detParity[g]; xnT[detID] = e_t[i]; } break; + } + } + + //************** rdt + if( g == 1 ){ + detID = detID - detMaxID[g-1]; + rdt[detID] = e[i] * detParity[g]; rdtT[detID] = e_t[i]; + } + + } + + } + } + + + if( isTraceExist && traceMethod >= 0 ){ + + int countTrace = 0; + + arr->Clear("C"); + + for( int i = 0; i < multi; i++){ + int detID = mapping[bd[i]][ch[i]]; + + } + + + } + + + newTree->Fill(); + + return kTRUE; +} + +//^############################################################## +void GeneralSort::Terminate(){ + + printf("========================= %s\n", __func__); + + TString option = GetOption(); + TObjArray * tokens = option.Tokenize(","); + traceMethod = ((TObjString*) tokens->At(0))->String().Atoi(); + saveFileName = ((TObjString*) tokens->At(1))->String(); + + //get entries + saveFile = TFile::Open(saveFileName); + if( saveFile->IsOpen() ){ + TTree * tree = (TTree*) saveFile->FindObjectAny("gen_tree"); + int validCount = tree->GetEntries(); + + saveFile->Close(); + + printf("=======================================================\n"); + PrintTraceMethod(); + printf("----- saved as \033[1;33m%s\033[0m. valid event: %d\n", saveFileName.Data() , validCount); + } +} + +//^############################################################## +void GeneralSort::Begin(TTree * tree){ + + printf( "=================================================================\n"); + printf( "===================== SOLARIS GeneralSort.C =================\n"); + printf( "=================================================================\n"); + + PrintMapping(mapping, detName, detMaxID); + +} + +void GeneralSort::SlaveBegin(TTree * /*tree*/){ + printf("%s\n", __func__); + +} + +void GeneralSort::SlaveTerminate(){ + printf("%s\n", __func__); + saveFile->cd(); + newTree->Write(); + fOutput->Add(proofFile); + saveFile->Close(); +} \ No newline at end of file diff --git a/armory/GeneralSort.h b/armory/GeneralSort.h new file mode 100644 index 0000000..7b04bd2 --- /dev/null +++ b/armory/GeneralSort.h @@ -0,0 +1,275 @@ +#ifndef GeneralSort_h +#define GeneralSort_h + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/*********************************======= + +the sequence of each method + +1) Begin (master, stdout) + 2) SlaveBegin (slave) + 3) Init + 4) Notify + 5) Process (looping each event) + 6) SlaveTerminate +7) Terminate + +// variable in the Master will not pass to Slave + +******************************************/ + + +/// in Process_Sort, copy the GeneralSortMapping.h to ~/.proof/working/ +#include "../working/Mapping.h" +#include "../armory/AnalysisLib.h" + +double fitFunc(double * x, double * par){ + /// par[0] = A + /// par[1] = t0 + /// par[2] = rise time + /// par[3] = baseline + /// par[4] = decay + /// par[5] = pre-rise slope + + if( x[0] < par[1] ) return par[3] + par[5] * (x[0]-par[1]); + + return par[3] + par[0] * (1 - TMath::Exp(- (x[0] - par[1]) / par[2]) ) * TMath::Exp(- (x[0] - par[1]) / par[4]); +} + +// Header file for the classes stored in the TTree if any. +class GeneralSort : public TSelector { +public : + TTree *fChain; //!pointer to the analyzed TTree or TChain + +// Fixed size dimensions of array or collections stored in the TTree if any. + + // Declaration of leaf types + ULong64_t evID; + Int_t multi; + Int_t bd[100]; //[multi] + Int_t ch[100]; //[multi] + Int_t e[100]; //[multi] + ULong64_t e_t[100]; //[multi] + UShort_t lowFlag[100]; //[multi] + UShort_t highFlag[100]; //[multi] + Int_t tl[100]; //[multi] + Int_t trace[100][2500]; //[multi] + + // List of branches + TBranch *b_event_ID; //! + TBranch *b_multi; //! + TBranch *b_bd; //! + TBranch *b_ch; //! + TBranch *b_e; //! + TBranch *b_e_t; //! + TBranch *b_lowFlag; //! + TBranch *b_highFlag; //! + TBranch *b_tl; //! + TBranch *b_trace; //! + + GeneralSort(TTree * /*tree*/ =0) : fChain(0) { + printf("constructor :: %s\n", __func__); + + isTraceExist = false; + traceMethod = 0; // -1 = ignore trace, 0 = no trace fit, 1 = fit, 2 = trapezoid + + } + virtual ~GeneralSort() { } + virtual Int_t Version() const { return 2; } + virtual void Begin(TTree *tree); + virtual void SlaveBegin(TTree *tree); + virtual void Init(TTree *tree); + virtual Bool_t Notify(); + virtual Bool_t Process(Long64_t entry); + virtual Int_t GetEntry(Long64_t entry, Int_t getall = 0) { return fChain ? fChain->GetTree()->GetEntry(entry, getall) : 0; } + virtual void SetOption(const char *option) { fOption = option; } + virtual void SetObject(TObject *obj) { fObject = obj; } + virtual void SetInputList(TList *input) { fInput = input; } + virtual TList *GetOutputList() const { return fOutput; } + virtual void SlaveTerminate(); + virtual void Terminate(); + + ClassDef(GeneralSort,0); + + bool isTraceExist; + int traceMethod; + + void SetTraceMethod(int methodID) {traceMethod = methodID;} + void PrintTraceMethod(); + + std::vector detNum; + + TString saveFileName; + TFile * saveFile; //! + TProofOutputFile * proofFile; //! + TTree * newTree; //! + + //TODO ---- 2D array + Float_t *eE; //! + ULong64_t *eT; //! + + Float_t *xf ; //! + ULong64_t *xfT; //! + + Float_t *xn ; //! + ULong64_t *xnT; //! + + Float_t *rdt ; //! + ULong64_t *rdtT; //! + + //trace + TClonesArray * arr ;//! + TGraph * gTrace; //! + TClonesArray * arrTrapezoid ;//! + TGraph * gTrapezoid; //! + + Float_t *teE; //! + Float_t *teT; //! + Float_t *teR; //! + + Float_t *trdt ; //! + Float_t *trdtT ; //! + Float_t *trdtR ; //! + +}; + +#endif + +#ifdef GeneralSort_cxx + +//^############################################################## +void GeneralSort::Init(TTree *tree){ + + printf("%s\n", __func__); + + // Set branch addresses and branch pointers + if (!tree) return; + fChain = tree; + fChain->SetMakeClass(1); + + fChain->SetBranchAddress("evID", &evID, &b_event_ID); + fChain->SetBranchAddress("multi", &multi, &b_multi); + fChain->SetBranchAddress("bd", bd, &b_bd); + fChain->SetBranchAddress("ch", ch, &b_ch); + fChain->SetBranchAddress("e", e, &b_e); + fChain->SetBranchAddress("e_t", e_t, &b_e_t); + fChain->SetBranchAddress("lowFlag", lowFlag, &b_lowFlag); + fChain->SetBranchAddress("highFlag", highFlag, &b_highFlag); + + TBranch * br = (TBranch *) fChain->GetListOfBranches()->FindObject("tl"); + if( br == NULL ){ + printf(" ++++++++ no Trace.\n"); + isTraceExist = false; + }else{ + isTraceExist = true; + fChain->SetBranchAddress("tl", tl, &b_tl); + fChain->SetBranchAddress("trace", trace, &b_trace); + } + + unsigned long NumEntries = fChain->GetEntries(); + printf( "========== total Entry : %ld\n", NumEntries); + + //########################### Get Option + TString option = GetOption(); + TObjArray * tokens = option.Tokenize(","); + traceMethod = ((TObjString*) tokens->At(0))->String().Atoi(); + saveFileName = ((TObjString*) tokens->At(1))->String(); + + if( isTraceExist ){ + PrintTraceMethod(); + }else{ + printf("++++++++ no Trace found\n"); + } + + proofFile = new TProofOutputFile(saveFileName, "M"); + saveFile = proofFile->OpenFile("RECREATE"); + + newTree = new TTree("gen_tree", "Tree After GeneralSort"); + newTree->SetDirectory(saveFile); + newTree->AutoSave(); + + detNum = ExtractDetNum(mapping, detName, detMaxID); + + eE = new Float_t[detNum[0]]; + xf = new Float_t[detNum[0]]; + xn = new Float_t[detNum[0]]; + eT = new ULong64_t[detNum[0]]; + xfT = new ULong64_t[detNum[0]]; + xnT = new ULong64_t[detNum[0]]; + + rdt = new Float_t[detNum[1]]; + rdtT = new ULong64_t[detNum[1]]; + + newTree->Branch("e", eE, Form("Energy[%d]/F", detNum[0])); + newTree->Branch("e_t", eT, Form("Energy_Timestamp[%d]/l", detNum[0])); + + newTree->Branch("xf", xf, Form("XF[%d]/F", detNum[0])); + newTree->Branch("xf_t", xfT, Form("XF_Timestamp[%d]/l", detNum[0])); + + newTree->Branch("xn", xn, Form("XN[%d]/F", detNum[0])); + newTree->Branch("xn_t", xnT, Form("XN_Timestamp[%d]/l", detNum[0])); + + newTree->Branch("rdt", rdt, Form("Recoil[%d]/F", detNum[1])); + newTree->Branch("rdt_t", rdtT, Form("Recoil_Timestamp[%d]/l", detNum[1])); + + if( isTraceExist && traceMethod >= 0){ + + arr = new TClonesArray("TGraph"); + + newTree->Branch("trace", arr, 256000); + arr->BypassStreamer(); + + if( traceMethod > 0 ){ + + teE = new Float_t[detNum[0]]; + teT = new Float_t[detNum[0]]; + teR = new Float_t[detNum[0]]; + + trdt = new Float_t[detNum[1]]; + trdtT = new Float_t[detNum[1]]; + trdtR = new Float_t[detNum[1]]; + + newTree->Branch("te", teE, Form("Trace_Energy[%d]/F", detNum[0])); + newTree->Branch("te_t", teT, Form("Trace_Energy_Time[%d]/F", detNum[0])); + newTree->Branch("te_r", teR, Form("Trace_Energy_RiseTime[%d]/F", detNum[0])); + + newTree->Branch("trdt", trdt , Form("Trace_RDT[%d]/F", detNum[1])); + newTree->Branch("trdt_t", trdtT, Form("Trace_RDT_Time[%d]/F", detNum[1])); + newTree->Branch("trdt_r", trdtR, Form("Trace_RDT_RiseTime[%d]/F", detNum[1])); + } + + } + + + printf("---- end of Init %s\n ", __func__); + +} + +Bool_t GeneralSort::Notify(){ + printf("%s\n", __func__); + return kTRUE; +} + +void GeneralSort::PrintTraceMethod(){ + const char* traceMethodStr; + switch(traceMethod) { + case -1 : traceMethodStr = "Ignore Trace"; break; + case 0 : traceMethodStr = "Copy"; break; + case 1 : traceMethodStr = "Fit"; break; + case 2 : traceMethodStr = "Trapezoid"; break; + default: traceMethodStr = "Unknown"; break; + } + printf(" Trace method ? %s \n", traceMethodStr); +} + + +#endif // #ifdef GeneralSort_cxx diff --git a/armory/GeneralSortAgent.C b/armory/GeneralSortAgent.C new file mode 100644 index 0000000..6ea044a --- /dev/null +++ b/armory/GeneralSortAgent.C @@ -0,0 +1,32 @@ + +#include "TTree.h" +#include "TProof.h" +#include "TChain.h" + +void GeneralSortAgent(Int_t runNum, int nWorker = 1, int traceMethod = 0){ + + TString name; + name.Form("../root_data/run%03d.root", runNum); + + TChain * chain = new TChain("tree"); + chain->Add(name); + + chain->GetListOfFiles()->Print(); + + printf("----------------------------\n"); + + TProof * p = TProof::Open("", Form("workers=%d", abs(nWorker))); + p->ShowCache(); + printf("----------------------------\n"); + + TString option; + + //this is the option for TSelector, the first one is traceMethod, 2nd is save fileName; + option.Form("%d,../root_data/gen_run%03d.root", traceMethod, runNum); + + chain->SetProof(); + chain->Process("../armory/GeneralSort.C+", option); + + + +} \ No newline at end of file diff --git a/armory/Process_BasicConfig b/armory/Process_BasicConfig new file mode 100644 index 0000000..d57ac02 --- /dev/null +++ b/armory/Process_BasicConfig @@ -0,0 +1,68 @@ +#!/bin/bash -l + +############################################## +# +# This script define color, PCID, and dataPath +# +############################################## + +RED='\033[1;31m' +YELLOW='\033[1;33m' +ORANGE='\033[0;33m' +GREEN='\033[1;32m' +BLUE='\033[0;34m' +CYAN='\033[0;36m' +NC='\033[0m' #no color +LRED='\033[1;91m' + +############## need to distingish mac and daq +Arch="$(uname -s)" +PCName="$(hostname)" +PCID=-1 #if PCID == 1 (DAQ), 2 (MAC), -1(OTHER) + +#------ Set up data folder, check disk space +echo -e "${YELLOW} ##################### Check computer name and arch. ${NC}" +echo "PC name : ${PCName}" +echo "Archetech: ${Arch}" + +if [ ${Arch} == "Linux" ] && [ ${PCName} == "solaris-daq" ]; then + + PCID=1 + + pathsSetting=${HOME}/SOLARIS_QT6_DAQ/programSettings.txt + if [ -e ${pathsSetting} ]; then + #echo "Found DAQ programSettings.txt for paths settings" + + analysisPath=$(cat ${pathsSetting} | head -n 2 | tail -n 1) + + if [ ! "${analysisPath}" = "$SOLARISANADIR" ]; then + echo "The analysisPath from ${analysisPath} is different from present folder $SOLARISANADIR. Abort." + exit + fi + + rawDataPathParent=$(cat ${pathsSetting} | head -n 3 | tail -n 1) + rootDataPathParent=$(cat ${pathsSetting} | head -n 4 | tail -n 1) + + databaseIP=$(cat ${pathsSetting} | head -n 6 | tail -n 1) + databaseName=$(cat ${pathsSetting} | head -n 7 | tail -n 1) + + #echo ${rawDataPathParent} + #echo ${rootDataPathParent} + #echo ${databaseIP} + #echo ${databaseName} + + else + + echo "${RED} Cannot found DAQ programSettings.txt for path settings ${NC}" + echo "Seek Ryan for help" + exit + + fi + +fi + +if [ ${Arch} == "Darwin" ] && [ ${PCName} == "SOLARISs-Mac-Studio.local" ]; then + PCID=2 + rawDataPathParent=${HOME}/experimentalData/ + rootDataPathParent=${HOME}/experimentalData/ +fi \ No newline at end of file diff --git a/armory/Process_EventBuilder b/armory/Process_EventBuilder new file mode 100644 index 0000000..898e0d1 --- /dev/null +++ b/armory/Process_EventBuilder @@ -0,0 +1,84 @@ +################################################ EventBuilder +RUN=$1 +EventBld=$2 + +rawDataPath=${SOLARISANADIR}/data_raw +rootDataPath=${SOLARISANADIR}/root_data + +rawDataPattern="${rawDataPath}/${expName}_${RUN}_" +rootDataName="${rootDataPath}/run${RUN}.root" + +dir=$(pwd) +cd ${SOLARISANADIR}/armory +make +cd ${dir} + +#==== check raw data exist +isRawDataExist=`ls -1 ${rawDataPattern}* 2>/dev/null | wc -l` + +if [ ! $isRawDataExist -gt 0 ]; then + echo -e "${LRED}################# Run Data not exist. Abort ${NC}" + exit +fi + +echo -e "${CYAN} ============== list of files ${NC}" +\du -h ${rawDataPattern}* + +totSize=$(\du -hc ${rawDataPattern}* | tail -n 1 | awk '{print $1}') +echo -e "${CYAN} ============== total file size : ${totSize}${NC}" + + +#==== check raw data timeStamp +if [ ${Arch} == "Linux" ]; then + rawDataTime=`stat -c "%Z" ${rawDataPattern}* | sort -rn | head -1` +else + rawDataTime=`stat -f "%Sm" -t "%Y%m%d%H%M%S" ${rawDataPattern}* | sort -rn | head -1` +fi + +#==== check if root data exist +isRootDataExist=`ls -1 $rootDataName 2>/dev/null | wc -l` + +#==== if merged data exist, check timeStamp +if [ ${isRootDataExist} -gt 0 ]; then + if [ ${Arch} == "Linux" ]; then + rootDataTime=`stat -c "%Z" $rootDataName | sort -rn | head -1` + else + rootDataTime=`stat -f "%Sm" -t "%Y%m%d%H%M%S" $rootDataName | sort -rn | head -1` + fi +else + rootDataTime=0 +fi + + +if [ ${EventBld} -eq 0 ]; then + + echo -e "${LRED}>>>>>>>>>>>>>>>>>>>>> Event Building Skipped by user. ${NC}" + +elif [ ${EventBld} -ge 1 ]; then + + if [ ${rawDataTime} -ge ${rootDataTime} ]; then + + echo -e "${LRED}>>>>>>>>>>>>>>>>>>>>> Event Building $(date) ${NC}" + if [ ${EventBld} -eq 1 ]; then + EventBuilder $rootDataName ${timeWin} 0 `ls -1 ${rawDataPattern}*` + elif [ ${EventBld} -eq 2 ]; then + EventBuilder $rootDataName ${timeWin} 1 `ls -1 ${rawDataPattern}*` + fi + echo -e "${LRED}<<<<<<<<<<<<<<<< Done Event Building $(date) ${NC}" + + else + echo -e "${GREEN}Merged data are newer than raw data. No need to merged again.${NC}" + echo -e "${GREEN}You can Force merging using option -${EventBld}, ${ORANGE} see ./process_run.sh -help${NC}" + fi + +else + + echo -e "${LRED}>>>>>>>>>>>>>>> Force Event Building $(date) ${NC}" + if [ ${EventBld} -eq -1 ]; then + EventBuilder $rootDataName ${timeWin} 0 `ls -1 ${rawDataPattern}*` + elif [ ${EventBld} -eq -2 ]; then + EventBuilder $rootDataName ${timeWin} 1 `ls -1 ${rawDataPattern}*` + fi + echo -e "${LRED}<<<<<<<<<<<<<<<< Done Event Building $(date) ${NC}" + +fi \ No newline at end of file diff --git a/armory/Process_MultiRuns b/armory/Process_MultiRuns new file mode 100755 index 0000000..53620e0 --- /dev/null +++ b/armory/Process_MultiRuns @@ -0,0 +1,17 @@ +#!/bin/bash + +if [ -z $SOLARISANADIR ]; then + echo "###### env variable SOLARISANADIR not defined. Abort. Please run the SOLARIS.sh." + echo "better add \"source \" into .bashrc" + exit +fi + +if [ $# -eq 0 ] || [ $# -eq 1 ] || [ $1 == "-help" ]; then + echo "$./process_MultiRuns [RunNum1] [RunNum2] [EventBuild] [GeneralSort]" + echo " RunNum1 = start run number" + echo " RunNum2 = stop run number" + echo " EventBld = 2/1/0* || 2 = with Trace" + echo " GenralSort = n/1/0* || 1 = GeneralSort.C, n = GeneralSortTraceProof.C with n-worker" + echo " * negative option = force " + exit 1 +fi; \ No newline at end of file diff --git a/armory/Process_PathSetting b/armory/Process_PathSetting deleted file mode 100644 index cc1f786..0000000 --- a/armory/Process_PathSetting +++ /dev/null @@ -1 +0,0 @@ -#!/bin/bash \ No newline at end of file diff --git a/armory/Process_Run b/armory/Process_Run index 4ae5d37..2c0c0e1 100755 --- a/armory/Process_Run +++ b/armory/Process_Run @@ -1,10 +1,18 @@ #!/bin/bash +if [ -z $SOLARISANADIR ]; then + echo "###### env variable SOLARISANADIR not defined. Abort. Please run the SOLARIS.sh." + echo "better add \"source \" into .bashrc" + exit +fi + + if [ $# -eq 0 ] || [ $1 == "-help" ]; then - echo "$ Proess_Run [RunNum] [EventBuild] [Monitor]" - echo " RunNum = run number / \"lastRun\" " - echo " EventBld = 2/1/0/-1/-2 || 2 = with Trace" - echo " Monitors = 2/1/0 || 1 = single run, 2 = using the list in ChainMonitors.C" + echo "$ Proess_Run [RunNum] [EventBuild] [GeneralSort] [Monitor]" + echo " RunNum = run number / \"lastRun\" " + echo " EventBld = 2/1/0/-1/-2 || 2 = with Trace" + echo " GeneralSort = n/0/-n || n = number of worker" + echo " Monitors = 2/1/0 || 1 = single run, 2 = using the list in ChainMonitors.C" echo " 10 = single run and post to websrv, 20 = list runs and post to websrv" echo "" echo " **** When feeding trace data to Monitors, the EventBld flag must be 2 or -2." @@ -14,7 +22,23 @@ fi; RUN=$1 -EventBld=$2 +runNum=$1 +EventBld=0 +nWorker=1 +isMonitor=0 + +if [ $# -ge 2 ]; then EventBld=$2; fi +if [ $# -ge 3 ]; then nWorker=$3; fi +if [ $# -ge 4 ]; then isMonitor=$4; fi + +timeWin=100000 + +source ${SOLARISANADIR}/armory/Process_BasicConfig +source ${SOLARISANADIR}/working/expName.sh + +if [ "$RUN" == "lastRun" ]; then + RUN=$runID +fi #padding if [ "${RUN:0:1}" == "0" ]; then @@ -24,14 +48,36 @@ else fi RUN=$(printf '%03d' ${RUN}) -source ~/Analysis/working/expName.sh +#################################### +if [ ${PCID} -eq 1 ]; then + source Process_EventBuilder $RUN ${EventBld} +fi -ls -1 ${rawDataPath}/${expName}_${RUN}_* +if [ ${PCID} -eq 2 ]; then + ## Dwonlaod Data + echo "Downlaod data" +fi -if [ ${EventBld} -neq 0 ]; then +#################################### GeneralSort - if [ ${EventBld} -eq 1 ]; then - ./EventBuilder ${rawDataPath}/${expName}_${RUN}.root 100 0 `ls -1 ${rawDataPath}/${expName}_${RUN}_*` - fi +if [ ${nWorker} -eq 0 ]; then + + echo -e "${LRED}>>>>>>>>>>>>>>>>>>>>> GeneralSort Skipped by user. ${NC}" + +else + source $ROOTSYS/bin/thisroot.sh + + mkdir ~/.proof/working + cp ${SOLARISANADIR}/working/Mapping.h ~/.proof/working/. + mkdir ~/.proof/armory + cp ${SOLARISANADIR}/armory/AnalysisLib.h ~/.proof/armory/. + + root -l -q -b "${SOLARISANADIR}/armory/GeneralSortAgent.C($runNum, ${nWorker})" fi +#################################### Monitor + + + + + diff --git a/working/ChainMonitors.C b/working/ChainMonitors.C new file mode 100644 index 0000000..d73a45e --- /dev/null +++ b/working/ChainMonitors.C @@ -0,0 +1,48 @@ +#include "Monitors.C+" // the plus sign mean compilation + +void ChainMonitors(int RUNNUM = -1, int RUNNUM2 = -1, bool saveCanvas = false, bool isTraceON = false) { + + ///default saveCanvas = false, no save Cavas + /// = true, save Canvas + + TChain * chain = new TChain("gen_tree"); + + if( RUNNUM == -1){ + /// this list only for manual Chain sort + ///********** start Marker for AutoCalibration. + + ///chain->Add("../root_data/gen_run135.root"); + ///chain->Add("../root_data/trace_run135.root"); + + ///********** end Marker for AutoCalibration. + + + }else{ + + TString fileName; + int endRUNNUM = RUNNUM2; + if( RUNNUM2 == -1) endRUNNUM = RUNNUM; + + for( int i = RUNNUM ; i <= endRUNNUM ; i++){ + + if( isTraceON == false )fileName.Form("../root_data/gen_run%03d.root", i); + if( isTraceON == true ) fileName.Form("../root_data/trace_run%03d.root", i); + chain->Add(fileName); + } + } + + + printf("\033[0;31m========================================== Number of Files : %2d\n",chain->GetListOfFiles()->GetEntries()); + chain->GetListOfFiles()->Print(); + printf("========================================== Number of Files : %2d\033[0m\n",chain->GetListOfFiles()->GetEntries()); + printf(" number of entries : %llu \n", chain->GetEntries()); + + //Simple call TSelector + //chain->Process("Monitors.C+"); + + //Some input to TSelector + Monitors * selector = new Monitors(); + if( saveCanvas ) selector->printControl(0); //quit after terminated + chain->Process(selector, ""); + +} \ No newline at end of file diff --git a/working/Mapping.h b/working/Mapping.h index 5689e7d..7a72b6f 100644 --- a/working/Mapping.h +++ b/working/Mapping.h @@ -17,54 +17,45 @@ #include #include -//#define NARRAY 60 -//#define NRDT 10 - -#define PARITYARRAY 1 -#define PARITYRDT 1 - -//#define NDIGITIZER 4 -//#define NCHANNEL 64 // number of channel per digitizer - -std::vector detName = {"Array", "Recoil"}; //*= The comment "//*=" is an indicator DON't Remove -std::vector detMaxID = { 100, 200}; //*# The comment "//*#" is an indicator DON't Remove +const std::vector detName = {"Array", "Recoil"}; //C= The comment "//C=" is an indicator DON't Remove +const std::vector detMaxID = { 100, 200}; //C# The comment "//C#" is an indicator DON't Remove +const std::vector detParity = { 1, 1}; //!The mapping[i] must match as the IP setting in the DAQ -std::vector> mapping = { +const std::vector> mapping = { { -//* 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 // this line is an indicator DON'T Remove +//C 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 // this line is an indicator DON'T Remove "//C " is an indcator 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, -1, /// 0 - 15 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, -1, /// 16 - 31 10, 10, 10, 11, 11, 11, 12, 12, 12, 13, 13, 13, 14, 14, 14, -1, /// 32 - 47 15, 15, 15, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 19, -1 /// 48 - 63 -//*------------- end of a digitizer // this line is an indicator DON'T Remove +//C------------- end of a digitizer // this line is an indicator DON'T Remove "//C-" is an indcator }, //^{ -//^//* 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 // this line is an indicator DON'T Remove +//^//C 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 // this line is an indicator DON'T Remove "//C " is an indcator //^ 20, 20, 20, 21, 21, 21, 22, 22, 22, 23, 23, 23, 24, 24, 24, -1, /// 0 - 15 //^ 25, 25, 25, 26, 26, 26, 27, 27, 27, 28, 28, 28, 29, 29, 29, -1, /// 16 - 31 //^ 30, 30, 30, 31, 31, 31, 32, 32, 32, 33, 33, 33, 34, 34, 34, -1, /// 32 - 47 //^ 35, 35, 35, 36, 36, 36, 37, 37, 37, 38, 38, 38, 39, 39, 39, -1 /// 48 - 63 -//^//*------------- end of a digitizer // this line is an indicator DON'T Remove +//^//C------------- end of a digitizer // this line is an indicator DON'T Remove "//C-" is an indcator //^}, //^{ -//^//* 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 // this line is an indicator DON'T Remove +//^//C 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 // this line is an indicator DON'T Remove "//C " is an indcator //^ 40, 40, 40, 41, 41, 41, 42, 42, 42, 43, 43, 43, 44, 44, 44, -1, /// 0 - 15 //^ 45, 45, 45, 46, 46, 46, 47, 47, 47, 48, 48, 48, 49, 49, 49, -1, /// 16 - 31 //^ 50, 50, 50, 51, 51, 51, 52, 52, 52, 53, 53, 53, 54, 54, 54, -1, /// 32 - 47 //^ 55, 55, 55, 56, 56, 56, 57, 57, 57, 58, 58, 58, 59, 59, 59, -1 /// 48 - 63 -//^//*------------- end of a digitizer // this line is an indicator DON'T Remove +//^//C------------- end of a digitizer // this line is an indicator DON'T Remove "//C-" is an indcator //^}, { -//* 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 // this line is an indicator DON'T Remove +//C 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 // this line is an indicator DON'T Remove "//C " is an indcator 100, 101, 102, 103, 104, 105, 106, 107, -1, -1, -1, -1, -1, -1, -1, -1, /// 0 - 15 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /// 16 - 31 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /// 32 - 47 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 /// 48 - 63 -//*------------- end of a digitizer // this line is an indicator DON'T Remove +//C------------- end of a digitizer // this line is an indicator DON'T Remove "//C-" is an indcator } }; -//& if all array is arrange like this, no need kind mapping. it is always e, xf, xn #endif diff --git a/working/expName.sh b/working/expName.sh index c21a45f..6f6ac88 100644 --- a/working/expName.sh +++ b/working/expName.sh @@ -1,6 +1,6 @@ expName=Master rawDataPath=/mnt/data0/Master rootDataPath=/mnt/data1/Master -runID=1 -elogID=14 -//------------end of file. \ No newline at end of file +runID=21 +elogID=59 +#------------end of file. \ No newline at end of file diff --git a/working/script.C b/working/script.C index 47ec58c..c55f0bf 100644 --- a/working/script.C +++ b/working/script.C @@ -43,7 +43,7 @@ void script(){ reader->GetFilePos(), reader->GetFileSize()); evt->PrintAll(); - evt->PrintAllTrace(); + //evt->PrintAllTrace(); } h1->Fill(evt->timestamp);