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()) {
131 return StatusCode::FAILURE;
136 ATH_CHECK(newParticlesWriteHandle.record(std::make_unique<xAOD::TruthParticleContainer>(),
137 std::make_unique<xAOD::TruthParticleAuxContainer>()));
141 unsigned int nParticles = truthParticles->size();
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;
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 );
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 );
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);
337 hadronOriginDecorator(*xTruthParticle) =
338 TopHadronOriginFlagAcc.withDefault (*theParticle, 0);
349 return StatusCode::SUCCESS;