10 #include "TFitResult.h" 
   40   static const char* 
const WILDCARD = 
"%";
 
   51 int main(
int argc, 
char **argv)
 
   55   using namespace KM3NETDAQ;
 
   66   double       LeftMargin        =  10.0;    
 
   67   double       RightMargin       =  10.0;    
 
   68   double       gradientThreshold =  -0.005;  
 
   87     JParser<> zap(
"Auxiliary program to fit time-over-threshold distributions.");
 
   89     zap[
'f'] = 
make_field(inputFile,         
"input file (output from JCalibrateToT).");
 
   91     zap[
'a'] = 
make_field(detectorFile,      
"detector file.");
 
   92     zap[
'P'] = 
make_field(pmtFile,           
"specify PMT file name that can be given to JTriggerEfficiency.") = 
"";
 
   93     zap[
'w'] = 
make_field(writeFits,         
"write fit results.");
 
   94     zap[
'O'] = 
make_field(option,            
"ROOT fit options, see TH1::Fit")                                 = 
"";
 
   96     zap[
'x'] = 
make_field(fitRange,          
"ROOT fit range (time-over-threshold).")                          = JRange_t(0.0, 35.0);    
 
  102   catch(
const exception &error) {
 
  103     FATAL(error.what() << endl);
 
  133   if (option.find(
'R') == string::npos) { option += 
'R'; }
 
  134   if (option.find(
'S') == string::npos) { option += 
'S'; }
 
  138   TFile* 
in = TFile::Open(inputFile.c_str(), 
"exist");
 
  140   if (
in == NULL || !
in->IsOpen()) {
 
  141     FATAL(
"File: " << inputFile << 
" not opened." << endl);
 
  145   TH2D 
gain(
"gain", NULL,
 
  148   TH1D chi2(
"chi2", NULL, 100,  0.0, 5.0);
 
  157   for (JDetector::iterator module = 
detector.begin(); module != 
detector.end(); ++module) {
 
  159     NOTICE(
"Module " << setw(10) << module->getID() << 
' ' << module->getLocation() << endl);
 
  161     if (module->empty()) {
 
  173       WARNING(
"No histogram " << module->getID() << 
"; skip fit." << endl);
 
  178     const double ny   = h2s->GetYaxis()->GetNbins();
 
  179     const double ymin = h2s->GetYaxis()->GetXmin();
 
  180     const double ymax = h2s->GetYaxis()->GetXmax();
 
  186     for (
int ix = 1; ix <= h2s->GetXaxis()->GetNbins(); ++ix) {
 
  192       TH1D 
h1(name.c_str(), NULL, ny, ymin, ymax); 
 
  196       for (
int iy = h2s->GetNbinsY(); iy >= 1; --iy) {
 
  198         const double w = 
h1.GetBinWidth (iy);
 
  199         const double y = h2s->GetBinContent(ix, iy);
 
  201         h1.SetBinContent(iy, y/w);
 
  202         h1.SetBinError  (iy, sqrt(y)/w);
 
  205       const double weight = 
h1.Integral(
h1.FindBin(fitRange.getLowerLimit()),
 
  206                                         h1.FindBin(fitRange.getUpperLimit()));
 
  208       if (weight <= Wmin) {
 
  210         WARNING(
"Insufficient histogram entries for PMT "    << 
id <<
 
  211                 "(" << weight << 
" < " << Wmin << 
"); skip fit." << endl);
 
  227       for (
int i = 
h1.GetBinCenter(ny-1);
 
  231          const double x = 
h1.GetBinCenter (i);
 
  232          const double y = 
h1.GetBinContent(i);
 
  234          const double gradient = ( (
h1.GetBinContent(i-1) - 
h1.GetBinContent(i+1)) /
 
  235                                    (
h1.GetBinCenter (i+1) - 
h1.GetBinCenter (i-1)) );
 
  242          } 
else if (gradient < -fabs(gradientThreshold) * 
h1.Integral()) {
 
  252       if (!fitRange.is_valid()) {
 
  253         fitRange.setRange(ToTmode - LeftMargin,
 
  254                           ToTmode + RightMargin);
 
  257       fitRange.setRange(std::max(
h1.GetXaxis()->GetXmin(), fitRange.getLowerLimit()),
 
  258                         std::min(
h1.GetXaxis()->GetXmax(), fitRange.getUpperLimit()));
 
  267       const double initGainSpread = initGain / 3.0;
 
  271         WARNING(
"Invalid initial gain for PMT " << 
id << 
"; set default values." << endl);
 
  286       const TFitResultPtr 
result = fit(
h1, option);
 
  288       if (
int(result) < 0 || !result->IsValid()) { 
 
  290         WARNING(
"Fit failure for PMT " << 
id << 
"; set initialization values." << endl);
 
  292         h1.GetListOfFunctions()->Clear();
 
  304       if ((ymin < fitRange.getLowerLimit()  || ymax > fitRange.getUpperLimit()) &&
 
  305           (option.find(
"0") == string::npos && option.find(
"N") == string::npos)) {
 
  314                           JFitToT::getNumberOfModelParameters());
 
  315         f1->SetParameters(fit.GetParameters());
 
  316         f1->SetLineStyle(kDotted);
 
  319         h1.GetListOfFunctions()->Add(f1);
 
  324       const double reducedChi2 = result->Chi2() / result->Ndf();
 
  329       chi2_1d.      SetBinContent(ix, reducedChi2);
 
  330       gain_1d.      SetBinContent(ix, 
values.gain);
 
  331       gain_1d.      SetBinError  (ix, errors.gain);
 
  332       gainspread_1d.SetBinContent(ix, 
values.gainSpread);
 
  333       gainspread_1d.SetBinError  (ix, errors.gainSpread);
 
  336       chi2.Fill(TMath::Log10(reducedChi2));
 
  338       NOTICE(
"PMT " << 
id << 
" chi2 / NDF " << result->Chi2() << 
' ' << result->Ndf() << endl);
 
  349       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. 
 
int main(int argc, char *argv[])
 
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 
 
static const double FITTOT_GAIN_MAX
Default maximal gain. 
 
Double_t gainSpread
PMT gain spread. 
 
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. 
 
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)...
 
Parametrisation of time-over-threshold distribution. 
 
Data structure for detector geometry and calibration. 
 
Fit parameters for two-fold coincidence rate due to K40. 
 
#define MAKE_STRING(A)
Make string. 
 
const JPMTAnalogueSignalProcessor & getCPU() const 
Access method for the analogue signal processor. 
 
static const std::string FITTOT_SUFFIX
 
Scanning of objects from a single file according a format that follows from the extension of each fil...
 
I/O formatting auxiliaries. 
 
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. 
 
General purpose messaging. 
 
Auxiliary data structure for sequence of same character. 
 
then $JPP_DIR examples JDetector JToT o $OUTPUT_FILE n N $NPE P gain
 
virtual double getNPE(const double tot_ns, const double eps=1.0e-3) const 
Get number of photo-electrons. 
 
void load(const std::string &file_name, JDetector &detector)
Load detector from input file. 
 
Auxiliary class to define a range between two values. 
 
Utility class to parse command line options. 
 
static const char *const _2SToT
Histogram naming. 
 
PMT analogue signal processor. 
 
static const double FITTOT_GAINSPREAD_MIN
Default minimal gain spread. 
 
Object reading from a list of files. 
 
do set_variable DETECTOR_TXT $WORKDIR detector
 
KM3NeT DAQ constants, bit handling, etc. 
 
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