143 :
TUnfold(hist_A,histmap,regmode,constraint)
156 fAoutside =
new TMatrixD(GetNx(),2);
159 fDAinColRelSq =
new TMatrixD(GetNx(),1);
161 Int_t nmax=GetNx()*GetNy();
167 for (
Int_t ix = 0; ix < GetNx(); ix++) {
168 Int_t ibinx = fXToHist[ix];
169 Double_t sum_sq= fSumOverY[ix]*fSumOverY[ix];
170 for (
Int_t ibiny = 0; ibiny <= GetNy()+1; ibiny++) {
172 if (histmap == kHistMapOutputHoriz) {
180 (*fDAinColRelSq)(ix,0) += normerr_sq;
184 if (histmap == kHistMapOutputHoriz) {
189 }
else if(ibiny==GetNy()+1) {
191 if (histmap == kHistMapOutputHoriz) {
198 rowDAinRelSq[da_nonzero]=ibiny-1;
199 colDAinRelSq[da_nonzero] = ix;
200 dataDAinRelSq[da_nonzero] = normerr_sq;
201 if(dataDAinRelSq[da_nonzero]>0.0) da_nonzero++;
206 fDAinRelSq = CreateSparseMatrix(GetNy(),GetNx(),da_nonzero,
207 rowDAinRelSq,colDAinRelSq,dataDAinRelSq);
209 DeleteMatrix(&fDAinColRelSq);
211 delete[] rowDAinRelSq;
212 delete[] colDAinRelSq;
213 delete[] dataDAinRelSq;
225 if(fSysIn->FindObject(name)) {
226 Error(
"AddSysError",
"Source %s given twice, ignoring 2nd call.\n",name);
233 Int_t nmax= GetNx()*GetNy();
238 for (
Int_t ix = 0; ix < GetNx(); ix++) {
239 Int_t ibinx = fXToHist[ix];
241 for(
Int_t loop=0;loop<2;loop++) {
242 for (
Int_t ibiny = 0; ibiny <= GetNy()+1; ibiny++) {
245 if (histmap == kHistMapOutputHoriz) {
251 if(mode!=kSysErrModeMatrix) {
253 if((ibiny>0)&&(ibiny<=GetNy())) {
254 z0=aCopy(ibiny-1,ix)*fSumOverY[ix];
255 }
else if(ibiny==0) {
256 z0=(*fAoutside)(ix,0);
258 z0=(*fAoutside)(ix,1);
260 if(mode==kSysErrModeShift) {
262 }
else if(mode==kSysErrModeRelative) {
270 if((ibiny>0)&&(ibiny<=GetNy())) {
276 data[nmax]=z/sum-aCopy(ibiny-1,ix);
280 if(data[nmax] != 0.0) nmax++;
288 "source %s has no influence and has not been added.\n",name);
291 nmax,rows,cols,data);
316 Warning(
"DoBackgroundSubtraction",
317 "inverse error matrix from user input,"
318 " not corrected for background");
326 for(key=bgrPtr.
Next();key;key=bgrPtr.
Next()) {
329 ((
const TPair *)*bgrPtr)->Value()
335 (*fY)(i,0) -= (*bgr)(i,0);
351 for(
Int_t k=vyydata_rows[i];k<vyydata_rows[i+1];k++) {
352 if(vyydata_data[k]>0.0) {
354 usedBin[vyydata_cols[k]]++;
361 for(key=bgrErrUncorrSqPtr.
Next();key;
362 key=bgrErrUncorrSqPtr.
Next()) {
365 ((
const TPair *)*bgrErrUncorrSqPtr)->Value()
372 if(!usedBin[yi])
continue;
373 vyy(yi,yi) +=(*bgrerruncorrSquared)(yi,0);
380 for(key=bgrErrScalePtr.
Next();key;key=bgrErrScalePtr.
Next()) {
383 ((
const TPair *)*bgrErrScalePtr)->Value()
390 if(!usedBin[yi])
continue;
392 if(!usedBin[yj])
continue;
393 vyy(yi,yj) +=(*bgrerrscale)(yi,0)* (*bgrerrscale)(yj,0);
406 Fatal(
"DoBackgroundSubtraction",
"No input vector defined");
412 const TH2 *hist_vyy_inv)
454 if(fBgrIn->FindObject(name)) {
455 Error(
"SubtractBackground",
"Source %s given twice, ignoring 2nd call.\n",
461 for(
Int_t row=0;row<GetNy();row++) {
463 (*bgrErrUncSq)(row,0) =
465 (*bgrErrCorr)(row,0) = scale_error*bgr->
GetBinContent(row+1);
468 fBgrErrUncorrInSq->Add(
new TObjString(name),bgrErrUncSq);
469 fBgrErrScaleIn->Add(
new TObjString(name),bgrErrCorr);
471 DoBackgroundSubtraction();
473 Info(
"SubtractBackground",
474 "Background subtraction prior to setting input data");
480 (
TH1 *bgrHist,
const char *bgrSource,
const Int_t *binMap,
484 ClearHistogram(bgrHist);
490 for(key=bgrPtr.
Next();key;key=bgrPtr.
Next()) {
492 if(bgrSource && bgrName.
CompareTo(bgrSource))
continue;
495 ((
const TPair *)*bgrPtr)->Value()
497 fBgrIn->GetValue(bgrName)
500 for(
Int_t i=0;i<GetNy();i++) {
501 Int_t destBin=binMap[i];
508 if(includeError &1) {
509 TMapIter bgrErrUncorrSqPtr(fBgrErrUncorrInSq);
510 for(key=bgrErrUncorrSqPtr.
Next();key;key=bgrErrUncorrSqPtr.
Next()) {
512 if(bgrSource && bgrName.
CompareTo(bgrSource))
continue;
515 ((
const TPair *)*bgrErrUncorrSqPtr)->Value()
517 fBgrErrUncorrInSq->GetValue(((
const TObjString *)key)
521 for(
Int_t i=0;i<GetNy();i++) {
522 Int_t destBin=binMap[i];
525 ((*bgrerruncorrSquared)(i,0)+
530 if(includeError & 2) {
531 TMapIter bgrErrScalePtr(fBgrErrScaleIn);
532 for(key=bgrErrScalePtr.
Next();key;key=bgrErrScalePtr.
Next()) {
534 if(bgrSource && bgrName.
CompareTo(bgrSource))
continue;
537 ((
const TPair *)*bgrErrScalePtr)->Value()
539 fBgrErrScaleIn->GetValue(((
const TObjString *)key)->GetString())
542 for(
Int_t i=0;i<GetNy();i++) {
543 Int_t destBin=binMap[i];
544 bgrHist->
SetBinError(destBin,hypot((*bgrerrscale)(i,0),
563 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,20,00)
579 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,20,00)
663 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,20,00)
713 ErrorMatrixToHist(ematrix,fEmatUncorrX,binMap,clearEmat);
812 if(fDAinColRelSq && fDAinRelSq) {
815 ScaleColumnsByVector(M1A_Z1,GetDXDAZ(1));
817 ScaleColumnsByVector(M1Rsq_Z1,GetDXDAZ(1));
819 TMatrixDSparse *AtZ0 = MultiplyMSparseTranspMSparse(fA,GetDXDAZ(0));
821 MultiplyMSparseTranspMSparse(fDAinRelSq,GetDXDAZ(0));
825 ScaleColumnsByVector(F,AtZ0);
826 AddMSparse(F,-1.0,M1A_Z1);
830 ScaleColumnsByVector(G,RsqZ0);
831 AddMSparse(G,-1.0,M1Rsq_Z1);
832 DeleteMatrix(&M1A_Z1);
833 DeleteMatrix(&M1Rsq_Z1);
835 DeleteMatrix(&RsqZ0);
837 r=MultiplyMSparseMSparseTranspVector(F,F,fDAinColRelSq);
843 AddMSparse(r,-1.0,r1);
844 AddMSparse(r,-1.0,r2);
859 for(
int index=0;index<Z0sq_rows[Z0sq.
GetNrows()];index++) {
860 Z0sq_data[index] *= Z0sq_data[index];
863 TMatrixDSparse *Z0sqRsq=MultiplyMSparseTranspMSparse(fDAinRelSq,&Z0sq);
866 DeleteMatrix(&Z0sqRsq);
872 for(
int index=0;index<Z1sq_rows[Z1sq.
GetNrows()];index++) {
873 Z1sq_data[index] *= Z1sq_data[index];
878 TMatrixDSparse *r4=MultiplyMSparseMSparseTranspVector(m_1,m_1,Z1sqRsq);
879 DeleteMatrix(&Z1sqRsq);
883 (m_0,fDAinRelSq,GetDXDAZ(1));
885 ScaleColumnsByVector(H,GetDXDAZ(0));
893 AddMSparse(r,1.0,r3);
899 AddMSparse(r,1.0,r4);
900 AddMSparse(r,-1.0,r5);
901 AddMSparse(r,-1.0,r6);
922 TMatrixDSparse *dsysT_VYAx = MultiplyMSparseTranspMSparse(dsys,GetDXDAZ(0));
924 DeleteMatrix(&dsysT_VYAx);
925 TMatrixDSparse *dsys_X = MultiplyMSparseMSparse(dsys,GetDXDAZ(1));
927 DeleteMatrix(&dsys_X);
928 AddMSparse(delta,-1.0,delta2);
929 DeleteMatrix(&delta2);
958 (
TH1 *hist_delta,
const char *source,
const Int_t *binMap)
970 dx=MultiplyMSparseM(GetDXDY(),dy);
972 VectorMapToHist(hist_delta,dx,binMap);
1003 emat=MultiplyMSparseMSparseTranspVector(delta,delta,0);
1005 ErrorMatrixToHist(ematrix,emat,binMap,clearEmat);
1006 DeleteMatrix(&emat);
1023 emat=MultiplyMSparseMSparseTranspVector(dx,dx,0);
1026 ErrorMatrixToHist(ematrix,emat,binMap,clearEmat);
1027 DeleteMatrix(&emat);
1040 emat=MultiplyMSparseMSparseTranspVector(fDeltaSysTau,fDeltaSysTau,0);
1042 ErrorMatrixToHist(ematrix,emat,binMap,clearEmat);
1043 DeleteMatrix(&emat);
1053 GetEmatrixFromVyy(fVyyData,ematrix,binMap,clearEmat);
1069 emat=MultiplyMSparseMSparseTranspVector(GetDXDY(),GetDXDY(),dySquared);
1071 ErrorMatrixToHist(ematrix,emat,binMap,clearEmat);
1072 DeleteMatrix(&emat);
1087 em=MultiplyMSparseMSparseTranspVector(dxdyVyy,GetDXDY(),0);
1088 DeleteMatrix(&dxdyVyy);
1090 ErrorMatrixToHist(ematrix,em,binMap,clearEmat);
1104 for(key=sysErrPtr.
Next();key;key=sysErrPtr.
Next()) {
1125 for(key=sysErrPtr.
Next();key;key=sysErrPtr.
Next()) {
1128 ((
const TPair *)*sysErrPtr)->Value()
1163 for(key=sysErrPtr.
Next();key;key=sysErrPtr.
Next()) {
1166 ((
const TPair *)*sysErrPtr)->Value()
1202 if(vdy_rows[i+1]>vdy_rows[i]) {
1203 r += vdy_data[vdy_rows[i]] * dy(i,0);
1234 Fatal(
"ScaleColumnsByVector error",
1235 "matrix cols/vector rows %d!=%d OR vector cols %d !=1\n",
1246 for(
Int_t index_m=rows_m[i];index_m<rows_m[i+1];index_m++) {
1247 Int_t j=cols_m[index_m];
1248 Int_t index_v=rows_v[j];
1249 if(index_v<rows_v[j+1]) {
1250 data_m[index_m] *= data_v[index_v];
1252 data_m[index_m] =0.0;
1258 for(
Int_t index=rows_m[i];index<rows_m[i+1];index++) {
1259 data_m[index] *= (*v)(cols_m[index],0);
1273 for(
Int_t i=0;i<nbin+2;i++) {
1277 Int_t binMapSize = fHistToX.GetSize();
1280 for(
Int_t i=0;i<binMapSize;i++) {
1281 Int_t destBinI=binMap ? binMap[i] : i;
1282 Int_t srcBinI=fHistToX[i];
1283 if((destBinI>=0)&&(destBinI<nbin+2)&&(srcBinI>=0)) {
1284 Int_t index=delta_rows[srcBinI];
1285 if(index<delta_rows[srcBinI+1]) {
1286 c[destBinI]+=delta_data[index];
1291 for(
Int_t i=0;i<nbin+2;i++) {
void InitTUnfoldSys(void)
virtual Int_t GetEntries() const
TMatrixDSparse * fEmatUncorrX
static void DeleteMatrix(TMatrixD **m)
TMatrixDSparse * CreateSparseMatrix(Int_t nrow, Int_t ncol, Int_t nele, Int_t *row, Int_t *col, Double_t *data) const
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
virtual void ClearResults(void)
TMatrixDSparse * InvertMSparseSymmPos(const TMatrixDSparse *A, Int_t *rank) const
Double_t GetChi2Sys(void)
void Fatal(const char *location, const char *msgfmt,...)
void GetEmatrixInput(TH2 *ematrix, const Int_t *binMap=0, Bool_t clearEmat=kTRUE)
Collectable string class.
virtual const Element * GetMatrixArray() const
Bool_t GetDeltaSysSource(TH1 *hist_delta, const char *source, const Int_t *binMap=0)
void VectorMapToHist(TH1 *hist_delta, const TMatrixDSparse *delta, const Int_t *binMap)
virtual TMatrixDSparse * PrepareCorrEmat(const TMatrixDSparse *m1, const TMatrixDSparse *m2, const TMatrixDSparse *dsys)
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
TMatrixDSparse * fDAinRelSq
virtual void PrepareSysError(void)
void Add(TObject *obj)
This function may not be used (but we need to provide it since it is a pure virtual in TCollection)...
TUnfold is used to decompose a measurement y into several sources x given the measurement uncertainti...
void SetTauError(Double_t delta_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)
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)
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
const TMatrixDSparse * GetDXDtauSquared(void) const
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
TMatrixDSparse * MultiplyMSparseM(const TMatrixDSparse *a, const TMatrixD *b) const
void GetEmatrixSysUncorr(TH2 *ematrix, const Int_t *binMap=0, Bool_t clearEmat=kTRUE)
void ClearHistogram(TH1 *h, Double_t x=0.) const
unsigned int r3[N_CITIES]
TMatrixDSparse * fDeltaSysTau
void GetEmatrixSysBackgroundScale(TH2 *ematrix, const char *source, const Int_t *binMap=0, Bool_t clearEmat=kTRUE)
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)
const TMatrixDSparse * GetVxx(void) const
TMatrixDSparse * GetSummedErrorMatrixXX(void)
virtual void SetBinError(Int_t bin, Double_t error)
see convention for numbering bins in TH1::GetBin
TMatrixDSparse * GetSummedErrorMatrixYY(void)
void Error(const char *location, const char *msgfmt,...)
TMatrixTSparse< Double_t > TMatrixDSparse
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
TMatrixT< Double_t > TMatrixD
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)
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)
const TMatrixDSparse * GetAx(void) const
TString GetString() const
virtual const Int_t * GetRowIndexArray() const
Service class for 2-Dim histogram classes.
virtual TMatrixDSparse * PrepareUncorrEmat(const TMatrixDSparse *m1, const TMatrixDSparse *m2)
void GetEmatrixTotal(TH2 *ematrix, const Int_t *binMap=0)
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
Bool_t GetDeltaSysTau(TH1 *delta, const Int_t *binMap=0)
virtual ~TUnfoldSys(void)
void SubtractBackground(const TH1 *hist_bgr, const char *name, Double_t scale=1.0, Double_t scale_error=0.0)
TMatrixDSparse * fVyyData
Class used by TMap to store (key,value) pairs.
void GetEmatrixSysTau(TH2 *ematrix, const Int_t *binMap=0, Bool_t clearEmat=kTRUE)
virtual void ClearResults(void)
TMap implements an associative array of (key,value) pairs using a THashTable for efficient retrieval ...
TMatrixDSparse * fEmatUncorrAx
void AddSysError(const TH2 *sysError, const char *name, EHistMap histmap, ESysErrMode mode)
#define ROOT_VERSION(a, b, c)
Mother of all ROOT objects.
virtual const Int_t * GetColIndexArray() const
void AddMSparse(TMatrixDSparse *dest, Double_t f, const TMatrixDSparse *src) const
ClassImp(TUnfoldSys) TUnfoldSys
TUnfold is used to decompose a measurement y into several sources x given the measurement uncertainti...
TMatrixDSparse * MultiplyMSparseMSparse(const TMatrixDSparse *a, const TMatrixDSparse *b) const
TObject * Next()
Returns the next key from a map.
void ScaleColumnsByVector(TMatrixDSparse *m, const TMatrixTBase< Double_t > *v) const
const TMatrixDSparse * GetDXDAM(int i) const
Double_t Sqrt(Double_t x)
void GetRhoItotal(TH1 *rhoi, const Int_t *binMap=0, TH2 *invEmat=0)
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)
Double_t GetRhoIFromMatrix(TH1 *rhoi, const TMatrixDSparse *eOrig, const Int_t *binMap, TH2 *invEmat) const
virtual TObject * FindObject(const char *name) const
Must be redefined in derived classes.
Bool_t GetDeltaSysBackgroundScale(TH1 *delta, const char *source, const Int_t *binMap=0)
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.
TMatrixDSparse * MultiplyMSparseMSparseTranspVector(const TMatrixDSparse *m1, const TMatrixDSparse *m2, const TMatrixTBase< Double_t > *v) const
void GetBackground(TH1 *bgr, const char *bgrSource=0, const Int_t *binMap=0, Int_t includeError=3, Bool_t clearHist=kTRUE) const
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.