BmnRoot
26.10.0-210-gc52d34b0
Software framework of the BM@N experiment
Toggle main menu visibility
Loading...
Searching...
No Matches
BmnHitDumper.cxx
Go to the documentation of this file.
1
/*
2
BM@N alignment routine
3
BM@N experiment at NICA complex, JINR, 2025
4
5
Department: Math & Soft Group of HEP lab
6
Author: Claude 4.7 (Opus)
7
Supervisor: Igor Polev, polev@jinr.int
8
9
BmnHitDumper class implementation
10
*/
11
12
#include "
BmnHitDumper.h
"
13
14
#include "
BmnEventHeader.h
"
15
#include "
CbmStsHit.h
"
16
#include "FairMCEventHeader.h"
17
#include "FairRootManager.h"
18
#include "
TSystem.h
"
19
#include "fairlogger/Logger.h"
20
21
BmnHitDumper::BmnHitDumper
(
const
TString
& dstFileName)
22
:
fCsvFilePath
(dstFileName)
23
{
24
// expand $VAR and ~ if present
25
char
* expanded =
gSystem
->ExpandPathName(
fCsvFilePath
.Data());
26
fCsvFilePath
= expanded;
27
delete
[] expanded;
28
// replace extension with .csv (or append if none)
29
Int_t
dotIdx{fCsvFilePath.Last(
'.'
)};
30
Int_t
sepIdx{fCsvFilePath.Last(
'/'
)};
31
if (dotIdx > sepIdx)
32
fCsvFilePath
.Replace(dotIdx,
fCsvFilePath
.Length() - dotIdx,
".csv"
);
33
else
34
fCsvFilePath
.Append(
".csv"
);
35
}
36
37
InitStatus
BmnHitDumper::Init
()
38
{
39
if
(
fDetModel
.IgnoresSome()) {
40
LOG(error) <<
" <!> BmnHitDumper::Init() : detector model is incomplete (ignores some hits)"
41
" - cannot be used to dump hits consistently. Task disabled."
;
42
SetActive(
kFALSE
);
43
return
kERROR;
44
}
45
FairRootManager* ioman = FairRootManager::Instance();
46
if
(!ioman) {
47
LOG(error) <<
" <!> BmnHitDumper::Init() : FairRootManager not found"
;
48
SetActive(
kFALSE
);
49
return
kERROR;
50
}
51
fpStsHitsArray
= (
TClonesArray
*)ioman->GetObject(
"StsHit"
);
52
if
(!
fpStsHitsArray
) {
53
LOG(error) <<
" <!> BmnHitDumper::Init() : Failed to get StsHit array"
;
54
SetActive(
kFALSE
);
55
return
kERROR;
56
}
57
// The "DstEventHeader." branch cannot be queried via ioman->GetObject(): the
58
// output DstEventHeader (registered via FairRunAna::SetEventHeader) shadows
59
// the input one in FairRootManager's folder lookup, and its BMN-specific
60
// fEventId is never populated by FairFileSource/BmnFileSource (which only
61
// touch FairEventHeader base fields). Read the per-event ID from the input
62
// header instead: BmnEventHeader. for experimental data, MCEventHeader. for
63
// simulation. Both are auto-updated each event via FairFileSource::ReadEvent.
64
fpBmnHeader
= (
BmnEventHeader
*)ioman->GetObject(
"BmnEventHeader."
);
65
fpMcHeader
= (
FairMCEventHeader
*)ioman->GetObject(
"MCEventHeader."
);
66
if
(!
fpBmnHeader
&& !
fpMcHeader
) {
67
LOG(error) <<
" <!> BmnHitDumper::Init() : "
68
"no BmnEventHeader. or MCEventHeader. branch in input"
;
69
SetActive(
kFALSE
);
70
return
kERROR;
71
}
72
if
(!
fDetModel
.Init()) {
73
LOG(error) <<
" <!> BmnHitDumper::Init() : Failed to initialize detector model"
;
74
SetActive(
kFALSE
);
75
return
kERROR;
76
}
77
fCsvFile
.open(
fCsvFilePath
.Data(), std::ofstream::out);
78
if
(!
fCsvFile
.is_open()) {
79
LOG(error) <<
" <!> BmnHitDumper::Init() : Failed to open output file "
<<
fCsvFilePath
.Data();
80
SetActive(
kFALSE
);
81
return
kERROR;
82
}
83
fCsvFile
<<
"eventID,detectorID,x,y,z,dx,dy\n"
;
84
LOG(info) <<
"BmnHitDumper: writing hits to "
<<
fCsvFilePath
.Data();
85
SetActive(
kTRUE
);
86
fTimer
.Start();
87
return
kSUCCESS;
88
}
89
90
void
BmnHitDumper::Exec
(
Option_t
*
/*opt*/
)
91
{
92
UInt_t
eventID{
fpBmnHeader
?
fpBmnHeader
->GetEventId() : (
UInt_t
)
fpMcHeader
->GetEventID()};
93
Int_t
n{
fpStsHitsArray
->GetEntriesFast()};
94
for
(
Int_t
i
= 0;
i
< n;
i
++) {
95
CbmStsHit
* hit =
static_cast<
CbmStsHit
*
>
(
fpStsHitsArray
->At(
i
));
96
fCsvFile
<< eventID <<
","
<<
fDetModel
.IDfromHit(hit->GetDetectorID()) <<
","
<< hit->GetX() <<
","
97
<< hit->GetY() <<
","
<< hit->GetZ() <<
","
<< hit->GetDx() <<
","
<< hit->GetDy() <<
"\n"
;
98
}
99
LOG(info) <<
"BmnHitDumper: "
<< n <<
" hits written from event "
<< eventID;
100
}
101
102
void
BmnHitDumper::Finish
()
103
{
104
if
(
fCsvFile
.is_open())
105
fCsvFile
.close();
106
fTimer
.Stop();
107
Int_t
secs{
static_cast<
Int_t
>
(
fTimer
.RealTime())};
108
LOG(info) <<
Form
(
"BmnHitDumper: total time spent: %dh %02dm %02ds"
, secs / 3600, (secs % 3600) / 60, secs % 60);
109
}
BmnEventHeader.h
BmnHitDumper.h
CbmStsHit.h
i
int i
Definition
P4_F32vec4.h:22
Int_t
int Int_t
UInt_t
unsigned int UInt_t
kFALSE
constexpr Bool_t kFALSE
kTRUE
constexpr Bool_t kTRUE
Option_t
const char Option_t
Form
char * Form(const char *fmt,...)
TSystem.h
gSystem
R__EXTERN TSystem * gSystem
BmnEventHeader
Definition
BmnEventHeader.h:24
BmnHitDumper::fpMcHeader
FairMCEventHeader * fpMcHeader
Definition
BmnHitDumper.h:32
BmnHitDumper::Finish
virtual void Finish()
Definition
BmnHitDumper.cxx:102
BmnHitDumper::Init
virtual InitStatus Init()
Definition
BmnHitDumper.cxx:37
BmnHitDumper::fpBmnHeader
BmnEventHeader * fpBmnHeader
Definition
BmnHitDumper.h:31
BmnHitDumper::fCsvFilePath
TString fCsvFilePath
Definition
BmnHitDumper.h:34
BmnHitDumper::fTimer
TStopwatch fTimer
Definition
BmnHitDumper.h:36
BmnHitDumper::fCsvFile
std::ofstream fCsvFile
Definition
BmnHitDumper.h:35
BmnHitDumper::fDetModel
BmnRun8DM fDetModel
Definition
BmnHitDumper.h:33
BmnHitDumper::fpStsHitsArray
TClonesArray * fpStsHitsArray
Definition
BmnHitDumper.h:30
BmnHitDumper::Exec
virtual void Exec(Option_t *opt)
Definition
BmnHitDumper.cxx:90
BmnHitDumper::BmnHitDumper
BmnHitDumper()=delete
CbmStsHit
Definition
CbmStsHit.h:27
FairMCEventHeader
TClonesArray
TString
align_new
src
BmnHitDumper.cxx
Generated on
for BmnRoot by
1.17.0