Jpp 20.0.0-195-g190c9e876
the software that should make you happy
Loading...
Searching...
No Matches
JOMGsim.cc File Reference

Auxiliary program to determine PMT parameters from OMGSim data. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <limits>
#include <vector>
#include <algorithm>
#include "TROOT.h"
#include "TFile.h"
#include "TH1D.h"
#include "TH2D.h"
#include "TRandom3.h"
#include "km3net-dataformat/offline/Head.hh"
#include "km3net-dataformat/offline/Evt.hh"
#include "km3net-dataformat/online/JDAQ.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDetector/JPMTParametersMap.hh"
#include "JDetector/JPMTAnalogueSignalProcessor.hh"
#include "JTrigger/JHit.hh"
#include "JSupport/JMultipleFileScanner.hh"
#include "JSupport/JMonteCarloFileSupportkit.hh"
#include "JSupport/JSupport.hh"
#include "JSupport/JMeta.hh"
#include "JTools/JCombinatorics.hh"
#include "JTools/JRouter.hh"
#include "JAAnet/JHead.hh"
#include "JCalibrate/JCalibrateK40.hh"
#include "JLang/JComparator.hh"
#include "JLang/JComparison.hh"
#include "JROOT/JRootToolkit.hh"
#include "JROOT/JRootFileWriter.hh"
#include "Jeep/JPrint.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 determine PMT parameters from OMGSim data.

Author
mdejong

Definition in file JOMGsim.cc.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 81 of file JOMGsim.cc.

