21 int N_quark_t_all = 0;
22 int N_quark_tbar_all = 0;
23 int N_pt_above_cut = 0;
24 int N_pt_above_cut_plus = 0;
25 int N_pt_above_cut_minus = 0;
27 int foundlepton[6] = {0, 0, 0, 0, 0, 0};
28 int count_found_leptons = 1;
32 const HepMC::GenEvent* genEvt = (*itr);
34 for (
const auto& pitr: *genEvt) {
35 if (std::abs(pitr->pdg_id()) != 6)
continue;
36 if ( pitr->pdg_id() == 6 ) N_quark_t_all++;
37 if ( pitr->pdg_id() == -6 ) N_quark_tbar_all++;
38 auto decayVtx = pitr->end_vertex();
40 if (!decayVtx)
continue;
42 if (decayVtx->particles_out().size() < 2)
continue;
43 for (
const auto& child_mcpart: decayVtx->particles_out()) {
45 if (std::abs(child_mcpart->pdg_id()) != 24)
continue;
46 if ( pitr->pdg_id() == 6 ) N_quark_t++;
47 if ( pitr->pdg_id() == -6 ) N_quark_tbar++;
49 bool useNextVertex =
false;
50 auto w_decayVtx = child_mcpart->end_vertex();
52 useNextVertex =
false;
53 for (
const auto& grandchild_mcpart: *w_decayVtx) {
54 int grandchild_pid = grandchild_mcpart->pdg_id();
55 ATH_MSG_DEBUG(
"W (t/tbar) has " << w_decayVtx->particles_out().size() <<
" children and the pdg_id of the next is " << grandchild_pid);
57 if (std::abs(grandchild_pid) == 24) {
58 w_decayVtx = grandchild_mcpart->end_vertex();
69 if (grandchild_pid == -11 && foundlepton[0] < count_found_leptons) {
70 if (grandchild_mcpart->momentum().perp() >=
m_Ptmin) {
73 N_pt_above_cut_minus++;
76 if (grandchild_pid == 11 && foundlepton[1] < count_found_leptons) {
77 if (grandchild_mcpart->momentum().perp() >=
m_Ptmin) {
80 N_pt_above_cut_plus++;
84 if (grandchild_pid == -13 && foundlepton[2] < count_found_leptons) {
85 if (grandchild_mcpart->momentum().perp() >=
m_Ptmin) {
88 N_pt_above_cut_minus++;
91 if (grandchild_pid == 13 && foundlepton[3] < count_found_leptons) {
92 if (grandchild_mcpart->momentum().perp() >=
m_Ptmin) {
95 N_pt_above_cut_plus++;
98 if (grandchild_pid == -15 && foundlepton[4] < count_found_leptons) {
99 if (grandchild_mcpart->momentum().perp() >=
m_Ptmin) {
102 N_pt_above_cut_minus++;
105 if (grandchild_pid == 15 && foundlepton[5] < count_found_leptons) {
106 if (grandchild_mcpart->momentum().perp() >=
m_Ptmin) {
109 N_pt_above_cut_plus++;
114 if (!useNextVertex)
break;
119 for (HepMC::GenEvent::particle_const_iterator pitr = genEvt->particles_begin(); pitr != genEvt->particles_end(); ++pitr) {
120 if (std::abs((*pitr)->pdg_id()) == 6) {
121 if ( (*pitr)->pdg_id() == 6 ) N_quark_t_all++;
122 if ( (*pitr)->pdg_id() == -6 ) N_quark_tbar_all++;
127 const HepMC::GenVertex * decayVtx = mcpart->end_vertex();
130 if (decayVtx != 0) n_daughters = decayVtx->particles_out_size();
133 if (n_daughters >= 2) {
134 HepMC::GenVertex::particles_in_const_iterator child_mcpartItr = decayVtx->particles_out_const_begin();
135 HepMC::GenVertex::particles_in_const_iterator child_mcpartItrE = decayVtx->particles_out_const_end();
136 for (; child_mcpartItr != child_mcpartItrE; ++child_mcpartItr) {
140 if (std::abs(child_mcpart->pdg_id()) == 24) {
141 if ( (*pitr)->pdg_id() == 6 ) N_quark_t++;
142 if ( (*pitr)->pdg_id() == -6 ) N_quark_tbar++;
144 bool useNextVertex =
false;
145 const HepMC::GenVertex * w_decayVtx = child_mcpart->end_vertex();
149 useNextVertex =
false;
150 int mcpart_n_particles_out = w_decayVtx->particles_out_size();
152 HepMC::GenVertex::particles_out_const_iterator grandchild_mcpartItr = w_decayVtx->particles_out_const_begin();
153 HepMC::GenVertex::particles_out_const_iterator grandchild_mcpartItrE = w_decayVtx->particles_out_const_end();
155 for (; grandchild_mcpartItr != grandchild_mcpartItrE; ++grandchild_mcpartItr) {
157 int grandchild_pid = grandchild_mcpart->pdg_id();
160 ATH_MSG_DEBUG(
"W (t/tbar) has " << mcpart_n_particles_out <<
" children and the pdg_id of the next is " << grandchild_pid);
163 if (std::abs(grandchild_pid) == 24) {
164 w_decayVtx = grandchild_mcpart->end_vertex();
172 useNextVertex =
true;
177 if (grandchild_pid == -11 && foundlepton[0] < count_found_leptons) {
178 if (grandchild_mcpart->momentum().perp() >=
m_Ptmin) {
181 N_pt_above_cut_minus++;
184 if (grandchild_pid == 11 && foundlepton[1] < count_found_leptons) {
185 if (grandchild_mcpart->momentum().perp() >=
m_Ptmin) {
188 N_pt_above_cut_plus++;
192 if (grandchild_pid == -13 && foundlepton[2] < count_found_leptons) {
193 if (grandchild_mcpart->momentum().perp() >=
m_Ptmin) {
196 N_pt_above_cut_minus++;
199 if (grandchild_pid == 13 && foundlepton[3] < count_found_leptons) {
200 if (grandchild_mcpart->momentum().perp() >=
m_Ptmin) {
203 N_pt_above_cut_plus++;
206 if (grandchild_pid == -15 && foundlepton[4] < count_found_leptons) {
207 if (grandchild_mcpart->momentum().perp() >=
m_Ptmin) {
210 N_pt_above_cut_minus++;
213 if (grandchild_pid == 15 && foundlepton[5] < count_found_leptons) {
214 if (grandchild_mcpart->momentum().perp() >=
m_Ptmin) {
217 N_pt_above_cut_plus++;
224 if (!useNextVertex)
break;
234 ATH_MSG_INFO(
"Found " << N_quark_t_all <<
" t quarks in event record");
235 ATH_MSG_INFO(
"Found " << N_quark_tbar_all <<
" tbar quarks in event record");
236 ATH_MSG_INFO(
"Found " << N_quark_t <<
" t -> W X decays");
237 ATH_MSG_INFO(
"Found " << N_quark_tbar <<
" tbar -> W X decays");
238 ATH_MSG_INFO(
"Num leptons from W decays from tops with lepton pt above " <<
m_Ptmin/1000.0 <<
" Gaudi::Units::GeV/c = " << N_pt_above_cut);
242 if (N_quark_t_all < count_tops || N_quark_tbar_all < count_tops) {
244 ATH_MSG_ERROR(
"No t or tbar quarks were found in a (presumably) ttbar event! Event is rejected.");
245 setFilterPassed(
false);
246 return StatusCode::SUCCESS;
249 if (N_quark_t < count_tops || N_quark_tbar < count_tops) {
251 ATH_MSG_ERROR(
"No t or tbar quarks were found decaying to W in a (presumably) ttbar event! Event is rejected. Event dump follows.");
255 const HepMC::GenEvent* genEvt = (*itr);
257 for (
const auto& mcpart: *genEvt) {
259 int pid = mcpart->pdg_id();
262 auto decayVtx = mcpart->end_vertex();
264 if ( !decayVtx )
continue;
266 for (
const auto& child_mcpart: *decayVtx) {
268 int child_pid = child_mcpart->pdg_id();
269 ATH_MSG_ERROR(
" child " << part_child <<
" with pdg_id = " << child_pid);
273 setFilterPassed(
false);
274 return StatusCode::SUCCESS;
280 ATH_MSG_WARNING(
"More than one t -> W X or tbar -> W X decays found. Event is accepted anyway.");
283 ATH_MSG_WARNING(
"More than one t -> W X or tbar -> W X decays found. Event is accepted anyway.");
285 setFilterPassed(N_pt_above_cut > 0);
288 if(
m_SSMLFilter) setFilterPassed( (N_pt_above_cut >=
m_numLeptons) && (N_pt_above_cut_plus >= 2 || N_pt_above_cut_minus >= 2));
293 return StatusCode::SUCCESS;