BmnRoot
26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Toggle main menu visibility
Loading...
Searching...
No Matches
BmnScWallReconstructor.cxx
Go to the documentation of this file.
1
/** @file BmnScWallReconstructor.cxx
2
** @author Nikolay Karpushkin <karpushkin@inr.ru>
3
** @date 03.04.2021
4
**
5
** Code for BmnScWallEvent reconstruction (creation) from BmnScWallDigi {Data} or BmnScWallDigit {Sim}
6
**/
7
8
#include "
BmnScWallReconstructor.h
"
9
10
#include "
TTreeFormula.h
"
11
12
BmnScWallReconstructor::BmnScWallReconstructor
(
bool
isExp,
bool
isGlobalCoordinates)
13
{
14
fIsExp
= isExp;
15
fIsGlobal
= isGlobalCoordinates;
16
LOG(detail) <<
Form
(
"BmnScWallReconstructor: isExp %i; isGlobal %i"
,
fIsExp
,
fIsGlobal
);
17
}
18
19
void
BmnScWallReconstructor::SetRecoCutsFile
(
TString
reco_cuts_file)
20
{
21
fRecoCutsFile
= reco_cuts_file;
22
ParseCuts
();
23
LOG(detail) <<
Form
(
"BmnScWallReconstructor: Reco cuts %s"
,
fRecoCutsFile
.Data());
24
}
25
26
BmnScWallReconstructor::~BmnScWallReconstructor
()
27
{
28
if
(
fBmnScWallEvent
)
29
delete
fBmnScWallEvent
;
30
}
31
32
InitStatus
BmnScWallReconstructor::Init
()
33
{
34
fworkTime
= 0.;
35
fpFairRootMgr
= FairRootManager::Instance();
36
(
fIsExp
) ?
fArrayOfDigits
= (
TClonesArray
*)
fpFairRootMgr
->GetObject(
"ScWallDigi"
)
37
:
fArrayOfDigits
= (
TClonesArray
*)
fpFairRootMgr
->GetObject(
"ScWallDigit"
);
38
39
if
(!
fArrayOfDigits
) {
40
LOG(error) <<
"BmnScWallReconstructor::Init(): branch with Digits not found! Task will be deactivated"
;
41
SetActive(
kFALSE
);
42
return
kERROR;
43
}
44
45
fBmnScWallEvent
=
new
BmnScWallEvent
();
46
fBmnScWallEvent
->reset();
47
ParseGeometry
();
48
fpFairRootMgr
->RegisterAny(
"ScWallEvent"
,
fBmnScWallEvent
,
kTRUE
);
49
50
LOG(debug) <<
"ScWall Reconstructor ready"
;
51
return
kSUCCESS;
52
}
53
54
void
BmnScWallReconstructor::ParseCuts
()
55
{
56
namespace
po = boost::program_options;
57
58
TString
dir = getenv(
"VMCWORKDIR"
);
59
TString
path = dir +
"/parameters/scwall/"
;
60
61
float
version;
62
std::string comment;
63
std::string cutExp;
64
std::string cutSim;
65
66
// Setup options.
67
po::options_description desc(
"Options"
);
68
desc.add_options()(
"VERSION.id"
, po::value<float>(&version),
69
"version identificator"
)(
"COMMENT.str"
, po::value<std::string>(&comment),
"comment"
)(
70
"EXPERIMENT.cut"
, po::value<std::string>(&cutExp),
71
"cut for Experimental data"
)(
"SIMULATION.cut"
, po::value<std::string>(&cutSim),
"cut for Simulated data"
);
72
73
// Load config file.
74
po::variables_map vm;
75
std::ifstream config_file((path +
fRecoCutsFile
).Data(), std::ifstream::in);
76
if
(!config_file.is_open()) {
77
LOG(error) <<
Form
(
"BmnScWallReconstructor: Loading Cuts from file: %s - file open error!"
,
78
fRecoCutsFile
.Data());
79
return
;
80
}
81
LOG(debug) <<
Form
(
"BmnScWallReconstructor: Loading Cuts from file: %s"
,
fRecoCutsFile
.Data());
82
po::store(po::parse_config_file(config_file, desc), vm);
83
config_file.close();
84
po::notify(vm);
85
86
if
(
fIsExp
)
87
fSelectionString
= cutExp;
88
else
89
fSelectionString
= cutSim;
90
}
91
92
void
BmnScWallReconstructor::ParseGeometry
()
93
{
94
BmnScWallGeo
* GeoHandler =
new
BmnScWallGeo
();
95
GeoHandler->
ReadGeometryFromGeoManager
(
fIsGlobal
);
96
const
auto
& positionMap = GeoHandler->
GetPositionMap
();
97
for
(
auto
it : positionMap) {
98
auto
unique_address = it.first;
99
if
(unique_address == 0)
100
continue
;
101
auto
cell_id =
BmnScWallAddress::GetCellId
(unique_address);
102
auto
this_cell =
fBmnScWallEvent
->GetCell(cell_id);
103
this_cell->SetCellId(cell_id);
104
this_cell->SetSignal(0.);
105
106
this_cell->SetPosition(it.second.first);
107
this_cell->SetPositionError(it.second.second);
108
}
109
delete
GeoHandler;
110
}
111
112
void
BmnScWallReconstructor::Exec
(
Option_t
* opt)
113
{
114
115
if
(!IsActive())
116
return
;
117
118
TStopwatch
sw;
119
sw.
Start
();
120
fBmnScWallEvent
->ResetCells();
121
auto
digiVector =
GetSelectedDigiVector
(
fSelectionString
);
122
123
for
(
auto
it : digiVector) {
124
BmnScWallDigit
* ThisDigi = (
BmnScWallDigit
*)it;
125
auto
cell_id = ThisDigi->
GetCellId
();
// 1 to 174
126
if
(cell_id <= 0 || cell_id >
BmnScWallEvent::fgkMaxCells
) {
127
if
(fVerbose)
128
LOG(warning) <<
Form
(
"ScWall digi ignored. Cell %d "
, cell_id);
129
continue
;
130
}
131
fBmnScWallEvent
->GetCell(cell_id)->SetSignal(ThisDigi->
GetSignal
());
132
}
133
134
fBmnScWallEvent
->SummarizeEvent();
135
sw.
Stop
();
136
fworkTime
+= sw.
RealTime
();
137
}
138
139
std::vector<TObject*>
BmnScWallReconstructor::GetSelectedDigiVector
(
TString
formulaString)
140
{
141
TTree
* temp_tree =
new
TTree
(
"temp_tree"
,
"temp_tree"
);
142
TString
temp_br_name = (
fIsExp
) ?
"ScWallDigi"
:
"ScWallDigit"
;
143
fSelectedDigiVector
.clear();
144
145
if
(
fIsExp
) {
146
BmnScWallDigi
* ptr =
nullptr
;
147
temp_tree->
Branch
(temp_br_name.
Data
(), &ptr);
148
for
(
int
i
= 0;
i
<
fArrayOfDigits
->GetEntriesFast();
i
++) {
149
ptr = (
BmnScWallDigi
*)
fArrayOfDigits
->At(
i
);
150
temp_tree->
Fill
();
151
}
152
}
else
{
153
BmnScWallDigit
* ptr =
nullptr
;
154
temp_tree->
Branch
(temp_br_name.
Data
(), &ptr);
155
for
(
int
i
= 0;
i
<
fArrayOfDigits
->GetEntriesFast();
i
++) {
156
ptr = (
BmnScWallDigit
*)
fArrayOfDigits
->At(
i
);
157
temp_tree->
Fill
();
158
}
159
}
160
161
TTreeFormula
* formula =
new
TTreeFormula
(
"TTreeformula"
, formulaString.
Data
(), temp_tree);
162
if
(!formula || formula->
GetNdim
() == 0)
163
LOG(error) <<
Form
(
"BmnScWallReconstructor::GetSelectedDigiVector. Bad cuts. Check formula %s from file %s"
,
164
formulaString.
Data
(),
fRecoCutsFile
.Data());
165
// next line is needed. Reason unclear. without it will lose some digis.
166
TObject
* ThisDigi =
nullptr
;
167
temp_tree->
SetBranchAddress
(temp_br_name.
Data
(), &ThisDigi);
168
for
(
int
i
= 0;
i
< temp_tree->
GetEntries
();
i
++) {
169
temp_tree->
GetEntry
(
i
);
170
formula->
GetNdata
();
171
if
(formula->
EvalInstance
() > 0)
// passed selection
172
fSelectedDigiVector
.push_back(
fArrayOfDigits
->At(
i
));
173
}
174
formula->
Delete
();
175
temp_tree->
Delete
();
176
return
fSelectedDigiVector
;
177
}
178
179
void
BmnScWallReconstructor::OnlineWrite
(
const
std::unique_ptr<TTree>& resultTree)
180
{
181
if
(!IsActive())
182
return
;
183
184
resultTree->Branch(
"ScWallEvent"
, &
fBmnScWallEvent
);
185
resultTree->Fill();
186
}
187
188
void
BmnScWallReconstructor::Finish
()
189
{
190
printf(
"Work time of BmnScWallReconstructor: %4.2f sec.\n"
,
fworkTime
);
191
}
i
int i
Definition
P4_F32vec4.h:22
kFALSE
constexpr Bool_t kFALSE
kTRUE
constexpr Bool_t kTRUE
Option_t
const char Option_t
Form
char * Form(const char *fmt,...)
TTreeFormula.h
BmnAbstractDigit::GetSignal
double GetSignal() const
Definition
BmnAbstractDigit.h:43
BmnGeoTemplate::GetPositionMap
const auto & GetPositionMap() const
Definition
BmnGeoTemplate.h:119
BmnGeoTemplate::ReadGeometryFromGeoManager
BmnStatus ReadGeometryFromGeoManager(bool getGlobalPosition=true)
Definition
BmnGeoTemplate.h:32
BmnScWallAddress::GetCellId
static uint32_t GetCellId(uint32_t address)
Return Cell id from address.
Definition
BmnScWallAddress.h:52
BmnScWallDigi
Class for experimental data at digi level.
Definition
BmnScWallDigi.h:21
BmnScWallDigit
Definition
BmnScWallDigit.h:14
BmnScWallDigit::GetCellId
uint32_t GetCellId() const
Definition
BmnScWallDigit.h:27
BmnScWallEvent
Class for Bmn ScWall data container in event.
Definition
BmnScWallEvent.h:22
BmnScWallEvent::fgkMaxCells
static const int fgkMaxCells
Definition
BmnScWallEvent.h:68
BmnScWallGeo
Definition
BmnScWallGeo.h:15
BmnScWallReconstructor::fRecoCutsFile
TString fRecoCutsFile
Definition
BmnScWallReconstructor.h:51
BmnScWallReconstructor::Init
virtual InitStatus Init()
Definition
BmnScWallReconstructor.cxx:32
BmnScWallReconstructor::fpFairRootMgr
FairRootManager * fpFairRootMgr
Definition
BmnScWallReconstructor.h:45
BmnScWallReconstructor::~BmnScWallReconstructor
~BmnScWallReconstructor()
Definition
BmnScWallReconstructor.cxx:26
BmnScWallReconstructor::fIsGlobal
bool fIsGlobal
Definition
BmnScWallReconstructor.h:54
BmnScWallReconstructor::BmnScWallReconstructor
BmnScWallReconstructor(bool isExp, bool isGlobalCoordinates)
Definition
BmnScWallReconstructor.cxx:12
BmnScWallReconstructor::fSelectionString
TString fSelectionString
Definition
BmnScWallReconstructor.h:52
BmnScWallReconstructor::SetRecoCutsFile
void SetRecoCutsFile(TString reco_cuts_file)
Definition
BmnScWallReconstructor.cxx:19
BmnScWallReconstructor::Finish
virtual void Finish()
Definition
BmnScWallReconstructor.cxx:188
BmnScWallReconstructor::fSelectedDigiVector
std::vector< TObject * > fSelectedDigiVector
Definition
BmnScWallReconstructor.h:48
BmnScWallReconstructor::ParseGeometry
void ParseGeometry()
Definition
BmnScWallReconstructor.cxx:92
BmnScWallReconstructor::ParseCuts
void ParseCuts()
Definition
BmnScWallReconstructor.cxx:54
BmnScWallReconstructor::Exec
virtual void Exec(Option_t *opt)
Definition
BmnScWallReconstructor.cxx:112
BmnScWallReconstructor::fworkTime
float fworkTime
Definition
BmnScWallReconstructor.h:56
BmnScWallReconstructor::fBmnScWallEvent
BmnScWallEvent * fBmnScWallEvent
Definition
BmnScWallReconstructor.h:49
BmnScWallReconstructor::fArrayOfDigits
TClonesArray * fArrayOfDigits
Definition
BmnScWallReconstructor.h:46
BmnScWallReconstructor::OnlineWrite
virtual void OnlineWrite(const std::unique_ptr< TTree > &resultTree)
Write task resul to tree.
Definition
BmnScWallReconstructor.cxx:179
BmnScWallReconstructor::GetSelectedDigiVector
std::vector< TObject * > GetSelectedDigiVector(TString formulaString)
Definition
BmnScWallReconstructor.cxx:139
BmnScWallReconstructor::fIsExp
bool fIsExp
Definition
BmnScWallReconstructor.h:53
ROOT::v5::TFormula::GetNdim
virtual Int_t GetNdim() const
TClonesArray
TObject
TObject::Delete
virtual void Delete(Option_t *option="")
TStopwatch
TStopwatch::RealTime
Double_t RealTime()
TStopwatch::Start
void Start(Bool_t reset=kTRUE)
TStopwatch::Stop
void Stop()
TString
TString::Data
const char * Data() const
TTreeFormula
TTreeFormula::EvalInstance
T EvalInstance(Int_t i=0, const char *stringStack[]=nullptr)
TTreeFormula::GetNdata
virtual Int_t GetNdata()
TTree
TTree::Fill
virtual Int_t Fill()
TTree::GetEntry
virtual Int_t GetEntry(Long64_t entry, Int_t getall=0)
TTree::Delete
void Delete(Option_t *option="") override
TTree::GetEntries
virtual Long64_t GetEntries() const
TTree::SetBranchAddress
Int_t SetBranchAddress(const char *bname, T **add, TBranch **ptr=nullptr)
TTree::Branch
virtual Int_t Branch(const char *folder, Int_t bufsize=32000, Int_t splitlevel=99)
BmnScWallReconstructor.h
reconstruction
scwall
BmnScWallReconstructor.cxx
Generated on
for BmnRoot by
1.17.0