52int main(
int argc,
char **argv)
72 JParser<> zap(
"Program to fit time-residuals histogram in output of JCalibrateMuon.cc.");
74 zap[
'f'] =
make_field(inputFile,
"input files (output from JCalibrateMuon).");
79 zap[
'T'] =
make_field(T_ns,
"ROOT fit range around maximum [ns].") = JTimeRange(-7.5,+5.0);
80 zap[
'O'] =
make_field(option,
"ROOT fit option, see TH1::Fit.") =
"";
81 zap[
'E'] =
make_field(
E_ns,
"validity range of t0 uncertainty [ns].") = JTimeRange( 0.0, 0.5);
89 catch(
const exception &error) {
94 if (!T_ns.is_valid()) {
95 FATAL(
"Invalid fit range [ns] " << T_ns <<
endl);
113 else if (
target == string_t)
116 FATAL(
"No valid target; check option -R" <<
endl);
118 if (option.find(
'S') == string::npos) { option +=
'S'; }
127 TFile in(i->c_str(),
"exist");
130 FATAL(
"File " << *i <<
" not opened." <<
endl);
133 TH2D* p =
dynamic_cast<TH2D*
>(in.Get(h2_t));
136 FATAL(
"File " << *i <<
" has no histogram <" << h2_t <<
">." <<
endl);
140 h2 = (
TH2D*) p->Clone();
150 FATAL(
"No histogram <" << h2_t <<
">." <<
endl);
162 result_type(
double value,
190 strings.size(), -0.5, strings.size() - 0.5,
191 floors.getUpperLimit(), 1 - 0.5,
floors.getUpperLimit() + 0.5);
207 const int index =
ix - 1;
208 const int id =
rpm->getID(index);
212 if (
ID != -1 &&
ID !=
id) {
227 h1.SetBinContent(
iy, h2->GetBinContent(
ix,
iy));
228 h1.SetBinError (
iy, sqrt(h2->GetBinContent(
ix,
iy)));
243 WARNING(
"Not enough entries for slice " <<
ix <<
' ' << W <<
"; skip fit." <<
endl);
250 const Double_t xmin = x0 + T_ns.getLowerLimit();
251 const Double_t xmax = x0 + T_ns.getUpperLimit();
258 f1 =
new TF1(function.c_str(),
"[0]*TMath::Gaus(x,[1],[2])");
260 f1->SetParameter(0, 0.8*
ymax);
261 f1->SetParameter(1, x0);
262 f1->SetParameter(2, sigma);
264 f1->SetParError(0, sqrt(
ymax) * 0.1);
265 f1->SetParError(1, 0.01);
266 f1->SetParError(2, 0.01);
270 f1 =
new TF1(function.c_str(),
"[0]*TMath::Landau(x,[1],[2])");
272 f1->SetParameter(0, 0.8*
ymax);
273 f1->SetParameter(1, x0);
274 f1->SetParameter(2, sigma);
276 f1->SetParError(0, sqrt(
ymax) * 0.1);
277 f1->SetParError(1, 0.01);
278 f1->SetParError(2, 0.01);
280 }
else if (function ==
emg_t) {
282 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]))");
284 f1->SetParameter(0, 0.5*
ymax);
285 f1->SetParameter(1, x0 - sigma);
286 f1->SetParameter(2, sigma);
287 f1->SetParameter(3, 0.06);
289 f1->SetParError(0, sqrt(
ymax) * 0.1);
290 f1->SetParError(1, 0.01);
291 f1->SetParError(2, 0.01);
292 f1->SetParError(3, 1.0e-4);
296 f1 =
new TF1(function.c_str(),
"(x <= [1])*[0]*[2]*TMath::BreitWigner(x,[1],[2])+(x > [1])*[0]*[3]*TMath::BreitWigner(x,[1],[3])");
298 f1->SetParameter(0, 0.8*
ymax);
299 f1->SetParameter(1, x0);
300 f1->SetParameter(2, 15.0);
301 f1->SetParameter(3, 25.0);
303 f1->SetParError(0, sqrt(
ymax) * 0.1);
304 f1->SetParError(1, 0.01);
305 f1->SetParError(2, 0.1);
306 f1->SetParError(3, 0.1);
310 FATAL(
"Unknown fit function " << function <<
endl);
316 for (
int i = 0; i != f1->GetNpar(); ++i) {
317 DEBUG(left <<
setw(12) << f1->GetParName (i) <<
' ' <<
323 TFitResultPtr result = h1.Fit(f1, option.c_str(),
"same", xmin, xmax);
325 const bool status = result->IsValid() &&
E_ns(f1->GetParError(1));
327 if (
debug >= notice_t || !result->IsValid()) {
330 <<
setw(16) << h1.GetName() <<
' '
331 <<
FIXED(7,3) << f1->GetParameter(1) <<
" +/- "
332 <<
FIXED(7,3) << f1->GetParError(1) <<
' '
333 <<
FIXED(9,2) << result->Chi2() <<
'/'
334 << result->Ndf() <<
' '
336 <<
E_ns(f1->GetParError(1)) <<
' '
337 << (status ?
"" :
"failed") <<
endl;
347 zmap[index] = result_type(f1->GetParameter(1), f1->GetParError(1));
350 if (result->Ndf() > 0) {
351 hc.SetBinContent(
ix, result->Chi2() / result->Ndf());
354 hq.SetBinContent(
ix, status ? 1.0 : 0.0);
368 for (map_type::const_iterator i = zmap.begin(); i != zmap.end(); ++i) {
369 t0 += i->second.value;
377 for (map_type::iterator i = zmap.begin(); i != zmap.end(); ++i) {
378 i->second.value -= t0;
381 for (map_type::const_iterator i = zmap.begin(); i != zmap.end(); ++i) {
382 h0.SetBinContent(i->first, i->second.value);
383 h0.SetBinError (i->first, i->second.error);
393 const JModule&
module = router.getModule(location);
394 const int index =
rpm->getIndex(
module.getID());
396 if (zmap.count(index) != 0) {
397 H2.SetBinContent(
ix,
iy, zmap[index].value);
409 for (
size_t string = 0;
string != strings.size(); ++string) {
410 for (
int floor = 1; floor <=
floors.getUpperLimit(); ++floor) {
412 const JLocation location(strings.at(
string), floor);
416 JModule&
module = detector[router.getIndex(location)];
417 const int index =
rpm->getIndex(
module.getID());
419 if (zmap.count(index) != 0) {
420 module.sub(zmap[index].value);