added skip event in to2root

This commit is contained in:
Ryan Tang 2022-01-07 14:46:32 -05:00
parent 044ad47bd8
commit bd453a99e0
3 changed files with 257 additions and 114 deletions

View File

@ -34,6 +34,8 @@ TH2F * hcoin;
TH2F * hcrystalBGO;
TH1F * hTDiff;
///----- after calibration and BGO veto
TH2F * heCalVID;
TH1F * heCal[NCRYSTAL];
@ -58,6 +60,8 @@ void Analyzer::Begin(TTree * tree){
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]);
hTDiff = new TH1F("hTDiff", "data time different within an event; tick [10 ns]", 110, 0, 110);
heVID->SetNdivisions(-409, "X");
heCalVID->SetNdivisions(-409, "X");
@ -113,32 +117,39 @@ Bool_t Analyzer::Process(Long64_t entry){
for( int i = 0; i < NCRYSTAL; i++) eCal[i] = TMath::QuietNaN();
///printf("---------------------------- %d \n", multi);
///=========== Looping data for the event
for( int i = 0; i < multi ; i ++){
int id = detID[i];
///printf("%d %f %llu\n", id, e[i], e_t[i]);
//======== Fill raw data
if( detID[i] < 100 ){ /// gamma data
heVID->Fill( detID[i], e[i]);
he[detID[i]]->Fill(e[i]);
if( 0 <= id && id < NCRYSTAL ){ /// gamma data
heVID->Fill( id, e[i]);
he[id]->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( 100 <= detID[j] && detID[j] < 200 ) hcrystalBGO->Fill(id, detID[j]-100); /// crystal - BGO coincident
if( detID[j] < 100 ) hcoin->Fill(detID[i], detID[j]); /// crystal-crystal coincident
if( detID[j] < 100 ) hcoin->Fill(id, detID[j]); /// crystal-crystal coincident
}
}
if ( 100 < detID[i] && detID[i] < 200 ){ /// BGO data
if ( 100 < id && id < 200 ){ /// BGO data
}
if ( i > 0 ) hTDiff->Fill( e_t[i] - e_t[0]);
//======== BGO veto
bool dropflag = false;
if( detID[i] < 100 && multi > 1) {
if( id < NCRYSTAL && 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) {
if( detID[j] >= 100 && (detID[j]-100)*4 <= id && id < (detID[j]-100 +1)*4) {
dropflag = true;
break;
}
@ -146,27 +157,28 @@ Bool_t Analyzer::Process(Long64_t entry){
}
if( dropflag ) return kTRUE;
//========= 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( 0<= id && id < NCRYSTAL ) {
if( e_corr == "" ){
eCal[detID[i]] = e[i];
eCal[id] = e[i];
}else{
eCal[detID[i]] = eCorr[detID[i]][0] + eCorr[detID[i]][1] * e[i];
///========= 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);
}
}
heCalVID->Fill( detID[i], eCal[detID[i]]);
heCal[detID[i]]->Fill(eCal[detID[i]]);
heCalVID->Fill( id, eCal[id]);
heCal[id]->Fill(eCal[id]);
for ( int j = i + 1; j < multi; j++){
if( 100 <= detID[j] && detID[j] < 200 ) hcrystalBGO_G->Fill(detID[i], detID[j]-100); /// crystal - BGO coincident
if( 100 <= detID[j] && detID[j] < 200 ) hcrystalBGO_G->Fill(id, detID[j]-100); /// crystal - BGO coincident
}
}
}

View File

@ -31,8 +31,6 @@
#define RAWE_REBIN_FACTOR 2.0 // Rebin 32k pixie16 spectra to something smaller to fit better into 8k.
#define MAXMULTI 100
#include "../mapping.h"
/////////////////////
@ -80,27 +78,38 @@ int main(int argc, char **argv) {
printf("=====================================\n");
// Check that the corrent number of arguments were provided.
if (argc != 2 && argc != 3 ) {
if (argc != 2 && argc != 3 && argc != 4 && argc != 5) {
printf("Incorrect number of arguments:\n");
printf("%s [*.to File] [timeWindow] \n", argv[0]);
printf("%s [*.to File] <timeWindow> <fraction> <saveFile>\n", argv[0]);
printf(" timeWindow : number of tick, 1 tick = 10 ns. default = 100 \n");
printf(" fraction : 0 to 100, default 100, last fraction of evt.to to root \n");
printf(" e.g. 10, last 10%% of the evt.to to root \n");
printf(" saveFile : default is replace evt.to with root \n");
return 1;
}
//CERN ROOT things
TString inFileName = argv[1];
TString outFileName = inFileName;
int timeWindow = 100;
if( argc >= 3 ) timeWindow = atoi(argv[2]);
int frac = 100;
if( argc >= 4 ) frac = abs(atoi(argv[3]));
TString outFileName = inFileName;
outFileName.Remove(inFileName.First('.'));
outFileName.Append(".root");
int pos = inFileName.Last('/');
outFileName.Remove(0, pos+1);
if( argc >= 5) outFileName = argv[4];
printf(" in file : %s \n", inFileName.Data());
printf(" our file : %s \n", outFileName.Data());
printf(" our file : \033[1;31m%s\033[m\n", outFileName.Data());
printf(" max number of detector channal: %d \n", MAX_ID);
printf(" Skipping the frist \033[0;34m %d %% \033[m of data \n", 100 - frac);
printf("------------------------ Event building time window : %d tics = %d nsec \n", timeWindow, timeWindow*10);
TFile * outRootFile = new TFile(outFileName, "recreate");
@ -109,9 +118,9 @@ int main(int argc, char **argv) {
unsigned long long evID = 0;
int multi = 0;
int id[MAXMULTI] = {0};
double e[MAXMULTI] = {TMath::QuietNaN()};
unsigned long long e_t[MAXMULTI] = {0};
int id[MAX_ID] = {0};
double e[MAX_ID] = {TMath::QuietNaN()};
unsigned long long e_t[MAX_ID] = {0};
Int_t multiCry = 0 ; /// this is total multiplicity for all crystal
//unsigned short pileup[MAXMULTI];
@ -144,7 +153,7 @@ int main(int argc, char **argv) {
/////////////////////
// MAIN WHILE LOOP //
/////////////////////
while (1) { //main while loop
while (!feof(fpr)) { //main while loop
/////////////////////////////////
// UNPACK DATA AND EVENT BUILD //
@ -152,11 +161,17 @@ int main(int argc, char **argv) {
long long int etime = -1;
long long int tdif = -1;
int sevtmult=0;
while (1) { //get subevents and event build for one "event"
if (fread(sub, sizeof(int)*HEADER_LENGTH, 1, fpr) != 1) break;
fprpos = ftell(fpr);
if ( fprpos < fprsize * ( 1. - frac/100.) ) {
//printf("%ld / %ld \n", fprpos, fprsize);
data.elen = (sub[0] & 0x7FFE0000) >> 17;
fseek(fpr, sizeof(int)*(data.elen - HEADER_LENGTH), SEEK_CUR);
continue;
}
data.chn = sub[0] & 0xF; /// channel in digitizer
data.sln = (sub[0] & 0xF0) >> 4; /// digitizer ID
@ -204,12 +219,12 @@ int main(int argc, char **argv) {
pileUpCount++;
}
//more data than just the header; read entire sub event, first rewind, then read data.elen
fseek(fpr, -sizeof(int)*HEADER_LENGTH, SEEK_CUR);
//if (fread(sub, sizeof(int)*dataBlock[sevtmult].elen, 1, fpr) != 1) break;
if (fread(sub, sizeof(int)*data.elen, 1, fpr) != 1) break;
/**
//trace
k=0;
@ -269,7 +284,6 @@ int main(int argc, char **argv) {
dataCount, (int)((100*pileUpCount)/dataCount), evID+1, (float)dataCount/((float)evID+1), (100*fprpos/fprsize), tempf, TMath::Floor(time/60.), time - TMath::Floor(time/60.)*60.);
}
outRootFile->cd();
tree->Fill();

View File

@ -1,22 +1,32 @@
#!/bin/bash
DIR=$(pwd)
DATA_DIR=data
TIMEWINDOW=100
Method=1 #1 : evt -> evt.to -> root , 2 : evt -> _raw.root -> root
if [ $Method -eq 1 ]; then
DATA_DIR=.
else
DATA_DIR=data
fi
if [ $# -eq 0 ] || [ $1 == "-help" ]; then
echo "$./process_run [Run Folder] [Merge] [BuildEvents] [Analysis]"
echo "$./process_run [RunFile] [Merge] [BuildEvents] [Analysis]"
echo " Run Folder = the name of run folder"
echo " Merge = 1/0/-1 || 1 = merge, 0 = not merge, -1 = force merge "
echo " BuildEvents = 1/0/-1 || "
echo " BuildEvents = 1/0/-1 || if |x| > 1, take last x %, e.g. 10, last 10 %"
echo " Analysis = 1/0/-1 || "
echo ""
if [ $Method -eq 1 ]; then
ls -l --color $DATA_DIR/
fi
exit 1
fi;
RunFile=$1
RunFolder=$1
isMerge=1
@ -34,6 +44,115 @@ BLUE='\033[0;34m'
Cyan='\033[0;36m'
NC='\033[0m'
################################### method 1 evt -> evt.to -> root
if [ $Method -eq 1 ]; then
if [ -f $RunFile ]; then
echo -e "found evt files. "${RunFile}
else
echo -e "!!!!! cannot found evt files ${RunFile}. Abort."
exit
fi
pos=`expr index "${RunFile}" /`
temp=${RunFile:pos}
pos=`expr index "${temp}" /`
toFile=${temp:pos}".to"
pos=`expr index "${toFile}" .`
rootFile=${toFile:0:pos}"root"
#echo ${RunFile}
#echo ${toFile}
#echo ${rootFile}
echo -e "$RED>>> `date` >>>>>>>>>>>>>>>>>>>>>>> Time sort evt to evt.to $NC"
if [ $isMerge -eq 1 ]; then
if [ -f ${toFile} ]; then #_raw.root exist
#check evt DateTime
evtDateTime=`stat -c "%Z" ${RunFile} | sort -rn | head -1`
toDateTime=`stat -c "%Z" ${toFile} | sort -rn | head -1`
if [ $evtDateTime -gt $toDateTime ]; then #if evt file is newer
./armory/pxi-time-order ${RunFile}
echo -e "$RED>>> `date` >>>>>>>>>>>>>>>>>>>>>>> Time sort finished$NC"
else
echo "there is no newer evt files"
fi
else
./armory/pxi-time-order ${RunFile}
echo -e "$RED>>> `date` >>>>>>>>>>>>>>>>>>>>>>> Time sort finished$NC"
fi
fi
if [ $isMerge -eq 0 ]; then
echo -e "$YELLOW skipped by user $NC"
fi
if [ $isMerge -eq -1 ]; then
echo -e "$YELLOW forced by user $NC"
./armory/pxi-time-order ${RunFile}
echo -e "$RED>>> `date` >>>>>>>>>>>>>>>>>>>>>>> Time sort finished$NC"
fi
echo -e "$RED>>> `date` >>>>>>>>>>>>>>>>>>>>>>> Build Events $NC"
if [ ${isBuildEvents} -ge 1 ]; then
if [ -f ${rootFolder} ]; then # root exist
toDateTime=`stat -c "%Z" ${toFolder} | sort -rn | head -1`
rootDateTime=`stat -c "%Z" ${rootFolder} | sort -rn | head -1`
if [ ${toDateTime} -gt ${rootDateTime} ]; then
if [ ${isBuildEvents} -gt 1 ]; then
./armory/to2root ${toFile} $TIMEWINDOW ${isBuildEvents}
else
./armory/to2root ${toFile} $TIMEWINDOW
fi
echo -e "$RED>>> `date` >>>>>>>>>>>>>>>>>>>>>>> Build Events finsihed.$NC"
else
echo -e "${rootFile} is up-to-date."
fi
else
./armory/to2root ${toFile} $TIMEWINDOW
echo -e "$RED>>> `date` >>>>>>>>>>>>>>>>>>>>>>> Build Events finsihed.$NC"
fi
fi
if [ ${isBuildEvents} -eq 0 ]; then
echo -e "$YELLOW skipped by user $NC"
fi
if [ ${isBuildEvents} -le -1 ]; then
echo -e "$YELLOW forced by user $NC"
if [ ${isBuildEvents} -lt 1 ]; then
./armory/to2root ${toFile} $TIMEWINDOW ${isBuildEvents}
else
./armory/to2root ${toFile} $TIMEWINDOW
fi
echo -e "$RED>>> `date` >>>>>>>>>>>>>>>>>>>>>>> Build Events finsihed.$NC"
fi
echo -e "$RED>>> `date` >>>>>>>>>>>>>>>>>>>>>>> Analysis $NC"
if [ ${isAnalysis} -eq 1 ]; then
root -l "process_run.c(\"${rootFile}\")"
fi
if [ ${isAnalysis} -eq 0 ]; then
echo -e "$YELLOW skipped by user $NC"
fi
if [ ${isAnalysis} -eq -1 ]; then
echo -e "$YELLOW forced by user $NC"
root -l "process_run.c(\"${rootFile}\")"
fi
fi
################################### method 2 evt -> _raw.root -> root
if [ $Method -eq 2 ]; then
if [ -f $DATA_DIR/$RunFolder/*.evt ]; then
echo -e "found evt files."
else
@ -42,7 +161,6 @@ else
fi
echo -e "$RED>>> `date` >>>>>>>>>>>>>>>>>>>>>>> Merge evt files to ${RunFolder}_raw.root $NC"
if [ $isMerge -eq 1 ]; then
# check is ${RunFolder}"_raw.root" exist
if [ -f ${RunFolder}_raw.root ]; then #_raw.root exist
@ -54,11 +172,8 @@ if [ $isMerge -eq 1 ]; then
else
echo "there is no newer evt files"
fi
else
./armory/MergeEVT ${RunFolder}"_raw.root" `ls ${DATA_DIR}/${RunFolder}/*.evt`
fi
fi
@ -75,7 +190,6 @@ echo -e "$RED>>> `date` >>>>>>>>>>>>>>>>>>>>>>> Merge finished$NC"
echo -e "$RED>>> `date` >>>>>>>>>>>>>>>>>>>>>>> Build Events$NC"
if [ ${isBuildEvents} -eq 1 ]; then
if [ -f ${RunFolder}.root ]; then # root exist
rawRootDateTime=`stat -c "%Z" ${RunFolder}"_raw.root" | sort -rn | head -1`
rootDateTime=`stat -c "%Z" ${RunFolder}".root" | sort -rn | head -1`
@ -88,7 +202,6 @@ if [ ${isBuildEvents} -eq 1 ]; then
else
./armory/EventBuilder ${RunFolder}"_raw.root" $TIMEWINDOW
fi
fi
if [ ${isBuildEvents} -eq 0 ]; then
@ -116,3 +229,7 @@ if [ ${isAnalysis} -eq -1 ]; then
root -l "process_run.c(\"${RunFolder}.root\")"
fi
fi