GENIEGenerator
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions | Variables
gEvScan.cxx File Reference
#include <string>
#include <vector>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <TSystem.h>
#include <TFile.h>
#include <TTree.h>
#include <TH1D.h>
#include <TLorentzVector.h>
#include "Framework/Conventions/Constants.h"
#include "Framework/EventGen/EventRecord.h"
#include "Framework/GHEP/GHepParticle.h"
#include "Framework/Ntuple/NtpMCFormat.h"
#include "Framework/Ntuple/NtpMCTreeHeader.h"
#include "Framework/Ntuple/NtpMCEventRecord.h"
#include "Framework/ParticleData/PDGLibrary.h"
#include "Framework/ParticleData/PDGCodes.h"
#include "Framework/ParticleData/PDGUtils.h"
#include "Framework/ParticleData/PDGCodeList.h"
#include "Framework/Messenger/Messenger.h"
#include "Physics/NuclearState/NuclearUtils.h"
#include "Framework/Utils/CmdLnArgParser.h"
#include "Framework/Utils/RunOpt.h"
Include dependency graph for gEvScan.cxx:

Go to the source code of this file.

Functions

void GetCommandLineArgs (int argc, char **argv)
 
void PrintSyntax (void)
 
bool CheckRootFilename (string filename)
 
void CheckEnergyMomentumConservation (void)
 
void CheckChargeConservation (void)
 
void CheckForPseudoParticlesInFinState (void)
 
void CheckForOffMassShellParticlesInFinState (void)
 
void CheckForNumFinStateNucleonsInconsistentWithTarget (void)
 
void CheckVertexDistribution (void)
 
void CheckDecayerConsistency (void)
 
int main (int argc, char **argv)
 

Variables

string gOptInpFilename = ""
 
string gOptOutFilename = ""
 
Long64_t gOptNEvtL = -1
 
Long64_t gOptNEvtH = -1
 
int gOptMaxNumErrs = -1
 
bool gOptAddEventPrintoutInErrLog = false
 
bool gOptCheckEnergyMomentumConservation = false
 
bool gOptCheckChargeConservation = false
 
bool gOptCheckForPseudoParticlesInFinState = false
 
bool gOptCheckForOffMassShellParticlesInFinState = false
 
bool gOptCheckForNumFinStateNucleonsInconsistentWithTarget = false
 
bool gOptCheckVertexDistribution = false
 
bool gOptCheckDecayerConsistency = false
 
Long64_t gFirstEventNum = -1
 
Long64_t gLastEventNum = -1
 
TTree * gEventTree = 0
 
NtpMCEventRecordgMCRec = 0
 
ofstream gErrLog
 

Function Documentation

void CheckChargeConservation ( void  )

Definition at line 290 of file gEvScan.cxx.

References genie::GHepParticle::Charge(), genie::NtpMCEventRecord::Clear(), epsilon, genie::NtpMCEventRecord::event, gErrLog, gEventTree, gFirstEventNum, gLastEventNum, gMCRec, gOptAddEventPrintoutInErrLog, gOptMaxNumErrs, genie::NtpMCRecordI::hdr, genie::kIStInitialState, genie::kIStStableFinalState, LOG, pERROR, pINFO, pNOTICE, and genie::GHepParticle::Status().

Referenced by main().

291 {
292  LOG("gevscan", pNOTICE) << "Checking charge conservation...";
293 
294  if(gErrLog.is_open()) {
295  gErrLog << "# Events failing the charge conservation test:" << endl;
296  gErrLog << "# " << endl;
297  }
298 
299  int nerr = 0;
300 
301  for(Long64_t i = gFirstEventNum; i <= gLastEventNum; i++)
302  {
303  if(gOptMaxNumErrs != -1 && nerr >= gOptMaxNumErrs) break;
304 
305  gEventTree->GetEntry(i);
306 
307  NtpMCRecHeader rec_header = gMCRec->hdr;
308  EventRecord & event = *(gMCRec->event);
309 
310  LOG("gevscan", pINFO) << "Checking event.... " << i;
311 
312  // Can't run the test for neutrinos scattered off nuclear targets
313  // because of intranuclear rescattering effects and the presence, in the event
314  // record, of a charged nuclear remnant pseudo-particle whose charge is not stored.
315  // To check charge conservation in the primary interaction, use a sample generated
316  // for a free nucleon targets.
317  GHepParticle * nucltgt = event.TargetNucleus();
318  if (nucltgt) {
319  LOG("gevscan", pINFO)
320  << "Event in nuclear target - Skipping test...";
321  }
322  else {
323  double Q_init = 0;
324  double Q_fin = 0;
325 
326  GHepParticle * p = 0;
327  TIter event_iter(&event);
328  while ( (p = dynamic_cast<GHepParticle *>(event_iter.Next())) ) {
329 
330  GHepStatus_t ist = p->Status();
331 
332  if(ist == kIStInitialState)
333  {
334  Q_init += p->Charge();
335  }
336  if(ist == kIStStableFinalState)
337  {
338  Q_fin += p->Charge();
339  }
340  }//p
341 
342  double epsilon = 1E-3;
343  bool ok = TMath::Abs(Q_init - Q_fin) < epsilon;
344  if(!ok) {
345  LOG("gevscan", pERROR)
346  << " ** Charge non-conservation in event: " << i
347  << "\n"
348  << event;
349  if(gErrLog.is_open()) {
350  gErrLog << i << endl;
352  gErrLog << event;
353  }
354  }
355  nerr++;
356  }
357 
358  }
359  gMCRec->Clear(); // clear out explicitly to prevent memory leak w/Root6
360  }//i
361 
362  if(gErrLog.is_open()) {
363  if(nerr == 0) {
364  gErrLog << "none" << endl;
365  }
366  }
367 
368  LOG("gevscan", pNOTICE)
369  << "Found " << nerr
370  << " events failing the charge conservation test";
371 }
NtpMCRecHeader hdr
record header
Definition: NtpMCRecordI.h:38
#define pERROR
Definition: Messenger.h:59
NtpMCEventRecord * gMCRec
Definition: gEvScan.cxx:110
GHepStatus_t Status(void) const
Definition: GHepParticle.h:64
const double epsilon
int gOptMaxNumErrs
Definition: gEvScan.cxx:96
Long64_t gFirstEventNum
Definition: gEvScan.cxx:106
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
Long64_t gLastEventNum
Definition: gEvScan.cxx:107
double Charge(void) const
Chrg that corresponds to the PDG code.
#define pINFO
Definition: Messenger.h:62
Generated Event Record. It is a GHepRecord object that can accept / be visited by EventRecordVisitorI...
Definition: EventRecord.h:37
ofstream gErrLog
Definition: gEvScan.cxx:111
bool gOptAddEventPrintoutInErrLog
Definition: gEvScan.cxx:97
MINOS-style Ntuple Class to hold an MC Event Record Header.
#define pNOTICE
Definition: Messenger.h:61
void Clear(Option_t *opt="")
TTree * gEventTree
Definition: gEvScan.cxx:109
STDHEP-like event record entry that can fit a particle or a nucleus.
Definition: GHepParticle.h:39
EventRecord * event
event
enum genie::EGHepStatus GHepStatus_t
void CheckDecayerConsistency ( void  )

