From baa211d30c3f24311c6273af887224b9baf32fdb Mon Sep 17 00:00:00 2001 From: "Ryan@WorkStation" Date: Tue, 21 Dec 2021 20:55:29 -0500 Subject: [PATCH] add Monitor_raw.C/h, bug fix for AnalysisLibrary.h --- Analyzer.C | 5 +- Monitor_raw.C | 113 +++++++++++++++++++++++++++++++++++++++ Monitor_raw.h | 81 ++++++++++++++++++++++++++++ armory/AnalysisLibrary.h | 3 +- process_run | 1 - 5 files changed, 199 insertions(+), 4 deletions(-) create mode 100644 Monitor_raw.C create mode 100644 Monitor_raw.h diff --git a/Analyzer.C b/Analyzer.C index 5e9465e..6e33d76 100644 --- a/Analyzer.C +++ b/Analyzer.C @@ -41,6 +41,7 @@ TH2F * heCalVID; TH1F * heCal[NCRYSTAL]; TH2F * hcoinBGO; +//############################################ BEGIN void Analyzer::Begin(TTree * tree){ TString option = GetOption(); @@ -77,7 +78,7 @@ void Analyzer::Begin(TTree * tree){ printf("======================== Start processing....\n"); } - +//############################################ PROCESS Bool_t Analyzer::Process(Long64_t entry){ ProcessedEntries++; @@ -148,7 +149,7 @@ Bool_t Analyzer::Process(Long64_t entry){ return kTRUE; } - +//############################################ TERMINATE void Analyzer::Terminate(){ printf("============================== finishing.\n"); diff --git a/Monitor_raw.C b/Monitor_raw.C new file mode 100644 index 0000000..0a7437d --- /dev/null +++ b/Monitor_raw.C @@ -0,0 +1,113 @@ +#define Monitor_raw_cxx + +#include "Monitor_raw.h" +#include +#include +#include +#include +#include +#include +#include + +//############################################ User setting + +int rawEnergyRange[2] = {500, 6000}; // in ch + +TString e_corr = "correction_e.dat"; + +Long64_t maxEvent = -1; + +//############################################ end of user setting + +ULong64_t NumEntries = 0; +ULong64_t ProcessedEntries = 0; +Float_t Frac = 0.1; ///Progress bar +TStopwatch StpWatch; + +vector> eCorr; + +//############################################ histogram declaration + +TH1F * hTDiff; +TH2F * hTDiffvEventID; + +//############################################ BEGIN +void Monitor_raw::Begin(TTree * tree){ + TString option = GetOption(); + + NumEntries = tree->GetEntries(); + + printf("======================== Creating histograms\n"); + + hTDiff = new TH1F("hTDiff", "time different between this and next event", 2000, -1000, 1000); + hTDiffvEventID = new TH2F("hTDiffvEventID", "time different between this and next event; eventID; TDiff", 50, 0, maxEvent, 2000, -1000, 1000); + + printf("======================== end of histograms creation.\n"); + + printf("======================== Load parameters.\n"); + eCorr = LoadCorrectionParameters(e_corr); + + StpWatch.Start(); + printf("======================== Start processing....\n"); + +} + +//############################################ PROCESS +Bool_t Monitor_raw::Process(Long64_t entry){ + + ProcessedEntries++; + + /*********** Progress Bar ******************************************/ + if (ProcessedEntries>NumEntries*Frac-1) { + TString msg; msg.Form("%llu", NumEntries/1000); + int len = msg.Sizeof(); + //printf(" %3.0f%% (%*llu/%llu k) processed in %6.1f sec | expect %6.1f sec\033[A\n", + printf(" %3.0f%% (%*llu/%llu k) processed in %6.1f sec | expect %6.1f sec\n", + Frac*100, len, ProcessedEntries/1000,NumEntries/1000,StpWatch.RealTime(), StpWatch.RealTime()/Frac); + StpWatch.Start(kFALSE); + Frac+=0.1; + } + + if ( maxEvent > 0 && entry > maxEvent ) { + Abort(Form("user abort, > %lld \n", maxEvent)); + Terminate(); + } + + b_energy->GetEntry(entry); + b_time_stamp->GetEntry(entry); + + ULong64_t t0 = t; + + if( entry < (Long64_t) NumEntries ) b_time_stamp->GetEntry(entry+1);; + + ULong64_t t1 = t; + + int tDiff = (int) t1 - t0; + + hTDiff->Fill( tDiff ); + hTDiffvEventID->Fill( entry, tDiff); + + return kTRUE; +} + +//############################################ TERMINATE +void Monitor_raw::Terminate(){ + + printf("============================== finishing.\n"); + gROOT->cd(); + + TCanvas * cc = new TCanvas("cc", "cc", 2000, 1000); + + if( cc->GetShowEventStatus() == 0 ) cc->ToggleEventStatus(); + + cc->Divide(2,1); + + cc->cd(1); + hTDiff->Draw(); + + cc->cd(2); + cc->cd(2)->SetGrid(); + hTDiffvEventID->SetMarkerStyle(3); + hTDiffvEventID->Draw(""); + +} diff --git a/Monitor_raw.h b/Monitor_raw.h new file mode 100644 index 0000000..734f612 --- /dev/null +++ b/Monitor_raw.h @@ -0,0 +1,81 @@ +#ifndef Monitor_raw_h +#define Monitor_raw_h + +#include +#include +#include +#include + +#include "mapping.h" +#include "armory/AnalysisLibrary.h" + +// Header file for the classes stored in the TTree if any. + +class Monitor_raw : 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 + Long64_t evID; + UShort_t detID; + UShort_t e; + ULong64_t t; + + // List of branches + TBranch *b_data_ID; //! + TBranch *b_det_ID; //! + TBranch *b_energy; //! + TBranch *b_time_stamp; //! + + Monitor_raw(TTree * /*tree*/ =0) : fChain(0) { } + virtual ~Monitor_raw() { } + 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(Monitor_raw,0); +}; + +#endif + +#ifdef Monitor_raw_cxx +void Monitor_raw::Init(TTree *tree) +{ + // Set branch addresses and branch pointers + if (!tree) return; + fChain = tree; + fChain->SetMakeClass(1); + + fChain->SetBranchAddress("evID", &evID, &b_data_ID); + fChain->SetBranchAddress("detID", &detID, &b_det_ID); + fChain->SetBranchAddress("e", &e, &b_energy); + fChain->SetBranchAddress("t", &t, &b_time_stamp); +} + +Bool_t Monitor_raw::Notify() +{ + return kTRUE; +} + + +void Monitor_raw::SlaveBegin(TTree * /*tree*/){ + TString option = GetOption(); +} + + +void Monitor_raw::SlaveTerminate(){} + + +#endif // #ifdef Monitor_raw_cxx diff --git a/armory/AnalysisLibrary.h b/armory/AnalysisLibrary.h index 030a6f6..ffb3b39 100644 --- a/armory/AnalysisLibrary.h +++ b/armory/AnalysisLibrary.h @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -280,7 +281,7 @@ std::vector> LoadCorrectionParameters(TString corrFile){ }else{ printf(".... fail\n"); std::vector temp = {0, 1}; - for( int i = 0; i < NCRYSTAL; i++){ + for( int i = 0; i < 36; i++){ corr.push_back(temp); } } diff --git a/process_run b/process_run index 7871959..963abe3 100755 --- a/process_run +++ b/process_run @@ -36,7 +36,6 @@ fileList=$(ls *.evt) numFile=$(ls -lhtr *.evt | wc -l) count=0 - cd $DIR for a in $fileList