35 , m_metaStore(
"MetaDataStore",
n )
50 ATH_MSG_INFO(
"Using " << m_particlesKey.key() <<
" as the input truth container key");
53 ATH_CHECK(m_outputParticlesKey.initialize());
54 ATH_MSG_INFO(
"New truth particles container key: " << m_outputParticlesKey.key() );
56 if (m_partString.empty()) {
58 return StatusCode::FAILURE;
59 }
else {
ATH_MSG_INFO(
"Truth particle selection string: " << m_partString );}
62 if (!m_partString.empty()) {
63 ATH_CHECK( initializeParser(m_partString) );
67 ATH_CHECK(m_originReadDecorKey.initialize());
68 ATH_CHECK(m_typeReadDecorKey.initialize());
69 ATH_CHECK(m_outcomeReadDecorKey.initialize());
70 ATH_CHECK(m_classificationReadDecorKey.initialize());
73 ATH_CHECK(m_linkDecoratorKey.initialize());
74 ATH_CHECK(m_originDecoratorKey.initialize());
75 ATH_CHECK(m_typeDecoratorKey.initialize());
76 ATH_CHECK(m_outcomeDecoratorKey.initialize());
77 ATH_CHECK(m_classificationDecoratorKey.initialize());
78 ATH_CHECK(m_motherIDDecoratorKey.initialize());
79 ATH_CHECK(m_daughterIDDecoratorKey.initialize());
80 ATH_CHECK(m_hadronOriginDecoratorKey.initialize());
82 return StatusCode::SUCCESS;
89 ATH_MSG_INFO(
"Processed "<< m_ntotpart <<
" truth particles, "<< m_npasspart <<
" were retained ");
91 return StatusCode::SUCCESS;
101 static const bool is_sherpa = [
this]() {
102 bool is_sherpa =
false;
110 if (m_metaStore->retrieve(truthMetaData).isSuccess() && !truthMetaData->
empty()){
112 const std::string gens = truthMetaData->
at(0)->generators();
113 is_sherpa = (gens.find(
"sherpa")==std::string::npos &&
114 gens.find(
"Sherpa")==std::string::npos &&
115 gens.find(
"SHERPA")==std::string::npos) ?
false :
true;
118 ATH_MSG_WARNING(
"Found xAODTruthMetaDataContainer empty! Configuring to be NOT Sherpa.");
120 ATH_MSG_INFO(
"From metadata configured: Sherpa? " << is_sherpa);
122 ATH_MSG_WARNING(
"Could not find metadata container in storegate; assuming NOT Sherpa");
129 if (!truthParticles.
isValid()) {
130 ATH_MSG_ERROR(
"Couldn't retrieve TruthParticle collection with name " << m_particlesKey);
131 return StatusCode::FAILURE;
136 ATH_CHECK(newParticlesWriteHandle.
record(std::make_unique<xAOD::TruthParticleContainer>(),
137 std::make_unique<xAOD::TruthParticleAuxContainer>()));
138 ATH_MSG_DEBUG(
"Recorded new TruthParticleContainer with key: " << (m_outputParticlesKey.key()));
141 unsigned int nParticles = truthParticles->
size();
142 m_ntotpart += nParticles;
161 if (!m_partString.empty()) {
162 std::vector<int>
entries = m_parser->evaluateAsVector();
166 ATH_MSG_ERROR(
"Sizes incompatible! Are you sure your selection string used TruthParticles?");
167 return StatusCode::FAILURE;
176 bool SherpaW =
false;
177 bool SherpaZ =
false;
178 if (m_partString.value().find(
"24") != std::string::npos && m_do_sherpa && is_sherpa) {
181 if (m_partString.value().find(
"23") != std::string::npos && m_do_sherpa && is_sherpa) {
184 if ((SherpaW or SherpaZ) && is_sherpa){
191 if ((SherpaW || SherpaZ) && is_sherpa){
193 std::vector<const xAOD::TruthParticle*> status_nonPhysical;
194 for (
unsigned int i=0;
i<nParticles; ++
i) {
196 if (!truthParticles->
at(
i))
continue;
200 if (!
MC::isPhysical(truthParticles->
at(
i))) status_nonPhysical.push_back( truthParticles->
at(
i) );
203 if ((status_nonPhysical.size()==2 || status_nonPhysical.size()==4 || status_nonPhysical.size()==6) && (SherpaZ || SherpaW)){
205 int gens[3] = {0,0,0};
206 for (
size_t i=0;
i<status_nonPhysical.size();++
i){
207 if (status_nonPhysical[
i]->absPdgId()<13) gens[0]++;
208 else if (status_nonPhysical[
i]->absPdgId()<15) gens[1]++;
212 if (gens[0]>2 || gens[0]==1 || gens[1]>2 || gens[1]==1 || gens[2]>2 || gens[2]==1){
214 ATH_MSG_VERBOSE(
"Too many leptons of one generation. Cannot make bosons. Give up");
215 return StatusCode::SUCCESS;
217 std::vector<const xAOD::TruthParticle*> boson;
218 for (
size_t i=0;
i<status_nonPhysical.size();++
i){
219 if (status_nonPhysical[
i]->absPdgId()<13) boson.push_back(status_nonPhysical[
i]);
220 else if (gens[0]==0 && status_nonPhysical[
i]->absPdgId()<15) boson.push_back(status_nonPhysical[
i]);
221 else if (gens[0]==0 && gens[1]==0) boson.push_back(status_nonPhysical[
i]);
222 if (boson.size()==2){
226 if (boson[0]->
pdgId()==-boson[1]->
pdgId()) pdg_id=23;
227 else if (std::abs(boson[0]->
pdgId()+boson[1]->
pdgId())!=1){
232 pdg_id=24*(boson[0]->pdgId()+boson[1]->pdgId());
234 if ( (SherpaW &&
MC::isW(pdg_id)) ||
235 (SherpaZ &&
MC::isZ(pdg_id)) ){
238 newParticlesWriteHandle->
push_back( xTruthParticle );
239 if (m_keep_navigation_info){
240 if (boson[0]->hasProdVtx()) {
241 if ((boson[0]->prodVtx()->nIncomingParticles() > 0) && (boson[0]->prodVtx()->incomingParticle(0)!=
nullptr)) {
242 motherIDDecorator(*xTruthParticle) = boson[0]->prodVtx()->incomingParticle(0)->pdgId();
243 }
else {motherIDDecorator(*xTruthParticle) = 0;}
244 }
else {motherIDDecorator(*xTruthParticle) = 0;}
245 if (boson[0]->hasDecayVtx()) {
246 if ((boson[0]->decayVtx()->nOutgoingParticles() > 0) && (boson[0]->decayVtx()->outgoingParticle(0)!=
nullptr)) {
247 daughterIDDecorator(*xTruthParticle) = boson[0]->decayVtx()->outgoingParticle(0)->pdgId();
248 }
else {daughterIDDecorator(*xTruthParticle) = 0;}
249 }
else {daughterIDDecorator(*xTruthParticle) = 0;}
258 xTruthParticle->
setM(new_mom.M());
259 xTruthParticle->
setPx(new_mom.Px());
260 xTruthParticle->
setPy(new_mom.Py());
261 xTruthParticle->
setPz(new_mom.Pz());
262 xTruthParticle->
setE(new_mom.E());
267 if (gens[0]==0 && gens[1]==0) gens[2]=0;
268 else if (gens[0]==0) gens[1]=0;
273 if (status_nonPhysical.size()==1 || status_nonPhysical.size()==3 || status_nonPhysical.size()==5 || status_nonPhysical.size()>6){
274 ATH_MSG_WARNING(status_nonPhysical.size() <<
" leptons found in the Sherpa event record. Not sure how to deal with this.");
276 return StatusCode::SUCCESS;
278 for (
unsigned int i=0;
i<nParticles; ++
i) {
285 bool same_as_mother =
false;
286 bool same_as_daughter =
false;
290 same_as_mother =
true;
297 same_as_daughter =
true;
301 if (same_as_mother && same_as_daughter){
307 newParticlesWriteHandle->
push_back( xTruthParticle );
308 if (m_keep_navigation_info){
312 }
else {motherIDDecorator(*xTruthParticle) = 0;}
313 }
else {motherIDDecorator(*xTruthParticle) = 0;}
317 }
else {daughterIDDecorator(*xTruthParticle) = 0;}
318 }
else {daughterIDDecorator(*xTruthParticle) = 0;}
321 *xTruthParticle=*theParticle;
323 typeDecorator(*xTruthParticle) =
324 typeReadDecor(*theParticle);
326 originDecorator(*xTruthParticle) =
327 originReadDecor(*theParticle);
329 outcomeDecorator(*xTruthParticle) =
330 outcomeReadDecor(*theParticle);
332 classificationDecorator(*xTruthParticle) =
333 classificationReadDecor(*theParticle);
335 if (m_outputParticlesKey.key()==
"TruthHFHadrons"){
337 hadronOriginDecorator(*xTruthParticle) =
338 TopHadronOriginFlagAcc.
withDefault (*theParticle, 0);
341 if(m_keep_navigation_info) linkDecorator(*xTruthParticle) = eltp;
346 for (
unsigned int i=0;
i<nParticles; ++
i)
if (
entries[
i]) ++m_npasspart;
349 return StatusCode::SUCCESS;