00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include <iostream>
00014 #include <fstream>
00015 #include <iomanip>
00016 #include <map>
00017 #include <TDOMParser.h>
00018 #include <TXMLDocument.h>
00019 #include "TUnfoldBinningXML.h"
00020
00021 using namespace std;
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048 void PrintBinMap(TUnfoldBinning *binning,const char * where,
00049 const Int_t *binMap);
00050
00051 void testUnfold6()
00052 {
00053 TDOMParser parser;
00054 ofstream dtdFile("tunfoldbinning.dtd");
00055 TUnfoldBinningXML::WriteDTD(dtdFile);
00056 dtdFile.close();
00057 Int_t error=parser.ParseFile("testUnfold6binning.xml");
00058 if(error) cout<<"error="<<error<<" from TDOMParser\n";
00059 TXMLDocument const *XMLdocument=parser.GetXMLDocument();
00060 TUnfoldBinningXML *binning=
00061 TUnfoldBinningXML::ImportXML(XMLdocument,"binning");
00062 if(!binning) {
00063 cout<<"error: can not read binning (document empty?)\n";
00064 } else {
00065 cout<<"Binning scheme:\n =================================\n";
00066 binning->PrintStream(cout);
00067 Int_t *binMap=binning->CreateEmptyBinMap();
00068 PrintBinMap(binning,"CreateEmptyBinMap",binMap);
00069
00070 TUnfoldBinning const *branch1=binning->FindNode("branch1");
00071 branch1->FillBinMap1D(binMap,"y[C]",2);
00072 PrintBinMap(binning,"branch1->FillBinMap1D(...,\"y[C]\",...,2)",binMap);
00073
00074 delete binMap; binMap=binning->CreateEmptyBinMap();
00075 TUnfoldBinning const *branch2=binning->FindNode("branch2");
00076 branch2->FillBinMap1D(binMap,"x[C]",7);
00077 PrintBinMap(binning,"branch2->FillBinMap1D(...,\"x[C]\",...,7)",binMap);
00078
00079 delete binMap; binMap=binning->CreateEmptyBinMap();
00080 binning->FillBinMap1D(binMap,"y[C]",1);
00081 PrintBinMap(binning,"binning->FillBinMap1D(...,\"y[C]\",...,1)",binMap);
00082
00083 binning->ExportXML("testUnfold6.out.xml");
00084 }
00085 }
00086
00087 void PrintBinMap(TUnfoldBinning *binning,const char * where,
00088 const Int_t *binMap) {
00089
00090 cout<<"\n"<<where<<"\n=======================\n";
00091 cout<<"global bin:";
00092 for(int i=0;i<binning->GetEndBin()+1;i++) {
00093 cout<<setw(3)<<i;
00094 }
00095 cout<<"\n";
00096 cout<<"mapped to: ";
00097 for(int i=0;i<binning->GetEndBin()+1;i++) {
00098 cout<<setw(3)<<binMap[i];
00099 }
00100 cout<<"\n";
00101 map<int,vector<int> > destBin;
00102 for(int i=0;i<binning->GetEndBin()+1;i++) {
00103 destBin[binMap[i]].push_back(i);
00104 }
00105 bool printed=false;
00106 for(map<int,vector<int> >::const_iterator i=destBin.begin();i!=destBin.end();i++) {
00107 if((*i).first>=0) {
00108 if(!printed) {
00109 cout<<"\ndest |contributing bins\n"
00110 <<"=====+======================================\n";
00111 printed=true;
00112 }
00113 for(size_t j=0;j<(*i).second.size();j++) {
00114 cout<<setw(4)<<(*i).first<<" |";
00115 cout<<setw(3)<<binning->GetBinName((*i).second[j])<<"\n";
00116 }
00117 cout<<"=====+======================================\n";
00118 }
00119 }
00120 }