82{
83 using namespace std;
84 using namespace JPP;
85 using namespace KM3NETDAQ;
86
88 JLimit_t& numberOfEvents = inputFile.getLimit();
89 string outputFile;
90 string detectorFile;
91 Double_t TMax_ns;
92 Double_t WBin_ns;
93 double R;
94 JPMTParametersMap parameters;
95 size_t recycling;
96 ULong_t seed;
97 int debug;
98
99 try {
100
101 JParser<> zap("Auxiliary program to determine PMT parameters from OMGsim data.");
102
103 zap['f'] = make_field(inputFile, "input file.");
104 zap['o'] = make_field(outputFile, "output file.") = "omgsim.root";
105 zap['n'] = make_field(numberOfEvents) = JLimit::max();
106 zap['a'] = make_field(detectorFile, "detector file.");
107 zap['T'] = make_field(TMax_ns, "time window [ns].") = 20.0;
108 zap['W'] = make_field(WBin_ns, "bin width [ns].") = 1.0;
109 zap['R'] = make_field(R, "radioactivity [Bq]");
110 zap['P'] = make_field(parameters, "PMT parameters") = JPARSER::initialised();
111 zap['N'] = make_field(recycling, "recycling of events") = 1;
112 zap['S'] = make_field(seed, "seed") = 0;
113 zap['d'] = make_field(debug, "debug flag.") = 1;
114
115 zap(argc, argv);
116 }
117 catch(const exception &error) {
118 FATAL(error.what() << endl);
119 }
120
121
122 gRandom->SetSeed(seed);
123
124
126
127 try {
128 load(detectorFile, detector);
129 }
130 catch(const JException& error) {
131 FATAL(error);
132 }
133
134 if (detector.size() != 1u) {
135 FATAL("Wrong number of modules " << detector.size() << endl);
136 }
137
138
139 const JModule& module = detector[0];
140
141 JCombinatorics combinatorics(module.size());
142
143 combinatorics.sort(JPairwiseComparator(module));
144
145 const Int_t nx = combinatorics.getNumberOfPairs();
146 const Double_t xmin = -0.5;
147 const Double_t xmax = nx - 0.5;
148
149 const Double_t ymin = -floor(TMax_ns) - 0.5*WBin_ns;
150 const Double_t ymax = +floor(TMax_ns) + 0.5*WBin_ns;
151 const Int_t ny = (Int_t) ((ymax - ymin) / WBin_ns);
152
153 TH2D h2r(MAKE_CSTRING(module.getID() << _2R), NULL, nx, xmin, xmax, ny, ymin, ymax);
154
155 h2r.Sumw2();
156
157 TH1D h1("M", NULL, 101, -0.5, 100.5);
158
159 JRouter<int> router;
160
161 size_t slewing = module.size();
162
163 //size_t slewing = 0;
164
166
167 for (size_t i = 0; i != module.size(); ++i) {
168
169 router.put(module[i].getID(), i);
170
171 const JPMTParameters& wip = parameters.getPMTParameters(JPMTIdentifier(module.getID(),i));
172
173 if (wip.slewing) {
174 //slewing += 1;
175 }
176
177 cpu.push_back(JPMTAnalogueSignalProcessor(wip));
178 }
179
180 if (slewing == 0)
181 JHit::setSlewing(false);
182 else if (slewing == module.size())
183 JHit::setSlewing(true);
184 else
185 FATAL("Inconsistent PMT slewing options " << slewing << endl);
186
187 NOTICE("PMT slewing option " << JHit::getSlewing() << endl);
188
189
190 double numberOfPrimaries = 0.0;
191
192 try {
193
194 STATUS("Extracting header data... " << flush);
195
196 const Head header = getHeader(inputFile);
197
198 const JHead buffer(header);
199
200 if (buffer.is_valid(&JHead::norma))
201 numberOfPrimaries = buffer.norma.numberOfPrimaries;
202 else
203 THROW(JException, "Missing header information.");
204
205 STATUS("OK" << endl);
206
207 } catch(const exception& error) {
208 FATAL(error.what() << endl);
209 }
210
211 if (numberOfPrimaries == 0.0) {
212 FATAL("Number of primaries " << numberOfPrimaries << endl);
213 }
214
215
216 TFile out(outputFile.c_str(), "recreate");
217
218 putObject(out, JMeta(argc, argv));
219
220 while (inputFile.hasNext()) {
221
222 if (inputFile.getCounter()%10000== 0) {
223 STATUS("event: " << setw(10) << inputFile.getCounter() << '\r'); DEBUG(endl);
224 }
225
226 const Evt* evt = inputFile.next();
227
228 if (evt->mc_hits.size() >= 2u) {
229
230 JModuleData input(module.size());
231
232 for (const auto& hit : evt->mc_hits) {
233
234 if (router.has(hit.pmt_id)) {
235
236 const int pmt = router.get(hit.pmt_id);
237
238 input[pmt].push_back(JPMTSignal(hit.t, hit.a));
239 }
240 }
241
242 for (size_t i = 0; i != recycling; ++i) {
243
244 vector<hit_type> buffer;
245
246 for (size_t pmt = 0; pmt != module.size(); ++pmt) {
247
248 if (!input[pmt].empty()) {
249
250 JPMTData<JPMTPulse> output;
251
252 cpu[pmt](module[pmt].getCalibration(), input[pmt], output);
253
254 for (const auto& hit : output) {
255 buffer.push_back(hit_type(pmt, hit));
256 }
257 }
258 }
259
260 if (buffer.size() >= 2u) {
261
262 sort(buffer.begin(), buffer.end());
263
264 for (vector<hit_type>::iterator p = buffer.begin(); p != buffer.end(); ) {
265
267
268 for (++q; q != buffer.end() && q->getT() - p->getT() <= TMax_ns; ++q) {} // time window
269
270 if (distance(p,q) >= 2) {
271
272 sort(p, q, make_comparator(&hit_type::pmt, JComparison::lt())); //
273
274 const int M = distance(p, unique(p, q, make_comparator(&hit_type::pmt, JComparison::eq()))); // unique PMTs
275
276 if (M >= 2) {
277 h1.Fill(M);
278 }
279
280 sort(p, q);
281 }
282
283 p = q;
284 }
285
286 if (debug >= debug_t) {
287
288 cout << "hit:";
289
290 for (const auto& hit : buffer) {
291 cout << ' ' << setw(2) << hit.pmt << ' ' << FIXED(10,1) << hit.getT() << ' ' << FIXED(3,0) << hit.getToT();
292 }
293
294 cout << endl;
295 }
296
297 for (vector<hit_type>::const_iterator p = buffer.begin(); p != buffer.end(); ++p) {
298 for (vector<hit_type>::const_iterator q = buffer.begin(); p != q; ++q) {
299 h2r.Fill((double) combinatorics.getIndex(p->pmt,q->pmt),
300 JCombinatorics::getSign(p->pmt,q->pmt) * (q->getT() - p->getT()));
301 }
302 }
303 }
304 }
305 }
306 }
307 STATUS(endl);
308
309 // reset under and overflows.
310
311 for (int ix = 0; ix <= h2r.GetXaxis()->GetNbins() + 1; ++ix) {
312 h2r.SetBinContent(ix, 0, 0.0); h2r.SetBinContent(ix, h2r.GetYaxis()->GetNbins() + 1, 0.0);
313 h2r.SetBinError (ix, 0, 0.0); h2r.SetBinError (ix, h2r.GetYaxis()->GetNbins() + 1, 0.0);
314 }
315
316 for (int iy = 0; iy <= h2r.GetYaxis()->GetNbins() + 1; ++iy) {
317 h2r.SetBinContent(0, iy, 0.0); h2r.SetBinContent(h2r.GetXaxis()->GetNbins() + 1, iy, 0.0);
318 h2r.SetBinError (0, iy, 0.0); h2r.SetBinError (h2r.GetXaxis()->GetNbins() + 1, iy, 0.0);
319 }
320
321
322 for (Int_t ix = 1; ix <= h2r.GetXaxis()->GetNbins(); ++ix) {
323 for (Int_t iy = 1; iy <= h2r.GetYaxis()->GetNbins(); ++iy) {
324 if (h2r.GetBinError(ix,iy) == 0.0) {
325 h2r.SetBinError(ix, iy, 1.0);
326 }
327 }
328 }
329
330 h2r.Scale(R / (numberOfPrimaries * recycling * WBin_ns));
331 h1 .Scale(R / (numberOfPrimaries * recycling));
332
333 out << h1 << h2r;
334
335 out.Write();
336 out.Close();
337}
string outputFile
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define STATUS(A)
Definition JMessage.hh:63
#define NOTICE(A)
Definition JMessage.hh:64
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:74
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
#define MAKE_CSTRING(A)
Make C-string.
Definition JPrint.hh:72
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance.
Monte Carlo run header.
Definition JHead.hh:1236
JAANET::norma norma
Definition JHead.hh:1621
const JCalibration & getCalibration() const
Get calibration.
Detector data structure.
Definition JDetector.hh:96
Data structure for a composite optical module.
Definition JModule.hh:76
Template data structure for PMT I/O.
Auxiliary class for map of PMT parameters.
const JPMTParameters & getPMTParameters(const JPMTIdentifier &id) const
Get PMT parameters.
Data structure for PMT parameters.
bool slewing
time slewing of analogue signal
General exception.
Definition JException.hh:24
int getID() const
Get identifier.
Definition JObjectID.hh:50
Utility class to parse command line options.
Definition JParser.hh:1698
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.
Auxiliary class to convert pair of indices to unique index and back.
static int getSign(const int first, const int second)
Sign of pair of indices.
Direct addressing of elements with unique identifiers.
Definition JRouter.hh:27
static bool getSlewing()
Get slewing option.
static void setSlewing(const bool slewing)
Set slewing option.
static const char *const _2R
Name extension for 2D rate measured.
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
@ debug_t
debug
Definition JMessage.hh:29
JComparator< JResult_t T::*, JComparison::lt > make_comparator(JResult_t T::*member)
Helper method to create comparator between values of data member.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
bool putObject(TDirectory &dir, const TObject &object)
Write object to ROOT directory.
Head getHeader(const JMultipleFileScanner_t &file_list)
Get Monte Carlo header.
KM3NeT DAQ data structures and auxiliaries.
Definition DataQueue.cc:39
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
Auxiliary data structure for floating point format specification.
Definition JManip.hh:448
The Head class reflects the header of Monte-Carlo event files, which consists of keys (also referred ...
Definition Head.hh:65
Detector file.
Definition JHead.hh:227
Transmission with position.
Definition JBillabong.cc:70
Auxiliary class to sort pairs of PMT addresses within optical module.
Data structure for PMT analogue signal.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition JParser.hh:68
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