still working on Monitor. Shift to TTreeReader

This commit is contained in:
Ryan@Home 2024-07-08 18:04:25 -04:00
parent 5bb5f58956
commit 56285cef62
6 changed files with 160 additions and 203 deletions

View File

@ -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]));
}

View File

@ -88,9 +88,11 @@ else
echo -e "$CYAN############### Only in SOLARIS MAC can donwload data. skip.$NC"
fi
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}"

View File

@ -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;
}
}
}

View File

@ -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<int> skipDetID = {11, 16, 23} ;//{2, 11, 17}
//^############################################ end of user setting
#include "MonAnalyzer.h"
#include <TH2.h>
#include <TStyle.h>
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");
// chain->Print();
TTreeReader reader(chain);
TTreeReaderValue<ULong64_t> evID = {reader, "evID"};
TTreeReaderArray<Float_t> e = {reader, "e"};
TTreeReaderArray<ULong64_t> e_t = {reader, "e_t"};
TTreeReaderArray<Float_t> xf = {reader, "xf"};
TTreeReaderArray<Float_t> xn = {reader, "xn"};
TTreeReaderArray<Float_t> rdt = {reader, "rdt"};
TTreeReaderArray<ULong64_t> rdt_t = {reader, "rdt_t"};
//TODO
// TTreeReaderArray<TClonesArray> 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);
}
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).
double eCal[mapping::NARRAY];
double xfCal[mapping::NARRAY];
double xnCal[mapping::NARRAY];
TString option = GetOption();
//^###########################################################
//^ * 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.
}

View File

@ -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 <TROOT.h>
#include <TChain.h>
#include <TFile.h>
#include <TSelector.h>
#include <TTreeReader.h>
#include <TTreeReaderValue.h>
#include <TTreeReaderArray.h>
// 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<ULong64_t> EventID = {fReader, "evID"};
TTreeReaderArray<Float_t> e = {fReader, "e"};
TTreeReaderArray<ULong64_t> e_Timestamp = {fReader, "e_t"};
TTreeReaderArray<Float_t> xf = {fReader, "xf"};
TTreeReaderArray<ULong64_t> xf_Timestamp = {fReader, "xf_t"};
TTreeReaderArray<Float_t> xn = {fReader, "xn"};
TTreeReaderArray<ULong64_t> xn_Timestamp = {fReader, "xn_t"};
TTreeReaderArray<Float_t> rdt = {fReader, "rdt"};
TTreeReaderArray<ULong64_t> rdt_Timestamp = {fReader, "rdt_t"};
TTreeReaderArray<unsigned int> trace_fUniqueID = {fReader, "trace.fUniqueID"};
TTreeReaderArray<unsigned int> trace_fBits = {fReader, "trace.fBits"};
TTreeReaderArray<TString> trace_fName = {fReader, "trace.fName"};
TTreeReaderArray<TString> trace_fTitle = {fReader, "trace.fTitle"};
TTreeReaderArray<Short_t> trace_fLineColor = {fReader, "trace.fLineColor"};
TTreeReaderArray<Short_t> trace_fLineStyle = {fReader, "trace.fLineStyle"};
TTreeReaderArray<Short_t> trace_fLineWidth = {fReader, "trace.fLineWidth"};
TTreeReaderArray<Short_t> trace_fFillColor = {fReader, "trace.fFillColor"};
TTreeReaderArray<Short_t> trace_fFillStyle = {fReader, "trace.fFillStyle"};
TTreeReaderArray<Short_t> trace_fMarkerColor = {fReader, "trace.fMarkerColor"};
TTreeReaderArray<Short_t> trace_fMarkerStyle = {fReader, "trace.fMarkerStyle"};
TTreeReaderArray<Float_t> trace_fMarkerSize = {fReader, "trace.fMarkerSize"};
TTreeReaderArray<Double_t> trace_fMinimum = {fReader, "trace.fMinimum"};
TTreeReaderArray<Double_t> trace_fMaximum = {fReader, "trace.fMaximum"};
TTreeReaderArray<TString> trace_fOption = {fReader, "trace.fOption"};
TTreeReaderArray<Float_t> trace_e = {fReader, "we"};
TTreeReaderArray<Float_t> trace_e_time = {fReader, "weT"};
TTreeReaderArray<Float_t> trace_e_rise = {fReader, "weR"};
TTreeReaderArray<Float_t> trace_xf = {fReader, "wxf"};
TTreeReaderArray<Float_t> trace_xf_time = {fReader, "wxfT"};
TTreeReaderArray<Float_t> trace_xf_rise = {fReader, "wxfR"};
TTreeReaderArray<Float_t> trace_xn = {fReader, "wxn"};
TTreeReaderArray<Float_t> trace_xn_time = {fReader, "wxnT"};
TTreeReaderArray<Float_t> trace_xn_rise = {fReader, "wxnR"};
TTreeReaderArray<Float_t> trace_rdt = {fReader, "wrdt"};
TTreeReaderArray<Float_t> trace_rdt_time = {fReader, "wrdtT"};
TTreeReaderArray<Float_t> 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

View File

@ -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];