36int main(
int argc,
char **argv)
42 double XMIN = -0.2*PI;
43 double XMAX = +0.2*PI;
64 JParser<> zap(
"Program to fit histogram in output of JMuonCompass.cc.");
67 zap[
'f'] =
make_field(inputFile,
"input files (output from JMuonCompass).");
71 "\nUse option -AA to also correct compass calibrations.");
72 zap[
'O'] =
make_field(option,
"ROOT fit option, see TH1::Fit.") =
"";
77 catch(
const exception &error) {
96 if (option.find(
'S') == string::npos) { option +=
'S'; }
105 TFile in(i->c_str(),
"exist");
108 FATAL(
"File " << *i <<
" not opened." <<
endl);
111 TH2D* p =
dynamic_cast<TH2D*
>(in.Get(h2_t));
114 FATAL(
"File " << *i <<
" has no histogram <" << h2_t <<
">." <<
endl);
118 h2 = (
TH2D*) p->Clone();
128 FATAL(
"No histogram <" << h2_t <<
">." <<
endl);
140 result_type(
double value,
166 strings.size(), -0.5, strings.size() - 0.5,
167 floors.getUpperLimit(), 1 - 0.5,
floors.getUpperLimit() + 0.5);
184 const int index =
ix - 1;
185 const JModule&
module = detector[index];
187 if (
module.getFloor() == 0) {
203 h1.SetBinContent(
iy, h2->GetBinContent(
ix,
iy));
204 h1.SetBinError (
iy, h2->GetEntries() * 1.0e-7 * parameters.FACTOR);
217 if (
ymax -
ymin >= parameters.YMIN) {
219 Double_t xmin = x0 + parameters.XMIN;
220 Double_t xmax = x0 + parameters.XMAX;
225 if (xmax >
y_axis->GetXmax()) {
Rx = -PI; }
245 if (i < 1) { i += (
Int_t) (2.0*PI /
dx); }
248 h1.SetBinContent(i, h2->GetBinContent(
ix,
iy));
249 h1.SetBinError (i, h2->GetEntries() * 1.0e-7 * parameters.FACTOR);
254 if (xmax >
y_axis->GetXmax()) { xmax =
y_axis->GetXmax(); xmin = xmax - 0.8*PI; }
256 TF1* f1 =
new TF1(
"f1",
"[0] - [1]*cos(x - [2])");
258 f1->SetParameter(0, 0.5 * (
ymin +
ymax));
259 f1->SetParameter(1, 0.5 * (
ymax -
ymin));
260 f1->SetParameter(2, x0);
262 f1->SetParError(0, 0.01*(
ymin+
ymax));
263 f1->SetParError(1, 0.01*(
ymin+
ymax));
264 f1->SetParError(2, 0.05);
268 for (
int i = 0; i != f1->GetNpar(); ++i) {
269 DEBUG(left <<
setw(12) << f1->GetParName (i) <<
' ' <<
275 TFitResultPtr result = h1.Fit(f1, option.c_str(),
"same", xmin, xmax);
277 const bool status = result->IsValid();
282 f1->SetParameter(2, f1->GetParameter(2) -
Rx);
285 if (
debug >= notice_t || !result->IsValid()) {
288 <<
setw(16) << h1.GetName() <<
' '
289 <<
FIXED(7,3) << f1->GetParameter(2) <<
" +/- "
290 <<
FIXED(7,3) << f1->GetParError(2) <<
" [rad] "
291 <<
FIXED(9,2) << result->Chi2() <<
'/'
292 << result->Ndf() <<
' '
294 << (status ?
"" :
"failed") <<
endl;
298 zmap[index] = result_type(f1->GetParameter(2), f1->GetParError(2));
310 H2d .SetBinContent(
H2.ix,
H2.iy, f1->GetParameter(2));
312 if (result->Ndf() > 0) {
313 H2c->SetBinContent(
H2.ix,
H2.iy, result->Chi2() / result->Ndf());
316 H2q->SetBinContent(
H2.ix,
H2.iy, status ? +1.0 : -1.0);
329 for (map_type::const_iterator i = zmap.begin(); i != zmap.end(); ++i) {
330 h0.SetBinContent(i->first, i->second.value);
331 h0.SetBinError (i->first, i->second.error);
340 for (map_type::const_iterator i = zmap.begin(); i != zmap.end(); ++i) {
342 JModule&
module = detector[i->first];
343 const JVector3D center =
module.getPosition();
347 module.rotate(JRotation3Z(i->second.value));
352 module.setQuaternion(module.getQuaternion() * JQuaternion3Z(i->second.value));