6 #include "ValidationControl.h"
7 #include "OutputValidationTool.h"
8 #include "SimpleEventTool.h"
11 #include "PhotosValidationTool.h"
15 #include "TauolaValidationTool.h"
19 #include "McTesterValidationTool.h"
23 #include "PythiaValidationTool.h"
31 m_momentum_check_events(0),
32 m_momentum_check_threshold(10e-6),
36 m_timer(
"processing time"),
37 m_has_input_source(0) {
48 std::ifstream in(filename.c_str());
51 printf(
"ValidationControl: error reading config file: %s\n",filename.c_str());
55 else printf(
"ValidationControl: parsing config file: %s\n",filename.c_str());
67 if( strlen(buf) < 3 || buf[0] ==
' ' || buf[0] ==
'#' ) {
73 if( strncmp(buf,
"EVENTS",6)==0 ) {
77 else if( strncmp(buf,
"INPUT",5)==0 ) {
84 if( strncmp(buf,
"SimpleEvent",11)==0 ) {
87 else if( strncmp(buf,
"pythia8",7)==0) {
92 status = UNAVAILABLE_TOOL;
95 else status = UNRECOGNIZED_INPUT;
104 else if( strncmp(buf,
"TOOL",3)==0 ) {
106 if ( strncmp(buf,
"output",6)==0 ) {
109 else if ( strncmp(buf,
"tauola",6)==0 ) {
113 status = UNAVAILABLE_TOOL;
116 else if( strncmp(buf,
"photos",6)==0 ) {
120 status = UNAVAILABLE_TOOL;
123 else if( strncmp(buf,
"mctester",8)==0 ) {
127 status = UNAVAILABLE_TOOL;
130 else status = UNRECOGNIZED_TOOL;
133 else if( strncmp(buf,
"SET",3)==0 ) {
136 if ( strncmp(buf,
"print_events",12)==0 ) {
140 if( strncmp(buf,
"ALL",3)==0 ) events = -1;
141 else events = atoi(buf);
145 else if( strncmp(buf,
"check_momentum",14)==0 ) {
149 if( strncmp(buf,
"ALL",3)==0 ) events = -1;
150 else events = atoi(buf);
154 else status = UNRECOGNIZED_OPTION;
156 else status = UNRECOGNIZED_COMMAND;
159 if(status != PARSING_OK) printf(
"ValidationControl: config file line %i: ",line);
162 case UNRECOGNIZED_COMMAND:
163 printf(
"skipping unrecognised command: '%s'\n",buf);
165 case UNRECOGNIZED_OPTION:
166 printf(
"skipping unrecognised option: '%s'\n",buf);
168 case UNRECOGNIZED_INPUT:
169 printf(
"skipping unrecognised input source: '%s'\n",buf);
171 case UNRECOGNIZED_TOOL:
172 printf(
"skipping unrecognised tool: '%s'\n",buf);
174 case UNAVAILABLE_TOOL:
175 printf(
"skipping unavailable tool: '%s'\n",buf);
177 case ADDITIONAL_INPUT:
178 printf(
"skipping additional input source: '%s'\n",buf);
180 case CANNOT_OPEN_FILE:
181 printf(
"skipping input file: '%s'\n",buf);
193 else printf(
"ValidationControl: no valid input source\n");
210 printf(
"ValidationControl: event 1 of %-7i\n",
m_events);
223 printf(
"ValidationControl: event 1\n");
230 printf(
"ValidationControl: event %7i (%6ims current, %7ims total)\n",
m_event_counter,elapsed,total);
239 printf(
"ValidationControl: initializing\n");
241 for (std::vector<ValidationTool *>::iterator tool=
m_toolchain.begin(); tool!=
m_toolchain.end(); ++tool) (*tool)->initialize();
251 Timer *timer = (*tool)->timer();
253 if(timer) timer->
start();
255 if(timer) timer->
stop();
261 printf(
"--------------------------------------------------------------\n");
262 printf(
" Print event: %s\n",(*tool)->name().c_str());
263 printf(
"--------------------------------------------------------------\n");
265 HEPMC2CODE( hepmc.print(); )
266 HEPMC3CODE( Print::listing(hepmc,8); )
274 for ( GenEvent::particle_const_iterator p = hepmc.particles_begin();
275 p != hepmc.particles_end(); ++p ) {
276 if( (*p)->status() != 1 )
continue;
281 sum.
setE ( sum.
e() + m.
e() );
284 double momentum = input_momentum.
px() + input_momentum.
py() + input_momentum.
pz() + input_momentum.
e();
285 if( fabs(momentum) > 10e-12 ) {
286 double px = input_momentum.
px() - sum.
px();
287 double py = input_momentum.
py() - sum.
py();
288 double pz = input_momentum.
pz() - sum.
pz();
289 double e = input_momentum.
e() - sum.
e();
290 delta = sqrt(px*px + py*py + pz*pz + e*e);
295 for (
auto p: hepmc.
particles())
if( p->status() != 1 )
continue;
else sum += p->momentum();
296 if(!input_momentum.
is_zero()) delta = (input_momentum - sum).
length();
299 printf(
"Momentum sum: %+15.8e %+15.8e %+15.8e %+15.8e (evt: %7i, %s)",sum.px(),sum.py(),sum.pz(),sum.e(),
m_event_counter,(*tool)->name().c_str());
302 else printf(
" - WARNING! Difference = %+15.8e\n",delta);
304 input_momentum = sum;
310 printf(
"ValidationControl: finalizing\n");
316 printf(
"ValidationControl: printing timers\n");
320 if((*t)->timer()) (*t)->timer()->print();
323 printf(
"ValidationControl: finished processing:\n");
327 printf(
" tool: %s\n",(*t)->long_name().c_str());
int m_events_print_step
events print step
~ValidationControl()
Destructor.
int m_momentum_check_events
mom check events
void check_momentum_for_events(int events)
N events to check momentum.
void read_file(const std::string &filename)
Read file.
bool is_zero() const
Check if the length of this vertex is zero.
std::vector< ValidationTool * > m_toolchain
Toolchain.
int m_event_counter
counter of events
void initialize()
Init function.
void print_events(int events)
N events to print.
PARSING_STATUS
parsing stutus
int m_print_events
print events
double e() const
Energy component of momentum.
Stores event-related information.
double px() const
x-component of momentum
bool m_has_input_source
Input source flag.
double m_momentum_check_threshold
mom check threshold
double length() const
Magnitude of spatial (x, y, z) 3-vector.
bool new_event()
New event.
double pz() const
z-component of momentum
double py() const
y-component of momentum
ValidationControl()
Constructor.
void process(GenEvent &hepmc)
Process event.
Used to benchmark MC generators.
const std::vector< ConstGenParticlePtr > & particles() const
Get list of particles (const)