59   using namespace KM3NETDAQ;
 
   71   double                          LeftMargin        =  10.0;    
 
   72   double                          RightMargin       =  10.0;    
 
   73   double                          gradientThreshold =  -0.005;  
 
   91     JParser<> zap(
"Auxiliary program to fit time-over-threshold distributions.");
 
   93     zap[
'f'] = 
make_field(inputFile,         
"input file (output from JCalibrateToT).");
 
   95     zap[
'a'] = 
make_field(detectorFile,      
"detector file.");
 
   96     zap[
'P'] = 
make_field(pmtFile,           
"specify PMT file name that can be given to JTriggerEfficiency.") = 
"";
 
   97     zap[
'w'] = 
make_field(writeFits,         
"write fit results.");
 
   98     zap[
'O'] = 
make_field(option,            
"ROOT fit options, see TH1::Fit")                                 = 
"";
 
  100     zap[
'x'] = 
make_field(fitRange,          
"ROOT fit range (time-over-threshold).")                          = JRange_t(0.0, 35.0);    
 
  106   catch(
const exception &error) {
 
  107     FATAL(error.what() << endl);
 
  127   if (!pmtFile.empty()) {
 
  130       parametersMap.
load(pmtFile.c_str()); 
 
  135   parametersMap.comment.add(
JMeta(argc, argv));
 
  138   if (option.find(
'R') == string::npos) { option += 
'R'; }
 
  139   if (option.find(
'S') == string::npos) { option += 
'S'; }
 
  143   TFile* 
in = TFile::Open(inputFile.c_str(), 
"exist");
 
  145   if (
in == NULL || !
in->IsOpen()) {
 
  146     FATAL(
"File: " << inputFile << 
" not opened." << endl);
 
  150   TH2D 
gain(
"gain", NULL,
 
  153   TH1D chi2(
"chi2", NULL, 100,  0.0, 5.0);
 
  167   for (JDetector::iterator module = 
detector.begin(); module != 
detector.end(); ++module) {
 
  169     NOTICE(
"Module " << setw(10) << module->getID() << 
' ' << module->getLocation() << endl);
 
  171     if (module->empty()) {
 
  183       WARNING(
"No histogram " << module->getID() << 
"; skip fit." << endl);
 
  188     const double ny   = h2s->GetYaxis()->GetNbins();
 
  189     const double ymin = h2s->GetYaxis()->GetXmin();
 
  190     const double ymax = h2s->GetYaxis()->GetXmax();
 
  196     for (
int ix = 1; ix <= h2s->GetXaxis()->GetNbins(); ++ix) {
 
  203       DEBUG(
"Processing histogram " << name << endl);
 
  205       TH1D 
h1(name.c_str(), NULL, ny, ymin, ymax); 
 
  209       for (
int iy = h2s->GetNbinsY(); iy >= 1; --iy) {
 
  211         const double w = 
h1.GetBinWidth (iy);
 
  212         const double y = h2s->GetBinContent(ix, iy);
 
  214         h1.SetBinContent(iy, y/w);
 
  215         h1.SetBinError  (iy, sqrt(y)/w);
 
  218       JRange_t     
range(fitRange);
 
  221                                         h1.FindBin(
range.getUpperLimit()));
 
  223       if (weight <= Wmin) {
 
  225         WARNING(
"Insufficient histogram entries for PMT "  << 
id <<
 
  226                 "(" << weight << 
" < " << Wmin << 
"); skip fit." << endl);
 
  245             RIGHT(10) << 
"threshold" << 
RIGHT(10) << 
"Mode"   << 
RIGHT(10) << 
"Max" << endl);
 
  247       for (
int i = 
h1.GetBinCenter(ny-1);
 
  251          const double x = 
h1.GetBinCenter (i);
 
  252          const double y = 
h1.GetBinContent(i);
 
  254          const double gradient = ( (
h1.GetBinContent(i-1) - 
h1.GetBinContent(i+1)) /
 
  255                                    (
h1.GetBinCenter (i+1) - 
h1.GetBinCenter (i-1)) );
 
  258                FIXED(10,1) << -fabs(gradientThreshold) * 
h1.Integral() << 
FIXED(10,1) << ToTmode << 
FIXED(10,1) << max << endl);
 
  266          } 
else if (gradient < -fabs(gradientThreshold) * 
h1.Integral()) {
 
  276       if (!
range.is_valid()) {
 
  277         range.setRange(ToTmode - LeftMargin,
 
  278                        ToTmode + RightMargin);
 
  281       range.setRange(std::max(
h1.GetXaxis()->GetXmin(), 
range.getLowerLimit()),
 
  282                      std::min(
h1.GetXaxis()->GetXmax(), 
range.getUpperLimit()));
 
  292       const double initGain       = fit.getCPU().getNPE(ToTmode);
 
  293       const double initGainSpread = initGain / 3.0;
 
  297         WARNING(
"Invalid initial gain for PMT " << 
id << 
"; set default values." << endl);
 
  310       fit.gainSpread = initGainSpread;
 
  312       const TFitResultPtr 
result = fit(
h1, option);
 
  314       if (
int(result) < 0 || !result->IsValid()) { 
 
  316         WARNING(
"Fit failure for PMT " << 
id << 
"; set initialization values." << endl);
 
  318         h1.GetListOfFunctions()->Clear();
 
  320         parameters.
gain       = initGain;
 
  330       if ((ymin < 
range.getLowerLimit()  || ymax > 
range.getUpperLimit()) &&
 
  331           (option.find(
"0") == string::npos && option.find(
"N") == string::npos)) {
 
  340                           JFitToT::getNumberOfModelParameters());
 
  341         f1->SetParameters(fit.GetParameters());
 
  342         f1->SetLineStyle(kDotted);
 
  345         h1.GetListOfFunctions()->Add(f1);
 
  350       const double reducedChi2 = result->Chi2() / result->Ndf();
 
  355       chi2_1d.      SetBinContent(ix, reducedChi2);
 
  356       gain_1d.      SetBinContent(ix, 
values.gain);
 
  357       gain_1d.      SetBinError  (ix, errors.gain);
 
  358       gainspread_1d.SetBinContent(ix, 
values.gainSpread);
 
  359       gainspread_1d.SetBinError  (ix, errors.gainSpread);
 
  361       gain.Fill(fit.gain, fit.gainSpread);
 
  362       chi2.Fill(TMath::Log10(reducedChi2));
 
  364       NOTICE(
"PMT " << 
id << 
" chi2 / NDF " << result->Chi2() << 
' ' << result->Ndf() << endl);
 
  366       parameters.
gain       = fit.gain;
 
  383     const JMeta& meta = *
in.next();
 
  385     parametersMap.comment.add(meta);
 
  391     parametersMap.store(pmtFile.c_str());
 
Utility class to parse command line options. 
 
double getValue(const JScale_t scale)
Get numerical value corresponding to scale. 
 
TString replace(const TString &target, const TRegexp ®exp, const T &replacement)
Replace regular expression in input by given replacement. 
 
#define gmake_property(A)
macro to convert (template) parameter to JPropertiesElement object 
 
double gainSpread
gain spread [unit] 
 
static const double FITTOT_GAIN_MAX
Default maximal gain. 
 
const double TIME_OVER_THRESHOLD_NS
Specification for time-over-threshold corresponding to a one photo-electron pulse. 
 
static const double FITTOT_GAIN_MIN
Default minimal gain. 
 
then echo Enter input within $TIMEOUT_S seconds echo n User name
 
Utility class to parse parameter values. 
 
*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
 
#define MAKE_CSTRING(A)
Make C-string. 
 
then for HISTOGRAM in h0 h1
 
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
 
Auxiliary data structure for floating point format specification. 
 
Parametrisation of time-over-threshold distribution. 
 
Fit parameters for two-fold coincidence rate due to K40. 
 
#define MAKE_STRING(A)
Make string. 
 
static const std::string FITTOT_SUFFIX
 
double mean_ns
mean time-over-threshold of threshold-band hits [ns] 
 
double sigma_ns
time-over-threshold standard deviation of threshold-band hits [ns] 
 
static const double FITTOT_GAINSPREAD_MAX
Default maximal gain spread. 
 
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object 
 
Auxiliary class for map of PMT parameters. 
 
Auxiliary data structure for sequence of same character. 
 
void load(const char *file_name)
Load from input file. 
 
z range($ZMAX-$ZMIN)< $MINIMAL_DZ." fi fi typeset -Z 4 STRING typeset -Z 2 FLOOR JPlot1D -f $
 
then $JPP_DIR examples JDetector JToT o $OUTPUT_FILE n N $NPE P gain
 
void load(const std::string &file_name, JDetector &detector)
Load detector from input file. 
 
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
 
static const char *const _2SToT
Histogram naming. 
 
static const double FITTOT_GAINSPREAD_MIN
Default minimal gain spread. 
 
Object reading from a list of files. 
 
Data structure for PMT parameters. 
 
do set_variable DETECTOR_TXT $WORKDIR detector
 
static const int NUMBER_OF_PMTS
Total number of PMTs in module. 
 
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY source JAcoustics sh $DETECTOR_ID CHECK_EXIT_CODE typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
 
static const std::string FITTOT_FNAME
 
std::vector< double > weight