BmnRoot
26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Toggle main menu visibility
Loading...
Searching...
No Matches
BmnTof1HitProducerIdeal.cxx
Go to the documentation of this file.
1
#include "
BmnTof1HitProducerIdeal.h
"
2
3
#include "
BmnTOF1Point.h
"
4
#include "
BmnTofHit.h
"
5
#include "FairLogger.h"
6
#include "FairRootManager.h"
7
#include "
TFile.h
"
8
9
#include <assert.h>
10
11
BmnTof1HitProducerIdeal::BmnTof1HitProducerIdeal
(
const
char
* name,
12
Bool_t
useMCdata,
13
Int_t
verbose,
14
Bool_t
test,
15
Bool_t
merge)
16
:
BmnTask
(name, verbose)
17
,
aMcPoints
(nullptr)
18
,
aMcTracks
(nullptr)
19
,
aExpDigits
(nullptr)
20
,
aTofHits
(nullptr)
21
,
fDoTest
(test)
22
,
fDoMergeHits
(merge)
23
,
fUseMCData
(useMCdata)
24
,
fOnlyPrimary
(false)
25
,
fTestFlnm
(
""
)
26
{}
27
28
BmnTof1HitProducerIdeal::~BmnTof1HitProducerIdeal
() {}
29
30
InitStatus
BmnTof1HitProducerIdeal::Init
()
31
{
32
LOG(info) <<
"[BmnTof1HitProducerIdeal::Init] Begin initialization."
;
33
34
FairRootManager* ioman = FairRootManager::Instance();
35
assert(ioman);
36
37
if
(
fUseMCData
) {
38
aMcPoints
= (
TClonesArray
*)FairRootManager::Instance()->GetObject(
"TOF400Point"
);
39
if
(!
aMcPoints
) {
40
cout <<
"BmnTof1HitProducerIdeal::Init(): branch TOF1Point not found! Task will be deactivated"
<< endl;
41
SetActive(
kFALSE
);
42
return
kERROR;
43
}
44
aMcTracks
= (
TClonesArray
*)FairRootManager::Instance()->GetObject(
"MCTrack"
);
45
if
(!
aMcTracks
) {
46
cout <<
"BmnTof1HitProducerIdeal::Init(): branch MCTrack not found! Task will be deactivated"
<< endl;
47
SetActive(
kFALSE
);
48
return
kERROR;
49
}
50
}
else
{
51
aExpDigits
= (
TClonesArray
*)FairRootManager::Instance()->GetObject(
"bmn_tof400"
);
52
if
(!
aExpDigits
) {
53
cout <<
"BmnTof1HitProducerIdeal::Init(): branch bmn_tof400 not found! Task will be deactivated"
<< endl;
54
SetActive(
kFALSE
);
55
return
kERROR;
56
}
57
}
58
59
// Create and register output array
60
aTofHits
=
new
TClonesArray
(
"BmnTofHit"
);
61
ioman->Register(
"TOF400Hit"
,
"TOF1"
,
aTofHits
,
kTRUE
);
62
63
LOG(info) <<
"[BmnTof1HitProducerIdeal::Init] Initialization finished succesfully."
;
64
65
return
kSUCCESS;
66
}
67
68
void
BmnTof1HitProducerIdeal::Exec
(
Option_t
* opt)
69
{
70
if
(!IsActive())
71
return
;
72
73
static
const
TVector3
XYZ_err(0., 0., 0.);
// FIXME:
74
75
aTofHits
->Clear();
76
77
Int_t
nSingleHits = 0;
78
TVector3
pos;
79
80
if
(
fUseMCData
) {
81
BmnTOF1Point
* pPoint;
82
Int_t
nTofPoint =
aMcPoints
->GetEntriesFast();
83
84
for
(
Int_t
pointIndex = 0; pointIndex < nTofPoint; pointIndex++)
// cycle by TOF points
85
{
86
pPoint = (
BmnTOF1Point
*)
aMcPoints
->UncheckedAt(pointIndex);
87
pPoint->Position(pos);
88
89
AddHit
(pPoint->GetDetectorID(), pos, XYZ_err, pointIndex, pPoint->GetTrackID(), pPoint->GetTime(),
kTOF1
);
90
nSingleHits++;
91
}
92
}
93
94
int
nFinally;
95
if
(
fDoMergeHits
) {
96
MergeHitsOnStrip
();
// save only the fastest hit in the strip
97
nFinally =
CompressHits
();
// remove blank slotes
98
}
else
99
nFinally =
aTofHits
->GetEntriesFast();
100
101
cout <<
" -I- [BmnTof1HitProducerIdeal::Exec] single hits= "
<< nSingleHits <<
", final hits= "
<< nFinally
102
<< endl;
103
}
104
105
void
BmnTof1HitProducerIdeal::Finish
() {}
106
107
Int_t
BmnTof1HitProducerIdeal::MergeHitsOnStrip
(
void
)
108
{
109
typedef
map<Int_t, BmnTofHit*> hitsMapType;
110
hitsMapType fHits;
// pair<detectorUID, BmnTofHit*> fastest hits map
111
hitsMapType::iterator it;
112
Int_t
mergedNmb = 0;
113
114
typedef
multiset<Int_t> msUIDsType;
// detectorUID for Hits
115
msUIDsType UIDs;
116
117
BmnTofHit
*fastHit, *slowHit;
118
for
(
Int_t
hitIndex = 0, nHits =
aTofHits
->GetEntriesFast(); hitIndex < nHits; hitIndex++)
// cycle by hits
119
{
120
BmnTofHit
* pHit = (
BmnTofHit
*)
aTofHits
->UncheckedAt(hitIndex);
121
assert(
nullptr
!= pHit);
122
123
Int_t
UID = pHit->GetDetectorID();
124
125
if
(
fDoTest
)
126
UIDs.insert(UID);
127
128
it = fHits.find(UID);
129
if
(it != fHits.end())
// hit for this detectorUID already exist
130
{
131
mergedNmb++;
132
133
if
(pHit->GetTimeStamp() < it->second->GetTimeStamp())
// faster hit found
134
{
135
fastHit = pHit;
136
slowHit = it->second;
137
}
else
{
138
fastHit = it->second;
139
slowHit = pHit;
140
}
141
142
fastHit->AddLinks(slowHit->GetLinks());
// copy links
143
aTofHits
->Remove(slowHit);
// remove old hit --> make blank slote !!
144
it->second = fastHit;
// change pair value to current UID
145
}
else
146
fHits.insert(make_pair(UID, pHit));
// insert new detectorUID pair
147
148
}
// cycle by hits
149
150
return
mergedNmb;
151
}
152
153
void
BmnTof1HitProducerIdeal::AddHit
(
Int_t
detUID,
154
const
TVector3
& posHit,
155
const
TVector3
& posHitErr,
156
Int_t
pointIndex,
157
Int_t
trackIndex,
158
Double_t
time,
159
Int_t
Idd =
kTOF1
)
160
{
161
BmnTofHit
* pHit =
new
((*aTofHits)[
aTofHits
->GetEntriesFast()])
BmnTofHit
(detUID, posHit, posHitErr, pointIndex);
162
163
FairRootManager::Instance()->SetUseFairLinks(
kTRUE
);
164
pHit->SetTimeStamp(time);
165
pHit->AddLink(FairLink(0x1, pointIndex));
166
pHit->AddLink(FairLink(0x2, trackIndex));
167
pHit->AddLink(FairLink(0x4, detUID));
168
Int_t
str =
BmnTOF1Point::GetStrip
(detUID) - 1;
169
Int_t
plane =
BmnTOF1Point::GetModule
(detUID) - 1;
170
pHit->
SetModule
(plane);
171
pHit->
SetStation
(str);
172
pHit->
SetDetId
(
DetectorId
(Idd));
173
FairRootManager::Instance()->SetUseFairLinks(
kFALSE
);
174
}
175
176
Int_t
BmnTof1HitProducerIdeal::CompressHits
()
177
{
178
aTofHits
->Compress();
179
return
aTofHits
->GetEntriesFast();
180
}
181
182
void
BmnTof1HitProducerIdeal::Dump
(
const
char
* title, ostream& out)
const
183
{
184
out <<
"\n [BmnTof1HitProducerIdeal::Dump] "
;
185
if
(title)
186
out << title;
187
out <<
", size= "
<<
aTofHits
->
GetEntriesFast
();
188
189
BmnTOF1Point
* point;
190
BmnTofHit
* pHit;
191
TVector3
hitPos, pointPos;
192
193
TIterator
* iter =
aTofHits
->
MakeIterator
();
194
while
((pHit = (
BmnTofHit
*)iter->
Next
())) {
195
pHit->Position(hitPos);
196
out <<
"\n hit detUID = "
<< pHit->GetDetectorID() <<
", hit pos("
<< hitPos.
X
() <<
","
<< hitPos.
Y
() <<
","
197
<< hitPos.
Z
() <<
"), "
;
198
if
(
aMcPoints
) {
199
point = (
BmnTOF1Point
*)
aMcPoints
->
UncheckedAt
(pHit->GetRefIndex());
200
point->Position(pointPos);
201
out <<
"\n point detUID = "
<< point->GetDetectorID() <<
", point pos("
<< pointPos.
X
() <<
","
202
<< pointPos.
Y
() <<
","
<< pointPos.
Z
() <<
"), dev="
<< (hitPos - pointPos).Mag();
203
}
204
}
205
206
delete
iter;
207
}
Bool_t
bool Bool_t
Int_t
int Int_t
kFALSE
constexpr Bool_t kFALSE
Double_t
double Double_t
kTRUE
constexpr Bool_t kTRUE
Option_t
const char Option_t
TFile.h
DetectorId
DetectorId
BM@N DetectorID enumerator.
Definition
BmnDetectorList.h:12
kTOF1
@ kTOF1
Definition
BmnDetectorList.h:16
BmnHit::SetModule
void SetModule(Int_t mod)
Definition
BmnHit.h:53
BmnHit::SetDetId
void SetDetId(DetectorId det)
Definition
BmnHit.h:51
BmnHit::SetStation
void SetStation(Short_t st)
Definition
BmnHit.h:52
BmnTOF1Point
Definition
BmnTOF1Point.h:11
BmnTOF1Point::GetModule
Int_t GetModule() const
Definition
BmnTOF1Point.h:39
BmnTOF1Point::GetStrip
Int_t GetStrip() const
Definition
BmnTOF1Point.h:38
BmnTask::BmnTask
BmnTask()
Default constructor.
Definition
BmnTask.cxx:3
BmnTof1HitProducerIdeal::Dump
void Dump(const char *comment=nullptr, std::ostream &out=std::cout) const
BmnTof1HitProducerIdeal::AddHit
void AddHit(Int_t detUID, const TVector3 &posHit, const TVector3 &posHitErr, Int_t pointIndex, Int_t trackIndex, Double_t time, Int_t Idd)
Definition
BmnTof1HitProducerIdeal.cxx:153
BmnTof1HitProducerIdeal::aMcPoints
TClonesArray * aMcPoints
Definition
BmnTof1HitProducerIdeal.h:18
BmnTof1HitProducerIdeal::Exec
virtual void Exec(Option_t *option)
Definition
BmnTof1HitProducerIdeal.cxx:68
BmnTof1HitProducerIdeal::Finish
virtual void Finish()
Definition
BmnTof1HitProducerIdeal.cxx:105
BmnTof1HitProducerIdeal::fUseMCData
Bool_t fUseMCData
Definition
BmnTof1HitProducerIdeal.h:32
BmnTof1HitProducerIdeal::fOnlyPrimary
Bool_t fOnlyPrimary
Definition
BmnTof1HitProducerIdeal.h:33
BmnTof1HitProducerIdeal::fDoMergeHits
Bool_t fDoMergeHits
Definition
BmnTof1HitProducerIdeal.h:31
BmnTof1HitProducerIdeal::aExpDigits
TClonesArray * aExpDigits
<— MC input
Definition
BmnTof1HitProducerIdeal.h:20
BmnTof1HitProducerIdeal::fTestFlnm
TString fTestFlnm
Definition
BmnTof1HitProducerIdeal.h:34
BmnTof1HitProducerIdeal::aTofHits
TClonesArray * aTofHits
<— The T0 time is stored in 'BmnTrigInfo.' branch in Run9
Definition
BmnTof1HitProducerIdeal.h:24
BmnTof1HitProducerIdeal::BmnTof1HitProducerIdeal
BmnTof1HitProducerIdeal(const char *name="TOF1 Ideal HitProducer", Bool_t useMCdata=true, Int_t verbose=1, Bool_t DoTest=false, Bool_t DoMergeHits=false)
Definition
BmnTof1HitProducerIdeal.cxx:11
BmnTof1HitProducerIdeal::Init
virtual InitStatus Init()
Definition
BmnTof1HitProducerIdeal.cxx:30
BmnTof1HitProducerIdeal::MergeHitsOnStrip
Int_t MergeHitsOnStrip()
Definition
BmnTof1HitProducerIdeal.cxx:107
BmnTof1HitProducerIdeal::fDoTest
Bool_t fDoTest
Definition
BmnTof1HitProducerIdeal.h:30
BmnTof1HitProducerIdeal::CompressHits
Int_t CompressHits()
Definition
BmnTof1HitProducerIdeal.cxx:176
BmnTof1HitProducerIdeal::~BmnTof1HitProducerIdeal
virtual ~BmnTof1HitProducerIdeal()
Definition
BmnTof1HitProducerIdeal.cxx:28
BmnTof1HitProducerIdeal::aMcTracks
TClonesArray * aMcTracks
<— MC input
Definition
BmnTof1HitProducerIdeal.h:19
BmnTofHit
Definition
BmnTofHit.h:22
TClonesArray
TIterator
TIterator::Next
virtual TObject * Next()=0
TObjArray::GetEntriesFast
Int_t GetEntriesFast() const
TObjArray::MakeIterator
TIterator * MakeIterator(Bool_t dir=kIterForward) const override
TObjArray::UncheckedAt
TObject * UncheckedAt(Int_t i) const
TVector3
TVector3::Z
Double_t Z() const
TVector3::Y
Double_t Y() const
TVector3::X
Double_t X() const
BmnTOF1Point.h
BmnTof1HitProducerIdeal.h
BmnTofHit.h
detectors
tof1
BmnTof1HitProducerIdeal.cxx
Generated on
for BmnRoot by
1.17.0