Jpp  18.5.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JGlow.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <iomanip>
4 #include <map>
5 #include <cmath>
6 
7 #include "TROOT.h"
8 #include "TFile.h"
9 #include "TH1D.h"
10 #include "TMath.h"
11 #include "TRandom3.h"
12 
13 #include "JTools/JConstants.hh"
14 #include "JTools/JQuantile.hh"
15 
18 
19 #include "JROOT/JRootToolkit.hh"
20 #include "JTools/JRange.hh"
21 #include "JSupport/JMeta.hh"
22 
24 #include "JCalibrate/JFitK40.hh"
25 
26 #include "JROOT/JManager.hh"
27 
28 #include "Jeep/JPrint.hh"
29 #include "Jeep/JParser.hh"
30 #include "Jeep/JMessage.hh"
31 
33 
34 using namespace JSUPERNOVA;
35 
36 /**
37  * \file
38  *
39  * Auxiliary program to test simulation of L0 background
40  *
41  * \author mlincett
42  */
43 
44 int main(int argc, char **argv) {
45  using namespace std;
46  using namespace JPP;
47 
48  string inputFile;
49  string outputFile;
50  int debug;
51  int duration_ms;
52  int outNumberOfLines;
53 
54  try {
55 
56  JParser<> zap("Auxiliary program to test generation of L0 background.");
57 
58  zap['f'] = make_field(inputFile, "input file (output from JRipple).");
59  zap['o'] = make_field(outputFile, "output file.") = "glow.root";
60  zap['T'] = make_field(duration_ms, "duration in ms of the background sample.") = 500;
61  zap['N'] = make_field(outNumberOfLines, "number of lines of the simulated (output) detector") = 115;
62  zap['d'] = make_field(debug) = 1;
63  zap(argc, argv);
64  }
65  catch(const exception &error) {
66  FATAL(error.what() << endl);
67  }
68 
69  TFile* in = TFile::Open(inputFile.c_str(), "exist");
70 
71  if (in == NULL || !in->IsOpen()) {
72  FATAL("File: " << inputFile << " not opened." << endl);
73  }
74 
75  NOTICE("Initialising generator." << endl);
76 
77  JLightCurveBackgroundGenerator simbad(in, true);
78 
79  in->Close();
80 
81  NOTICE("File loaded." << endl);
82 
83  int T_ms = duration_ms;
84 
85  simbad.configureTimeWindow(T_ms);
86  simbad.setSeed();
87 
88  int inNumberOfLines = 1;
89 
90  simbad.configureRatio(inNumberOfLines, outNumberOfLines);
91 
92  JManager<int, TH1D> RT_SEQ(new TH1D("RT_SEQ_%", "Hit count" , T_ms, 0, T_ms));
93  JManager<int, TH1D> NC_SEQ(new TH1D("NC_SEQ_%", "Active channels" , T_ms, 0, T_ms));
94 
95  JManager<int, TH1D> RT_SHF(new TH1D("RT_SHF_%", "Hit count" , T_ms, 0, T_ms));
96  JManager<int, TH1D> NC_SHF(new TH1D("NC_SHF_%", "Active channels" , T_ms, 0, T_ms));
97 
98  JManager<string, TH1D> RT_FIT(new TH1D("RT_FIT_%", "Hit count" , T_ms, 0, T_ms));
99 
100  NOTICE("Generation SEQ" << endl);
101 
102  for (int i = 0; i < 10; i++) {
103  bg_type seq = simbad.generate();
104 
105  for (int j = 0; j < T_ms; j++) {
106  RT_SEQ[i]->Fill(j, seq[0][j]);
107  NC_SEQ[i]->Fill(j, seq[1][j]);
108 
109  }
110 
111  }
112 
113  NOTICE("Generation SHF" << endl);
114 
115  for (int i = 0; i < 10; i++) {
116  bg_type shf = simbad.generate_shuffled();
117 
118  for (int j = 0; j < T_ms; j++) {
119 
120  RT_SHF[i]->Fill(j, shf[0][j]);
121  NC_SHF[i]->Fill(j, shf[1][j]);
122 
123  }
124  }
125 
126  NOTICE("Generation H2D + FIT" << endl);
127 
128  h2d_t* test1 = simbad.generate_H2D();
129 
130  bg_type fit1 = simbad.generate_fitted();
131 
132  for (int j = 0; j < T_ms; j++) {
133  RT_FIT["SG_1"]->Fill(j, fit1[0][j]);
134  }
135 
136  NOTICE("Generation H2D + FIT - rebin = 5" << endl);
137 
138  h2d_t* test5 = simbad.generate_H2D(5);
139 
140 
141  bg_type fit5 = simbad.generate_fitted(5);
142 
143  for (size_t j = 0; j < fit5[0].size(); j++) {
144  cout << fit5[0][j] << endl;
145  RT_FIT["SG_5"]->Fill(j, fit5[0][j]);
146  }
147 
148 
149  /*
150  NOTICE("Generation FIT" << endl);
151 
152  for (int i = 0; i < 10; i++) {
153 
154  // RT_FIT["BG"]->Fill(j, fit[1][j]);
155  // RT_FIT["ER"]->Fill(j, fit[2][j]);
156  }
157 
158  }*/
159 
160 
161  TFile out(outputFile.c_str(), "recreate");
162 
163  TDirectory* dseq = out.mkdir("SEQ");
164  TDirectory* dshf = out.mkdir("SHF");
165  TDirectory* dfit = out.mkdir("FIT");
166 
167  RT_SEQ.Write(*dseq);
168  NC_SEQ.Write(*dseq);
169 
170  RT_SHF.Write(*dshf);
171  NC_SHF.Write(*dshf);
172 
173  RT_FIT.Write(*dfit);
174 
175  dfit->cd();
176  test1->Write();
177  test5->Write();
178 
179  out.Close();
180 
181 }
Utility class to parse command line options.
Definition: JParser.hh:1514
int main(int argc, char *argv[])
Definition: Main.cc:15
TH2F h2d_t
Definition: JRipple.hh:7
void configureTimeWindow(const int T_ms)
Configure the duration of an output sample.
void setSeed(const UInt_t uSeed=0)
Set TRandom seed.
void configureRatio(const int inputNumberOfLines, const int outputNumberOfLines)
Configure generation ratio.
Dynamic ROOT object management.
string outputFile
Auxiliary class to manage set of compatible ROOT objects (e.g. histograms) using unique keys...
Definition: JManager.hh:43
I/O formatting auxiliaries.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
bg_type generate()
Generate sample of L0 background L0 data are randomly sampled from a single L0 dataset.
Class to emulate L0 background for an arbitrarily sized detector.
ROOT I/O of application specific meta data.
#define NOTICE(A)
Definition: JMessage.hh:64
bg_type generate_shuffled(bool randomizeRun=false)
Generate sample of L0 background The sampling of the L0 data is not sequential but random within the ...
void Write(TDirectory &out, const bool wm=false)
Write objects to file.
Definition: JManager.hh:295
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
Constants.
Auxiliary class to define a range between two values.
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:48
Utility class to parse command line options.
bg_type generate_fitted(int rb=1)
Generate fitted L1 sample.
int j
Definition: JPolint.hh:792
h2d_t * generate_H2D(int rb=1)
Generate 2D sample.
This file provides a class to emulate a L0 (L1) background on the ms time scale for an arbitrarily si...
KM3NeT DAQ constants, bit handling, etc.
int debug
debug level