Jpp
Functions
JModK40.cc File Reference
#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 add noise to 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 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 add noise to 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['f'] = JPARSER::initialised();
67 
68  zap(argc, argv);
69  }
70  catch(const exception &error) {
71  FATAL(error.what() << endl);
72  }
73 
74 
75  gRandom->SetSeed(seed);
76 
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  JMultipleFileScanner<Head> io(inputFile);
109 
110  io >> outputFile;
111 
112  while (inputFile.hasNext()) {
113 
114  STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
115 
116  Evt* event = inputFile.next();
117 
118  JTimeRange time_range(JTimeRange::DEFAULT_RANGE);
119 
120  vector<Hit>::iterator __end = event->mc_hits.end();
121 
122  for (vector<Hit>::iterator i = event->mc_hits.begin(); i != __end; ) {
123 
124  if (is_noise(*i)) {
125 
126  iter_swap(i, --__end);
127 
128  } else {
129 
130  time_range.include(getTime(*i));
131 
132  ++i;
133  }
134  }
135 
136  event->mc_hits.erase(__end, event->mc_hits.end());
137 
138  if (time_range.is_valid())
139  time_range.add(period);
140  else
141  time_range = period;
142 
143 
144  const int npe = 1;
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  STATUS(endl);
174 
175  outputFile.put(*gRandom);
176  outputFile.close();
177 }
JDETECTOR::JK40DefaultSimulator
Default implementation of the simulation of K40 background.
Definition: JK40DefaultSimulator.hh:25
JAANET::JHit_t
Auxiliary class to set-up Hit.
Definition: JHit_t.hh:25
JSUPPORT::JLimit
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
JDETECTOR::JModuleData
Data structure for PMT data corresponding to a detector module.
Definition: JPMTSimulator.hh:211
JPARSER::initialised
Empty structure for specification of parser element that is initialised (i.e.
Definition: JParser.hh:63
JDETECTOR::load
void load(const JString &file_name, JDetector &detector)
Load detector from input file.
Definition: JDetectorToolkit.hh:476
std::vector
Definition: JSTDTypes.hh:12
JTOOLS::JRange< double >
Evt
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition: Evt.hh:19
JPARSER::JParser
Utility class to parse command line options.
Definition: JParser.hh:1493
JAANET::HIT_TYPE_NOISE
Random noise.
Definition: JAAnetToolkit.hh:76
JTOOLS::JTimeRange
JRange< double > JTimeRange
Type definition for time range.
Definition: JTools/JTimeRange.hh:19
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JDETECTOR::JK40Rates
Auxiliary class for K40 rates.
Definition: JK40Rates.hh:41
JDETECTOR::getMaximalTime
double getMaximalTime(const JDetector &detector)
Get maximal time between modules in detector following causality.
Definition: JDetectorToolkit.hh:306
JSUPPORT::JMultipleFileScanner::getCounter
counter_type getCounter() const
Get counter.
Definition: JMultipleFileScanner.hh:323
debug
int debug
debug level
Definition: JSirene.cc:59
JSUPPORT::JMultipleFileScanner::next
virtual const pointer_type & next()
Get next element.
Definition: JMultipleFileScanner.hh:398
JSUPPORT::JMultipleFileScanner< Head >
Template specialisation of JMultipleFileScanner for Monte Carlo header.
Definition: JMonteCarloFileSupportkit.hh:324
JAANET::getTime
double getTime(const Hit &hit)
Get true time of hit.
Definition: JAAnetToolkit.hh:87
STATUS
#define STATUS(A)
Definition: JMessage.hh:63
JSUPPORT::JMultipleFileScanner::hasNext
virtual bool hasNext()
Check availability of next element.
Definition: JMultipleFileScanner.hh:350
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
JSUPPORT::JMultipleFileScanner
General purpose class for object reading from a list of file names.
Definition: JMultipleFileScanner.hh:167
JDETECTOR::JDetector
Detector data structure.
Definition: JDetector.hh:80
JAANET::detector
Detector file.
Definition: JHead.hh:130
JSUPPORT::JMeta
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:71
DEBUG
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
std
Definition: jaanetDictionary.h:36
JDETECTOR::JModuleData::reset
void reset(size_t size)
Reset buffers.
Definition: JPMTSimulator.hh:228
FATAL
#define FATAL(A)
Definition: JMessage.hh:67
outputFile
string outputFile
Definition: JDAQTimesliceSelector.cc:37
JSUPPORT::JFileRecorder
Object writing to file.
Definition: JFileRecorder.hh:41
JLANG::JException
General exception.
Definition: JException.hh:23
JAANET::is_noise
bool is_noise(const Hit &hit)
Verify hit origin.
Definition: JAAnetToolkit.hh:121