127{
128
131
132
133 SG::ThinningHandle<xAOD::TruthParticleContainer> inTruthParts
135 SG::ThinningHandle<xAOD::TruthVertexContainer> inTruthVerts
137
138 SG::ReadHandle<xAOD::TruthParticleContainer> inHardParts(
m_hardParticleKey, ctx);
139 if (!inHardParts.isValid()) {
141 return StatusCode::FAILURE;
142 }
143
144
145
146
147
148
149 std::vector<const xAOD::TruthParticle*> hardPart;
150 std::vector<TLorentzVector> pLepGam;
151
152 for (const auto* pItr : *inHardParts) {
154 hardPart.push_back(pItr);
156 int ida = pItr->absPdgId();
158 pLepGam.push_back( pItr->p4() );
159 }
160 }
161 }
162 }
163
164
165 long long int evtNum{};
166 if( doPrint ){
170 return StatusCode::FAILURE;
171 }
172 evtNum =
evt->eventNumber();
173
175 }
176
177
178
179
180
181 std::vector<bool> partMask;
182 std::vector<bool> vertMask;
183 unsigned int inPartNum = inTruthParts->size();
184 unsigned int inVertNum = inTruthVerts->size();
185 partMask.assign(inPartNum, false);
186 vertMask.assign(inVertNum, false);
187
188 ATH_MSG_DEBUG(
"Initial particles/vertices = " <<inPartNum <<
" " <<inVertNum);
189
190
191
192
193
194
195
196
197 std::vector<const xAOD::TruthParticle*> kids;
198
199 for (const auto* pItr : *inTruthParts) {
200
202 bool isHard = false;
203 for(
unsigned int i=0;
i<hardPart.size(); ++
i){
205 isHard = true;
206 if( pItr->pdgId() != (hardPart[i])->pdgId() ){
210 <<" " <<(hardPart[i])->pdgId());
212 break;
213 }
214 }
215 }
216 if( isHard ){
218 partMask[ pItr->index() ] = true;
219 }
220
221
222 int ida = pItr->absPdgId();
223 bool isKeep = false;
226 isKeep = true;
227 break;
228 }
229 }
230 if( isKeep ){
232 partMask[pItr->index()] = true;
234 for(
int i=0;
i<nkids; ++
i){
237 partMask[ (kids[
i])->
index() ] =
true;
239 if( v ) vertMask[
v->index() ] =
true;
240 }
241 }
242
243
244 if( !pLepGam.empty() && pItr->pt() >
m_isolPtCut ){
245 TLorentzVector pp4 = pItr->p4();
246 for(unsigned int lep=0; lep<pLepGam.size(); ++lep){
247 double r = pp4.DeltaR( pLepGam[lep] );
250 partMask[ pItr->index() ] = true;
251 }
252 }
253 }
254 }
255
256
257
258
259
260
262
264 if (!inJets.isValid()) {
266 return StatusCode::FAILURE;
267 }
268
269 std::vector<int> uidJetConst;
270
271 for(const auto* ajet : *inJets){
273 if( std::abs(ajet->eta()) >
m_jetEtaCut )
continue;
274
275 xAOD::JetConstituentVector aconst = ajet->getConstituents();
276 xAOD::JetConstituentVector::iterator aItr = aconst.
begin();
277 xAOD::JetConstituentVector::iterator aItrE = aconst.
end();
278 for( ; aItr != aItrE; ++aItr){
279 const xAOD::JetConstituent* aip = (*aItr);
283 if( pp ) {
286 }
289 }
290 } else {
292 }
293 }
294 }
295
296 for (const auto* pItr : *inTruthParts) {
298 bool isJet = false;
299 for(
unsigned int i=0;
i<uidJetConst.size(); ++
i){
300 if( uid == uidJetConst[i] ){
301 isJet = true;
302 break;
303 }
304 }
305 if( isJet ){
307 partMask[ pItr->index() ] = true;
308 }
309 }
310
311 }
312
313
314
315 inTruthParts.keep (partMask);
316 inTruthVerts.keep (vertMask);
317
318
319 int outPartNum = 0;
320 for(
unsigned int i=0;
i<partMask.size(); ++
i){
321 if( partMask[i] ) ++outPartNum;
322 }
323 int outVertNum = 0;
324 for(
unsigned int i=0;
i<vertMask.size(); ++
i){
325 if( vertMask[i] ) ++outVertNum;
326 }
327
328 ATH_MSG_DEBUG(
"Final particles/vertices = " <<outPartNum <<
" " <<outVertNum);
329
330 if( doPrint ){
331 std::cout <<"======================================================================================" <<std::endl;
332 std::cout <<"HardTruthThinning complete for event " <<evtNum <<std::endl;
333 std::cout <<"Saved " <<outPartNum <<" particles" <<std::endl;
334 std::cout <<"Particle unique IDs = ";
335 for(
unsigned int i=0;
i<partMask.size(); ++
i){
336 if( partMask[i] ) std::cout <<
HepMC::uniqueID((*inTruthParts)[i]) <<
" ";
337 }
338 std::cout <<std::endl;
339
340 std::cout <<"Saved " <<outVertNum <<" vertices" <<std::endl;
341 std::cout <<"Vertex unique IDs = ";
342 for(
unsigned int i=0;
i<vertMask.size(); ++
i){
343 if( vertMask[i] ) std::cout <<
HepMC::uniqueID((*inTruthVerts)[i]) <<
" ";
344 }
345 std::cout <<std::endl;
346 std::cout <<"======================================================================================" <<std::endl;
347 }
348
349 return StatusCode::SUCCESS;
350
351}
#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.