From 56285cef62de487335946a05e1348e9a8dcbdb3d Mon Sep 17 00:00:00 2001 From: "Ryan@Home" Date: Mon, 8 Jul 2024 18:04:25 -0400 Subject: [PATCH] still working on Monitor. Shift to TTreeReader --- Armory/GeneralSort.h | 4 +- Armory/Process_Download | 8 +- working/ClassMonPlotter.h | 6 + working/MonAnalyzer.C | 224 +++++++++++++++++++++++++------------- working/MonAnalyzer.h | 115 ------------------- working/Monitor.C | 6 - 6 files changed, 160 insertions(+), 203 deletions(-) delete mode 100644 working/MonAnalyzer.h diff --git a/Armory/GeneralSort.h b/Armory/GeneralSort.h index 937f49b..afb8a5a 100644 --- a/Armory/GeneralSort.h +++ b/Armory/GeneralSort.h @@ -182,7 +182,7 @@ void GeneralSort::SetUpTree(){ newSaveTree->SetDirectory(saveFile); newSaveTree->AutoSave(); - newSaveTree->Branch( "evID", &evID, "EventID/l"); // simply copy + newSaveTree->Branch( "evID", &evID, "evID/l"); // simply copy eE = new Float_t * [mapping::nDetType]; eT = new ULong64_t * [mapping::nDetType]; @@ -198,7 +198,7 @@ void GeneralSort::SetUpTree(){ } newSaveTree->Branch( mapping::detTypeName[i].c_str(), eE[i], Form("%s[%d]/F", mapping::detTypeName[i].c_str(), mapping::detNum[i])); - newSaveTree->Branch( (mapping::detTypeName[i]+"_t").c_str(), eT[i], Form("%s_Timestamp[%d]/l", mapping::detTypeName[i].c_str(), mapping::detNum[i])); + newSaveTree->Branch( (mapping::detTypeName[i]+"_t").c_str(), eT[i], Form("%s_t[%d]/l", mapping::detTypeName[i].c_str(), mapping::detNum[i])); } diff --git a/Armory/Process_Download b/Armory/Process_Download index 0e4a26e..aa5e0bd 100755 --- a/Armory/Process_Download +++ b/Armory/Process_Download @@ -88,9 +88,11 @@ else echo -e "$CYAN############### Only in SOLARIS MAC can donwload data. skip.$NC" fi -echo -e "$YELLOW=============================================$NC" -tail -10 ${rawDataPath}/RunTimeStamp.dat -echo -e "$YELLOW=============================================$NC" +if [ -z ${rawDataPath}/RunTimeStamp.dat ]; then + echo -e "$YELLOW=============================================$NC" + tail -10 ${rawDataPath}/RunTimeStamp.dat + echo -e "$YELLOW=============================================$NC" +fi count=`ls -1 ${rawDataPath}/${expName}_${RUN}_*.sol 2>/dev/null | wc -l` echo -e "========================= Number of Files : ${count}${YELLOW}" diff --git a/working/ClassMonPlotter.h b/working/ClassMonPlotter.h index 0fc8a69..427be43 100644 --- a/working/ClassMonPlotter.h +++ b/working/ClassMonPlotter.h @@ -300,6 +300,12 @@ void MonPlotter::Plot(){ for( int i = 0; i < numPad; i++ ){ canvas->cd(i+1); + switch (i){ + case 0: he_ID->Draw("colz");break; + case 1: hxf_ID->Draw("colz");break; + case 2: hxn_ID->Draw("colz");break; + default:break; + } } } diff --git a/working/MonAnalyzer.C b/working/MonAnalyzer.C index 6626ed1..724e792 100644 --- a/working/MonAnalyzer.C +++ b/working/MonAnalyzer.C @@ -1,88 +1,158 @@ -#define MonAnalyzer_cxx -// The class definition in MonAnalyzer.h has been generated automatically -// by the ROOT utility TTree::MakeSelector(). This class is derived -// from the ROOT class TSelector. For more information on the TSelector -// framework see $ROOTSYS/README/README.SELECTOR or the ROOT User Manual. + +#include "../Armory/AnalysisLib.h" +#include "../Armory/ClassDetGeo.h" +#include "../Armory/ClassReactionConfig.h" +#include "../Armory/ClassCorrParas.h" +// #include "../Cleopatra/ClassHelios.h" +#include "../Cleopatra/ClassTransfer.h" + +#include "ClassMonPlotter.h" +#include "Mapping.h" + +#include "TFile.h" +#include "TChain.h" +#include "TH1F.h" +#include "TTreeReader.h" +#include "TTreeReaderValue.h" +#include "TTreeReaderArray.h" +#include "TClonesArray.h" +#include "TH2.h" +#include "TStyle.h" +#include "TStopwatch.h" + +#include "vector" +//^############################################ User setting +int rawEnergyRange[2] = { 100, 4000}; /// share with e, xf, xn +int energyRange[2] = { 0, 10}; /// in the E-Z plot +int rdtDERange[2] = { 0, 80}; +int rdtERange[2] = { 0, 80}; +int thetaCMRange[2] = {0, 80}; + +double exRange[3] = { 100, -2, 10}; /// bin [keV], low[MeV], high[MeV] -// The following methods are defined in this file: -// Begin(): called every time a loop on the tree starts, -// a convenient place to create your histograms. -// SlaveBegin(): called after Begin(), when on PROOF called only on the -// slave servers. -// Process(): called for each event, in this function you decide what -// to read and fill your histograms. -// SlaveTerminate: called at the end of the loop on the tree, when on PROOF -// called only on the slave servers. -// Terminate(): called at the end of the loop on the tree, -// a convenient place to draw/fit your histograms. -// -// To use this file, try the following session on your Tree T: -// -// root> T->Process("MonAnalyzer.C") -// root> T->Process("MonAnalyzer.C","some options") -// root> T->Process("MonAnalyzer.C+") -// +//---Gate +bool isTimeGateOn = true; +int timeGate[2] = {-20, 12}; /// min, max, 1 ch = 10 ns +double eCalCut[2] = {0.5, 50}; /// lower & higher limit for eCal + +std::vector skipDetID = {11, 16, 23} ;//{2, 11, 17} +//^############################################ end of user setting -#include "MonAnalyzer.h" -#include -#include +void MonAnalyzer(){ -void MonAnalyzer::Begin(TTree * /*tree*/) -{ - // The Begin() function is called at the start of the query. - // When running with PROOF Begin() is only called on the client. - // The tree argument is deprecated (on PROOF 0 is passed). +// TFile * file = new TFile("../root_data/gen_run043.root"); - TString option = GetOption(); -} + TChain *chain = new TChain("gen_tree"); + chain->Add("../root_data/gen_run043.root"); -void MonAnalyzer::SlaveBegin(TTree * /*tree*/) -{ - // The SlaveBegin() function is called after the Begin() function. - // When running with PROOF SlaveBegin() is called on each slave server. - // The tree argument is deprecated (on PROOF 0 is passed). + // chain->Print(); - TString option = GetOption(); + TTreeReader reader(chain); + + TTreeReaderValue evID = {reader, "evID"}; + TTreeReaderArray e = {reader, "e"}; + TTreeReaderArray e_t = {reader, "e_t"}; + TTreeReaderArray xf = {reader, "xf"}; + TTreeReaderArray xn = {reader, "xn"}; + + TTreeReaderArray rdt = {reader, "rdt"}; + TTreeReaderArray rdt_t = {reader, "rdt_t"}; + + //TODO + // TTreeReaderArray array = {reader, "trace"}; + + //*========================================== + ULong64_t NumEntries = chain->GetEntries(); + CorrParas * corr = new CorrParas; + DetGeo * detGeo = new DetGeo("detectorGeo.txt"); + // TransferReaction * transfer = new TransferReaction("reactionConfig.txt"); + + MonPlotter ** plotter = new MonPlotter *[detGeo->numGeo]; + for( int i = 0; i < detGeo->numGeo; i++ ) { + plotter[i] = new MonPlotter(i, detGeo, mapping::NRDT); + plotter[i]->SetUpCanvas("haha", 500, 3, 2); + plotter[i]->SetUpHistograms(rawEnergyRange, energyRange, exRange, thetaCMRange, rdtDERange, rdtERange); + } + + double eCal[mapping::NARRAY]; + double xfCal[mapping::NARRAY]; + double xnCal[mapping::NARRAY]; + + //^########################################################### + //^ * Process + //^########################################################### + ULong64_t processedEntries = 0; + float Frac = 0.1; + TStopwatch StpWatch; + StpWatch.Start(); + + while (reader.Next()) { + + // printf("%llu | %llu | %lu\n", processedEntries, *evID, e.GetSize()); + + //*============================================= Array; + for( int id = 0; id < e.GetSize() ; id++ ){ + short aID = detGeo->GetArrayID(id); + if( aID < 0 ) continue; + + //@================== Filling raw data + plotter[aID]->he[id]->Fill(e[id]); + plotter[aID]->hxf[id]->Fill(xf[id]); + plotter[aID]->hxn[id]->Fill(xn[id]); + plotter[aID]->hxf_xn[id]->Fill(xf[id],xn[id]); + plotter[aID]->he_xs[id]->Fill(xf[id]+xn[id], e[id]); + + plotter[aID]->he_ID->Fill(id, e[id]); + plotter[aID]->hxf_ID->Fill(id, xf[id]); + plotter[aID]->hxn_ID->Fill(id, xn[id]); + + // //@==================== Basic gate + // if( TMath::IsNaN(e[id]) ) continue ; + // if( TMath::IsNaN(xn[id]) && TMath::IsNaN(xf[id]) ) continue ; + + // //@==================== Skip detector + // bool skipFlag = false; + // for( unsigned int kk = 0; kk < skipDetID.size() ; kk++){ + // if( id == skipDetID[kk] ) { + // skipFlag = true; + // break; + // } + // } + // if (skipFlag ) continue; + + // //@==================== Calibrations go here + // if( corr->xnCorr.size() >= id && corr->xfxneCorr.size() >= id ) xnCal[id] = xn[id] * corr->xnCorr[id] * corr->xfxneCorr[id][1] + corr->xfxneCorr[id][0]; + // if( corr->xfxneCorr.size() >= id ) xfCal[id] = xf[id] * corr->xfxneCorr[id][1] + corr->xfxneCorr[id][0]; + // if( corr->eCorr.size() >= id) eCal[id] = e[id] / corr->eCorr[id][0] + corr->eCorr[id][1]; + + // if( eCal[id] < eCalCut[0] || eCalCut[1] < eCal[id] ) continue; + + + + }//*==== end of array + + + + + //*============================================ Progress Bar + processedEntries ++; + 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\n", + Frac*100, len, processedEntries/1000,NumEntries/1000,StpWatch.RealTime(), StpWatch.RealTime()/Frac); + StpWatch.Start(kFALSE); + Frac += 0.1; + } + if( processedEntries > 1000 ) break; + + }//^############################################## End of Process + + for( int i = 0; i < detGeo->numGeo ; i++){ + plotter[i]->Plot(); + } } -bool MonAnalyzer::Process(Long64_t entry) -{ - // The Process() function is called for each entry in the tree (or possibly - // keyed object in the case of PROOF) to be processed. The entry argument - // specifies which entry in the currently loaded tree is to be processed. - // When processing keyed objects with PROOF, the object is already loaded - // and is available via the fObject pointer. - // - // This function should contain the \"body\" of the analysis. It can contain - // simple or elaborate selection criteria, run algorithms on the data - // of the event and typically fill histograms. - // - // The processing can be stopped by calling Abort(). - // - // Use fStatus to set the return value of TTree::Process(). - // - // The return value is currently not used. - - fReader.SetLocalEntry(entry); - - return true; -} - -void MonAnalyzer::SlaveTerminate() -{ - // The SlaveTerminate() function is called after all entries or objects - // have been processed. When running with PROOF SlaveTerminate() is called - // on each slave server. - -} - -void MonAnalyzer::Terminate() -{ - // The Terminate() function is the last function to be called during - // a query. It always runs on the client, it can be used to present - // the results graphically or save the results to file. - -} \ No newline at end of file diff --git a/working/MonAnalyzer.h b/working/MonAnalyzer.h deleted file mode 100644 index 37378bd..0000000 --- a/working/MonAnalyzer.h +++ /dev/null @@ -1,115 +0,0 @@ -////////////////////////////////////////////////////////// -// This class has been automatically generated on -// Mon Jul 8 13:26:58 2024 by ROOT version 6.32.02 -// from TTree gen_tree/Tree After GeneralSort -// found on file: ../root_data/gen_run043.root -////////////////////////////////////////////////////////// - -#ifndef MonAnalyzer_h -#define MonAnalyzer_h - -#include -#include -#include -#include -#include -#include -#include - -// Headers needed by this particular selector -#include "TClonesArray.h" - - - -class MonAnalyzer : public TSelector { -public : - TTreeReader fReader; //!the tree reader - TTree *fChain = 0; //!pointer to the analyzed TTree or TChain - - // Readers to access the data (delete the ones you do not need). - TTreeReaderValue EventID = {fReader, "evID"}; - TTreeReaderArray e = {fReader, "e"}; - TTreeReaderArray e_Timestamp = {fReader, "e_t"}; - TTreeReaderArray xf = {fReader, "xf"}; - TTreeReaderArray xf_Timestamp = {fReader, "xf_t"}; - TTreeReaderArray xn = {fReader, "xn"}; - TTreeReaderArray xn_Timestamp = {fReader, "xn_t"}; - TTreeReaderArray rdt = {fReader, "rdt"}; - TTreeReaderArray rdt_Timestamp = {fReader, "rdt_t"}; - TTreeReaderArray trace_fUniqueID = {fReader, "trace.fUniqueID"}; - TTreeReaderArray trace_fBits = {fReader, "trace.fBits"}; - TTreeReaderArray trace_fName = {fReader, "trace.fName"}; - TTreeReaderArray trace_fTitle = {fReader, "trace.fTitle"}; - TTreeReaderArray trace_fLineColor = {fReader, "trace.fLineColor"}; - TTreeReaderArray trace_fLineStyle = {fReader, "trace.fLineStyle"}; - TTreeReaderArray trace_fLineWidth = {fReader, "trace.fLineWidth"}; - TTreeReaderArray trace_fFillColor = {fReader, "trace.fFillColor"}; - TTreeReaderArray trace_fFillStyle = {fReader, "trace.fFillStyle"}; - TTreeReaderArray trace_fMarkerColor = {fReader, "trace.fMarkerColor"}; - TTreeReaderArray trace_fMarkerStyle = {fReader, "trace.fMarkerStyle"}; - TTreeReaderArray trace_fMarkerSize = {fReader, "trace.fMarkerSize"}; - TTreeReaderArray trace_fMinimum = {fReader, "trace.fMinimum"}; - TTreeReaderArray trace_fMaximum = {fReader, "trace.fMaximum"}; - TTreeReaderArray trace_fOption = {fReader, "trace.fOption"}; - TTreeReaderArray trace_e = {fReader, "we"}; - TTreeReaderArray trace_e_time = {fReader, "weT"}; - TTreeReaderArray trace_e_rise = {fReader, "weR"}; - TTreeReaderArray trace_xf = {fReader, "wxf"}; - TTreeReaderArray trace_xf_time = {fReader, "wxfT"}; - TTreeReaderArray trace_xf_rise = {fReader, "wxfR"}; - TTreeReaderArray trace_xn = {fReader, "wxn"}; - TTreeReaderArray trace_xn_time = {fReader, "wxnT"}; - TTreeReaderArray trace_xn_rise = {fReader, "wxnR"}; - TTreeReaderArray trace_rdt = {fReader, "wrdt"}; - TTreeReaderArray trace_rdt_time = {fReader, "wrdtT"}; - TTreeReaderArray trace_rdt_rise = {fReader, "wrdtR"}; - - - MonAnalyzer(TTree * /*tree*/ =0) { } - ~MonAnalyzer() override { } - Int_t Version() const override { return 2; } - void Begin(TTree *tree) override; - void SlaveBegin(TTree *tree) override; - void Init(TTree *tree) override; - bool Notify() override; - bool Process(Long64_t entry) override; - Int_t GetEntry(Long64_t entry, Int_t getall = 0) override { return fChain ? fChain->GetTree()->GetEntry(entry, getall) : 0; } - void SetOption(const char *option) override { fOption = option; } - void SetObject(TObject *obj) override { fObject = obj; } - void SetInputList(TList *input) override { fInput = input; } - TList *GetOutputList() const override { return fOutput; } - void SlaveTerminate() override; - void Terminate() override; - - ClassDefOverride(MonAnalyzer,0); - -}; - -#endif - -#ifdef MonAnalyzer_cxx -void MonAnalyzer::Init(TTree *tree) -{ - // The Init() function is called when the selector needs to initialize - // a new tree or chain. Typically here the reader is initialized. - // It is normally not necessary to make changes to the generated - // code, but the routine can be extended by the user if needed. - // Init() will be called many times when running on PROOF - // (once per file to be processed). - - fReader.SetTree(tree); -} - -bool MonAnalyzer::Notify() -{ - // The Notify() function is called when a new file is opened. This - // can be either for a new TTree in a TChain or when when a new TTree - // is started when using PROOF. It is normally not necessary to make changes - // to the generated code, but the routine can be extended by the - // user if needed. The return value is currently not used. - - return true; -} - - -#endif // #ifdef MonAnalyzer_cxx diff --git a/working/Monitor.C b/working/Monitor.C index 7afe47f..86604e6 100644 --- a/working/Monitor.C +++ b/working/Monitor.C @@ -317,12 +317,6 @@ Bool_t Monitor::Process(Long64_t entry){ } if (skipFlag ) continue; - //@==================== Basic gate - if( TMath::IsNaN(e[id]) ) continue ; - ///if( ring[id] < -100 || ring[id] > 100 ) continue; - ///if( ring[id] > 300 ) continue; - if( TMath::IsNaN(xn[id]) && TMath::IsNaN(xf[id]) ) continue ; - //@==================== Calibrations go here if( corr->xnCorr.size() >= id && corr->xfxneCorr.size() >= id ) xnCal[id] = xn[id] * corr->xnCorr[id] * corr->xfxneCorr[id][1] + corr->xfxneCorr[id][0]; if( corr->xfxneCorr.size() >= id ) xfCal[id] = xf[id] * corr->xfxneCorr[id][1] + corr->xfxneCorr[id][0];