Jpp  15.0.0-rc.2
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/Evt.hh"
#include "JAAnet/JAAnetToolkit.hh"
#include "JAAnet/JHit_t.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 39 of file JModK40.cc.

40 {
41  using namespace std;
42  using namespace JPP;
43 
44  JMultipleFileScanner<Evt> inputFile;
46  JLimit_t& numberOfEvents = inputFile.getLimit();
47  string detectorFile;
48  JK40Rates rates_Hz;
49  JTimeRange period;
50  UInt_t seed;
51  int debug;
52 
53  try {
54 
55  JParser<> zap("Auxiliary program to generate noise in Monte Carlo event.");
56 
57  zap['f'] = make_field(inputFile) = JPARSER::initialised();
58  zap['o'] = make_field(outputFile) = "modk40.root";
59  zap['n'] = make_field(numberOfEvents) = JLimit::max();
60  zap['a'] = make_field(detectorFile);
61  zap['T'] = make_field(period) = JTimeRange::DEFAULT_RANGE;
62  zap['B'] = make_field(rates_Hz) = JPARSER::initialised();
63  zap['S'] = make_field(seed) = 0;
64  zap['d'] = make_field(debug) = 1;
65 
66  zap(argc, argv);
67  }
68  catch(const exception &error) {
69  FATAL(error.what() << endl);
70  }
71 
72 
73  gRandom->SetSeed(seed);
74 
75  const int NPE = 1;
76 
77 
79 
80  try {
81  load(detectorFile, detector);
82  }
83  catch(const JException& error) {
84  FATAL(error);
85  }
86 
87 
88  if (period == JTimeRange::DEFAULT_RANGE) {
89 
90  const double Tmax = getMaximalTime(detector);
91 
92  period = JTimeRange(-Tmax, +Tmax);
93  }
94 
95 
96  const JK40DefaultSimulator modk40(rates_Hz);
97 
98  outputFile.open();
99 
100  if (!outputFile.is_open()) {
101  FATAL("Error opening file " << outputFile << endl);
102  }
103 
104  outputFile.put(JMeta(argc, argv));
105  outputFile.put(*gRandom);
106 
107  if (!inputFile.empty()) {
108 
109  JMultipleFileScanner<Head> io(inputFile);
110 
111  io >> outputFile;
112 
113  while (inputFile.hasNext()) {
114 
115  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
116 
117  Evt* event = inputFile.next();
118 
119  JTimeRange time_range(JTimeRange::DEFAULT_RANGE);
120 
121  vector<Hit>::iterator __end = event->mc_hits.end();
122 
123  for (vector<Hit>::iterator i = event->mc_hits.begin(); i != __end; ) {
124 
125  if (is_noise(*i)) {
126 
127  iter_swap(i, --__end);
128 
129  } else {
130 
131  time_range.include(getTime(*i));
132 
133  ++i;
134  }
135  }
136 
137  event->mc_hits.erase(__end, event->mc_hits.end());
138 
139  if (time_range.is_valid())
140  time_range.add(period);
141  else
142  time_range = period;
143 
144 
145  JModuleData buffer;
146 
147  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
148 
149  buffer.reset(module->size());
150 
151  modk40.generateHits(*module, time_range, buffer);
152 
153  for (unsigned int pmt = 0; pmt != buffer.size(); ++pmt) {
154 
155  const JModuleData::value_type& frame = buffer[pmt];
156 
157  for (JModuleData::value_type::const_iterator hit = frame.begin(); hit != frame.end(); ++hit) {
158 
159  event->mc_hits.push_back(JHit_t(event->mc_hits.size() + 1,
160  module->getPMT(pmt).getID(),
162  0,
163  hit->t_ns,
164  NPE));
165  }
166  }
167  }
168 
169 
170  outputFile.put(*event);
171  }
172  } else {
173 
174  for (counter_type counter = 0; counter != numberOfEvents; ++counter) {
175 
176  STATUS("event: " << setw(10) << counter << '\r'); DEBUG(endl);
177 
178  Evt event;
179 
180  JModuleData buffer;
181 
182  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
183 
184  buffer.reset(module->size());
185 
186  modk40.generateHits(*module, period, buffer);
187 
188  for (unsigned int pmt = 0; pmt != buffer.size(); ++pmt) {
189 
190  const JModuleData::value_type& frame = buffer[pmt];
191 
192  for (JModuleData::value_type::const_iterator hit = frame.begin(); hit != frame.end(); ++hit) {
193 
194  event.mc_hits.push_back(JHit_t(event.mc_hits.size() + 1,
195  module->getPMT(pmt).getID(),
197  0,
198  hit->t_ns,
199  NPE));
200  }
201  }
202  }
203 
204 
205  outputFile.put(event);
206  }
207  }
208  STATUS(endl);
209 
210  outputFile.put(*gRandom);
211  outputFile.close();
212 }
Auxiliary class to set-up Hit.
Definition: JHit_t.hh:25
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:1500
void reset(size_t size)
Reset buffers.
General exception.
Definition: JException.hh:23
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
JTOOLS::JRange< double > JTimeRange
Type definition for time range (unit [ns]).
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:66
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:196
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
int debug
debug level
Definition: JSirene.cc:63
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:45
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:73
do set_variable DETECTOR_TXT $WORKDIR detector
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:19