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 "CbmTimeSlice.h" // added to access timeslice info and TimeSliceMetaData does not work
18#include "CbmTofDigi.h"
19#include "CbmTrdDigi.h"
20#include "FairRootManager.h"
21
22#include <Logger.h>
23
25{
26 if (fQa != nullptr) {
27 delete fQa;
28 }
29}
30
31template<>
32double CbmSeedFinderSlidingWindow::GetTime(const std::vector<double>* vIn, int32_t i);
33
34template<class inType>
35void CbmSeedFinderSlidingWindow::FillSeedTimes(const std::vector<inType>* vIn, const std::vector<CbmMatch>* vDigiMatch)
36{
37 // Reset output array
38 fvSeedTimes->clear();
39
40 if (fQa) {
41 fQa->ResetPerTsStorage();
42 }
43
44 // Ideal mode ignores digi input and copies MC event list
45 if (fbIdealMode) {
46
47 std::vector<CbmMatch> eventMatches;
48
49 fTimeSlice = (CbmTimeSlice*) FairRootManager::Instance()->GetObject(
50 "TimeSlice."); // accessing timeslice info (because TimeSliceMetaData branch does not work)
51 double TSList_starttime = fTimeSlice->GetStartTime();
52
53
54 for (uint32_t i = 0; i < fEventList->GetNofEvents(); i++) {
55
56 if (fIdealModeFileId != -1 && fEventList->GetFileIdByIndex(i) != fIdealModeFileId) {
57 continue;
58 }
59 const double seedTime = fEventList->GetEventTimeByIndex(i);
60 double shiftedSeedTime =
61 seedTime - TSList_starttime; // shifting the absolute time of MC Event by the corresponding Timeslice start
62 fvSeedTimes->push_back(
63 shiftedSeedTime); // in order to match it later with relative times of digis (fixing the ideal mode)
64
65
66 if (fQa) {
67 const uint32_t eventId = fEventList->GetEventIdByIndex(i);
68 const uint32_t fileId = fEventList->GetFileIdByIndex(i);
69 CbmMatch eventMatch;
70 eventMatch.AddLink(1.0, 0, eventId, fileId);
71 eventMatches.push_back(eventMatch);
72 }
73 }
74 if (fQa) {
75 for (uint32_t i = 0; i < fvSeedTimes->size(); i++) {
76 fQa->FillQaSeedInfo(i, i, &eventMatches, fvSeedTimes->at(i));
77 }
78 fQa->FillQaMCInfo();
79 }
80 return;
81 }
82
83 const int32_t nDigisTot = vIn->size();
84 int32_t nDigisWin = 0;
85 int32_t winStartN = 0;
86 double winStartT = -1111;
87
88 //LOG(debug) << "CbmTaskBuildRawEvents::FillSeedTimesSlidingWindow: digis in slice " << nDigisTot;
89
90 for (int32_t i = 0; i < nDigisTot; i++) {
91 const double currentT = GetTime(vIn, i);
92 int32_t j = 0;
93
94 nDigisWin++;
95 if (winStartT == -1111) {
96 winStartN = i;
97 winStartT = currentT;
98 }
99 if (currentT - winStartT > fdWindDur) {
100 for (j = winStartN; j < i; j++) {
101
102 winStartT = GetTime(vIn, j);
103 if (currentT - winStartT <= fdWindDur) {
104 winStartN = j;
105 break;
106 }
107 nDigisWin--;
108 }
109 if (j == i) {
110 winStartN = i;
111 winStartT = currentT;
112 }
113 }
114
115 if (nDigisWin >= fminDigis) {
116 // Reached required number of digis
117 const double seedTime =
118 fdOffset + (currentT + winStartT) / 2.; //one possibility. perhaps better to place seed at end of window.
119 fvSeedTimes->push_back(seedTime);
120
121 if (vDigiMatch && fQa) { // QA mode
122 fQa->FillQaSeedInfo(winStartN, i, vDigiMatch, seedTime);
123 }
124 nDigisWin = 0;
125
126 for (j = i + 1; j < nDigisTot; j++) {
127 const double newStartT = GetTime(vIn, j);
128 if (newStartT - currentT > fdDeadT) break;
129 }
130 if (j == nDigisTot) {
131 //Reached the end of the slice
132 break;
133 }
134 i = j - 1;
135 winStartN = j;
136 winStartT = GetTime(vIn, j);
137 }
138 }
139
140 if (fQa) {
141 fQa->FillQaMCInfo();
142 }
143
144 //if (fQa && vDigiMatch) { // QA mode
145 // std::cout << "CbmSeedFinderSlidingWindow::FillSeedTimes(): Found " << GetNofSeeds() << " seeds for this timeslice."
146 // << std::endl;
147 //}
148}
149template void CbmSeedFinderSlidingWindow::FillSeedTimes(const std::vector<CbmBmonDigi>*, const std::vector<CbmMatch>*);
150template void CbmSeedFinderSlidingWindow::FillSeedTimes(const std::vector<CbmMuchBeamTimeDigi>*,
151 const std::vector<CbmMatch>*);
152template void CbmSeedFinderSlidingWindow::FillSeedTimes(const std::vector<CbmMuchDigi>*, const std::vector<CbmMatch>*);
153template void CbmSeedFinderSlidingWindow::FillSeedTimes(const std::vector<CbmPsdDigi>*, const std::vector<CbmMatch>*);
154template void CbmSeedFinderSlidingWindow::FillSeedTimes(const std::vector<CbmFsdDigi>*, const std::vector<CbmMatch>*);
155template void CbmSeedFinderSlidingWindow::FillSeedTimes(const std::vector<CbmRichDigi>*, const std::vector<CbmMatch>*);
156template void CbmSeedFinderSlidingWindow::FillSeedTimes(const std::vector<CbmStsDigi>*, const std::vector<CbmMatch>*);
157template void CbmSeedFinderSlidingWindow::FillSeedTimes(const std::vector<CbmTofDigi>*, const std::vector<CbmMatch>*);
158template void CbmSeedFinderSlidingWindow::FillSeedTimes(const std::vector<CbmTrdDigi>*, const std::vector<CbmMatch>*);
159template void CbmSeedFinderSlidingWindow::FillSeedTimes(const std::vector<double>*, const std::vector<CbmMatch>*);
160
162{
163 if (!fbIdealMode) {
164 std::cout << "CbmSeedFinderSlidingWindow: Error, called algo without digi input, but ideal mode is not set."
165 << std::endl;
166 exit(1);
167 }
168 FillSeedTimes<double>(nullptr);
169}
170
171template<class inType>
172double CbmSeedFinderSlidingWindow::GetTime(const std::vector<inType>* vIn, int32_t i)
173{
174 const inType* digi = &(vIn->at(i));
175 if (digi == nullptr) {
176 std::cout << "CbmSeedFinderSlidingWindow: Error, non-allocated digi in input vector at position: " << i
177 << std::endl;
178 }
179 return digi->GetTime();
180}
181
182template<>
183double CbmSeedFinderSlidingWindow::GetTime(const std::vector<double>* vIn, int32_t i)
184{
185 return vIn->at(i);
186}
187
189{
190 if (doQA == true) {
191 if (fQa == nullptr) {
192 fQa = new CbmSeedFinderQa();
193 }
194 }
195 else {
196 if (fQa != nullptr) {
197 delete fQa;
198 }
199 }
200}
201
203{
204 if (fQa) {
205 fQa->Init();
206 }
207
208 if (fbIdealMode) {
209 if (!FairRootManager::Instance() || !FairRootManager::Instance()->GetObject("MCEventList.")) {
210 LOG(error) << "No MC event list found";
211 return;
212 }
213 fEventList = (CbmMCEventList*) FairRootManager::Instance()->GetObject("MCEventList.");
214 }
215}
216
218{
219 if (fQa) {
220 fQa->OutputQa();
221 }
222}
Class for sliding window seed finder.
Class for sliding window seed finder.
Container class for MC events with number, file and start time.
void AddLink(const CbmLink &newLink)
Definition CbmMatch.cxx:47
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.
Bookkeeping of time-slice content.