From 0a262bf921ac52ea9c0d1f71cb21882c50eca183 Mon Sep 17 00:00:00 2001 From: splitPoleDAQ Date: Sat, 27 Jan 2024 00:10:17 -0500 Subject: [PATCH] change the ApplyMapping.C/h to Mapper.cpp, need compilation --- .gitignore | 4 +- ApplyMapping.C | 147 ----------------------------- ApplyMapping.h | 245 ------------------------------------------------- Makefile | 24 +++++ Mapper.cpp | 202 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 229 insertions(+), 393 deletions(-) delete mode 100644 ApplyMapping.C delete mode 100644 ApplyMapping.h create mode 100644 Makefile create mode 100644 Mapper.cpp diff --git a/.gitignore b/.gitignore index 04576a0..939ba91 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,6 @@ EventBuilder* *.d *.so *.pcm -*.root \ No newline at end of file +*.root + +Mapper \ No newline at end of file diff --git a/ApplyMapping.C b/ApplyMapping.C deleted file mode 100644 index b02c56a..0000000 --- a/ApplyMapping.C +++ /dev/null @@ -1,147 +0,0 @@ -#define ApplyMapping_cxx - -#include "ApplyMapping.h" -#include -#include -#include -#include - -#include -#include - - -void ApplyMapping::Begin(TTree * /*tree*/){ - - TString option = GetOption(); - - run = option.Atoi(); - -} - -void ApplyMapping::SlaveBegin(TTree * /*tree*/){ - - TString option = GetOption(); - -} - -Bool_t ApplyMapping::Process(Long64_t entry){ - - b_event_ID->GetEntry(entry); - b_multi->GetEntry(entry); - b_sn->GetEntry(entry); - b_ch->GetEntry(entry); - b_e->GetEntry(entry); - b_e_t->GetEntry(entry); - - eventID = evID; - - // printf("======================== %llu, %u\n", evID, multi); - - sx3.multi = 0; - qqq.multi = 0; - pc.multi = 0; - - for( unsigned int i = 0; i < multi; i++){ - - //printf("%10u/%10u| %5d, %2u, %6u, %14llu\n", i, multi, sn[i], ch[i], e[i], e_t[i] ); - int globalCh = ch[i]; - for( int j = 0; j < nBd; j++){ - if( board.at(j) == sn[i]){ - globalCh += sn[i] > 1000 ? j * 64 : 7*64 + (j-7) * 16; - } - } - unsigned short ID = mapping[globalCh]; - - //=================================== sx3 - if( ID < 10000 ) { - - sx3.id[sx3.multi] = ID / 100; - sx3.ch[sx3.multi] = ID % 100; - sx3.e[sx3.multi] = e[i]; - sx3.t[sx3.multi] = e_t[i]; - sx3.multi ++; - - } - - //=================================== qqq - if( 10000 <= ID && ID < 20000 ) { - - qqq.id[qqq.multi] = (ID - 10000) / 100; - qqq.ch[qqq.multi] = (ID - 10000) % 100; - qqq.e[qqq.multi] = e[i]; - qqq.t[qqq.multi] = e_t[i]; - - qqq.multi ++; - - } - - //=================================== pc - if( 20000 <= ID && ID < 30000 ) { - - pc.id[pc.multi] = (ID - 20000) / 100; - pc.ch[pc.multi] = (ID - 20000) % 100; - pc.e[pc.multi] = e[i]; - pc.t[pc.multi] = e_t[i]; - - pc.multi ++; - } - - } - - //if(entry == 0 ) sx3.Print(); - - /************************************************************************/ - saveFile->cd(); //set focus on this file - newTree->Fill(); - newTree->Write(); - - printf("%6lu/%6u [%2d%%]\n\033[A\r", eventID, totnumEntry, TMath::Nint((eventID+1)*100./totnumEntry)); - - // clock.Stop("timer"); - // Double_t time = clock.GetRealTime("timer"); - // clock.Start("timer"); - - // if ( !shown ) { - // if (fmod(time, 10) < 1 ){ - // printf( "%10lu[%2d%%]|%3.0f min %5.2f sec | expect:%5.2f min\n", - // eventID, - // TMath::Nint((eventID+1)*100./totnumEntry), - // TMath::Floor(time/60.), time - TMath::Floor(time/60.)*60., - // totnumEntry*time/(eventID+1.)/60.); - // shown = true; - // } - // }else{ - // if (fmod(time, 10) > 9 ){ - // shown = false; - // } - // } - - - return kTRUE; -} - -void ApplyMapping::SlaveTerminate(){ - -} - -void ApplyMapping::Terminate(){ - - // Double_t time = clock.GetRealTime("timer"); - - // printf( "%10lu[%2d%%]|%3.0f min %5.2f sec | expect:%5.2f min\n", - // eventID, - // TMath::Nint((eventID+1)*100./totnumEntry), - // TMath::Floor(time/60.), time - TMath::Floor(time/60.)*60., - // totnumEntry*time/(eventID+1.)/60.); - // shown = true; - - saveFile->cd(); //set focus on this file - newTree->Write(); - - UInt_t eventNumber = newTree->GetEntries(); - - saveFile->Close(); - - printf("-------------- done, saved in %s, %u\n", saveFileName.Data(), eventNumber); - -} diff --git a/ApplyMapping.h b/ApplyMapping.h deleted file mode 100644 index 9e356b9..0000000 --- a/ApplyMapping.h +++ /dev/null @@ -1,245 +0,0 @@ -////////////////////////////////////////////////////////// -// This class has been automatically generated on -// Mon Jan 22 14:02:44 2024 by ROOT version 6.26/04 -// from TTree tree/pulsertest_018_10000_noTrace.root -// found on file: pulsertest_018_10000_noTrace.root -////////////////////////////////////////////////////////// - -#ifndef ApplyMapping_h -#define ApplyMapping_h - -#include -#include -#include -#include -#include -#include - -#include "mapping.h" - -#define MAXMULTI 1000 -// Header file for the classes stored in the TTree if any. - -class Det{ - -public: - Det(): multi(0) {Clear(); } - - UShort_t multi; - UShort_t id[MAXMULTI]; - UShort_t ch[MAXMULTI]; - UShort_t e[MAXMULTI]; - ULong64_t t[MAXMULTI]; - - void Clear(){ - - multi = 0; - for( int i = 0; i < MAXMULTI; i++){ - id[i] = 0; - ch[i] = 0; - e[i] = 0; - t[i] = 0; - } - - } - - void Print(){ - printf("=============================== multi : %u\n", multi); - for( int i = 0; i < multi; i++) { - printf(" %3d | %2d-%2d %5u %llu \n", i, id[i], ch[i], e[i], t[i]); - } - } - -}; - -class ApplyMapping : public TSelector { -public : - TChain *fChain; //!pointer to the analyzed TTree or TChain - - // Fixed size dimensions of array or collections stored in the TTree if any. - - // Declaration of leaf types - ULong64_t evID; - UInt_t multi; - UShort_t sn[MAXMULTI]; //[multi] - UShort_t ch[MAXMULTI]; //[multi] - UShort_t e[MAXMULTI]; //[multi] - UShort_t e2[MAXMULTI]; //[multi] - ULong64_t e_t[MAXMULTI]; //[multi] - UShort_t e_f[MAXMULTI]; //[multi] - - // List of branches - TBranch *b_event_ID; //! - TBranch *b_multi; //! - TBranch *b_sn; //! - TBranch *b_ch; //! - TBranch *b_e; //! - TBranch *b_e2; //! - TBranch *b_e_t; //! - TBranch *b_e_f; //! - - ApplyMapping(TTree * /*tree*/ =0) : fChain(0) { } - virtual ~ApplyMapping() { } - virtual Int_t Version() const { return 2; } - virtual void Begin(TTree *tree); - virtual void SlaveBegin(TTree *tree); - virtual void Init(TTree *tree); - virtual Bool_t Notify(); - virtual Bool_t Process(Long64_t entry); - virtual Int_t GetEntry(Long64_t entry, Int_t getall = 0) { return fChain ? fChain->GetTree()->GetEntry(entry, getall) : 0; } - virtual void SetOption(const char *option) { fOption = option; } - virtual void SetObject(TObject *obj) { fObject = obj; } - virtual void SetInputList(TList *input) { fInput = input; } - virtual TList *GetOutputList() const { return fOutput; } - virtual void SlaveTerminate(); - virtual void Terminate(); - - void SetRunID(UInt_t runID) { run = runID; } - - ClassDef(ApplyMapping,0); - - - //=============================== - TFile * saveFile; - TTree * newTree; - TString saveFileName; - int totnumEntry; // of original root - - //tree - ULong_t eventID; - UInt_t run; - - Det sx3; - Det qqq; - Det pc ; - - //clock - TBenchmark clock; - Bool_t shown; - -}; - -#endif - -#ifdef ApplyMapping_cxx -void ApplyMapping::Init(TTree *tree){ - - if (!tree) return; - - //====================================== - totnumEntry = tree->GetEntries(); - printf( "===================================== \n"); - printf( "====== total Entry : %d \n", totnumEntry); - printf( "===================================== \n"); - - - fChain = (TChain *) tree; - fChain->SetMakeClass(1); - - fChain->SetBranchAddress("evID", &evID, &b_event_ID); - fChain->SetBranchAddress("multi", &multi, &b_multi); - fChain->SetBranchAddress("sn", sn, &b_sn); - fChain->SetBranchAddress("ch", ch, &b_ch); - fChain->SetBranchAddress("e", e, &b_e); - fChain->SetBranchAddress("e2", e2, &b_e2); - fChain->SetBranchAddress("e_t", e_t, &b_e_t); - fChain->SetBranchAddress("e_f", e_f, &b_e_f); - - PrintMapping(); - - //================= Formation of file name - // TString expName = ""; - - // fChain->GetListOfFiles()->Print(); - // int numFile = fChain->GetListOfFiles()->GetLast() + 1; - // if( numFile > 0 ) { - // int oldRunNum = -100; - // bool contFlag = false; // is runNumber continue; - // for( int i = 0; i < numFile ; i++){ - // TString name = fChain->GetListOfFiles()->At(i)->GetTitle(); - - // TString prefix = name; - - // int found = name.Last('/'); - // found = name.Index("_", found+1); // find next "_" - // name.Remove(0, found+1); - // name.Remove(3); // name should be only runID - // int runNum = name.Atoi(); // this should give the 3 digit run number - - // if( i == 0 ) { - // int found = prefix.Last('/'); - // prefix.Remove(0, found+1); - // found = name.Index("_"); - // prefix.Remove(0, found+1); // this should give the expName; - // expName = prefix; - // saveFileName = expName + "_" + prefix + "_run"; - // } - - // if( runNum == oldRunNum + 1 ){ - // int kk = saveFileName.Sizeof(); - // if( contFlag == false ){ - // saveFileName.Remove(kk-2); //remove the "-" - // saveFileName += "-"; - // }else{ - // saveFileName.Remove(kk-5); //remove the runNum and "-" - // } - // contFlag = true; - // } - // if( runNum > oldRunNum + 1) contFlag = false; - - // saveFileName += Form("%03d_", runNum); - // oldRunNum = runNum; - // } - // int kk = saveFileName.Sizeof(); - // saveFileName.Remove(kk-2); // remove the last "-" - // saveFileName += ".root"; - // }else{ - // saveFileName.Form("%s_default.root", expName.Data()); - // } - saveFileName = "test.root"; - - printf("save file name : %s \n", saveFileName.Data()); - printf("---------------------------------------------\n"); - if( saveFileName == ".root" ) gROOT->ProcessLine(".q"); - - saveFile = new TFile( saveFileName,"recreate"); - - //====================== Create tree - newTree = new TTree("tree","tree"); - - eventID = 0; - run = 0; - sx3.Clear(); - qqq.Clear(); - pc.Clear(); - - newTree->Branch("eventID",&eventID,"eventID/l"); - newTree->Branch("run", &run,"run/i"); - - newTree->Branch("sx3Multi", &sx3.multi, "sx3Multi/s"); - newTree->Branch("sx3ID", &sx3.id, "sx3ID[sx3Multi]/s"); - newTree->Branch("sx3Ch", &sx3.ch, "sx3Ch[sx3Multi]/s"); - newTree->Branch("sx3E", &sx3.e, "sx3Energy[sx3Multi]/s"); - newTree->Branch("sx3T", &sx3.t, "sx3Time[sx3Multi]/l"); - - newTree->Branch("qqqMulti", &qqq.multi, "qqqMulti/s"); - newTree->Branch("qqqID", &qqq.id, "qqqID[qqqMulti]/s"); - newTree->Branch("qqqCh", &qqq.ch, "qqqCh[qqqMulti]/s"); - newTree->Branch("qqqE", &qqq.e, "qqqEnergy[qqqMulti]/s"); - newTree->Branch("qqqT", &qqq.t, "qqqTime[qqqMulti]/l"); - - newTree->Branch("pcMulti", &pc.multi, "pcMulti/s"); - newTree->Branch("pcID", &pc.id, "pcID[pcMulti]/s"); - newTree->Branch("pcCh", &pc.ch, "pcCh[pcMulti]/s"); - newTree->Branch("pcE", &pc.e, "pcEnergy[pcMulti]/s"); - newTree->Branch("pcT", &pc.t, "pcTime[pcMulti]/l"); - - shown = false; -} - -Bool_t ApplyMapping::Notify(){ - - return kTRUE; -} - -#endif // #ifdef ApplyMapping_cxx diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..3427d34 --- /dev/null +++ b/Makefile @@ -0,0 +1,24 @@ +######################################################################## +# +# +######################################################################### + +CC = g++ + +#COPTS = -fPIC -DLINUX -O2 -std=c++17 -lpthread +COPTS = -fPIC -DLINUX -g -O0 -Wall -std=c++17 -lpthread + +ROOTLIBS = `root-config --cflags --glibs` + +ALL = Mapper + +######################################################################### + +all : $(ALL) + +clean : + /bin/rm -f $(OBJS) $(ALL) + +Mapper : Mapper.cpp mapping.h + @echo "--------- making Mapper" + $(CC) $(COPTS) -o Mapper Mapper.cpp $(ROOTLIBS) diff --git a/Mapper.cpp b/Mapper.cpp new file mode 100644 index 0000000..012a5ef --- /dev/null +++ b/Mapper.cpp @@ -0,0 +1,202 @@ + +#include +#include + +#include +#include +#include +#include +#include + +#include "mapping.h" + +#define MAXMULTI 1000 + +class Det{ +public: + Det(): multi(0) {Clear(); } + + UShort_t multi; + UShort_t id[MAXMULTI]; + UShort_t ch[MAXMULTI]; + UShort_t e[MAXMULTI]; + ULong64_t t[MAXMULTI]; + + void Clear(){ + multi = 0; + for( int i = 0; i < MAXMULTI; i++){ + id[i] = 0; + ch[i] = 0; + e[i] = 0; + t[i] = 0; + } + } + + void Print(){ + printf("=============================== multi : %u\n", multi); + for( int i = 0; i < multi; i++) { + printf(" %3d | %2d-%2d %5u %llu \n", i, id[i], ch[i], e[i], t[i]); + } + } +}; + +//=============================== +int main(int argc, char **argv){ + + printf("=========================================\n"); + printf("=== Mapper ===\n"); + printf("=========================================\n"); + if (argc != 2) { + printf("Incorrect number of arguments:\n"); + printf("%s [inFile]\n", argv[0]); + printf("\n\n"); + return 1; + } + + ///============= read input + std::string inFileName = argv[1]; + + PrintMapping(); + + + TFile * inFile = new TFile(inFileName.c_str(), "READ"); + TTree * tree = (TTree*) inFile->Get("tree"); + unsigned long long totnumEntry = tree->GetEntries(); + + ULong64_t evID; + UInt_t multi; + UShort_t sn[MAXMULTI]; + UShort_t ch[MAXMULTI]; + UShort_t e[MAXMULTI]; + UShort_t e2[MAXMULTI]; + ULong64_t e_t[MAXMULTI]; + UShort_t e_f[MAXMULTI]; + + tree->SetBranchAddress("evID", &evID); + tree->SetBranchAddress("multi", &multi); + tree->SetBranchAddress("sn", sn); + tree->SetBranchAddress("ch", ch); + tree->SetBranchAddress("e", e); + tree->SetBranchAddress("e2", e2); + tree->SetBranchAddress("e_t", e_t); + tree->SetBranchAddress("e_f", e_f); + + ///================== new tree + TString outFileName = inFileName; + TString runStr = outFileName; + int pos = outFileName.Last('/'); + pos = outFileName.Index("_", pos+1); // find next "_" + runStr.Remove(0, pos+1); + runStr.Remove(3); + pos = outFileName.Index("_", pos+1); // find next "_" + outFileName.Remove(pos); // remove the rest + outFileName += "_mapped.root"; + + ULong_t eventID; + UInt_t run = runStr.Atoi(); + + Det sx3; + Det qqq; + Det pc ; + + printf(" Raw root file : %s\n", inFileName.c_str()); + printf(" Run : %03d\n", run); + printf( " total Entry : %lld \n", totnumEntry); + printf(" Out file name : %s \n", outFileName.Data()); + + TFile * saveFile = new TFile( outFileName,"RECREATE"); + TTree * newTree = new TTree("tree","tree"); + + + newTree->Branch("evID", &eventID,"eventID/l"); + newTree->Branch("run", &run,"run/i"); + + newTree->Branch("sx3Multi", &sx3.multi, "sx3Multi/s"); + newTree->Branch("sx3ID", &sx3.id, "sx3ID[sx3Multi]/s"); + newTree->Branch("sx3Ch", &sx3.ch, "sx3Ch[sx3Multi]/s"); + newTree->Branch("sx3E", &sx3.e, "sx3Energy[sx3Multi]/s"); + newTree->Branch("sx3T", &sx3.t, "sx3Time[sx3Multi]/l"); + + newTree->Branch("qqqMulti", &qqq.multi, "qqqMulti/s"); + newTree->Branch("qqqID", &qqq.id, "qqqID[qqqMulti]/s"); + newTree->Branch("qqqCh", &qqq.ch, "qqqCh[qqqMulti]/s"); + newTree->Branch("qqqE", &qqq.e, "qqqEnergy[qqqMulti]/s"); + newTree->Branch("qqqT", &qqq.t, "qqqTime[qqqMulti]/l"); + + newTree->Branch("pcMulti", &pc.multi, "pcMulti/s"); + newTree->Branch("pcID", &pc.id, "pcID[pcMulti]/s"); + newTree->Branch("pcCh", &pc.ch, "pcCh[pcMulti]/s"); + newTree->Branch("pcE", &pc.e, "pcEnergy[pcMulti]/s"); + newTree->Branch("pcT", &pc.t, "pcTime[pcMulti]/l"); + + ///================== looping old tree and apply mapping + + //clock + // TBenchmark clock; + // Bool_t shown; + + for( unsigned long long ev = 0; ev < totnumEntry; ev++){ + tree->GetEntry(ev); + + eventID = evID; + sx3.multi = 0; + qqq.multi = 0; + pc.multi = 0; + + for( unsigned int i = 0; i < multi; i++){ + + //printf("%10u/%10u| %5d, %2u, %6u, %14llu\n", i, multi, sn[i], ch[i], e[i], e_t[i] ); + int globalCh = ch[i]; + for( int j = 0; j < nBd; j++){ + if( board.at(j) == sn[i]){ + globalCh += sn[i] > 1000 ? j * 64 : 7*64 + (j-7) * 16; + } + } + unsigned short ID = mapping[globalCh]; + + //=================================== sx3 + if( ID < 10000 ) { + sx3.id[sx3.multi] = ID / 100; + sx3.ch[sx3.multi] = ID % 100; + sx3.e[sx3.multi] = e[i]; + sx3.t[sx3.multi] = e_t[i]; + sx3.multi ++; + } + + //=================================== qqq + if( 10000 <= ID && ID < 20000 ) { + qqq.id[qqq.multi] = (ID - 10000) / 100; + qqq.ch[qqq.multi] = (ID - 10000) % 100; + qqq.e[qqq.multi] = e[i]; + qqq.t[qqq.multi] = e_t[i]; + qqq.multi ++; + } + + //=================================== pc + if( 20000 <= ID && ID < 30000 ) { + pc.id[pc.multi] = (ID - 20000) / 100; + pc.ch[pc.multi] = (ID - 20000) % 100; + pc.e[pc.multi] = e[i]; + pc.t[pc.multi] = e_t[i]; + pc.multi ++; + } + } + + saveFile->cd(); //set focus on this file + newTree->Fill(); + + if( eventID % 100 == 0 ) printf("%6lu/%6llu [%2d%%]\n\033[A\r", eventID, totnumEntry, TMath::Nint((eventID+1)*100./totnumEntry)); + + } + + inFile->Close(); + + saveFile->cd(); //set focus on this file + newTree->Write(); + UInt_t eventNumber = newTree->GetEntries(); + saveFile->Close(); + printf("-------------- done, %u\n", eventNumber); + + return 0; + +} \ No newline at end of file