add Monitor_raw.C/h, bug fix for AnalysisLibrary.h

This commit is contained in:
Ryan Tang 2021-12-21 20:55:29 -05:00
parent 3e19117a49
commit baa211d30c
5 changed files with 199 additions and 4 deletions

View File

@ -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");

113
Monitor_raw.C Normal file
View File

@ -0,0 +1,113 @@
#define Monitor_raw_cxx
#include "Monitor_raw.h"
#include <TH2.h>
#include <TH1.h>
#include <TStyle.h>
#include <TCanvas.h>
#include <TMath.h>
#include <vector>
#include <TStopwatch.h>
//############################################ 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<vector<double>> 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("");
}

81
Monitor_raw.h Normal file
View File

@ -0,0 +1,81 @@
#ifndef Monitor_raw_h
#define Monitor_raw_h
#include <TROOT.h>
#include <TChain.h>
#include <TFile.h>
#include <TSelector.h>
#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

View File

@ -6,6 +6,7 @@
#include <TSpectrum.h>
#include <TMath.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
@ -280,7 +281,7 @@ std::vector<std::vector<double>> LoadCorrectionParameters(TString corrFile){
}else{
printf(".... fail\n");
std::vector<double> temp = {0, 1};
for( int i = 0; i < NCRYSTAL; i++){
for( int i = 0; i < 36; i++){
corr.push_back(temp);
}
}

View File

@ -36,7 +36,6 @@ fileList=$(ls *.evt)
numFile=$(ls -lhtr *.evt | wc -l)
count=0
cd $DIR
for a in $fileList