Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Functions
JInterDomCal_IO.hh File Reference
#include <iostream>
#include <tuple>
#include "JDAQ/JDAQTimeslice.hh"
#include "JSupport/JMultipleFileScanner.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JModuleLocation.hh"
#include "JDetector/JPMTRouter.hh"
#include "JLang/JObjectID.hh"
#include "Detector.hh"
#include "Control_utils.hh"
#include "JDetector/JModuleRouter.hh"
#include "JDetector/JDetectorToolkit.hh"

Go to the source code of this file.

Classes

struct  IO
 Structure to store the different command line arguments for JRunAnalyzer. More...
 

Functions

int read_options (IO &options, int argc, char **argv)
 Parses the command line options and fills an IO structure with them. More...
 
void write_output_det (string filename, const JDetector &detector)
 Writes a .detx file with a JDetector. More...
 
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. More...
 
void write_output_checks (string filename, NBRun &run)
 Writes a .root file with some objects that can be used to check the calibration. More...
 

Function Documentation

int read_options ( IO options,
int  argc,
char **  argv 
)
inline

Parses the command line options and fills an IO structure with them.

Parameters
optionsan option structure
argcthe number of command line arguments
argvthe command line arguments
Returns
1 if works 2 if it doesn't work

Definition at line 82 of file JInterDomCal_IO.hh.

82  {
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 }
int up_pmts
Utility class to parse command line options.
Definition: JParser.hh:1410
string ofname_txt
int string_number
int down_pmts
string ofname_checks
int tgt_pmt
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1836
#define ERROR(A)
Definition: JMessage.hh:64
string ifname
Definition: JRunAnalyzer.cc:42
int read(const int argc, const char *const argv[])
Parse the program&#39;s command line options.
Definition: JParser.hh:1673
int number_neighbors
string ofname_detx
int ref_pmt
string detector_file
Definition: JRunAnalyzer.cc:46
int analysis_level
void write_output_det ( string  filename,
const JDetector detector 
)
inline

Writes a .detx file with a JDetector.

Parameters
filenamepath to the name of the .detx
detectorthe detector to be stored

Definition at line 139 of file JInterDomCal_IO.hh.

139  {
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 }
void store(const JString &file_name, const JDetector &detector)
Store detector to output file.
void write_output_compare ( string  filename,
const JDetector old_detector,
const JDetector new_detector,
int  string_number,
int  ref_pmt,
int  tgt_pmt 
)
inline

Writes a .txt with the comparison of the t0s in a given DU for two JDetectors.

Parameters
filenamepath to the name of the .txt
old_detectorone JDetector
new_detectorthe other JDetector
string_numberthe number of the DU to compare
ref_pmtpmt in upper hemisphere used for the comparison
tgt_pmtpmt in lower hemisphere used for the comparsion

Definition at line 163 of file JInterDomCal_IO.hh.

163  {
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 }
vector< tuple< double, double, double > > get_t0_offsets_vs_depth(int strNr, const JDetector &detector)
Definition: Detector.hh:83
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
void write_output_checks ( string  filename,
NBRun run 
)
inline

Writes a .root file with some objects that can be used to check the calibration.

Parameters
filenamepath to the name of the .root
runThe nanobeacon calibration run

Definition at line 225 of file JInterDomCal_IO.hh.

225  {
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 }
vector< SuperModule * > getSuperModules()
Get the SuperModules in the DU.
Definition: NBRun.hh:323
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...
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...
TCanvas * c1
Global variables to handle mouse events.
TH2D * tgts_th2(NBRun *Run)
Produces a TH2 to be interpreted as a table that summarizes which modules were targets for each sourc...
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...