Jpp  18.0.1-rc.1
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 
9 
10 #include "JAAnet/JHead.hh"
11 #include "JAAnet/JHeadToolkit.hh"
12 #include "JAAnet/JAAnetToolkit.hh"
13 
17 #include "JSupport/JSupport.hh"
18 
19 #include "Jeep/JParser.hh"
20 #include "Jeep/JMessage.hh"
21 
22 
23 /**
24  * \file
25  *
26  * Example program to resize coordinate system of Monte Carlo events.
27  * \author mdejong
28  */
29 int main(int argc, char **argv)
30 {
31  using namespace std;
32  using namespace JPP;
33  JMultipleFileScanner<Evt> inputFile;
34  JLimit_t& numberOfEvents = inputFile.getLimit();
36  double scale;
37  int debug;
38 
39  try {
40 
41  JParser<> zap("Example program to resize coordinate system of Monte Carlo events.");
42 
43  zap['f'] = make_field(inputFile);
44  zap['o'] = make_field(outputFile);
45  zap['n'] = make_field(numberOfEvents) = JLimit::max();
46  zap['F'] = make_field(scale) = 1.0;
47  zap['d'] = make_field(debug) = 2;
48 
49  zap(argc, argv);
50  }
51  catch(const exception &error) {
52  FATAL(error.what() << endl);
53  }
54 
55 
56  Head header = getHeader(inputFile);
57  Vec center(0,0,0);
58  bool genhen = false;
59  bool mupage = false;
60 
61  {
62  JHead buffer(header);
63 
64  center = get<Vec>(buffer);
65  genhen = is_genhen(buffer);
66  mupage = is_mupage(buffer);
67 
68  if (genhen && buffer.is_valid(&JHead::genvol)) {
69 
70  buffer.genvol.mul(scale, center.z);
71 
72  } else if (mupage && buffer.is_valid(&JHead::livetime)) {
73 
74  buffer.livetime.mul(scale);
75 
76  } else {
77 
78  FATAL("Invalid generator." << endl);
79  }
80 
81  copy(buffer, header);
82  }
83 
84 
85  outputFile.open();
86 
87  outputFile.put(header);
88 
89  while (inputFile.hasNext()) {
90 
91  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
92 
93  Evt* event = inputFile.next();
94 
95  if (genhen) {
96 
97  for (vector<Trk>::iterator track = event->mc_trks.begin(); track != event->mc_trks.end(); ++track) {
98 
99  track->pos -= center;
100  track->pos *= scale;
101  track->pos += center;
102  }
103  }
104 
105  if (mupage) {
106 
107  double E = 0.0;
108  Vec pos;
109 
110  for (vector<Trk>::const_iterator track = event->mc_trks.begin(); track != event->mc_trks.end(); ++track) {
111  E += track->E;
112  pos += track->pos * track->E;
113  }
114 
115  pos /= E;
116  pos = (pos - center) * (scale - 1.0);
117  pos.z = 0.0;
118 
119  for (vector<Trk>::iterator track = event->mc_trks.begin(); track != event->mc_trks.end(); ++track) {
120  track->pos += pos;
121  }
122  }
123 
124  outputFile.put(*event);
125  }
126  STATUS(endl);
127 
128  outputFile.close();
129 }
bool is_mupage(const JHead &header)
Check for generator.
Definition: JHeadToolkit.hh:85
Object writing to file.
Utility class to parse command line options.
Definition: JParser.hh:1514
livetime & mul(const double factor)
Scale.
Definition: JHead.hh:875
JAANET::genvol genvol
Definition: JHead.hh:1582
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:693
then usage $script< input file >[option[primary[working directory]]] nWhere option can be E
Definition: JMuonPostfit.sh:40
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
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:1586
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
Definition of hit and track types and auxiliary methods for handling Monte Carlo data.
General purpose messaging.
Monte Carlo run header.
Definition: JHead.hh:1221
The Head class reflects the header of Monte-Carlo event files, which consists of keys (also referred ...
Definition: Head.hh:65
#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:37
General purpose class for object reading from a list of file names.
Utility class to parse command line options.
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition: JHead.cc:162
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:84
bool is_valid(T JHead::*pd) const
Check validity of given data member in JHead.
Definition: JHead.hh:1305
int debug
debug level
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:20
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
void scale(vector< double > &v, double c)
scale vector content