16 #include "Gaudi/Property.h"
42 const std::string&
name,
43 const IInterface*
parent ) :
53 "StoreGate location of the reference McEventCollection" );
57 "Location of the 'to-be-validated' McEventCollection" );
61 "Name of the output text file which will contain the "
62 "hard-scattering vertices" );
67 "Tool to write the reference HepMC::GenEvent into a dedicated file" );
72 "Tool to write the \"to-be-checked\" HepMC::GenEvent "
73 "into a dedicated file" );
107 ATH_MSG_ERROR(
"Could not open output Hard-Scattering vertices file at : "
113 return StatusCode::FAILURE;
118 ATH_MSG_ERROR(
"Could not configure the HepMC::GenEvent writer tools !!");
119 return StatusCode::FAILURE;
122 return StatusCode::SUCCESS;
129 return StatusCode::SUCCESS;
137 nullptr == refMcEvents ) {
138 ATH_MSG_ERROR(
"Could not retrieve reference McEventCollection at ["
140 return StatusCode::FAILURE;
142 ATH_MSG_VERBOSE(
"Successfully retrieved reference McEventCollection at ["
154 nullptr == checkMcEvents ) {
155 ATH_MSG_ERROR(
"Could not retrieve 'to-be-validated' McEventCollection at ["
157 return StatusCode::FAILURE;
160 (
"Successfully retrieved 'to-be-validated' McEventCollection at ["
176 if (
nullptr == refMcEvents ) {
177 ATH_MSG_ERROR(
"NULL pointer to reference McEventCollection !!");
178 return StatusCode::FAILURE;
181 if (
nullptr == checkMcEvents ) {
182 ATH_MSG_ERROR(
"NULL pointer to the 'to-be-validated' McEventCollection !!");
183 return StatusCode::FAILURE;
186 if ( refMcEvents->
size() != checkMcEvents->
size() ) {
187 ATH_MSG_ERROR(
"McEventCollections to be compared don't have the same size !"
190 <<
"Current: " << checkMcEvents->
size());
193 const unsigned int nMaxEvts =
std::min( refMcEvents->
size(),
194 checkMcEvents->
size() );
195 for (
unsigned int iEvt = 0; iEvt != nMaxEvts; ++iEvt ) {
198 (*checkMcEvents)[iEvt] ).isFailure() ) {
200 << (*refMcEvents)[iEvt]->event_number()
205 return StatusCode::SUCCESS;
210 const HepMC::GenEvent* checkMcEvts )
212 if (
nullptr == refMcEvts ) {
213 ATH_MSG_ERROR(
"NULL pointer to reference HepMC::GenEvent !!");
214 return StatusCode::FAILURE;
217 if (
nullptr == checkMcEvts ) {
218 ATH_MSG_ERROR(
"NULL pointer to the 'to-be-validated' HepMC::GenEvent !!");
219 return StatusCode::FAILURE;
222 const unsigned int evtNbr = refMcEvts->event_number();
223 (*m_outFile) <<
">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
225 <<
"Event: " << evtNbr
229 std::map<int,int> ref_bc_to_id;
230 const auto& refvertices = refMcEvts->vertices();
231 for (
const auto& vtx: refvertices) {
236 for (
auto&
p: vtx->particles_out())
if (
p->pdg_id() == 91||
p->pdg_id() == 92||
p->pdg_id() == 94) showerout++;
237 if ( partonsin >= 2 && showerout == 0 ) {
241 std::map<int,int> che_bc_to_id;
242 const auto& chevertices = checkMcEvts->vertices();
243 for (
const auto& checkVtx: chevertices) {
246 std::set<int> allbarcodes;
247 for (
const auto &[bc,
id]: ref_bc_to_id) allbarcodes.insert(bc);
248 for (
const auto &[bc,
id]: che_bc_to_id) allbarcodes.insert(bc);
249 for (
const auto &bc: allbarcodes){
250 auto ref_it = ref_bc_to_id.find(bc);
251 auto che_it = che_bc_to_id.find(bc);
252 if (ref_it == ref_bc_to_id.end()) {
ATH_MSG_WARNING(
"In Event [" << evtNbr <<
"]: got null ref-vertex (barcode: " << bc <<
")");
continue; }
253 if (che_it == che_bc_to_id.end()) {
ATH_MSG_WARNING(
"Output GenEvent is missing the selected HardScattering Vtx !!"<<
" (" << bc <<
")");
continue; }
254 if (-ref_it->second >
int(refvertices.size()) ) {
continue; }
255 if (-che_it->second >
int(chevertices.size()) ) {
continue; }
256 const auto& refvtx = refvertices[-ref_it->second-1];
257 const auto& chevtx = chevertices[-che_it->second-1];
258 (*m_outFile) << refvtx << std::endl;
259 (*m_outFile) << chevtx << std::endl;
260 (*m_outFile) <<
"---------" << std::endl;
262 ATH_MSG_WARNING(
"Selected HardScattering vertices are NOT the same !!"<<
" at Event [" << evtNbr <<
"]"<<
" refVtx = " << refvtx<<
" chevtx = " << chevtx);
265 (*m_outFile) <<
"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" << std::endl;
267 std::set<int> ref_bc;
268 for (
auto vtxIt = refMcEvts->vertices_begin(); vtxIt != refMcEvts->vertices_end(); ++vtxIt ) {
275 for (
auto p = vtx->particles_in_const_begin();
p!=vtx->particles_in_const_end();++
p )
if (
MC::isQuark(*
p) ||
MC::isGluon(*
p)) partonsin++;
277 for (
auto&
p : *vtx)
if (
p->pdg_id() == 91||
p->pdg_id() == 92||
p->pdg_id() == 94) showerout++;
278 if ( partonsin >= 2 && showerout == 0 ) {
279 ref_bc.insert(vtx->barcode());
282 std::set<int> che_bc;
283 for (
auto vtxIt = checkMcEvts->vertices_begin(); vtxIt != checkMcEvts->vertices_end(); ++vtxIt ) {
285 che_bc.insert(vtx->barcode());
287 std::set<int> allbarcodes;
288 for (
const auto &bc: ref_bc) allbarcodes.insert(bc);
289 for (
const auto &bc: che_bc) allbarcodes.insert(bc);
290 for (
const auto &bc: allbarcodes){
291 auto ref_it = ref_bc.find(bc);
292 auto che_it = che_bc.find(bc);
293 if (ref_it == ref_bc.end()) {
ATH_MSG_WARNING(
"In Event [" << evtNbr <<
"]: got null ref-vertex (barcode: " << bc <<
")");
continue; }
294 if (che_it == che_bc.end()) {
ATH_MSG_WARNING(
"Output GenEvent is missing the selected HardScattering Vtx !!"<<
" (" << bc <<
")");
continue; }
295 const auto refvtx = refMcEvts->barcode_to_vertex(bc);
296 const auto chevtx = checkMcEvts->barcode_to_vertex(bc);
297 (*m_outFile) << refvtx << std::endl;
298 (*m_outFile) << chevtx << std::endl;
299 (*m_outFile) <<
"---------" << std::endl;
301 ATH_MSG_WARNING(
"Selected HardScattering vertices are NOT the same !!"<<
" at Event [" << evtNbr <<
"]"<<
" refVtx = " << refvtx<<
" chevtx = " << chevtx);
304 (*m_outFile) <<
"<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" << std::endl;
307 return StatusCode::SUCCESS;
312 if ( !vtx1 || !vtx2 ) {
314 <<
" vtx1: " << vtx1 <<
endmsg
315 <<
" vtx2: " << vtx2);
320 auto inVtx1 = vtx1->particles_in();
321 auto inVtx2 = vtx2->particles_in();
322 if (inVtx1.size() != inVtx2.size()) {
323 ATH_MSG_ERROR(
"Not the same number of branches !!" <<
endmsg <<
" in: " << inVtx1.size() <<
"\t" << inVtx2.size());
326 std::sort(inVtx1.begin(), inVtx1.end(), [](
auto&
a,
auto&
b) ->
bool{return a->momentum().pz() > b->momentum().pz(); });
327 std::sort(inVtx2.begin(), inVtx2.end(), [](
auto&
a,
auto&
b) ->
bool{return a->momentum().pz() > b->momentum().pz(); });
328 for (
size_t i=0;
i<inVtx1.size(); ++
i){
333 auto outVtx1 = vtx1->particles_out();
334 auto outVtx2 = vtx2->particles_out();
335 if (outVtx1.size() != outVtx2.size()) {
336 ATH_MSG_ERROR(
"Not the same number of branches !!" <<
endmsg <<
" out: " << outVtx1.size() <<
"\t" << outVtx2.size());
339 std::sort(outVtx1.begin(), outVtx1.end(), [](
auto&
a,
auto&
b) ->
bool{return a->momentum().pz() > b->momentum().pz(); });
340 std::sort(outVtx2.begin(), outVtx2.end(), [](
auto&
a,
auto&
b) ->
bool{return a->momentum().pz() > b->momentum().pz(); });
341 for (
size_t i=0;
i<outVtx1.size(); ++
i){
347 const int inVtx1 = vtx1->particles_in_size();
348 const int inVtx2 = vtx2->particles_in_size();
350 const int outVtx1 = vtx1->particles_out_size();
351 const int outVtx2 = vtx2->particles_out_size();
353 if ( inVtx1 != inVtx2 || outVtx1 != outVtx2 ) {
355 <<
" in: " << inVtx1 <<
"\t" << inVtx2 <<
endmsg
356 <<
" out: " << outVtx1 <<
"\t" << outVtx2);
360 for ( HepMC::GenVertex::particles_in_const_iterator inPart1 = vtx1->particles_in_const_begin();
361 inPart1 != vtx1->particles_in_const_end();
363 bool inParticleOK =
false;
364 for ( HepMC::GenVertex::particles_in_const_iterator inPart2 = vtx2->particles_in_const_begin();
365 inPart2 != vtx2->particles_in_const_end();
373 if ( !inParticleOK ) {
381 for ( HepMC::GenVertex::particles_out_const_iterator outPart1 = vtx1->particles_out_const_begin();
382 outPart1 != vtx1->particles_out_const_end();
384 bool outParticleOK =
false;
385 for ( HepMC::GenVertex::particles_out_const_iterator outPart2 = vtx2->particles_out_const_begin();
386 outPart2 != vtx2->particles_out_const_end();
389 outParticleOK =
true;
394 if ( !outParticleOK ) {
419 const HepMC::FourVector hlv1 =
p1->momentum();
420 const int id1 =
p1->pdg_id();
421 const int status1 =
p1->status();
425 const HepMC::FourVector hlv2 =
p2->momentum();
426 const int id2 =
p2->pdg_id();
427 const int status2 =
p2->status();
431 const bool isOK = ( hlv1 == hlv2 &&
433 status1 == status2 &&
440 (
"=============================" <<
endmsg
441 <<
"\thlv: " << std::boolalpha << (hlv1 == hlv2 ) <<
endmsg
442 <<
"\tid: " << std::boolalpha << (id1 ==
id2 ) <<
endmsg
443 <<
"\tstatus: " << std::boolalpha << (status1 == status2) <<
endmsg
444 <<
"\tflow: " << std::boolalpha << (flow1 == flow2 ) <<
endmsg
445 <<
"\tpolar: " << std::boolalpha << (pol1 == pol2 ) <<
endmsg
446 <<
"=============================");
458 return StatusCode::FAILURE;
465 return StatusCode::FAILURE;
474 return StatusCode::FAILURE;
482 return StatusCode::FAILURE;
485 return StatusCode::SUCCESS;