Jpp
Functions
JVoltageOptimizer.cc File Reference
#include <string>
#include <iostream>
#include <sstream>
#include <iomanip>
#include "TTree.h"
#include "NBRun.hh"
#include "Detector.hh"
#include "JVoltageOptimizer_IO.hh"
#include "JVoltageOptimizer_utils.hh"
#include "Control_utils.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 24 of file JVoltageOptimizer.cc.

24  {
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 }
IO::max_neighbors
int max_neighbors
Definition: JVoltageOptimizer_IO.hh:51
IO::ofname_opt
string ofname_opt
Definition: JVoltageOptimizer_IO.hh:37
IO::ofname_cal
string ofname_cal
Definition: JVoltageOptimizer_IO.hh:39
IO::ifnames
JMultipleFileScanner ifnames
Definition: JPulseFinder_IO.hh:40
IO::down_pmts
int down_pmts
Definition: JInterDomCal_IO.hh:59
read_user_options
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
NBRun
Class dedicated to the nanobeacon analyses, where the Modules in the detector are not regarded as sin...
Definition: NBRun.hh:24
std::vector
Definition: JSTDTypes.hh:12
IO::saturation_tot
double saturation_tot
Definition: JVoltageOptimizer_IO.hh:53
IO
Structure to store the different command line arguments for JRunAnalyzer.
Definition: JRunAnalyzer.cc:40
JDETECTOR::getNumberOfFloors
int getNumberOfFloors(const JDetector &detector)
Get number of floors.
Definition: JDetectorToolkit.hh:414
NBRun::getVoltage
double getVoltage()
Get nanobeacon voltage.
Definition: NBRun.hh:439
NBRun::getRunNumber
int getRunNumber()
Get run number.
Definition: NBRun.hh:427
write_output_cal
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.
Definition: JVoltageOptimizer_IO.hh:215
refs_th2
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...
Definition: Control_utils.hh:27
NBRun::analyze
void analyze(int option)
Loops over all the SUPERMODULES.
Definition: NBRun.hh:140
IO::up_pmts
int up_pmts
Definition: JInterDomCal_IO.hh:57
JTOOLS::v
data_type v[N+1][M+1]
Definition: JPolint.hh:707
IO::ofname_txt
string ofname_txt
Definition: JInterDomCal_IO.hh:51
IO::string_number
int string_number
Definition: JInterDomCal_IO.hh:55
NBRun::computeMeanToTs
void computeMeanToTs()
Loops over all the SUPERMODULES to compute the mean ToT of the hits from the different nanobeacon pul...
Definition: NBRun.hh:105
JDETECTOR::JDetector
Detector data structure.
Definition: JDetector.hh:80
optimize_voltage
vector< pair< double, int > > optimize_voltage(vector< vector< event > > evt_table, double max_tot)
Optimizes the voltage of each nanobeacon.
Definition: JVoltageOptimizer_utils.hh:49
IO::detector_file
string detector_file
Definition: JRunAnalyzer.cc:46
write_output_txt
void write_output_txt(string filename, vector< pair< double, int > > optimal_voltages)
Writes a .txt file with the result produced by JVoltageOptimizer.
Definition: JVoltageOptimizer_IO.hh:183
loadDetector
JDetector loadDetector(string detectorFile)
Loads the content of a detector file in a JDetector object.
Definition: Detector.hh:28
write_output_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.
Definition: JVoltageOptimizer_IO.hh:123
NBRun::getSuperModules
vector< SuperModule * > getSuperModules()
Get the SuperModules in the DU.
Definition: NBRun.hh:323