16 #include "dbclient/KM3NeTDBClient.h" 
   40 #include "TGraphErrors.h" 
   49 int main(
int argc, 
char **argv)
 
   57   typedef typename JMultiMap_t::super_const_iterator                    JSuperIt_t;
 
   79     JParser<> zap(
"Example program to find optimal HV-settings.");
 
   84     zap[
'f'] = 
make_field(inputFiles,  
"map of run numbers and associated ToT-fit root files (JFitToT output)");
 
   86     zap[
'T'] = 
make_field(testType,    
"test type")                                 = 
"HV-TUNING-SEA-GAIN-v1";
 
   87     zap[
'P'] = 
make_field(testProduct, 
"test product")                              = 
"";  
 
   88     zap[
'e'] = 
make_field(HVerr,       
"Error on high-voltage measurements [V]")    = 5.0; 
 
   90     zap[
'o'] = 
make_field(graphFile,   
"Graphical output           (root format)")  = 
"";
 
   95   catch(
const exception &error) {
 
   96     FATAL(error.what() << endl);
 
  100   time_t startTime = time(0);
 
  114       ResultSet& rs       = 
getResultSet(getTable<JPersons>(), selector);
 
  123       ResultSet& rs       = 
getResultSet(getTable<JDetectorIntegration>(), selector); 
 
  127         if (detint.PMTID >= 0) {
 
  129           const JUPI upi = detint.PMTUPI;
 
  131           locMap[detint.DOMID][detint.DUID][detint.FLOORID][detint.PMTID] = upi;
 
  142       const int runNr = fileIt->first;
 
  144       NOTICE(
"Extracting Gain-/HV-data for run " << runNr << endl);
 
  152         ResultSet& rs       = 
getResultSet(getTable<JPMTHVRunSettings>(), selector);
 
  157           for (JSuperIt_t locIt = locMap.super_begin(); locIt != locMap.super_end(); ++locIt) {
 
  159             if (parameters.DUID     == locIt->second->first &&
 
  160                 parameters.FLOORID  == locIt->second->second->first &&
 
  161                 parameters.PMTINTID == locIt->second->second->second->first) {
 
  163               const JUPI upi = locIt.getValue();
 
  165               HVmap[upi] = log(fabs(parameters.HV_VALUE));
 
  175       TFile 
in(fileIt->second.c_str(), 
"READ");
 
  176       TIter next(
in.GetListOfKeys());
 
  178       while(TKey* key = (TKey*)next()) {
 
  180         const string name(key->GetName());
 
  181         if (!gROOT->GetClass(key->GetClassName())->InheritsFrom(
"TH1") ||
 
  182             name.find(
"1ToT") == string::npos) { 
continue; }
 
  184         const int pos   = 
name.find(
".");
 
  185         const int modID = stoi(
name.substr(0, pos));
 
  186         const int pmtID = stoi(
name.substr(pos+1, 2));
 
  188         for (JSuperIt_t locIt = locMap.super_begin(); locIt != locMap.super_end(); ++locIt) {
 
  190           if (modID == locIt->first &&
 
  191               pmtID == locIt->second->second->second->first) {
 
  193             const JUPI   upi      = locIt.getValue();
 
  194             const double logAbsHV = HVmap[upi];
 
  196             const TH1*   
h1       = (TH1*) key->ReadObj();
 
  199             double gain, gainErr;
 
  202               const int Ngain = f1->GetParNumber(
"gain");
 
  204               gain      = f1->GetParameter(Ngain);
 
  205               gainErr   = f1->GetParError (Ngain);
 
  209               const double prevG = (dataMap[upi].size() > 0 ?
 
  210                                     (--(dataMap[upi].lower_bound(logAbsHV)))->second.first : log(
FITTOT_GAIN_MIN));
 
  216             dataMap[upi][logAbsHV] = element_t{log(gain), gainErr / gain};
 
  222   catch (
const exception& error) {
 
  223     FATAL(error.what() << endl);
 
  233   NOTICE(
"Searching optimal high-voltage settings...\n\t" <<
 
  234          "High-Voltage [V] --- Gain [-]" << endl);
 
  236   for (datamap_t::const_iterator 
pmt  = (testProduct.empty() ? dataMap.cbegin() :    dataMap.find(testProduct)) ;
 
  237                                  pmt != (testProduct.empty() ? dataMap.cend()   : ++(dataMap.find(testProduct)));
 
  243     string location, serialID;
 
  244     for (JSuperIt_t locIt = locMap.super_begin(); locIt != locMap.super_end(); ++locIt) {
 
  246       if (locIt.getValue().getVariant() == upi.
getVariant()) {
 
  249                                locIt->second->first << setw(0) << 
"." <<
 
  250                                setw(2) << locIt->second->second->first << setw(0) << 
"." <<
 
  251                                setw(2) << locIt->second->second->second->first <<
 
  252                                setw(0) << setfill(
' '));
 
  254         serialID = 
MAKE_STRING(locIt->first << 
"." << left << setw(2) << 
 
  255                                locIt->second->second->second->first << right << setw(0));
 
  259     NOTICE(upi << 
" (a.k.a. " << serialID << 
" / " << location << 
"):\n\t");
 
  261     if (data.size() < 2) {
 
  263       WARNING(
"Insufficient data; skip!" << endl);
 
  267     manager[serialID]->Set(data.size());
 
  268     manager[serialID]->SetMarkerStyle(kFullDotSmall);
 
  274     double minDistance = (D2 > D1 ? D2 : D1);
 
  282       const int dIt = 
distance(data.cbegin(), it);
 
  283       manager[serialID]->SetPoint(dIt, it->first / log(10), it->second.first / log(10));
 
  284       manager[serialID]->SetPointError(dIt, fabs(HVerr / 
exp(it->first) / log(10)), fabs(it->second.second / log(10)));
 
  288       const double distance = fabs(logNominalGain - it->second.first);
 
  290       if (distance < minDistance) {
 
  294         k1 = ( it->second.first < logNominalGain ?
 
  295               (it != --data.cend() ? next(it,1) : prev(it,1)) : 
 
  296               (it != data.cbegin() ? prev(it,1) : next(it,1)) ); 
 
  307     if ((k1->first < k0->first && k1->second.first < k0->second.first) ||
 
  308         (k1->first > k0->first && k1->second.first > k0->second.first)) {
 
  312       const double logHV0       = k0->first;
 
  313       const double logHV1       = k1->first;
 
  315       const double logHV0err    = HVerr / 
exp(logHV0);
 
  316       const double logHV1err    = HVerr / 
exp(logHV1);
 
  318       const double logGain0     = k0->second.first;
 
  319       const double logGain1     = k1->second.first;
 
  321       const double logGain0err  = k0->second.second;
 
  322       const double logGain1err  = k1->second.second;
 
  325       const double slope        = (logGain1 - logGain0) / (logHV1 - logHV0); 
 
  326       const double logNominalHV = (logNominalGain - logGain0) / slope + logHV0;
 
  328       const double err1 = logHV0err * logHV0err;
 
  329       const double err2 = logGain0err * logGain0err / slope / slope;
 
  330       const double err3 = ( pow(logNominalGain - logGain0 / slope, 2.0) *
 
  331                             ((logGain0err*logGain0err + logGain1err*logGain1err) / pow(logGain1 - logGain0, 2.0) +
 
  332                              (logHV0err*logHV0err + logHV1err*logHV1err) / pow(logHV1 - logHV0, 2.0)) );
 
  334       const double logNominalHVerr = sqrt(err1 + err2 + err3);
 
  336       if (fabs(logNominalHV - logHV0) / fabs(logHV1 - logHV0) < 2.0) {
 
  341         errors.first  =  
exp(logNominalHV) * logNominalHVerr;
 
  346       if ((k0 == data.cbegin() && logNominalGain < logGain0) ||
 
  347           (k0 == --data.cend() && logNominalGain > logGain0)) {
 
  350                 "Extrapolation " << (valid ? 
"successful!" : 
"failed; Setting closest values!") << 
"\n\t");
 
  355       WARNING(
"Could not find optimal high-voltage; Setting closest values!\n\t");
 
  358     NOTICE(setw(8) << setprecision(2) << fixed << left <<
 
  359            result.first  << setw(0) << 
" +/- " << setw(4) << errors.first << setw(10) << right << 
 
  360            result.second << setw(0) << 
" +/- " << setw(3) << errors.second << endl);
 
  368     HVcalibrations.push_back(HVcal);
 
  372   if (! graphFile.empty()) {
 
  374     TFile out(graphFile.c_str(), 
"RECREATE");
 
  383   time_t stopTime = time(0);
 
  388   js[
User_t]                  = person.LOGIN;
 
  397   ofs << setw(2) << setprecision(8);
 
Utility class to parse command line options. 
 
JMultiMap is a general purpose multidimensional map based on a type list of maps. ...
 
static const std::string Failed_t
 
std::vector< T >::difference_type distance(typename std::vector< T >::const_iterator first, typename PhysicsEvent::const_iterator< T > second)
Specialisation of STL distance. 
 
static const std::string Tests_t
 
static const std::string OK_t
 
static const double FITTOT_GAIN_MAX
Maximal gain. 
 
static const double FITTOT_GAIN_MIN
Minimal gain. 
 
esac print_variable DETECTOR INPUT_FILE OUTPUT_FILE CDF for TYPE in
 
T get(const JHead &header)
Get object from header. 
 
*fatal Wrong number of arguments esac JCookie sh typeset Z DETECTOR typeset Z SOURCE_RUN typeset Z TARGET_RUN set_variable PARAMETERS_FILE $WORKDIR parameters
 
then for HISTOGRAM in h0 h1
 
static const std::string Location_t
 
Dynamic ROOT object management. 
 
Auxiliary class for specifying selection of database data. 
 
Data structure for detector geometry and calibration. 
 
#define MAKE_STRING(A)
Make string. 
 
esac $JPP_DIR examples JDetector JTransitTime o $OUTPUT_FILE n N $NPE T $TTS_NS d $DEBUG for HISTOGRAM in tts tt2 pmt
 
then echo Variable JPP_DIR undefined exit fi source $JPP_DIR setenv sh $JPP_DIR set_variable DEBUG set_variable NPE set_variable FIT_RANGE set_variable OUTPUT_DIR tmp set_variable OUTPUT_JSON $OUTPUT_DIR HVtuning json set_variable OUTPUT_ROOT $OUTPUT_DIR HVtuning root set_variable FIT_OPTIONS RME set_variable PMT_DEFAULT gain
 
Auxiliary class to manage set of compatible ROOT objects (e.g. 
 
I/O formatting auxiliaries. 
 
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object 
 
static const std::string Test_t
 
const std::string & getVariant() const 
Get variant. 
 
const double NOMINAL_GAIN
Specification for normalized gain corresponding to a one photo-electron pulse. 
 
General purpose messaging. 
 
static const JDetectorsHelper & getDetector
Function object for mapping serial number and object identifier of detectors. 
 
Universal product identifier (UPI). 
 
static const std::string EndTime_t
 
Utility class to parse command line options. 
 
Data structure for PMT high-voltage calibration. 
 
static const std::string Type_t
 
std::string to_string(const T &value)
Convert value to string. 
 
ResultSet & getResultSet(const std::string &query)
Get result set. 
 
static const std::string StartTime_t
 
std::string get_date_string(const std::time_t &time)
Create ISO 8601 date string for output file header. 
 
static const std::string User_t
Detector calibration key words for JSON I/O. 
 
This file is automatically created by make. 
 
Template definition for getting table specific selector. 
 
static const std::string FITTOT_FNAME
 
then set_variable FORMULA *[0] exp(-0.5 *(x-[1])*(x-[1])/([2]*[2]))" set_variable OUTPUT_FILE histogram.root JHistogram1D -o $WORKDIR/$OUTPUT_FILE -F "$FORMULA" -
 
bool putObject(TDirectory *dir, const T &object)
Write object to ROOT directory. 
 
int main(int argc, char *argv[])