changed variables to comply with the ROOT standards. Error messages now sent to stderr rather than stdout

This commit is contained in:
nemu
2009-10-30 08:29:27 +00:00
parent e14feae99d
commit 2a03bb7f61
34 changed files with 1822 additions and 1773 deletions

View File

@ -59,7 +59,7 @@ PRunAsymmetry::PRunAsymmetry() : PRunBase()
* \param msrInfo pointer to the msr info structure
* \param runNo number of the run of the msr-file
*/
PRunAsymmetry::PRunAsymmetry(PMsrHandler *msrInfo, PRunDataHandler *rawData, unsigned int runNo, EPMusrHandleTag tag) : PRunBase(msrInfo, rawData, runNo, tag)
PRunAsymmetry::PRunAsymmetry(PMsrHandler *msrInfo, PRunDataHandler *rawData, UInt_t runNo, EPMusrHandleTag tag) : PRunBase(msrInfo, rawData, runNo, tag)
{
// check if alpha and/or beta is fixed --------------------
@ -67,31 +67,34 @@ PRunAsymmetry::PRunAsymmetry(PMsrHandler *msrInfo, PRunDataHandler *rawData, uns
// check if alpha is given
if (fRunInfo->fAlphaParamNo == -1) { // no alpha given
cout << endl << "PRunAsymmetry::PRunAsymmetry(): no alpha parameter given! This is needed for an asymmetry fit!";
cerr << endl << "PRunAsymmetry::PRunAsymmetry(): **ERROR** no alpha parameter given! This is needed for an asymmetry fit!";
cerr << endl;
fValid = false;
return;
}
// check if alpha parameter is within proper bounds
if ((fRunInfo->fAlphaParamNo < 0) || (fRunInfo->fAlphaParamNo > (int)param->size())) {
cout << endl << "PRunAsymmetry::PRunAsymmetry(): alpha parameter no = " << fRunInfo->fAlphaParamNo;
cout << endl << " This is out of bound, since there are only " << param->size() << " parameters.";
if ((fRunInfo->fAlphaParamNo < 0) || (fRunInfo->fAlphaParamNo > (Int_t)param->size())) {
cerr << endl << "PRunAsymmetry::PRunAsymmetry(): **ERROR** alpha parameter no = " << fRunInfo->fAlphaParamNo;
cerr << endl << " This is out of bound, since there are only " << param->size() << " parameters.";
cerr << endl;
fValid = false;
return;
}
// check if alpha is fixed
bool alphaFixedToOne = false;
Bool_t alphaFixedToOne = false;
//cout << endl << ">> alpha = " << (*param)[fRunInfo->fAlphaParamNo-1].fValue << ", " << (*param)[fRunInfo->fAlphaParamNo-1].fStep;
if (((*param)[fRunInfo->fAlphaParamNo-1].fStep == 0.0) &&
((*param)[fRunInfo->fAlphaParamNo-1].fValue == 1.0))
alphaFixedToOne = true;
// check if beta is given
bool betaFixedToOne = false;
Bool_t betaFixedToOne = false;
if (fRunInfo->fBetaParamNo == -1) { // no beta given hence assuming beta == 1
betaFixedToOne = true;
} else if ((fRunInfo->fBetaParamNo < 0) || (fRunInfo->fBetaParamNo > (int)param->size())) { // check if beta parameter is within proper bounds
cout << endl << "PRunAsymmetry::PRunAsymmetry(): beta parameter no = " << fRunInfo->fBetaParamNo;
cout << endl << " This is out of bound, since there are only " << param->size() << " parameters.";
} else if ((fRunInfo->fBetaParamNo < 0) || (fRunInfo->fBetaParamNo > (Int_t)param->size())) { // check if beta parameter is within proper bounds
cerr << endl << "PRunAsymmetry::PRunAsymmetry(): **ERROR** beta parameter no = " << fRunInfo->fBetaParamNo;
cerr << endl << " This is out of bound, since there are only " << param->size() << " parameters.";
cerr << endl;
fValid = false;
return;
} else { // check if beta is fixed
@ -140,22 +143,22 @@ PRunAsymmetry::~PRunAsymmetry()
*
* \param par parameter vector iterated by minuit
*/
double PRunAsymmetry::CalcChiSquare(const std::vector<double>& par)
Double_t PRunAsymmetry::CalcChiSquare(const std::vector<Double_t>& par)
{
double chisq = 0.0;
double diff = 0.0;
double asymFcnValue = 0.0;
double a, b, f;
Double_t chisq = 0.0;
Double_t diff = 0.0;
Double_t asymFcnValue = 0.0;
Double_t a, b, f;
// calculate functions
for (int i=0; i<fMsrInfo->GetNoOfFuncs(); i++) {
for (Int_t i=0; i<fMsrInfo->GetNoOfFuncs(); i++) {
fFuncValues[i] = fMsrInfo->EvalFunc(fMsrInfo->GetFuncNo(i), fRunInfo->fMap, par);
}
// calculate chisq
double time;
for (unsigned int i=0; i<fData.GetValue()->size(); i++) {
time = fData.GetDataTimeStart() + (double)i*fData.GetDataTimeStep();
Double_t time;
for (UInt_t i=0; i<fData.GetValue()->size(); i++) {
time = fData.GetDataTimeStart() + (Double_t)i*fData.GetDataTimeStep();
if ((time>=fFitStartTime) && (time<=fFitStopTime)) {
switch (fAlphaBetaTag) {
case 1: // alpha == 1, beta == 1
@ -199,7 +202,7 @@ double PRunAsymmetry::CalcChiSquare(const std::vector<double>& par)
*
* \param par parameter vector iterated by minuit
*/
double PRunAsymmetry::CalcMaxLikelihood(const std::vector<double>& par)
Double_t PRunAsymmetry::CalcMaxLikelihood(const std::vector<Double_t>& par)
{
cout << endl << "PRunSingleHisto::CalcMaxLikelihood(): not implemented yet ..." << endl;
@ -216,22 +219,22 @@ double PRunAsymmetry::CalcMaxLikelihood(const std::vector<double>& par)
void PRunAsymmetry::CalcTheory()
{
// feed the parameter vector
std::vector<double> par;
std::vector<Double_t> par;
PMsrParamList *paramList = fMsrInfo->GetMsrParamList();
for (unsigned int i=0; i<paramList->size(); i++)
for (UInt_t i=0; i<paramList->size(); i++)
par.push_back((*paramList)[i].fValue);
// calculate functions
for (int i=0; i<fMsrInfo->GetNoOfFuncs(); i++) {
for (Int_t i=0; i<fMsrInfo->GetNoOfFuncs(); i++) {
fFuncValues[i] = fMsrInfo->EvalFunc(fMsrInfo->GetFuncNo(i), fRunInfo->fMap, par);
}
// calculate asymmetry
double asymFcnValue = 0.0;
double a, b, f;
double time;
for (unsigned int i=0; i<fData.GetValue()->size(); i++) {
time = fData.GetDataTimeStart() + (double)i*fData.GetDataTimeStep();
Double_t asymFcnValue = 0.0;
Double_t a, b, f;
Double_t time;
for (UInt_t i=0; i<fData.GetValue()->size(); i++) {
time = fData.GetDataTimeStart() + (Double_t)i*fData.GetDataTimeStep();
switch (fAlphaBetaTag) {
case 1: // alpha == 1, beta == 1
asymFcnValue = fTheory->Func(time, par, fFuncValues);
@ -274,7 +277,7 @@ void PRunAsymmetry::CalcTheory()
* (b_i^{\rm c})^2 (\Delta f_i^{\rm c})^2 +
* (\Delta b_i^{\rm c})^2 (f_i^{\rm c})^2\right]^{1/2}\f]
*/
bool PRunAsymmetry::PrepareData()
Bool_t PRunAsymmetry::PrepareData()
{
//cout << endl << "in PRunAsymmetry::PrepareData(): will feed fData" << endl;
@ -282,7 +285,8 @@ bool PRunAsymmetry::PrepareData()
// get the correct run
PRawRunData *runData = fRawData->GetRunData(fRunInfo->fRunName[0]);
if (!runData) { // run not found
cout << endl << "PRunAsymmetry::PrepareData(): Couldn't get run " << fRunInfo->fRunName[0].Data() << "!";
cerr << endl << "PRunAsymmetry::PrepareData(): **ERROR** Couldn't get run " << fRunInfo->fRunName[0].Data() << "!";
cerr << endl;
return false;
}
@ -304,7 +308,8 @@ bool PRunAsymmetry::PrepareData()
fT0s.push_back(runData->GetT0(fRunInfo->fForwardHistoNo-1)); // forward t0
fT0s.push_back(runData->GetT0(fRunInfo->fBackwardHistoNo-1)); // backward t0
} else { // t0's are neither in the run data nor in the msr-file -> not acceptable!
cout << endl << "PRunAsymmetry::PrepareData(): NO t0's found, neither in the run data nor in the msr-file!";
cerr << endl << "PRunAsymmetry::PrepareData(): **ERROR** NO t0's found, neither in the run data nor in the msr-file!";
cerr << endl;
return false;
}
} else { // t0's in the msr-file
@ -312,18 +317,18 @@ bool PRunAsymmetry::PrepareData()
if (runData->GetT0s().size() != 0) {
// compare t0's of the msr-file with the one in the data file
if (fabs(fRunInfo->fT0[0]-runData->GetT0(fRunInfo->fForwardHistoNo-1))>5.0) { // given in bins!!
cout << endl << "PRunAsymmetry::PrepareData(): **WARNING**: forward histo";
cout << endl << " t0 from the msr-file is " << fRunInfo->fT0[0];
cout << endl << " t0 from the data file is " << runData->GetT0(fRunInfo->fForwardHistoNo-1);
cout << endl << " This is quite a deviation! Is this done intentionally??";
cout << endl;
cerr << endl << "PRunAsymmetry::PrepareData(): **WARNING**: forward histo";
cerr << endl << " t0 from the msr-file is " << fRunInfo->fT0[0];
cerr << endl << " t0 from the data file is " << runData->GetT0(fRunInfo->fForwardHistoNo-1);
cerr << endl << " This is quite a deviation! Is this done intentionally??";
cerr << endl;
}
if (fabs(fRunInfo->fT0[1]-runData->GetT0(fRunInfo->fBackwardHistoNo-1))>5.0) { // given in bins!!
cout << endl << "PRunAsymmetry::PrepareData(): **WARNING**: backward histo";
cout << endl << " t0 from the msr-file is " << fRunInfo->fT0[1];
cout << endl << " t0 from the data file is " << runData->GetT0(fRunInfo->fBackwardHistoNo-1);
cout << endl << " This is quite a deviation! Is this done intentionally??";
cout << endl;
cerr << endl << "PRunAsymmetry::PrepareData(): **WARNING**: backward histo";
cerr << endl << " t0 from the msr-file is " << fRunInfo->fT0[1];
cerr << endl << " t0 from the data file is " << runData->GetT0(fRunInfo->fBackwardHistoNo-1);
cerr << endl << " This is quite a deviation! Is this done intentionally??";
cerr << endl;
}
}
fT0s.push_back(fRunInfo->fT0[0]); // forward t0
@ -331,17 +336,17 @@ bool PRunAsymmetry::PrepareData()
}
// check if post pile up data shall be used
unsigned int histoNo[2]; // forward/backward
UInt_t histoNo[2]; // forward/backward
histoNo[0] = fRunInfo->fForwardHistoNo-1;
histoNo[1] = fRunInfo->fBackwardHistoNo-1;
// first check if forward/backward given in the msr-file are valid
if ((runData->GetNoOfHistos() < histoNo[0]+1) || (histoNo[0] < 0) ||
(runData->GetNoOfHistos() < histoNo[1]+1) || (histoNo[1] < 0)) {
cout << endl << "PRunAsymmetry::PrepareData(): **PANIC ERROR**:";
cout << endl << " forward/backward histo no found = " << histoNo[0]+1;
cout << ", " << histoNo[1]+1 << ", but there are only " << runData->GetNoOfHistos() << " histo sets!?!?";
cout << endl << " Will quit :-(";
cout << endl;
cerr << endl << "PRunAsymmetry::PrepareData(): **PANIC ERROR**:";
cerr << endl << " forward/backward histo no found = " << histoNo[0]+1;
cerr << ", " << histoNo[1]+1 << ", but there are only " << runData->GetNoOfHistos() << " histo sets!?!?";
cerr << endl << " Will quit :-(";
cerr << endl;
return false;
}
@ -355,16 +360,17 @@ bool PRunAsymmetry::PrepareData()
// check if there are runs to be added to the current one
if (fRunInfo->fRunName.size() > 1) { // runs to be added present
PRawRunData *addRunData;
for (unsigned int i=1; i<fRunInfo->fRunName.size(); i++) {
for (UInt_t i=1; i<fRunInfo->fRunName.size(); i++) {
// get run to be added to the main one
addRunData = fRawData->GetRunData(fRunInfo->fRunName[i]);
if (addRunData == 0) { // couldn't get run
cout << endl << "PRunAsymmetry::PrepareData(): **ERROR** Couldn't get addrun " << fRunInfo->fRunName[i].Data() << "!";
cerr << endl << "PRunAsymmetry::PrepareData(): **ERROR** Couldn't get addrun " << fRunInfo->fRunName[i].Data() << "!";
cerr << endl;
return false;
}
// get T0's of the to be added run
int t0Add[2] = {0, 0};
Int_t t0Add[2] = {0, 0};
// check if the t0's are given in the msr-file
if (2*i+1 >= fRunInfo->fT0.size()) { // t0's are NOT in the msr-file
// check if the t0's are in the data file
@ -374,7 +380,8 @@ bool PRunAsymmetry::PrepareData()
t0Add[0] = addRunData->GetT0(fRunInfo->fForwardHistoNo-1); // forward t0
t0Add[1] = addRunData->GetT0(fRunInfo->fBackwardHistoNo-1); // backward t0
} else { // t0's are neither in the run data nor in the msr-file -> not acceptable!
cout << endl << "PRunAsymmetry::PrepareData(): NO t0's found, neither in the addrun (" << fRunInfo->fRunName[i].Data() << ") data nor in the msr-file!";
cerr << endl << "PRunAsymmetry::PrepareData(): **ERROR** NO t0's found, neither in the addrun (" << fRunInfo->fRunName[i].Data() << ") data nor in the msr-file!";
cerr << endl;
return false;
}
} else { // t0's in the msr-file
@ -383,38 +390,38 @@ bool PRunAsymmetry::PrepareData()
t0Add[0] = fRunInfo->fT0[2*i];
t0Add[1] = fRunInfo->fT0[2*i+1];
} else {
cout << endl << "PRunAsymmetry::PrepareData(): **WARNING** NO t0's found, neither in the addrun data (";
cout << fRunInfo->fRunName[i].Data();
cout << "), nor in the msr-file! Will try to use the T0 of the run data (";
cout << fRunInfo->fRunName[i].Data();
cout << ") without any warranty!";
cerr << endl << "PRunAsymmetry::PrepareData(): **WARNING** NO t0's found, neither in the addrun data (";
cerr << fRunInfo->fRunName[i].Data();
cerr << "), nor in the msr-file! Will try to use the T0 of the run data (";
cerr << fRunInfo->fRunName[i].Data();
cerr << ") without any warranty!";
t0Add[0] = fRunInfo->fT0[0];
t0Add[1] = fRunInfo->fT0[1];
}
if (addRunData->GetT0s().size() != 0) {
// compare t0's of the msr-file with the one in the data file
if (fabs(t0Add[0]-addRunData->GetT0(fRunInfo->fForwardHistoNo-1))>5.0) { // given in bins!!
cout << endl << "PRunAsymmetry::PrepareData(): **WARNING**: forward histo";
cout << endl << " t0 from the msr-file is " << fRunInfo->fT0[2*i];
cout << endl << " t0 from the data file is " << addRunData->GetT0(fRunInfo->fForwardHistoNo-1);
cout << endl << " This is quite a deviation! Is this done intentionally??";
cout << endl << " addrun: " << fRunInfo->fRunName[i].Data();
cout << endl;
cerr << endl << "PRunAsymmetry::PrepareData(): **WARNING**: forward histo";
cerr << endl << " t0 from the msr-file is " << fRunInfo->fT0[2*i];
cerr << endl << " t0 from the data file is " << addRunData->GetT0(fRunInfo->fForwardHistoNo-1);
cerr << endl << " This is quite a deviation! Is this done intentionally??";
cerr << endl << " addrun: " << fRunInfo->fRunName[i].Data();
cerr << endl;
}
if (fabs(t0Add[1]-addRunData->GetT0(fRunInfo->fBackwardHistoNo-1))>5.0) { // given in bins!!
cout << endl << "PRunAsymmetry::PrepareData(): **WARNING**: backward histo";
cout << endl << " t0 from the msr-file is " << fRunInfo->fT0[2*i+1];
cout << endl << " t0 from the data file is " << addRunData->GetT0(fRunInfo->fBackwardHistoNo-1);
cout << endl << " This is quite a deviation! Is this done intentionally??";
cout << endl << " addrun: " << fRunInfo->fRunName[i].Data();
cout << endl;
cerr << endl << "PRunAsymmetry::PrepareData(): **WARNING**: backward histo";
cerr << endl << " t0 from the msr-file is " << fRunInfo->fT0[2*i+1];
cerr << endl << " t0 from the data file is " << addRunData->GetT0(fRunInfo->fBackwardHistoNo-1);
cerr << endl << " This is quite a deviation! Is this done intentionally??";
cerr << endl << " addrun: " << fRunInfo->fRunName[i].Data();
cerr << endl;
}
}
}
// add forward run
UInt_t addRunSize = addRunData->GetDataBin(histoNo[0])->size();
for (unsigned int j=0; j<runData->GetDataBin(histoNo[0])->size(); j++) {
for (UInt_t j=0; j<runData->GetDataBin(histoNo[0])->size(); j++) {
// make sure that the index stays in the proper range
if ((j-t0Add[0]+fT0s[0] >= 0) && (j-t0Add[0]+fT0s[0] < addRunSize)) {
fForward[j] += addRunData->GetDataBin(histoNo[0])->at(j-t0Add[0]+fT0s[0]);
@ -423,7 +430,7 @@ bool PRunAsymmetry::PrepareData()
// add backward run
addRunSize = addRunData->GetDataBin(histoNo[1])->size();
for (unsigned int j=0; j<runData->GetDataBin(histoNo[1])->size(); j++) {
for (UInt_t j=0; j<runData->GetDataBin(histoNo[1])->size(); j++) {
// make sure that the index stays in the proper range
if ((j-t0Add[1]+fT0s[1] >= 0) && (j-t0Add[1]+fT0s[1] < addRunSize)) {
fBackward[j] += addRunData->GetDataBin(histoNo[1])->at(j-t0Add[1]+fT0s[1]);
@ -438,8 +445,8 @@ bool PRunAsymmetry::PrepareData()
if (!SubtractEstimatedBkg())
return false;
} else { // no background given to do the job
cout << endl << "PRunAsymmetry::PrepareData(): Neither fix background nor background bins are given!";
cout << endl << "One of the two is needed! Will quit ...";
cerr << endl << "PRunAsymmetry::PrepareData(): **ERROR** Neither fix background nor background bins are given!";
cerr << endl << "One of the two is needed! Will quit ...";
return false;
}
} else { // fixed background given
@ -448,7 +455,7 @@ bool PRunAsymmetry::PrepareData()
}
// everything looks fine, hence fill data set
bool status;
Bool_t status;
switch(fHandleTag) {
case kFit:
status = PrepareFitData(runData, histoNo);
@ -479,9 +486,9 @@ bool PRunAsymmetry::PrepareData()
* where \f$ f_i^{\rm c} \f$ is the background corrected histogram, \f$ f_i \f$ the raw histogram
* and \f$ \mathrm{bkg} \f$ the fix given background.
*/
bool PRunAsymmetry::SubtractFixBkg()
Bool_t PRunAsymmetry::SubtractFixBkg()
{
for (unsigned int i=0; i<fForward.size(); i++) {
for (UInt_t i=0; i<fForward.size(); i++) {
fForwardErr.push_back(TMath::Sqrt(fForward[i]+fRunInfo->fBkgFix[0] * fTimeResolution * 1.0e3));
fForward[i] -= fRunInfo->fBkgFix[0] * fTimeResolution * 1.0e3; // bkg per ns -> bkg per bin; 1.0e3: us -> ns
fBackwardErr.push_back(TMath::Sqrt(fBackward[i]+fRunInfo->fBkgFix[1] * fTimeResolution * 1.0e3));
@ -508,9 +515,9 @@ bool PRunAsymmetry::SubtractFixBkg()
* \pm\frac{1}{N}\left[\sum_{i=0}^N f_i \right]^{1/2},\f]
* where \f$N\f$ is the number of bins over which the background is formed.
*/
bool PRunAsymmetry::SubtractEstimatedBkg()
Bool_t PRunAsymmetry::SubtractEstimatedBkg()
{
double beamPeriod = 0.0;
Double_t beamPeriod = 0.0;
// check if data are from PSI, RAL, or TRIUMF
if (fRunInfo->fInstitute[0].Contains("psi"))
@ -523,23 +530,23 @@ bool PRunAsymmetry::SubtractEstimatedBkg()
beamPeriod = 0.0;
// check if start and end are in proper order
unsigned int start[2] = {fRunInfo->fBkgRange[0], fRunInfo->fBkgRange[2]};
unsigned int end[2] = {fRunInfo->fBkgRange[1], fRunInfo->fBkgRange[3]};
for (unsigned int i=0; i<2; i++) {
UInt_t start[2] = {fRunInfo->fBkgRange[0], fRunInfo->fBkgRange[2]};
UInt_t end[2] = {fRunInfo->fBkgRange[1], fRunInfo->fBkgRange[3]};
for (UInt_t i=0; i<2; i++) {
if (end[i] < start[i]) {
cout << endl << "PRunAsymmetry::SubtractEstimatedBkg(): end = " << end[i] << " > start = " << start[i] << "! Will swap them!";
unsigned int keep = end[i];
UInt_t keep = end[i];
end[i] = start[i];
start[i] = keep;
}
}
// calculate proper background range
for (unsigned int i=0; i<2; i++) {
for (UInt_t i=0; i<2; i++) {
if (beamPeriod != 0.0) {
double beamPeriodBins = beamPeriod/fRunInfo->fPacking;
unsigned int periods = (unsigned int)((double)(end[i] - start[i] + 1) / beamPeriodBins);
end[i] = start[i] + (unsigned int)round((double)periods*beamPeriodBins);
Double_t beamPeriodBins = beamPeriod/fRunInfo->fPacking;
UInt_t periods = (UInt_t)((Double_t)(end[i] - start[i] + 1) / beamPeriodBins);
end[i] = start[i] + (UInt_t)round((Double_t)periods*beamPeriodBins);
cout << "PRunAsymmetry::SubtractEstimatedBkg(): Background " << start[i] << ", " << end[i] << endl;
if (end[i] == start[i])
end[i] = fRunInfo->fBkgRange[2*i+1];
@ -549,47 +556,47 @@ bool PRunAsymmetry::SubtractEstimatedBkg()
// check if start is within histogram bounds
if ((start[0] < 0) || (start[0] >= fForward.size()) ||
(start[1] < 0) || (start[1] >= fBackward.size())) {
cout << endl << "PRunAsymmetry::SubtractEstimatedBkg(): background bin values out of bound!";
cout << endl << " histo lengths (f/b) = (" << fForward.size() << "/" << fBackward.size() << ").";
cout << endl << " background start (f/b) = (" << start[0] << "/" << start[1] << ").";
cerr << endl << "PRunAsymmetry::SubtractEstimatedBkg(): **ERROR** background bin values out of bound!";
cerr << endl << " histo lengths (f/b) = (" << fForward.size() << "/" << fBackward.size() << ").";
cerr << endl << " background start (f/b) = (" << start[0] << "/" << start[1] << ").";
return false;
}
// check if end is within histogram bounds
if ((end[0] < 0) || (end[0] >= fForward.size()) ||
(end[1] < 0) || (end[1] >= fBackward.size())) {
cout << endl << "PRunAsymmetry::SubtractEstimatedBkg(): background bin values out of bound!";
cout << endl << " histo lengths (f/b) = (" << fForward.size() << "/" << fBackward.size() << ").";
cout << endl << " background end (f/b) = (" << end[0] << "/" << end[1] << ").";
cerr << endl << "PRunAsymmetry::SubtractEstimatedBkg(): **ERROR** background bin values out of bound!";
cerr << endl << " histo lengths (f/b) = (" << fForward.size() << "/" << fBackward.size() << ").";
cerr << endl << " background end (f/b) = (" << end[0] << "/" << end[1] << ").";
return false;
}
// calculate background
double bkg[2] = {0.0, 0.0};
double errBkg[2] = {0.0, 0.0};
Double_t bkg[2] = {0.0, 0.0};
Double_t errBkg[2] = {0.0, 0.0};
// forward
for (unsigned int i=start[0]; i<end[0]; i++)
for (UInt_t i=start[0]; i<end[0]; i++)
bkg[0] += fForward[i];
errBkg[0] = TMath::Sqrt(bkg[0])/(end[0] - start[0] + 1);
bkg[0] /= static_cast<double>(end[0] - start[0] + 1);
bkg[0] /= static_cast<Double_t>(end[0] - start[0] + 1);
//cout << endl << ">> bkg[0] = " << bkg[0];
// backward
for (unsigned int i=start[1]; i<end[1]; i++)
for (UInt_t i=start[1]; i<end[1]; i++)
bkg[1] += fBackward[i];
errBkg[1] = TMath::Sqrt(bkg[1])/(end[0] - start[0] + 1);
bkg[1] /= static_cast<double>(end[1] - start[1] + 1);
bkg[1] /= static_cast<Double_t>(end[1] - start[1] + 1);
//cout << endl << ">> bkg[1] = " << bkg[1] << endl;
// correct error for forward, backward
for (unsigned int i=0; i<fForward.size(); i++) {
for (UInt_t i=0; i<fForward.size(); i++) {
fForwardErr.push_back(TMath::Sqrt(fForward[i]+errBkg[0]*errBkg[0]));
fBackwardErr.push_back(TMath::Sqrt(fBackward[i]+errBkg[1]*errBkg[1]));
}
// subtract background from data
for (unsigned int i=0; i<fForward.size(); i++) {
for (UInt_t i=0; i<fForward.size(); i++) {
fForward[i] -= bkg[0];
fBackward[i] -= bkg[1];
}
@ -604,35 +611,38 @@ bool PRunAsymmetry::SubtractEstimatedBkg()
* <p>
*
*/
bool PRunAsymmetry::PrepareFitData(PRawRunData* runData, unsigned int histoNo[2])
Bool_t PRunAsymmetry::PrepareFitData(PRawRunData* runData, UInt_t histoNo[2])
{
// transform raw histo data. This is done the following way (for details see the manual):
// first rebin the data, than calculate the asymmetry
// first get start data, end data, and t0
int start[2] = {fRunInfo->fDataRange[0], fRunInfo->fDataRange[2]};
int end[2] = {fRunInfo->fDataRange[1], fRunInfo->fDataRange[3]};
double t0[2] = {fT0s[0], fT0s[1]};
Int_t start[2] = {fRunInfo->fDataRange[0], fRunInfo->fDataRange[2]};
Int_t end[2] = {fRunInfo->fDataRange[1], fRunInfo->fDataRange[3]};
Double_t t0[2] = {fT0s[0], fT0s[1]};
// check if start, end, and t0 make any sense
// 1st check if start and end are in proper order
for (unsigned int i=0; i<2; i++) {
for (UInt_t i=0; i<2; i++) {
if (end[i] < start[i]) { // need to swap them
int keep = end[i];
Int_t keep = end[i];
end[i] = start[i];
start[i] = keep;
}
// 2nd check if start is within proper bounds
if ((start[i] < 0) || (start[i] > (int)runData->GetDataBin(histoNo[i])->size())) {
cout << endl << "PRunAsymmetry::PrepareFitData(): **ERROR** start data bin doesn't make any sense!";
if ((start[i] < 0) || (start[i] > (Int_t)runData->GetDataBin(histoNo[i])->size())) {
cerr << endl << "PRunAsymmetry::PrepareFitData(): **ERROR** start data bin doesn't make any sense!";
cerr << endl;
return false;
}
// 3rd check if end is within proper bounds
if ((end[i] < 0) || (end[i] > (int)runData->GetDataBin(histoNo[i])->size())) {
cout << endl << "PRunAsymmetry::PrepareFitData(): **ERROR** end data bin doesn't make any sense!";
if ((end[i] < 0) || (end[i] > (Int_t)runData->GetDataBin(histoNo[i])->size())) {
cerr << endl << "PRunAsymmetry::PrepareFitData(): **ERROR** end data bin doesn't make any sense!";
cerr << endl;
return false;
}
// 4th check if t0 is within proper bounds
if ((t0[i] < 0) || (t0[i] > (int)runData->GetDataBin(histoNo[i])->size())) {
cout << endl << "PRunAsymmetry::PrepareFitData(): **ERROR** t0 data bin doesn't make any sense!";
if ((t0[i] < 0) || (t0[i] > (Int_t)runData->GetDataBin(histoNo[i])->size())) {
cerr << endl << "PRunAsymmetry::PrepareFitData(): **ERROR** t0 data bin doesn't make any sense!";
cerr << endl;
return false;
}
}
@ -640,10 +650,10 @@ bool PRunAsymmetry::PrepareFitData(PRawRunData* runData, unsigned int histoNo[2]
// everything looks fine, hence fill packed forward and backward histo
PRunData forwardPacked;
PRunData backwardPacked;
double value = 0.0;
double error = 0.0;
Double_t value = 0.0;
Double_t error = 0.0;
// forward
for (int i=start[0]; i<end[0]; i++) {
for (Int_t i=start[0]; i<end[0]; i++) {
if (fRunInfo->fPacking == 1) {
forwardPacked.AppendValue(fForward[i]);
forwardPacked.AppendErrorValue(fForwardErr[i]);
@ -665,7 +675,7 @@ bool PRunAsymmetry::PrepareFitData(PRawRunData* runData, unsigned int histoNo[2]
}
}
// backward
for (int i=start[1]; i<end[1]; i++) {
for (Int_t i=start[1]; i<end[1]; i++) {
if (fRunInfo->fPacking == 1) {
backwardPacked.AppendValue(fBackward[i]);
backwardPacked.AppendErrorValue(fBackwardErr[i]);
@ -688,20 +698,20 @@ bool PRunAsymmetry::PrepareFitData(PRawRunData* runData, unsigned int histoNo[2]
}
// check if packed forward and backward hist have the same size, otherwise take the minimum size
unsigned int noOfBins = forwardPacked.GetValue()->size();
UInt_t noOfBins = forwardPacked.GetValue()->size();
if (forwardPacked.GetValue()->size() != backwardPacked.GetValue()->size()) {
if (forwardPacked.GetValue()->size() > backwardPacked.GetValue()->size())
noOfBins = backwardPacked.GetValue()->size();
}
// form asymmetry including error propagation
double asym;
double f, b, ef, eb;
Double_t asym;
Double_t f, b, ef, eb;
// fill data time start, and step
// data start at data_start-t0 shifted by (pack-1)/2
fData.SetDataTimeStart(fTimeResolution*((double)start[0]-t0[0]+(double)(fRunInfo->fPacking-1)/2.0));
fData.SetDataTimeStep(fTimeResolution*(double)fRunInfo->fPacking);
for (unsigned int i=0; i<noOfBins; i++) {
fData.SetDataTimeStart(fTimeResolution*((Double_t)start[0]-t0[0]+(Double_t)(fRunInfo->fPacking-1)/2.0));
fData.SetDataTimeStep(fTimeResolution*(Double_t)fRunInfo->fPacking);
for (UInt_t i=0; i<noOfBins; i++) {
// to make the formulae more readable
f = forwardPacked.GetValue()->at(i);
b = backwardPacked.GetValue()->at(i);
@ -722,10 +732,10 @@ bool PRunAsymmetry::PrepareFitData(PRawRunData* runData, unsigned int histoNo[2]
}
// count the number of bins to be fitted
double time;
Double_t time;
fNoOfFitBins=0;
for (unsigned int i=0; i<fData.GetValue()->size(); i++) {
time = fData.GetDataTimeStart() + (double)i * fData.GetDataTimeStep();
for (UInt_t i=0; i<fData.GetValue()->size(); i++) {
time = fData.GetDataTimeStart() + (Double_t)i * fData.GetDataTimeStep();
if ((time >= fFitStartTime) && (time <= fFitStopTime))
fNoOfFitBins++;
}
@ -746,32 +756,32 @@ bool PRunAsymmetry::PrepareFitData(PRawRunData* runData, unsigned int histoNo[2]
* <p>
*
*/
bool PRunAsymmetry::PrepareViewData(PRawRunData* runData, unsigned int histoNo[2])
Bool_t PRunAsymmetry::PrepareViewData(PRawRunData* runData, UInt_t histoNo[2])
{
// check if view_packing is wished
int packing = fRunInfo->fPacking;
Int_t packing = fRunInfo->fPacking;
if (fMsrInfo->GetMsrPlotList()->at(0).fViewPacking > 0) {
packing = fMsrInfo->GetMsrPlotList()->at(0).fViewPacking;
}
// feed the parameter vector
std::vector<double> par;
std::vector<Double_t> par;
PMsrParamList *paramList = fMsrInfo->GetMsrParamList();
for (unsigned int i=0; i<paramList->size(); i++)
for (UInt_t i=0; i<paramList->size(); i++)
par.push_back((*paramList)[i].fValue);
// transform raw histo data. This is done the following way (for details see the manual):
// first rebin the data, than calculate the asymmetry
// first get start data, end data, and t0
int val = fRunInfo->fDataRange[0]-packing*(fRunInfo->fDataRange[0]/packing);
Int_t val = fRunInfo->fDataRange[0]-packing*(fRunInfo->fDataRange[0]/packing);
do {
if (fRunInfo->fDataRange[2] - fRunInfo->fDataRange[0] < 0)
val += packing;
} while (val + fRunInfo->fDataRange[2] - fRunInfo->fDataRange[0] < 0);
int start[2] = {val, val + fRunInfo->fDataRange[2] - fRunInfo->fDataRange[0]};
int end[2];
double t0[2] = {fT0s[0], fT0s[1]};
Int_t start[2] = {val, val + fRunInfo->fDataRange[2] - fRunInfo->fDataRange[0]};
Int_t end[2];
Double_t t0[2] = {fT0s[0], fT0s[1]};
/*
cout << endl << ">> start[0]=" << start[0] << ", end[0]=" << end[0];
@ -780,8 +790,8 @@ cout << endl;
*/
// make sure that there are equal number of rebinned bins in forward and backward
unsigned int noOfBins0 = (runData->GetDataBin(histoNo[0])->size()-start[0])/packing;
unsigned int noOfBins1 = (runData->GetDataBin(histoNo[1])->size()-start[1])/packing;
UInt_t noOfBins0 = (runData->GetDataBin(histoNo[0])->size()-start[0])/packing;
UInt_t noOfBins1 = (runData->GetDataBin(histoNo[1])->size()-start[1])/packing;
if (noOfBins0 > noOfBins1)
noOfBins0 = noOfBins1;
end[0] = start[0] + noOfBins0 * packing;
@ -789,25 +799,28 @@ cout << endl;
// check if start, end, and t0 make any sense
// 1st check if start and end are in proper order
for (unsigned int i=0; i<2; i++) {
for (UInt_t i=0; i<2; i++) {
if (end[i] < start[i]) { // need to swap them
int keep = end[i];
Int_t keep = end[i];
end[i] = start[i];
start[i] = keep;
}
// 2nd check if start is within proper bounds
if ((start[i] < 0) || (start[i] > (int)runData->GetDataBin(histoNo[i])->size())) {
cout << endl << "PRunAsymmetry::PrepareViewData(): **ERROR** start data bin doesn't make any sense!";
if ((start[i] < 0) || (start[i] > (Int_t)runData->GetDataBin(histoNo[i])->size())) {
cerr << endl << "PRunAsymmetry::PrepareViewData(): **ERROR** start data bin doesn't make any sense!";
cerr << endl;
return false;
}
// 3rd check if end is within proper bounds
if ((end[i] < 0) || (end[i] > (int)runData->GetDataBin(histoNo[i])->size())) {
cout << endl << "PRunAsymmetry::PrepareViewData(): **ERROR** end data bin doesn't make any sense!";
if ((end[i] < 0) || (end[i] > (Int_t)runData->GetDataBin(histoNo[i])->size())) {
cerr << endl << "PRunAsymmetry::PrepareViewData(): **ERROR** end data bin doesn't make any sense!";
cerr << endl;
return false;
}
// 4th check if t0 is within proper bounds
if ((t0[i] < 0) || (t0[i] > (int)runData->GetDataBin(histoNo[i])->size())) {
cout << endl << "PRunAsymmetry::PrepareViewData(): **ERROR** t0 data bin doesn't make any sense!";
if ((t0[i] < 0) || (t0[i] > (Int_t)runData->GetDataBin(histoNo[i])->size())) {
cerr << endl << "PRunAsymmetry::PrepareViewData(): **ERROR** t0 data bin doesn't make any sense!";
cerr << endl;
return false;
}
}
@ -815,10 +828,10 @@ cout << endl;
// everything looks fine, hence fill packed forward and backward histo
PRunData forwardPacked;
PRunData backwardPacked;
double value = 0.0;
double error = 0.0;
Double_t value = 0.0;
Double_t error = 0.0;
// forward
for (int i=start[0]; i<end[0]; i++) {
for (Int_t i=start[0]; i<end[0]; i++) {
if (packing == 1) {
forwardPacked.AppendValue(fForward[i]);
forwardPacked.AppendErrorValue(fForwardErr[i]);
@ -840,7 +853,7 @@ cout << endl;
error += fForwardErr[i]*fForwardErr[i];
}
// backward
for (int i=start[1]; i<end[1]; i++) {
for (Int_t i=start[1]; i<end[1]; i++) {
if (packing == 1) {
backwardPacked.AppendValue(fBackward[i]);
backwardPacked.AppendErrorValue(fBackwardErr[i]);
@ -863,19 +876,19 @@ cout << endl;
}
// check if packed forward and backward hist have the same size, otherwise take the minimum size
unsigned int noOfBins = forwardPacked.GetValue()->size();
UInt_t noOfBins = forwardPacked.GetValue()->size();
if (forwardPacked.GetValue()->size() != backwardPacked.GetValue()->size()) {
if (forwardPacked.GetValue()->size() > backwardPacked.GetValue()->size())
noOfBins = backwardPacked.GetValue()->size();
}
// form asymmetry including error propagation
double asym;
double f, b, ef, eb, alpha = 1.0, beta = 1.0;
Double_t asym;
Double_t f, b, ef, eb, alpha = 1.0, beta = 1.0;
// fill data time start, and step
// data start at data_start-t0
fData.SetDataTimeStart(fTimeResolution*((double)start[0]-t0[0]+(double)(packing-1)/2.0));
fData.SetDataTimeStep(fTimeResolution*(double)packing);
fData.SetDataTimeStart(fTimeResolution*((Double_t)start[0]-t0[0]+(Double_t)(packing-1)/2.0));
fData.SetDataTimeStep(fTimeResolution*(Double_t)packing);
/*
cout << endl << ">> start time = " << fData.GetDataTimeStart() << ", step = " << fData.GetDataTimeStep();
@ -905,7 +918,7 @@ cout << endl << "--------------------------------" << endl;
}
//cout << endl << ">> alpha = " << alpha << ", beta = " << beta;
for (unsigned int i=0; i<forwardPacked.GetValue()->size(); i++) {
for (UInt_t i=0; i<forwardPacked.GetValue()->size(); i++) {
// to make the formulae more readable
f = forwardPacked.GetValue()->at(i);
b = backwardPacked.GetValue()->at(i);
@ -926,10 +939,10 @@ cout << endl << "--------------------------------" << endl;
}
// count the number of bins to be fitted
double time;
Double_t time;
fNoOfFitBins=0;
for (unsigned int i=0; i<fData.GetValue()->size(); i++) {
time = fData.GetDataTimeStart() + (double)i * fData.GetDataTimeStep();
for (UInt_t i=0; i<fData.GetValue()->size(); i++) {
time = fData.GetDataTimeStart() + (Double_t)i * fData.GetDataTimeStep();
if ((time >= fFitStartTime) && (time <= fFitStopTime))
fNoOfFitBins++;
}
@ -942,22 +955,22 @@ cout << endl << "--------------------------------" << endl;
// fill theory vector for kView
// calculate functions
for (int i=0; i<fMsrInfo->GetNoOfFuncs(); i++) {
for (Int_t i=0; i<fMsrInfo->GetNoOfFuncs(); i++) {
fFuncValues[i] = fMsrInfo->EvalFunc(fMsrInfo->GetFuncNo(i), fRunInfo->fMap, par);
}
// calculate theory
unsigned int size = runData->GetDataBin(histoNo[0])->size();
double factor = 1.0;
UInt_t size = runData->GetDataBin(histoNo[0])->size();
Double_t factor = 1.0;
if (fData.GetValue()->size() * 10 > runData->GetDataBin(histoNo[0])->size()) {
size = fData.GetValue()->size() * 10;
factor = (double)runData->GetDataBin(histoNo[0])->size() / (double)size;
factor = (Double_t)runData->GetDataBin(histoNo[0])->size() / (Double_t)size;
}
//cout << endl << ">> runData->fDataBin[histoNo[0]].size() = " << runData->fDataBin[histoNo[0]].size() << ", fData.GetValue()->size() * 10 = " << fData.GetValue()->size() * 10 << ", size = " << size << ", factor = " << factor << endl;
fData.SetTheoryTimeStart(fData.GetDataTimeStart());
fData.SetTheoryTimeStep(fTimeResolution*factor);
for (unsigned int i=0; i<size; i++) {
time = fData.GetTheoryTimeStart() + (double)i*fTimeResolution*factor;
for (UInt_t i=0; i<size; i++) {
time = fData.GetTheoryTimeStart() + (Double_t)i*fTimeResolution*factor;
value = fTheory->Func(time, par, fFuncValues);
if (fabs(value) > 10.0) { // dirty hack needs to be fixed!!
value = 0.0;