Diana Software
QCalibrationParameters.cc
Go to the documentation of this file.
3 #include <sstream>
4 
5 using std::stringstream;
6 using std::vector;
7 using std::endl;
8 using std::cout;
9 using std::string;
10 
12 
14 {
15  Clear();
16 }
18 {
19  fFunction.Clear();
20  fSource.clear();
21  fResiduals.clear();
22  fChisquareNdf = 0.;
23  fSourceRuns.clear();
24 }
25 
27 {
29 
30  // fit function
31  o<<"fFunction.fName"<<"\t"<<fFunction.GetName()<<endl;
32  o<<"fFunction.fTitle"<<"\t"<<fFunction.GetTitle()<<endl;
33  o<<"fFunction.fNpar"<<"\t"<<fFunction.GetNpar()<<endl;
34  for(Int_t i=0; i<fFunction.GetNpar(); i++) {
35  o<<"fFunction.fPar["<<i<<"]\t";
36  o<<fFunction.GetParameter(i)<<" ";
37  o<<fFunction.GetParError(i)<<endl;
38  }
39  o<<"fFunction.fChisquare"<<"\t"<<fFunction.GetChisquare()<<endl;
40  o<<"fChisquareNdf"<<"\t"<<fChisquareNdf<<endl;
41 
42  // source
43  o<<"fSource"<<"\t"<<fSource<<endl;
44 
45  // residuals
46  o<<"fResiduals.fSize"<<"\t"<<fResiduals.size()<<endl;
47  for(size_t i =0; i < fResiduals.size(); i++) {
48  o<<"fResiduals["<<i<<"]\t";
49  o<<fResiduals[i].PeakEnergy<<" ";
50  o<<fResiduals[i].Residual<<" ";
51  o<<fResiduals[i].ErrorResidual<<endl;
52  }
53 
54  // source runs
55  o<<"fSourceRuns.size"<<"\t"<<fSourceRuns.size()<<endl;
56 
57  if(fSourceRuns.empty()) return err;
58 
59  for(size_t j=0; j<fSourceRuns.size(); j++) {
60  o<<"fSourceRuns["<<j<<"]"<<"\t"<<fSourceRuns[j]<<"\t"<< endl;
61  }
62 
63  return err;
64 }
65 
67 {
69 
70  std::string tag, name, formula, source;
71  int npar, nres, size, run;
72  Double_t chisq, chisqndf;
73  Double_t par, par_err;
74  Double_t ene, res, res_err;
75 
76  // fit function
77  ob >> tag >> name;
78  if(tag != "fFunction.fName") {
80  err.SetDescription("Expected tag fFunction.fName");
81  return err;
82  }
83  ob >> tag >> formula;
84  if(tag != "fFunction.fTitle") {
86  err.SetDescription("Expected tag fFunction.fTitle");
87  return err;
88  }
89  ob >> tag >> npar;
90  if(tag != "fFunction.fNpar") {
92  err.SetDescription("Expected tag fFunction.fNpar");
93  return err;
94 }
95 
96  TF1 f(name.c_str(),formula.c_str());
97  fFunction = f;
98 
99  for(Int_t i=0; i<npar; i++) {
100  ob >> tag >> par >> par_err;
101  if(tag != Form("%s%d%s","fFunction.fPar[",i,"]")) {
103  err.SetDescription("Expected tag fFunction.fPar");
104  return err;
105 }
106  fFunction.SetParameter(i,par);
107  fFunction.SetParError(i,par_err);
108  }
109 
110  ob >> tag >> chisq;
111  if(tag != "fFunction.fChisquare") {
113  err.SetDescription("Expected tag fFunction.fChisquare");
114  return err;
115 }
116  fFunction.SetChisquare(chisq);
117 
118  ob >> tag >> chisqndf;
119  if(tag != "fChisquareNdf") {
121  err.SetDescription("Expected tag fChisquareNdf");
122  return err;
123 }
124  fChisquareNdf = chisqndf;
125 
126  // source
127  ob >> tag >> source;
128  if(tag != "fSource") {
130  err.SetDescription("Expected tag fSource");
131  return err;
132  }
133  fSource = source;
134 
135  // residuals
136  fResiduals.clear();
137  ob >> tag >> nres;
138  if(tag != "fResiduals.fSize") {
140  err.SetDescription("Expected tag fResiduals");
141  return err;
142  }
143  fResiduals.resize(nres);
144 
145  for(Int_t i=0; i<nres; i++) {
146  ob >> tag >> ene >> res >> res_err;
147  stringstream tagstr;
148  tagstr<<"fResiduals["<<i<<"]";
149  if(tag != tagstr.str()) {
151  err.SetDescription(string("Expected tag ")+tagstr.str());
152  return err;
153  }
154  fResiduals[i].PeakEnergy = ene;
155  fResiduals[i].Residual = res;
156  fResiduals[i].ErrorResidual = res_err;
157  }
158 
159  // read fSource Runs
160  ob >> tag >> size;
161  if(tag != "fSourceRuns.size") {
163  err.SetDescription("Expected tag fSourceRuns.size");
164  return err;
165  }
166 
167  char s[50];
168 
169  for(Int_t i=0; i<size; i++) {
170  ob >> tag >> run;
171  snprintf(s,50,"fSourceRuns[%d]",i);
172  if(tag != s) {
174  err.SetDescription("Expected tag fSourceRuns");
175  return err;
176  }
177  fSourceRuns.push_back(run);
178  }
179 
180  return err;
181 }
err
Definition: CheckOF.C:114
QObjectImp(QCalibrationParameters)
@ QERR_UNKNOWN_ERR
Definition: QError.hh:108
@ QERR_SUCCESS
Definition: QError.hh:27
object containing calibration data (function, coefficients, source and residuals) and run numbers of ...
std::vector< int > fSourceRuns
QError ReadFromStream(std::istream &ob)
std::vector< QCalibrationResiduals > fResiduals
QError WriteOnStream(std::ostream &o) const
error class with error type and description
Definition: QError.hh:115