ok

Definition at line 710 of file gEvScan.cxx.

References genie::NtpMCEventRecord::Clear(), genie::NtpMCEventRecord::event, genie::PDGCodeList::ExistsInPDGCodeList(), genie::PDGLibrary::Find(), gErrLog, gEventTree, gFirstEventNum, gLastEventNum, gMCRec, gOptAddEventPrintoutInErrLog, genie::NtpMCRecordI::hdr, genie::PDGLibrary::Instance(), genie::kIStDecayedState, genie::kIStStableFinalState, LOG, genie::GHepParticle::Pdg(), pINFO, pNOTICE, genie::PDGCodeList::push_back(), and genie::GHepParticle::Status().

Referenced by main().

711 {
712 // Check that particles seen in the final state in some events do not appear to
713 // have decayed in other events.
714 // This might happen if, for example, particle decay flags which are applied to
715 // GENIE events do not get applied to intermediate particles appearing in the
716 // PYTHIA hadronization. It might also happen if the decayed particle status is
717 // used incorrectly in some modules (eg intranuke).
718 //
719  LOG("gevscan", pNOTICE)
720  << "Checking decayer consistency...";
721 
722  if(gErrLog.is_open()) {
723  gErrLog << "# Decayer consistency check:" << endl;
724  gErrLog << "# " << endl;
725  }
726 
727  bool allowdup = false;
728  PDGCodeList final_state_particles(allowdup);
729  PDGCodeList decayed_particles(allowdup);
730 
731  for(Long64_t i = gFirstEventNum; i <= gLastEventNum; i++)
732  {
733  gEventTree->GetEntry(i);
734 
735  NtpMCRecHeader rec_header = gMCRec->hdr;
736  EventRecord & event = *(gMCRec->event);
737 
738  LOG("gevscan", pINFO) << "Checking event.... " << i;
739 
740  GHepParticle * p = 0;
741  TIter event_iter(&event);
742  while ( (p = dynamic_cast<GHepParticle *>(event_iter.Next())) ) {
743  GHepStatus_t ist = p->Status();
744  int pdgc = p->Pdg();
745  if(ist == kIStStableFinalState) { final_state_particles.push_back(pdgc); }
746  if(ist == kIStDecayedState ) { decayed_particles.push_back(pdgc); }
747  }//p
748  gMCRec->Clear(); // clear out explicitly to prevent memory leak w/Root6
749  }//i
750 
751  // find particles which appear in both lists
752  PDGCodeList particles_in_both_lists(allowdup);
753 
754  PDGCodeList::const_iterator iter;
755  for(iter = final_state_particles.begin();
756  iter != final_state_particles.end(); ++iter)
757  {
758  int pdgc = *iter;
759  if(decayed_particles.ExistsInPDGCodeList(pdgc))
760  {
761  particles_in_both_lists.push_back(pdgc);
762  }
763  }
764 
765  bool ok = true;
766  ostringstream mesg;
767  if(particles_in_both_lists.size() == 0) {
768  mesg << "OK.\n" << "No particle seen both in the final state and to have decayed.";
769  } else {
770  ok = false;
771  mesg << "Problem!\n" << particles_in_both_lists.size() << " particles seen both final state and to have decayed.";
772  }
773 
774  LOG("gevscan", pNOTICE)
775  << mesg.str();
776  LOG("gevscan", pNOTICE)
777  << "Particles seen in final state: " << final_state_particles;
778  LOG("gevscan", pNOTICE)
779  << "Particles seen to have decayed: " << decayed_particles;
780  LOG("gevscan", pNOTICE)
781  << "Particles seen in both lists: " << particles_in_both_lists;
782 
783  if(gErrLog.is_open()) {
784  gErrLog << mesg.str() << endl;
785  gErrLog << "\nParticles seen in final state:" << final_state_particles << endl;
786  gErrLog << "\nParticles seen to have decayed:" << decayed_particles << endl;
787  gErrLog << "\nParticles seen in both lists:" << particles_in_both_lists << endl;
788  }
789 
790  // find example events
791  if(!ok) {
792  if(gErrLog.is_open()) {
793  gErrLog << "\nExample events: " << endl;
794  }
795  for(iter = particles_in_both_lists.begin();
796  iter != particles_in_both_lists.end(); ++iter)
797  {
798  int pdgc_bothlists = *iter;
799  int iev_decay = -1;
800  int iev_fs = -1;
801  bool have_example = false;
802  for(Long64_t i = gFirstEventNum; i <= gLastEventNum; i++)
803  {
804  have_example = (iev_decay != -1 && iev_fs != -1);
805  if(have_example) break;
806 
807  gEventTree->GetEntry(i);
808  EventRecord & event = *(gMCRec->event);
809  GHepParticle * p = 0;
810  TIter event_iter(&event);
811  while ( (p = dynamic_cast<GHepParticle *>(event_iter.Next())) ) {
812  int pdgc = p->Pdg();
813  if(pdgc != pdgc_bothlists) continue;
814  GHepStatus_t ist = p->Status();
815  if(ist == kIStStableFinalState && iev_fs == -1) { iev_fs = i; }
816  if(ist == kIStDecayedState && iev_decay == -1) { iev_decay = i; }
817  }//p
818  gMCRec->Clear(); // clear out explicitly to prevent memory leak w/Root6
819  }//i
820  if(gErrLog.is_open()) {
821  gErrLog << ">> " << PDGLibrary::Instance()->Find(pdgc_bothlists)->GetName()
822  << ": Decayed in event " << iev_decay
823  << ". Seen in final state in event " << iev_fs << "." << endl;
825  gEventTree->GetEntry(iev_decay);
826  EventRecord & event_dec = *(gMCRec->event);
827  gErrLog << "Event " << iev_decay << ":";
828  gErrLog << event_dec;
829  gEventTree->GetEntry(iev_fs);
830  EventRecord & event_fs = *(gMCRec->event);
831  gErrLog << "Event: " << iev_fs << ":";
832  gErrLog << event_fs;
833  }
834  }
835  }//pdgc
836  }//!ok
837 
838 }
NtpMCRecHeader hdr
record header
Definition: NtpMCRecordI.h:38
NtpMCEventRecord * gMCRec
Definition: gEvScan.cxx:110
GHepStatus_t Status(void) const
Definition: GHepParticle.h:64
A list of PDG codes.
Definition: PDGCodeList.h:32
int Pdg(void) const
Definition: GHepParticle.h:63
Long64_t gFirstEventNum
Definition: gEvScan.cxx:106
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
Long64_t gLastEventNum
Definition: gEvScan.cxx:107
#define pINFO
Definition: Messenger.h:62
Generated Event Record. It is a GHepRecord object that can accept / be visited by EventRecordVisitorI...
Definition: EventRecord.h:37
ofstream gErrLog
Definition: gEvScan.cxx:111
bool gOptAddEventPrintoutInErrLog
Definition: gEvScan.cxx:97
MINOS-style Ntuple Class to hold an MC Event Record Header.
#define pNOTICE
Definition: Messenger.h:61
void Clear(Option_t *opt="")
TTree * gEventTree
Definition: gEvScan.cxx:109
STDHEP-like event record entry that can fit a particle or a nucleus.
Definition: GHepParticle.h:39
EventRecord * event
event
enum genie::EGHepStatus GHepStatus_t
void CheckEnergyMomentumConservation ( void  )

