Commit 81a4dfbc authored by Dominik Smith's avatar Dominik Smith
Browse files

CbmTaskBuildRawEvents: Implemented a simple seed finder which takes digi...

CbmTaskBuildRawEvents: Implemented a simple seed finder which takes digi timestamps from a given list of detectors and compiles them into a sorted list of seed times. Works as input for CbmAlgoBuildRawEvents.
parent db2b64f9
......@@ -20,6 +20,8 @@
#include "THttpServer.h"
#include <TFile.h>
#include <iomanip>
CbmTaskBuildRawEvents::CbmTaskBuildRawEvents() : FairTask("CbmTaskBuildRawEvents")
{
/// Create Algo. To be made generic/switchable when more event building algo are available!
......@@ -30,6 +32,35 @@ CbmTaskBuildRawEvents::~CbmTaskBuildRawEvents() {}
void CbmTaskBuildRawEvents::SetParContainers() {}
void CbmTaskBuildRawEvents::SetSeedTimeFiller(RawEventBuilderDetector seedDet)
{
if (fSeedTimeDetList.size() > 0) { LOG(fatal) << "Cannot use seed detector list and single instance together."; }
fSeedTimeDet = seedDet;
if (fSeedTimeDet != kRawEventBuilderDetUndef) {
if (fSeedTimes == nullptr) { fSeedTimes = new std::vector<Double_t>; }
}
else {
if (fSeedTimes != nullptr) {
fSeedTimes->clear();
delete fSeedTimes;
fSeedTimes = nullptr;
}
}
fpAlgo->SetSeedTimes(fSeedTimes);
}
void CbmTaskBuildRawEvents::AddSeedTimeFillerToList(RawEventBuilderDetector seedDet)
{
if (fSeedTimeDet != kRawEventBuilderDetUndef) {
LOG(fatal) << "Cannot use seed detector list and single instance together.";
}
if (fSeedTimes == nullptr) { fSeedTimes = new std::vector<Double_t>; }
fSeedTimeDetList.push_back(seedDet);
fpAlgo->SetSeedTimes(fSeedTimes);
}
InitStatus CbmTaskBuildRawEvents::Init()
{
/// Get a handle from the IO manager
......@@ -123,8 +154,12 @@ void CbmTaskBuildRawEvents::Exec(Option_t* /*option*/)
//as the digi manager can return -1, which would be casted to +1
//during comparison, leading to an error.
if (fSeedTimeDet != kRawEventBuilderDetUndef && fSeedTimeDetList.size() > 0) {
LOG(fatal) << "Cannot use seed detector list and single instance together.";
}
//Reset explicit seed times if set
if (fSeedTimeDet != kRawEventBuilderDetUndef) { fSeedTimes->clear(); }
if (fSeedTimeDet != kRawEventBuilderDetUndef || fSeedTimeDetList.size() > 0) { fSeedTimes->clear(); }
//Read STS digis
if (fDigiMan->IsPresent(ECbmModuleId::kSts)) {
......@@ -210,6 +245,9 @@ void CbmTaskBuildRawEvents::Exec(Option_t* /*option*/)
LOG(debug) << "In DigiManager: " << fPsdDigis->size() << " PSD digis.";
}
if (fSeedTimeDetList.size() > 0) { FillSeedTimesFromDetList(); }
//DumpSeedTimesFromDetList();
/// Call Algo ProcessTs method
fpAlgo->ProcessTs();
......@@ -218,6 +256,102 @@ void CbmTaskBuildRawEvents::Exec(Option_t* /*option*/)
LOG(debug2) << "CbmTaskBuildRawEvents::Exec => Done";
}
void CbmTaskBuildRawEvents::FillSeedTimesFromDetList()
{
std::map<ECbmModuleId, UInt_t> DigiNumbers;
std::map<ECbmModuleId, UInt_t> DigiCounters;
fSeedTimes->clear();
for (RawEventBuilderDetector& system : fSeedTimeDetList) {
DigiNumbers[system.detId] = GetNofDigis(system.detId);
DigiCounters[system.detId] = 0;
}
do {
ECbmModuleId nextAddedSystem;
Double_t earliestTime = -1;
for (RawEventBuilderDetector& system : fSeedTimeDetList) {
if (DigiCounters[system.detId] < DigiNumbers[system.detId]) {
Double_t thisTime = GetDigiTime(system.detId, DigiCounters[system.detId]);
if (thisTime < earliestTime || earliestTime == -1) {
nextAddedSystem = system.detId;
earliestTime = thisTime;
}
}
}
if (earliestTime != -1) {
fSeedTimes->push_back(earliestTime);
DigiCounters[nextAddedSystem]++;
}
else {
break;
}
} while (true);
}
void CbmTaskBuildRawEvents::DumpSeedTimesFromDetList()
{
std::ofstream timesUnsorted("digiTimesUnsorted.dat", std::ofstream::out);
timesUnsorted << std::setprecision(16);
for (RawEventBuilderDetector& system : fSeedTimeDetList) {
for (UInt_t i = 0; i < GetNofDigis(system.detId); i++) {
timesUnsorted << GetDigiTime(system.detId, i) << std::endl;
}
}
timesUnsorted.close();
LOG(info) << "Completed write of unsorted digi list.";
std::ofstream timesSorted("digiTimesSorted.dat", std::ofstream::out);
timesSorted << std::setprecision(16);
for (UInt_t i = 0; i < fSeedTimes->size(); i++) {
timesSorted << fSeedTimes->at(i) << std::endl;
}
timesSorted.close();
LOG(info) << "Completed DumpSeedTimesFromDetList(). Closing.";
exit(0); //terminate as this method should only be used for diagnostics
}
Double_t CbmTaskBuildRawEvents::GetDigiTime(ECbmModuleId _system, UInt_t _entry)
{
switch (_system) {
case ECbmModuleId::kMuch:
if (fbUseMuchBeamtimeDigi) { return (fMuchBeamTimeDigis->at(_entry)).GetTime(); }
else {
return (fMuchDigis->at(_entry)).GetTime();
}
case ECbmModuleId::kSts: return (fStsDigis->at(_entry)).GetTime();
case ECbmModuleId::kTrd: return (fTrdDigis->at(_entry)).GetTime();
case ECbmModuleId::kTof: return (fTofDigis->at(_entry)).GetTime();
case ECbmModuleId::kRich: return (fRichDigis->at(_entry)).GetTime();
case ECbmModuleId::kPsd: return (fPsdDigis->at(_entry)).GetTime();
case ECbmModuleId::kHodo: return (fT0Digis->at(_entry)).GetTime();
default: break;
}
return -1;
}
UInt_t CbmTaskBuildRawEvents::GetNofDigis(ECbmModuleId _system)
{
switch (_system) {
case ECbmModuleId::kMuch:
if (fbUseMuchBeamtimeDigi) { return fMuchBeamTimeDigis->size(); }
else {
return fMuchDigis->size();
}
case ECbmModuleId::kSts: return fStsDigis->size();
case ECbmModuleId::kTrd: return fTrdDigis->size();
case ECbmModuleId::kTof: return fTofDigis->size();
case ECbmModuleId::kRich: return fRichDigis->size();
case ECbmModuleId::kPsd: return fPsdDigis->size();
case ECbmModuleId::kHodo: return fT0Digis->size();
default: break;
}
return 0;
}
void CbmTaskBuildRawEvents::Finish()
{
/// Call Algo finish method
......
......@@ -114,27 +114,17 @@ public:
if (nullptr != fpAlgo) fpAlgo->ChangeMuchBeamtimeDigiFlag(bFlagIn);
fbUseMuchBeamtimeDigi = bFlagIn;
}
void SetSeedTimeFiller(RawEventBuilderDetector seedDet)
{
fSeedTimeDet = seedDet;
if (fSeedTimeDet != kRawEventBuilderDetUndef) {
if (fSeedTimes == nullptr) { fSeedTimes = new std::vector<Double_t>; }
}
else {
if (fSeedTimes != nullptr) {
fSeedTimes->clear();
delete fSeedTimes;
fSeedTimes = nullptr;
}
}
fpAlgo->SetSeedTimes(fSeedTimes);
}
void SetSeedTimeFiller(RawEventBuilderDetector seedDet);
void AddSeedTimeFillerToList(RawEventBuilderDetector seedDet);
void DumpSeedTimesFromDetList();
void SetSeedTimeWindow(Double_t beg, Double_t end) { fpAlgo->SetSeedTimeWindow(beg, end); }
private:
void FillOutput();
void SaveHistos();
Bool_t fbUseMuchBeamtimeDigi = kTRUE; //! Switch between MUCH digi classes
CbmDigiManager* fDigiMan = nullptr;
const std::vector<CbmTofDigi>* fT0Digis = nullptr;
std::vector<CbmMuchDigi>* fMuchDigis = nullptr;
......@@ -144,12 +134,15 @@ private:
std::vector<CbmTofDigi>* fTofDigis = nullptr;
std::vector<CbmRichDigi>* fRichDigis = nullptr;
std::vector<CbmPsdDigi>* fPsdDigis = nullptr;
std::vector<Double_t>* fSeedTimes = nullptr;
std::vector<Double_t>* fSeedTimes = nullptr;
std::vector<RawEventBuilderDetector> fSeedTimeDetList; //if multiple are desired
RawEventBuilderDetector fSeedTimeDet = kRawEventBuilderDetUndef; //single seed det
Bool_t fbUseMuchBeamtimeDigi = kTRUE; //! Switch between MUCH digi classes
Double_t GetDigiTime(ECbmModuleId _system, UInt_t _entry);
UInt_t GetNofDigis(ECbmModuleId _system);
RawEventBuilderDetector fSeedTimeDet = kRawEventBuilderDetUndef;
void FillSeedTimesFromDetList();
CbmAlgoBuildRawEvents* fpAlgo = nullptr;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment