123 DeleteMatrix(&fDAinRelSq);
124 DeleteMatrix(&fDAinColRelSq);
126 delete fBgrErrUncorrInSq;
127 delete fBgrErrScaleIn;
132 DeleteMatrix(&fYData);
133 DeleteMatrix(&fVyyData);
160 :
TUnfold(hist_A,histmap,regmode,constraint)
169 fAoutside =
new TMatrixD(GetNx(),2);
172 fDAinColRelSq =
new TMatrixD(GetNx(),1);
174 Int_t nmax=GetNx()*GetNy();
180 for (
Int_t ix = 0; ix < GetNx(); ix++) {
181 Int_t ibinx = fXToHist[ix];
182 Double_t sum_sq= fSumOverY[ix]*fSumOverY[ix];
183 for (
Int_t ibiny = 0; ibiny <= GetNy()+1; ibiny++) {
185 if (histmap == kHistMapOutputHoriz) {
193 (*fDAinColRelSq)(ix,0) += normerr_sq;
197 if (histmap == kHistMapOutputHoriz) {
202 }
else if(ibiny==GetNy()+1) {
204 if (histmap == kHistMapOutputHoriz) {
211 rowDAinRelSq[da_nonzero]=ibiny-1;
212 colDAinRelSq[da_nonzero] = ix;
213 dataDAinRelSq[da_nonzero] = normerr_sq;
214 if(dataDAinRelSq[da_nonzero]>0.0) da_nonzero++;
219 fDAinRelSq = CreateSparseMatrix(GetNy(),GetNx(),da_nonzero,
220 rowDAinRelSq,colDAinRelSq,dataDAinRelSq);
222 DeleteMatrix(&fDAinColRelSq);
224 delete[] rowDAinRelSq;
225 delete[] colDAinRelSq;
226 delete[] dataDAinRelSq;
252 if(fSysIn->FindObject(name)) {
253 Error(
"AddSysError",
"Source %s given twice, ignoring 2nd call.\n",name);
261 Int_t nmax= GetNx()*GetNy();
266 for (
Int_t ix = 0; ix < GetNx(); ix++) {
267 Int_t ibinx = fXToHist[ix];
269 for(
Int_t loop=0;loop<2;loop++) {
270 for (
Int_t ibiny = 0; ibiny <= GetNy()+1; ibiny++) {
273 if (histmap == kHistMapOutputHoriz) {
279 if(mode!=kSysErrModeMatrix) {
281 if((ibiny>0)&&(ibiny<=GetNy())) {
282 z0=aCopy(ibiny-1,ix)*fSumOverY[ix];
283 }
else if(ibiny==0) {
284 z0=(*fAoutside)(ix,0);
286 z0=(*fAoutside)(ix,1);
288 if(mode==kSysErrModeShift) {
290 }
else if(mode==kSysErrModeRelative) {
298 if((ibiny>0)&&(ibiny<=GetNy())) {
304 data[nmax]=z/sum-aCopy(ibiny-1,ix);
308 if(data[nmax] != 0.0) nmax++;
316 "source %s has no influence and has not been added.\n",name);
319 nmax,rows,cols,data);
349 Warning(
"DoBackgroundSubtraction",
350 "inverse error matrix from user input,"
351 " not corrected for background");
359 for(key=bgrPtr.
Next();key;key=bgrPtr.
Next()) {
362 ((
const TPair *)*bgrPtr)->Value()
368 (*fY)(i,0) -= (*bgr)(i,0);
384 for(
Int_t k=vyydata_rows[i];k<vyydata_rows[i+1];k++) {
385 if(vyydata_data[k]>0.0) {
387 usedBin[vyydata_cols[k]]++;
394 for(key=bgrErrUncorrSqPtr.
Next();key;
395 key=bgrErrUncorrSqPtr.
Next()) {
398 ((
const TPair *)*bgrErrUncorrSqPtr)->Value()
405 if(!usedBin[yi])
continue;
406 vyy(yi,yi) +=(*bgrerruncorrSquared)(yi,0);
413 for(key=bgrErrScalePtr.
Next();key;key=bgrErrScalePtr.
Next()) {
416 ((
const TPair *)*bgrErrScalePtr)->Value()
423 if(!usedBin[yi])
continue;
425 if(!usedBin[yj])
continue;
426 vyy(yi,yj) +=(*bgrerrscale)(yi,0)* (*bgrerrscale)(yj,0);
439 Fatal(
"DoBackgroundSubtraction",
"No input vector defined");
467 const TH2 *hist_vyy_inv)
508 if(fBgrIn->FindObject(name)) {
509 Error(
"SubtractBackground",
"Source %s given twice, ignoring 2nd call.\n",
515 for(
Int_t row=0;row<GetNy();row++) {
517 (*bgrErrUncSq)(row,0) =
519 (*bgrErrCorr)(row,0) = scale_error*bgr->
GetBinContent(row+1);
522 fBgrErrUncorrInSq->Add(
new TObjString(name),bgrErrUncSq);
523 fBgrErrScaleIn->Add(
new TObjString(name),bgrErrCorr);
525 DoBackgroundSubtraction();
527 Info(
"SubtractBackground",
528 "Background subtraction prior to setting input data");
551 (
TH1 *bgrHist,
const char *bgrSource,
const Int_t *binMap,
555 ClearHistogram(bgrHist);
561 for(key=bgrPtr.
Next();key;key=bgrPtr.
Next()) {
563 if(bgrSource && bgrName.
CompareTo(bgrSource))
continue;
566 ((
const TPair *)*bgrPtr)->Value()
568 fBgrIn->GetValue(bgrName)
571 for(
Int_t i=0;i<GetNy();i++) {
572 Int_t destBin=binMap[i];
579 if(includeError &1) {
580 TMapIter bgrErrUncorrSqPtr(fBgrErrUncorrInSq);
581 for(key=bgrErrUncorrSqPtr.
Next();key;key=bgrErrUncorrSqPtr.
Next()) {
583 if(bgrSource && bgrName.
CompareTo(bgrSource))
continue;
586 ((
const TPair *)*bgrErrUncorrSqPtr)->Value()
588 fBgrErrUncorrInSq->GetValue(((
const TObjString *)key)
592 for(
Int_t i=0;i<GetNy();i++) {
593 Int_t destBin=binMap[i];
596 ((*bgrerruncorrSquared)(i,0)+
601 if(includeError & 2) {
602 TMapIter bgrErrScalePtr(fBgrErrScaleIn);
603 for(key=bgrErrScalePtr.
Next();key;key=bgrErrScalePtr.
Next()) {
605 if(bgrSource && bgrName.
CompareTo(bgrSource))
continue;
608 ((
const TPair *)*bgrErrScalePtr)->Value()
610 fBgrErrScaleIn->GetValue(((
const TObjString *)key)->GetString())
613 for(
Int_t i=0;i<GetNy();i++) {
614 Int_t destBin=binMap[i];
615 bgrHist->
SetBinError(destBin,hypot((*bgrerrscale)(i,0),
635 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,20,00)
651 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,20,00)
724 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,20,00)
790 ErrorMatrixToHist(ematrix,fEmatUncorrX,binMap,clearEmat);
901 if(fDAinColRelSq && fDAinRelSq) {
904 ScaleColumnsByVector(M1A_Z1,GetDXDAZ(1));
906 ScaleColumnsByVector(M1Rsq_Z1,GetDXDAZ(1));
908 TMatrixDSparse *AtZ0 = MultiplyMSparseTranspMSparse(fA,GetDXDAZ(0));
910 MultiplyMSparseTranspMSparse(fDAinRelSq,GetDXDAZ(0));
914 ScaleColumnsByVector(F,AtZ0);
915 AddMSparse(F,-1.0,M1A_Z1);
919 ScaleColumnsByVector(G,RsqZ0);
920 AddMSparse(G,-1.0,M1Rsq_Z1);
921 DeleteMatrix(&M1A_Z1);
922 DeleteMatrix(&M1Rsq_Z1);
924 DeleteMatrix(&RsqZ0);
926 r=MultiplyMSparseMSparseTranspVector(F,F,fDAinColRelSq);
932 AddMSparse(r,-1.0,r1);
933 AddMSparse(r,-1.0,r2);
948 for(
int index=0;index<Z0sq_rows[Z0sq.
GetNrows()];index++) {
949 Z0sq_data[index] *= Z0sq_data[index];
952 TMatrixDSparse *Z0sqRsq=MultiplyMSparseTranspMSparse(fDAinRelSq,&Z0sq);
955 DeleteMatrix(&Z0sqRsq);
961 for(
int index=0;index<Z1sq_rows[Z1sq.
GetNrows()];index++) {
962 Z1sq_data[index] *= Z1sq_data[index];
967 TMatrixDSparse *r4=MultiplyMSparseMSparseTranspVector(m_1,m_1,Z1sqRsq);
968 DeleteMatrix(&Z1sqRsq);
972 (m_0,fDAinRelSq,GetDXDAZ(1));
974 ScaleColumnsByVector(H,GetDXDAZ(0));
982 AddMSparse(r,1.0,r3);
988 AddMSparse(r,1.0,r4);
989 AddMSparse(r,-1.0,r5);
990 AddMSparse(r,-1.0,r6);
1017 TMatrixDSparse *dsysT_VYAx = MultiplyMSparseTranspMSparse(dsys,GetDXDAZ(0));
1019 DeleteMatrix(&dsysT_VYAx);
1020 TMatrixDSparse *dsys_X = MultiplyMSparseMSparse(dsys,GetDXDAZ(1));
1022 DeleteMatrix(&dsys_X);
1023 AddMSparse(delta,-1.0,delta2);
1024 DeleteMatrix(&delta2);
1056 const Int_t *binMap)
1083 (
TH1 *hist_delta,
const char *source,
const Int_t *binMap)
1090 dx=MultiplyMSparseM(GetDXDY(),dy);
1092 VectorMapToHist(hist_delta,dx,binMap);
1150 emat=MultiplyMSparseMSparseTranspVector(delta,delta,0);
1152 ErrorMatrixToHist(ematrix,emat,binMap,clearEmat);
1153 DeleteMatrix(&emat);
1182 emat=MultiplyMSparseMSparseTranspVector(dx,dx,0);
1185 ErrorMatrixToHist(ematrix,emat,binMap,clearEmat);
1186 DeleteMatrix(&emat);
1216 emat=MultiplyMSparseMSparseTranspVector(fDeltaSysTau,fDeltaSysTau,0);
1218 ErrorMatrixToHist(ematrix,emat,binMap,clearEmat);
1219 DeleteMatrix(&emat);
1240 GetEmatrixFromVyy(fVyyData,ematrix,binMap,clearEmat);
1266 emat=MultiplyMSparseMSparseTranspVector(GetDXDY(),GetDXDY(),dySquared);
1268 ErrorMatrixToHist(ematrix,emat,binMap,clearEmat);
1269 DeleteMatrix(&emat);
1294 em=MultiplyMSparseMSparseTranspVector(dxdyVyy,GetDXDY(),0);
1295 DeleteMatrix(&dxdyVyy);
1297 ErrorMatrixToHist(ematrix,em,binMap,clearEmat);
1320 for(key=sysErrPtr.
Next();key;key=sysErrPtr.
Next()) {
1346 for(key=sysErrPtr.
Next();key;key=sysErrPtr.
Next()) {
1349 ((
const TPair *)*sysErrPtr)->Value()
1389 for(key=sysErrPtr.
Next();key;key=sysErrPtr.
Next()) {
1392 ((
const TPair *)*sysErrPtr)->Value()
1430 if(vdy_rows[i+1]>vdy_rows[i]) {
1431 r += vdy_data[vdy_rows[i]] * dy(i,0);
1485 Fatal(
"ScaleColumnsByVector error",
1486 "matrix cols/vector rows %d!=%d OR vector cols %d !=1\n",
1497 for(
Int_t index_m=rows_m[i];index_m<rows_m[i+1];index_m++) {
1498 Int_t j=cols_m[index_m];
1499 Int_t index_v=rows_v[j];
1500 if(index_v<rows_v[j+1]) {
1501 data_m[index_m] *= data_v[index_v];
1503 data_m[index_m] =0.0;
1509 for(
Int_t index_m=rows_m[i];index_m<rows_m[i+1];index_m++) {
1510 Int_t j=cols_m[index_m];
1511 data_m[index_m] *= (*v)(j,0);
1539 for(
Int_t i=0;i<nbin+2;i++) {
1543 Int_t binMapSize = fHistToX.GetSize();
1546 for(
Int_t i=0;i<binMapSize;i++) {
1547 Int_t destBinI=binMap ? binMap[i] : i;
1548 Int_t srcBinI=fHistToX[i];
1549 if((destBinI>=0)&&(destBinI<nbin+2)&&(srcBinI>=0)) {
1550 Int_t index=delta_rows[srcBinI];
1551 if(index<delta_rows[srcBinI+1]) {
1552 c[destBinI]+=delta_data[index];
1557 for(
Int_t i=0;i<nbin+2;i++) {
void InitTUnfoldSys(void)
Initialize pointers and TMaps.
virtual Int_t GetEntries() const
static long int sum(long int i)
TMatrixDSparse * fEmatUncorrX
Result: syst.error from fDA2 on fX.
static void DeleteMatrix(TMatrixD **m)
delete matrix and invalidate pointer
TMatrixDSparse * CreateSparseMatrix(Int_t nrow, Int_t ncol, Int_t nele, Int_t *row, Int_t *col, Double_t *data) const
Create a sparse matrix, given the nonzero elements.
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
virtual void ClearResults(void)
Clear all data members which depend on the unfolding results.
TMatrixDSparse * InvertMSparseSymmPos(const TMatrixDSparse *A, Int_t *rank) const
Get the inverse or pseudo-inverse of a positive, sparse matrix.
Double_t GetChi2Sys(void)
Calculate total chi**2 including all systematic errors.
void Fatal(const char *location, const char *msgfmt,...)
void GetEmatrixInput(TH2 *ematrix, const Int_t *binMap=0, Bool_t clearEmat=kTRUE)
Covariance matrix contribution from input measurement uncertainties.
Collectable string class.
TMap * fBgrErrScaleIn
Input: background sources correlated error.
virtual const Element * GetMatrixArray() const
Bool_t GetDeltaSysSource(TH1 *hist_delta, const char *source, const Int_t *binMap=0)
Correlated one-sigma shifts correspinding to a given systematic uncertainty.
TMap * fBgrIn
Input: size of background sources.
void VectorMapToHist(TH1 *hist_delta, const TMatrixDSparse *delta, const Int_t *binMap)
Map delta to hist_delta, possibly summing up bins.
virtual TMatrixDSparse * PrepareCorrEmat(const TMatrixDSparse *m1, const TMatrixDSparse *m2, const TMatrixDSparse *dsys)
Propagate correlated systematic shift to an output vector.
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
TMatrixDSparse * fDAinRelSq
Input: normalized errors from input matrix.
virtual void PrepareSysError(void)
Matrix calculations required to propagate systematic errors.
void Add(TObject *obj)
This function may not be used (but we need to provide it since it is a pure virtual in TCollection)...
An algorithm to unfold distributions from detector to truth level, with background subtraction and pr...
void SetTauError(Double_t delta_tau)
Specify an uncertainty on tau.
Double_t fDtau
Input: error on tau.
virtual Int_t SetInput(const TH1 *hist_y, Double_t scaleBias=0.0, Double_t oneOverZeroError=0.0, const TH2 *hist_vyy=0, const TH2 *hist_vyy_inv=0)
Define the input data for subsequent calls to DoUnfold(Double_t).
virtual Int_t GetNbinsX() const
#define ROOT_VERSION_CODE
void GetEmatrixSysBackgroundUncorr(TH2 *ematrix, const char *source, const Int_t *binMap=0, Bool_t clearEmat=kTRUE)
Covariance contribution from background uncorrelated uncertainty.
TMap * fSysIn
Input: correlated errors.
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
const TMatrixDSparse * GetDXDtauSquared(void) const
vector of derivative dx/dtauSquared, using internal bin counting
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
TMatrixDSparse * MultiplyMSparseM(const TMatrixDSparse *a, const TMatrixD *b) const
Multiply sparse matrix and a non-sparse matrix.
you should not use this method at all Int_t Int_t Double_t Double_t em
void GetEmatrixSysUncorr(TH2 *ematrix, const Int_t *binMap=0, Bool_t clearEmat=kTRUE)
Covariance contribution from uncorrelated uncertainties of the response matrix.
void ClearHistogram(TH1 *h, Double_t x=0.) const
Initialize bin contents and bin errors for a given histogram.
unsigned int r3[N_CITIES]
TSortedList * GetBgrSources(void) const
Get a new list of all background sources.
EHistMap
arrangement of axes for the response matrix (TH2 histogram)
EConstraint
type of extra constraint
TMatrixDSparse * fDeltaSysTau
Result: systematic shift from tau.
void GetEmatrixSysBackgroundScale(TH2 *ematrix, const char *source, const Int_t *binMap=0, Bool_t clearEmat=kTRUE)
Covariance contribution from background normalisation uncertainty.
A sorted doubly linked list.
void Info(const char *location, const char *msgfmt,...)
TObject * GetValue(const char *keyname) const
Returns a pointer to the value associated with keyname as name of the key.
void DoBackgroundSubtraction(void)
Perform background subtraction.
const TMatrixDSparse * GetVxx(void) const
covariance matrix of the result
TMatrixDSparse * GetSummedErrorMatrixXX(void)
Determine total error matrix on the vector x.
virtual void SetBinError(Int_t bin, Double_t error)
See convention for numbering bins in TH1::GetBin.
TMatrixDSparse * GetSummedErrorMatrixYY(void)
Determine total error matrix on the vector Ax.
void Error(const char *location, const char *msgfmt,...)
TMatrixTSparse< Double_t > TMatrixDSparse
ERegMode
choice of regularisation scheme
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
TObject * FindObject(const char *keyname) const
Check if a (key,value) pair exists with keyname as name of the key.
void GetEmatrix(TH2 *ematrix, const Int_t *binMap=0) const
Get output covariance matrix, possibly cumulated over several bins.
TMatrixT< Double_t > TMatrixD
TMap * fBgrErrUncorrInSq
Input: uncorr error squared from bgr sources.
virtual void SetOwnerKeyValue(Bool_t ownkeys=kTRUE, Bool_t ownvals=kTRUE)
Set ownership for keys and values.
void GetEmatrixSysSource(TH2 *ematrix, const char *source, const Int_t *binMap=0, Bool_t clearEmat=kTRUE)
Covariance contribution from a systematic variation of the response matrix.
virtual Int_t SetInput(const TH1 *hist_y, Double_t scaleBias=0.0, Double_t oneOverZeroError=0.0, const TH2 *hist_vyy=0, const TH2 *hist_vyy_inv=0)
Define input data for subsequent calls to DoUnfold(tau).
TMap * fDeltaCorrX
Result: syst.shift from fSysIn on fX.
const TMatrixDSparse * GetAx(void) const
vector of folded-back result
Int_t GetNy(void) const
returns the number of measurement bins
TMap * fDeltaCorrAx
Result: syst.shift from fSysIn on fAx.
virtual const Int_t * GetRowIndexArray() const
Service class for 2-Dim histogram classes.
virtual TMatrixDSparse * PrepareUncorrEmat(const TMatrixDSparse *m1, const TMatrixDSparse *m2)
Propagate uncorrelated systematic errors to a covariance matrix.
void GetEmatrixTotal(TH2 *ematrix, const Int_t *binMap=0)
Get total error matrix, summing up all contributions.
unsigned int r1[N_CITIES]
virtual void SetBinContent(Int_t bin, Double_t content)
Set bin content see convention for numbering bins in TH1::GetBin In case the bin number is greater th...
const TMatrixDSparse * GetVyyInv(void) const
inverse of covariance matrix of the data y
Bool_t GetDeltaSysTau(TH1 *delta, const Int_t *binMap=0)
Correlated one-sigma shifts from shifting tau.
TMatrixD * fY
input (measured) data y
Double_t fTauSquared
regularisation parameter tau squared
TMatrixDSparse * fVyy
covariance matrix Vyy corresponding to y
void SubtractBackground(const TH1 *hist_bgr, const char *name, Double_t scale=1.0, Double_t scale_error=0.0)
Specify a source of background.
TMatrixDSparse * fVyyData
Input: error on fY prior to bgr subtraction.
Class used by TMap to store (key,value) pairs.
void GetEmatrixSysTau(TH2 *ematrix, const Int_t *binMap=0, Bool_t clearEmat=kTRUE)
Covariance matrix contribution from error on regularisation parameter.
virtual void ClearResults(void)
Reset all results.
TMatrixD * fDAinColRelSq
Input: normalized column err.sq. (inp.matr.)
TMap implements an associative array of (key,value) pairs using a THashTable for efficient retrieval ...
const TString & GetString() const
TUnfoldSys(void)
Only for use by root streamer or derived classes.
TMatrixDSparse * fEmatUncorrAx
Result: syst.error from fDA2 on fAx.
void AddSysError(const TH2 *sysError, const char *name, EHistMap histmap, ESysErrMode mode)
Specify a correlated systematic uncertainty.
#define ROOT_VERSION(a, b, c)
Mother of all ROOT objects.
virtual const Int_t * GetColIndexArray() const
you should not use this method at all Int_t Int_t z
TMatrixDSparse * fA
response matrix A
void AddMSparse(TMatrixDSparse *dest, Double_t f, const TMatrixDSparse *src) const
Add a sparse matrix, scaled by a factor, to another scaled matrix.
An algorithm to unfold distributions from detector to truth level.
TMatrixDSparse * MultiplyMSparseMSparse(const TMatrixDSparse *a, const TMatrixDSparse *b) const
Multiply two sparse matrices.
TObject * Next()
Returns the next key from a map.
void ScaleColumnsByVector(TMatrixDSparse *m, const TMatrixTBase< Double_t > *v) const
Scale columns of a matrix by the corresponding rows of a vector.
TMatrixD * fYData
Input: fY prior to bgr subtraction.
const TMatrixDSparse * GetDXDAM(int i) const
matrix contributions of the derivative dx/dA
void Add(TObject *obj)
Add object in sorted list.
Double_t Sqrt(Double_t x)
void GetRhoItotal(TH1 *rhoi, const Int_t *binMap=0, TH2 *invEmat=0)
Get global correlatiocn coefficients, summing up all contributions.
TSortedList * GetSysSources(void) const
Get a new list of all systematic uuncertainty sources.
virtual Double_t GetBinError(Int_t bin) const
Return value of error associated to bin number bin.
void GetEmatrixFromVyy(const TMatrixDSparse *vyy, TH2 *ematrix, const Int_t *binMap, Bool_t clearEmat)
Propagate an error matrix on the input vector to the unfolding result.
Double_t GetRhoIFromMatrix(TH1 *rhoi, const TMatrixDSparse *eOrig, const Int_t *binMap, TH2 *invEmat) const
Get global correlation coefficients with arbitrary min map.
virtual TObject * FindObject(const char *name) const
Must be redefined in derived classes.
ESysErrMode
type of matrix specified with AddSysError()
Bool_t GetDeltaSysBackgroundScale(TH1 *delta, const char *source, const Int_t *binMap=0)
Correlated one-sigma shifts from background normalisation uncertainty.
unsigned int r2[N_CITIES]
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
void Clear(Option_t *option="")
Remove all (key,value) pairs from the map.
TMatrixD * fAoutside
Input: underflow/overflow bins.
TMatrixDSparse * MultiplyMSparseMSparseTranspVector(const TMatrixDSparse *m1, const TMatrixDSparse *m2, const TMatrixTBase< Double_t > *v) const
Calculate a sparse matrix product where the diagonal matrix V is given by a vector.
void GetBackground(TH1 *bgr, const char *bgrSource=0, const Int_t *binMap=0, Int_t includeError=3, Bool_t clearHist=kTRUE) const
Get background into a histogram.
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.