Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
pulse_classification.cc
Go to the documentation of this file.
1 // c++ standard library
2 #include <string>
3 #include <iostream>
4 #include <sstream>
5 #include <iomanip>
6 
7 #include "TCanvas.h"
8 #include "RooPlot.h"
9 #include "RooDerivative.h"
10 #include "TLine.h"
11 #include "TF1.h"
12 
13 #include "NBRun.hh"
14 #include "Detector.hh"
16 #include "Control_utils.hh"
17 
18 // namespaces
19 
20 using namespace std;
21 
22 
23 /**
24  * Writes a .root file with some objects that can be used to check the calibration.
25  *
26  * \param filename path to the name of the .root
27  * \param run The nanobeacon calibration run
28  */
29 inline void write_output(string filename , NBRun& run){
30 
31  if (filename.length()==0){
32 
33  cout << "Omitting calibration checks..." << endl ;
34 
35  return ;
36 
37  }else{
38 
39  cout << "Writing pulses to file: " << endl ;
40 
41  cout << filename << endl ;
42 
43  cout << "------------------------------------" << endl << endl ;
44 
45  TFile outfile(filename.c_str() , "recreate") ;
46 
47  outfile.cd() ;
48 
49  outfile.mkdir("REF/Good") ;
50  outfile.mkdir("REF/Weak") ;
51  outfile.mkdir("REF/Saturated") ;
52 
53  outfile.mkdir("TGT/Good") ;
54  outfile.mkdir("TGT/Weak") ;
55  outfile.mkdir("TGT/Saturated") ;
56 
57  vector <SuperModule*> SuperMods = run.getSuperModules() ;
58 
59 
60  for (auto & sm : SuperMods){
61 
62  for (auto & spm : sm->get_ref_pmts()){
63 
64  if (spm->getNBPulse()->IsGood()==true) outfile.cd("REF/Good") ;
65 
66  if (spm->getNBPulse()->IsSaturatedHit()==true) outfile.cd("REF/Saturated") ;
67 
68  if (spm->getNBPulse()->IsWeak()==true) outfile.cd("REF/Weak") ;
69 
70  spm->getNBPulse()->getHtime_full()->Write() ;
71 
72  if (spm->getNBPulse()->IsFitted()==true){
73 
74  RooWorkspace w = spm->getNBPulse()->getWorkspace() ;
75 
76  TH1D* h = spm->getNBPulse()->getHtime_full() ;
77 
78  TCanvas* c1 = RooCanvas(w , h) ;
79 
80  c1->Write() ;
81 
82  w.Write() ;
83 
84  }
85 
86  outfile.cd() ;
87 
88  }
89 
90  for (auto & sms : sm->get_sources()){
91 
92  for (auto & spm : sms.second){
93 
94  if (spm->getNBPulse()->IsGood()==true) outfile.cd("TGT/Good") ;
95 
96  if (spm->getNBPulse()->IsSaturatedHit()==true) outfile.cd("TGT/Saturated") ;
97 
98  if (spm->getNBPulse()->IsWeak()==true) outfile.cd("TGT/Weak") ;
99 
100  spm->getNBPulse()->getHtime_full()->Write() ;
101 
102  if (spm->getNBPulse()->IsFitted()==true){
103 
104  RooWorkspace w = spm->getNBPulse()->getWorkspace() ;
105 
106  TH1D* h = spm->getNBPulse()->getHtime_full() ;
107 
108  TCanvas* c1 = RooCanvas(w , h) ;
109 
110  c1->Write() ;
111 
112  w.Write() ;
113 
114  }
115 
116  outfile.cd() ;
117 
118  }
119 
120  }
121 
122  }
123 
124  outfile.Close() ;
125 
126  }
127 
128 }
129 
130 
131 int main(int argc, char **argv) {
132 
133  IO options ;
134 
135  read_user_options(options, argc , argv);
136 
137  JDetector detector = loadDetector(options.detector_file) ;
138 
139  NBRun run (options.ifname , detector , options.string_number , options.up_pmts , options.down_pmts , options.number_neighbors) ;
140 
141  run.analyze(options.analysis_level) ;
142 
143  write_output(options.ofname , run) ;
144 
145 }
int up_pmts
int string_number
vector< SuperModule * > getSuperModules()
Get the SuperModules in the DU.
Definition: NBRun.hh:323
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
Definition: JRunAnalyzer.cc:44
void write_output(IO options, vector< vector< TH2D * > > ToT_vs_time, vector< vector< TH1D * > > ToT, vector< vector< TH1D * > > time)
Writes a .root file with the nanobeacon pulses found by JPulseFinder.
JDetector loadDetector(string detectorFile)
Loads the content of a detector file in a JDetector object.
Definition: Detector.hh:28
string ifname
Definition: JRunAnalyzer.cc:42
TCanvas * c1
Global variables to handle mouse events.
void analyze(int option)
Loops over all the SUPERMODULES.
Definition: NBRun.hh:140
int number_neighbors
string detector_file
Definition: JRunAnalyzer.cc:46
Class dedicated to the nanobeacon analyses, where the Modules in the detector are not regarded as sin...
Definition: NBRun.hh:24
int read_user_options(IO &options, int argc, char **argv)
Parses the command line options and fills an IO structure with them.
Definition: JRunAnalyzer.cc:59
TCanvas * RooCanvas(RooWorkspace w, TH1D *h)
Produces a TCanvas with the nanobeacon peak and the fit performed with Roofit.
int analysis_level
int main(int argc, char *argv[])
Definition: Main.cpp:15