Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JVoltageOptimizer.cc
Go to the documentation of this file.
1 // C++
2 #include <string>
3 #include <iostream>
4 #include <sstream>
5 #include <iomanip>
6 
7 
8 // ROOT
9 #include "TTree.h"
10 
11 
12 // Nanobeacons
13 #include "NBRun.hh"
14 #include "Detector.hh"
15 #include "JVoltageOptimizer_IO.hh"
17 #include "Control_utils.hh"
18 
19 
20 // namespaces
21 using namespace std;
22 
23 
24 int main(int argc, char **argv) {
25 
26  IO options ;
27 
28  read_user_options(options, argc , argv) ;
29 
30  JDetector detector = loadDetector(options.detector_file) ;
31 
32  int Nruns = options.ifnames.size() ;
33 
34  int Nbeacons = getNumberOfFloors(detector) ;
35 
36  vector < vector < event > > evt_table (Nbeacons , vector < event > (Nruns)) ;
37 
38  char tname [50] ;
39 
40  sprintf(tname , "DU_%d" , options.string_number) ;
41 
42  TTree* t = new TTree(tname , tname) ;
43 
44  vector < TH2D* > summary_refs ;
45 
46  char bname [50] ;
47 
48  for (int i=0 ; i<Nbeacons ; i++){
49 
50  sprintf(bname , "NB%d" , i+1) ;
51 
52  t->Branch(bname , &evt_table[i][0] , "V/D:meanToT_ref/D:meanToT_tgt/D:sigmaToT_ref/D:sigmaToT_tgt/D") ;
53 
54  }
55 
56  int run_index = 0 ;
57 
58  vector < NBRun* > Sruns (Nruns) ;
59 
60  for(auto & file : options.ifnames){
61 
62  NBRun* run = new NBRun (file , detector , options.string_number , options.up_pmts , options.down_pmts , options.max_neighbors) ;
63 
64  Sruns[run_index] = run ;
65 
66  double v = run->getVoltage() ;
67 
68  summary_refs.push_back(refs_th2(run)) ;
69 
70  cout << "Analyzing run number: " << run->getRunNumber() << " Voltage = " << v << " V." << endl ;
71 
72  run->analyze(0) ;
73 
74  run->computeMeanToTs() ;
75 
76  int i = 0 ;
77 
78  for (auto & sm : run->getSuperModules()){
79 
80  sprintf(bname , "NB%d" , i+1) ;
81 
82  t->SetBranchAddress(bname , &evt_table[i][run_index]) ;
83 
84  evt_table[i][run_index].V = v ;
85 
86  evt_table[i][run_index].meanToT_ref = sm->getMeanToT_refs() ;
87 
88  evt_table[i][run_index].meanToT_tgt = sm->getMeanToT_tgts() ;
89 
90  evt_table[i][run_index].sigmaToT_ref = sm->getSigmaToT_refs() ;
91 
92  evt_table[i][run_index].sigmaToT_tgt = sm->getSigmaToT_tgts() ;
93 
94  i++ ;
95 
96  }
97 
98  t->Fill() ;
99 
100  run_index++ ;
101  }
102 
103  vector < pair < double , int > > OptimalVoltages = optimize_voltage (evt_table , options.saturation_tot ) ;
104 
105  write_output_txt( options.ofname_txt , OptimalVoltages ) ;
106 
107  write_output_opt( options.ofname_opt , t , summary_refs , Sruns) ;
108 
109  write_output_cal( options.ofname_cal , OptimalVoltages , Sruns , options.string_number , getNumberOfFloors(detector) ) ;
110 
111 }
int up_pmts
string ofname_txt
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
TH2D * refs_th2(NBRun *Run)
Produces a TH2 to be read as a table that summarizes which pmts were used as references for each modu...
Structure to store the different command line arguments for JRunAnalyzer.
Definition: JRunAnalyzer.cc:40
string ofname_opt
void write_output_opt(string filename, TTree *t, vector< TH2D * > summary_refs, vector< NBRun * > &Runs)
Writes a .root file with the optional output produced by JVoltageOptimizer.
string ofname_cal
JMultipleFileScanner ifnames
int max_neighbors
void computeMeanToTs()
Loops over all the SUPERMODULES to compute the mean ToT of the hits from the different nanobeacon pul...
Definition: NBRun.hh:105
vector< pair< double, int > > optimize_voltage(vector< vector< event > > evt_table, double max_tot)
Optimizes the voltage of each nanobeacon.
double saturation_tot
int getNumberOfFloors(const JDetector &detector)
Get number of floors.
JDetector loadDetector(string detectorFile)
Loads the content of a detector file in a JDetector object.
Definition: Detector.hh:28
double getVoltage()
Get nanobeacon voltage.
Definition: NBRun.hh:439
int getRunNumber()
Get run number.
Definition: NBRun.hh:427
void analyze(int option)
Loops over all the SUPERMODULES.
Definition: NBRun.hh:140
string detector_file
Definition: JRunAnalyzer.cc:46
void write_output_txt(string filename, vector< pair< double, int > > optimal_voltages)
Writes a .txt file with the result produced by JVoltageOptimizer.
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
void write_output_cal(string filename, vector< pair< double, int > > &optimal_voltages, vector< NBRun * > &Runs, int string_number, int nFloors)
Writes a .root file with the optional output produced by JVoltageOptimizer.
int main(int argc, char *argv[])
Definition: Main.cpp:15