// --------------------------------------------------------------------------------- // ----- FairSttSource ----- // ----- Author: S.Costanza ----- // --------------------------------------------------------------------------------- #include "TList.h" #include "TObjString.h" #include "TTree.h" #include "TClonesArray.h" #include "TMatrixT.h" #include "TH1F.h" #include "TMath.h" #include "FairRootManager.h" #include "FairRunOnline.h" #include "FairRuntimeDb.h" #include "FairLogger.h" //Stt headers #include "FairSttSource.h" #include #include using namespace std; FairSttSource::FairSttSource() : FairMbsSource(), fCurrentFile(0), fFileNames(new TList()), fVerbose(0) { } FairSttSource::FairSttSource(const FairSttSource& source) : FairMbsSource(source), fCurrentFile(source.GetCurrentFile()), fFileNames(new TList()), fNHits(0), fTotNHits(0), fTotEvtNum(0) { } FairSttSource::~FairSttSource() { fFileNames->Delete(); delete fFileNames; } void FairSttSource::AddFile(TString fileName) { TObjString* str = new TObjString(fileName); fFileNames->Add(str); } Bool_t FairSttSource::Init() { if(! FairMbsSource::Init()) { return kFALSE; } if(fFileNames->GetSize() == 0) { return kFALSE; } TString name = ((TObjString*)fFileNames->At(fCurrentFile))->GetString(); fCurrentFile += 1; InFile = new TFile(name); return kTRUE; } Int_t FairSttSource::ReadEvent() { if (fVerbose>0) cout << "=== FairSttSource::ReadEvent --- hit # " << fTotNHits << ", ev num " << fTotEvtNum << endl; fTree = (TTree*) InFile->Get("STTpanda_FADC"); Int_t entries = fTree->GetEntriesFast(); if (fVerbose>0 && fTotEvtNum==0) cout << "Entries (total # of hits) = " << entries << endl; Int_t evNum = 0; // global event number Int_t layer = 0; // layer number Int_t tube = 0; // tube number Float_t raw_led = 0; // raw leading edge discriminator [ns] Float_t raw_zct = 0; // raw zero crossing time [ns] Float_t raw_cfd = 0; // raw constant fraction discriminator [ns] Float_t raw_ampl = 0; // raw pulse amplitude (first maximum) [bins - a.u.] Float_t raw_de = 0; // raw energy loss (pulse area) [bins - a.u.] Float_t fpga_led = 0; // fpga leading edge discriminator [ns] Float_t fpga_zct = 0; // fpga zero crossing time [ns] Float_t fpga_cfd = 0; // fpga constant fraction discriminator [ns] Float_t fpga_ampl = 0; // fpga pulse amplitude (first maximum) [bins - a.u.] Float_t fpga_de = 0; // fpga energy loss (pulse area) [bins - a.u.] // devo riempire quelle variabili! fTree->SetBranchAddress("globEvNum", &evNum); fTree->SetBranchAddress("fpl", &layer); fTree->SetBranchAddress("fel", &tube); fTree->SetBranchAddress("raw_led", &raw_led); fTree->SetBranchAddress("raw_zct", &raw_zct); fTree->SetBranchAddress("raw_cfd", &raw_cfd); fTree->SetBranchAddress("raw_ampl", &raw_ampl); fTree->SetBranchAddress("raw_de", &raw_de); fTree->SetBranchAddress("fpga_led", &fpga_led); fTree->SetBranchAddress("fpga_zct", &fpga_zct); fTree->SetBranchAddress("fpga_cfd", &fpga_cfd); fTree->SetBranchAddress("fpga_ampl", &fpga_ampl); fTree->SetBranchAddress("fpga_de", &fpga_de); Int_t event = 0; TMatrixT HitInfo; if (fTotNHits==entries) return 1; for (Int_t hitn = fTotNHits; hitn <= entries; hitn++) { if (hitn==entries) { if (fVerbose>0) cout << "Event " << fTotEvtNum << ", # hits: " << fNHits << "\t --> hit counter = " << hitn << endl; if (! Unpack(fNHits, HitInfo)) return 2; return 0; } fTree->GetEntry(hitn); if (evNum != event) { event = evNum; if (fNHits!=0) { if (fVerbose>0) cout << "Event " << fTotEvtNum << ", # hits: " << fNHits << "\t --> hit counter = " << hitn << endl; if (! Unpack(fNHits, HitInfo)) return 2; fTotEvtNum++; fNHits = 0; HitInfo.Clear(); return 0; } } if (evNum==event) { if (fVerbose>1) { cout << "Global event number is " << evNum << ", evt # " << fTotEvtNum << ", hit # " << fNHits << endl; if (fVerbose>2) { cout << "Plane number is " << layer << endl; cout << "Tube number is " << tube << endl; cout << "Raw led is " << raw_led << endl; cout << "Raw zct is " << raw_zct << endl; cout << "Raw cfd is " << raw_cfd << endl; cout << "Raw ampl is " << raw_ampl << endl; cout << "Raw de is " << raw_de << endl; cout << "Fpga led is " << fpga_led << endl; cout << "Fpga zct is " << fpga_zct << endl; cout << "Fpga cfd is " << fpga_cfd << endl; cout << "Fpga ampl is " << fpga_ampl << endl; cout << "Fpga de is " << fpga_de << endl; } } HitInfo.ResizeTo(fNHits+1,13); HitInfo[fNHits][0] = evNum; HitInfo[fNHits][1] = layer; HitInfo[fNHits][2] = tube; HitInfo[fNHits][3] = raw_led; HitInfo[fNHits][4] = raw_zct; HitInfo[fNHits][5] = raw_cfd; HitInfo[fNHits][6] = raw_ampl; HitInfo[fNHits][7] = raw_de; HitInfo[fNHits][8] = fpga_led; HitInfo[fNHits][9] = fpga_zct; HitInfo[fNHits][10] = fpga_cfd; HitInfo[fNHits][11] = fpga_ampl; HitInfo[fNHits][12] = fpga_de; fNHits++; fTotNHits++; } } return 0; } void FairSttSource::Close() { InFile->Close(); } ClassImp(FairSttSource)