Definition at line 199 of file gEvScan.cxx.

References genie::NtpMCEventRecord::Clear(), genie::GHepParticle::E(), epsilon, genie::NtpMCEventRecord::event, gErrLog, gEventTree, gFirstEventNum, gLastEventNum, gMCRec, gOptAddEventPrintoutInErrLog, gOptMaxNumErrs, genie::NtpMCRecordI::hdr, genie::kIStFinalStateNuclearRemnant, genie::kIStInitialState, genie::kIStStableFinalState, LOG, pERROR, pINFO, pNOTICE, genie::GHepParticle::Px(), genie::GHepParticle::Py(), genie::GHepParticle::Pz(), and genie::GHepParticle::Status().

Referenced by main().

200 {
201  LOG("gevscan", pNOTICE) << "Checking energy/momentum conservation...";
202 
203  if(gErrLog.is_open()) {
204  gErrLog << "# Events failing the energy-momentum conservation test:" << endl;
205  gErrLog << "# " << endl;
206  }
207 
208  int nerr = 0;
209 
210  for(Long64_t i = gFirstEventNum; i <= gLastEventNum; i++)
211  {
212  if(gOptMaxNumErrs != -1 && nerr >= gOptMaxNumErrs) break;
213 
214  gEventTree->GetEntry(i);
215 
216  NtpMCRecHeader rec_header = gMCRec->hdr;
217  EventRecord & event = *(gMCRec->event);
218 
219  LOG("gevscan", pINFO) << "Checking event.... " << i;
220 
221  double E_init = 0, E_fin = 0; // E
222  double px_init = 0, px_fin = 0; // px
223  double py_init = 0, py_fin = 0; // py
224  double pz_init = 0, pz_fin = 0; // pz
225 
226  GHepParticle * p = 0;
227  TIter event_iter(&event);
228  while ( (p = dynamic_cast<GHepParticle *>(event_iter.Next())) ) {
229 
230  GHepStatus_t ist = p->Status();
231 
232  if(ist == kIStInitialState)
233  {
234  E_init += p->E();
235  px_init += p->Px();
236  py_init += p->Py();
237  pz_init += p->Pz();
238  }
239  if(ist == kIStStableFinalState ||
241  {
242  E_fin += p->E();
243  px_fin += p->Px();
244  py_fin += p->Py();
245  pz_fin += p->Pz();
246  }
247  }//p
248 
249  double epsilon = 1E-3;
250 
251  bool E_conserved = TMath::Abs(E_init - E_fin) < epsilon;
252  bool px_conserved = TMath::Abs(px_init - px_fin) < epsilon;
253  bool py_conserved = TMath::Abs(py_init - py_fin) < epsilon;
254  bool pz_conserved = TMath::Abs(pz_init - pz_fin) < epsilon;
255 
256  bool ok = E_conserved &&
257  px_conserved &&
258  py_conserved &&
259  pz_conserved;
260 
261  if(!ok) {
262  LOG("gevscan", pERROR)
263  << " ** Energy-momentum non-conservation in event: " << i
264  << "\n"
265  << event;
266  if(gErrLog.is_open()) {
267  gErrLog << i;
269  gErrLog << event;
270  }
271  }
272  nerr++;
273  }
274 
275  gMCRec->Clear(); // clear out explicitly to prevent memory leak w/Root6
276 
277  }//i
278 
279  if(gErrLog.is_open()) {
280  if(nerr == 0) {
281  gErrLog << "none" << endl;
282  }
283  }
284 
285  LOG("gevscan", pNOTICE)
286  << "Found " << nerr
287  << " events failing the energy/momentum conservation test";
288 }
NtpMCRecHeader hdr
record header
Definition: NtpMCRecordI.h:38
#define pERROR
Definition: Messenger.h:59
double E(void) const
Get energy.
Definition: GHepParticle.h:91
NtpMCEventRecord * gMCRec
Definition: gEvScan.cxx:110
double Pz(void) const
Get Pz.
Definition: GHepParticle.h:90
GHepStatus_t Status(void) const
Definition: GHepParticle.h:64
double Px(void) const
Get Px.
Definition: GHepParticle.h:88
const double epsilon
int gOptMaxNumErrs
Definition: gEvScan.cxx:96
Long64_t gFirstEventNum
Definition: gEvScan.cxx:106
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
Long64_t gLastEventNum
Definition: gEvScan.cxx:107
#define pINFO
Definition: Messenger.h:62
Generated Event Record. It is a GHepRecord object that can accept / be visited by EventRecordVisitorI...
Definition: EventRecord.h:37
ofstream gErrLog
Definition: gEvScan.cxx:111
bool gOptAddEventPrintoutInErrLog
Definition: gEvScan.cxx:97
MINOS-style Ntuple Class to hold an MC Event Record Header.
#define pNOTICE
Definition: Messenger.h:61
void Clear(Option_t *opt="")
TTree * gEventTree
Definition: gEvScan.cxx:109
STDHEP-like event record entry that can fit a particle or a nucleus.
Definition: GHepParticle.h:39
EventRecord * event
event
enum genie::EGHepStatus GHepStatus_t
double Py(void) const
Get Py.
Definition: GHepParticle.h:89
void CheckForNumFinStateNucleonsInconsistentWithTarget ( void  )

