Jpp  19.1.0-rc.1
the software that should make you happy
JFixedCan.cc
Go to the documentation of this file.
1 
2 #include <string>
3 #include <iostream>
4 #include <iomanip>
5 
9 
13 #include "JSupport/JSupport.hh"
14 #include "JSupport/JMeta.hh"
15 
16 #include "JSystem/JDateAndTime.hh"
17 
19 
20 #include "Jeep/JParser.hh"
21 #include "Jeep/JMessage.hh"
22 
23 
24 /**
25  * \file
26  * Auxiliary program to shift the generated tracks according a given offset.
27  *
28  * \author vkulikovskiy
29  */
30 int main(int argc, char **argv)
31 {
32  using namespace std;
33  using namespace JPP;
34 
35  JMultipleFileScanner<Evt> inputFile;
37  JLimit_t& numberOfEvents = inputFile.getLimit();
38  double xshift;
39  double yshift;
40  double zshift;
41  int debug;
42 
43  try {
44 
45  JParser<> zap("Auxiliary program to shift the generated tracks according a given offset.");
46 
47  zap['f'] = make_field(inputFile);
48  zap['o'] = make_field(outputFile);
49  zap['n'] = make_field(numberOfEvents) = JLimit::max();
50  zap['x'] = make_field(xshift) = 0.0;
51  zap['y'] = make_field(yshift) = 0.0;
52  zap['z'] = make_field(zshift) = 0.0;
53  zap['d'] = make_field(debug) = 1;
54 
55  zap(argc, argv);
56  }
57  catch(const exception& error) {
58  FATAL(error.what() << endl);
59  }
60 
61 
62  outputFile.open();
63 
64  outputFile.put(JMeta(argc,argv));
65 
66  const Vec offset(xshift,yshift,zshift);
67 
68  NOTICE("Offset applied to true tracks is: " << offset << endl);
69 
70  Head header;
71 
72  try {
73 
74  header = getHeader(inputFile);
75 
76  JHead buffer(header);
77 
78  JAANET::simul info;
79 
80  info.program = argv[0];
81  info.version = getGITVersion();
82  info.date = getDate();
83  info.time = getTime();
84 
85  buffer.simul.push_back(info);
86 
87  buffer.push(&JHead::simul);
88 
89  bool can_found = buffer.is_valid(&JHead::can);
90  bool fixedcan_found = buffer.is_valid(&JHead::fixedcan);
91 
92  if (can_found) {
93  NOTICE("can found" << endl);
94  }
95  if (fixedcan_found) {
96  NOTICE("fixedcan found" << endl);
97  }
98 
99  if (can_found && !fixedcan_found) {
100 
101  buffer.fixedcan.xcenter = xshift;
102  buffer.fixedcan.ycenter = yshift;
103  buffer.fixedcan.zmin = buffer.can.zmin + zshift;
104  buffer.fixedcan.zmax = buffer.can.zmax + zshift;
105  buffer.fixedcan.radius = buffer.can.r;
106 
107  buffer.push(&JHead::fixedcan);
108 
109  buffer.erase(&JHead::can);
110 
111  } else if (fixedcan_found && !can_found) {
112 
113  buffer.fixedcan.xcenter = buffer.fixedcan.xcenter + xshift;
114  buffer.fixedcan.ycenter = buffer.fixedcan.ycenter + yshift;
115  buffer.fixedcan.zmin = buffer.fixedcan.zmin + zshift;
116  buffer.fixedcan.zmax = buffer.fixedcan.zmax + zshift;
117 
118  } else if (!can_found && !fixedcan_found) {
119 
120  FATAL("Neither can nor fixedcan is found" << endl);
121 
122  } else {
123 
124  FATAL("Both can and fixedcan are found" << endl);
125  }
126 
127  copy(buffer, header);
128  }
129  catch(const JException& error) {
130  FATAL(error << endl);
131  }
132 
133  outputFile.put(header);
134 
135 
136  while (inputFile.hasNext()) {
137 
138  Evt* evt = inputFile.next(); // input
139 
140  for (vector<Trk>::iterator track = evt->mc_trks.begin(); track != evt->mc_trks.end(); ++track) {
141  track->pos += offset;
142  }
143 
144  outputFile.put(*evt);
145  }
146 
147  outputFile.close();
148 }
string outputFile
Date and time functions.
Recording of objects on file according a format that follows from the file name extension.
int main(int argc, char **argv)
Definition: JFixedCan.cc:30
General purpose messaging.
#define NOTICE(A)
Definition: JMessage.hh:64
#define FATAL(A)
Definition: JMessage.hh:67
int debug
debug level
Definition: JSirene.cc:69
ROOT I/O of application specific meta data.
Scanning of objects from multiple files according a format that follows from the extension of each fi...
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2158
ROOT TTree parameter settings of various packages.
Monte Carlo run header.
Definition: JHead.hh:1236
std::vector< JAANET::simul > simul
Definition: JHead.hh:1591
void push(T JHead::*pd)
Push given data member to Head.
Definition: JHead.hh:1374
JAANET::can can
Definition: JHead.hh:1598
JAANET::fixedcan fixedcan
Definition: JHead.hh:1599
bool is_valid(T JHead::*pd) const
Check validity of given data member in JHead.
Definition: JHead.hh:1319
void erase(T JHead::*pd)
Reset and remove given data member from Head.
Definition: JHead.hh:1392
General exception.
Definition: JException.hh:24
Utility class to parse command line options.
Definition: JParser.hh:1714
Object writing to file.
virtual bool hasNext() override
Check availability of next element.
virtual const pointer_type & next() override
Get next element.
double getTime(const Hit &hit)
Get true time of hit.
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition: JHead.cc:162
std::string getGITVersion(const std::string &tag)
Get GIT version for given GIT tag.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Head getHeader(const JMultipleFileScanner_t &file_list)
Get Monte Carlo header.
const char * getDate()
Get current local date conform ISO-8601 standard.
Definition: JDateAndTime.hh:36
Definition: JSTDTypes.hh:14
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:21
std::vector< Trk > mc_trks
MC: list of MC truth tracks.
Definition: Evt.hh:49
The Head class reflects the header of Monte-Carlo event files, which consists of keys (also referred ...
Definition: Head.hh:65
double zmin
Bottom [m].
Definition: JHead.hh:598
double zmax
Top [m].
Definition: JHead.hh:599
double r
Radius [m].
Definition: JHead.hh:600
double zmax
Top [m].
Definition: JHead.hh:639
double radius
Radius [m].
Definition: JHead.hh:640
double zmin
Bottom [m].
Definition: JHead.hh:638
double ycenter
y-center [m]
Definition: JHead.hh:637
double xcenter
x-center [m]
Definition: JHead.hh:636
std::string time
processing time
Definition: JHead.hh:507
std::string date
processing date
Definition: JHead.hh:506
std::string program
program name
Definition: JHead.hh:504
std::string version
program version
Definition: JHead.hh:505
Generator for simulation.
Definition: JHead.hh:528
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:45
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:72
The Vec class is a straightforward 3-d vector, which also works in pyroot.
Definition: Vec.hh:13