XIAEventBuilder/Analyzer.C

215 lines
6.7 KiB
C++
Raw Normal View History

2021-12-14 10:35:05 -05:00
#define Analyzer_cxx
#include "Analyzer.h"
#include <TH2.h>
#include <TStyle.h>
#include <TH1.h>
#include <TCanvas.h>
#include <TMath.h>
#include <vector>
#include <stdio.h>
2021-12-14 10:35:05 -05:00
//############################################ User setting
int rawEnergyRange[2] = {0, 6000}; // in ch
int energyRange[3] = {1, 50, 2000}; // keV {resol, min, max}
2021-12-14 10:35:05 -05:00
double BGO_threshold = 0; // in ch
2021-12-14 10:35:05 -05:00
TString e_corr = "correction_e.dat";
bool save_ev2 = true;
2021-12-14 10:35:05 -05:00
//############################################ end of user setting
2021-12-14 10:35:05 -05:00
//############################################ histogram declaration
TH2F * heVID;
2021-12-16 19:36:36 -05:00
TH1F * he[NCRYSTAL];
2021-12-14 10:35:05 -05:00
2021-12-16 19:36:36 -05:00
TH2F * hgg[NCRYSTAL][NCRYSTAL];
2021-12-14 10:35:05 -05:00
TH2F * hcoin;
///----- after calibration and BGO veto
TH2F * heCalVID;
2021-12-16 19:36:36 -05:00
TH1F * heCal[NCRYSTAL];
2021-12-14 10:52:55 -05:00
TH2F * hcoinBGO;
2021-12-14 10:35:05 -05:00
TH2F * hcrystalBGO;
//############################################ BEGIN
2021-12-14 10:35:05 -05:00
void Analyzer::Begin(TTree * tree){
TString option = GetOption();
totnumEntry = tree->GetEntries();
printf( "=========================================================================== \n");
printf( "========================== Analysis.C/h ================================ \n");
printf( "====== total Entry : %lld \n", totnumEntry);
printf( "=========================================================================== \n");
2021-12-14 10:35:05 -05:00
printf("======================== Histograms declaration\n");
2021-12-16 10:30:38 -05:00
heVID = new TH2F("heVID", "e vs ID; det ID; e [ch]", NCRYSTAL, 0, NCRYSTAL, rawEnergyRange[1] - rawEnergyRange[0], rawEnergyRange[0], rawEnergyRange[1]);
heCalVID = new TH2F("heCalVID", Form("eCal vs ID (BGO veto > %.1f); det ID; Energy [keV]", BGO_threshold), NCRYSTAL, 0, NCRYSTAL, (energyRange[2] - energyRange[1])/energyRange[0], energyRange[1], energyRange[2]);
2021-12-24 16:29:50 -05:00
heVID->SetNdivisions(-409, "X");
heCalVID->SetNdivisions(-409, "X");
2021-12-24 16:29:50 -05:00
2021-12-16 19:36:36 -05:00
for( int i = 0; i < NCRYSTAL; i ++){
2021-12-14 10:35:05 -05:00
he[i] = new TH1F( Form("he%02d", i), Form("e -%02d", i), rawEnergyRange[1] - rawEnergyRange[0], rawEnergyRange[0], rawEnergyRange[1]);
2021-12-16 19:36:36 -05:00
heCal[i] = new TH1F(Form("heCal%02d", i), Form("eCal -%02d (BGO veto > %.1f); Energy [keV]; count / %d keV", i, BGO_threshold, energyRange[0]), (energyRange[2] - energyRange[1])/energyRange[0], energyRange[1], energyRange[2]);
2021-12-14 10:35:05 -05:00
}
2021-12-16 19:36:36 -05:00
for( int i = 0; i < NCRYSTAL; i++){
for( int j = i+1; j < NCRYSTAL; j++){
//hgg[i][j] = new TH2F(Form("hgg%02d%02d", i, j), Form("e%02d vs e%02d; e%02d; e%02d", i, j, i, j),
// (rawEnergyRange[1] - rawEnergyRange[0])/2, rawEnergyRange[0], rawEnergyRange[1],
// (rawEnergyRange[1] - rawEnergyRange[0])/2, rawEnergyRange[0], rawEnergyRange[1]);
2021-12-14 10:35:05 -05:00
}
}
2021-12-16 19:36:36 -05:00
hcoin = new TH2F("hcoin", "detector coin.; det ID; det ID", NCRYSTAL, 0, NCRYSTAL, NCRYSTAL, 0 , NCRYSTAL);
2021-12-16 19:36:36 -05:00
hcoinBGO = new TH2F("hcoinBGO", Form("detector coin. (BGO veto > %.1f); det ID; det ID", BGO_threshold), NCRYSTAL, 0, NCRYSTAL, NCRYSTAL, 0 , NCRYSTAL);
hcrystalBGO = new TH2F("hcrystalBGO", Form("crystal vs BGO ; det ID; BGO ID"), NCRYSTAL, 0, NCRYSTAL, NBGO, 0 , NBGO);
2021-12-14 10:35:05 -05:00
printf("======================== Load parameters.\n");
eCorr = LoadCorrectionParameters(e_corr);
saveEV2 = save_ev2;
2021-12-14 10:35:05 -05:00
}
//############################################ PROCESS
2021-12-14 10:35:05 -05:00
Bool_t Analyzer::Process(Long64_t entry){
ProcessedEntries++;
/*********** Progress Bar ******************************************/
if (ProcessedEntries>totnumEntry*Frac-1) {
TString msg; msg.Form("%llu", totnumEntry/1000);
2021-12-14 10:35:05 -05:00
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,totnumEntry/1000,StpWatch.RealTime(), StpWatch.RealTime()/Frac);
2021-12-14 10:35:05 -05:00
StpWatch.Start(kFALSE);
Frac+=0.1;
}
b_energy->GetEntry(entry);
b_time->GetEntry(entry);
b_multi->GetEntry(entry);
b_multiCry->GetEntry(entry);
b_detID->GetEntry(entry);
2021-12-14 10:35:05 -05:00
if( multi == 0 ) return kTRUE;
for( int i = 0; i < NCRYSTAL; i++) eCal[i] = TMath::QuietNaN();
2021-12-14 10:35:05 -05:00
///=========== Looping data for the event
for( int i = 0; i < multi ; i ++){
2021-12-14 10:35:05 -05:00
//======== Fill raw data
if( detID[i] < 100 ){ /// gamma data
heVID->Fill( detID[i], e[i]);
he[detID[i]]->Fill(e[i]);
for ( int j = i + 1; j < multi; j++){
if( 100 <= detID[j] && detID[j] < 200 ) hcrystalBGO->Fill(detID[i], detID[j]-100); /// crystal - BGO coincident
if( detID[j] < 100 ) hcoin->Fill(detID[i], detID[j]); /// crystal-crystal coincident
}
}
if ( 100 < detID[i] && detID[i] < 200 ){ /// BGO data
2021-12-14 10:35:05 -05:00
}
2021-12-14 10:35:05 -05:00
//======== BGO veto
bool dropflag = false;
if( detID[i] < 100 && multi > 1) {
for( int j = i + 1; j < multi; j++){
if( detID[j] > 100 && (detID[j]-100)*4 < detID[i] && detID[i] < (detID[j]-100 +1)*4) {
dropflag = true;
break;
}
2021-12-14 10:35:05 -05:00
}
}
if( dropflag ) return kTRUE;
2021-12-14 10:35:05 -05:00
//========= apply correction
//int order = (int) eCorr[detID].size();
//for( int i = 0; i < order ; i++){
// eCal[detID] += eCorr[detID][i] * TMath::Power(e[detID], i);
//}
if( detID[i] < 100 ) {
if( e_corr == "" ){
eCal[detID[i]] = e[i];
}else{
eCal[detID[i]] = eCorr[detID[i]][0] + eCorr[detID[i]][1] * e[i];
}
heCalVID->Fill( detID[i], eCal[detID[i]]);
heCal[detID[i]]->Fill(eCal[detID[i]]);
2021-12-14 10:52:55 -05:00
}
2021-12-14 10:35:05 -05:00
}
if ( saveEV2) Save2ev2();
2021-12-14 10:35:05 -05:00
return kTRUE;
}
//############################################ TERMINATE
2021-12-14 10:35:05 -05:00
void Analyzer::Terminate(){
if(saveEV2) fclose(outEV2);
2021-12-14 10:35:05 -05:00
printf("============================== finishing.\n");
gROOT->cd();
2021-12-14 10:52:55 -05:00
int canvasXY[2] = {1200 , 1200} ;// x, y
int canvasDiv[2] = {2,2};
2021-12-14 10:35:05 -05:00
TCanvas *cCanvas = new TCanvas("cCanvas", "" ,canvasXY[0],canvasXY[1]);
cCanvas->Modified(); cCanvas->Update();
cCanvas->cd(); cCanvas->Divide(canvasDiv[0],canvasDiv[1]);
gStyle->SetOptStat("neiou");
cCanvas->cd(1);
cCanvas->cd(1)->SetLogz(1);
heVID->Draw("colz");
2021-12-14 10:35:05 -05:00
cCanvas->cd(2);
cCanvas->cd(2)->SetLogz(1);
heCalVID->Draw("colz");
2021-12-14 10:35:05 -05:00
2021-12-14 10:52:55 -05:00
cCanvas->cd(3);
cCanvas->cd(3)->SetLogz(1);
hcrystalBGO->Draw("colz");
2021-12-14 10:52:55 -05:00
cCanvas->cd(4);
//cCanvas->cd(4)->SetLogz(1);
he[0]->SetLineColor(2);
he[0]->Draw();
heCal[0]->Draw("same");
//hcoinBGO->Draw("colz");
2021-12-16 19:36:36 -05:00
printf("=============== loaded AutoFit.C, try showFitMethos()\n");
2021-12-20 17:26:48 -05:00
gROOT->ProcessLine(".L armory/AutoFit.C");
printf("=============== Analyzer Utility\n");
2021-12-20 17:26:48 -05:00
gROOT->ProcessLine(".L armory/Analyzer_Utili.c");
gROOT->ProcessLine("listDraws()");
2021-12-14 10:35:05 -05:00
2021-12-16 19:36:36 -05:00
2021-12-14 10:35:05 -05:00
}