BmnRoot
26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Toggle main menu visibility
Loading...
Searching...
No Matches
BmnNdetReconstructor.cxx
Go to the documentation of this file.
1
/** @file BmnNdetReconstructor.cxx
2
** @author Nikolay Karpushkin <karpushkin@inr.ru>
3
** @date 03.04.2021
4
**
5
** Code for BmnNdetEvent reconstruction (creation) from BmnNdetDigi {Data} or BmnNdetDigit {Sim}
6
**/
7
8
#include "
BmnNdetReconstructor.h
"
9
10
#include "BmnNdetDigi.h"
11
#include "BmnNdetDigit.h"
12
#include "BmnNdetGeo.h"
13
#include "BmnNdetPoint.h"
14
#include "BmnNdetSurfacePoint.h"
15
#include "FairLogger.h"
16
#include "
TTreeFormula.h
"
17
18
#include <
TStopwatch.h
>
19
20
BmnNdetReconstructor::BmnNdetReconstructor
(
bool
isExp,
bool
isGlobalCoordinates)
21
:
fBmnNdetEvent
(nullptr)
22
,
fCuts
(nullptr)
23
,
fIsExp
(isExp)
24
,
fIsGlobal
(isGlobalCoordinates)
25
,
fworkTime
(0.)
26
{
27
LOG(detail) <<
Form
(
"BmnNdetReconstructor: isExp %i; isGlobal %i"
,
fIsExp
,
fIsGlobal
);
28
fDoMatchMC
= (
fIsExp
) ?
false
:
true
;
29
}
30
31
void
BmnNdetReconstructor::SetRecoCutsFile
(
const
std::string& cuts)
32
{
33
std::string fullPath = std::string(getenv(
"VMCWORKDIR"
)) +
"/parameters/ndet/"
+ cuts;
34
std::ifstream test(fullPath);
35
if
(!test.is_open()) {
36
LOG(warn) <<
Form
(
"BmnNdetReconstructor: cuts file not found: %s. Using default (no cuts)."
, fullPath.c_str());
37
fCuts
=
nullptr
;
38
return
;
39
}
40
41
fCuts
=
new
BmnNdetCuts
(
BmnNdetCuts::Load
(fullPath,
fIsExp
));
42
LOG(info) <<
Form
(
"BmnNdetReconstructor: cuts loaded from %s (isExp=%d)"
, fullPath.c_str(),
fIsExp
);
43
}
44
45
BmnNdetReconstructor::~BmnNdetReconstructor
()
46
{
47
if
(
fBmnNdetEvent
)
48
delete
fBmnNdetEvent
;
49
if
(
fGeoHandler
)
50
delete
fGeoHandler
;
51
if
(
fCuts
)
52
delete
fCuts
;
53
}
54
55
InitStatus
BmnNdetReconstructor::Init
()
56
{
57
fworkTime
= 0.;
58
fpFairRootMgr
= FairRootManager::Instance();
59
60
if
(
fIsExp
) {
61
if
(
auto
* a = (
TClonesArray
*)
fpFairRootMgr
->GetObject(
"HgndDigi"
))
62
fDigits
.push_back(a);
63
if
(
auto
* a = (
TClonesArray
*)
fpFairRootMgr
->GetObject(
"NdetDigi"
))
64
fDigits
.push_back(a);
65
66
if
(
fDigits
.empty()) {
67
LOG(error) <<
"BmnNdetReconstructor::Init(): no experimental digi branches (HgndDigi/NdetDigi) found! "
68
"Task will be deactivated"
;
69
SetActive(
kFALSE
);
70
return
kERROR;
71
}
72
LOG(info) <<
Form
(
"BmnNdetReconstructor::Init(): using %zu experimental branch(es)"
,
fDigits
.size());
73
}
else
{
74
if
(
auto
* a = (
TClonesArray
*)
fpFairRootMgr
->GetObject(
"NdetDigit"
))
75
fDigits
.push_back(a);
76
else
{
77
LOG(error) <<
"BmnNdetReconstructor::Init(): branch with Digits not found! Task will be deactivated"
;
78
SetActive(
kFALSE
);
79
return
kERROR;
80
}
81
82
fArrayOfPoints
= (
TClonesArray
*)
fpFairRootMgr
->GetObject(
"NdetPoint"
);
83
if
(!
fArrayOfPoints
) {
84
LOG(error) <<
"BmnNdetReconstructor::Init(): branch with NdetPoints not found! Task will be deactivated"
;
85
SetActive(
kFALSE
);
86
return
kERROR;
87
}
88
89
fArrayOfSurfacePoints
= (
TClonesArray
*)
fpFairRootMgr
->GetObject(
"NdetSurfacePoint"
);
90
if
(!
fArrayOfSurfacePoints
) {
91
LOG(error)
92
<<
"BmnNdetReconstructor::Init(): branch with NdetSurfacePoint not found! Task will be deactivated"
;
93
SetActive(
kFALSE
);
94
return
kERROR;
95
}
96
fpFairRootMgr
->Register(
"NdetSurfacePoint"
,
"NDET"
,
fArrayOfSurfacePoints
,
kTRUE
);
97
}
98
99
fBmnNdetEvent
=
new
BmnNdetEvent
();
100
fBmnNdetEvent
->reset();
101
ParseGeometry
();
102
fpFairRootMgr
->RegisterAny(
"NdetEvent"
,
fBmnNdetEvent
,
kTRUE
);
103
fpFairRootMgr
->Register(
"NdetEvent"
,
"NDET"
,
fBmnNdetEvent
,
kFALSE
);
104
105
LOG(debug) <<
"Ndet Reconstructor ready"
;
106
return
kSUCCESS;
107
}
108
109
void
BmnNdetReconstructor::ParseGeometry
()
110
{
111
fGeoHandler
=
new
BmnNdetGeo
();
112
fGeoHandler
->ReadGeometryFromGeoManager(
fIsGlobal
);
113
}
114
115
void
BmnNdetReconstructor::Exec
(
Option_t
* opt)
116
{
117
if
(!IsActive())
118
return
;
119
TStopwatch
sw;
120
sw.
Start
();
121
fBmnNdetEvent
->reset();
122
123
auto
digiVector =
GetSelectedDigis
();
124
for
(
auto
* ThisDigi : digiVector) {
125
auto
address = ThisDigi->GetAddress();
126
const
auto
& posMap =
fGeoHandler
->GetPositionMap();
127
auto
pos = posMap.find(address);
128
if
(pos == posMap.end()) {
129
LOG(debug2) <<
Form
(
"BmnNdetReconstructor : Exec. Digi address %d not found in geometry. Skipping"
,
130
address);
131
if
(FairLogger::GetLogger()->IsLogNeeded(fair::Severity::debug2))
132
ThisDigi->Print();
133
continue
;
134
}
135
BmnNdetCell
* this_cell =
new
BmnNdetCell
();
136
this_cell->
SetAddress
(address);
137
this_cell->SetPosition(pos->second.first);
138
this_cell->SetPositionError(pos->second.second);
139
this_cell->
SetSignal
(ThisDigi->GetSignal());
140
this_cell->
SetTime
(ThisDigi->GetTime());
141
fBmnNdetEvent
->AddCell(this_cell);
142
}
143
144
if
(!
fIsExp
&&
fDoMatchMC
)
145
MatchMCTracks
();
146
147
sw.
Stop
();
148
fworkTime
+= sw.
RealTime
();
149
}
150
151
std::vector<BmnNdetDigit*>
BmnNdetReconstructor::GetSelectedDigis
()
152
{
153
std::vector<BmnNdetDigit*> denoised;
154
155
size_t
total = 0;
156
for
(
auto
* arr :
fDigits
)
157
total += arr->GetEntriesFast();
158
denoised.reserve(total);
159
160
for
(
auto
* arr :
fDigits
) {
161
for
(
int
i
= 0,
n
= arr->GetEntriesFast();
i
<
n
; ++
i
) {
162
TObject
* obj = arr->At(
i
);
163
if
(!obj)
164
continue
;
165
166
if
(
fIsExp
) {
167
if
(
auto
* dexp =
dynamic_cast<
BmnHgndDigi
*
>
(obj)) {
168
if
(!
fCuts
||
fCuts
->PassExp(dexp))
169
denoised.push_back(dexp);
170
}
else
if
(
auto
* dprt =
dynamic_cast<
BmnNdetDigi
*
>
(obj)) {
171
if
(!
fCuts
||
fCuts
->PassPrototype(dprt))
172
denoised.push_back(dprt);
173
}
174
}
else
{
175
auto
* d =
static_cast<
BmnNdetDigit
*
>
(obj);
176
if
(!
fCuts
||
fCuts
->PassSim(d))
177
denoised.push_back(d);
178
}
179
}
180
}
181
182
LOG(debug4) <<
Form
(
"BmnNdetReconstructor::GetSelectedDigis: kept %zu / %zu"
, denoised.size(), total);
183
return
denoised;
184
}
185
186
void
BmnNdetReconstructor::MatchMCTracks
()
187
{
188
// Enable the use of FairLinks in FairRootManager
189
fpFairRootMgr
->SetUseFairLinks(
kTRUE
);
190
191
// Iterate over all cells in the event
192
auto
* cells =
fBmnNdetEvent
->GetModifiableCells();
193
for
(
int
ice = 0, nce = cells->GetEntriesFast(); ice < nce; ++ice) {
194
auto
* cell =
static_cast<
BmnNdetCell
*
>
(cells->At(ice));
195
if
(!cell)
196
continue
;
197
198
// Iterate over all points
199
for
(
int
iPt = 0, nPt =
fArrayOfPoints
->GetEntriesFast(); iPt < nPt; ++iPt) {
200
auto
* point =
static_cast<
BmnNdetPoint
*
>
(
fArrayOfPoints
->At(iPt));
201
if
(!point)
202
continue
;
203
if
(point->GetAddress() != cell->GetAddress())
204
continue
;
// Skip if point is from another cell
205
cell->AddLink(FairLink(
static_cast<
int
>
(
BmnNdetCell::LinkType::MCPoint
), iPt, point->GetEnergyLoss()));
206
for
(
auto
link : point->GetLinks()) {
207
link.SetWeight(point->GetEnergyLoss());
208
cell->AddLink(link);
209
}
210
LOG(debug) <<
Form
(
"BmnNdetReconstructor::MatchMCTracks. Matched MC point and MC track. Updated cell with "
211
"address %d. Now it has %d links"
,
212
cell->GetAddress(), cell->GetNLinks());
213
}
214
}
215
216
// Disable the use of FairLinks in FairRootManager
217
fpFairRootMgr
->SetUseFairLinks(
kFALSE
);
218
}
219
220
void
BmnNdetReconstructor::OnlineWrite
(
const
std::unique_ptr<TTree>& resultTree)
221
{
222
if
(!IsActive())
223
return
;
224
225
resultTree->Branch(
"NdetEvent"
, &
fBmnNdetEvent
);
226
if
(!
fIsExp
)
227
resultTree->Branch(
"NdetSurfacePoint"
, &
fArrayOfSurfacePoints
);
228
resultTree->Fill();
229
}
230
231
void
BmnNdetReconstructor::Finish
()
232
{
233
printf(
"Work time of BmnNdetReconstructor: %4.2f sec.\n"
,
fworkTime
);
234
}
i
int i
Definition
P4_F32vec4.h:22
kFALSE
constexpr Bool_t kFALSE
kTRUE
constexpr Bool_t kTRUE
Option_t
const char Option_t
TStopwatch.h
Form
char * Form(const char *fmt,...)
TTreeFormula.h
BmnHgndDigi
Data structure for a single HGND digit.
Definition
BmnHgndDigi.h:20
BmnNdetCell
Definition
BmnNdetCell.h:11
BmnNdetCell::SetAddress
void SetAddress(uint32_t address)
Definition
BmnNdetCell.h:39
BmnNdetCell::SetSignal
void SetSignal(double signal)
Definition
BmnNdetCell.h:40
BmnNdetCell::LinkType::MCPoint
@ MCPoint
Definition
BmnNdetCell.h:17
BmnNdetCell::SetTime
void SetTime(double time)
Definition
BmnNdetCell.h:41
BmnNdetDigi
Data class for Bmn Ndet digital signal processing.
Definition
BmnNdetDigi.h:24
BmnNdetDigit
Definition
BmnNdetDigit.h:11
BmnNdetEvent
Class for Bmn Ndet data container in event.
Definition
BmnNdetEvent.h:20
BmnNdetGeo
Definition
BmnNdetGeo.h:17
BmnNdetPoint
Definition
BmnNdetPoint.h:15
BmnNdetReconstructor::Init
virtual InitStatus Init()
Definition
BmnNdetReconstructor.cxx:55
BmnNdetReconstructor::fCuts
BmnNdetCuts * fCuts
Definition
BmnNdetReconstructor.h:51
BmnNdetReconstructor::fDoMatchMC
bool fDoMatchMC
Definition
BmnNdetReconstructor.h:53
BmnNdetReconstructor::~BmnNdetReconstructor
~BmnNdetReconstructor()
Definition
BmnNdetReconstructor.cxx:45
BmnNdetReconstructor::MatchMCTracks
void MatchMCTracks()
Definition
BmnNdetReconstructor.cxx:186
BmnNdetReconstructor::fBmnNdetEvent
BmnNdetEvent * fBmnNdetEvent
Definition
BmnNdetReconstructor.h:46
BmnNdetReconstructor::fIsGlobal
bool fIsGlobal
Definition
BmnNdetReconstructor.h:54
BmnNdetReconstructor::Exec
virtual void Exec(Option_t *opt)
Definition
BmnNdetReconstructor.cxx:115
BmnNdetReconstructor::GetSelectedDigis
std::vector< BmnNdetDigit * > GetSelectedDigis()
Definition
BmnNdetReconstructor.cxx:151
BmnNdetReconstructor::fGeoHandler
BmnNdetGeo * fGeoHandler
Definition
BmnNdetReconstructor.h:42
BmnNdetReconstructor::fIsExp
bool fIsExp
Definition
BmnNdetReconstructor.h:52
BmnNdetReconstructor::Finish
virtual void Finish()
Definition
BmnNdetReconstructor.cxx:231
BmnNdetReconstructor::SetRecoCutsFile
void SetRecoCutsFile(const std::string &cuts)
Definition
BmnNdetReconstructor.cxx:31
BmnNdetReconstructor::fworkTime
float fworkTime
Definition
BmnNdetReconstructor.h:56
BmnNdetReconstructor::fArrayOfSurfacePoints
TClonesArray * fArrayOfSurfacePoints
Definition
BmnNdetReconstructor.h:47
BmnNdetReconstructor::fpFairRootMgr
FairRootManager * fpFairRootMgr
Definition
BmnNdetReconstructor.h:41
BmnNdetReconstructor::OnlineWrite
virtual void OnlineWrite(const std::unique_ptr< TTree > &resultTree)
Write task resul to tree.
Definition
BmnNdetReconstructor.cxx:220
BmnNdetReconstructor::ParseGeometry
void ParseGeometry()
Definition
BmnNdetReconstructor.cxx:109
BmnNdetReconstructor::fDigits
std::vector< TClonesArray * > fDigits
Definition
BmnNdetReconstructor.h:43
BmnNdetReconstructor::BmnNdetReconstructor
BmnNdetReconstructor(bool isExp, bool isGlobalCoordinates=true)
Definition
BmnNdetReconstructor.cxx:20
BmnNdetReconstructor::fArrayOfPoints
TClonesArray * fArrayOfPoints
Definition
BmnNdetReconstructor.h:44
TClonesArray
TObject
TStopwatch
TStopwatch::RealTime
Double_t RealTime()
TStopwatch::Start
void Start(Bool_t reset=kTRUE)
TStopwatch::Stop
void Stop()
n
*brief user defined string literal for JSON values *sa std::size_t n
Definition
json.hpp:20362
BmnNdetReconstructor.h
BmnNdetCuts
Definition
BmnNdetCuts.h:15
BmnNdetCuts::Load
static BmnNdetCuts Load(const std::string &file, bool isExp)
Definition
BmnNdetCuts.h:47
reconstruction
ndet
BmnNdetReconstructor.cxx
Generated on
for BmnRoot by
1.17.0