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>
2022-01-06 13:18:29 -05:00
# include <stdio.h>
2021-12-14 10:35:05 -05:00
//############################################ User setting
2022-01-06 13:18:29 -05:00
int rawEnergyRange [ 2 ] = { 0 , 6000 } ; // in ch
2022-01-06 18:00:36 -05:00
int energyRange [ 3 ] = { 1 , 50 , 2000 } ; // keV {resol, min, max}
2021-12-14 10:35:05 -05:00
2022-01-06 13:18:29 -05:00
double BGO_threshold = 0 ; // in ch
2021-12-14 10:35:05 -05:00
2022-01-06 18:00:36 -05:00
TString e_corr = " correction_e.dat " ;
bool save_ev2 = true ;
2021-12-16 15:24:18 -05:00
2021-12-14 10:35:05 -05:00
//############################################ end of user setting
2021-12-16 15:24:18 -05:00
2021-12-14 10:35:05 -05:00
//############################################ histogram declaration
2022-01-06 18:00:36 -05:00
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 ;
2022-01-07 13:10:17 -05:00
TH2F * hcrystalBGO ;
2022-01-07 14:46:32 -05:00
TH1F * hTDiff ;
2022-01-13 18:23:41 -05:00
TH2F * hPID ;
TH2F * hPID209 ;
TH2F * hPID219 ;
2021-12-14 20:39:20 -05:00
///----- after calibration and BGO veto
2022-01-06 18:00:36 -05:00
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
2022-01-07 13:10:17 -05:00
TH2F * hcrystalBGO_G ;
2022-01-06 13:18:29 -05:00
2021-12-21 20:55:29 -05:00
//############################################ BEGIN
2021-12-14 10:35:05 -05:00
void Analyzer : : Begin ( TTree * tree ) {
TString option = GetOption ( ) ;
2022-01-06 13:18:29 -05:00
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
2021-12-16 15:24:18 -05:00
printf ( " ======================== Histograms declaration \n " ) ;
2021-12-16 10:30:38 -05:00
2022-01-06 18:00:36 -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
2022-01-07 14:46:32 -05:00
hTDiff = new TH1F ( " hTDiff " , " data time different within an event; tick [10 ns] " , 110 , 0 , 110 ) ;
2022-01-06 18:00:36 -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
}
2022-01-13 18:23:41 -05:00
hPID = new TH2F ( " hPID " , " PID; tail; peak " , 400 , - 20 , 300 , 400 , - 50 , 800 ) ;
hPID209 = new TH2F ( " hPID209 " , " PID detID = 209; tail; peak " , 400 , - 20 , 300 , 400 , - 50 , 800 ) ;
hPID219 = new TH2F ( " hPID219 " , " PID detID = 219; tail; peak " , 400 , - 20 , 300 , 400 , - 50 , 800 ) ;
2021-12-16 19:36:36 -05:00
for ( int i = 0 ; i < NCRYSTAL ; i + + ) {
for ( int j = i + 1 ; j < NCRYSTAL ; j + + ) {
2021-12-16 15:24:18 -05:00
//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 ) ;
2022-01-06 13:18:29 -05:00
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 ) ;
2022-01-06 13:18:29 -05:00
hcrystalBGO = new TH2F ( " hcrystalBGO " , Form ( " crystal vs BGO ; det ID; BGO ID " ) , NCRYSTAL , 0 , NCRYSTAL , NBGO , 0 , NBGO ) ;
2022-01-07 13:10:17 -05:00
hcrystalBGO_G = new TH2F ( " hcrystalBGO_G " , Form ( " crystal vs BGO (BGO veto); det ID; BGO ID " ) , NCRYSTAL , 0 , NCRYSTAL , NBGO , 0 , NBGO ) ;
2021-12-14 10:35:05 -05:00
2021-12-16 15:24:18 -05:00
printf ( " ======================== Load parameters. \n " ) ;
eCorr = LoadCorrectionParameters ( e_corr ) ;
2022-01-06 18:00:36 -05:00
saveEV2 = save_ev2 ;
2021-12-14 10:35:05 -05:00
}
2022-01-06 18:00:36 -05:00
2021-12-21 20:55:29 -05:00
//############################################ PROCESS
2021-12-14 10:35:05 -05:00
Bool_t Analyzer : : Process ( Long64_t entry ) {
ProcessedEntries + + ;
/*********** Progress Bar ******************************************/
2022-01-06 13:18:29 -05:00
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 " ,
2022-01-06 13:18:29 -05:00
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 ) ;
2022-01-06 13:18:29 -05:00
b_multi - > GetEntry ( entry ) ;
2022-01-06 19:29:26 -05:00
b_multiCry - > GetEntry ( entry ) ;
b_detID - > GetEntry ( entry ) ;
2022-01-13 18:23:41 -05:00
b_qdc - > GetEntry ( entry ) ;
2021-12-14 10:35:05 -05:00
if ( multi = = 0 ) return kTRUE ;
2022-01-06 13:18:29 -05:00
2022-01-06 18:00:36 -05:00
for ( int i = 0 ; i < NCRYSTAL ; i + + ) eCal [ i ] = TMath : : QuietNaN ( ) ;
2021-12-14 10:35:05 -05:00
2022-01-07 14:46:32 -05:00
///printf("---------------------------- %d \n", multi);
2022-01-13 18:23:41 -05:00
double bgC [ 2 ] = { 0 } , peakC [ 2 ] = { 0 } , tailC [ 2 ] = { 0 } ;
int count = 0 ;
///=========== Looping data for the event
2022-01-06 19:29:26 -05:00
for ( int i = 0 ; i < multi ; i + + ) {
2022-01-07 14:46:32 -05:00
int id = detID [ i ] ;
///printf("%d %f %llu\n", id, e[i], e_t[i]);
2022-01-06 19:29:26 -05:00
2021-12-14 10:35:05 -05:00
//======== Fill raw data
2022-01-07 14:46:32 -05:00
if ( 0 < = id & & id < NCRYSTAL ) { /// gamma data
heVID - > Fill ( id , e [ i ] ) ;
he [ id ] - > Fill ( e [ i ] ) ;
2022-01-06 19:29:26 -05:00
for ( int j = i + 1 ; j < multi ; j + + ) {
2022-01-07 14:46:32 -05:00
if ( 100 < = detID [ j ] & & detID [ j ] < 200 ) hcrystalBGO - > Fill ( id , detID [ j ] - 100 ) ; /// crystal - BGO coincident
2022-01-06 19:29:26 -05:00
2022-01-07 14:46:32 -05:00
if ( detID [ j ] < 100 ) hcoin - > Fill ( id , detID [ j ] ) ; /// crystal-crystal coincident
2022-01-06 19:29:26 -05:00
}
2022-01-06 13:18:29 -05:00
}
2022-01-07 14:46:32 -05:00
if ( 100 < id & & id < 200 ) { /// BGO data
2022-01-06 19:29:26 -05:00
2021-12-14 10:35:05 -05:00
}
2022-01-13 18:23:41 -05:00
if ( 200 < id & & id < 300 ) { /// GAGG
}
if ( id = = 209 ) {
double bg = ( qdc [ i ] [ 0 ] + qdc [ i ] [ 1 ] ) / 60. ;
double peak = qdc [ i ] [ 3 ] / 20. - bg ;
double tail = qdc [ i ] [ 5 ] / 55. - bg ;
hPID209 - > Fill ( tail , peak ) ;
}
if ( id = = 219 ) {
double bg = ( qdc [ i ] [ 0 ] + qdc [ i ] [ 1 ] ) / 60. ;
double peak = qdc [ i ] [ 3 ] / 20. - bg ;
double tail = qdc [ i ] [ 5 ] / 55. - bg ;
hPID219 - > Fill ( tail , peak ) ;
}
if ( count < 2 & & ( id = = 209 | | id = = 219 ) ) {
bgC [ count ] = ( qdc [ i ] [ 0 ] + qdc [ i ] [ 1 ] ) / 60. ;
peakC [ count ] = qdc [ i ] [ 3 ] / 20. - bgC [ count ] ;
tailC [ count ] = qdc [ i ] [ 5 ] / 55. - bgC [ count ] ;
count + + ;
}
2022-01-07 14:46:32 -05:00
if ( i > 0 ) hTDiff - > Fill ( e_t [ i ] - e_t [ 0 ] ) ;
2022-01-06 19:29:26 -05:00
2022-01-07 14:46:32 -05:00
2021-12-14 10:35:05 -05:00
//======== BGO veto
2022-01-06 19:29:26 -05:00
bool dropflag = false ;
2022-01-07 14:46:32 -05:00
if ( id < NCRYSTAL & & multi > 1 ) {
2022-01-06 19:29:26 -05:00
for ( int j = i + 1 ; j < multi ; j + + ) {
2022-01-07 14:46:32 -05:00
if ( detID [ j ] > = 100 & & ( detID [ j ] - 100 ) * 4 < = id & & id < ( detID [ j ] - 100 + 1 ) * 4 ) {
2022-01-06 19:29:26 -05:00
dropflag = true ;
break ;
}
2021-12-14 10:35:05 -05:00
}
}
2022-01-06 19:29:26 -05:00
if ( dropflag ) return kTRUE ;
2021-12-14 10:35:05 -05:00
2022-01-07 14:46:32 -05:00
if ( 0 < = id & & id < NCRYSTAL ) {
2022-01-06 19:29:26 -05:00
if ( e_corr = = " " ) {
2022-01-07 14:46:32 -05:00
eCal [ id ] = e [ i ] ;
2022-01-06 19:29:26 -05:00
} else {
2022-01-07 14:46:32 -05:00
///========= apply correction
int order = ( int ) eCorr [ id ] . size ( ) ;
eCal [ id ] = 0 ;
for ( int k = 0 ; k < order ; k + + ) {
eCal [ id ] + = eCorr [ id ] [ k ] * TMath : : Power ( e [ i ] , k ) ;
}
2022-01-06 19:29:26 -05:00
}
2022-01-07 14:46:32 -05:00
heCalVID - > Fill ( id , eCal [ id ] ) ;
heCal [ id ] - > Fill ( eCal [ id ] ) ;
2022-01-07 13:10:17 -05:00
for ( int j = i + 1 ; j < multi ; j + + ) {
2022-01-07 14:46:32 -05:00
if ( 100 < = detID [ j ] & & detID [ j ] < 200 ) hcrystalBGO_G - > Fill ( id , detID [ j ] - 100 ) ; /// crystal - BGO coincident
2022-01-07 13:10:17 -05:00
}
2021-12-14 10:52:55 -05:00
}
2022-01-07 14:46:32 -05:00
2021-12-14 10:35:05 -05:00
}
2022-01-06 13:18:29 -05:00
2022-01-13 18:23:41 -05:00
hPID - > Fill ( ( tailC [ 0 ] + tailC [ 1 ] ) / 2. , ( peakC [ 0 ] + peakC [ 1 ] ) / 2. ) ;
2022-01-06 18:00:36 -05:00
if ( saveEV2 ) Save2ev2 ( ) ;
2022-01-06 13:18:29 -05:00
2021-12-14 10:35:05 -05:00
return kTRUE ;
}
2021-12-21 20:55:29 -05:00
//############################################ TERMINATE
2021-12-14 10:35:05 -05:00
void Analyzer : : Terminate ( ) {
2022-01-06 13:18:29 -05:00
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 ) ;
2022-01-13 18:23:41 -05:00
hPID209 - > Draw ( " colz " ) ;
2021-12-14 10:35:05 -05:00
cCanvas - > cd ( 2 ) ;
cCanvas - > cd ( 2 ) - > SetLogz ( 1 ) ;
2022-01-13 18:23:41 -05:00
hPID219 - > Draw ( " colz " ) ;
2021-12-14 10:35:05 -05:00
2021-12-14 10:52:55 -05:00
cCanvas - > cd ( 3 ) ;
2021-12-16 15:24:18 -05:00
cCanvas - > cd ( 3 ) - > SetLogz ( 1 ) ;
2022-01-13 18:23:41 -05:00
hPID - > Draw ( " colz " ) ;
2021-12-14 10:52:55 -05:00
cCanvas - > cd ( 4 ) ;
2022-01-07 13:10:17 -05:00
cCanvas - > cd ( 4 ) - > SetLogz ( 1 ) ;
2022-01-13 18:23:41 -05:00
//gROOT->ProcessLine(".x script.C");
//hcrystalBGO_G->Draw("colz");
2022-01-07 13:10:17 -05:00
//he[0]->SetLineColor(2);
//he[0]->Draw();
//heCal[0]->Draw("same");
2022-01-06 13:18:29 -05:00
//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 " ) ;
2021-12-14 20:39:20 -05:00
printf ( " =============== Analyzer Utility \n " ) ;
2021-12-20 17:26:48 -05:00
gROOT - > ProcessLine ( " .L armory/Analyzer_Utili.c " ) ;
2021-12-16 15:24:18 -05:00
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
}