Jpp test-rotations-new
the software that should make you happy
Loading...
Searching...
No Matches
JModK40.cc File Reference

Auxiliary program to generate noise in Monte Carlo event. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <vector>
#include "TROOT.h"
#include "TFile.h"
#include "TRandom3.h"
#include "km3net-dataformat/offline/Head.hh"
#include "km3net-dataformat/offline/MultiHead.hh"
#include "km3net-dataformat/offline/Evt.hh"
#include "JAAnet/JAAnetToolkit.hh"
#include "JSirene/JSirene.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDetector/JK40DefaultSimulator.hh"
#include "JDetector/JTimeRange.hh"
#include "JSupport/JMultipleFileScanner.hh"
#include "JSupport/JFileRecorder.hh"
#include "JSupport/JMonteCarloFileSupportkit.hh"
#include "JSupport/JSupport.hh"
#include "JSupport/JMeta.hh"
#include "JROOT/JRandom.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

Auxiliary program to generate noise in Monte Carlo event.


This program will be deprecated (JTriggerEfficiency.cc should be used instead).

Author
mdejong

Definition in file JModK40.cc.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 42 of file JModK40.cc.

43{
44 using namespace std;
45 using namespace JPP;
46
49 JLimit_t& numberOfEvents = inputFile.getLimit();
50 string detectorFile;
51 JK40Rates rates_Hz;
52 JTimeRange period;
53 JRandom seed;
54 int debug;
55
56 try {
57
58 JParser<> zap("Auxiliary program to generate noise in Monte Carlo event.");
59
60 zap['f'] = make_field(inputFile) = JPARSER::initialised();
61 zap['o'] = make_field(outputFile) = "modk40.root";
62 zap['n'] = make_field(numberOfEvents) = JLimit::max();
63 zap['a'] = make_field(detectorFile);
64 zap['T'] = make_field(period) = JTimeRange::DEFAULT_RANGE();
65 zap['B'] = make_field(rates_Hz) = JPARSER::initialised();
66 zap['S'] = make_field(seed) = 0;
67 zap['d'] = make_field(debug) = 1;
68
69 zap(argc, argv);
70 }
71 catch(const exception &error) {
72 FATAL(error.what() << endl);
73 }
74
75
76 seed.set(gRandom);
77
78 const int NPE = 1;
79
80
82
83 try {
84 load(detectorFile, detector);
85 }
86 catch(const JException& error) {
87 FATAL(error);
88 }
89
90
91 if (period == JTimeRange::DEFAULT_RANGE()) {
92
93 const double Tmax = getMaximalTime(detector);
94
95 period = JTimeRange(-Tmax, +Tmax);
96 }
97
98
99 const JK40DefaultSimulator modk40(rates_Hz);
100
101 outputFile.open();
102
103 if (!outputFile.is_open()) {
104 FATAL("Error opening file " << outputFile << endl);
105 }
106
107 outputFile.put(JMeta(argc, argv));
108 outputFile.put(*gRandom);
109
110 if (!inputFile.empty()) {
111
112 JMultipleFileScanner<Head> io(inputFile);
113
114 io >> outputFile;
115
116 while (inputFile.hasNext()) {
117
118 STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
119
120 Evt* event = inputFile.next();
121
123
124 vector<Hit>::iterator __end = event->mc_hits.end();
125
126 for (vector<Hit>::iterator i = event->mc_hits.begin(); i != __end; ) {
127
128 if (is_noise(*i)) {
129
130 iter_swap(i, --__end);
131
132 } else {
133
134 time_range.include(getTime(*i));
135
136 ++i;
137 }
138 }
139
140 event->mc_hits.erase(__end, event->mc_hits.end());
141
142 if (time_range.is_valid())
143 time_range.add(period);
144 else
145 time_range = period;
146
147
148 JModuleData buffer;
149
150 for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
151
152 buffer.reset(module->size());
153
154 modk40.generateHits(*module, time_range, buffer);
155
156 for (unsigned int pmt = 0; pmt != buffer.size(); ++pmt) {
157
158 const JModuleData::value_type& frame = buffer[pmt];
159
160 for (JModuleData::value_type::const_iterator hit = frame.begin(); hit != frame.end(); ++hit) {
161
162 event->mc_hits.push_back(JHit_t(event->mc_hits.size() + 1,
163 module->getPMT(pmt).getID(),
165 0,
166 hit->t_ns,
167 NPE));
168 }
169 }
170 }
171
172
173 outputFile.put(*event);
174 }
175 } else {
176
177 for (counter_type counter = 0; counter != numberOfEvents; ++counter) {
178
179 STATUS("event: " << setw(10) << counter << '\r'); DEBUG(endl);
180
181 Evt event;
182
183 JModuleData buffer;
184
185 for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
186
187 buffer.reset(module->size());
188
189 modk40.generateHits(*module, period, buffer);
190
191 for (unsigned int pmt = 0; pmt != buffer.size(); ++pmt) {
192
193 const JModuleData::value_type& frame = buffer[pmt];
194
195 for (JModuleData::value_type::const_iterator hit = frame.begin(); hit != frame.end(); ++hit) {
196
197 event.mc_hits.push_back(JHit_t(event.mc_hits.size() + 1,
198 module->getPMT(pmt).getID(),
200 0,
201 hit->t_ns,
202 NPE));
203 }
204 }
205 }
206
207
208 outputFile.put(event);
209 }
210 }
211 STATUS(endl);
212
213 outputFile.put(*gRandom);
214 outputFile.close();
215}
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:72
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
Detector data structure.
Definition JDetector.hh:96
Default implementation of the simulation of K40 background.
Data structure for PMT data corresponding to a detector module.
void reset(size_t size)
Reset buffers.
General exception.
Definition JException.hh:24
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.
static JRange< double, std::less< double > > DEFAULT_RANGE()
Definition JRange.hh:555
@ HIT_TYPE_NOISE
Random noise.
bool is_noise(const Hit &hit)
Verify hit origin.
JTOOLS::JRange< double > JTimeRange
Type definition for time range (unit [s]).
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Long64_t counter_type
Type definition for counter.
const char * getTime()
Get current local time conform ISO-8601 standard.
double getMaximalTime(const double R_Hz)
Get maximal time for given rate.
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition Evt.hh:21
std::vector< Hit > mc_hits
MC: list of MC truth hits.
Definition Evt.hh:48
Detector file.
Definition JHead.hh:227
Template definition of random value generator.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition JParser.hh:68
Auxiliary class for K40 rates.
Definition JK40Rates.hh:41
Auxiliary class to set-up Hit.
Definition JSirene.hh:58
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
Auxiliary class for ROOT I/O of application specific meta data.
Definition JMeta.hh:72