CbmRoot
Loading...
Searching...
No Matches
CbmSeedFinderSlidingWindow.cxx
Go to the documentation of this file.
1/* Copyright (C) 2007-2021 Facility for Antiproton and Ion Research in Europe, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Dominik Smith [committer] */
4
6
7#include "CbmBmonDigi.h"
8#include "CbmFsdDigi.h"
9#include "CbmMCEventList.h"
10#include "CbmMatch.h"
11#include "CbmMuchBeamTimeDigi.h"
12#include "CbmMuchDigi.h"
13#include "CbmPsdDigi.h"
14#include "CbmRichDigi.h"
15#include "CbmSeedFinderQa.h"
16#include "CbmStsDigi.h"
17#include "CbmTofDigi.h"
18#include "CbmTrdDigi.h"
19#include "FairRootManager.h"
20
21#include <Logger.h>
22
24{
25 if (fQa != nullptr) {
26 delete fQa;
27 }
28}
29
30template<>
31double CbmSeedFinderSlidingWindow::GetTime(const std::vector<double>* vIn, int32_t i);
32
33template<class inType>
34void CbmSeedFinderSlidingWindow::FillSeedTimes(const std::vector<inType>* vIn, const std::vector<CbmMatch>* vDigiMatch)
35{
36 // Reset output array
37 fvSeedTimes->clear();
38
39 if (fQa) {
41 }
42
43 // Ideal mode ignores digi input and copies MC event list
44 if (fbIdealMode) {
45
46 std::vector<CbmMatch> eventMatches;
47
48 for (uint32_t i = 0; i < fEventList->GetNofEvents(); i++) {
49
51 continue;
52 }
53 const double seedTime = fEventList->GetEventTimeByIndex(i);
54 fvSeedTimes->push_back(seedTime);
55
56 if (fQa) {
57 const uint32_t eventId = fEventList->GetEventIdByIndex(i);
58 const uint32_t fileId = fEventList->GetFileIdByIndex(i);
59 CbmMatch eventMatch;
60 eventMatch.AddLink(1.0, 0, eventId, fileId);
61 eventMatches.push_back(eventMatch);
62 }
63 }
64 if (fQa) {
65 for (uint32_t i = 0; i < fvSeedTimes->size(); i++) {
66 fQa->FillQaSeedInfo(i, i, &eventMatches, fvSeedTimes->at(i));
67 }
69 }
70 return;
71 }
72
73 const int32_t nDigisTot = vIn->size();
74 int32_t nDigisWin = 0;
75 int32_t winStartN = 0;
76 double winStartT = -1111;
77
78 //LOG(debug) << "CbmTaskBuildRawEvents::FillSeedTimesSlidingWindow: digis in slice " << nDigisTot;
79
80 for (int32_t i = 0; i < nDigisTot; i++) {
81 const double currentT = GetTime(vIn, i);
82 int32_t j = 0;
83
84 nDigisWin++;
85 if (winStartT == -1111) {
86 winStartN = i;
87 winStartT = currentT;
88 }
89 if (currentT - winStartT > fdWindDur) {
90 for (j = winStartN; j < i; j++) {
91
92 winStartT = GetTime(vIn, j);
93 if (currentT - winStartT <= fdWindDur) {
94 winStartN = j;
95 break;
96 }
97 nDigisWin--;
98 }
99 if (j == i) {
100 winStartN = i;
101 winStartT = currentT;
102 }
103 }
104
105 if (nDigisWin >= fminDigis) {
106 // Reached required number of digis
107 const double seedTime =
108 fdOffset + (currentT + winStartT) / 2.; //one possibility. perhaps better to place seed at end of window.
109 fvSeedTimes->push_back(seedTime);
110
111 if (vDigiMatch && fQa) { // QA mode
112 fQa->FillQaSeedInfo(winStartN, i, vDigiMatch, seedTime);
113 }
114 nDigisWin = 0;
115
116 for (j = i + 1; j < nDigisTot; j++) {
117 const double newStartT = GetTime(vIn, j);
118 if (newStartT - currentT > fdDeadT) break;
119 }
120 if (j == nDigisTot) {
121 //Reached the end of the slice
122 break;
123 }
124 i = j - 1;
125 winStartN = j;
126 winStartT = GetTime(vIn, j);
127 }
128 }
129
130 if (fQa) {
131 fQa->FillQaMCInfo();
132 }
133
134 //if (fQa && vDigiMatch) { // QA mode
135 // std::cout << "CbmSeedFinderSlidingWindow::FillSeedTimes(): Found " << GetNofSeeds() << " seeds for this timeslice."
136 // << std::endl;
137 //}
138}
139template void CbmSeedFinderSlidingWindow::FillSeedTimes(const std::vector<CbmBmonDigi>*, const std::vector<CbmMatch>*);
140template void CbmSeedFinderSlidingWindow::FillSeedTimes(const std::vector<CbmMuchBeamTimeDigi>*,
141 const std::vector<CbmMatch>*);
142template void CbmSeedFinderSlidingWindow::FillSeedTimes(const std::vector<CbmMuchDigi>*, const std::vector<CbmMatch>*);
143template void CbmSeedFinderSlidingWindow::FillSeedTimes(const std::vector<CbmPsdDigi>*, const std::vector<CbmMatch>*);
144template void CbmSeedFinderSlidingWindow::FillSeedTimes(const std::vector<CbmFsdDigi>*, const std::vector<CbmMatch>*);
145template void CbmSeedFinderSlidingWindow::FillSeedTimes(const std::vector<CbmRichDigi>*, const std::vector<CbmMatch>*);
146template void CbmSeedFinderSlidingWindow::FillSeedTimes(const std::vector<CbmStsDigi>*, const std::vector<CbmMatch>*);
147template void CbmSeedFinderSlidingWindow::FillSeedTimes(const std::vector<CbmTofDigi>*, const std::vector<CbmMatch>*);
148template void CbmSeedFinderSlidingWindow::FillSeedTimes(const std::vector<CbmTrdDigi>*, const std::vector<CbmMatch>*);
149template void CbmSeedFinderSlidingWindow::FillSeedTimes(const std::vector<double>*, const std::vector<CbmMatch>*);
150
152{
153 if (!fbIdealMode) {
154 std::cout << "CbmSeedFinderSlidingWindow: Error, called algo without digi input, but ideal mode is not set."
155 << std::endl;
156 exit(1);
157 }
158 FillSeedTimes<double>(nullptr);
159}
160
161template<class inType>
162double CbmSeedFinderSlidingWindow::GetTime(const std::vector<inType>* vIn, int32_t i)
163{
164 const inType* digi = &(vIn->at(i));
165 if (digi == nullptr) {
166 std::cout << "CbmSeedFinderSlidingWindow: Error, non-allocated digi in input vector at position: " << i
167 << std::endl;
168 }
169 return digi->GetTime();
170}
171
172template<>
173double CbmSeedFinderSlidingWindow::GetTime(const std::vector<double>* vIn, int32_t i)
174{
175 return vIn->at(i);
176}
177
179{
180 if (doQA == true) {
181 if (fQa == nullptr) {
182 fQa = new CbmSeedFinderQa();
183 }
184 }
185 else {
186 if (fQa != nullptr) {
187 delete fQa;
188 }
189 }
190}
191
193{
194 if (fQa) {
195 fQa->Init();
196 }
197
198 if (fbIdealMode) {
199 if (!FairRootManager::Instance() || !FairRootManager::Instance()->GetObject("MCEventList.")) {
200 LOG(error) << "No MC event list found";
201 return;
202 }
203 fEventList = (CbmMCEventList*) FairRootManager::Instance()->GetObject("MCEventList.");
204 }
205}
206
208{
209 if (fQa) {
210 fQa->OutputQa();
211 }
212}
Class for sliding window seed finder.
Class for sliding window seed finder.
Container class for MC events with number, file and start time.
int32_t GetFileIdByIndex(uint32_t index)
File number by index @value File number for event at given index in list.
double GetEventTimeByIndex(uint32_t index)
Event time by index @value Event time for event at given index in list.
int32_t GetEventIdByIndex(uint32_t index)
Event number by index @value Event number for event at given index in list.
std::size_t GetNofEvents() const
Number of events in the list @value Number of events.
void AddLink(const CbmLink &newLink)
Definition CbmMatch.cxx:47
void FillQaSeedInfo(const int32_t WinStart, const int32_t WinEnd, const std::vector< CbmMatch > *vDigiMatch, const double seedTime)
Gather QA Information. @params WinStart Starting position of seed window. @params WinStart End positi...
void Init()
Initialize communication with FairRootManager (needed for MC events).
void OutputQa()
Output QA Information.
void ResetPerTsStorage()
Reset containers that are persistent for one TS.
void FillQaMCInfo()
Fill QA Information that uses the full list of MC events per TS.
void OutputQa()
Output QA Information.
double fdOffset
Global time offset which is applied to each trigger time.
int32_t fminDigis
Minimum number of digis which must be found in the seed window.
CbmSeedFinderQa * fQa
Processes QA info.
void SetQa(bool doQA=true)
Enable or disable the generation of QA information.
int32_t fIdealModeFileId
If only a single file is to be used in `‘ideal mode’' (-1 = all files).
std::vector< double > * fvSeedTimes
Output of the algorithm. Stores seed times for current time slice.
void Init()
Initializes QA object if set.
double fdDeadT
`‘Dead time’' i.e. time interval which is discarded after a seed is found.
void FillSeedTimes()
Function which builds event seeds without digi input. Can only be used in ideal mode.
double GetTime(const std::vector< inType > *vIn, int32_t i)
Fetches time at position i of either a digi vector or vector of times.
double fdWindDur
Size of sliding window.
CbmMCEventList * fEventList
To access MC truth in `‘ideal mode’'.
bool fbIdealMode
`‘ideal mode’' uses MC truth as trigger times.