bugs fixed, add correction parameter loading

This commit is contained in:
Ryan Tang 2021-12-16 15:24:18 -05:00
parent 923dc4626f
commit ba8c8d4657
7 changed files with 173 additions and 79 deletions

View File

@ -12,10 +12,12 @@
//############################################ User setting
int rawEnergyRange[2] = {100, 6000}; // in ch
int energyRange[2] = {100, 2000}; // keV
int energyRange[3] = {1, 100, 2000}; // keV {resol, min, max}
double BGO_threshold = 100; // in ch
TString e_corr = "e_corr.txt";
//############################################ end of user setting
ULong64_t NumEntries = 0;
@ -23,13 +25,13 @@ ULong64_t ProcessedEntries = 0;
Float_t Frac = 0.1; ///Progress bar
TStopwatch StpWatch;
vector<vector<double>> eCorr;
//############################################ histogram declaration
TH2F * heVID;
TH1F * he[NCLOVER];
TH1F * h1, * h2;
TH2F * hgg[NCLOVER][NCLOVER];
TH2F * hcoin;
@ -45,10 +47,7 @@ void Analyzer::Begin(TTree * tree){
NumEntries = tree->GetEntries();
printf("======================== histogram declaration\n");
h1 = new TH1F("h1", "h1", 1900, 100, 2000);
h2 = new TH1F("h2", "h2 BGO gated", 1900, 100, 2000);
printf("======================== Histograms declaration\n");
heVID = new TH2F("heVID", "e vs ID; det ID; e [ch]", NCLOVER, 0, NCLOVER, rawEnergyRange[1] - rawEnergyRange[0], rawEnergyRange[0], rawEnergyRange[1]);
heCalVID = new TH2F("heCalVID", Form("eCal vs ID (BGO veto > %.1f); det ID; e [ch]", BGO_threshold), NCLOVER, 0, NCLOVER, rawEnergyRange[1] - rawEnergyRange[0], rawEnergyRange[0], rawEnergyRange[1]);
@ -59,17 +58,23 @@ void Analyzer::Begin(TTree * tree){
for( int i = 0; i < NCLOVER; i++){
for( int j = i+1; j < NCLOVER; 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]);
//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]);
}
}
hcoin = new TH2F("hcoin", "detector coin.; det ID; det ID", NCLOVER, 0, NCLOVER, NCLOVER, 0 , NCLOVER);
hcoinBGO = new TH2F("hcoinBGO", Form("detector coin. (BGO veto > %.1f); det ID; det ID", BGO_threshold), NCLOVER, 0, NCLOVER, NCLOVER, 0 , NCLOVER);
printf("======================== End of histograms Declaration\n");
printf("======================== End of histograms declaration\n");
printf("======================== Load parameters.\n");
eCorr = LoadCorrectionParameters(e_corr);
StpWatch.Start();
printf("======================== Start processing....\n");
}
@ -105,30 +110,12 @@ Bool_t Analyzer::Process(Long64_t entry){
//======== Fill raw data
heVID->Fill( detID, e[detID]);
he[detID]->Fill(e[detID]);
if( 8 == detID ) {
h1->Fill( e[detID]*0.307484 - 0.505163 );
heCal[detID]->Fill( e[detID]*0.307484 - 0.505163 );
}
if( 9 == detID ) {
h1->Fill( e[detID]*0.308628 + 0.672629 );
heCal[detID]->Fill( e[detID]*0.308628 + 0.672629 );
}
if( 10 == detID ) {
h1->Fill( e[detID]*0.308445 + 0.238095 );
heCal[detID]->Fill( e[detID]*0.308445 + 0.238095 );
}
if( 11 == detID ) {
h1->Fill( e[detID]*0.312665 + 0.359117 );
heCal[detID]->Fill( e[detID]*0.312665 + 0.359117 );
}
for( int detJ = detID +1; detJ < NCLOVER; detJ++) {
if( TMath::IsNaN(e[detJ])) continue;
hgg[detID][detJ]->Fill(e[detID], e[detJ]); // x then y
//hgg[detID][detJ]->Fill(e[detID], e[detJ]); // x then y
hcoin->Fill(detID, detJ);
}
@ -141,19 +128,11 @@ Bool_t Analyzer::Process(Long64_t entry){
}
if( 8 == detID ) h2->Fill( e[detID]*0.307484 - 0.505163 );
if( 9 == detID ) h2->Fill( e[detID]*0.308628 + 0.672629 );
if( 10 == detID ) h2->Fill( e[detID]*0.308445 + 0.238095 );
if( 11 == detID ) h2->Fill( e[detID]*0.312665 + 0.359117 );
//========= apply correction
double eCal = e[detID];
heCalVID->Fill( detID, eCal);
//heCal[detID]->Fill(eCal);
heCal[detID]->Fill(eCal);
for( int detJ = detID +1; detJ < NCLOVER; detJ++) {
if( TMath::IsNaN(e[detJ])) continue;
@ -187,22 +166,16 @@ void Analyzer::Terminate(){
heCalVID->Draw("colz");
cCanvas->cd(3);
//cCanvas->cd(3)->SetLogz(1);
//hcoin->Draw("colz");
h1->Draw("");
heCal[8]->SetLineColor(2);heCal[8]->Draw("same");
heCal[9]->SetLineColor(4);heCal[9]->Draw("same");
heCal[10]->SetLineColor(6);heCal[10]->Draw("same");
heCal[11]->SetLineColor(7);heCal[11]->Draw("same");
cCanvas->cd(3)->SetLogz(1);
hcoin->Draw("colz");
cCanvas->cd(4);
//cCanvas->cd(4)->SetLogz(1);
//hcoinBGO->Draw("colz");
h2->Draw("");
cCanvas->cd(4)->SetLogz(1);
hcoinBGO->Draw("colz");
printf("=============== Analyzer Utility\n");
gROOT->ProcessLine(".L Analyzer_Utilt.c");
//gROOT->ProcessLine("listDraws()");
gROOT->ProcessLine(".L Analyzer_Utili.c");
gROOT->ProcessLine("listDraws()");
printf("=============== loaded AutoFit.C\n");
gROOT->ProcessLine(".L AutoFit.C");

View File

@ -8,6 +8,7 @@
#ifndef Analyzer_h
#define Analyzer_h
#include <fstream>
#include <TROOT.h>
#include <TChain.h>
#include <TFile.h>
@ -112,4 +113,97 @@ void Analyzer::SlaveTerminate(){
}
std::vector<std::string> SplitStr(std::string tempLine, std::string splitter, int shift = 0){
std::vector<std::string> output;
size_t pos;
do{
pos = tempLine.find(splitter); /// fine splitter
if( pos == 0 ){ ///check if it is splitter again
tempLine = tempLine.substr(pos+1);
continue;
}
std::string secStr;
if( pos == std::string::npos ){
secStr = tempLine;
}else{
secStr = tempLine.substr(0, pos+shift);
tempLine = tempLine.substr(pos+shift);
}
///check if secStr is begin with space
while( secStr.substr(0, 1) == " "){
secStr = secStr.substr(1);
};
///check if secStr is end with space
while( secStr.back() == ' '){
secStr = secStr.substr(0, secStr.size()-1);
}
output.push_back(secStr);
//printf(" |%s---\n", secStr.c_str());
}while(pos != std::string::npos );
return output;
}
std::vector<std::vector<double>> LoadCorrectionParameters(TString corrFile){
printf("==================== load correction parameters : %s", corrFile.Data());
std::ifstream file;
file.open(corrFile.Data());
std::vector<std::vector<double>> corr;
corr.clear();
std::vector<double> detCorr;
detCorr.clear();
if( file.is_open() ){
while( file.good() ){
std::string line;
getline(file, line);
if( line.substr(0,1) == "#" ) continue;
if( line.substr(0,2) == "//" ) continue;
if( line.size() == 0 ) continue;
std::vector<std::string> temp = SplitStr(line, " ");
detCorr.clear();
for( int i = 0; i < (int) temp.size() ; i++){
detCorr.push_back(std::stod(temp[i]));
}
corr.push_back(detCorr);
}
file.close();
printf(".... done\n");
printf("===== correction parameters \n");
for( int i = 0; i < (int) corr.size(); i++){
printf("det : %2d | ", i );
int len = (int) corr[i].size();
for( int j = 0; j < len - 1 ; j++){
printf("%6.2f, ", corr[i][j]);
}
printf("%6.2f\n", corr[i][len-1]);
}
}else{
printf(".... fail\n");
}
return corr;
}
#endif // #ifdef Analyzer_cxx

View File

@ -4,7 +4,7 @@ void listDraws(void) {
printf("-----------------------------------------------------\n");
printf(" rawEvID() - Raw e vs ID\n");
printf(" drawE() - Raw e for all %d detectors\n", NCLOVER);
printf(" drawGG() - Gamma - Gamma Coincident for all %d detectors\n", NCLOVER);
//printf(" drawGG() - Gamma - Gamma Coincident for all %d detectors\n", NCLOVER);
printf("-----------------------------------------------------\n");
}
@ -32,25 +32,15 @@ void drawE(bool isLogy = false, bool cali = false){
TCanvas *cRawE = (TCanvas *) gROOT->FindObjectAny("cRawE");
if( cRawE == NULL ) cRawE = new TCanvas("cRawE", cali ? "Cal e" : "Raw e", size * numCol, size * nCrystal);
cRawE->Clear();cRawE->Divide(numCol, 4);
//cRawE->SetRightMargin(0);
//cRawE->SetLeftMargin(0);
//cRawE->SetTopMargin(0);
//cRawE->SetBottomMargin(0);
//cRawE->SetTicks(1,1);
//cRawE->SetBorderMode(1);
cRawE->Clear();cRawE->Divide(numCol, 4, 0);
for (Int_t i = 0; i < nCrystal; i++) {
for( Int_t j = 0; j < numCol; j++){
int canvasID = numCol * i + j + 1;
cRawE->cd(canvasID);
cRawE->cd(canvasID)->SetGrid();
cRawE->cd(canvasID)->SetRightMargin(0.1);
//cRawE->cd(canvasID)->SetLeftMargin(0);
cRawE->cd(canvasID)->SetTopMargin(0);
//cRawE->cd(canvasID)->SetBottomMargin(0);
//cRawE->cd(canvasID)->SetBorderMode(1);
cRawE->cd(canvasID)->SetTickx(2);
cRawE->cd(canvasID)->SetTicky(2);
if( isLogy ) cRawE->cd(canvasID)->SetLogy();
int hID = nCrystal*j+ i;
if( cali ) {
@ -63,6 +53,7 @@ void drawE(bool isLogy = false, bool cali = false){
}
/**
void drawGG(){
int nCrystal = 4;
@ -81,4 +72,13 @@ void drawGG(){
}
}
}
*/
void energyCalibration(){
// TCanvas
}

View File

@ -1,3 +1,12 @@
/************************************************************
#
# Created by Tsz Leung (Ryan) Tang
# goluckyryan@gmail.com
# rtang@fsu.edu
#
*************************************************************/
#ifndef AutoFit_C
#define AutoFit_C
@ -8,7 +17,7 @@
#include <TMath.h>
#include <vector>
void ShowFitMethod(){
void showFitMethod(){
printf("----------------------- Method of Fitting ---------------\n");
printf("---------------------------------------------------------\n");
printf(" fitAuto() - estimate BG, find peak, and fit n-Gauss \n");

View File

@ -4,9 +4,16 @@ void ChainAnalysis(){
TChain * chain = new TChain("tree");
chain->Add("Dec15-07-00[0-9].root");
/******************/
//chain->Add("Dec15-07-00[0-9].root");
chain->Add("ti74pt7a-*.root");
/******************/
printf("\033[31m");
chain->GetListOfFiles()->Print();
printf("\033[m");
chain->Process("Analyzer.C+");

View File

@ -1,5 +1,9 @@
#1/bin/bash
DIR=$(pwd)
DATA_DIR=fsu_run_2021
sortTime=$DIR/$DATA_DIR/pxi-time-order
if [ $# -eq 0 ] || [ $1 == "-help" ]; then
echo "$./process_run [Run Folder] [Time Sort] [EventBuild] [Analysis]"
echo " Run Folder = the name of run folder"
@ -17,9 +21,6 @@ if [ $# -gt 1 ]; then TimeSort=$2; fi
EventBuild=1
if [ $# -gt 2 ]; then EventBuild=$3; fi
DIR=$(pwd)
DATA_DIR=fsu_run_2021
RED='\033[1;31m'
YELLOW='\033[1;33m'
ORANGE='\033[0;33m'
@ -34,6 +35,8 @@ cd $DATA_DIR/$RunFolder
fileList=$(ls *.evt)
numFile=$(ls -lhtr *.evt | wc -l)
count=0
cd $DIR
for a in $fileList
@ -47,21 +50,24 @@ do
if [ $TimeSort -eq 1 ]; then
evtDateTime=`stat -c "%Z" $DATA_DIR/$RunFolder/$a | sort -rn | head -1`
istoExist=`ls -1 $a.to | wc -l`
istoExist=`ls -1 $a.to 2> /dev/null | wc -l`
if [ ${istoExist} -gt 0 ]; then
echo "found $a.to"
echo "--- found $a.to"
toDateTime=`stat -c "%Z" $a.to | sort -rn | head -1`
if [ ${evtDateTime} -ge ${toDateTime} ]; then
$DIR/$DATA_DIR/pxi-time-order $a
$sortTime $DATA_DIR/$RunFolder/$a
else
echo "$a.to is generated after $a. skip."
fi
else
echo "cannot find $a.to, sort"
$sortTime $DATA_DIR/$RunFolder/$a
fi
elif [ $TimeSort -eq 0 ]; then
echo "skipped time sort by user."
else
echo "force Time sort"
$DATA_DIR/pxi-time-order $DATA_DIR/$RunFolder/$a
$sortTime $DATA_DIR/$RunFolder/$a
fi
@ -71,15 +77,18 @@ do
len=`echo $a | wc -c`
len=$(($len-5))
rootFile=${a:0:$len}".root"
isRootExist=`ls -1 $rootFile | wc -l`
isRootExist=`ls -1 $rootFile 2> /dev/null | wc -l`
if [ ${isRootExist} -gt 0 ]; then
echo "found $rootFile"
echo "--- found $rootFile"
rootDateTime=`stat -c "%Z" $rootFile | sort -rn | head -1`
if [ ${toDateTime} -ge ${rootDateTime} ]; then
$DATA_DIR/pixie2root $a.to
$DIR/pixie2root $a.to
else
echo "$rootFile is generated after $a.to skip."
fi
else
echo "cannot find $rootFile, build events"
$DIR/pixie2root $a.to
fi
elif [ $TimeSort -eq 0 ]; then
echo "skipped event build by user."
@ -92,4 +101,6 @@ done
fileList=$(ls *.root)
cd $DIR