Jpp 19.3.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
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"
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 */
29int main(int argc, char **argv)
30{
31 using namespace std;
32 using namespace JPP;
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}
Definition of hit and track types and auxiliary methods for handling Monte Carlo data.
void scale(vector< double > &v, double c)
scale vector content
string outputFile
Recording of objects on file according a format that follows from the file name extension.
General purpose messaging.
#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:72
Scanning of objects from multiple files according a format that follows from the extension of each fi...
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
ROOT TTree parameter settings of various packages.
int main(int argc, char **argv)
Definition JSwordfish.cc:29
Monte Carlo run header.
Definition JHead.hh:1236
JAANET::livetime livetime
Definition JHead.hh:1604
JAANET::genvol genvol
Definition JHead.hh:1600
bool is_valid(T JHead::*pd) const
Check validity of given data member in JHead.
Definition JHead.hh:1319
Utility class to parse command line options.
Definition JParser.hh:1698
Object writing to file.
General purpose class for object reading from a list of file names.
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.
Vec getOrigin(const JHead &header)
Get origin.
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition JHead.cc:163
bool is_mupage(const JHead &header)
Check for generator.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Head getHeader(const JMultipleFileScanner_t &file_list)
Get Monte Carlo header.
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
genvol & mul(const double factor, const double z=0.0)
Scale.
Definition JHead.hh:706
livetime & mul(const double factor)
Scale.
Definition JHead.hh:888
Auxiliary class for defining the range of iterations of objects.
Definition JLimit.hh:45
static counter_type max()
Get maximum counter value.
Definition JLimit.hh:128
The Vec class is a straightforward 3-d vector, which also works in pyroot.
Definition Vec.hh:13
double z
Definition Vec.hh:14