tree title will be file name

This commit is contained in:
nrb@Debain10 2022-03-22 20:55:23 -04:00
parent 91f2727802
commit f0bcd2abae
4 changed files with 57 additions and 28 deletions

View File

@ -1,12 +1,14 @@
#define PreAnalyzer_cxx #define PreAnalyzer_cxx
#include "PreAnalyzer.h"
#include <TStyle.h> #include <TStyle.h>
#include <TMath.h> #include <TMath.h>
#include <stdio.h> #include <stdio.h>
#define TREESTRUCT 1 // if 0 = multi, 1 = array.
#include "PreAnalyzer.h"
//############################################ BEGIN //############################################ BEGIN
void PreAnalyzer::Begin(TTree * tree){ void PreAnalyzer::Begin(TTree * tree){
@ -153,19 +155,32 @@ Bool_t PreAnalyzer::Process(Long64_t entry){
//################ Gamma-Paritcle //################ Gamma-Paritcle
for( int i = 0 ; i < NCLOVER; i++){ for( int i = 0 ; i < NCLOVER; i++){
if( gamma[i] > 0 ) { if( gamma[i] > 0 ) {
gammaID[multi_N] = i;
gamma_N[multi_N] = gamma[i]; if( TREESTRUCT == 0 ){
gamma_t[multi_N] = gammaTime[i]; gammaID[multi_N] = i;
gamma_N[multi_N] = gamma[i];
gamma_t[multi_N] = gammaTime[i];
}else{
gamma_N[i] = gamma[i];
gamma_t[i] = gammaTime[i];
}
multi_N++; multi_N++;
} }
} }
for ( int i = 0 ; i < NGAGG ; i++){ for ( int i = 0 ; i < NGAGG ; i++){
if( count[i] == 2 ){ if( count[i] == 2 ){
gaggID[multiGagg_N] = i;
gagg_tail[multiGagg_N] = (tail[i][0]+tail[i][1])/2.; if ( TREESTRUCT == 0 ){
gagg_peak[multiGagg_N] = (peak[i][0]+peak[i][1])/2.; gaggID[multiGagg_N] = i;
gagg_t[multiGagg_N] = gaggTime[i]; gagg_tail[multiGagg_N] = (tail[i][0]+tail[i][1])/2.;
gagg_peak[multiGagg_N] = (peak[i][0]+peak[i][1])/2.;
gagg_t[multiGagg_N] = gaggTime[i];
}else{
gagg_tail[i] = (tail[i][0]+tail[i][1])/2.;
gagg_peak[i] = (peak[i][0]+peak[i][1])/2.;
gagg_t[i] = gaggTime[i];
}
multiGagg_N++; multiGagg_N++;
} }
} }
@ -186,9 +201,10 @@ void PreAnalyzer::Terminate(){
saveFile->cd(); //set focus on this file saveFile->cd(); //set focus on this file
newTree->Write(); newTree->Write();
Long64_t nEntries = newTree->GetEntries();
saveFile->Close(); saveFile->Close();
printf("-------------- done, saved in %s.\n", saveFileName.Data()); printf("-------------- done, saved in %s. number of entry : %lld\n", saveFileName.Data(), nEntries);
gROOT->ProcessLine(".q"); gROOT->ProcessLine(".q");

View File

@ -141,14 +141,18 @@ void PreAnalyzer::Init(TTree *tree)
eCorr = LoadCorrectionParameters("correction_e.dat"); eCorr = LoadCorrectionParameters("correction_e.dat");
///======================== open a new file ///======================== open a new file
saveFileName = "haha.root"; //TODO, if it is TChain, then we can get file name, else, use option
if( option == "" ){
saveFileName = "haha.root";
}else{
saveFileName = option;
}
saveFile = new TFile( saveFileName,"recreate"); saveFile = new TFile( saveFileName,"recreate");
TMacro e_corr("correction_e.dat"); TMacro e_corr("correction_e.dat");
e_corr.Write("correction_e"); e_corr.Write("correction_e");
newTree = new TTree("tree", "tree"); newTree = new TTree("tree", saveFileName);
eventID = -1; eventID = -1;
runID = 0; runID = 0;
@ -156,18 +160,27 @@ void PreAnalyzer::Init(TTree *tree)
multi_N = 0; multi_N = 0;
multiGagg_N = 0; multiGagg_N = 0;
newTree->Branch("eventID", &eventID, "eventID/l"); if( TREESTRUCT == 0 ){
newTree->Branch("runID", &runID_N, "runID/I"); newTree->Branch("eventID", &eventID, "eventID/l");
newTree->Branch("multi", &multi_N, "multi/I"); newTree->Branch("runID", &runID_N, "runID/I");
newTree->Branch("multiGagg", &multiGagg_N, "multiGagg/I"); newTree->Branch("multi", &multi_N, "multi/I");
newTree->Branch("gammaID", gammaID, "gammaID[multi]/S"); newTree->Branch("multiGagg", &multiGagg_N, "multiGagg/I");
newTree->Branch("gamma", gamma_N, "gamma[multi]/D"); newTree->Branch("gammaID", gammaID, "gammaID[multi]/S");
newTree->Branch("gamma_t", gamma_t, "gamma_t[multi]/l"); newTree->Branch("gamma", gamma_N, "gamma[multi]/D");
newTree->Branch("gaggID", gaggID, "gaggID[multiGagg]/I"); newTree->Branch("gamma_t", gamma_t, "gamma_t[multi]/l");
newTree->Branch("gaggP", gagg_peak, "gaggP[multiGagg]/D"); newTree->Branch("gaggID", gaggID, "gaggID[multiGagg]/I");
newTree->Branch("gaggT", gagg_tail, "gaggT[multiGagg]/D"); newTree->Branch("gaggP", gagg_peak, "gaggP[multiGagg]/D");
newTree->Branch("gagg_t", gagg_t, "gagg_t[multiGagg]/l"); newTree->Branch("gaggT", gagg_tail, "gaggT[multiGagg]/D");
newTree->Branch("gagg_t", gagg_t, "gagg_t[multiGagg]/l");
}else{
newTree->Branch("eventID", &eventID, "eventID/l");
newTree->Branch("runID", &runID_N, "runID/I");
newTree->Branch("gamma", gamma_N, Form("gamma[%d]/D", NCLOVER));
newTree->Branch("gamma_t", gamma_t, Form("gamma_t[%d]/l", NCLOVER));
newTree->Branch("gaggP", gagg_peak, Form("gaggP[%d]/D", NGAGG));
newTree->Branch("gaggT", gagg_tail, Form("gaggT[%d]/D", NGAGG));
newTree->Branch("gagg_t", gagg_t, Form("gagg_t[%d]/l", NGAGG));
}
printf("======================== Start processing....\n"); printf("======================== Start processing....\n");
StpWatch.Start(); StpWatch.Start();

View File

@ -80,7 +80,7 @@ int main(int argn, char **argv){
printf(">>> Create output tree\n"); printf(">>> Create output tree\n");
TFile * saveFile = new TFile(outFileName, "recreate"); TFile * saveFile = new TFile(outFileName, "recreate");
saveFile->cd(); saveFile->cd();
TTree * newtree = new TTree("tree", "tree"); TTree * newtree = new TTree("tree", outFileName);
Int_t eventID = 0 ; Int_t eventID = 0 ;
Int_t multi = 0; /// this is total multipicilty for all detectors Int_t multi = 0; /// this is total multipicilty for all detectors

View File

@ -77,7 +77,7 @@ int main(int argc, char **argv) {
TFile * outRootFile = new TFile(outFileName, "recreate"); TFile * outRootFile = new TFile(outFileName, "recreate");
outRootFile->cd(); outRootFile->cd();
TTree * tree = new TTree("tree", "tree"); TTree * tree = new TTree("tree", outFileName);
unsigned long long evID = 0; unsigned long long evID = 0;
int multi = 0; int multi = 0;