ATLAS Offline Software
Loading...
Searching...
No Matches
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
18#include "TrkTrack/Track.h"
24
25#include <algorithm>
26#include <cmath>
27#include <cstdlib>
28#include <ctime>
29#include <map>
30#include <sstream>
31
34
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
56
60
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
90 ATH_MSG_DEBUG("in finalize()");
91
92 return StatusCode::SUCCESS;
93
94}
95
98
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
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;
151 (evtStore()->retrieve(trackmap[key],key)).isSuccess()){
152 } else {
153 trackmap[key] = new TrackCollection;
154 }
155 }
156
157 for (const auto & key : m_trackKeys){
159 tpbmap[key] = tempTpbs;
161 (evtStore()->retrieve(tpbmap[key],key)).isSuccess()){
162 } else {
163 tpbmap[key] = new Trk::TrackParticleBaseCollection;
164 }
165 }
166
167 //We need to add an approprate 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 remining
178 //instead, we will just put in rand() call
179 m_isOdd = std::rand() % 2;
180 oeNameString.clear();
181 if (m_isOdd) oeNameString = "odd";
182 if (!m_isOdd) oeNameString = "even";
183 sss.str("");
184 sss << oeNameString << "_" << m_addToVx << "_Tracks";
185 std::string oecontainerName = sss.str();
186 std::string allNameString = "all";
187 sss.str("");
188 sss << allNameString << "_" << m_addToVx << "_Tracks";
189 std::string allcontainerName = sss.str();
192 ATH_MSG_DEBUG("found a trackparticlebase, with momentum "<<tpb->definingParameters().momentum()<<" giving it the key: "<< oecontainerName);
193 tpbmap[oecontainerName]->push_back(trkCopy1);
194 ATH_MSG_DEBUG("found a trackparticlebase, with momentum "<<tpb->definingParameters().momentum()<<" giving it the key: "<< allcontainerName);
195 tpbmap[allcontainerName]->push_back(trkCopy2);
196
197 m_addToVx++;
198 if (m_addToVx > m_maxVtx) m_addToVx = 1;
199 }
200 }
201
202 if (!m_savetpb){
203 std::cout<<"NotYet Implemented"<<std::endl;
204 }
205
206 if (m_savetpb){
207 for (const auto & key : m_trackKeys){
208 if(evtStore()->record(tpbmap[key],key,false).isFailure() ){
209 ATH_MSG_ERROR("Could not save the "<< key);
210 }
211 }
212 } else {
213 for (const auto & key : m_trackKeys){
214 if(evtStore()->record(trackmap[key],key,false).isFailure() ){
215 ATH_MSG_ERROR("Could not save the "<< key);
216 }
217 }
218 }
219 ATH_MSG_DEBUG("split_vertices() succeeded");
220 m_eventN++;
221 return StatusCode::SUCCESS;
222}
223
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
static Double_t ss
static Double_t sc
DataVector< Trk::Track > TrackCollection
This typedef represents a collection of Trk::Track objects.
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
std::vector< std::string > m_trackKeys
~InDetEventSplitter()
Destructor - check up memory allocation delete any memory allocation on the heap.
StatusCode execute()
Execute - on event by event.
InDetEventSplitter(const std::string &name, ISvcLocator *pSvcLocator)
Author: Peter V.
std::string m_tpbContainerName
containers to retrieve
StatusCode initialize()
Initialize initialize StoreGate.
StatusCode finalize()
Finalize - delete any memory allocation from the heap.
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition hcg.cxx:114
DataVector< TrackParticleBase > TrackParticleBaseCollection