Definition at line 506 of file gEvScan.cxx.

References genie::GHepParticle::A(), genie::NtpMCEventRecord::Clear(), genie::NtpMCEventRecord::event, genie::GHepParticle::FirstDaughter(), gErrLog, gEventTree, gFirstEventNum, gLastEventNum, gMCRec, gOptAddEventPrintoutInErrLog, gOptMaxNumErrs, genie::NtpMCRecordI::hdr, genie::pdg::IsIon(), genie::pdg::IsNeutron(), genie::pdg::IsProton(), genie::kIStHadronInTheNucleus, genie::kIStStableFinalState, genie::GHepParticle::LastDaughter(), LOG, genie::GHepParticle::Pdg(), pERROR, pINFO, pNOTICE, genie::GHepParticle::Status(), and genie::GHepParticle::Z().

Referenced by main().

507 {
508  LOG("gevscan", pNOTICE)
509  << "Checking for number of final state nucleons inconsistent with target...";
510 
511  if(gErrLog.is_open()) {
512  gErrLog << "# Events with number of final state nucleons inconsistent with target:" << endl;
513  gErrLog << "# " << endl;
514  }
515 
516  int nerr = 0;
517 
518  for(Long64_t i = gFirstEventNum; i <= gLastEventNum; i++)
519  {
520  if(gOptMaxNumErrs != -1 && nerr >= gOptMaxNumErrs) break;
521 
522  gEventTree->GetEntry(i);
523 
524  NtpMCRecHeader rec_header = gMCRec->hdr;
525  EventRecord & event = *(gMCRec->event);
526 
527  LOG("gevscan", pINFO) << "Checking event.... " << i;
528 
529  // get target nucleus
530  GHepParticle * nucltgt = event.TargetNucleus();
531  if (!nucltgt) {
532  LOG("gevscan", pINFO)
533  << "Event not in nuclear target - Skipping test...";
534  }
535  else {
536  GHepParticle * p = 0;
537 
538  int Z = 0;
539  int N = 0;
540 
541  // get number of spectator nucleons
542  int fd = nucltgt->FirstDaughter();
543  int ld = nucltgt->LastDaughter();
544  for(int d = fd; d <= ld; d++) {
545  p = event.Particle(d);
546  if(!p) continue;
547  int pdgc = p->Pdg();
548  if(pdg::IsIon(pdgc)) {
549  Z = p->Z();
550  N = p->A() - p->Z();
551  }
552  }
553  // add nucleons from the primary interaction
554  TIter event_iter(&event);
555  while ( (p = dynamic_cast<GHepParticle *>(event_iter.Next())) ) {
556  GHepStatus_t ist = p->Status();
557  if(ist != kIStHadronInTheNucleus) continue;
558  int pdgc = p->Pdg();
559  if(pdg::IsProton (pdgc)) { Z++; }
560  if(pdg::IsNeutron(pdgc)) { N++; }
561  }//p
562 
563  LOG("gevscan", pINFO)
564  << "Before intranuclear hadron transport: Z = " << Z << ", N = " << N;
565 
566  // count final state nucleons
567  int Zf = 0;
568  int Nf = 0;
569  event_iter.Reset();
570  while ( (p = dynamic_cast<GHepParticle *>(event_iter.Next())) ) {
571  GHepStatus_t ist = p->Status();
572  if(ist != kIStStableFinalState) continue;
573  int pdgc = p->Pdg();
574  if(pdg::IsProton (pdgc)) { Zf++; }
575  if(pdg::IsNeutron(pdgc)) { Nf++; }
576  }
577  LOG("gevscan", pINFO)
578  << "In the final state: Z = " << Zf << ", N = " << Nf;
579 
580  bool ok = (Zf <= Z && Nf <= N);
581  if(!ok) {
582  LOG("gevscan", pERROR)
583  << " ** Number of final state nucleons inconsistent with target in event: " << i
584  << "\n"
585  << event;
586  if(gErrLog.is_open()) {
587  gErrLog << i << endl;
589  gErrLog << event;
590  }
591  }
592  nerr++;
593  }
594  } //nucltgt
595 
596  gMCRec->Clear(); // clear out explicitly to prevent memory leak w/Root6
597 
598  }//i
599 
600 
601  if(gErrLog.is_open()) {
602  if(nerr == 0) {
603  gErrLog << "none" << endl;
604  }
605  }
606 
607  LOG("gevscan", pNOTICE)
608  << "Found " << nerr
609  << " events with a number of final state nucleons inconsistent with target";
610 }
int Z(void) const
NtpMCRecHeader hdr
record header
Definition: NtpMCRecordI.h:38
#define pERROR
Definition: Messenger.h:59
int FirstDaughter(void) const
Definition: GHepParticle.h:68
NtpMCEventRecord * gMCRec
Definition: gEvScan.cxx:110
GHepStatus_t Status(void) const
Definition: GHepParticle.h:64
int Pdg(void) const
Definition: GHepParticle.h:63
bool IsNeutron(int pdgc)
Definition: PDGUtils.cxx:341
int gOptMaxNumErrs
Definition: gEvScan.cxx:96
Long64_t gFirstEventNum
Definition: gEvScan.cxx:106
int LastDaughter(void) const
Definition: GHepParticle.h:69
bool IsProton(int pdgc)
Definition: PDGUtils.cxx:336
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
Long64_t gLastEventNum
Definition: gEvScan.cxx:107
#define pINFO
Definition: Messenger.h:62
Generated Event Record. It is a GHepRecord object that can accept / be visited by EventRecordVisitorI...
Definition: EventRecord.h:37
bool IsIon(int pdgc)
Definition: PDGUtils.cxx:42
ofstream gErrLog
Definition: gEvScan.cxx:111
bool gOptAddEventPrintoutInErrLog
Definition: gEvScan.cxx:97
MINOS-style Ntuple Class to hold an MC Event Record Header.
int A(void) const
#define pNOTICE
Definition: Messenger.h:61
void Clear(Option_t *opt="")
TTree * gEventTree
Definition: gEvScan.cxx:109
STDHEP-like event record entry that can fit a particle or a nucleus.
Definition: GHepParticle.h:39
EventRecord * event
event
enum genie::EGHepStatus GHepStatus_t
void CheckForOffMassShellParticlesInFinState ( void  )

Definition at line 440 of file gEvScan.cxx.

References genie::NtpMCEventRecord::Clear(), genie::NtpMCEventRecord::event, gErrLog, gEventTree, gFirstEventNum, gLastEventNum, gMCRec, gOptAddEventPrintoutInErrLog, gOptMaxNumErrs, genie::NtpMCRecordI::hdr, genie::GHepParticle::IsOffMassShell(), genie::kIStStableFinalState, LOG, pERROR, pINFO, pNOTICE, and genie::GHepParticle::Status().

Referenced by main().

441 {
442  LOG("gevscan", pNOTICE)
443  << "Checking for off-mass-shell particles appearing in the final state...";
444 
445  if(gErrLog.is_open()) {
446  gErrLog << "# Events with off-mass-shell particles in final state:" << endl;
447  gErrLog << "# " << endl;
448  }
449 
450  int nerr = 0;
451 
452  for(Long64_t i = gFirstEventNum; i <= gLastEventNum; i++)
453  {
454  if(gOptMaxNumErrs != -1 && nerr >= gOptMaxNumErrs) break;
455 
456  gEventTree->GetEntry(i);
457 
458  NtpMCRecHeader rec_header = gMCRec->hdr;
459  EventRecord & event = *(gMCRec->event);
460 
461  LOG("gevscan", pINFO) << "Checking event.... " << i;
462 
463  GHepParticle * p = 0;
464  TIter event_iter(&event);
465  bool ok = true;
466  while ( (p = dynamic_cast<GHepParticle *>(event_iter.Next())) ) {
467 
468  GHepStatus_t ist = p->Status();
469  if(ist != kIStStableFinalState) continue;
470  if(p->IsOffMassShell())
471  {
472  ok = false;
473  break;
474  }
475  }//p
476 
477  if(!ok) {
478  LOG("gevscan", pERROR)
479  << " ** Off-mass-shell final state particle in event: " << i
480  << "\n"
481  << event;
482  if(gErrLog.is_open()) {
483  gErrLog << i << endl;
485  gErrLog << event;
486  }
487  }
488  nerr++;
489  }
490 
491  gMCRec->Clear(); // clear out explicitly to prevent memory leak w/Root6
492 
493  }//i
494 
495  if(gErrLog.is_open()) {
496  if(nerr == 0) {
497  gErrLog << "none" << endl;
498  }
499  }
500 
501  LOG("gevscan", pNOTICE)
502  << "Found " << nerr
503  << " events with off-mass-shell particles in final state";
504 }
NtpMCRecHeader hdr
record header
Definition: NtpMCRecordI.h:38
#define pERROR
Definition: Messenger.h:59
NtpMCEventRecord * gMCRec
Definition: gEvScan.cxx:110
GHepStatus_t Status(void) const
Definition: GHepParticle.h:64
int gOptMaxNumErrs
Definition: gEvScan.cxx:96
Long64_t gFirstEventNum
Definition: gEvScan.cxx:106
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
Long64_t gLastEventNum
Definition: gEvScan.cxx:107
#define pINFO
Definition: Messenger.h:62
bool IsOffMassShell(void) const
Generated Event Record. It is a GHepRecord object that can accept / be visited by EventRecordVisitorI...
Definition: EventRecord.h:37
ofstream gErrLog
Definition: gEvScan.cxx:111
bool gOptAddEventPrintoutInErrLog
Definition: gEvScan.cxx:97
MINOS-style Ntuple Class to hold an MC Event Record Header.
#define pNOTICE
Definition: Messenger.h:61
void Clear(Option_t *opt="")
TTree * gEventTree
Definition: gEvScan.cxx:109
STDHEP-like event record entry that can fit a particle or a nucleus.
Definition: GHepParticle.h:39
EventRecord * event
event
enum genie::EGHepStatus GHepStatus_t
void CheckForPseudoParticlesInFinState ( void  )

Definition at line 373 of file gEvScan.cxx.

References genie::NtpMCEventRecord::Clear(), genie::NtpMCEventRecord::event, gErrLog, gEventTree, gFirstEventNum, gLastEventNum, gMCRec, gOptAddEventPrintoutInErrLog, gOptMaxNumErrs, genie::NtpMCRecordI::hdr, genie::pdg::IsPseudoParticle(), genie::kIStStableFinalState, LOG, genie::GHepParticle::Pdg(), pERROR, pINFO, pNOTICE, and genie::GHepParticle::Status().

Referenced by main().

374 {
375  LOG("gevscan", pNOTICE)
376  << "Checking for pseudo-particles appearing in final state...";
377 
378  if(gErrLog.is_open()) {
379  gErrLog << "# Events with pseudo-particles in final state:" << endl;
380  gErrLog << "# " << endl;
381  }
382 
383  int nerr = 0;
384 
385  for(Long64_t i = gFirstEventNum; i <= gLastEventNum; i++)
386  {
387  if(gOptMaxNumErrs != -1 && nerr >= gOptMaxNumErrs) break;
388 
389  gEventTree->GetEntry(i);
390 
391  NtpMCRecHeader rec_header = gMCRec->hdr;
392  EventRecord & event = *(gMCRec->event);
393 
394  LOG("gevscan", pINFO) << "Checking event.... " << i;
395 
396  GHepParticle * p = 0;
397  TIter event_iter(&event);
398  bool ok = true;
399  while ( (p = dynamic_cast<GHepParticle *>(event_iter.Next())) ) {
400 
401  GHepStatus_t ist = p->Status();
402  if(ist != kIStStableFinalState) continue;
403  int pdgc = p->Pdg();
404  if(pdg::IsPseudoParticle(pdgc))
405  {
406  ok = false;
407  break;
408  }
409  }//p
410 
411  if(!ok) {
412  LOG("gevscan", pERROR)
413  << " ** Pseudo-particle final state particle in event: " << i
414  << "\n"
415  << event;
416  if(gErrLog.is_open()) {
417  gErrLog << i << endl;
419  gErrLog << event;
420  }
421  }
422  nerr++;
423  }
424 
425  gMCRec->Clear(); // clear out explicitly to prevent memory leak w/Root6
426 
427  }//i
428 
429  if(gErrLog.is_open()) {
430  if(nerr == 0) {
431  gErrLog << "none" << endl;
432  }
433  }
434 
435  LOG("gevscan", pNOTICE)
436  << "Found " << nerr
437  << " events with pseudo-particles in final state";
438 }
NtpMCRecHeader hdr
record header
Definition: NtpMCRecordI.h:38
#define pERROR
Definition: Messenger.h:59
NtpMCEventRecord * gMCRec
Definition: gEvScan.cxx:110
GHepStatus_t Status(void) const
Definition: GHepParticle.h:64
int Pdg(void) const
Definition: GHepParticle.h:63
int gOptMaxNumErrs
Definition: gEvScan.cxx:96
Long64_t gFirstEventNum
Definition: gEvScan.cxx:106
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
Long64_t gLastEventNum
Definition: gEvScan.cxx:107
#define pINFO
Definition: Messenger.h:62
Generated Event Record. It is a GHepRecord object that can accept / be visited by EventRecordVisitorI...
Definition: EventRecord.h:37
ofstream gErrLog
Definition: gEvScan.cxx:111
bool IsPseudoParticle(int pdgc)
Definition: PDGUtils.cxx:27
bool gOptAddEventPrintoutInErrLog
Definition: gEvScan.cxx:97
MINOS-style Ntuple Class to hold an MC Event Record Header.
#define pNOTICE
Definition: Messenger.h:61
void Clear(Option_t *opt="")
TTree * gEventTree
Definition: gEvScan.cxx:109
STDHEP-like event record entry that can fit a particle or a nucleus.
Definition: GHepParticle.h:39
EventRecord * event
event
enum genie::EGHepStatus GHepStatus_t
bool CheckRootFilename ( string  filename)

Definition at line 2033 of file gEvComp.cxx.

2034 {
2035  if(filename.size() == 0) return false;
2036 
2037  bool is_accessible = ! (gSystem->AccessPathName(filename.c_str()));
2038  if (!is_accessible) {
2039  LOG("gevcomp", pERROR)
2040  << "The input ROOT file [" << filename << "] is not accessible";
2041  return false;
2042  }
2043  return true;
2044 }
#define pERROR
Definition: Messenger.h:59
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
void CheckVertexDistribution ( void  )

Definition at line 612 of file gEvScan.cxx.

References genie::units::A, genie::GHepParticle::A(), genie::NtpMCEventRecord::Clear(), genie::utils::nuclear::Density(), genie::NtpMCEventRecord::event, gErrLog, gEventTree, gFirstEventNum, gLastEventNum, gMCRec, genie::NtpMCRecordI::hdr, genie::constants::kPi, LOG, pINFO, pNOTICE, Write(), genie::GHepParticle::X4(), and genie::GHepParticle::Z().

Referenced by main().

