ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
InnerDetector
InDetValidation
InDetVertexSplitter
src
InDetEventSplitter.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
10
11
#include "GaudiKernel/MsgStream.h"
12
14
#include "
InDetEventSplitter.h
"
15
16
#include "
Particle/TrackParticle.h
"
17
#include "
Particle/TrackParticleContainer.h
"
18
#include "
TrkTrack/Track.h
"
19
#include "
TrkTrack/LinkToTrack.h
"
20
#include "
TrkTrack/TrackCollection.h
"
21
#include "
TrkParticleBase/TrackParticleBase.h
"
22
#include "
TrkParticleBase/LinkToTrackParticleBase.h
"
23
#include "
TrkParticleBase/TrackParticleBaseCollection.h
"
24
25
#include <algorithm>
26
#include <cmath>
27
#include <cstdlib>
28
#include <ctime>
29
#include <map>
30
#include <sstream>
31
34
35
InDet::InDetEventSplitter::InDetEventSplitter
(
const
std::string& name,
36
ISvcLocator* pSvcLocator) :
37
AthAlgorithm
(name, pSvcLocator),
38
m_isOdd
(false),
39
m_addToVx
(0),
40
m_eventN
(0){
41
43
declareProperty
(
"TPBContainerName"
,
m_tpbContainerName
=
"TrackParticleCandidate"
);
44
declareProperty
(
"TrackContainerName"
,
m_trackContainerName
=
"Tracks"
);
45
declareProperty
(
"MaxVertexNumber"
,
m_maxVtx
= 1);
//this should not be changed until a more robust handling of multi vertices is implemented
46
declareProperty
(
"PrimaryOnly"
,
m_priOnly
=
true
);
//this should not be changed presently
47
declareProperty
(
"UseTrackParticleBase"
,
m_savetpb
=
true
);
//is this needed?
48
declareProperty
(
"RandomSeed"
,
m_rndSeed
= 7);
49
}
50
54
55
InDet::InDetEventSplitter::~InDetEventSplitter
() =
default
;
56
60
61
StatusCode
InDet::InDetEventSplitter::initialize
() {
62
63
std::srand(
m_rndSeed
);
64
m_isOdd
=
false
;
65
m_addToVx
= 1;
66
m_eventN
= 0;
67
68
for
(
int
i = 1; i <=
m_maxVtx
; i++){
69
std::stringstream
ss
;
70
ss
<<
"odd_"
<< i <<
"_Tracks"
;
71
m_trackKeys
.push_back(
ss
.str());
72
ss
.str(
""
);
73
ss
<<
"even_"
<< i <<
"_Tracks"
;
74
m_trackKeys
.push_back(
ss
.str());
75
ss
.str(
""
);
76
ss
<<
"all_"
<< i <<
"_Tracks"
;
77
m_trackKeys
.push_back(
ss
.str());
78
ss
.str(
""
);
79
}
80
81
ATH_MSG_INFO
(
"Initializing InDetEventSplitter"
);
82
83
return
StatusCode::SUCCESS;
84
}
85
88
89
StatusCode
InDet::InDetEventSplitter::finalize
() {
90
ATH_MSG_DEBUG
(
"in finalize()"
);
91
92
return
StatusCode::SUCCESS;
93
94
}
95
98
99
StatusCode
InDet::InDetEventSplitter::execute
(
const
EventContext&
/*ctx*/
) {
100
101
ATH_MSG_DEBUG
(
"in execute()"
);
102
103
StatusCode
sc
= StatusCode::SUCCESS;
104
105
sc
=
split_vertices
();
106
if
(
sc
.isFailure()) {
107
ATH_MSG_ERROR
(
"InDetEventSplitter Failed"
);
108
return
sc
;
109
}
110
111
return
sc
;
112
}
113
115
116
StatusCode
InDet::InDetEventSplitter::split_vertices
() {
117
118
ATH_MSG_DEBUG
(
"in split_vertices()"
);
119
120
StatusCode
sc
= StatusCode::SUCCESS;
121
122
const
Rec::TrackParticleContainer
* tpbTES{};
123
const
TrackCollection
* trkTES{};
124
125
if
(
m_savetpb
){
126
sc
=
evtStore
()->retrieve( tpbTES,
m_tpbContainerName
);
127
if
(
sc
.isFailure() || !tpbTES ) {
128
ATH_MSG_WARNING
(
"No TrackParticleBase container found in TDS tried "
<<
m_tpbContainerName
);
129
return
StatusCode::SUCCESS;
130
}
131
ATH_MSG_DEBUG
(
"TrackParticleCandidate Collection successfully retrieved"
);
132
}
133
else
{
134
sc
=
evtStore
()->retrieve( trkTES,
m_trackContainerName
);
135
if
(
sc
.isFailure() || !trkTES ) {
136
ATH_MSG_WARNING
(
"No TrackCollection container found in TDS tried "
<<
m_trackContainerName
);
137
return
StatusCode::SUCCESS;
138
}
139
ATH_MSG_DEBUG
(
"TrackParticleCandidate Collection successfully retrieved"
);
140
}
141
142
std::map<std::string,TrackCollection*> trackmap;
143
std::map<std::string,Trk::TrackParticleBaseCollection*> tpbmap;
144
145
// We need to create every container for each event, even if we don't write to them
146
147
for
(
const
auto
& key :
m_trackKeys
){
148
TrackCollection
* tempTracks{};
149
trackmap[key] = tempTracks;
150
if
(
evtStore
()->
contains<TrackCollection>
(key) &&
151
(
evtStore
()->retrieve(trackmap[key],key)).isSuccess()){
152
}
else
{
153
trackmap[key] =
new
TrackCollection
;
154
}
155
}
156
157
for
(
const
auto
& key :
m_trackKeys
){
158
Trk::TrackParticleBaseCollection
* tempTpbs{};
159
tpbmap[key] = tempTpbs;
160
if
(
evtStore
()->
contains<Trk::TrackParticleBaseCollection>
(key) &&
161
(
evtStore
()->retrieve(tpbmap[key],key)).isSuccess()){
162
}
else
{
163
tpbmap[key] =
new
Trk::TrackParticleBaseCollection
;
164
}
165
}
166
167
//We need to add an appropriate fraction of unfit tracks to the half and full vertex collections
168
//lets pull in the full list of tracks
169
170
if
(
m_savetpb
and tpbTES){
171
//we loop over that list
172
std::string oeNameString;
173
std::stringstream sss;
174
oeNameString.reserve(20);
175
for
(
const
auto
* tpb: *tpbTES){
176
//it looks like our track collection is actually sorted by the vertex that they're in
177
//which means that just alternating odd vs even is equivalent to splitting the vertex first, then splitting the remaining
178
//instead, we will just put in rand() call
179
//
180
//coverity[DC.WEAK_CRYPTO]
181
m_isOdd
= std::rand() % 2;
182
oeNameString.clear();
183
if
(
m_isOdd
) oeNameString =
"odd"
;
184
if
(!
m_isOdd
) oeNameString =
"even"
;
185
sss.str(
""
);
186
sss << oeNameString <<
"_"
<<
m_addToVx
<<
"_Tracks"
;
187
std::string oecontainerName = sss.str();
188
sss.str(
""
);
189
sss <<
"all_"
<<
m_addToVx
<<
"_Tracks"
;
190
std::string allcontainerName = sss.str();
191
Trk::TrackParticleBase
*trkCopy1 =
new
Trk::TrackParticleBase
(*tpb);
192
Trk::TrackParticleBase
*trkCopy2 =
new
Trk::TrackParticleBase
(*tpb);
193
ATH_MSG_DEBUG
(
"found a trackparticlebase, with momentum "
<<tpb->definingParameters().momentum()<<
" giving it the key: "
<< oecontainerName);
194
tpbmap[oecontainerName]->push_back(trkCopy1);
195
ATH_MSG_DEBUG
(
"found a trackparticlebase, with momentum "
<<tpb->definingParameters().momentum()<<
" giving it the key: "
<< allcontainerName);
196
tpbmap[allcontainerName]->push_back(trkCopy2);
197
198
m_addToVx
++;
199
if
(
m_addToVx
>
m_maxVtx
)
m_addToVx
= 1;
200
}
201
}
202
203
if
(!
m_savetpb
){
204
std::cout<<
"NotYet Implemented"
<<std::endl;
205
}
206
207
if
(
m_savetpb
){
208
for
(
const
auto
& key :
m_trackKeys
){
209
if
(
evtStore
()->record(tpbmap[key],key,
false
).isFailure() ){
210
ATH_MSG_ERROR
(
"Could not save the "
<< key);
211
}
212
}
213
}
else
{
214
for
(
const
auto
& key :
m_trackKeys
){
215
if
(
evtStore
()->record(trackmap[key],key,
false
).isFailure() ){
216
ATH_MSG_ERROR
(
"Could not save the "
<< key);
217
}
218
}
219
}
220
ATH_MSG_DEBUG
(
"split_vertices() succeeded"
);
221
m_eventN
++;
222
return
StatusCode::SUCCESS;
223
}
224
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition
AthMsgStreamMacros.h:33
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition
AthMsgStreamMacros.h:31
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition
AthMsgStreamMacros.h:32
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
InDetEventSplitter.h
ss
static Double_t ss
Definition
LArPhysWaveHECTool.cxx:37
sc
static Double_t sc
Definition
LArPhysWaveHECTool.cxx:37
LinkToTrackParticleBase.h
LinkToTrack.h
TrackParticleContainer.h
TrackParticle.h
TrackCollection.h
TrackCollection
DataVector< Trk::Track > TrackCollection
This typedef represents a collection of Trk::Track objects.
Definition
TrackCollection.h:19
TrackParticleBaseCollection.h
TrackParticleBase.h
Track.h
AthAlgorithm::AthAlgorithm
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition
AthAlgorithm.cxx:10
AthCommonAlgorithm< Gaudi::Algorithm >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
Definition
AthCommonDataStore.h:145
AthCommonAlgorithm< Gaudi::Algorithm >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
Definition
AthCommonDataStore.h:85
InDet::InDetEventSplitter::m_trackKeys
std::vector< std::string > m_trackKeys
Definition
InDetEventSplitter.h:44
InDet::InDetEventSplitter::m_savetpb
bool m_savetpb
Definition
InDetEventSplitter.h:56
InDet::InDetEventSplitter::~InDetEventSplitter
~InDetEventSplitter()
Destructor - check up memory allocation delete any memory allocation on the heap.
InDet::InDetEventSplitter::m_priOnly
bool m_priOnly
Definition
InDetEventSplitter.h:55
InDet::InDetEventSplitter::m_isOdd
bool m_isOdd
Definition
InDetEventSplitter.h:46
InDet::InDetEventSplitter::m_rndSeed
int m_rndSeed
Definition
InDetEventSplitter.h:57
InDet::InDetEventSplitter::m_eventN
int m_eventN
Definition
InDetEventSplitter.h:59
InDet::InDetEventSplitter::m_trackContainerName
std::string m_trackContainerName
Definition
InDetEventSplitter.h:53
InDet::InDetEventSplitter::split_vertices
StatusCode split_vertices()
Definition
InDetEventSplitter.cxx:116
InDet::InDetEventSplitter::InDetEventSplitter
InDetEventSplitter(const std::string &name, ISvcLocator *pSvcLocator)
Author: Peter V.
Definition
InDetEventSplitter.cxx:35
InDet::InDetEventSplitter::execute
StatusCode execute(const EventContext &ctx)
Execute - on event by event.
Definition
InDetEventSplitter.cxx:99
InDet::InDetEventSplitter::m_addToVx
int m_addToVx
Definition
InDetEventSplitter.h:47
InDet::InDetEventSplitter::m_tpbContainerName
std::string m_tpbContainerName
containers to retrieve
Definition
InDetEventSplitter.h:52
InDet::InDetEventSplitter::initialize
StatusCode initialize()
Initialize initialize StoreGate.
Definition
InDetEventSplitter.cxx:61
InDet::InDetEventSplitter::finalize
StatusCode finalize()
Finalize - delete any memory allocation from the heap.
Definition
InDetEventSplitter.cxx:89
InDet::InDetEventSplitter::m_maxVtx
int m_maxVtx
Definition
InDetEventSplitter.h:54
Rec::TrackParticleContainer
Definition
Reconstruction/Particle/Particle/TrackParticleContainer.h:33
Trk::TrackParticleBase
Definition
TrackParticleBase.h:41
contains
bool contains(const std::string &s, const std::string ®x)
does a string contain the substring
Definition
hcg.cxx:116
Trk::TrackParticleBaseCollection
DataVector< TrackParticleBase > TrackParticleBaseCollection
Definition
TrackParticleBaseCollection.h:14
Generated on
for ATLAS Offline Software by
1.17.0