Jpp  debug
the software that should make you happy
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

◆ main()

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 origin(0,0,0);
58  bool genhen = false;
59  bool mupage = false;
60 
61  {
62  JHead buffer(header);
63 
64  origin = getOrigin(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, origin.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 -= origin;
100  track->pos *= scale;
101  track->pos += origin;
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 - origin) * (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 }
void scale(vector< double > &v, double c)
scale vector content
string outputFile
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
#define STATUS(A)
Definition: JMessage.hh:63
#define FATAL(A)
Definition: JMessage.hh:67
int debug
debug level
Definition: JSirene.cc:69
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2158
Monte Carlo run header.
Definition: JHead.hh:1236
Utility class to parse command line options.
Definition: JParser.hh:1714
Object writing to file.
virtual bool hasNext() override
Check availability of next element.
counter_type getCounter() const
Get counter.
virtual const pointer_type & next() override
Get next element.
bool is_genhen(const JHead &header)
Check for generator.
Definition: JHeadToolkit.hh:37
Vec getOrigin(const JHead &header)
Get origin.
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition: JHead.cc:162
bool is_mupage(const JHead &header)
Check for generator.
Definition: JHeadToolkit.hh:85
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Head getHeader(const JMultipleFileScanner_t &file_list)
Get Monte Carlo header.
Definition: JSTDTypes.hh:14
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:21
The Head class reflects the header of Monte-Carlo event files, which consists of keys (also referred ...
Definition: Head.hh:65
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:45
The Vec class is a straightforward 3-d vector, which also works in pyroot.
Definition: Vec.hh:13
double z
Definition: Vec.hh:14