20 bool isLastTop =
false;
21 bool isFirstTop =
false;
22 double topPairInvariantMass = 0.;
23 std::vector<HepMC::ConstGenParticlePtr> tops;
24 std::vector<HepMC::ConstGenVertexPtr> top_vtxs;
27 const HepMC::GenEvent* genEvt = (*itr);
29 for (
const auto& mcpart: *genEvt) {
36 if (std::abs(mcpart->pdg_id()) == 6) {
39 auto decayVtx = mcpart->end_vertex();
42 ATH_MSG_WARNING(
"top particle" << mcpart <<
" has no valid decay vertex. ");
43 ATH_MSG_WARNING(
"It looks like a Pythia history particle. Skip this particle ");
49 for (
const auto& child_mcpart: decayVtx->particles_out() ) {
50 if (std::abs(child_mcpart->pdg_id()) == 6) {
59 ATH_MSG_DEBUG(
"Top particle " << mcpart <<
" is found and stored");
60 tops.push_back(mcpart);
69 auto prodVtx = mcpart->production_vertex();
71 ATH_MSG_WARNING(
"Top particle " << mcpart <<
" has no valid production vertex");
73 top_vtxs.emplace_back(
nullptr);
76 while (!isFirstTop && prodVtx) {
78 for (
const auto& mother_mcpart: prodVtx->particles_in()) {
80 if (mother_mcpart->pdg_id() == 6) {
82 prodVtx = mother_mcpart->production_vertex();
84 ATH_MSG_WARNING(
"mother particle is still a top " << mcpart <<
", but has no valid production vertex");
85 top_vtxs.emplace_back(
nullptr);
100 top_vtxs.push_back(prodVtx);
109 if (tops[tops.size()-1]->pdg_id() == 6)
top++;
else topbar++;
113 if (
top==1 && topbar==1)
break;
120 if (
top > 1 || topbar > 1)
ATH_MSG_INFO(
"More than one top-pair exist in the event.");
125 if (
top==2 && topbar==2)
break;
130 HepMC::GenEvent::particle_const_iterator pitr = genEvt->particles_begin();
131 for (; pitr!=genEvt->particles_end(); ++pitr) {
139 if (std::abs(mcpart->pdg_id()) == 6) {
142 HepMC::GenVertex* decayVtx = mcpart->end_vertex();
145 ATH_MSG_WARNING(
"top particle " << mcpart <<
" has no valid decay vertex. ");
146 ATH_MSG_WARNING(
"It looks like a Pythia history particle. Skip this particle ");
153 HepMC::GenVertex::particles_out_const_iterator child_mcpartItr = decayVtx->particles_out_const_begin();
154 HepMC::GenVertex::particles_out_const_iterator child_mcpartItrE = decayVtx->particles_out_const_end();
155 for (; child_mcpartItr!=child_mcpartItrE; ++child_mcpartItr) {
157 if (std::abs(child_mcpart->pdg_id()) == 6) {
166 ATH_MSG_DEBUG(
"Top particle " << mcpart <<
" is found and stored");
167 tops.push_back(mcpart);
176 HepMC::GenVertex* prodVtx = mcpart->production_vertex();
178 ATH_MSG_WARNING(
"Top particle " << mcpart <<
" has no valid production vertex");
180 top_vtxs.push_back(NULL);
183 while (!isFirstTop && prodVtx) {
185 HepMC::GenVertex::particles_in_const_iterator mother_mcpartItr = prodVtx->particles_in_const_begin();
186 HepMC::GenVertex::particles_in_const_iterator mother_mcpartItrE = prodVtx->particles_in_const_end();
187 for (; mother_mcpartItr != mother_mcpartItrE; ++mother_mcpartItr) {
190 if (mother_mcpart->pdg_id() == 6) {
192 prodVtx = mother_mcpart->production_vertex();
194 ATH_MSG_WARNING(
"mother particle is still a top " << mcpart <<
", but has no valid production vertex");
195 top_vtxs.push_back(NULL);
210 top_vtxs.push_back(prodVtx);
219 if (tops[tops.size()-1]->pdg_id() == 6)
top++;
else topbar++;
223 if (
top==1 && topbar==1)
break;
230 if (
top > 1 || topbar > 1)
ATH_MSG_INFO(
"More than one top-pair exist in the event.");
235 if (
top==2 && topbar==2)
break;
244 if (tops.size()==2) {
245 HepMC::FourVector topSumMomentum(0.,0.,0.,0.);
250 topPairInvariantMass = topSumMomentum.m();
257 else if (tops.size() == 4 && top_vtxs.size() == 4) {
258 HepMC::FourVector topSumMomentum_1(0.,0.,0.,0.);
259 HepMC::FourVector topSumMomentum_2(0.,0.,0.,0.);
260 double topPairInvMass_1=0.;
261 double topPairInvMass_2=0.;
264 auto prodVtx = top_vtxs[0];
269 for (
size_t i = 1;
i < top_vtxs.size(); ++
i) {
270 if (top_vtxs[
i] == prodVtx) top_12=
i;
272 if (top_21 < 0) top_21 =
i;
279 ATH_MSG_ERROR(
"First top particle doesn't share the production vertex to any other top particles. Event failed the filter");
280 setFilterPassed(
false);
281 return StatusCode::SUCCESS;
283 if ((top_21 < 0) or (top_22 < 0)) {
285 setFilterPassed(
false);
286 return StatusCode::SUCCESS;
290 if (top_vtxs[top_21] != top_vtxs[top_22]) {
291 ATH_MSG_ERROR(
"Production vertex for the second top-pair particles is not the same. Event failed the filter");
292 setFilterPassed(
false);
293 return StatusCode::SUCCESS;
297 if (tops[top_11]->pdg_id() == tops[top_12]->pdg_id())
ATH_MSG_ERROR(
"first top-pair particles have the same charge");
304 topPairInvMass_1 = topSumMomentum_1.m();
308 if (tops[top_21]->pdg_id() == tops[top_21]->pdg_id())
ATH_MSG_ERROR(
"second top-pair particles have the same charge");
315 topPairInvMass_2 = topSumMomentum_2.m();
319 topPairInvariantMass =
std::max(topPairInvMass_1, topPairInvMass_2);
323 else ATH_MSG_ERROR(
"Size of the collected final top particles vector " << tops.size() <<
324 " doesn't match to the size of there production vertices vector size " << top_vtxs.size() <<
325 ". Event fails the filter");
331 if (tops.size() != 2 && tops.size() != 4) {
332 ATH_MSG_WARNING(
"1 or 2 top-pairs are expected in the event. But there are " << tops.size() <<
" final-status top particles.");
337 ATH_MSG_DEBUG(
"The top-pair invariant mass is " << topPairInvariantMass <<
" CLHEP::MeV");
338 return StatusCode::SUCCESS;