Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JInterDomCal_IO.hh
Go to the documentation of this file.
1 #ifndef __IO_CAL__
2 #define __IO_CAL__
3 
4 //c++ standard library
5 #include <iostream>
6 #include <tuple>
7 
8 // Jpp
9 #include "JDAQ/JDAQTimeslice.hh"
11 #include "Jeep/JParser.hh"
12 #include "Jeep/JMessage.hh"
14 #include "JDetector/JDetector.hh"
16 #include "JDetector/JPMTRouter.hh"
17 #include "JLang/JObjectID.hh"
18 
19 #include "Detector.hh"
20 #include "Control_utils.hh"
21 
22 #include "JDetector/JDetector.hh"
25 
26 
27 using namespace JDETECTOR ;
28 // namespaces
29 using namespace std;
30 using namespace JSUPPORT; // for JFileScanner
31 using namespace JLANG; // for JMultipleFileScanner
32 using namespace JDETECTOR; // for JModuleLocation
33 
34 /**
35  * \author rgruiz
36  */
37 
38 
39 
40 /**
41  * Structure to store the different command line arguments for JInterDomCal.
42  */
43 struct IO{
44 
45  string detector_file ;
46 
47  string ofname_detx ;
48 
49  string ofname_checks ;
50 
51  string ofname_txt ;
52 
53  string ifname ;
54 
56 
57  int up_pmts ;
58 
59  int down_pmts ;
60 
62 
64 
65  int ref_pmt ;
66 
67  int tgt_pmt ;
68 
69 };
70 
71 
72 
73 /**
74  * Parses the command line options and fills an IO structure with them.
75  *
76  * \param options an option structure
77  * \param argc the number of command line arguments
78  * \param argv the command line arguments
79  *
80  * \return 1 if works 2 if it doesn't work
81  */
82 inline int read_options(IO &options, int argc, char **argv){
83 
84  int a = 0 ;
85 
86  try {
87 
88  JParser<string> zap;
89 
90  zap["c"] = make_field(options.ofname_checks) = "" ;
91 
92  zap["x"] = make_field(options.ofname_detx) = "out.detx" ;
93 
94  zap["t"] = make_field(options.ofname_txt) = "" ;
95 
96  zap["f"] = make_field(options.ifname) ;
97 
98  zap["a"] = make_field(options.detector_file) ;
99 
100  zap["s"] = make_field(options.string_number) ;
101 
102  zap["u"] = make_field(options.up_pmts) = 1 ;
103 
104  zap["d"] = make_field(options.down_pmts) = 4 ;
105 
106  zap["n"] = make_field(options.number_neighbors) = 2 ;
107 
108  zap["l"] = make_field(options.analysis_level) = 0 ;
109 
110  zap["rpm"] = make_field(options.ref_pmt) = 0 ;
111 
112  zap["tpm"] = make_field(options.tgt_pmt) = 22 ;
113 
114  if (zap.read(argc, argv) != 0)
115 
116  a = 1;
117 
118  }
119 
120  catch(const exception &error) {
121 
122  ERROR(error.what() << endl);
123 
124  a = 2;
125 
126  }
127 
128  return a ;
129 
130 }
131 
132 
133 /**
134  * Writes a .detx file with a JDetector.
135  *
136  * \param filename path to the name of the .detx
137  * \param detector the detector to be stored
138  */
139 inline void write_output_det(string filename , const JDetector &detector){
140 
141  store(filename , detector) ;
142 
143  cout << endl << "New detector stored in file: " << endl ;
144 
145  cout << filename << endl ;
146 
147  cout << "------------------------------------" << endl << endl ;
148 
149 }
150 
151 
152 
153 /**
154  * Writes a .txt with the comparison of the t0s in a given DU for two JDetectors.
155  *
156  * \param filename path to the name of the .txt
157  * \param old_detector one JDetector
158  * \param new_detector the other JDetector
159  * \param string_number the number of the DU to compare
160  * \param ref_pmt pmt in upper hemisphere used for the comparison
161  * \param tgt_pmt pmt in lower hemisphere used for the comparsion
162  */
163 inline void write_output_compare(string filename , const JDetector &old_detector, const JDetector &new_detector , int string_number , int ref_pmt , int tgt_pmt){
164 
165  if (filename.length()==0){
166 
167  cout << "Omitting comparison with old detector" << endl ;
168 
169  return ;
170 
171  }else{
172 
173  cout << "Writing comparison between new and old detx in file: " << endl ;
174 
175  cout << filename << endl ;
176 
177  cout << "------------------------------------" << endl << endl ;
178 
179  vector<double> t0_diff_new = getDetFile_t0_differences(string_number , new_detector , ref_pmt , tgt_pmt) ;
180 
181  vector<double> t0_diff_old = getDetFile_t0_differences(string_number , old_detector , ref_pmt , tgt_pmt) ;
182 
183  vector < tuple <double , double , double> > t0_vs_depth_new = get_t0_offsets_vs_depth(string_number , new_detector) ;
184 
185  vector < tuple <double , double , double> > t0_vs_depth_old = get_t0_offsets_vs_depth(string_number , old_detector) ;
186 
187  ofstream txtfile;
188 
189  txtfile.open (filename);
190 
191  txtfile << "# Comparison between detector files: column 1 = Delta_t0 new detx , column 2 = Delta_t0 old detx , column 3 = column1 - column 2" << endl;
192 
193  for(int i=0 ; i<(int)t0_diff_new.size() ; i++){
194 
195  txtfile << t0_diff_new[i] << "\t" << t0_diff_old[i] << "\t" << t0_diff_new[i] - t0_diff_old[i] << endl;
196 
197  }
198 
199  txtfile << "\n# t0 vs depth: column 1 = floor , columns 2,3,4 = depth_new, mean_centered_t0_new , error_new , columns 5,6,7 = depth_old, mean_centered_t0_old , error_old , column 8 = t0_old - t0_new " << endl ;
200 
201  for (int i=0 ; i < (int)t0_vs_depth_new.size() ; i++){
202 
203  txtfile << i+1 << "\t"
204  << get<0>(t0_vs_depth_new[i]) << "\t"
205  << get<1>(t0_vs_depth_new[i]) << "\t"
206  << get<2>(t0_vs_depth_new[i]) << "\t"
207  << get<0>(t0_vs_depth_old[i]) << "\t"
208  << get<1>(t0_vs_depth_old[i]) << "\t"
209  << get<2>(t0_vs_depth_old[i]) << "\t"
210  << get<1>(t0_vs_depth_new[i]) - get<1>(t0_vs_depth_old[i]) << endl ;
211  }
212 
213  }
214 
215 }
216 
217 
218 
219 /**
220  * Writes a .root file with some objects that can be used to check the calibration.
221  *
222  * \param filename path to the name of the .root
223  * \param run The nanobeacon calibration run
224  */
225 inline void write_output_checks(string filename , NBRun& run){
226 
227  if (filename.length()==0){
228 
229  cout << "Omitting calibration checks..." << endl ;
230 
231  return ;
232 
233  }else{
234 
235  cout << "Writing calibration checks in file: " << endl ;
236 
237  cout << filename << endl ;
238 
239  cout << "------------------------------------" << endl << endl ;
240 
241  TFile outfile(filename.c_str() , "recreate") ;
242 
243  outfile.cd() ;
244 
245  TH2D* srcs = srcs_th2(&run) ;
246  TH2D* tgts = tgts_th2(&run) ;
247  TH2D* refs = good_refs_th2(&run) ;
248  TH2D* tgt_pmts = good_tgt_pmts_th2(&run) ;
249 
250  srcs->Write() ;
251  tgts->Write() ;
252  refs->Write() ;
253  tgt_pmts->Write();
254 
255  outfile.mkdir("REF/Good") ;
256  outfile.mkdir("REF/Weak") ;
257  outfile.mkdir("REF/Saturated") ;
258 
259  outfile.mkdir("TGT/Good") ;
260  outfile.mkdir("TGT/Weak") ;
261  outfile.mkdir("TGT/Saturated") ;
262 
263  vector <SuperModule*> SuperMods = run.getSuperModules() ;
264 
265 
266  for (auto & sm : SuperMods){
267 
268  for (auto & spm : sm->get_ref_pmts()){
269 
270  if (spm->getNBPulse()->IsGood()==true) outfile.cd("REF/Good") ;
271 
272  if (spm->getNBPulse()->IsSaturatedHit()==true) outfile.cd("REF/Saturated") ;
273 
274  if (spm->getNBPulse()->IsWeak()==true) outfile.cd("REF/Weak") ;
275 
276  spm->getNBPulse()->getHtime_full()->Write() ;
277 
278  if (spm->getNBPulse()->IsFitted()==true){
279 
280  RooWorkspace w = spm->getNBPulse()->getWorkspace() ;
281 
282  TH1D* h = spm->getNBPulse()->getHtime_full() ;
283 
284  TCanvas* c1 = RooCanvas(w , h) ;
285 
286  c1->Write() ;
287 
288  w.Write() ;
289 
290  }
291 
292  outfile.cd() ;
293 
294  }
295 
296  for (auto & sms : sm->get_sources()){
297 
298  for (auto & spm : sms.second){
299 
300  if (spm->getNBPulse()->IsGood()==true) outfile.cd("TGT/Good") ;
301 
302  if (spm->getNBPulse()->IsSaturatedHit()==true) outfile.cd("TGT/Saturated") ;
303 
304  if (spm->getNBPulse()->IsWeak()==true) outfile.cd("TGT/Weak") ;
305 
306  spm->getNBPulse()->getHtime_full()->Write() ;
307 
308  if (spm->getNBPulse()->IsFitted()==true){
309 
310  RooWorkspace w = spm->getNBPulse()->getWorkspace() ;
311 
312  TH1D* h = spm->getNBPulse()->getHtime_full() ;
313 
314  TCanvas* c1 = RooCanvas(w , h) ;
315 
316  c1->Write() ;
317 
318  w.Write() ;
319 
320  }
321 
322  outfile.cd() ;
323 
324  }
325 
326  }
327 
328  }
329 
330  outfile.Close() ;
331 
332  }
333 
334 }
335 
336 
337 #endif
int up_pmts
Utility class to parse command line options.
Definition: JParser.hh:1410
vector< tuple< double, double, double > > get_t0_offsets_vs_depth(int strNr, const JDetector &detector)
Definition: Detector.hh:83
string ofname_txt
int string_number
Logical location of module.
vector< SuperModule * > getSuperModules()
Get the SuperModules in the DU.
Definition: NBRun.hh:323
void write_output_checks(string filename, NBRun &run)
Writes a .root file with some objects that can be used to check the calibration.
int down_pmts
Detector data structure.
Definition: JDetector.hh:77
Structure to store the different command line arguments for JRunAnalyzer.
Definition: JRunAnalyzer.cc:40
string ofname_checks
void write_output_compare(string filename, const JDetector &old_detector, const JDetector &new_detector, int string_number, int ref_pmt, int tgt_pmt)
Writes a .txt with the comparison of the t0s in a given DU for two JDetectors.
int tgt_pmt
Data structure for detector geometry and calibration.
int read_options(IO &options, int argc, char **argv)
Parses the command line options and fills an IO structure with them.
void write_output_det(string filename, const JDetector &detector)
Writes a .detx file with a JDetector.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1836
TH2D * good_refs_th2(NBRun *Run)
Produces a TH2 to be read as a table that summarizes which pmts were used as good references for each...
#define ERROR(A)
Definition: JMessage.hh:64
TH2D * good_tgt_pmts_th2(NBRun *Run)
Produces a TH2 to be read as a table that summarizes which pmts were used as good references for each...
Direct access to PMT in detector data structure.
string ifname
Definition: JRunAnalyzer.cc:42
General purpose messaging.
Scanning of objects from multiple files according a format that follows from the extension of each fi...
Direct access to module in detector data structure.
TCanvas * c1
Global variables to handle mouse events.
int read(const int argc, const char *const argv[])
Parse the program&#39;s command line options.
Definition: JParser.hh:1673
int number_neighbors
Utility class to parse command line options.
string ofname_detx
int ref_pmt
string detector_file
Definition: JRunAnalyzer.cc:46
void store(const JString &file_name, const JDetector &detector)
Store detector to output file.
TH2D * tgts_th2(NBRun *Run)
Produces a TH2 to be interpreted as a table that summarizes which modules were targets for each sourc...
Class dedicated to the nanobeacon analyses, where the Modules in the detector are not regarded as sin...
Definition: NBRun.hh:24
TCanvas * RooCanvas(RooWorkspace w, TH1D *h)
Produces a TCanvas with the nanobeacon peak and the fit performed with Roofit.
TH2D * srcs_th2(NBRun *Run)
Produces a TH2 to be read as a table that summarizes which modules were used as good sources for each...
int analysis_level
vector< double > getDetFile_t0_differences(int strNr, JDetector detector, int ref_pmt, int tgt_pmt)
Loops over the floors in the string chosen by the user.
Definition: Detector.hh:66