35 #include "GaudiKernel/MsgStream.h"
41 #include "TLorentzVector.h"
91 return StatusCode::SUCCESS;
101 const EventContext& context = Gaudi::Hive::currentContext();
103 xTruthParticleContainer(
105 if (!xTruthParticleContainer.
isValid()) {
106 ATH_MSG_ERROR(
"Could not retrieve xAOD::TruthParticleGenContainer with key:"
109 return StatusCode::FAILURE;
118 std::vector<const xAOD::TruthParticle *> Muons;
120 unsigned int nPart = xTruthParticleContainer->
size();
121 ATH_MSG_DEBUG(
"xAODMuDstarFilter:number of particles " << nPart);
131 ATH_MSG_DEBUG(
"xAODMuDstarFilter: PV x, y = " << primx <<
" , " << primy);
145 Muons.push_back(pitr);
151 setFilterPassed(
false);
152 return StatusCode::SUCCESS;
155 ATH_MSG_DEBUG(
"xAODMuDstarFilter: NumMuons = " << NumMuons );
162 if (std::abs(pitr->pdgId()) == MC::DSTAR)
170 if (!(pitr->decayVtx()))
172 double Rxy = std::hypot(pitr->decayVtx()->x() - primx, pitr->decayVtx()->y() - primy);
179 auto firstChild = pitr->decayVtx()->outgoingParticle(0);
180 if (firstChild->pdgId() == pitr->pdgId())
183 TLorentzVector p4_pis;
191 for (
size_t thisChild_id = 0; thisChild_id < pitr->decayVtx()->nOutgoingParticles(); thisChild_id++)
194 auto thisChild = pitr->decayVtx()->outgoingParticle(thisChild_id);
198 if (std::abs(thisChild->pdgId()) == MC::PIPLUS)
206 p4_pis.SetPtEtaPhiM(thisChild->pt(), thisChild->eta(), thisChild->phi(),
m_PionMass);
207 pis_pdg = thisChild->pdgId();
220 int NumChildD0Charged = 0;
221 int NumChildD0neutrinos = 0;
222 int NumChildD0gammas = 0;
223 int ChargeD0Child1 = 0;
224 int ChargeD0Child2 = 0;
226 int NumChildD0pi = 0;
227 int NumChildD0mu = 0;
229 for (
size_t thisChild_id = 0; thisChild_id < pitr->decayVtx()->nOutgoingParticles(); thisChild_id++)
235 if (std::abs(thisChild->pdgId()) == MC::D0)
237 if (! thisChild->decayVtx())
continue;
239 for (
size_t thisChild1_id = 0; thisChild1_id < thisChild->decayVtx()->nOutgoingParticles(); thisChild1_id++)
245 if (thisChild1->isElectron() || thisChild1->isMuon() ||
246 std::abs(thisChild1->pdgId()) == MC::PIPLUS || std::abs(thisChild1->pdgId()) == MC::KPLUS)
256 if (NumChildD0Charged == 1)
258 D0Child1 = thisChild1;
259 ChargeD0Child1 = D0Child1->
charge();
261 if (NumChildD0Charged == 2)
263 D0Child2 = thisChild1;
264 ChargeD0Child2 = D0Child2->charge();
266 if (thisChild1->isMuon())
269 D0ChildMu = thisChild1;
271 if (std::abs(thisChild1->pdgId()) == MC::PIPLUS)
273 if (std::abs(thisChild1->pdgId()) == MC::KPLUS)
276 K_pdg = thisChild1->pdgId();
280 else if (std::abs(thisChild1->pdgId()) == MC::PI0)
284 else if (thisChild1->isNeutrino())
286 NumChildD0neutrinos++;
288 else if (thisChild1->isPhoton())
292 else if (std::abs(thisChild1->pdgId()) == MC::K0 || std::abs(thisChild1->pdgId()) == MC::K0L ||
293 std::abs(thisChild1->pdgId()) == MC::K0S)
298 else if (thisChild1->decayVtx())
300 for (
size_t thisChild2_id = 0; thisChild2_id < thisChild1->decayVtx()->nOutgoingParticles(); thisChild2_id++)
303 auto thisChild2 = thisChild1->decayVtx()->outgoingParticle(thisChild2_id);
307 if (thisChild2->isElectron() || thisChild2->isMuon() ||
308 std::abs(thisChild2->pdgId()) == MC::PIPLUS || std::abs(thisChild2->pdgId()) == MC::KPLUS)
318 if (NumChildD0Charged == 1)
320 D0Child1 = thisChild2;
321 ChargeD0Child2 = D0Child1->charge();
323 if (NumChildD0Charged == 2)
325 D0Child2 = thisChild2;
326 ChargeD0Child2 = D0Child2->charge();
328 if (thisChild2->isMuon())
331 D0ChildMu = thisChild2;
335 else if (std::abs(thisChild2->pdgId()) == MC::PI0)
339 else if (thisChild2->isNeutrino())
341 NumChildD0neutrinos++;
343 else if (thisChild2->isPhoton())
347 else if (std::abs(thisChild2->pdgId()) == MC::K0 || std::abs(thisChild2->pdgId()) == MC::K0L ||
348 std::abs(thisChild2->pdgId()) == MC::K0S)
353 else if (thisChild2->decayVtx())
362 ATH_MSG_DEBUG(
"xAODMuDstarFilter: unexpected D0 granddaughter = " << thisChild2->pdgId());
370 ATH_MSG_DEBUG(
"xAODMuDstarFilter: unexpected D0 daughter = " << thisChild1->pdgId());
374 ATH_MSG_DEBUG(
"xAODMuDstarFilter: NumChildD0, NumChildD0Charged = " << NumChildD0 <<
" , " << NumChildD0Charged);
376 if (NumChildD0 <= 3 && NumChildD0Charged == 2 && ChargeD0Child1 * ChargeD0Child2 < 0)
380 if (NumChildD0 == 2 && NumChildD0K == 1 && NumChildD0pi == 1){
396 if (pis_pdg * ChargeD0Child1 > 0)
std::swap(D0Child1, D0Child2);
398 p4_K.SetPtEtaPhiM(D0Child1->pt(), D0Child1->eta(), D0Child1->phi(),
m_KaonMass);
399 TLorentzVector p4_pi;
400 p4_pi.SetPtEtaPhiM(D0Child2->pt(), D0Child2->eta(), D0Child2->phi(),
m_PionMass);
402 TLorentzVector p4_D0 = p4_K + p4_pi;
403 double mKpi = p4_D0.M();
410 TLorentzVector p4_Dstar = p4_D0 + p4_pis;
412 double delta_m = p4_Dstar.M() - mKpi;
420 ATH_MSG_DEBUG(
"xAODMuDstarFilter: NumDstars = " << NumDstars);
422 for (
size_t i = 0;
i < Muons.size(); ++
i)
425 if (NumChildD0mu == 1)
427 if (std::fabs(Muons[
i]->
pt() - D0ChildMu->pt()) < std::numeric_limits<double>::epsilon())
429 ATH_MSG_DEBUG(
"xAODMuDstarFilter: Mu(pT), D0Mu(pT) = " << Muons[
i]->
pt() <<
" , " << D0ChildMu->pt());
432 TLorentzVector p4_Mu;
435 TLorentzVector p4_DstarMu = p4_Dstar + p4_Mu;
437 ATH_MSG_DEBUG(
"xAODMuDstarFilter: p4_DstarMu.M() = " << p4_DstarMu.M());
443 ATH_MSG_DEBUG(
"xAODMuDstarFilter: p4_DstarMu.M() = " << p4_DstarMu.M());
444 ATH_MSG_DEBUG(
"xAODMuDstarFilter: NumChildD0, NumChildD0Charged = " << NumChildD0 <<
" , " << NumChildD0Charged);
445 ATH_MSG_DEBUG(
"xAODMuDstarFilter: NumChildD0K, NumChildD0pi, NumChildD0mu = " << NumChildD0K <<
" , " << NumChildD0pi <<
" , " << NumChildD0mu);
447 if (NumChildD0mu == 1)
450 ATH_MSG_DEBUG(
"xAODMuDstarFilter: Mu(pT), D0Mu(pT) = " << Muons[
i]->
pt() <<
" , " << D0ChildMu->pt());
453 ATH_MSG_DEBUG(
"xAODMuDstarFilter: NumChildD0neutrinos, NumChildD0gammas = " << NumChildD0neutrinos <<
" , " << NumChildD0gammas);
454 ATH_MSG_DEBUG(
"xAODMuDstarFilter: pis_pdg, K_pdg, ChargeD0Child1, ChargeD0Child2 = " << pis_pdg <<
" , " << K_pdg <<
" , " << ChargeD0Child1 <<
" , " << ChargeD0Child2);
456 setFilterPassed(
true);
457 return StatusCode::SUCCESS;
476 setFilterPassed(
false);
477 return StatusCode::SUCCESS;