24 #include "GaudiKernel/SystemOfUnits.h"
26 #include "GaudiKernel/ThreadLocalContext.h"
46 const std::string&
t,
const std::string&
n,
const IInterface*
p ) :
57 "hard particle container name");
60 "truth jet container name");
63 "truth jet minumum pt");
66 "truth jet maximum abs(eta)");
69 "jet constituent minimum pt");
72 "jet constituent photon minimum pt");
75 "list of abs(pdgID) to keep");
77 declareProperty(
"IsolRadius",
m_isolR,
78 "isolation radius for leptons and photons");
81 "isolation particle minimum pt");
83 declareProperty(
"MaxCount",
85 "maximum number of events to print");
104 ATH_CHECK (m_truthParticleName.initialize (m_streamName) );
105 ATH_CHECK (m_truthVertexName.initialize (m_streamName) );
111 if( m_jetPhotonPtCut < m_jetConstPtCut ) m_jetPhotonPtCut =m_jetConstPtCut;
113 return StatusCode::SUCCESS;
120 if( m_errCount > 0 ){
121 ATH_MSG_WARNING(
"TruthHard/TruthEvent pdgId mismatches " <<m_errCount);
123 ATH_MSG_INFO(
"No TruthHard/TruthEvent pdgId mismatches");
126 return StatusCode::SUCCESS;
136 const EventContext& ctx = Gaudi::Hive::currentContext();
139 bool doPrint = m_evtCount < m_maxCount;
146 return StatusCode::FAILURE;
148 long long int evtNum =
evt->eventNumber();
156 (m_truthParticleName, ctx);
158 (m_truthVertexName, ctx);
161 if( evtStore()->
retrieve(inHardParts, m_hardParticleName).isFailure() ){
163 <<m_hardParticleName);
164 return StatusCode::FAILURE;
172 std::vector<const xAOD::TruthParticle*> hardPart;
173 std::vector<TLorentzVector> pLepGam;
175 pItr = inHardParts->
begin();
176 pItrE = inHardParts->
end();
177 for(; pItr!=pItrE; ++pItr){
179 hardPart.push_back(*pItr);
181 int ida = abs( (*pItr)->pdgId() );
182 if( ida==11 || ida==13 || ida==15 || ida==22 ){
183 pLepGam.push_back( (*pItr)->p4() );
192 printxAODTruth(evtNum, inTruthParts.cptr());
199 std::vector<bool> partMask;
200 std::vector<bool> vertMask;
201 unsigned int inPartNum = inTruthParts->size();
202 unsigned int inVertNum = inTruthVerts->size();
203 partMask.assign(inPartNum,
false);
204 vertMask.assign(inVertNum,
false);
206 ATH_MSG_DEBUG(
"Initial particles/vertices = " <<inPartNum <<
" " <<inVertNum);
215 pItr = inTruthParts->begin();
216 pItrE = inTruthParts->end();
217 std::vector<const xAOD::TruthParticle*> kids;
219 for(; pItr!=pItrE; ++pItr){
224 for(
unsigned int i=0;
i<hardPart.size(); ++
i){
227 if( (*pItr)->pdgId() != (hardPart[
i])->pdgId() ){
231 <<
" " <<(hardPart[
i])->pdgId());
239 partMask[ (*pItr)->index() ] =
true;
243 int ida = abs((*pItr)->pdgId());
245 for(
unsigned int i=0;
i<m_keepIds.size(); ++
i){
246 if( ida == m_keepIds[
i] ){
253 partMask[(*pItr)->index()] =
true;
255 int nkids = getDescendants( ppItr, kids );
256 for(
int i=0;
i<nkids; ++
i){
259 partMask[ (kids[
i])->
index() ] =
true;
261 if(
v ) vertMask[
v->index() ] =
true;
266 if( !pLepGam.empty() && (*pItr)->pt() > m_isolPtCut ){
267 TLorentzVector pp4 = (*pItr)->p4();
268 for(
unsigned int lep=0; lep<pLepGam.size(); ++lep){
269 double r = pp4.DeltaR( pLepGam[lep] );
272 partMask[ (*pItr)->index() ] =
true;
285 if( !m_jetName.empty() ){
288 if( evtStore()->
retrieve(inJets, m_jetName).isFailure() ){
289 ATH_MSG_ERROR(
"No JetContainer found with name " <<m_jetName);
290 return StatusCode::FAILURE;
293 std::vector<int> uidJetConst;
295 for(
unsigned int j=0; j<inJets->
size(); ++j){
297 if( ajet->
pt() < m_jetPtCut )
continue;
298 if( std::abs(ajet->
eta()) > m_jetEtaCut )
continue;
303 for( ; aItr != aItrE; ++aItr){
309 if( pp->
pt()>m_jetConstPtCut && pp->
pdgId()!=22 ){
312 if( pp->
pt()>m_jetPhotonPtCut && pp->
pdgId()==22 ){
321 pItr = inTruthParts->begin();
322 pItrE = inTruthParts->end();
323 for(; pItr!=pItrE; ++pItr){
326 for(
unsigned int i=0;
i<uidJetConst.size(); ++
i){
327 if( uid == uidJetConst[
i] ){
334 partMask[ (*pItr)->index() ] =
true;
342 inTruthParts.
keep (partMask);
343 inTruthVerts.
keep (vertMask);
347 for(
unsigned int i=0;
i<partMask.size(); ++
i){
348 if( partMask[
i] ) ++outPartNum;
351 for(
unsigned int i=0;
i<vertMask.size(); ++
i){
352 if( vertMask[
i] ) ++outVertNum;
355 ATH_MSG_DEBUG(
"Final particles/vertices = " <<outPartNum <<
" " <<outVertNum);
358 std::cout <<
"======================================================================================" <<std::endl;
359 std::cout <<
"HardTruthThinning complete for event " <<evtNum <<std::endl;
360 std::cout <<
"Saved " <<outPartNum <<
" particles" <<std::endl;
361 std::cout <<
"Particle unique IDs = ";
362 for(
unsigned int i=0;
i<partMask.size(); ++
i){
365 std::cout <<std::endl;
367 std::cout <<
"Saved " <<outVertNum <<
" vertices" <<std::endl;
368 std::cout <<
"Vertex unique IDs = ";
369 for(
unsigned int i=0;
i<vertMask.size(); ++
i){
372 std::cout <<std::endl;
373 std::cout <<
"======================================================================================" <<std::endl;
376 return StatusCode::SUCCESS;
392 std::vector<const xAOD::TruthParticle*>& descendants ) {
394 if( ! (
p->hasDecayVtx()) )
return 0;
396 if( !dvtx )
return 0;
399 const std::vector< ElementLink< xAOD::TruthParticleContainer > >& outPart =
401 for(
unsigned int k=0;
k<outPart.size(); ++
k){
402 if( ! (outPart[
k]).
isValid() )
continue;
404 descendants.push_back(kid);
408 int nstop = descendants.size();
410 while( nstop > nstart ){
411 for(
int i=nstart;
i<nstop; ++
i){
418 const std::vector< ElementLink< xAOD::TruthParticleContainer > >&
420 for(
unsigned int k=0;
k<outPart2.size(); ++
k){
421 if( ! (outPart2[
k]).isValid() )
continue;
425 for(
unsigned int kk=0;
kk<descendants.size(); ++
kk){
426 if(kpp==descendants[
kk]) isIn =
true;
428 if( !isIn ) descendants.push_back(kpp);
432 nstop = descendants.size();
447 std::vector<int> uidPars;
448 std::vector<int> uidKids;
450 std::cout <<
"======================================================================================" <<std::endl;
451 std::cout <<
"xAODTruth Event " <<evnum <<std::endl;
452 std::cout <<
" Unique ID PDG Id Status px(GeV) py(GeV) pz(GeV) E(GeV) Parent: Decay" <<std::endl;
453 std::cout <<
" -----------------------------------------------------------------------------------" <<std::endl;
455 for(; tpItr != tpItrE; ++tpItr ) {
458 int id = (*tpItr)->pdgId();
459 int stat = (*tpItr)->status();
460 float px = (*tpItr)->px()/1000.;
461 float py = (*tpItr)->py()/1000.;
462 float pz = (*tpItr)->pz()/1000.;
463 float e = (*tpItr)->e()/1000.;
467 if( (*tpItr)->hasProdVtx() ){
470 const std::vector< ElementLink< xAOD::TruthParticleContainer > >&
pars =
472 for(
unsigned int k=0;
k<
pars.size(); ++
k){
479 if( (*tpItr)->hasDecayVtx() ){
482 const std::vector< ElementLink< xAOD::TruthParticleContainer > >& kids =
484 for(
unsigned int k=0;
k<kids.size(); ++
k){
485 if( ! (kids[
k]).isValid() )
continue;
492 std::cout <<std::setw(10)<<uid <<std::setw(12)<<
id
494 <<std::setprecision(2)<<std::fixed
495 <<std::setw(10)<<
px <<std::setw(10)<<
py
496 <<std::setw(10)<<
pz <<std::setw(10)<<
e <<
" ";
498 for(
unsigned int k=0;
k<uidPars.size(); ++
k){
499 std::cout <<uidPars[
k] <<
" ";
502 for(
unsigned int k=0;
k<uidKids.size(); ++
k){
503 std::cout <<uidKids[
k] <<
" ";
505 std::cout <<std::endl;
507 std::cout <<
"======================================================================================" <<std::endl;