13 #include "TFitResult.h" 
   32   const char* h2_t           =  
"h2";
 
   34   const char* gauss_t        =  
"Gauss";           
 
   35   const char* landau_t       =  
"Landau";          
 
   36   const char* emg_t          =  
"EMG";             
 
   37   const char* breitwigner_t  =  
"BreitWigner";     
 
   46 int main(
int argc, 
char **argv)
 
   54   bool            overwriteDetector;
 
   64     JParser<> zap(
"Program to fit time-residuals histogram in output of JCalibrateMuon.cc.");
 
   66     zap[
'f'] = 
make_field(inputFile,         
"input files (output from JCalibrateMuon).");
 
   68     zap[
'a'] = 
make_field(detectorFile,      
"detector file.");
 
   69     zap[
'A'] = 
make_field(overwriteDetector, 
"overwrite detector file provided through '-a' with correct time offsets.");
 
   70     zap[
'F'] = 
make_field(
function,          
"fit function")                                                   = gauss_t, landau_t, emg_t, breitwigner_t;
 
   72     zap[
'O'] = 
make_field(option,            
"ROOT fit option, see TH1::Fit.")                                 = 
"";
 
   74     zap[
'W'] = 
make_field(WMin,              
"minimal histogram contents.")                                    = 100.0;
 
   79   catch(
const exception &error) {
 
   80     FATAL(error.what() << endl);
 
   86   if (!T_ns.is_valid()) {
 
   87     FATAL(
"Invalid fit range [ns] " << T_ns << endl);
 
   99   if (option.find(
'S') == string::npos) { option += 
'S'; }
 
  107     NOTICE(
"Processing " << *i << endl);
 
  109     TFile 
in(i->c_str(), 
"exist");
 
  112       FATAL(
"File " << *i << 
" not opened." << endl);
 
  115     TH2D* p = 
dynamic_cast<TH2D*
>(
in.Get(h2_t));
 
  118       FATAL(
"File " << *i << 
" has no histogram <" << h2_t << 
">." << endl);
 
  122       h2 = (TH2D*) p->Clone();
 
  132     FATAL(
"No histogram <" << h2_t << 
">." << endl);
 
  144     result_type(
double value,
 
  161   const TAxis* x_axis = h2->GetXaxis();
 
  162   const TAxis* y_axis = h2->GetYaxis();
 
  164   TH1D h0(
"h0", NULL, x_axis->GetNbins(), -0.5, x_axis->GetNbins() - 0.5);
 
  165   TH1D hc(
"hc", NULL, x_axis->GetNbins(), -0.5, x_axis->GetNbins() - 0.5);
 
  166   TH1D hq(
"hq", NULL, x_axis->GetNbins(), -0.5, x_axis->GetNbins() - 0.5);
 
  171   for (
int ix = 1; ix <= x_axis->GetNbins(); ++ix) {
 
  173     if (
detector[ix - 1].getFloor() == 0) {
 
  177     TH1D 
h1(
MAKE_CSTRING(
detector[ix - 1].getID() << 
".1D"), NULL, y_axis->GetNbins(), y_axis->GetXmin(), y_axis->GetXmax());
 
  183     Double_t sigma  =  4.5;       
 
  186     for (
int iy = 1; iy <= y_axis->GetNbins(); ++iy) {
 
  188       h1.SetBinContent(iy,      h2->GetBinContent(ix,iy));
 
  189       h1.SetBinError  (iy, sqrt(h2->GetBinContent(ix,iy)));
 
  191       const Double_t x = 
h1.GetBinCenter (iy);
 
  192       const Double_t y = 
h1.GetBinContent(iy);
 
  204       WARNING(
"Not enough entries for slice " << ix << 
' ' << W << 
"; skip fit." << endl);
 
  210     const Double_t xmin = x0 + T_ns.getLowerLimit();
 
  211     const Double_t xmax = x0 + T_ns.getUpperLimit();
 
  216     if        (
function == gauss_t) {
 
  218       f1 = 
new TF1(
function.c_str(), 
"[0]*TMath::Gaus(x,[1],[2])");
 
  220       f1->SetParameter(0, ymax);
 
  221       f1->SetParameter(1, x0);
 
  222       f1->SetParameter(2, sigma);
 
  224     } 
else if (
function == landau_t) {
 
  226       f1 = 
new TF1(
function.c_str(), 
"[0]*TMath::Landau(x,[1],[2])");
 
  228       f1->SetParameter(0, ymax);
 
  229       f1->SetParameter(1, x0);
 
  230       f1->SetParameter(2, sigma);
 
  232     } 
else if (
function == emg_t) {
 
  234       f1 = 
new TF1(
function.c_str(), 
"[0]*TMath::Exp(0.5*[3]*(2.0*[1]+[3]*[2]*[2]-2.0*x))*TMath::Erfc(([1]+[3]*[2]*[2]-x)/(TMath::Sqrt(2.0)*[2]))");
 
  236       f1->SetParameter(0, ymax);
 
  237       f1->SetParameter(1, x0 - sigma);
 
  238       f1->SetParameter(2, sigma);
 
  239       f1->SetParameter(3, 0.04);
 
  241     } 
else if (
function == breitwigner_t) {
 
  243       f1 = 
new TF1(
function.c_str(), 
"(x <= [1])*[0]*[2]*TMath::BreitWigner(x,[1],[2])+(x > [1])*[0]*[3]*TMath::BreitWigner(x,[1],[3])");
 
  245       f1->SetParameter(0, ymax);
 
  246       f1->SetParameter(1, x0);
 
  247       f1->SetParameter(2, 15.0);
 
  248       f1->SetParameter(3, 25.0);
 
  252       FATAL(
"Unknown fit function " << 
function << endl);
 
  256     DEBUG(
"Start values:" << endl);
 
  258     for (
int i = 0; i != f1->GetNpar(); ++i) {
 
  259       DEBUG(left << setw(12) << f1->GetParName  (i) << 
' ' << 
 
  260             SCIENTIFIC(12,5) << f1->GetParameter(i) << endl);
 
  265     TFitResultPtr 
result = 
h1.Fit(f1, option.c_str(), 
"same", xmin, xmax);
 
  269            << setw(4)    << ix                    << 
' ' 
  270            << setw(16)   << 
h1.GetName()          << 
' ' 
  271            << 
FIXED(7,3) << f1->GetParameter(1)   << 
" +/- "  
  272            << 
FIXED(7,3) << f1->GetParError(1)    << 
' '  
  273            << 
FIXED(7,3) << result->Chi2()        << 
'/' 
  274            << result->Ndf()                       << 
' ' 
  275            << (result->IsValid() ? 
"" : 
"failed") << endl;
 
  278     if (result->IsValid()) {
 
  279       zmap[ix] = result_type(f1->GetParameter(1), f1->GetParError (1)); 
 
  282     if (result->Ndf() > 0) {
 
  283       hc.SetBinContent(ix, result->Chi2() / result->Ndf());
 
  285     hq.SetBinContent(ix, result->IsValid() ? 1.0 : 0.0);
 
  299     for (map_type::const_iterator i = zmap.begin(); i != zmap.end(); ++i) {
 
  300       t0 += i->second.value;
 
  305     NOTICE(
"Average time offset [ns] " << 
FIXED(7,2) << t0 << endl);
 
  307     for (map_type::iterator i = zmap.begin(); i != zmap.end(); ++i) {
 
  308       i->second.value -= t0;
 
  311     for (map_type::const_iterator i = zmap.begin(); i != zmap.end(); ++i) {
 
  312       h0.SetBinContent(i->first, i->second.value);
 
  313       h0.SetBinError  (i->first, i->second.error);
 
  322               string.getLength() + 1,
 
  323               string.getLowerLimit() - 0.5,
 
  324               string.getUpperLimit() + 0.5,
 
  329       for (map_type::const_iterator i = zmap.begin(); i != zmap.end(); ++i) {
 
  330         hi.SetBinContent(
detector[i->first - 1].getString(), 
 
  339     if (overwriteDetector) {
 
  341       NOTICE(
"Store calibration data on file " << detectorFile << endl);
 
  345       for (map_type::const_iterator i = zmap.begin(); i != zmap.end(); ++i) {
 
  347         if (E_ns(i->second.error))
 
  348           detector[i->first - 1].sub(i->second.value);
 
  350           ERROR(
"Slice " << setw(4) << i->first << 
" fit uncertainty " << 
FIXED(5,2) << i->second.error << 
" outside specified range (option -E <E_ns>)" << endl);
 
  358     NOTICE(
"No calibration results." << endl);
 
Utility class to parse command line options. 
 
int main(int argc, char *argv[])
 
JTOOLS::JRange< double > JTimeRange
Type definition for time range (unit [ns]). 
 
#define MAKE_CSTRING(A)
Make C-string. 
 
then for HISTOGRAM in h0 h1
 
Auxiliary data structure for floating point format specification. 
 
Data structure for detector geometry and calibration. 
 
I/O formatting auxiliaries. 
 
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object 
 
const array_type< JValue_t > & make_array(const JValue_t(&array)[N])
Method to create array of values. 
 
void store(const std::string &file_name, const JDetector &detector)
Store detector to output file. 
 
General purpose messaging. 
 
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. 
 
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
 
do set_variable DETECTOR_TXT $WORKDIR detector
 
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
 
Auxiliary data structure for floating point format specification.