613 {
614  LOG("gevscan", pNOTICE)
615  << "Checking intra-nuclear vertex distribution...";
616 
617  if(gErrLog.is_open()) {
618  gErrLog << "# Intranuclear vertex distribution check:" << endl;
619  gErrLog << "# " << endl;
620  }
621 
622  TH1D * r_distr_mc = new TH1D("r_distr_mc","", 150,0,30); //fm
623  TH1D * r_distr_expected = new TH1D("r_distr_expected","",150,0,30); //fm
624 
625  int Z = -1;
626  int A = -1;
627 
628  // get vertex position distribution
629  for(Long64_t i = gFirstEventNum; i <= gLastEventNum; i++)
630  {
631  gEventTree->GetEntry(i);
632 
633  NtpMCRecHeader rec_header = gMCRec->hdr;
634  EventRecord & event = *(gMCRec->event);
635 
636  LOG("gevscan", pINFO) << "Checking event.... " << i;
637 
638  // get target nucleus
639  GHepParticle * nucltgt = event.TargetNucleus();
640  if (!nucltgt) {
641  LOG("gevscan", pINFO)
642  << "Event not in nuclear target - Skipping...";
643  }
644  else {
645  if(Z == -1 && A == -1) {
646  Z = nucltgt->Z();
647  A = nucltgt->A();
648  }
649 
650  // this test is run on a MC sample for a given target
651  if(Z != nucltgt->Z() || A != nucltgt->A()) {
652  LOG("gevscan", pINFO)
653  << "Event not in nuclear target seen first - Skipping...";
654  }
655  else {
656  GHepParticle * probe = event.Particle(0);
657  double r = probe->X4()->Vect().Mag();
658 
659  r_distr_mc->Fill(r);
660  }
661  } //nucltgt
662 
663  gMCRec->Clear(); // clear out explicitly to prevent memory leak w/Root6
664 
665  }//i
666 
667  if(A > 1) {
668  // get expected vertex position distribution
669  for(int ir = 1; ir <= r_distr_expected->GetNbinsX(); ir++) {
670  double r = r_distr_expected->GetBinCenter(ir);
671  double rho = utils::nuclear::Density(r,A);
672  double nexp = 4*kPi*r*r*rho;
673  r_distr_expected->SetBinContent(ir,nexp);
674  }
675 
676  // normalize
677  double N = r_distr_mc->GetEntries();
678  r_distr_expected -> Scale (N / r_distr_expected -> Integral());
679 
680  // check consistency
681  double pvalue = r_distr_mc->Chi2Test(r_distr_expected,"WWP");
682  LOG("gevscan", pNOTICE) << "p-value {\\chi^2 test} = " << pvalue;
683 
684  if(gErrLog.is_open()) {
685  if(pvalue < 0.99) {
686  gErrLog << "Problem! p-value = " << pvalue << endl;
687  } else {
688  gErrLog << "OK! p-value = " << pvalue << endl;
689  }
690  }
691 
692 #ifdef __debug__
693  TFile f("./check_vtx.root","recreate");
694  r_distr_mc -> Write();
695  r_distr_expected -> Write();
696  f.Close();
697 #endif
698 
699  }//A
700  else {
701 
702  if(gErrLog.is_open()) {
703  gErrLog << "Can not run test with current sample" << endl;
704  }
705 
706  }
707 
708 }
int Z(void) const
NtpMCRecHeader hdr
record header
Definition: NtpMCRecordI.h:38
NtpMCEventRecord * gMCRec
Definition: gEvScan.cxx:110
Long64_t gFirstEventNum
Definition: gEvScan.cxx:106
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
static constexpr double A
Definition: Units.h:74
Long64_t gLastEventNum
Definition: gEvScan.cxx:107
#define pINFO
Definition: Messenger.h:62
Generated Event Record. It is a GHepRecord object that can accept / be visited by EventRecordVisitorI...
Definition: EventRecord.h:37
ofstream gErrLog
Definition: gEvScan.cxx:111
const TLorentzVector * X4(void) const
Definition: GHepParticle.h:79
hadnt Write("hadnt")
MINOS-style Ntuple Class to hold an MC Event Record Header.
int A(void) const
#define pNOTICE
Definition: Messenger.h:61
void Clear(Option_t *opt="")
TTree * gEventTree
Definition: gEvScan.cxx:109
STDHEP-like event record entry that can fit a particle or a nucleus.
Definition: GHepParticle.h:39
double Density(double r)
Definition: PREM.cxx:18
EventRecord * event
event
void GetCommandLineArgs ( int  argc,
char **  argv 
)
int main ( int  argc,
char **  argv 
)

Definition at line 114 of file gEvScan.cxx.

References genie::NtpMCFormat::AsString(), CheckChargeConservation(), CheckDecayerConsistency(), CheckEnergyMomentumConservation(), CheckForNumFinStateNucleonsInconsistentWithTarget(), CheckForOffMassShellParticlesInFinState(), CheckForPseudoParticlesInFinState(), CheckVertexDistribution(), genie::gAbortingInErr, gErrLog, GetCommandLineArgs(), gEventTree, gFirstEventNum, gLastEventNum, gMCRec, gOptCheckChargeConservation, gOptCheckDecayerConsistency, gOptCheckEnergyMomentumConservation, gOptCheckForNumFinStateNucleonsInconsistentWithTarget, gOptCheckForOffMassShellParticlesInFinState, gOptCheckForPseudoParticlesInFinState, gOptCheckVertexDistribution, gOptInpFilename, gOptNEvtH, gOptNEvtL, gOptOutFilename, genie::RunOpt::Instance(), genie::kNFGHEP, LOG, pERROR, pFATAL, pINFO, PrintSyntax(), and genie::GHepRecord::SetPrintLevel().

