Jpp
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 "JGizmo/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  JL0BackgroundSimulator 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  // bg_type fit5 = JL0BackgroundSimulator::fit_H2D(test5);
141 
142  bg_type fit5 = simbad.generate_fitted(5);
143 
144  for (int j = 0; j < fit5[0].size(); j++) {
145  cout << fit5[0][j] << endl;
146  RT_FIT["SG_5"]->Fill(j, fit5[0][j]);
147  }
148 
149 
150  /*
151  NOTICE("Generation FIT" << endl);
152 
153  for (int i = 0; i < 10; i++) {
154 
155 
156 
157 
158 
159  // RT_FIT["BG"]->Fill(j, fit[1][j]);
160  // RT_FIT["ER"]->Fill(j, fit[2][j]);
161  }
162 
163  }*/
164 
165 
166  TFile out(outputFile.c_str(), "recreate");
167 
168  TDirectory* dseq = out.mkdir("SEQ");
169  TDirectory* dshf = out.mkdir("SHF");
170  TDirectory* dfit = out.mkdir("FIT");
171 
172  RT_SEQ.Write(*dseq);
173  NC_SEQ.Write(*dseq);
174 
175  RT_SHF.Write(*dshf);
176  NC_SHF.Write(*dshf);
177 
178  RT_FIT.Write(*dfit);
179 
180  dfit->cd();
181  test1->Write();
182  test5->Write();
183 
184  out.Close();
185 
186 }
JMeta.hh
JDAQ.hh
JManager::Write
void Write(TFile &out)
Write histograms to file.
Definition: JHistogramToolkit.hh:227
JManager< string, TH1D >
JMessage.hh
JPrint.hh
JFitK40.hh
JSUPERNOVA::JL0BackgroundSimulator
Class to emulate L0 background for an arbitrarily sized detector.
Definition: JL0BackgroundSimulator.hh:57
std::vector
Definition: JSTDTypes.hh:12
JTOOLS::j
int j
Definition: JPolint.hh:634
JPARSER::JParser
Utility class to parse command line options.
Definition: JParser.hh:1493
JGIZMO::JManager
Auxiliary class to manage set of compatible ROOT objects (e.g.
Definition: JManager.hh:40
NOTICE
#define NOTICE(A)
Definition: JMessage.hh:64
JQuantile.hh
JManager.hh
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JRange.hh
JL0BackgroundSimulator.hh
debug
int debug
debug level
Definition: JSirene.cc:59
JConstants.hh
JSUPERNOVA::JL0BackgroundSimulator::generate_fitted
bg_type generate_fitted(int rb=1)
Generate fitted L1 sample.
Definition: JL0BackgroundSimulator.hh:453
JSUPERNOVA::JL0BackgroundSimulator::generate_H2D
h2d_t * generate_H2D(int rb=1)
Generate 2D sample.
Definition: JL0BackgroundSimulator.hh:375
main
int main(int argc, char **argv)
Definition: JGlow.cc:44
JRootToolkit.hh
JGIZMO::JManager::Write
void Write(TDirectory &out, const bool wm=false)
Write objects to file.
Definition: JManager.hh:258
JParser.hh
JDetectorToolkit.hh
JSUPERNOVA::JL0BackgroundSimulator::generate
bg_type generate()
Generate sample of L0 background L0 data are randomly sampled from a single L0 dataset.
Definition: JL0BackgroundSimulator.hh:204
JManager::Fill
void Fill(const JFit &fA, const JFit &fB, const bool option)
Fill histograms.
Definition: JHistogramToolkit.hh:196
JSUPERNOVA::JL0BackgroundSimulator::setSeed
void setSeed(const UInt_t uSeed=0)
Set TRandom seed.
Definition: JL0BackgroundSimulator.hh:170
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
std
Definition: jaanetDictionary.h:36
JSUPERNOVA::JL0BackgroundSimulator::configureRatio
void configureRatio(const int iSize, const int oSize)
Set rebinning ratio.
Definition: JL0BackgroundSimulator.hh:189
JCalibrateK40.hh
JSUPERNOVA::JL0BackgroundSimulator::configureTimeWindow
void configureTimeWindow(const int T_ms)
Configure the duration of an output sample.
Definition: JL0BackgroundSimulator.hh:161
FATAL
#define FATAL(A)
Definition: JMessage.hh:67
outputFile
string outputFile
Definition: JDAQTimesliceSelector.cc:37
JSUPERNOVA::JL0BackgroundSimulator::generate_shuffled
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 ...
Definition: JL0BackgroundSimulator.hh:258
JSUPERNOVA::h2d_t
TH2F h2d_t
Definition: JRipple.hh:7
JSUPERNOVA
Definition: JSupernova.hh:24