Jpp  15.0.0
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/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 28 of file JSwordfish.cc.

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
double z
Definition: Vec.hh:14
#define STATUS(A)
Definition: JMessage.hh:63
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
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
int debug
debug level
Definition: JSirene.cc:63
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
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.
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
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