Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JHead.hh
Go to the documentation of this file.
1 #ifndef __JAANET__JHEAD__
2 #define __JAANET__JHEAD__
3 
4 #include <string>
5 #include <vector>
6 #include <cmath>
7 #include <ctype.h>
8 #include <sstream>
9 
10 #include "TObject.h"
11 
14 
15 #include "JLang/JException.hh"
17 #include "JLang/JLangToolkit.hh"
18 
19 #include "JROOT/JRootClass.hh"
20 
21 
22 /**
23  * \author mdejong
24  */
25 
26 namespace JAANET {}
27 namespace JPP { using namespace JAANET; }
28 
29 namespace JAANET {
30 
31  using JLANG::JException;
33 
34 
35  static const char AANET_TAG_SEPARATOR = '_'; //!< Separator for AAnet tag extension for multiple tags ("_<counter>").
36 
37  class JHead; // forward declaration for copy methods
38 
39 
40  /**
41  * Copy header from <tt>from</tt> to <tt>to</tt>.
42  *
43  * \param from header
44  * \param to header
45  */
46  extern void copy(const JHead& from, Head& to);
47 
48 
49  /**
50  * Copy header from <tt>from</tt> to <tt>to</tt>.
51  *
52  * \param from header
53  * \param to header
54  */
55  extern void copy(const Head& from, JHead& to);
56 
57 
58  /**
59  * Get tag without aanet extension "_<counter>" for identical tags.
60  *
61  * \param tag tag
62  * \return tag
63  */
64  inline std::string getTag(const std::string& tag)
65  {
66  using namespace std;
67 
68  const string::size_type pos = tag.find(AANET_TAG_SEPARATOR);
69 
70  if (pos != string::npos) {
71 
72  for (string::size_type i = pos + 1; i != tag.size(); ++i) {
73  if (!isdigit(tag[i])) {
74  return tag;
75  }
76  }
77 
78  return tag.substr(0, pos);
79  }
80 
81  return tag;
82  }
83 
84 
85  /**
86  * Get tag with aanet extension "_<counter>" for identical tags.
87  *
88  * \param tag tag
89  * \param counter counter
90  * \return tag
91  */
92  inline std::string getTag(const std::string& tag, const int counter)
93  {
94  std::ostringstream os;
95 
96  os << tag << AANET_TAG_SEPARATOR << counter;
97 
98  return os.str();
99  }
100 
101 
102  /**
103  * Start of run record.
104  */
105  struct start_run {
106  /**
107  * Default constructor.
108  */
110  run_id(0)
111  {}
112 
113  int run_id; ///< MC run number
114 
116  };
117 
118 
119  /**
120  * General purpose string class.
121  */
122  struct String {
123  /**
124  * Default constructor.
125  */
126  String() :
127  buffer()
128  {}
129 
130  /**
131  * Test match.
132  *
133  * \param object string
134  * \return true if matches; else false
135  */
136  inline bool match(const String& object) const
137  {
138  return !(*this).less(object) && !(object).less(*this);
139  }
140 
141  /**
142  * Comparison.
143  *
144  * \param object string
145  * \return true if this string less than given string; else false
146  */
147  inline bool less(const String& object) const
148  {
149  using namespace std;
150 
151  istringstream i0(this ->buffer);
152  istringstream i1(object.buffer);
153 
154  vector<string> v0;
155  vector<string> v1;
156 
157  copy(istream_iterator<string>(i0), istream_iterator<string>(), back_inserter(v0));
158  copy(istream_iterator<string>(i1), istream_iterator<string>(), back_inserter(v1));
159 
160  return v0 < v1;
161  }
162 
163  /**
164  * Read string from input stream.
165  *
166  * \param in input stream
167  * \param object string
168  * \return input stream
169  */
170  friend inline std::istream& operator>>(std::istream& in, String& object)
171  {
172  return std::getline(in, object.buffer);
173  }
174 
175  /**
176  * Write string to output stream.
177  *
178  * \param out output stream
179  * \param object string
180  * \return output stream
181  */
182  friend inline std::ostream& operator<<(std::ostream& out, const String& object)
183  {
184  return out << object.buffer;
185  }
186 
187  std::string buffer; ///< General purpose name
188 
189  ClassDefNV(String,1);
190  };
191 
192 
193  /**
194  * Detector file.
195  */
196  struct detector
197  {
198  /**
199  * Default constructor.
200  */
202  {}
203 
204  /**
205  * Test match.
206  *
207  * \param object detector
208  * \return true if matches; else false
209  */
210  inline bool match(const detector& object) const
211  {
212  return this->program == object.program && this->filename == object.filename;
213  }
214 
215  /**
216  * Read detector from input stream.
217  *
218  * \param in input stream
219  * \param object detector
220  * \return input stream
221  */
222  friend inline std::istream& operator>>(std::istream& in, detector& object)
223  {
224  using namespace JPP;
225 
226  in >> object.program >> object.filename;
227 
228  if (!in || is_integer(object.filename)) { // legacy
229  object.filename = object.program;
230  object.program = "?";
231  }
232 
233  return in;
234  }
235 
236  /**
237  * Write detector to output stream.
238  *
239  * \param out output stream
240  * \param object detector
241  * \return output stream
242  */
243  friend inline std::ostream& operator<<(std::ostream& out, const detector& object)
244  {
245  return out << object.program << ' ' << object.filename;
246  }
247 
248  std::string program;
249  std::string filename;
250 
251  ClassDefNV(detector,1);
252  };
253 
254 
255  /**
256  * Muon descriptor file.
257  */
258  struct muon_desc_file :
259  public String
260  {
262  };
263 
264 
265  /**
266  * Target.
267  */
268  struct target :
269  public String
270  {
271  ClassDefNV(target,1);
272  };
273 
274 
275  /**
276  * Neutrino cross section file.
277  */
278  struct XSecFile :
279  public String
280  {
281  ClassDefNV(XSecFile,1);
282  };
283 
284 
285  /**
286  * Drawing.
287  */
288  struct drawing :
289  public String
290  {
291  ClassDefNV(drawing,1);
292  };
293 
294 
295  /**
296  * General purpose class of phase space generation.
297  */
298  struct cut {
299  /**
300  * Default constructor.
301  */
302  cut() :
303  Emin(0),
304  Emax(0),
305  cosTmin(0),
306  cosTmax(0)
307  {}
308 
309  /**
310  * Comparison.
311  *
312  * \param object cut
313  * \return true if this cut less than given cut; else false
314  */
315  inline bool less(const cut& object) const
316  {
317  if (Emin == object.Emin) {
318 
319  if (Emax == object.Emax) {
320 
321  if (cosTmin == object.cosTmin)
322  return cosTmax < object.cosTmax;
323  else
324  return cosTmin < object.cosTmin;
325 
326  } else {
327 
328  return Emax < object.Emax;
329  }
330 
331  } else {
332 
333  return Emin < object.Emin;
334  }
335  }
336 
337  /**
338  * Test match.
339  *
340  * \param object cut
341  * \return true if matches; else false
342  */
343  inline bool match(const cut& object) const
344  {
345  return (Emin == object.Emin &&
346  Emax == object.Emax &&
347  cosTmin == object.cosTmin &&
348  cosTmax == object.cosTmax);
349  }
350 
351  double Emin; ///< Minimal energy [GeV]
352  double Emax; ///< Maximal energy [GeV]
353  double cosTmin; ///< Minimal cosine zenith angle
354  double cosTmax; ///< Maximal cosine zenith angle
355 
356  ClassDefNV(cut,1);
357  };
358 
359 
360  /**
361  * Phase space of primary particle.
362  */
363  struct cut_primary :
364  public cut
365  {
367  };
368 
369 
370  /**
371  * Phase space of atmospheric muon generation.
372  */
373  struct cut_seamuon :
374  public cut
375  {
377  };
378 
379 
380  /**
381  * Phase space of incoming particle
382  */
383  struct cut_in :
384  public cut
385  {
386  ClassDefNV(cut_in,1);
387  };
388 
389 
390  /**
391  * Phase space of incident neutrino.
392  */
393  struct cut_nu :
394  public cut
395  {
396  ClassDefNV(cut_nu,1);
397  };
398 
399 
400  /**
401  * Description of Monte Carlo event generation applications.
402  */
403  struct generator {
404  /**
405  * Default constructor.
406  */
408  program(),
409  version(),
410  date(),
411  time()
412  {}
413 
414  /**
415  * Comparison.
416  *
417  * \param object generator
418  * \return true if this primary particle is less than given primary particle; else false
419  */
420  inline bool less(const generator& object) const
421  {
422  return program < object.program;
423  }
424 
425  /**
426  * Test match.
427  *
428  * Note that only the name of program is matched.
429  *
430  * \param object generator
431  * \return true if matches; else false
432  */
433  inline bool match(const generator& object) const
434  {
435  return program == object.program;
436  }
437 
438  std::string program; ///< program name
439  std::string version; ///< program version
440  std::string date; ///< processing date
441  std::string time; ///< processing time
442 
444  };
445 
446 
447  /**
448  * Physics information.
449  */
450  struct physics :
451  public String
452  {
453  ClassDefNV(physics,1);
454  };
455 
456 
457  /**
458  * Generator for simulation.
459  */
460  struct simul :
461  public generator
462  {
463  ClassDefNV(simul,1);
464  };
465 
466 
467  /**
468  * Neutrino energy spectrum.
469  */
470  struct spectrum {
471  /**
472  * Default constructor.
473  */
474  spectrum() :
475  alpha(0)
476  {}
477 
478  /**
479  * Comparison.
480  *
481  * \param object spectrum
482  * \return true if this spectrum less than given spectrum; else false
483  */
484  inline bool less(const spectrum& object) const
485  {
486  return alpha < object.alpha;
487  }
488 
489  /**
490  * Test match.
491  *
492  * \param object spectrum
493  * \return true if matches; else false
494  */
495  inline bool match(const spectrum& object) const
496  {
497  return (alpha == object.alpha);
498  }
499 
500  double alpha; ///< Energy spectrum: \f$ \Phi \propto E^{-\alpha} \f$
501 
502  ClassDefNV(spectrum,1);
503  };
504 
505 
506  /**
507  * The cylinder used for photon tracking.
508  */
509  struct can {
510  /**
511  * Default constructor.
512  */
513  can() :
514  zmin(0),
515  zmax(0),
516  r(0)
517  {}
518 
519  /**
520  * Test match.
521  *
522  * \param object can
523  * \return true if matches; else false
524  */
525  inline bool match(const can& object) const
526  {
527  return (zmin == object.zmin &&
528  zmax == object.zmax &&
529  r == object.r);
530  }
531 
532  double zmin; ///< Bottom [m]
533  double zmax; ///< Top [m]
534  double r; ///< Radius [m]
535 
536  ClassDefNV(can,1);
537  };
538 
539 
540  /**
541  * The fixed cylinder used for photon tracking.
542  */
543  struct fixedcan {
544  /**
545  * Default constructor.
546  */
548  xcenter(0),
549  ycenter(0),
550  zmin(0),
551  zmax(0),
552  radius(0)
553  {}
554 
555  /**
556  * Test match.
557  *
558  * \param object can
559  * \return true if matches; else false
560  */
561  inline bool match(const fixedcan& object) const
562  {
563  return (xcenter == object.xcenter &&
564  xcenter == object.ycenter &&
565  zmin == object.zmin &&
566  zmax == object.zmax &&
567  radius == object.radius);
568  }
569 
570  double xcenter; ///< x-center [m]
571  double ycenter; ///< y-center [m]
572  double zmin; ///< Bottom [m]
573  double zmax; ///< Top [m]
574  double radius; ///< Radius [m]
575 
576  ClassDefNV(fixedcan,1);
577  };
578 
579 
580  /**
581  * Neutrino vertex volume.
582  */
583  struct genvol {
584  /**
585  * Default constructor.
586  */
587  genvol() :
588  zmin(0),
589  zmax(0),
590  r(0),
591  volume(0),
592  numberOfEvents(0)
593  {}
594 
595  /**
596  * Comparison.
597  *
598  * \param object genvol
599  * \return true if this genvol less than given genvol; else false
600  */
601  inline bool less(const genvol& object) const
602  {
603  return volume < object.volume;
604  }
605 
606  /**
607  * Test match.
608  *
609  * \param object generation volume
610  * \return true if matches; else false
611  */
612  inline bool match(const genvol& object) const
613  {
614  return (zmin == object.zmin &&
615  zmax == object.zmax &&
616  r == object.r);
617  }
618 
619  /**
620  * Addition.
621  *
622  * \param object generation volume
623  * \return this generation volume
624  */
625  inline genvol& add(const genvol& object)
626  {
627  numberOfEvents += object.numberOfEvents;
628 
629  return *this;
630  }
631 
632  /**
633  * Scale.
634  *
635  * \param factor 1D scale factor
636  * \param z z position
637  * \return this genvol
638  */
639  inline genvol& mul(const double factor,
640  const double z = 0.0)
641  {
642  zmin = (zmin - z) * factor + z;
643  zmax = (zmax - z) * factor + z;
644  r *= factor;
645  volume *= factor * factor * factor;
646 
647  return *this;
648  }
649 
650  double zmin; ///< Bottom [m]
651  double zmax; ///< Top [m]
652  double r; ///< Radius [m]
653  double volume; ///< Volume [m^3]
654  double numberOfEvents; ///< Number of events
655 
656  ClassDefNV(genvol,1);
657  };
658 
659 
660  /**
661  * Coordinate origin.
662  */
663  struct coord_origin :
664  public Vec
665  {
666  /**
667  * Default constructor.
668  */
670  Vec()
671  {}
672 
673  /**
674  * Constructor.
675  *
676  * \param x x position
677  * \param y y position
678  * \param z z position
679  */
680  coord_origin(const double x,
681  const double y,
682  const double z) :
683  Vec(x,y,z)
684  {}
685 
686  /**
687  * Test match.
688  *
689  * \param object coordinate origin
690  * \return true if matches; else false
691  */
692  inline bool match(const coord_origin& object) const
693  {
694  return (x == object.x &&
695  y == object.y &&
696  z == object.z);
697  }
698 
700  };
701 
702 
703  /**
704  * Phase space for incident neutrino.
705  */
706  struct genhencut {
707  /**
708  * Default constructor.
709  */
711  gDir(0),
712  Emin(0)
713  {}
714 
715  double gDir; ///< Angle
716  double Emin; ///< Minimal energy [GeV]
717 
719  };
720 
721 
722  /**
723  * Normlisation of CORSIKA events.
724  */
725  struct norma {
726  /**
727  * Default constructor.
728  */
729  norma() :
730  primaryFlux(0),
731  numberOfPrimaries(0)
732  {}
733 
734  /**
735  * Test match.
736  *
737  * \param object normalisation
738  * \return true if matches; else false
739  */
740  inline bool match(const norma& object) const
741  {
742  return (primaryFlux == object.primaryFlux);
743  }
744 
745  /**
746  * Addition.
747  *
748  * \param object normalisation
749  * \return this normalisation
750  */
751  inline norma& add(const norma& object)
752  {
753  numberOfPrimaries += object.numberOfPrimaries;
754 
755  return *this;
756  }
757 
758  double primaryFlux; ///< Primary flux
759  double numberOfPrimaries; ///< Number of primaries
760 
761  ClassDefNV(norma,1);
762  };
763 
764 
765  /**
766  * Normalisation of MUPAGE events.
767  */
768  struct livetime {
769  /**
770  * Default constructor.
771  */
773  numberOfSeconds(0),
774  errorOfSeconds(0)
775  {}
776 
777  /**
778  * Comparison.
779  *
780  * \param object livetime
781  * \return true if this livetime is less than given livetime; else false
782  */
783  inline bool less(const livetime& object) const
784  {
785  return numberOfSeconds < object.numberOfSeconds;
786  }
787 
788  /**
789  * Test match.
790  *
791  * \param object live time
792  * \return true if matches; else false
793  */
794  inline bool match(const livetime& object) const
795  {
796  return ((numberOfSeconds == 0.0 && object.numberOfSeconds == 0.0) ||
797  (numberOfSeconds > 0.0 && object.numberOfSeconds > 0.0));
798  }
799 
800  /**
801  * Addition.
802  *
803  * \param object live time
804  * \return this live time
805  */
806  inline livetime& add(const livetime& object)
807  {
808  numberOfSeconds += object.numberOfSeconds;
809  errorOfSeconds = sqrt(errorOfSeconds * errorOfSeconds +
810  object.errorOfSeconds * object.errorOfSeconds);
811 
812  return *this;
813  }
814 
815  /**
816  * Scale.
817  *
818  * \param factor 1D scale factor
819  * \return this livetime
820  */
821  inline livetime& mul(const double factor)
822  {
823  numberOfSeconds /= (factor * factor);
824  errorOfSeconds /= (factor * factor);
825 
826  return *this;
827  }
828 
829  double numberOfSeconds; ///< Live time [s]
830  double errorOfSeconds; ///< Uncertainty on live time [s]
831 
832  ClassDefNV(livetime,1);
833  };
834 
835 
836  /**
837  * Neutrino flux.
838  */
839  struct flux {
840  public:
841  /**
842  * Default constructor.
843  */
844  flux() :
845  type(0),
846  key(),
847  file_1(),
848  file_2()
849  {}
850 
851  int type; ///< Type
852  std::string key; ///< Key
853  std::string file_1; ///< File name
854  std::string file_2; ///< File name
855 
856  ClassDefNV(flux,1);
857  };
858 
859 
860  /**
861  * The bottom of the sea.
862  */
863  struct seabottom {
864  /**
865  * Default constructor.
866  */
868  z(0)
869  {}
870 
871  /**
872  * Test match.
873  *
874  * \param object sea bottom
875  * \return true if matches; else false
876  */
877  inline bool match(const seabottom& object) const
878  {
879  return (z == object.z);
880  }
881 
882  double z; ///< Sea bottom [m]
883 
885  };
886 
887 
888  /**
889  * Depth.
890  */
891  struct depth {
892  /**
893  * Default constructor.
894  */
895  depth() :
896  z(0)
897  {}
898 
899  /**
900  * Test match.
901  *
902  * \param object sea bottom
903  * \return true if matches; else false
904  */
905  inline bool match(const depth& object) const
906  {
907  return (z == object.z);
908  }
909 
910  double z; ///< Sea bottom [m]
911 
912  ClassDefNV(depth,1);
913  };
914 
915 
916  /**
917  * Livetime of DAQ data.
918  */
919  struct DAQ {
920  public:
921  /**
922  * Default constructor.
923  */
924  DAQ() :
925  livetime_s(0.0)
926  {}
927 
928  /**
929  * Comparison.
930  *
931  * \param object DAQ
932  * \return true if this DAQ is less than given DAQ; else false
933  */
934  inline bool less(const DAQ& object) const
935  {
936  return livetime_s < object.livetime_s;
937  }
938 
939  /**
940  * Test match.
941  *
942  * \param object DAQ
943  * \return true if matches; else false
944  */
945  inline bool match(const DAQ& object) const
946  {
947  return ((livetime_s == 0.0 && object.livetime_s == 0.0) ||
948  (livetime_s > 0.0 && object.livetime_s > 0.0));
949  }
950 
951  /**
952  * Addition.
953  *
954  * \param object DAQ
955  * \return this DAQ
956  */
957  inline DAQ& add(const DAQ& object)
958  {
959  livetime_s += object.livetime_s;
960 
961  return *this;
962  }
963 
964  double livetime_s; ///< Live time [s]
965 
966  ClassDefNV(DAQ,1);
967  };
968 
969 
970  /**
971  * Scaling time of neutrino interaction generators (number of seconds in one year).
972  */
973  struct tgen {
974  /**
975  * Default constructor.
976  */
977  tgen() :
978  numberOfSeconds(0)
979  {}
980 
981  double numberOfSeconds; ///< Time in seconds
982 
983  ClassDefNV(tgen,1);
984  };
985 
986 
987  /**
988  * Primary particle.
989  */
990  struct primary {
991  /**
992  * Default constructor.
993  */
994  primary() :
995  type(0)
996  {}
997 
998  /**
999  * Comparison.
1000  *
1001  * \param object primary particle
1002  * \return true if this primary particle is less than given primary particle; else false
1003  */
1004  inline bool less(const primary& object) const
1005  {
1006  return type < object.type;
1007  }
1008 
1009  /**
1010  * Test match.
1011  *
1012  * \param object primary particle
1013  * \return true if matches; else false
1014  */
1015  inline bool match(const primary& object) const
1016  {
1017  return (type == object.type);
1018  }
1019 
1020  int type; ///< Particle type
1021 
1022  ClassDefNV(primary,1);
1023  };
1024 
1025 
1026  /**
1027  * End of event record.
1028  */
1029  struct end_event {
1030  /**
1031  * Default constructor.
1032  */
1034  {}
1035 
1036  ClassDefNV(end_event,1);
1037  };
1038 
1039 
1040  /**
1041  * Monte Carlo run header.
1042  *
1043  * This class extends the Head class so that the data from specific tags
1044  * can be promoted to concrete data types.
1045  *
1046  * Note that for the copy of new JHead data (e.g.\ data not obtained via a previous JAANET::copy) to become effective,
1047  * the key words in the corresponding map of the Head class should be set. \n
1048  * To this end, member method JHead::push can be used.
1049  */
1050  struct JHead :
1051  public Head
1052  {
1053  /**
1054  * Default constructor.
1055  */
1057  {}
1058 
1059 
1060  /**
1061  * Copy constructor.
1062  *
1063  * \param header header
1064  */
1065  JHead(const Head& header)
1066  {
1067  copy(header, *this);
1068  }
1069 
1070 
1071  /**
1072  * Virtual destructor.
1073  */
1074  virtual ~JHead()
1075  {}
1076 
1077 
1078  /**
1079  * Get header.
1080  *
1081  * \return header
1082  */
1083  const JHead& getHeader() const
1084  {
1085  return static_cast<const JHead&>(*this);
1086  }
1087 
1088 
1089  /**
1090  * Get header.
1091  *
1092  * \return header
1093  */
1095  {
1096  return static_cast<JHead&>(*this);
1097  }
1098 
1099 
1100  /**
1101  * Set header.
1102  *
1103  * \param header header
1104  */
1105  void setHeader(const JHead& header)
1106  {
1107  static_cast<JHead&>(*this) = header;
1108  }
1109 
1110 
1111  /**
1112  * Check validity of given data member in JHead.
1113  *
1114  * The validity is defined by the presence of the name of the data member in the underlying map.
1115  *
1116  * \param pd pointer to data member
1117  * \return true if valid; else false
1118  */
1119  template<class T>
1120  inline bool is_valid(T JHead::*pd) const
1121  {
1122  return (this->pull(pd) != this->end());
1123  }
1124 
1125 
1126  /**
1127  * Check validity of given data member in JHead.
1128  *
1129  * The validity is defined by difference between actual and default value.
1130  *
1131  * \param object object
1132  * \return true if valid; else false
1133  */
1134  template<class T>
1135  static bool is_valid(const T& object)
1136  {
1137  static const T value;
1138 
1139  return (object.less(value) || value.less(object));
1140  }
1141 
1142 
1143  /**
1144  * Pull given data member from Head.
1145  *
1146  * \param pd pointer to data member
1147  * \return iterator of Head
1148  */
1149  template<class T>
1150  inline const_iterator pull(T JHead::*pd) const
1151  {
1152  return this->find(JROOT::getDataMember(pd)->GetName());
1153  }
1154 
1155 
1156  /**
1157  * Pull given data member from Head.
1158  *
1159  * \param pd pointer to data member
1160  * \return iterator of Head
1161  */
1162  template<class T>
1163  inline iterator pull(T JHead::*pd)
1164  {
1165  return this->find(JROOT::getDataMember(pd)->GetName());
1166  }
1167 
1168 
1169  /**
1170  * Push given data member to Head.
1171  *
1172  * \param pd pointer to data member
1173  */
1174  template<class T>
1175  inline void push(T JHead::*pd)
1176  {
1177  (*this)[JROOT::getDataMember(pd)->GetName()] = "";
1178  }
1179 
1180 
1181  /**
1182  * Remove given data member from Head.
1183  *
1184  * \param pd pointer to data member
1185  */
1186  template<class T>
1187  inline void erase(T JHead::*pd)
1188  {
1189  iterator p = this->pull(pd);
1190 
1191  if (p != this->end()) {
1192 
1193  this->*pd = T();
1194 
1195  static_cast<Head*>(this)->erase(p);
1196  }
1197  }
1198 
1199 
1200  /**
1201  * Test match of headers.
1202  *
1203  * \param header second header
1204  * \return true if matches; else false
1205  */
1206  inline bool match(const JHead& header) const
1207  {
1208  return (match(*this, header, &JHead::cut_primary) &&
1209  match(*this, header, &JHead::cut_seamuon) &&
1210  match(*this, header, &JHead::cut_in) &&
1211  match(*this, header, &JHead::cut_nu) &&
1212  match(*this, header, &JHead::detector) &&
1213  match(*this, header, &JHead::physics) &&
1214  match(*this, header, &JHead::simul) &&
1215  match(*this, header, &JHead::spectrum) &&
1216  match(*this, header, &JHead::can) &&
1217  match(*this, header, &JHead::fixedcan) &&
1218  match(*this, header, &JHead::genvol) &&
1219  match(*this, header, &JHead::coord_origin) &&
1220  match(*this, header, &JHead::norma) &&
1221  match(*this, header, &JHead::livetime) &&
1222  match(*this, header, &JHead::seabottom) &&
1223  match(*this, header, &JHead::depth) &&
1224  match(*this, header, &JHead::primary) &&
1225  match(*this, header, &JHead::DAQ));
1226  }
1227 
1228 
1229  /**
1230  * Comparison of headers.
1231  *
1232  * \param header header
1233  * \return true if this header less than given header; else false
1234  */
1235  inline bool less(const JHead& header) const
1236  {
1237 #define RETURN_IF_DIFFERENT(A, B) \
1238  if (less(A,B)) { return true; } \
1239  if (less(B,A)) { return false; }
1240 
1241  // compare physics
1242 
1243  RETURN_IF_DIFFERENT(this->physics, header.physics);
1244 
1245  // compare simulation
1246 
1247  RETURN_IF_DIFFERENT(this->simul, header.simul);
1248 
1249  // compare generation data
1250 
1251  RETURN_IF_DIFFERENT(this->primary, header.primary);
1252  RETURN_IF_DIFFERENT(this->spectrum, header.spectrum);
1255  RETURN_IF_DIFFERENT(this->cut_in, header.cut_in);
1256  RETURN_IF_DIFFERENT(this->cut_nu, header.cut_nu);
1257  RETURN_IF_DIFFERENT(this->genvol, header.genvol);
1258 
1259  // compare compatibility
1260 
1261  if (is_valid(this->livetime) == is_valid(header.livetime) &&
1262  is_valid(this->DAQ) == is_valid(header.DAQ)) {
1263  return false;
1264  }
1265 
1266  THROW(JException, "JHead::less() headers do not compare.");
1267 
1268 #undef RETURN_IF_DIFFERENT
1269  }
1270 
1271 
1272  /**
1273  * Addition of headers.
1274  *
1275  * \param header header
1276  * \return this header
1277  */
1278  inline JHead& add(const JHead& header)
1279  {
1280  if (match(header)) {
1281 
1282  genvol .add(header.genvol);
1283  norma .add(header.norma);
1284  livetime.add(header.livetime);
1285  DAQ .add(header.DAQ);
1286 
1287  } else {
1288 
1289  THROW(JException, "JHead::add() headers do not match.");
1290  }
1291 
1292  return *this;
1293  }
1294 
1295 
1296  /**
1297  * Equal operator.
1298  *
1299  * Note that this operator uses the JHead::match method.
1300  *
1301  * \param first first header
1302  * \param second second header
1303  * \return true if two headers are equal; else false
1304  */
1305  friend inline bool operator==(const JHead& first,
1306  const JHead& second)
1307  {
1308  return first.match(second);
1309  }
1310 
1311 
1312  /**
1313  * Less than operator.
1314  *
1315  * \param first first header
1316  * \param second second header
1317  * \return true if first header is less than second header; else false
1318  */
1319  friend inline bool operator<(const JHead& first,
1320  const JHead& second)
1321  {
1322  return first.less(second);
1323  }
1324 
1325 
1326  JAANET::start_run start_run; // first data member
1351  JAANET::end_event end_event; // last data member
1352 
1353 
1354  /**
1355  * Get equation parameters corresponding to Monte Carlo ASCII format, i.e:
1356  * <pre>
1357  * <key>: <value> [<value>]*
1358  * <key>: <value> [<value>]*
1359  * </pre>
1360  *
1361  * \return equation parameters
1362  */
1364  {
1365  static JLANG::JEquationParameters parameters(":", "\n", "", "");
1366 
1367  return parameters;
1368  }
1369 
1370 
1371  /**
1372  * Set equation parameters.
1373  *
1374  * \param equation equation parameters
1375  */
1376  static inline void setEquationParameters(const JLANG::JEquationParameters& equation)
1377  {
1378  getEquationParameters() = equation;
1379  }
1380 
1381 
1382  /**
1383  * Read header from input.
1384  *
1385  * \param in input stream
1386  * \return input stream
1387  */
1388  std::istream& read(std::istream& in);
1389 
1390 
1391  /**
1392  * Write header to output.
1393  *
1394  * \param out output stream
1395  * \return output stream
1396  */
1397  std::ostream& write(std::ostream& out) const;
1398 
1399 
1400  /**
1401  * Print header to output.
1402  *
1403  * \param out output stream
1404  * \return output stream
1405  */
1406  std::ostream& print(std::ostream& out) const;
1407 
1408 
1409  ClassDef(JHead,3);
1410 
1411  private:
1412  /**
1413  * Comparison.
1414  *
1415  * \param first first object
1416  * \param second second object
1417  * \return true if first less than second; else false
1418  */
1419  template<class T>
1420  static inline bool less(const T& first,
1421  const T& second)
1422  {
1423  return first.less(second);
1424  }
1425 
1426 
1427  /**
1428  * Test match.
1429  *
1430  * \param first first object
1431  * \param second second object
1432  * \return true if matches; else false
1433  */
1434  template<class T>
1435  static inline bool match(const T& first,
1436  const T& second)
1437  {
1438  return first.match(second);
1439  }
1440 
1441 
1442  /**
1443  * Comparison of containers.
1444  * It is assumed that the containers are ordered in the same way.
1445  *
1446  * \param first first object
1447  * \param second second object
1448  * \return true if first is less than second; else false
1449  */
1450  template<class T>
1451  static inline bool less(const std::vector<T>& first,
1452  const std::vector<T>& second)
1453  {
1454  if (first.size() == second.size()) {
1455 
1456  for (size_t i = 0; i != first.size(); ++i) {
1457  if (less(first[i], second[i])) {
1458  return true;
1459  }
1460  }
1461 
1462  return false;
1463 
1464  } else {
1465 
1466  return first.size() < second.size();
1467  }
1468  }
1469 
1470 
1471  /**
1472  * Test is containers match.
1473  * It is assumed that the containers are ordered in the same way.
1474  *
1475  * \param first first object
1476  * \param second second object
1477  * \return true if matches; else false
1478  */
1479  template<class T>
1480  static inline bool match(const std::vector<T>& first,
1481  const std::vector<T>& second)
1482  {
1483  for (size_t i = 0; i != first.size() && i != second.size(); ++i) {
1484  if (!match(first[i], second[i])) {
1485  return false;
1486  }
1487  }
1488 
1489  return first.size() == second.size();
1490  }
1491 
1492 
1493  /**
1494  * Test match of given data member of headers.
1495  *
1496  * \param first first header
1497  * \param second second header
1498  * \param pd pointer to data member
1499  * \return true if matches; else false
1500  */
1501  template<class T>
1502  static inline bool match(const JHead& first,
1503  const JHead& second,
1504  T JHead::*pd)
1505  {
1506  return match(first.*pd, second.*pd);
1507  }
1508  };
1509 
1510 
1511  /**
1512  * Equal operator.
1513  *
1514  * Note that this operator uses the JHead::match method.
1515  *
1516  * \param first first header
1517  * \param second second header
1518  * \return true if two headers are equal; else false
1519  */
1520  inline bool operator==(const Head& first,
1521  const Head& second)
1522  {
1523  return JHead(first).match(JHead(second));
1524  }
1525 
1526 
1527  /**
1528  * Less than operator.
1529  *
1530  * \param first first header
1531  * \param second second header
1532  * \return true if first header is less than second header; else false
1533  */
1534  inline bool operator<(const Head& first,
1535  const Head& second)
1536  {
1537  return JHead(first).less(JHead(second));
1538  }
1539 }
1540 
1541 
1542 /**
1543  * Read header from input.
1544  *
1545  * \param in input stream
1546  * \param header header
1547  * \return input stream
1548  */
1549 inline std::istream& operator>>(std::istream& in, JAANET::JHead& header)
1550 {
1551  return header.read(in);
1552 }
1553 
1554 
1555 /**
1556  * Write header to output.
1557  *
1558  * \param out output stream
1559  * \param header header
1560  * \return output stream
1561  */
1562 inline std::ostream& operator<<(std::ostream& out, const JAANET::JHead& header)
1563 {
1564  return header.write(out);
1565 }
1566 #endif
norma & add(const norma &object)
Addition.
Definition: JHead.hh:751
bool match(const cut &object) const
Test match.
Definition: JHead.hh:343
bool match(const detector &object) const
Test match.
Definition: JHead.hh:210
double zmin
Bottom [m].
Definition: JHead.hh:532
JAANET::depth depth
Definition: JHead.hh:1347
JAANET::genhencut genhencut
Definition: JHead.hh:1343
General exception.
Definition: JException.hh:23
Phase space of incident neutrino.
Definition: JHead.hh:393
Drawing.
Definition: JHead.hh:288
static bool is_valid(const T &object)
Check validity of given data member in JHead.
Definition: JHead.hh:1135
livetime & mul(const double factor)
Scale.
Definition: JHead.hh:821
JAANET::genvol genvol
Definition: JHead.hh:1341
Neutrino vertex volume.
Definition: JHead.hh:583
Exceptions.
bool less(const String &object) const
Comparison.
Definition: JHead.hh:147
double r
Radius [m].
Definition: JHead.hh:652
JAANET::norma norma
Definition: JHead.hh:1344
Target.
Definition: JHead.hh:268
genvol & mul(const double factor, const double z=0.0)
Scale.
Definition: JHead.hh:639
double volume
Volume [m^3].
Definition: JHead.hh:653
Livetime of DAQ data.
Definition: JHead.hh:919
seabottom()
Default constructor.
Definition: JHead.hh:867
livetime & add(const livetime &object)
Addition.
Definition: JHead.hh:806
friend bool operator<(const JHead &first, const JHead &second)
Less than operator.
Definition: JHead.hh:1319
Depth.
Definition: JHead.hh:891
bool less(const DAQ &object) const
Comparison.
Definition: JHead.hh:934
void setHeader(const JHead &header)
Set header.
Definition: JHead.hh:1105
friend std::istream & operator>>(std::istream &in, String &object)
Read string from input stream.
Definition: JHead.hh:170
#define RETURN_IF_DIFFERENT(A, B)
const JHead & getHeader() const
Get header.
Definition: JHead.hh:1083
Phase space of incoming particle.
Definition: JHead.hh:383
Generator for simulation.
Definition: JHead.hh:460
bool operator<(const Head &first, const Head &second)
Less than operator.
Definition: JHead.hh:1534
double alpha
Energy spectrum: .
Definition: JHead.hh:500
const TDataMember * getDataMember(const JRootClass &parent, const JRootClass &member)
Get ROOT data member for given parent and member class.
Definition: JRootClass.hh:636
Phase space for incident neutrino.
Definition: JHead.hh:706
JAANET::drawing drawing
Definition: JHead.hh:1328
double numberOfEvents
Number of events.
Definition: JHead.hh:654
bool less(const generator &object) const
Comparison.
Definition: JHead.hh:420
static bool less(const T &first, const T &second)
Comparison.
Definition: JHead.hh:1420
friend std::istream & operator>>(std::istream &in, detector &object)
Read detector from input stream.
Definition: JHead.hh:222
bool read(Vec &v, std::istream &is)
Read a Vec(tor) from a stream.
Definition: io_ascii.hh:141
std::string program
program name
Definition: JHead.hh:438
depth()
Default constructor.
Definition: JHead.hh:895
Neutrino cross section file.
Definition: JHead.hh:278
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:670
livetime()
Default constructor.
Definition: JHead.hh:772
double zmax
Top [m].
Definition: JHead.hh:573
Normlisation of CORSIKA events.
Definition: JHead.hh:725
JAANET::cut_primary cut_primary
Definition: JHead.hh:1334
double errorOfSeconds
Uncertainty on live time [s].
Definition: JHead.hh:830
*fatal Wrong number of arguments esac JCookie sh typeset Z DETECTOR typeset Z SOURCE_RUN typeset Z TARGET_RUN set_variable PARAMETERS_FILE $WORKDIR parameters
Definition: diff-Tuna.sh:38
std::vector< JAANET::physics > physics
Definition: JHead.hh:1332
Simple data structure to support I/O of equations (see class JLANG::JEquation).
bool match(const generator &object) const
Test match.
Definition: JHead.hh:433
double Emax
Maximal energy [GeV].
Definition: JHead.hh:352
static void setEquationParameters(const JLANG::JEquationParameters &equation)
Set equation parameters.
Definition: JHead.hh:1376
bool match(const JHead &header) const
Test match of headers.
Definition: JHead.hh:1206
data_type r[M+1]
Definition: JPolint.hh:742
std::vector< JAANET::simul > simul
Definition: JHead.hh:1333
double livetime_s
Live time [s].
Definition: JHead.hh:964
JHead & add(const JHead &header)
Addition of headers.
Definition: JHead.hh:1278
genhencut()
Default constructor.
Definition: JHead.hh:710
General purpose class of phase space generation.
Definition: JHead.hh:298
bool match(const spectrum &object) const
Test match.
Definition: JHead.hh:495
DAQ & add(const DAQ &object)
Addition.
Definition: JHead.hh:957
bool match(const can &object) const
Test match.
Definition: JHead.hh:525
Coordinate origin.
Definition: JHead.hh:663
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
Physics information.
Definition: JHead.hh:450
Description of Monte Carlo event generation applications.
Definition: JHead.hh:403
double ycenter
y-center [m]
Definition: JHead.hh:571
genvol & add(const genvol &object)
Addition.
Definition: JHead.hh:625
ClassDefNV(start_run, 1)
Start of run record.
Definition: JHead.hh:105
spectrum()
Default constructor.
Definition: JHead.hh:474
JAANET::end_event end_event
Definition: JHead.hh:1351
bool less(const JHead &header) const
Comparison of headers.
Definition: JHead.hh:1235
double zmax
Top [m].
Definition: JHead.hh:651
JAANET::fixedcan fixedcan
Definition: JHead.hh:1340
JAANET::can can
Definition: JHead.hh:1339
std::string buffer
General purpose name.
Definition: JHead.hh:187
double xcenter
x-center [m]
Definition: JHead.hh:570
bool operator==(Packet const &p, ID const &id)
The Vec class is a straightforward 3-d vector, which also works in pyroot.
Definition: Vec.hh:12
void push(T JHead::*pd)
Push given data member to Head.
Definition: JHead.hh:1175
int type
Particle type.
Definition: JHead.hh:1020
bool match(const fixedcan &object) const
Test match.
Definition: JHead.hh:561
Detector file.
Definition: JHead.hh:196
JNET::JTag getTag(JLANG::JType< KM3NETDAQ::JDAQTimeslice >)
Definition: JDAQTags.hh:82
JAANET::cut_seamuon cut_seamuon
Definition: JHead.hh:1335
generator()
Default constructor.
Definition: JHead.hh:407
double numberOfPrimaries
Number of primaries.
Definition: JHead.hh:759
JAANET::livetime livetime
Definition: JHead.hh:1345
static JLANG::JEquationParameters & getEquationParameters()
Get equation parameters corresponding to Monte Carlo ASCII format, i.e:
Definition: JHead.hh:1363
JHead()
Default constructor.
Definition: JHead.hh:1056
flux()
Default constructor.
Definition: JHead.hh:844
std::istream & read(std::istream &in)
Read header from input.
Definition: JHead.cc:30
bool less(const primary &object) const
Comparison.
Definition: JHead.hh:1004
void erase(T JHead::*pd)
Remove given data member from Head.
Definition: JHead.hh:1187
JAANET::seabottom seabottom
Definition: JHead.hh:1346
cut()
Default constructor.
Definition: JHead.hh:302
Neutrino flux.
Definition: JHead.hh:839
do set_variable OUTPUT_DIRECTORY $WORKDIR T
friend std::ostream & operator<<(std::ostream &out, const String &object)
Write string to output stream.
Definition: JHead.hh:182
JAANET::start_run start_run
Definition: JHead.hh:1326
bool match(const depth &object) const
Test match.
Definition: JHead.hh:905
bool is_valid(const json &js)
Check validity of JSon data.
ClassDefNV(String, 1)
friend bool operator==(const JHead &first, const JHead &second)
Equal operator.
Definition: JHead.hh:1305
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
Definition: JString.hh:478
std::string version
program version
Definition: JHead.hh:439
Scaling time of neutrino interaction generators (number of seconds in one year).
Definition: JHead.hh:973
JAANET::spectrum spectrum
Definition: JHead.hh:1338
std::string file_2
File name.
Definition: JHead.hh:854
bool match(const norma &object) const
Test match.
Definition: JHead.hh:740
std::string key
Key.
Definition: JHead.hh:852
int type
Type.
Definition: JHead.hh:851
DAQ()
Default constructor.
Definition: JHead.hh:924
bool is_integer(const std::string &buffer)
Check if string is an integer.
Definition: JLangToolkit.hh:58
JAANET::primary primary
Definition: JHead.hh:1350
double z
Sea bottom [m].
Definition: JHead.hh:910
double zmin
Bottom [m].
Definition: JHead.hh:572
print
Definition: JConvertDusj.sh:44
bool match(const livetime &object) const
Test match.
Definition: JHead.hh:794
double zmin
Bottom [m].
Definition: JHead.hh:650
Monte Carlo run header.
Definition: JHead.hh:1050
genvol()
Default constructor.
Definition: JHead.hh:587
bool less(const spectrum &object) const
Comparison.
Definition: JHead.hh:484
int run_id
MC run number.
Definition: JHead.hh:113
double Emin
Minimal energy [GeV].
Definition: JHead.hh:716
The Head class reflects the header of Monte-Carlo event files, which consists of keys (also referred ...
Definition: Head.hh:66
can()
Default constructor.
Definition: JHead.hh:513
std::string filename
Definition: JHead.hh:249
static bool match(const std::vector< T > &first, const std::vector< T > &second)
Test is containers match.
Definition: JHead.hh:1480
JAANET::muon_desc_file muon_desc_file
Definition: JHead.hh:1330
#define ClassDef(name, version)
Definition: JRoot.hh:32
norma()
Default constructor.
Definition: JHead.hh:729
virtual ~JHead()
Virtual destructor.
Definition: JHead.hh:1074
std::string program
Definition: JHead.hh:248
bool match(const coord_origin &object) const
Test match.
Definition: JHead.hh:692
double r
Radius [m].
Definition: JHead.hh:534
coord_origin(const double x, const double y, const double z)
Constructor.
Definition: JHead.hh:680
bool match(const genvol &object) const
Test match.
Definition: JHead.hh:612
std::vector< JAANET::detector > detector
Definition: JHead.hh:1329
Normalisation of MUPAGE events.
Definition: JHead.hh:768
static bool match(const JHead &first, const JHead &second, T JHead::*pd)
Test match of given data member of headers.
Definition: JHead.hh:1502
bool less(const genvol &object) const
Comparison.
Definition: JHead.hh:601
bool match(const seabottom &object) const
Test match.
Definition: JHead.hh:877
detector()
Default constructor.
Definition: JHead.hh:201
iterator pull(T JHead::*pd)
Pull given data member from Head.
Definition: JHead.hh:1163
std::string date
processing date
Definition: JHead.hh:440
bool write(const Vec &v, std::ostream &os)
Write a Vec(tor) to a stream.
Definition: io_ascii.hh:154
primary()
Default constructor.
Definition: JHead.hh:994
JAANET::tgen tgen
Definition: JHead.hh:1349
JAANET::cut_in cut_in
Definition: JHead.hh:1336
JHead & getHeader()
Get header.
Definition: JHead.hh:1094
static bool less(const std::vector< T > &first, const std::vector< T > &second)
Comparison of containers.
Definition: JHead.hh:1451
bool less(const cut &object) const
Comparison.
Definition: JHead.hh:315
General purpose string class.
Definition: JHead.hh:122
start_run()
Default constructor.
Definition: JHead.hh:109
double gDir
Angle.
Definition: JHead.hh:715
double primaryFlux
Primary flux.
Definition: JHead.hh:758
double radius
Radius [m].
Definition: JHead.hh:574
double cosTmax
Maximal cosine zenith angle.
Definition: JHead.hh:354
bool match(const DAQ &object) const
Test match.
Definition: JHead.hh:945
JAANET::target target
Definition: JHead.hh:1331
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition: JHead.cc:139
Primary particle.
Definition: JHead.hh:990
Muon descriptor file.
Definition: JHead.hh:258
fixedcan()
Default constructor.
Definition: JHead.hh:547
The fixed cylinder used for photon tracking.
Definition: JHead.hh:543
static bool match(const T &first, const T &second)
Test match.
Definition: JHead.hh:1435
double z
Sea bottom [m].
Definition: JHead.hh:882
JAANET::cut_nu cut_nu
Definition: JHead.hh:1337
bool less(const livetime &object) const
Comparison.
Definition: JHead.hh:783
end_event()
Default constructor.
Definition: JHead.hh:1033
Phase space of atmospheric muon generation.
Definition: JHead.hh:373
double numberOfSeconds
Time in seconds.
Definition: JHead.hh:981
std::string time
processing time
Definition: JHead.hh:441
tgen()
Default constructor.
Definition: JHead.hh:977
End of event record.
Definition: JHead.hh:1029
Phase space of primary particle.
Definition: JHead.hh:363
JAANET::coord_origin coord_origin
Definition: JHead.hh:1342
static const char AANET_TAG_SEPARATOR
Separator for AAnet tag extension for multiple tags (&quot;_&lt;counter&gt;&quot;).
Definition: JHead.hh:35
bool is_valid(T JHead::*pd) const
Check validity of given data member in JHead.
Definition: JHead.hh:1120
JAANET::XSecFile XSecFile
Definition: JHead.hh:1327
JAANET::DAQ DAQ
Definition: JHead.hh:1348
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY source JAcoustics sh $DETECTOR_ID typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:36
double Emin
Minimal energy [GeV].
Definition: JHead.hh:351
double numberOfSeconds
Live time [s].
Definition: JHead.hh:829
bool match(const primary &object) const
Test match.
Definition: JHead.hh:1015
double cosTmin
Minimal cosine zenith angle.
Definition: JHead.hh:353
Vec coord_origin() const
Get coordinate origin.
Definition: Head.hh:319
JHead(const Head &header)
Copy constructor.
Definition: JHead.hh:1065
version
Definition: JCalibratePMT.sh:7
friend std::ostream & operator<<(std::ostream &out, const detector &object)
Write detector to output stream.
Definition: JHead.hh:243
bool match(const String &object) const
Test match.
Definition: JHead.hh:136
Neutrino energy spectrum.
Definition: JHead.hh:470
The bottom of the sea.
Definition: JHead.hh:863
std::ostream & write(std::ostream &out) const
Write header to output.
Definition: JHead.cc:68
String()
Default constructor.
Definition: JHead.hh:126
double zmax
Top [m].
Definition: JHead.hh:533
const_iterator pull(T JHead::*pd) const
Pull given data member from Head.
Definition: JHead.hh:1150
The cylinder used for photon tracking.
Definition: JHead.hh:509
std::string file_1
File name.
Definition: JHead.hh:853
coord_origin()
Default constructor.
Definition: JHead.hh:669