6 #include "ValidationControl.h"
9 #include "SimpleEventTool.h"
13 #include "PhotosValidationTool.h"
17 #include "TauolaValidationTool.h"
21 #include "McTesterValidationTool.h"
25 #include "PythiaValidationTool.h"
33 m_momentum_check_events(0),
34 m_momentum_check_threshold(10e-6),
38 m_timer(
"processing time"),
39 m_has_input_source(0) {
50 std::ifstream in(filename.c_str());
53 printf(
"ValidationControl: error reading config file: %s\n",filename.c_str());
57 else printf(
"ValidationControl: parsing config file: %s\n",filename.c_str());
69 if( strlen(buf) < 3 || buf[0] ==
' ' || buf[0] ==
'#' ) {
75 if( strncmp(buf,
"EVENTS",6)==0 ) {
79 else if( strncmp(buf,
"INPUT",5)==0 ) {
86 if( strncmp(buf,
"tool",4)==0 ) {
87 #ifdef SIMPLEEVENTTOOL
90 status = UNAVAILABLE_TOOL;
93 else if( strncmp(buf,
"pythia8",7)==0) {
98 status = UNAVAILABLE_TOOL;
101 else status = UNRECOGNIZED_INPUT;
110 else if( strncmp(buf,
"TOOL",3)==0 ) {
113 if ( strncmp(buf,
"tauola",6)==0 ) {
117 status = UNAVAILABLE_TOOL;
120 else if( strncmp(buf,
"photos",6)==0 ) {
124 status = UNAVAILABLE_TOOL;
127 else if( strncmp(buf,
"mctester",8)==0 ) {
131 status = UNAVAILABLE_TOOL;
134 else status = UNRECOGNIZED_TOOL;
137 else if( strncmp(buf,
"SET",3)==0 ) {
140 if ( strncmp(buf,
"print_events",12)==0 ) {
144 if( strncmp(buf,
"ALL",3)==0 ) events = -1;
145 else events = atoi(buf);
149 else if( strncmp(buf,
"check_momentum",14)==0 ) {
153 if( strncmp(buf,
"ALL",3)==0 ) events = -1;
154 else events = atoi(buf);
158 else status = UNRECOGNIZED_OPTION;
160 else status = UNRECOGNIZED_COMMAND;
163 if(status != PARSING_OK) printf(
"ValidationControl: config file line %i: ",line);
166 case UNRECOGNIZED_COMMAND:
167 printf(
"skipping unrecognised command: '%s'\n",buf);
169 case UNRECOGNIZED_OPTION:
170 printf(
"skipping unrecognised option: '%s'\n",buf);
172 case UNRECOGNIZED_INPUT:
173 printf(
"skipping unrecognised input source: '%s'\n",buf);
175 case UNRECOGNIZED_TOOL:
176 printf(
"skipping unrecognised tool: '%s'\n",buf);
178 case UNAVAILABLE_TOOL:
179 printf(
"skipping unavailable tool: '%s'\n",buf);
181 case ADDITIONAL_INPUT:
182 printf(
"skipping additional input source: '%s'\n",buf);
184 case CANNOT_OPEN_FILE:
185 printf(
"skipping input file: '%s'\n",buf);
197 else printf(
"ValidationControl: no valid input source\n");
214 printf(
"ValidationControl: event 1 of %-7i\n",
m_events);
227 printf(
"ValidationControl: event 1\n");
234 printf(
"ValidationControl: event %7i (%6ims current, %7ims total)\n",
m_event_counter,elapsed,total);
243 printf(
"ValidationControl: initializing\n");
245 for (std::vector<ValidationTool *>::iterator tool=
m_toolchain.begin(); tool!=
m_toolchain.end(); ++tool) (*tool)->initialize();
255 Timer *timer = (*tool)->timer();
257 if(timer) timer->
start();
259 if(timer) timer->
stop();
265 printf(
"--------------------------------------------------------------\n");
266 printf(
" Print event: %s\n",(*tool)->name().c_str());
267 printf(
"--------------------------------------------------------------\n");
269 HEPMC2CODE( hepmc.print(); )
270 HEPMC3CODE( Print::listing(hepmc,8); )
278 for ( GenEvent::particle_const_iterator p = hepmc.particles_begin();
279 p != hepmc.particles_end(); ++p ) {
280 if( (*p)->status() != 1 )
continue;
286 sum.
setE ( sum.
e() + m.
e() );
289 double momentum = input_momentum.
px() + input_momentum.
py() + input_momentum.
pz() + input_momentum.
e();
290 if( fabs(momentum) > 10e-12 ) {
291 double px = input_momentum.
px() - sum.
px();
292 double py = input_momentum.
py() - sum.
py();
293 double pz = input_momentum.
pz() - sum.
pz();
294 double e = input_momentum.
e() - sum.
e();
295 delta = sqrt(px*px + py*py + pz*pz + e*e);
301 for (
auto p: hepmc.
particles())
if( p->status() != 1 )
continue;
else sum += p->momentum();
302 if(!input_momentum.
is_zero()) delta = (input_momentum - sum).
length();
305 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());
308 else printf(
" - WARNING! Difference = %+15.8e\n",delta);
310 input_momentum = sum;
316 printf(
"ValidationControl: finalizing\n");
322 printf(
"ValidationControl: printing timers\n");
326 if((*t)->timer()) (*t)->timer()->print();
329 printf(
"ValidationControl: finished processing:\n");
333 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)