Jpp  15.0.1-rc.2-highQE
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JSwordfish.cc
Go to the documentation of this file.
1 
2 #include <string>
3 #include <iostream>
4 #include <iomanip>
5 
8 
9 #include "JAAnet/JHead.hh"
10 #include "JAAnet/JHeadToolkit.hh"
11 #include "JAAnet/JAAnetToolkit.hh"
12 
16 #include "JSupport/JSupport.hh"
17 
18 #include "Jeep/JParser.hh"
19 #include "Jeep/JMessage.hh"
20 
21 
22 /**
23  * \file
24  *
25  * Example program to resize coordinate system of Monte Carlo events.
26  * \author mdejong
27  */
28 int main(int argc, char **argv)
29 {
30  using namespace std;
31  using namespace JPP;
32  JMultipleFileScanner<Evt> inputFile;
33  JLimit_t& numberOfEvents = inputFile.getLimit();
35  double scale;
36  int debug;
37 
38  try {
39 
40  JParser<> zap("Example program to resize coordinate system of Monte Carlo events.");
41 
42  zap['f'] = make_field(inputFile);
43  zap['o'] = make_field(outputFile);
44  zap['n'] = make_field(numberOfEvents) = JLimit::max();
45  zap['F'] = make_field(scale) = 1.0;
46  zap['d'] = make_field(debug) = 2;
47 
48  zap(argc, argv);
49  }
50  catch(const exception &error) {
51  FATAL(error.what() << endl);
52  }
53 
54 
55  Head header = getHeader(inputFile);
56  Vec center(0,0,0);
57  bool genhen = false;
58  bool mupage = false;
59 
60  {
61  JHead buffer(header);
62 
63  center = get<Vec>(buffer);
64  genhen = is_genhen(buffer);
65  mupage = is_mupage(buffer);
66 
67  if (genhen && buffer.is_valid(&JHead::genvol)) {
68 
69  buffer.genvol.mul(scale, center.z);
70 
71  } else if (mupage && buffer.is_valid(&JHead::livetime)) {
72 
73  buffer.livetime.mul(scale);
74 
75  } else {
76 
77  FATAL("Invalid generator." << endl);
78  }
79 
80  copy(buffer, header);
81  }
82 
83 
84  outputFile.open();
85 
86  outputFile.put(header);
87 
88  while (inputFile.hasNext()) {
89 
90  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
91 
92  Evt* event = inputFile.next();
93 
94  if (genhen) {
95 
96  for (vector<Trk>::iterator track = event->mc_trks.begin(); track != event->mc_trks.end(); ++track) {
97 
98  track->pos -= center;
99  track->pos *= scale;
100  track->pos += center;
101  }
102  }
103 
104  if (mupage) {
105 
106  double E = 0.0;
107  Vec pos;
108 
109  for (vector<Trk>::const_iterator track = event->mc_trks.begin(); track != event->mc_trks.end(); ++track) {
110  E += track->E;
111  pos += track->pos * track->E;
112  }
113 
114  pos /= E;
115  pos = (pos - center) * (scale - 1.0);
116  pos.z = 0.0;
117 
118  for (vector<Trk>::iterator track = event->mc_trks.begin(); track != event->mc_trks.end(); ++track) {
119  track->pos += pos;
120  }
121  }
122 
123  outputFile.put(*event);
124  }
125  STATUS(endl);
126 
127  outputFile.close();
128 }
bool is_mupage(const JHead &header)
Check for generator.
Definition: JHeadToolkit.hh:78
Object writing to file.
Utility class to parse command line options.
Definition: JParser.hh:1500
livetime & mul(const double factor)
Scale.
Definition: JHead.hh:821
JAANET::genvol genvol
Definition: JHead.hh:1408
int main(int argc, char *argv[])
Definition: Main.cc:15
ROOT TTree parameter settings of various packages.
genvol & mul(const double factor, const double z=0.0)
Scale.
Definition: JHead.hh:639
double z
Definition: Vec.hh:14
#define STATUS(A)
Definition: JMessage.hh:63
Recording of objects on file according a format that follows from the file name extension.
string outputFile
then usage E
Definition: JMuonPostfit.sh:35
Head getHeader(const JMultipleFileScanner_t &file_list)
Get Monte Carlo header.
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
The Vec class is a straightforward 3-d vector, which also works in pyroot.
Definition: Vec.hh:12
JAANET::livetime livetime
Definition: JHead.hh:1412
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
Definition of hit and track types and auxiliary methods for handling Monte Carlo data.
int debug
debug level
Definition: JSirene.cc:63
General purpose messaging.
Monte Carlo run header.
Definition: JHead.hh:1113
The Head class reflects the header of Monte-Carlo event files, which consists of keys (also referred ...
Definition: Head.hh:67
#define FATAL(A)
Definition: JMessage.hh:67
Scanning of objects from multiple files according a format that follows from the extension of each fi...
bool is_genhen(const JHead &header)
Check for generator.
Definition: JHeadToolkit.hh:36
General purpose class for object reading from a list of file names.
Utility class to parse command line options.
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition: JHead.cc:139
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:73
bool is_valid(T JHead::*pd) const
Check validity of given data member in JHead.
Definition: JHead.hh:1183
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:19
void scale(vector< double > &v, double c)
scale vector content