Monitor_raw.C/h can build event, but it is not perfered
This commit is contained in:
parent
60af179708
commit
d37251f2d7
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -12,6 +12,7 @@ pxi-time-order
|
||||||
evt2root
|
evt2root
|
||||||
evt2hist
|
evt2hist
|
||||||
ev22txt
|
ev22txt
|
||||||
|
EventBuilder
|
||||||
|
|
||||||
*.so
|
*.so
|
||||||
*.d
|
*.d
|
||||||
|
|
|
@ -1,31 +1,31 @@
|
||||||
#define Monitor_raw_cxx
|
#define Monitor_raw_cxx
|
||||||
|
|
||||||
#include "Monitor_raw.h"
|
|
||||||
#include <TH2.h>
|
#include <TH2.h>
|
||||||
#include <TH1.h>
|
#include <TH1.h>
|
||||||
#include <TStyle.h>
|
#include <TStyle.h>
|
||||||
|
|
||||||
#include <TCanvas.h>
|
#include <TCanvas.h>
|
||||||
#include <TMath.h>
|
#include <TMath.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <TStopwatch.h>
|
|
||||||
|
|
||||||
//############################################ User setting
|
//############################################ User setting
|
||||||
|
|
||||||
int rawEnergyRange[2] = {500, 6000}; // in ch, {min, max}
|
int rawEnergyRange[2] = {500, 6000}; // in ch, {min, max}
|
||||||
int energyRange[3] = {2, 40, 2000}; // in keV, {resol, min, max}
|
int energyRange[3] = {1, 40, 2000}; // in keV, {resol, min, max}
|
||||||
|
|
||||||
TString e_corr = "correction_e.dat";
|
TString e_corr = "correction_e.dat";
|
||||||
|
|
||||||
Long64_t maxEvent = -1;
|
Long64_t maxEvent = -1;
|
||||||
|
|
||||||
|
bool isBuildEventRoot = true; // is true, no histogram
|
||||||
|
|
||||||
|
|
||||||
//############################################ end of user setting
|
//############################################ end of user setting
|
||||||
|
|
||||||
ULong64_t NumEntries = 0;
|
#include "Monitor_raw.h"
|
||||||
ULong64_t ProcessedEntries = 0;
|
|
||||||
Float_t Frac = 0.1; ///Progress bar
|
|
||||||
TStopwatch StpWatch;
|
|
||||||
|
|
||||||
vector<vector<double>> eCorr;
|
|
||||||
|
|
||||||
//############################################ histogram declaration
|
//############################################ histogram declaration
|
||||||
|
|
||||||
|
@ -38,8 +38,15 @@ TH2F * heCalvID;
|
||||||
void Monitor_raw::Begin(TTree * tree){
|
void Monitor_raw::Begin(TTree * tree){
|
||||||
TString option = GetOption();
|
TString option = GetOption();
|
||||||
|
|
||||||
NumEntries = tree->GetEntries();
|
totnumEntry = tree->GetEntries();
|
||||||
|
|
||||||
|
printf( "=========================================================================== \n");
|
||||||
|
printf( "========================== Monitor_raw.C/h ================================ \n");
|
||||||
|
printf( "====== total Entry : %lld \n", totnumEntry);
|
||||||
|
printf( "=========================================================================== \n");
|
||||||
|
|
||||||
|
|
||||||
|
if( isBuildEvent == false && isBuildEventRoot == false) {
|
||||||
printf("======================== Creating histograms\n");
|
printf("======================== Creating histograms\n");
|
||||||
|
|
||||||
for( int i = 0 ; i < NCRYSTAL ; i++){
|
for( int i = 0 ; i < NCRYSTAL ; i++){
|
||||||
|
@ -63,13 +70,17 @@ void Monitor_raw::Begin(TTree * tree){
|
||||||
heCalvID = new TH2F("heCalvID", "ID vs Energy (Cali.); ID; Energy", NCRYSTAL, 0, NCRYSTAL, (energyRange[2]-energyRange[1])/energyRange[0], energyRange[1], energyRange[2]);
|
heCalvID = new TH2F("heCalvID", "ID vs Energy (Cali.); ID; Energy", NCRYSTAL, 0, NCRYSTAL, (energyRange[2]-energyRange[1])/energyRange[0], energyRange[1], energyRange[2]);
|
||||||
|
|
||||||
|
|
||||||
printf("======================== end of histograms creation.\n");
|
printf("------------------------ end of histograms creation.\n");
|
||||||
|
}
|
||||||
|
|
||||||
printf("======================== Load parameters.\n");
|
printf("======================== Load parameters.\n");
|
||||||
eCorr = LoadCorrectionParameters(e_corr);
|
eCorr = LoadCorrectionParameters(e_corr);
|
||||||
|
|
||||||
StpWatch.Start();
|
time0 = 0;
|
||||||
printf("======================== Start processing....\n");
|
timeDiff = 0;
|
||||||
|
|
||||||
|
ClearTreeData();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,11 +90,11 @@ Bool_t Monitor_raw::Process(Long64_t entry){
|
||||||
ProcessedEntries++;
|
ProcessedEntries++;
|
||||||
|
|
||||||
/*********** Progress Bar ******************************************/
|
/*********** Progress Bar ******************************************/
|
||||||
if (ProcessedEntries>NumEntries*Frac-1) {
|
if (ProcessedEntries>totnumEntry*Frac-1) {
|
||||||
TString msg; msg.Form("%llu", NumEntries/1000);
|
TString msg; msg.Form("%llu", totnumEntry/1000);
|
||||||
int len = msg.Sizeof();
|
int len = msg.Sizeof();
|
||||||
printf(" %3.0f%% (%*llu/%llu k) processed in %6.1f sec | expect %6.1f sec\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);
|
Frac*100, len, ProcessedEntries/1000,totnumEntry/1000,StpWatch.RealTime(), StpWatch.RealTime()/Frac);
|
||||||
StpWatch.Start(kFALSE);
|
StpWatch.Start(kFALSE);
|
||||||
Frac+=0.1;
|
Frac+=0.1;
|
||||||
}
|
}
|
||||||
|
@ -93,22 +104,25 @@ Bool_t Monitor_raw::Process(Long64_t entry){
|
||||||
Terminate();
|
Terminate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( isBuildEventRoot || isBuildEvent ) entry = index[entry];
|
||||||
|
|
||||||
b_ID->GetEntry(entry);
|
b_ID->GetEntry(entry);
|
||||||
b_energy->GetEntry(entry);
|
b_energy->GetEntry(entry);
|
||||||
b_timestamp->GetEntry(entry);
|
b_energy_timestamp->GetEntry(entry);
|
||||||
|
|
||||||
int detID = mapping[ID];
|
if ( isBuildEventRoot || isBuildEvent ) {
|
||||||
|
BuildEvent();
|
||||||
|
}else{
|
||||||
|
if( detID < 100 ){
|
||||||
|
he[detID]->Fill(energy);
|
||||||
|
|
||||||
if( 0 <= detID && detID < 100 ){
|
///double eCal = ApplyCorrection(eCorr, detID, e); //slow, why?
|
||||||
he[detID]->Fill(e);
|
double eCal = eCorr[detID][0] + eCorr[detID][1]*energy;
|
||||||
|
|
||||||
//double eCal = ApplyCorrection(eCorr, detID, e);
|
|
||||||
double eCal = eCorr[detID][0]+eCorr[detID][1]*e;
|
|
||||||
heCal[detID]->Fill(eCal);
|
heCal[detID]->Fill(eCal);
|
||||||
|
|
||||||
heCalvID->Fill(detID, eCal);
|
heCalvID->Fill(detID, eCal);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return kTRUE;
|
return kTRUE;
|
||||||
}
|
}
|
||||||
|
@ -116,9 +130,16 @@ Bool_t Monitor_raw::Process(Long64_t entry){
|
||||||
//############################################ TERMINATE
|
//############################################ TERMINATE
|
||||||
void Monitor_raw::Terminate(){
|
void Monitor_raw::Terminate(){
|
||||||
|
|
||||||
printf("============================== finishing.\n");
|
|
||||||
|
printf("============================== finished.\n");
|
||||||
gROOT->cd();
|
gROOT->cd();
|
||||||
|
|
||||||
|
if ( isBuildEventRoot || isBuildEvent ) {
|
||||||
|
saveFile->cd();
|
||||||
|
newtree->Write();
|
||||||
|
saveFile->Close();
|
||||||
|
}else{
|
||||||
|
|
||||||
int nCrystalPerClover = 4;
|
int nCrystalPerClover = 4;
|
||||||
int nClover = NCRYSTAL / nCrystalPerClover;
|
int nClover = NCRYSTAL / nCrystalPerClover;
|
||||||
|
|
||||||
|
@ -150,4 +171,6 @@ void Monitor_raw::Terminate(){
|
||||||
heCalvID->SetNdivisions(-409, "X");
|
heCalvID->SetNdivisions(-409, "X");
|
||||||
heCalvID->Draw("colz");
|
heCalvID->Draw("colz");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
233
Monitor_raw.h
233
Monitor_raw.h
|
@ -3,8 +3,12 @@
|
||||||
|
|
||||||
#include <TROOT.h>
|
#include <TROOT.h>
|
||||||
#include <TChain.h>
|
#include <TChain.h>
|
||||||
|
#include <TTree.h>
|
||||||
#include <TFile.h>
|
#include <TFile.h>
|
||||||
|
#include <TMacro.h>
|
||||||
#include <TSelector.h>
|
#include <TSelector.h>
|
||||||
|
#include <TStopwatch.h>
|
||||||
|
#include <TTreeIndex.h>
|
||||||
|
|
||||||
#include "mapping.h"
|
#include "mapping.h"
|
||||||
#include "armory/AnalysisLibrary.h"
|
#include "armory/AnalysisLibrary.h"
|
||||||
|
@ -19,17 +23,20 @@ public :
|
||||||
|
|
||||||
// Declaration of leaf types
|
// Declaration of leaf types
|
||||||
Long64_t evID;
|
Long64_t evID;
|
||||||
UShort_t ID;
|
UShort_t detID;
|
||||||
UShort_t e;
|
UShort_t energy;
|
||||||
ULong64_t t;
|
ULong64_t energy_t;
|
||||||
|
|
||||||
// List of branches
|
// List of branches
|
||||||
TBranch *b_data_ID; //!
|
TBranch *b_data_ID; //!
|
||||||
TBranch *b_ID; //!
|
TBranch *b_ID; //!
|
||||||
TBranch *b_energy; //!
|
TBranch *b_energy; //!
|
||||||
TBranch *b_timestamp; //!
|
TBranch *b_energy_timestamp; //!
|
||||||
|
|
||||||
Monitor_raw(TTree * /*tree*/ =0) : fChain(0) { }
|
Monitor_raw(TTree * /*tree*/ =0) : fChain(0) { isBuildEvent = false;
|
||||||
|
timeWindow = 100;
|
||||||
|
saveFileName = "test.root";
|
||||||
|
}
|
||||||
virtual ~Monitor_raw() { }
|
virtual ~Monitor_raw() { }
|
||||||
virtual Int_t Version() const { return 2; }
|
virtual Int_t Version() const { return 2; }
|
||||||
virtual void Begin(TTree *tree);
|
virtual void Begin(TTree *tree);
|
||||||
|
@ -45,7 +52,43 @@ public :
|
||||||
virtual void SlaveTerminate();
|
virtual void SlaveTerminate();
|
||||||
virtual void Terminate();
|
virtual void Terminate();
|
||||||
|
|
||||||
|
void SetBuildEvent(bool buildOption = false){ isBuildEvent = buildOption;}
|
||||||
|
|
||||||
ClassDef(Monitor_raw,0);
|
ClassDef(Monitor_raw,0);
|
||||||
|
|
||||||
|
//=================== progress
|
||||||
|
ULong64_t ProcessedEntries = 0;
|
||||||
|
Float_t Frac = 0.1; ///Progress bar
|
||||||
|
TStopwatch StpWatch;
|
||||||
|
|
||||||
|
//=================== correction parameters
|
||||||
|
vector<vector<double>> eCorr;
|
||||||
|
|
||||||
|
//=================== output tree;
|
||||||
|
bool isBuildEvent;
|
||||||
|
int timeWindow;
|
||||||
|
ULong64_t time0; //time-0 for each event
|
||||||
|
int timeDiff;
|
||||||
|
Long64_t * index; //!
|
||||||
|
|
||||||
|
TFile * saveFile; //!
|
||||||
|
TTree * newtree; //!
|
||||||
|
TString saveFileName;
|
||||||
|
Long64_t totnumEntry; /// of original root
|
||||||
|
|
||||||
|
//tree
|
||||||
|
void ClearTreeData();
|
||||||
|
void BuildEvent();
|
||||||
|
|
||||||
|
Int_t eventID;
|
||||||
|
double e[NCRYSTAL];
|
||||||
|
ULong64_t e_t[NCRYSTAL];
|
||||||
|
double bgo[NBGO];
|
||||||
|
ULong64_t bgo_t[NBGO];
|
||||||
|
Short_t other[NOTHER];
|
||||||
|
Short_t multi;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -55,15 +98,187 @@ void Monitor_raw::Init(TTree *tree)
|
||||||
{
|
{
|
||||||
// Set branch addresses and branch pointers
|
// Set branch addresses and branch pointers
|
||||||
if (!tree) return;
|
if (!tree) return;
|
||||||
fChain = tree;
|
|
||||||
|
fChain = (TChain *) tree;
|
||||||
fChain->SetMakeClass(1);
|
fChain->SetMakeClass(1);
|
||||||
|
|
||||||
fChain->SetBranchAddress("evID", &evID, &b_data_ID);
|
fChain->SetBranchAddress("evID", &evID, &b_data_ID);
|
||||||
fChain->SetBranchAddress("id", &ID, &b_ID);
|
fChain->SetBranchAddress("id", &detID, &b_ID);
|
||||||
fChain->SetBranchAddress("e", &e, &b_energy);
|
fChain->SetBranchAddress("e", &energy, &b_energy);
|
||||||
fChain->SetBranchAddress("t", &t, &b_timestamp);
|
fChain->SetBranchAddress("e_t", &energy_t, &b_energy_timestamp);
|
||||||
|
|
||||||
|
if( isBuildEventRoot || isBuildEvent){
|
||||||
|
|
||||||
|
printf("======================== Buidling Index using the timestamp\n");
|
||||||
|
tree->BuildIndex("e_t");
|
||||||
|
TTreeIndex *in = (TTreeIndex*) tree->GetTreeIndex();
|
||||||
|
index = in->GetIndex();
|
||||||
|
|
||||||
|
//for(int i = 0; i < 100; i++){
|
||||||
|
// printf(" %3d | %lld \n", i, index[i]);
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
TString option = GetOption();
|
||||||
|
|
||||||
|
//printf("======================== Formation of output file name\n");
|
||||||
|
//int numFile = fChain->GetListOfFiles()->GetLast() + 1; //need input of TChain
|
||||||
|
//
|
||||||
|
//printf(".......... number of files : %d \n", numFile);
|
||||||
|
//
|
||||||
|
//if( numFile > 0 ) {
|
||||||
|
// int oldRunNum = -100;
|
||||||
|
// bool contFlag = false; // is runNumber continue;
|
||||||
|
// for( int i = 0; i < numFile ; i++){
|
||||||
|
// TString name = ((TChain *) fChain)->GetListOfFiles()->At(i)->GetTitle();
|
||||||
|
// int found = name.Last('/');
|
||||||
|
// name.Remove(0, found + 1 ); // this should give "XXX_run0XX.root"
|
||||||
|
// TString prefix = name;
|
||||||
|
// found = name.Last('.');
|
||||||
|
// name.Remove(found); // this should give "XXX_run0XX"
|
||||||
|
// found = name.Last('_');
|
||||||
|
// int runNum = name.Remove(0, found+4).Atoi(); // this should give the 3 digit run number
|
||||||
|
//
|
||||||
|
// if( i == 0 ) {
|
||||||
|
// found = prefix.First("_");
|
||||||
|
// prefix.Remove(found);
|
||||||
|
// saveFileName = prefix + "_run";
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if( runNum == oldRunNum + 1 ){
|
||||||
|
// int kk = saveFileName.Sizeof();
|
||||||
|
// if( contFlag == false ){
|
||||||
|
// saveFileName.Remove(kk-2); //remove the "-"
|
||||||
|
// saveFileName += "-";
|
||||||
|
// }else{
|
||||||
|
// saveFileName.Remove(kk-5); //remove the runNum and "-"
|
||||||
|
// }
|
||||||
|
// contFlag = true;
|
||||||
|
// }
|
||||||
|
// if( runNum > oldRunNum + 1) contFlag = false;
|
||||||
|
//
|
||||||
|
// saveFileName += Form("%03d_", runNum);
|
||||||
|
// oldRunNum = runNum;
|
||||||
|
// }
|
||||||
|
// int kk = saveFileName.Sizeof();
|
||||||
|
// saveFileName.Remove(kk-2); // remove the last "-"
|
||||||
|
// saveFileName += ".root";
|
||||||
|
//}else{
|
||||||
|
// gROOT->ProcessLine(".q");
|
||||||
|
//}
|
||||||
|
|
||||||
|
if( option != "" ) saveFileName = option;
|
||||||
|
|
||||||
|
printf("save file name : %s \n", saveFileName.Data());
|
||||||
|
printf("---------------------------------------------\n");
|
||||||
|
|
||||||
|
//TODO;
|
||||||
|
saveFile = new TFile(saveFileName, "recreate");
|
||||||
|
saveFile->cd();
|
||||||
|
newtree = new TTree("tree", "tree");
|
||||||
|
|
||||||
|
printf("======================== Create output tree\n");
|
||||||
|
|
||||||
|
newtree->Branch("evID", &eventID, "event_ID/l");
|
||||||
|
newtree->Branch("e", e, Form("e[%d]/D", NCRYSTAL));
|
||||||
|
newtree->Branch("e_t", e_t, Form("e_timestamp[%d]/l", NCRYSTAL));
|
||||||
|
//newtree->Branch("p", pileup, Form("pile_up_flag[%d]/s", NCRYSTAL));
|
||||||
|
//newtree->Branch("hit", hit, Form("hit[%d]/s", NCRYSTAL));
|
||||||
|
|
||||||
|
newtree->Branch("bgo", bgo, Form("BGO_e[%d]/D", NBGO));
|
||||||
|
newtree->Branch("bgo_t", bgo_t, Form("BGO_timestamp[%d]/l", NBGO));
|
||||||
|
|
||||||
|
newtree->Branch("other", other, Form("other_e[%d]/D", NOTHER));
|
||||||
|
|
||||||
|
newtree->Branch("multi", &multi, "multiplicity_crystal/I");
|
||||||
|
|
||||||
|
|
||||||
|
if( eCorr.size() > 0 ) {
|
||||||
|
TMacro energyCorr(e_corr);
|
||||||
|
energyCorr.Write("energyCorr");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
printf("======================== Start processing....\n");
|
||||||
|
StpWatch.Start();
|
||||||
|
eventID = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Monitor_raw::ClearTreeData(){
|
||||||
|
|
||||||
|
for( int i = 0; i < NCRYSTAL; i++){
|
||||||
|
e[i] = TMath::QuietNaN();
|
||||||
|
e_t[i] = 0;
|
||||||
|
//pileup[i] = 0;
|
||||||
|
//hit[i] = 0;
|
||||||
|
}
|
||||||
|
for( int i = 0; i < NBGO; i++) {
|
||||||
|
bgo[i] = TMath::QuietNaN();
|
||||||
|
bgo_t[i] = 0 ;
|
||||||
|
}
|
||||||
|
for( int i = 0; i < NOTHER; i++) {
|
||||||
|
other[i] = TMath::QuietNaN();
|
||||||
|
}
|
||||||
|
multi = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Monitor_raw::BuildEvent(){
|
||||||
|
|
||||||
|
if( time0 == 0) time0 = energy_t;
|
||||||
|
|
||||||
|
timeDiff = (int) (energy_t - time0);
|
||||||
|
|
||||||
|
if( timeDiff < timeWindow ) {
|
||||||
|
|
||||||
|
if ( detID < NCRYSTAL ){
|
||||||
|
e[detID] = energy;
|
||||||
|
e_t[detID] = energy_t;
|
||||||
|
multi++;
|
||||||
|
}
|
||||||
|
if ( 100 <= detID && detID < 100 + NBGO ){
|
||||||
|
bgo[detID-100] = energy;
|
||||||
|
bgo_t[detID-100] = energy_t;
|
||||||
|
}
|
||||||
|
if ( 200 <= detID && detID < 200 + NOTHER){
|
||||||
|
other[detID-200] = energy;
|
||||||
|
}
|
||||||
|
|
||||||
|
//printf("%d | %3d %6d %10llu, %3d\n", multi, detID, energy, energy_t, timeDiff);
|
||||||
|
|
||||||
|
}else{
|
||||||
|
//---- end of event
|
||||||
|
eventID ++;
|
||||||
|
|
||||||
|
saveFile->cd();
|
||||||
|
newtree->Fill();
|
||||||
|
|
||||||
|
ClearTreeData();
|
||||||
|
|
||||||
|
/// fill 1st data of an event
|
||||||
|
time0 = energy_t;
|
||||||
|
timeDiff = 0;
|
||||||
|
|
||||||
|
if ( detID < NCRYSTAL ){
|
||||||
|
e[detID] = energy;
|
||||||
|
e_t[detID] = energy_t;
|
||||||
|
multi = 1;
|
||||||
|
}
|
||||||
|
if ( 100 <= detID && detID < 100 + NBGO ){
|
||||||
|
bgo[detID-100] = energy;
|
||||||
|
bgo_t[detID-100] = energy_t;
|
||||||
|
}
|
||||||
|
if ( 200 <= detID && detID < 200 + NOTHER){
|
||||||
|
other[detID-200] = energy;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Bool_t Monitor_raw::Notify()
|
Bool_t Monitor_raw::Notify()
|
||||||
{
|
{
|
||||||
return kTRUE;
|
return kTRUE;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user