128{
129 const EventContext& ctx = Gaudi::Hive::currentContext();
130
133
134
135 SG::ThinningHandle<xAOD::TruthParticleContainer> inTruthParts
137 SG::ThinningHandle<xAOD::TruthVertexContainer> inTruthVerts
139
140 SG::ReadHandle<xAOD::TruthParticleContainer> inHardParts(
m_hardParticleKey, ctx);
141 if (!inHardParts.isValid()) {
143 return StatusCode::FAILURE;
144 }
145
146
147
148
149
150
151 std::vector<const xAOD::TruthParticle*> hardPart;
152 std::vector<TLorentzVector> pLepGam;
153
154 for (const auto* pItr : *inHardParts) {
156 hardPart.push_back(pItr);
158 int ida = pItr->absPdgId();
160 pLepGam.push_back( pItr->p4() );
161 }
162 }
163 }
164 }
165
166
167 long long int evtNum{};
168 if( doPrint ){
172 return StatusCode::FAILURE;
173 }
174 evtNum =
evt->eventNumber();
175
177 }
178
179
180
181
182
183 std::vector<bool> partMask;
184 std::vector<bool> vertMask;
185 unsigned int inPartNum = inTruthParts->size();
186 unsigned int inVertNum = inTruthVerts->size();
187 partMask.assign(inPartNum, false);
188 vertMask.assign(inVertNum, false);
189
190 ATH_MSG_DEBUG(
"Initial particles/vertices = " <<inPartNum <<
" " <<inVertNum);
191
192
193
194
195
196
197
198
199 std::vector<const xAOD::TruthParticle*> kids;
200
201 for (const auto* pItr : *inTruthParts) {
202
204 bool isHard = false;
205 for(
unsigned int i=0;
i<hardPart.size(); ++
i){
207 isHard = true;
208 if( pItr->pdgId() != (hardPart[i])->pdgId() ){
212 <<" " <<(hardPart[i])->pdgId());
214 break;
215 }
216 }
217 }
218 if( isHard ){
220 partMask[ pItr->index() ] = true;
221 }
222
223
224 int ida = pItr->absPdgId();
225 bool isKeep = false;
228 isKeep = true;
229 break;
230 }
231 }
232 if( isKeep ){
234 partMask[pItr->index()] = true;
236 for(
int i=0;
i<nkids; ++
i){
239 partMask[ (kids[
i])->
index() ] =
true;
241 if( v ) vertMask[
v->index() ] =
true;
242 }
243 }
244
245
246 if( !pLepGam.empty() && pItr->pt() >
m_isolPtCut ){
247 TLorentzVector pp4 = pItr->p4();
248 for(unsigned int lep=0; lep<pLepGam.size(); ++lep){
249 double r = pp4.DeltaR( pLepGam[lep] );
252 partMask[ pItr->index() ] = true;
253 }
254 }
255 }
256 }
257
258
259
260
261
262
264
266 if (!inJets.isValid()) {
268 return StatusCode::FAILURE;
269 }
270
271 std::vector<int> uidJetConst;
272
273 for(const auto* ajet : *inJets){
275 if( std::abs(ajet->eta()) >
m_jetEtaCut )
continue;
276
277 xAOD::JetConstituentVector aconst = ajet->getConstituents();
278 xAOD::JetConstituentVector::iterator aItr = aconst.
begin();
279 xAOD::JetConstituentVector::iterator aItrE = aconst.
end();
280 for( ; aItr != aItrE; ++aItr){
281 const xAOD::JetConstituent* aip = (*aItr);
285 if( pp ) {
288 }
291 }
292 } else {
294 }
295 }
296 }
297
298 for (const auto* pItr : *inTruthParts) {
300 bool isJet = false;
301 for(
unsigned int i=0;
i<uidJetConst.size(); ++
i){
302 if( uid == uidJetConst[i] ){
303 isJet = true;
304 break;
305 }
306 }
307 if( isJet ){
309 partMask[ pItr->index() ] = true;
310 }
311 }
312
313 }
314
315
316
317 inTruthParts.keep (partMask);
318 inTruthVerts.keep (vertMask);
319
320
321 int outPartNum = 0;
322 for(
unsigned int i=0;
i<partMask.size(); ++
i){
323 if( partMask[i] ) ++outPartNum;
324 }
325 int outVertNum = 0;
326 for(
unsigned int i=0;
i<vertMask.size(); ++
i){
327 if( vertMask[i] ) ++outVertNum;
328 }
329
330 ATH_MSG_DEBUG(
"Final particles/vertices = " <<outPartNum <<
" " <<outVertNum);
331
332 if( doPrint ){
333 std::cout <<"======================================================================================" <<std::endl;
334 std::cout <<"HardTruthThinning complete for event " <<evtNum <<std::endl;
335 std::cout <<"Saved " <<outPartNum <<" particles" <<std::endl;
336 std::cout <<"Particle unique IDs = ";
337 for(
unsigned int i=0;
i<partMask.size(); ++
i){
338 if( partMask[i] ) std::cout <<
HepMC::uniqueID((*inTruthParts)[i]) <<
" ";
339 }
340 std::cout <<std::endl;
341
342 std::cout <<"Saved " <<outVertNum <<" vertices" <<std::endl;
343 std::cout <<"Vertex unique IDs = ";
344 for(
unsigned int i=0;
i<vertMask.size(); ++
i){
345 if( vertMask[i] ) std::cout <<
HepMC::uniqueID((*inTruthVerts)[i]) <<
" ";
346 }
347 std::cout <<std::endl;
348 std::cout <<"======================================================================================" <<std::endl;
349 }
350
351 return StatusCode::SUCCESS;
352
353}
#define ATH_MSG_WARNING(x)
SG::ThinningHandleKey< xAOD::TruthVertexContainer > m_truthVertexName
static void printxAODTruth(long long evnum, const xAOD::TruthParticleContainer *truths)
std::atomic< int > m_errCount
SG::ThinningHandleKey< xAOD::TruthParticleContainer > m_truthParticleName
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_hardParticleKey
std::atomic< int > m_evtCount
SG::ReadHandleKey< xAOD::JetContainer > m_truthJetsKey
static int getDescendants(const xAOD::TruthParticle *p, std::vector< const xAOD::TruthParticle * > &d)
iterator begin() const
iterator on the first constituent
iterator end() const
iterator after the last constituent
const IParticle * rawConstituent() const
Access the real underlying IParticle.
virtual double pt() const override final
The transverse momentum ( ) of the particle.
bool isPhoton(const T &p)
bool isElectron(const T &p)
bool isStable(const T &p)
Identify if the particle is stable, i.e. has not decayed.
TruthVertex_v1 TruthVertex
Typedef to implementation.
TruthParticle_v1 TruthParticle
Typedef to implementation.