54 using namespace KM3NETDAQ;
71 JParser<> zap(
"Auxiliary program to fit time-over-threshold distributions.");
73 zap[
'f'] =
make_field(inputFile,
"input file (output from JCalibrateToT).");
75 zap[
'a'] =
make_field(detectorFile,
"detector file.");
76 zap[
'P'] =
make_field(pmtFile,
"specify PMT file name that can be given to JTriggerEfficiency.") =
"";
77 zap[
'w'] =
make_field(writeFits,
"write fit results.");
78 zap[
'x'] =
make_field(fitRange,
"ROOT fit range (time-over-threshold).") =
JRange_t(0.0, 35.0);
79 zap[
'O'] =
make_field(option,
"ROOT fit options, see TH1::Fit.") =
"";
80 zap[
'W'] =
make_field(WMin,
"minimal histogram contents.") = 1000.0;
86 catch(
const exception &error) {
87 FATAL(error.what() << endl);
117 if (option.find(
'R') == string::npos) { option +=
'R'; }
118 if (option.find(
'S') == string::npos) { option +=
'S'; }
122 TFile*
in = TFile::Open(inputFile.c_str(),
"exist");
124 if (
in == NULL || !
in->IsOpen()) {
125 FATAL(
"File: " << inputFile <<
" not opened." << endl);
129 TH2D
gain(
"gain", NULL,
132 TH1D chi2(
"chi2", NULL, 100, 0.0, 5.0);
141 for (JDetector::iterator module =
detector.begin(); module !=
detector.end(); ++module) {
143 DEBUG(
"Module " << module->getID() << endl);
153 WARNING(
"No histogram " << module->getID() <<
"; skip fit." << endl);
158 const int ny = h2s->GetYaxis()->GetNbins();
159 const double ymin = h2s->GetYaxis()->GetXmin();
160 const double ymax = h2s->GetYaxis()->GetXmax();
166 for (
int ix = 1; ix <= h2s->GetXaxis()->GetNbins(); ++ix) {
172 TH1D
h1(
MAKE_CSTRING(module->getID() <<
"." <<
id.getPMTAddress() <<
".1ToT"), NULL, ny, ymin, ymax);
176 for (
int iy = h2s->GetNbinsY(); iy >= 1; --iy) {
178 const double w =
h1.GetBinWidth (iy);
179 const double y = h2s->GetBinContent(ix, iy);
181 h1.SetBinContent(iy, y/w);
182 h1.SetBinError (iy, sqrt(y)/w);
186 const double Wtot =
h1.Integral();
195 const TFitResultPtr
result = fit(
h1, WMin/Wtot, option.c_str());
197 if ((
int(result) < 0) || (!result->IsValid())) {
199 WARNING(
"Fit failure for PMT " <<
id <<
"; set default values." << endl);
201 h1.GetListOfFunctions()->Clear();
203 const double initG = fit.getInitGain();
204 const double initGS = fit.getInitGainSpread();
218 if ((ymin < fitRange.getLowerLimit() || ymax > fitRange.getUpperLimit()) &&
219 (option.find(
"0") == string::npos && option.find(
"N") == string::npos)) {
228 JFitToT::getNumberOfModelParameters());
229 f1->SetParameters(fit.GetParameters());
230 f1->SetLineStyle(kDotted);
233 h1.GetListOfFunctions()->Add(f1);
238 const double reducedChi2 = result->Chi2() / result->Ndf();
243 chi2_1d. SetBinContent(ix, reducedChi2);
244 gain_1d. SetBinContent(ix, values.gain);
245 gain_1d. SetBinError (ix, errors.gain);
246 gainspread_1d.SetBinContent(ix, values.gainSpread);
247 gainspread_1d.SetBinError (ix, errors.gainSpread);
249 gain.Fill(fit.gain, fit.gainSpread);
250 chi2.Fill(TMath::Log10(reducedChi2));
252 NOTICE(
"PMT " <<
id <<
" chi2 / NDF " << result->Chi2() <<
' ' << result->Ndf() << endl);
263 out << chi2_1d << gain_1d << gainspread_1d;
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.
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
*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
Parametrisation of time-over-threshold distribution.
Fit parameters for two-fold coincidence rate due to K40.
#define MAKE_STRING(A)
Make string.
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
static const double FITTOT_GAINSPREAD_MAX
Maximal gain spread.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Auxiliary class for map of PMT parameters.
void load(const JString &file_name, JDetector &detector)
Load detector from input file.
JRange< Double_t > JRange_t
static const char *const _2SToT
Histogram naming.
static const double FITTOT_GAINSPREAD_MIN
Minimal gain spread.
static const int NUMBER_OF_PMTS
Total number of PMTs in module.
static const std::string FITTOT_FNAME
#define DEBUG(A)
Message macros.