#include "PndTorinoDetectorDigiTask.h" #include "PndTorinoDetectorPoint.h" #include "PndTorinoDetectorDigi.h" #include "FairHit.h" #include "FairRootManager.h" #include "TRandom.h" #include "TMath.h" #include using namespace std; // ----- Default constructor ------------------------------------------- PndTorinoDetectorDigiTask::PndTorinoDetectorDigiTask(): fTimeResolution(0.) { } // ------------------------------------------------------------------------- // ----- Destructor ---------------------------------------------------- PndTorinoDetectorDigiTask::~PndTorinoDetectorDigiTask() { } // ------------------------------------------------------------------------- // ----- Public method Init (abstract in base class) -------------------- InitStatus PndTorinoDetectorDigiTask::Init() { FairRootManager* ioman = FairRootManager::Instance(); if (!ioman) { std::cout << "-E- PndTorinoDetectorDigiTask::Init: " ///todo replace with logger! << "RootManager not instantiated!" << std::endl; return kFATAL; } fPointArray = (TClonesArray*) ioman->GetObject("PndTorinoDetectorPoint"); if (!fPointArray) { std::cout << "-W- PndTorinoDetectorDigiTask::Init: " << "No Point array!" << std::endl; return kERROR; } // Create and register output array fDigiArray = new TClonesArray("PndTorinoDetectorDigi"); ioman->Register("PndTorinoDetectorDigi", "PndTorinoDetector", fDigiArray, kTRUE); return kSUCCESS; } // ----- Public method Exec -------------------------------------------- void PndTorinoDetectorDigiTask::Exec(Option_t* opt) { fDigiArray->Delete(); // fill the map for(int ipnt = 0; ipnt < fPointArray->GetEntries(); ipnt++) { PndTorinoDetectorPoint* point = (PndTorinoDetectorPoint*) fPointArray->At(ipnt); if(!point) continue; Int_t xPad = CalcPad(point->GetX(), point->GetXOut()); Int_t yPad = CalcPad(point->GetY(), point->GetYOut()); Int_t zPad = CalcPad(point->GetZ(), point->GetZOut()); Double_t timestamp = CalcTimeStamp(point->GetTime()); PndTorinoDetectorDigi* digi = new ((*fDigiArray)[ipnt]) PndTorinoDetectorDigi(xPad, yPad, zPad, timestamp); if (fTimeResolution > 0){ digi->SetTimeStampError(fTimeResolution/TMath::Sqrt(fTimeResolution)); } else { digi->SetTimeStampError(0); } digi->SetLink(FairLink("PndTorinoDetectorPoint", ipnt)); } } // ------------------------------------------------------------------------- Int_t PndTorinoDetectorDigiTask::CalcPad(Double_t posIn, Double_t posOut) { Int_t result = (Int_t)(posIn + posOut)/2; return result; } // ------------------------------------------------------------------------- Double_t PndTorinoDetectorDigiTask::CalcTimeStamp(Double_t timeOfFlight) { Double_t eventTime = FairRootManager::Instance()->GetEventTime(); Double_t detectionTime = gRandom->Gaus(0, fTimeResolution); Double_t result = eventTime + timeOfFlight + detectionTime; if (result < 0) { return 0; } else { return result; } } ClassImp(PndTorinoDetectorDigiTask)