HepMC3 event record library
PhotosValidationTool.cc
1 // -*- C++ -*-
2 //
3 // This file is part of HepMC
4 // Copyright (C) 2014-2019 The HepMC collaboration (see AUTHORS for details)
5 //
6 #include "PhotosValidationTool.h"
7 
8 #include <cstring> // memset
9 #include <cstdio> // printf
10 
11 PhotosValidationTool::PhotosValidationTool():m_more_photons_added(0),m_timer("Photos++ processing time") {
12  memset(m_photons_added,0,sizeof(int)*MAX_PHOTONS_TO_KEEP_TRACK_OF);
13 }
14 
16  Photospp::Photos::initialize();
17  Photospp::Photos::setInfraredCutOff(0.001/200);
18 
19  HEPMC2CODE( Photospp::Photos::createHistoryEntries(false,3); )
20  HEPMC3CODE( Photospp::Photos::createHistoryEntries(false,3); )
21 }
22 
24 
25  HEPMC2CODE( int buf = -hepmc.particles_size(); )
26  HEPMC3CODE(
27  vector<GenParticlePtr> results = applyFilter(Selector::STATUS==1 && Selector::PDG_ID==22,hepmc.particles());
28  int buf = -results.size();
29  )
30  // Time only processing
31  m_timer.start();
32 
33  // Process by Photos++
34  HEPMC2CODE( Photospp::PhotosHepMCEvent *p_event = new Photospp::PhotosHepMCEvent (&hepmc); )
35  HEPMC3CODE( Photospp::PhotosHepMC3Event *p_event = new Photospp::PhotosHepMC3Event(&hepmc); )
36 
37  p_event->process();
38  delete p_event;
39 
40  m_timer.stop();
41 
42  // Check number of photons created
43  HEPMC2CODE( buf += hepmc.particles_size(); )
44 
45  HEPMC3CODE(
46  vector<GenParticlePtr> results2 = applyFilter(Selector::STATUS==1 && Selector::PDG_ID==22,hepmc.particles());
47  buf += results2.size();
48  )
49 
50  if(buf<MAX_PHOTONS_TO_KEEP_TRACK_OF) ++m_photons_added[buf];
51  else ++m_more_photons_added;
52 
53  return 0;
54 }
55 
57  Photospp::Log::Summary();
58 
59  int sum = m_more_photons_added;
60  for(int i=0; i<MAX_PHOTONS_TO_KEEP_TRACK_OF; ++i) sum += m_photons_added[i];
61 
62  if( sum == 0 ) sum = 1;
63 
64  printf("---------------------------------------------------\n");
65  printf(" Number of photons added by Photos++ (per event):\n");
66  printf("---------------------------------------------------\n");
67  for(int i=0; i<MAX_PHOTONS_TO_KEEP_TRACK_OF; ++i) {
68  printf("%5i: %7i events (%6.2f%%)\n",i,m_photons_added[i],m_photons_added[i]*100./sum );
69  }
70  printf(" more: %7i events (%6.2f%%)\n",m_more_photons_added,m_more_photons_added*100./sum );
71  printf("total: %7i events\n",sum );
72  printf("---------------------------------------------------\n");
73 }
void initialize()
Initialize.
Stores event-related information.
Definition: GenEvent.h:42
const std::vector< ConstGenParticlePtr > & particles() const
Get list of particles (const)
Definition: GenEvent.cc:40
int process(GenEvent &hepmc)
Process event.
vector< GenParticlePtr > applyFilter(const Filter &filter, const vector< GenParticlePtr > &particles)
Apply a Filter to a list of GenParticles Returns a vector of GenParticles that satisfy the Filter...
Definition: Filter.h:21