Jpp  17.3.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JSwordfish.cc File Reference

Example program to resize coordinate system of Monte Carlo events. More...

#include <string>
#include <iostream>
#include <iomanip>
#include "km3net-dataformat/offline/Head.hh"
#include "km3net-dataformat/offline/MultiHead.hh"
#include "km3net-dataformat/offline/Evt.hh"
#include "JAAnet/JHead.hh"
#include "JAAnet/JHeadToolkit.hh"
#include "JAAnet/JAAnetToolkit.hh"
#include "JSupport/JMultipleFileScanner.hh"
#include "JSupport/JFileRecorder.hh"
#include "JSupport/JMonteCarloFileSupportkit.hh"
#include "JSupport/JSupport.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Example program to resize coordinate system of Monte Carlo events.

Author
mdejong

Definition in file JSwordfish.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 29 of file JSwordfish.cc.

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:84
Object writing to file.
Utility class to parse command line options.
Definition: JParser.hh:1517
then usage E
Definition: JMuonPostfit.sh:35
double z
Definition: Vec.hh:14
#define STATUS(A)
Definition: JMessage.hh:63
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
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1993
Monte Carlo run header.
Definition: JHead.hh:1167
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
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.
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:73
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