From e1244f1026be5a7412063365263770b4e3fd7ee0 Mon Sep 17 00:00:00 2001 From: "carina@hades" Date: Tue, 3 Sep 2024 13:41:36 -0400 Subject: [PATCH] added analyzer.cpp --- .vscode/c_cpp_properties.json | 12 ++++ BinReader.h | 25 +++++-- analyzer.cpp | 125 ++++++++++++++++++++++++++++++++++ script.sh | 11 +++ test.C | 7 +- 5 files changed, 174 insertions(+), 6 deletions(-) create mode 100644 analyzer.cpp create mode 100755 script.sh diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index cca8d1b..fc24ff4 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -11,6 +11,18 @@ "cStandard": "c17", "cppStandard": "gnu++17", "intelliSenseMode": "linux-gcc-x64" + }, + { + "name": "Hades", + "includePath": [ + "${workspaceFolder}/**", + "/usr/local/cern/root_v6.26.06/**" + ], + "defines": [], + "compilerPath": "/usr/bin/gcc", + "cStandard": "c17", + "cppStandard": "gnu++17", + "intelliSenseMode": "linux-gcc-x64" } ], "version": 4 diff --git a/BinReader.h b/BinReader.h index d693a04..086ca06 100644 --- a/BinReader.h +++ b/BinReader.h @@ -49,7 +49,7 @@ struct Data{ }else{ printf("Energy : %5u, TimeStamp : %16lu ps\n", Energy, TimeStamp); } - printf(" Flag : 0x%X\n", Flags); + printf(" Flag : 0x%08X\n", Flags); if( (Header & 0x8 ) >= 1 ){ /// is waevform exist printf(" Wave form code : %d , nSample : %d\n", WaveformCode, NSample); for( int i = 0 ; i < NSample ; i++){ @@ -81,6 +81,7 @@ class BinReader{ Long64_t blockIDPrecent[10]; bool isHeaderOK; + bool isOldFormat; template int FillData(T * dataItem); // if successful, return 1, else 0; cannot fill Trace @@ -123,6 +124,7 @@ BinReader::BinReader(){ isOpened = false; isHeaderOK = false; + isOldFormat = false; } @@ -168,8 +170,17 @@ void BinReader::OpenFile(TString inFileName){ return; } ///printf("HEADER: 0x%X , 0x%X\n", data.Header, (data.Header >> 4)); + + if( (data.Header >> 4 ) == 0 ){ + printf(" Old format of CoMPASS, 0x%04x\n", data.Header); + isHeaderOK = true; + isOldFormat = true; + data.Header = 0xCAE5; // only with energy and energy short + return; + } + if( (data.Header >> 4 ) != 0xCAE ) { - printf(" Header format not right. \n"); + printf(" Header format not right. 0x%04x\n", data.Header); isHeaderOK = false; return ; } @@ -233,6 +244,11 @@ int BinReader::ReadBlock(int skipTrace){ if( (data.Header & 0x4 ) != 0 ) FillData(&data.Energy_short); FillData(&data.Flags); + + if( isOldFormat ) { + uint32_t dummy = 0; + FillData(&dummy); + } /// check is wave form exist if( (data.Header & 0x8) == 1){ @@ -279,10 +295,11 @@ void BinReader::ScanNumHit(){ printf("scan complete: number of data Block : %ld\n", numHit); rewind(inFile); ///back to the File begining - FillData(&data.Header); + if( !isOldFormat ){ + FillData(&data.Header); + } inFilePos = 0; hitID = -1; - endOfFile = false; } diff --git a/analyzer.cpp b/analyzer.cpp new file mode 100644 index 0000000..8665795 --- /dev/null +++ b/analyzer.cpp @@ -0,0 +1,125 @@ +#include "TFile.h" +#include "TTree.h" +#include "TTreeReader.h" +#include "TTreeReaderArray.h" +#include "TH2F.h" +#include "TStyle.h" +#include "TCanvas.h" +#include "TCutG.h" +#include "TChain.h" +#include +#include +#include + +#define NDET 16 + +TH1F * tDiff[NDET]; +TH1F * tDiffg[NDET]; +TH2F * PSD[NDET]; +TH2F * PSDg[NDET]; + +TH2F * eL_tDiff[NDET]; + +ushort eL[NDET]; +ushort eS[NDET]; + +const float timeResol = 2.0; //ns +const int timeRange[2] = {200, 800}; +const int timeBin = (timeRange[1] - timeRange[0])/timeResol; + +void analyzer(){ + + for( int i = 0; i < NDET; i++ ){ + + tDiff[i] = new TH1F(Form("Tdiff-%d", i), Form(" Detector %d", i), timeBin, timeRange[0], timeRange[1]); + + PSD[i] = new TH2F(Form("PSD-%d", i), Form(" Detector %d", i), 4096, 0, 30000,512,-1,1); + + eL_tDiff[i] = new TH2F(Form("E_tDiff-%d", i), Form(" Detector %d; TOF [ns]; eL", i), timeBin, timeRange[0], timeRange[1] ,1000, 0,15000); + + } + + TFile * file = new TFile("run268_3000.root"); + TTree * tree = (TTree *) file->Get("tree"); + + TTreeReader reader(tree); + + TTreeReaderValue evID = {reader, "evID"}; + TTreeReaderValue multi = {reader, "multi"}; + TTreeReaderArray sn = {reader, "sn"}; // serial no. + TTreeReaderArray ch = {reader, "ch"}; // channel + TTreeReaderArray e = {reader, "e"}; //long + TTreeReaderArray e2 = {reader, "e2"}; //short + TTreeReaderArray e_t = {reader, "e_t"}; // in ns + TTreeReaderArray e_f = {reader, "e_f"}; // in ps + + //^########################################################### + //^ * Process + //^########################################################### + + while(reader.Next()){ + + unsigned long long tRF = 0; + unsigned long long tN[NDET]; + for( int i =0; i < NDET; i++){ + tN[i] = 0; + eL[i] = 0; + eS[i] = 0; + } + + if( *multi > 2) continue; + + for( int i = 0; i < *multi; i++){ + + int bd = sn[i] - 6; // 6 = RF, 7 = Neutron detector + int ID = ch[i]; + + if( sn[i] == 6){ + tRF = e_t[i] * 1000 + e_f[i]; //in ps + }else{ + continue; + } + + eL[ID] = e[i]; + eS[ID] = e2[i]; + + tN[ID] = e_t[i] * 1000 + e_f[i]; //in ps + + } // end multiplicity for loop + + for( int i = 0; i < NDET; i++) { + if( tRF == 0 || tN[i] == 0 ) continue; + + double tdf; + + if( tRF > tN[i]){ + tdf = (tRF - tN[i])*1./1000.; + }else{ + tdf = (tN[i] - tRF)*(-1.)/1000.; + } + + //std::cout << "Finito" << std::endl; + + PSD[i]->Fill(eL[i],(eL[i]-eS[i])*1.0/eL[i]); + tDiff[i]->Fill( tdf ); + + } // end for loop over NDET + + } // end while(reader.Next()) + + + + gStyle->SetOptStat(11111111); + + TCanvas *canvas = new TCanvas("canvas", "anlayszer", 1000, 1000); + canvas->Divide(4,4); + + for( int i = 0 ; i < NDET; i++ ){ + + canvas->cd(i+1); + tDiff[i]->Draw(); + + } + +} // end script() + diff --git a/script.sh b/script.sh new file mode 100755 index 0000000..b1ca1d5 --- /dev/null +++ b/script.sh @@ -0,0 +1,11 @@ +#!/usr/bin/bash + + +./Bin2Root 3000 0 \ +run_268/CH0@V1725_324_Data_run_268.bin \ +run_268/CH1@V1725_324_Data_run_268.bin \ +run_268/CH2@V1725_324_Data_run_268.bin \ +run_268/CH3@V1725_324_Data_run_268.bin \ +run_268/CH4@V1725_324_Data_run_268.bin \ +run_268/CH5@V1725_324_Data_run_268.bin \ +run_268/CH0@V1730_89_Data_run_268.bin diff --git a/test.C b/test.C index 965ba8c..af8cfdc 100644 --- a/test.C +++ b/test.C @@ -17,7 +17,8 @@ TH1I * hChannel; TH1I * he[NChannel]; // BinReader * reader = new BinReader("/home/ryan/ExpData/fsu_testing/testing_014_single.bin"); -BinReader * reader = new BinReader("data/run_123/UNFILTERED/Data_CH9@V1725S_19555_run_123.BIN"); +// BinReader * reader = new BinReader("data/run_123/UNFILTERED/Data_CH9@V1725S_19555_run_123.BIN"); +BinReader * reader = new BinReader("run_268/CH0@V1725_324_Data_run_268.bin"); void test(){ @@ -34,9 +35,11 @@ void test(){ reader->data.Print(); count ++; + // if( count > 10 ) break; + }while( !reader->IsEndOfFile() ); - printf(">>>>>>>>>>>>>>. count : %ld\n", count); + printf(">>>>>>>>>>>>>>. count : %u\n", count); reader->PrintStatus(1); printf("\n\n\n");