Jpp  18.5.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
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 "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

int main ( int  argc,
char **  argv 
)

Definition at line 40 of file JModK40.cc.

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