Commit bedae5cb authored by Pierre-Alain Loizeau's avatar Pierre-Alain Loizeau
Browse files

[Evt Builder] Restore and expand support for T0 digis in TOF vector

- Change masking in Algo from full address to detector type
- Due to this, introduce in Algo implementation file a templated function to get the type if TofDigi or 0 instead
- Add support for using T0 as reference even if stored in TOF data (only in Algo, not in Task!)
- Add support for using T0 as trigger check detector even if stored in TOF data (only in Algo, not in Task!)
- Replace hard-coded constant in Algo with members + setters in both Algo and Task
parent 9f13a7c8
......@@ -33,6 +33,18 @@
template<>
void CbmAlgoBuildRawEvents::LoopOnSeeds<Double_t>();
template<class Digi>
uint32_t GetTofDetType(Digi* /*pDigi*/)
{
return 0;
}
uint32_t GetTofDetType(CbmTofDigi* pDigi)
{
/// Used only if TOF digi, otherwise template with 0 return is called
return CbmTofAddress::GetSmType(pDigi->GetAddress());
}
Bool_t CbmAlgoBuildRawEvents::InitAlgo()
{
LOG(info) << "CbmAlgoBuildRawEvents::InitAlgo => Starting sequence";
......@@ -271,13 +283,38 @@ template<class DigiSeed>
void CbmAlgoBuildRawEvents::LoopOnSeeds()
{
if (ECbmModuleId::kT0 == fRefDet.detId) {
const UInt_t uNbRefDigis = fT0DigiVec->size();
/// Loop on size of vector
for (UInt_t uDigi = 0; uDigi < uNbRefDigis; ++uDigi) {
LOG(debug) << Form("Checking seed %6u / %6u", uDigi, uNbRefDigis);
Double_t dTime = fT0DigiVec->at(uDigi).GetTime();
/// Check Seed and build event if needed
CheckSeed(dTime, uDigi);
if (0 == fuDetTypeT0) {
const UInt_t uNbRefDigis = fT0DigiVec->size();
/// Loop on size of vector
for (UInt_t uDigi = 0; uDigi < uNbRefDigis; ++uDigi) {
LOG(debug) << Form("Checking seed %6u / %6u", uDigi, uNbRefDigis);
Double_t dTime = fT0DigiVec->at(uDigi).GetTime();
/// Check Seed and build event if needed
CheckSeed(dTime, uDigi);
}
}
else {
// filter T0 digis from Tof (remove this block if T0 properly implemented)
const UInt_t uNbRefDigis = GetNofDigis(ECbmModuleId::kTof);
/// Loop on size of vector
for (UInt_t uDigi = 0; uDigi < uNbRefDigis; ++uDigi) {
LOG(debug) << Form("Checking seed %6u / %6u", uDigi, uNbRefDigis);
const DigiSeed* pDigi = GetDigi<DigiSeed>(uDigi);
// filter T0 digis from Tof
if (GetTofDetType(pDigi) != fuDetTypeT0) { continue; }
const Double_t dTime = pDigi->GetTime();
/// Check if seed in acceptance window
if (dTime < fdSeedWindowBeg) { continue; }
else if (fdSeedWindowEnd < dTime) {
break;
}
/// Check Seed and build event if needed
CheckSeed(dTime, uDigi);
}
}
}
else {
......@@ -289,7 +326,7 @@ void CbmAlgoBuildRawEvents::LoopOnSeeds()
const DigiSeed* pDigi = GetDigi<DigiSeed>(uDigi);
// filter T0 digis from Tof (remove this line if T0 properly implemented)
if (fRefDet.detId == ECbmModuleId::kTof && pDigi->GetAddress() == fuT0Address) { continue; }
if (fRefDet.detId == ECbmModuleId::kTof && 0 != fuDetTypeT0 && GetTofDetType(pDigi) == fuDetTypeT0) { continue; }
const Double_t dTime = pDigi->GetTime();
......@@ -359,7 +396,14 @@ void CbmAlgoBuildRawEvents::CheckSeed(Double_t dSeedTime, UInt_t uSeedDigiIdx)
if (fRefDet.fdTimeWinBeg < fRefDet.fdTimeWinEnd) {
SearchMatches(dSeedTime, fRefDet);
/// Also add the seed if the window starts after the seed
if (0 < fRefDet.fdTimeWinBeg) AddDigiToEvent(fRefDet, uSeedDigiIdx);
if (0 < fRefDet.fdTimeWinBeg) {
if (ECbmModuleId::kT0 == fRefDet.detId && 0 != fuDetTypeT0) {
AddDigiToEvent(kRawEventBuilderDetTof, uSeedDigiIdx);
}
else {
AddDigiToEvent(fRefDet, uSeedDigiIdx);
}
}
}
else {
AddDigiToEvent(fRefDet, uSeedDigiIdx);
......@@ -468,30 +512,62 @@ void CbmAlgoBuildRawEvents::SearchMatches(Double_t dSeedTime, RawEventBuilderDet
/// Check the Digis until out of window
if (ECbmModuleId::kT0 == detMatch.detId) {
/// Loop on size of vector
const UInt_t uNbSelDigis = fT0DigiVec->size();
for (UInt_t uDigi = detMatch.fuStartIndex; uDigi < uNbSelDigis; ++uDigi) {
const Double_t dTime = fT0DigiVec->at(uDigi).GetTime();
const Double_t dTimeDiff = dTime - dSeedTime;
/// Check if within time window, update start/stop indices if needed
if (dTimeDiff < detMatch.fdTimeWinBeg) {
++uLocalIndexStart;
continue;
if (0 == fuDetTypeT0) {
/// Loop on size of vector
const UInt_t uNbSelDigis = fT0DigiVec->size();
for (UInt_t uDigi = detMatch.fuStartIndex; uDigi < uNbSelDigis; ++uDigi) {
const Double_t dTime = fT0DigiVec->at(uDigi).GetTime();
const Double_t dTimeDiff = dTime - dSeedTime;
/// Check if within time window, update start/stop indices if needed
if (dTimeDiff < detMatch.fdTimeWinBeg) {
++uLocalIndexStart;
continue;
}
else if (detMatch.fdTimeWinEnd < dTimeDiff) {
/// Store as end the first digi out of window to avoid double counting in case of
/// merged overlap event mode
uLocalIndexEnd = uDigi;
break;
}
AddDigiToEvent(detMatch, uDigi);
if (fdPrevEvtEndTime < dTime) fdPrevEvtEndTime = dTime;
}
else if (detMatch.fdTimeWinEnd < dTimeDiff) {
/// Store as end the first digi out of window to avoid double counting in case of
/// merged overlap event mode
uLocalIndexEnd = uDigi;
break;
/// catch the case where we reach the end of the vector before being out of the time window
if (uLocalIndexEnd < uLocalIndexStart) uLocalIndexEnd = uNbSelDigis;
}
else {
// filter T0 digis from Tof (remove this block if T0 properly implemented)
const UInt_t uNbSelDigis = GetNofDigis(ECbmModuleId::kTof);
/// Loop on size of vector
for (UInt_t uDigi = detMatch.fuStartIndex; uDigi < uNbSelDigis; ++uDigi) {
const DigiCheck* pDigi = GetDigi<DigiCheck>(uDigi);
// filter T0 digis from Tof
if (GetTofDetType(pDigi) != fuDetTypeT0) { continue; }
const Double_t dTime = pDigi->GetTime();
const Double_t dTimeDiff = dTime - dSeedTime;
LOG(debug4) << detMatch.sName << Form(" => Checking match %6u / %6u, dt %f", uDigi, uNbSelDigis, dTimeDiff);
/// Check if within time window, update start/stop indices if needed
if (dTimeDiff < detMatch.fdTimeWinBeg) {
++uLocalIndexStart;
continue;
}
else if (detMatch.fdTimeWinEnd < dTimeDiff) {
/// Store as end the first digi out of window to avoid double counting in case of
/// merged overlap event mode
uLocalIndexEnd = uDigi;
break;
}
AddDigiToEvent(kRawEventBuilderDetTof, uDigi);
if (fdPrevEvtEndTime < dTime) fdPrevEvtEndTime = dTime;
}
AddDigiToEvent(detMatch, uDigi);
if (fdPrevEvtEndTime < dTime) fdPrevEvtEndTime = dTime;
/// catch the case where we reach the end of the vector before being out of the time window
if (uLocalIndexEnd < uLocalIndexStart) uLocalIndexEnd = uNbSelDigis;
}
/// catch the case where we reach the end of the vector before being out of the time window
if (uLocalIndexEnd < uLocalIndexStart) uLocalIndexEnd = uNbSelDigis;
}
else {
const UInt_t uNbSelDigis = GetNofDigis(detMatch.detId);
......@@ -514,7 +590,7 @@ void CbmAlgoBuildRawEvents::SearchMatches(Double_t dSeedTime, RawEventBuilderDet
}
// filter T0 digis from Tof (remove this line if T0 properly implemented)
//if (detMatch.detId == ECbmModuleId::kTof && pDigi->GetAddress() == fuT0Address) { continue; }
if (detMatch.detId == ECbmModuleId::kTof && 0 != fuDetTypeT0 && GetTofDetType(pDigi) == fuDetTypeT0) { continue; }
const Double_t dTime = pDigi->GetTime();
const Double_t dTimeDiff = dTime - dSeedTime;
......@@ -543,7 +619,7 @@ void CbmAlgoBuildRawEvents::SearchMatches(Double_t dSeedTime, RawEventBuilderDet
detMatch.fuEndIndex = uLocalIndexEnd;
}
void CbmAlgoBuildRawEvents::AddDigiToEvent(RawEventBuilderDetector& det, Int_t _entry)
void CbmAlgoBuildRawEvents::AddDigiToEvent(const RawEventBuilderDetector& det, Int_t _entry)
{
fCurrentEvent->AddData(det.dataType, _entry);
}
......@@ -586,7 +662,7 @@ Bool_t CbmAlgoBuildRawEvents::HasTrigger(CbmEvent* event)
return kTRUE;
}
Bool_t CbmAlgoBuildRawEvents::CheckTriggerConditions(CbmEvent* event, RawEventBuilderDetector& det)
Bool_t CbmAlgoBuildRawEvents::CheckTriggerConditions(CbmEvent* event, const RawEventBuilderDetector& det)
{
/// Check if both Trigger conditions disabled for this detector
if (0 == det.fuTriggerMinDigis && det.fiTriggerMaxDigis < 0) { return kTRUE; }
......@@ -600,7 +676,21 @@ Bool_t CbmAlgoBuildRawEvents::CheckTriggerConditions(CbmEvent* event, RawEventBu
}
/// Check trigger rejection by minimal number or absence
const Int_t iNbDigis = event->GetNofData(det.dataType);
int32_t iNbDigis = event->GetNofData(det.dataType);
if (ECbmModuleId::kT0 == det.detId && 0 != fuDetTypeT0) {
// filter T0 digis from Tof (remove this block if T0 properly implemented)
iNbDigis = 0;
int32_t uNbSelDigisTofT0 = event->GetNofData(kRawEventBuilderDetTof.dataType);
/// Loop on size of vector
for (int32_t iDigi = 0; iDigi < uNbSelDigisTofT0; ++iDigi) {
uint idx = event->GetIndex(kRawEventBuilderDetTof.dataType, iDigi);
const CbmTofDigi* pDigi = GetDigi<CbmTofDigi>(idx);
if (nullptr == pDigi) continue;
// filter T0 digis from Tof
if (GetTofDetType(pDigi) == fuDetTypeT0) { iNbDigis++; }
}
}
if ((-1 == iNbDigis) || (static_cast<UInt_t>(iNbDigis) < det.fuTriggerMinDigis)) {
LOG(debug2) << "Event does not have enough digis: " << iNbDigis << " vs " << det.fuTriggerMinDigis << " for "
<< det.sName;
......@@ -663,14 +753,14 @@ Bool_t CbmAlgoBuildRawEvents::CheckTriggerConditions(CbmEvent* event, RawEventBu
break;
}
case ECbmModuleId::kMuch: {
LOG(fatal) << "CbmAlgoBuildRawEvents::CheckDataAvailable => Fired detectors check not implemented yet for "
LOG(fatal) << "CbmAlgoBuildRawEvents::CheckTriggerConditions => Fired detectors check not implemented yet for "
<< det.sName;
return kFALSE;
break;
}
case ECbmModuleId::kTrd2d: // Same data storage as trd 1d
case ECbmModuleId::kTrd: {
LOG(fatal) << "CbmAlgoBuildRawEvents::CheckDataAvailable => Fired detectors check not implemented yet for "
LOG(fatal) << "CbmAlgoBuildRawEvents::CheckTriggerConditions => Fired detectors check not implemented yet for "
<< det.sName;
return kFALSE;
break;
......@@ -717,25 +807,25 @@ Bool_t CbmAlgoBuildRawEvents::CheckTriggerConditions(CbmEvent* event, RawEventBu
break;
}
case ECbmModuleId::kRich: {
LOG(fatal) << "CbmAlgoBuildRawEvents::CheckDataAvailable => Fired detectors check not implemented yet for "
LOG(fatal) << "CbmAlgoBuildRawEvents::CheckTriggerConditions => Fired detectors check not implemented yet for "
<< det.sName;
return kFALSE;
break;
}
case ECbmModuleId::kPsd: {
LOG(fatal) << "CbmAlgoBuildRawEvents::CheckDataAvailable => Fired detectors check not implemented yet for "
LOG(fatal) << "CbmAlgoBuildRawEvents::CheckTriggerConditions => Fired detectors check not implemented yet for "
<< det.sName;
return kFALSE;
break;
}
case ECbmModuleId::kT0: {
LOG(fatal) << "CbmAlgoBuildRawEvents::CheckDataAvailable => Fired detectors check not implemented yet for "
LOG(fatal) << "CbmAlgoBuildRawEvents::CheckTriggerConditions => Fired detectors check not implemented yet for "
<< det.sName;
return kFALSE;
break;
}
default: {
LOG(fatal) << "CbmAlgoBuildRawEvents::CheckDataAvailable => Fired detectors check not implemented yet for "
LOG(fatal) << "CbmAlgoBuildRawEvents::CheckTriggerConditions => Fired detectors check not implemented yet for "
<< det.sName;
return kFALSE;
break;
......@@ -749,7 +839,7 @@ Bool_t CbmAlgoBuildRawEvents::CheckTriggerConditions(CbmEvent* event, RawEventBu
//----------------------------------------------------------------------
Bool_t CbmAlgoBuildRawEvents::CheckDataAvailable(RawEventBuilderDetector& det)
Bool_t CbmAlgoBuildRawEvents::CheckDataAvailable(const RawEventBuilderDetector& det)
{
if (!CheckDataAvailable(det.detId)) {
LOG(info) << "No " << det.sName << " digi input found.";
......@@ -784,7 +874,9 @@ bool CbmAlgoBuildRawEvents::CheckDataAvailable(ECbmModuleId detId)
return fPsdDigis != nullptr;
}
case ECbmModuleId::kT0: {
return fT0DigiVec != nullptr;
if (0 != fuDetTypeT0) return fTofDigis != nullptr;
else
return fT0DigiVec != nullptr;
}
default: {
LOG(fatal) << "CbmAlgoBuildRawEvents::CheckDataAvailable => "
......@@ -820,7 +912,9 @@ UInt_t CbmAlgoBuildRawEvents::GetNofDigis(ECbmModuleId detId)
return fPsdDigis->size();
}
case ECbmModuleId::kT0: {
return fT0DigiVec->size(); //what to do here? Not in digi manager.
if (0 != fuDetTypeT0) return fTofDigis->size();
else
return fT0DigiVec->size(); //what to do here? Not in digi manager.
}
default: {
LOG(fatal) << "CbmAlgoBuildRawEvents::GetNofDigis => "
......
......@@ -113,8 +113,6 @@ static const RawEventBuilderDetector kRawEventBuilderDetUndef = RawEventBuilderD
class CbmAlgoBuildRawEvents {
public:
const static uint32_t fuT0Address = 10246;
/** Default constructor **/
CbmAlgoBuildRawEvents() = default;
......@@ -177,6 +175,8 @@ public:
void ChangeMuchBeamtimeDigiFlag(Bool_t bFlagIn = kFALSE) { fbUseMuchBeamtimeDigi = bFlagIn; }
void SetT0InTofDetType(uint32_t uTypeIn = 5) { fuDetTypeT0 = uTypeIn; }
/// For monitor algos
void AddHistoToVector(TNamed* pointer, std::string sFolder = "")
{
......@@ -224,7 +224,7 @@ public:
private:
/// Internal methods
Bool_t CheckDataAvailable(RawEventBuilderDetector& det);
Bool_t CheckDataAvailable(const RawEventBuilderDetector& det);
void InitTs();
void InitSeedWindow();
void BuildEvents();
......@@ -241,9 +241,9 @@ private:
template<class DigiCheck>
void SearchMatches(Double_t dSeedTime, RawEventBuilderDetector& detMatch);
void SearchMatches(Double_t dSeedTime, RawEventBuilderDetector& detMatch);
void AddDigiToEvent(RawEventBuilderDetector& det, Int_t uIdx);
void AddDigiToEvent(const RawEventBuilderDetector& det, Int_t uIdx);
Bool_t HasTrigger(CbmEvent*);
Bool_t CheckTriggerConditions(CbmEvent* event, RawEventBuilderDetector& det);
Bool_t CheckTriggerConditions(CbmEvent* event, const RawEventBuilderDetector& det);
void UpdateTimeWinBoundariesExtrema();
void UpdateWidestTimeWinRange();
......@@ -261,8 +261,10 @@ private:
Bool_t fbUseMuchBeamtimeDigi = kTRUE; //! Switch between MUCH digi classes
Bool_t fbGetTimings = kFALSE; //! Measure CPU time using stopwatch
Bool_t fbUseTsMetaData = kTRUE; //! Read Ts Parameters from input tree
/// Event building mode and detectors selection
/// Event building mode and detectors selection
EOverlapModeRaw fOverMode {EOverlapModeRaw::AllowOverlap};
/// for filtering T0 digis from Tof (remove this line if T0 properly implemented)
uint32_t fuDetTypeT0 = 0;
TStopwatch* fTimer = nullptr; //! is create when fbGetTimings is set before init
......
......@@ -266,8 +266,8 @@ void CbmTaskBuildRawEvents::FillSeedTimesFromDetList(std::vector<Double_t>* vdSe
if (DigiCounters[system.detId] < DigiNumbers[system.detId]) {
// filter T0 digis from Tof (remove this statement if T0 properly implemented)
if (system.detId == ECbmModuleId::kTof
&& (fTofDigis->at(DigiCounters[system.detId])).GetAddress() == CbmAlgoBuildRawEvents::fuT0Address) {
if (system.detId == ECbmModuleId::kTof && 0 != fuDetTypeT0
&& (fTofDigis->at(DigiCounters[system.detId])).GetType() == fuDetTypeT0) {
DigiCounters[system.detId]++;
continue;
} // end of T0 filter
......@@ -329,8 +329,7 @@ void CbmTaskBuildRawEvents::FillSeedTimesFromSlidingWindow(const RawEventBuilder
for (Int_t i = 0; i < fDigiMan->GetNofDigis(seedDet->detId); i++) {
// filter T0 digis from Tof (remove this statement if T0 properly implemented)
if (seedDet->detId == ECbmModuleId::kTof
&& (fTofDigis->at(i)).GetAddress() == CbmAlgoBuildRawEvents::fuT0Address) {
if (seedDet->detId == ECbmModuleId::kTof && 0 != fuDetTypeT0 && (fTofDigis->at(i)).GetType() == fuDetTypeT0) {
continue;
} // end of T0 filter
......@@ -352,23 +351,42 @@ void CbmTaskBuildRawEvents::FillSeedTimesFromSlidingWindow(const RawEventBuilder
case ECbmModuleId::kSts: fSeedFinderSlidingWindow->FillSeedTimes(fStsDigis, fvDigiMatchQa); break;
case ECbmModuleId::kTrd: fSeedFinderSlidingWindow->FillSeedTimes(fTrdDigis, fvDigiMatchQa); break;
case ECbmModuleId::kTof: {
// filter T0 digis from Tof (remove this statement if T0 properly implemented)
std::vector<CbmTofDigi> vFilteredTofDigis;
for (const auto& tofDigi : *fTofDigis) {
if (tofDigi.GetAddress() == CbmAlgoBuildRawEvents::fuT0Address) { continue; }
vFilteredTofDigis.push_back(tofDigi);
if (0 != fuDetTypeT0) {
// filter T0 digis from Tof (remove this block if T0 properly implemented)
std::vector<CbmTofDigi> vFilteredTofDigis;
for (const auto& tofDigi : *fTofDigis) {
if (tofDigi.GetType() == fuDetTypeT0) { continue; }
vFilteredTofDigis.push_back(tofDigi);
}
fSeedFinderSlidingWindow->FillSeedTimes(&vFilteredTofDigis, fvDigiMatchQa);
// end of T0 filter
}
else {
// original version (no T0 filter)
fSeedFinderSlidingWindow->FillSeedTimes(fTofDigis, fvDigiMatchQa);
}
fSeedFinderSlidingWindow->FillSeedTimes(&vFilteredTofDigis, fvDigiMatchQa);
break;
// end of T0 filter
//original version (no T0 filter)
//fSeedFinderSlidingWindow->FillSeedTimes(fTofDigis, fvDigiMatchQa); break;
}
case ECbmModuleId::kRich: fSeedFinderSlidingWindow->FillSeedTimes(fRichDigis, fvDigiMatchQa); break;
case ECbmModuleId::kPsd: fSeedFinderSlidingWindow->FillSeedTimes(fPsdDigis, fvDigiMatchQa); break;
case ECbmModuleId::kT0: fSeedFinderSlidingWindow->FillSeedTimes(fT0Digis, fvDigiMatchQa); break;
case ECbmModuleId::kT0: {
if (0 != fuDetTypeT0) {
// filter T0 digis in Tof array (remove this block if T0 properly implemented)
// => This T0 seed finding is untested and without ensurance
std::vector<CbmTofDigi> vFilteredTofDigis;
for (const auto& tofDigi : *fTofDigis) {
if (tofDigi.GetType() != fuDetTypeT0) { continue; }
vFilteredTofDigis.push_back(tofDigi);
}
fSeedFinderSlidingWindow->FillSeedTimes(&vFilteredTofDigis, fvDigiMatchQa);
// end of T0 filter
}
else {
// original version (no T0 filter needed)
fSeedFinderSlidingWindow->FillSeedTimes(fT0Digis, fvDigiMatchQa);
}
break;
}
default: break;
}
}
......
......@@ -118,6 +118,11 @@ public:
if (nullptr != fpAlgo) fpAlgo->SetTimings(bFlagIn);
fbGetTimings = bFlagIn;
}
void SetT0InTofDetType(uint32_t uTypeIn = 5)
{
if (nullptr != fpAlgo) fpAlgo->SetT0InTofDetType(uTypeIn);
fuDetTypeT0 = uTypeIn;
}
void SetSeedFinderQa(Bool_t bFlagIn = kTRUE);
void PrintTimings();
......@@ -183,6 +188,8 @@ private:
Bool_t fbFillHistos {kTRUE}; //! Switch ON/OFF filling of histograms
Bool_t fbWriteHistosToFairSink {kTRUE}; //! Write histos to FairRootManager instead of separate file
Bool_t fbGetTimings = kFALSE; //! Measure CPU time using stopwatch
/// for filtering T0 digis from Tof (remove this line if T0 properly implemented)
uint32_t fuDetTypeT0 = 0;
/** Name of the histogram output file **/
TString fsOutFileName {"data/HistosEvtWin.root"};
......
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