115 {
116  GetCommandLineArgs (argc, argv);
117 
118  // Set GHEP print level
119  GHepRecord::SetPrintLevel(RunOpt::Instance()->EventRecordPrintLevel());
120 
121  TFile file(gOptInpFilename.c_str(),"READ");
122 
123  NtpMCTreeHeader * thdr = dynamic_cast <NtpMCTreeHeader *> ( file.Get("header") );
124  LOG("gevscan", pINFO) << "Input tree header: " << *thdr;
125  NtpMCFormat_t format = thdr->format;
126  if(format != kNFGHEP) {
127  LOG("gevscan", pERROR)
128  << "*** Unsupported event-tree format : "
129  << NtpMCFormat::AsString(format);
130  file.Close();
131  return 3;
132  }
133 
134  gEventTree = dynamic_cast <TTree *> (file.Get("gtree"));
135  gEventTree->SetBranchAddress("gmcrec", &gMCRec);
136 
137  Long64_t nev = gEventTree->GetEntries();
138  if(gOptNEvtL == -1 && gOptNEvtH == -1) {
139  // read all events
140  gFirstEventNum = 0;
141  gLastEventNum = nev-1;
142  }
143  else {
144  // read a range of events
145  gFirstEventNum = TMath::Max((Long64_t)0, gOptNEvtL);
146  gLastEventNum = TMath::Min(nev-1, gOptNEvtH);
147  if(gLastEventNum - gFirstEventNum < 0) {
148  LOG("gevdump", pFATAL) << "Invalid event range";
149  PrintSyntax();
150  gAbortingInErr = true;
151  exit(1);
152  }
153  }
154 
155 
156  if(gOptOutFilename.size() == 0) {
157  ostringstream logfile;
158  logfile << gOptInpFilename << ".errlog";
159  gOptOutFilename = logfile.str();
160  }
161  if(gOptOutFilename != "none") {
162  gErrLog.open(gOptOutFilename.c_str());
163  gErrLog << "# ..................................................................................." << endl;
164  gErrLog << "# Error log for event file " << gOptInpFilename << endl;
165  gErrLog << "# ..................................................................................." << endl;
166  gErrLog << "# " << endl;
167  }
168 
171  }
174  }
177  }
180  }
183  }
186  }
189  }
190 
191 
192  if(gOptOutFilename != "none") {
193  gErrLog.close();
194  }
195 
196  return 0;
197 }
void CheckDecayerConsistency(void)
Definition: gEvScan.cxx:710
void CheckEnergyMomentumConservation(void)
Definition: gEvScan.cxx:199
bool gOptCheckVertexDistribution
Definition: gEvScan.cxx:103
#define pERROR
Definition: Messenger.h:59
bool gOptCheckForPseudoParticlesInFinState
Definition: gEvScan.cxx:100
NtpMCEventRecord * gMCRec
Definition: gEvScan.cxx:110
#define pFATAL
Definition: Messenger.h:56
Long64_t gFirstEventNum
Definition: gEvScan.cxx:106
void CheckForOffMassShellParticlesInFinState(void)
Definition: gEvScan.cxx:440
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
Long64_t gOptNEvtL
Definition: gEvDump.cxx:74
MINOS-style Ntuple Class to hold an output MC Tree Header.
Long64_t gLastEventNum
Definition: gEvScan.cxx:107
void CheckForPseudoParticlesInFinState(void)
Definition: gEvScan.cxx:373
#define pINFO
Definition: Messenger.h:62
void CheckForNumFinStateNucleonsInconsistentWithTarget(void)
Definition: gEvScan.cxx:506
void CheckVertexDistribution(void)
Definition: gEvScan.cxx:612
bool gOptCheckForNumFinStateNucleonsInconsistentWithTarget
Definition: gEvScan.cxx:102
bool gOptCheckChargeConservation
Definition: gEvScan.cxx:99
void CheckChargeConservation(void)
Definition: gEvScan.cxx:290
bool gOptCheckForOffMassShellParticlesInFinState
Definition: gEvScan.cxx:101
string gOptInpFilename
Definition: gEvDump.cxx:76
bool gOptCheckDecayerConsistency
Definition: gEvScan.cxx:104
ofstream gErrLog
Definition: gEvScan.cxx:111
bool gOptCheckEnergyMomentumConservation
Definition: gEvScan.cxx:98
Long64_t gOptNEvtH
Definition: gEvDump.cxx:75
const char * AsString(Resonance_t res)
resonance id -&gt; string
enum genie::ENtpMCFormat NtpMCFormat_t
void GetCommandLineArgs(int argc, char **argv)
Definition: gAtmoEvGen.cxx:563
bool gAbortingInErr
Definition: Messenger.cxx:34
TTree * gEventTree
Definition: gEvScan.cxx:109
void PrintSyntax(void)
string gOptOutFilename
Definition: gEvScan.cxx:93
void PrintSyntax ( void  )

Variable Documentation

ofstream gErrLog
TTree* gEventTree = 0
Long64_t gFirstEventNum = -1
Long64_t gLastEventNum = -1
NtpMCEventRecord* gMCRec = 0
bool gOptAddEventPrintoutInErrLog = false
bool gOptCheckChargeConservation = false

Definition at line 99 of file gEvScan.cxx.

Referenced by main().

bool gOptCheckDecayerConsistency = false

Definition at line 104 of file gEvScan.cxx.

Referenced by main().

bool gOptCheckEnergyMomentumConservation = false

Definition at line 98 of file gEvScan.cxx.

Referenced by main().

bool gOptCheckForNumFinStateNucleonsInconsistentWithTarget = false

Definition at line 102 of file gEvScan.cxx.

Referenced by main().

bool gOptCheckForOffMassShellParticlesInFinState = false

Definition at line 101 of file gEvScan.cxx.

Referenced by main().

bool gOptCheckForPseudoParticlesInFinState = false

Definition at line 100 of file gEvScan.cxx.

Referenced by main().

bool gOptCheckVertexDistribution = false

Definition at line 103 of file gEvScan.cxx.

Referenced by main().

string gOptInpFilename = ""

Definition at line 92 of file gEvScan.cxx.

int gOptMaxNumErrs = -1
Long64_t gOptNEvtH = -1

Definition at line 95 of file gEvScan.cxx.

Long64_t gOptNEvtL = -1

Definition at line 94 of file gEvScan.cxx.

string gOptOutFilename = ""

Definition at line 93 of file gEvScan.cxx.

Referenced by main().