14 #include "TFitResult.h" 
   42 int main(
int argc, 
char **argv) {
 
   54     JParser<> zap(
"Auxiliary program to fit multiplicity rates from JMonitorMultiplicity output.");
 
   56     zap[
'f'] = 
make_field(inputFile,         
"input file");
 
   58     zap[
'O'] = 
make_field(option,            
"fitting option")                                        = 
"Q";
 
   59     zap[
'B'] = 
make_field(fitBackground,     
"get signal by fit and subtraction from background from the integral");
 
   64   catch(
const exception &error) {
 
   65     FATAL(error.what() << endl);
 
   68   TFile* in = TFile::Open(inputFile.c_str(), 
"exist");
 
   70   if (in == NULL || !in->IsOpen()) {
 
   71     FATAL(
"File: " << inputFile << 
" not opened." << endl);
 
   80   const double xmin = -0.5;
 
   81   const double xmax = nx - 0.5;
 
   86   JManager_t HTF(
new TH1D(
"%F", 
"",  nx, xmin, xmax));
 
   88   JManager_t HTFE(
new TH1D(
"%FE", 
"", nx, xmin, xmax));
 
   98   if (hLiveTime == NULL) {
 
   99     FATAL(
"File " << inputFile << 
" does not contain livetime histogram." << endl);
 
  112   TDirectory *fdir = out.mkdir(
"FIT");
 
  113   TDirectory *pdir = out.mkdir(
"MUL"); 
 
  116   for (
int bin = 2; bin <= hLiveTime->GetNbinsX(); bin++) { 
 
  118     TString prefix = hLiveTime->GetXaxis()->GetBinLabel(bin);
 
  120     DEBUG(
"Processing data from " << prefix << endl);
 
  122     double T = hLiveTime->GetBinContent(bin);
 
  124     TString h1D_label = prefix + TString(
"_P" );
 
  125     TString h2D_label = prefix + TString(
"_HT");
 
  129       TH2D* h1D = (TH2D*) in->Get(h1D_label);
 
  130       TH2D* h2D = (TH2D*) in->Get(h2D_label);
 
  144         TDirectory* cdir = fdir->mkdir(h2D_label); cdir->cd();     
 
  148           int Mbin = h2D->GetXaxis()->FindBin(M);
 
  150           TH1D* hI = h2D->ProjectionY(h2D_label + Form(
"_%d", M), Mbin, 
NUMBER_OF_PMTS);
 
  154           if (hI->GetEntries() > 0) {
 
  156             const double W = (hI->GetXaxis()->GetXmax() - hI->GetXaxis()->GetXmin()); 
 
  157             const double N = hI->GetNbinsX();
 
  158             const double V = W / N;
 
  159             const double minRMS = 0.1;
 
  161             double inclusiveCountVal = 0, inclusiveCountErr = 0;
 
  163             if (hI->GetRMS() > minRMS) {
 
  167               TF1 f1(
"f1", 
"[0]*exp(-0.5*(x-[1])*(x-[1])/([2]*[2]))/(TMath::Sqrt(2*TMath::Pi())*[2]) + [3]");
 
  169               f1.SetParameter(0, hI->GetMaximum());
 
  170               f1.SetParameter(1, hI->GetMean());
 
  171               f1.SetParameter(2, hI->GetRMS() * 0.25);
 
  172               f1.SetParameter(3, hI->GetMinimum());
 
  174               hI->Fit(&f1, option.c_str(), 
"same");
 
  176               double sg_v = f1.GetParameter(0);
 
  177               double sg_e = f1.GetParError( 0);
 
  179               double bg_v = f1.GetParameter(3);
 
  180               double bg_e = f1.GetParError( 3);
 
  183               if (bg_v / bg_e <= 2.0) { bg_v = bg_e = 0; }
 
  184               if (sg_v / sg_e <= 2.0) { sg_v = sg_e = 0; }
 
  186               double integral = hI->GetSumOfWeights();
 
  190                 inclusiveCountVal = V * (integral - (bg_v * N));
 
  191                 inclusiveCountErr = V * bg_e * N;
 
  195                 inclusiveCountErr = sg_e;
 
  196                 inclusiveCountVal = sg_v;
 
  203               hI->Fit(&f1, option.c_str(), 
"same");         
 
  207             if (inclusiveCountVal <= 0) { inclusiveCountVal = 0; }
 
  219             int bin = HTF[h2D_label]->FindBin(M);
 
  221             HTF[h2D_label]->SetBinContent(bin, inclusiveCountVal);
 
  223             double binError = sqrt(inclusiveCountVal + pow(inclusiveCountErr, 2));
 
  225             HTF[h2D_label]->SetBinError(bin, binError);
 
  231             double exclusiveCountVal = 0;
 
  234               exclusiveCountVal = inclusiveCountVal;
 
  236               int prevBin = HTF[h2D_label]->GetXaxis()->FindBin(M+1);
 
  237               exclusiveCountVal = inclusiveCountVal - HTF[h2D_label]->GetBinContent(prevBin); 
 
  240             HTFE[h2D_label]->SetBinContent(HTFE[h2D_label]->FindBin(M), exclusiveCountVal);
 
  248         ERROR(
"Histogram " << h2D_label << 
" not found, skipping DOM." << endl);
 
  253       HTFE[h2D_label]->Sumw2();
 
  255       HTF[h2D_label ]->Scale(1.0 / T);
 
  256       HTFE[h2D_label]->Scale(1.0 / T);
 
  261   fdir = out.mkdir(
"HTF" ); fdir->cd();
 
  265   fdir = out.mkdir(
"HTFE"); fdir->cd();