138using std::ofstream, std::stringstream;
150 <<
"<!ELEMENT TUnfoldBinning (BinningNode)+ >\n"
151 <<
"<!ELEMENT BinningNode ((Bins?,BinningNode*)|(Binfactorlist?,Axis,BinningNode*)) >\n"
152 <<
"<!ATTLIST BinningNode name ID #REQUIRED firstbin CDATA \"-1\"\n"
153 <<
" factor CDATA \"1.\">\n"
154 <<
"<!ELEMENT Axis ((Bin+,Axis?)|(Axis)) >\n"
155 <<
"<!ATTLIST Axis name CDATA #REQUIRED lowEdge CDATA #REQUIRED>\n"
156 <<
"<!ELEMENT Binfactorlist (#PCDATA)>\n"
157 <<
"<!ATTLIST Binfactorlist length CDATA #REQUIRED>\n"
158 <<
"<!ELEMENT Bin EMPTY>\n"
159 <<
"<!ATTLIST Bin width CDATA #REQUIRED location CDATA #IMPLIED\n"
160 <<
" center CDATA #IMPLIED repeat CDATA #IMPLIED>\n"
161 <<
"<!ELEMENT Bins (BinLabel)* >\n"
162 <<
"<!ATTLIST Bins nbin CDATA #REQUIRED>\n"
163 <<
"<!ELEMENT BinLabel EMPTY>\n"
164 <<
"<!ATTLIST BinLabel index CDATA #REQUIRED name CDATA #REQUIRED>\n";
199 node->GetAttributes()) {
201 TIterator *i=node->GetAttributes()->MakeIterator();
230 const char *
name=
nullptr;
234 const char *binNames=
nullptr;
257 if(
child->GetAttributes()) {
258 i=
child->GetAttributes()->MakeIterator();
270 binName=binName->GetNextNode()) {
273 i=binName->GetAttributes()->MakeIterator();
274 const char *binLabelName=
nullptr;
282 binLabelName=
attr->GetValue();
285 if((
index>=0)&&(binLabelName)) {
295 if(theBinNames.
At(ii)) {
296 for(
Int_t k=0;k<emptyName;k++) binNameList+=
";";
303 if(binNameList.
Length()>0) {
304 binNames=binNameList;
321 i=
child->GetAttributes()->MakeIterator();
329 if(
length==
r->GetDistributionNumberOfBins()) {
333 stringstream readFactors(
text);
334 for(;nread<
length;nread++) {
335 readFactors>> (*perBinFactors)(nread);
336 if(readFactors.fail())
break;
341 child->Error(
"ImportXMLNode",
"while reading per-bin factors"
342 " node=%s length=%d (expected %d)",
r->GetName(),
343 length,
r->GetDistributionNumberOfBins());
344 }
else if(nread!=
length) {
345 child->Error(
"ImportXMLNode",
"while reading per-bin factors"
346 " TUnfoldBinning=%s expected %d found %d",
348 delete perBinFactors;
349 perBinFactors=
nullptr;
355 r->SetBinFactor(factor,perBinFactors);
362 child->GetAttributes()) {
364 r->AddBinning(childBinning);
387 const char *axisName=
nullptr;
394 axisName=
attr->GetValue();
410 i=
child->GetAttributes()->MakeIterator();
415 isUnderflow= !attText.
CompareTo(
"underflow");
416 isOverflow= !attText.
CompareTo(
"overflow");
419 repeat=attText.
Atof();
424 "attribute repeat=%d changed to repeat=1",
428 if((isUnderflow || isOverflow)&&(repeat!=1)) {
429 node->
Error(
"AddAxisXML",
430 "underflow/overflow can not have repeat!=1 attribute");
432 if(isUnderflow || isOverflow) {
433 underflow |= isUnderflow;
434 overflow |= isOverflow;
437 Int_t iBin1=iBin0+repeat;
440 i=
child->GetAttributes()->MakeIterator();
448 node->
Error(
"AddAxisXML",
449 "bin withd can not be smaller than zero");
451 for(
int iBin=iBin0;iBin<iBin1;iBin++) {
452 binEdges[iBin]=binEdges[iBin0-1]+(iBin-iBin0+1)*binWidth;
483 out<<
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"
484 <<
"<!DOCTYPE TUnfoldBinning SYSTEM \"tunfoldbinning.dtd\">\n"
485 <<
"<TUnfoldBinning>\n";
488 out<<trailer<<
"<BinningNode name=\""<<binning.
GetName()<<
"\" firstbin=\""
494 out<<trailer<<
" <Binfactorlist length=\""
497 if(!(i % 10)) out<<trailer<<
" ";
502 out<<trailer<<
" </Binfactorlist>\n";
510 out<<trailer<<
" <BinLabel index=\""<<i<<
"\" name=\""
511 <<
name->GetString()<<
"\" />\n";
513 out<<trailer<<
" </Bins>\n";
519 <<
"\" lowEdge=\""<<(*edges)[0]<<
"\">\n";
521 out<<axisTrailer<<
" <Bin location=\"underflow\" width=\""
529 for(
Int_t j=i+1;j<edges->GetNrows()-1;j++) {
530 double xEnd=(j-i+1)*
width+(*edges)[i];
531 double xCent=center+(j-i)*
width;
541 out<<axisTrailer<<
" <Bin width=\""
542 <<
width<<
"\" center=\""<<center<<
"\" />\n";
544 out<<axisTrailer<<
" <Bin repeat=\""<<repeat
545 <<
"\" width=\""<<
width<<
"\" center=\""<<center<<
"\" />\n";
550 out<<axisTrailer<<
" <Bin location=\"overflow\" width=\""
557 out<<axisTrailer<<
"</Axis>\n";
564 out<<trailer<<
"</BinningNode>\n";
566 out<<
"</TUnfoldBinning>\n";
568 return out.fail() ? 0 : 1;
580 ofstream outFile(fileName);
bool Bool_t
Boolean (0=false, 1=true) (bool).
int Int_t
Signed integer 4 bytes (int).
double Double_t
Double 8 bytes.
static void indent(ostringstream &buf, int indent_level)
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h length
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t child
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t attr
Option_t Option_t TPoint TPoint const char text
TVectorT< Double_t > TVectorD
Array of doubles (64 bits per element).
void Set(Int_t n) override
Set size of this array to n doubles.
const Double_t * GetArray() const
Iterator abstract base class.
virtual TObject * Next()=0
TIterator * MakeIterator(Bool_t dir=kIterForward) const override
Return a list iterator.
const char * GetName() const override
Returns name of object.
Int_t GetEntriesFast() const
virtual void AddAtAndExpand(TObject *obj, Int_t idx)
Add object at position idx.
TObject * At(Int_t idx) const override
Collectable string class.
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
Int_t Atoi() const
Return integer value of string.
Double_t Atof() const
Return floating-point value contained in string.
static Int_t ExportXML(const TUnfoldBinning &binning, std::ostream &out, Bool_t writeHeader, Bool_t writeFooter, Int_t indent=0)
export a binning scheme to a stream in XML format
void AddAxisXML(TXMLNode *node)
import axis from XML node
static TUnfoldBinningXML * ImportXMLNode(TXMLNode *node)
recursively import one node from the XML tree
static TUnfoldBinningXML * ImportXML(const TXMLDocument *document, const char *name)
import a binning scheme from an XML file
static void WriteDTD(const char *fileName="tunfoldbinning.dtd")
write dtd file
TUnfoldBinningXML(const char *name=nullptr, Int_t nBins=0, const char *binNames=nullptr)
construct a new binning scheme, for use with the root streamer
Bool_t HasOverflow(int axis) const
check whether the axis has an overflow bin
virtual Double_t GetDistributionOverflowBinWidth(Int_t axis) const
return bin width assigned to the overflow bin
Int_t GetDistributionDimension(void) const
query dimension of this node's distribution
virtual Double_t GetDistributionUnderflowBinWidth(Int_t axis) const
return bin width assigned to the underflow bin
Int_t GetDistributionNumberOfBins(void) const
number of bins in the distribution possibly including under/overflow
Double_t GetGlobalFactor(void) const
return global scaling factor for this node
Bool_t HasUnconnectedBins(void) const
check whether there are bins but no axis
virtual Double_t GetBinFactor(Int_t iBin) const
return scaling factor for the given global bin number
Bool_t HasUnderflow(int axis) const
check whether an axis has an underflow bin
virtual Double_t GetDistributionBinCenter(Int_t axis, Int_t bin) const
return bin center for a given axis and bin number
virtual Bool_t IsBinFactorGlobal(void) const
check whether there is only a global scaling factor for this node
TString GetDistributionAxisLabel(Int_t axis) const
get name of an axis
const TObjString * GetUnconnectedBinName(Int_t bin) const
return the bin names of unconnected bins
TVectorD const * GetDistributionBinning(Int_t axis) const
get vector of bin borders for one axis
Bool_t AddAxis(const char *name, Int_t nBins, const Double_t *binBorders, Bool_t hasUnderflow, Bool_t hasOverflow)
add an axis with the specified bin borders
Int_t GetStartBin(void) const
first bin of this node
TUnfoldBinning(const char *name=nullptr, Int_t nBins=0, const char *binNames=nullptr)
create a new node without axis
TUnfoldBinning const * GetChildNode(void) const
first daughter node
static const char * GetTUnfoldVersion(void)
return a string describing the TUnfold version
TXMLAttribute is the attribute of an Element.
TXMLDocument contains a pointer to an xmlDoc structure, after the parser returns a tree built during ...
TXMLNode * GetRootNode() const
Returns the root element node.
TXMLNode contains a pointer to xmlNode, which is a node under the DOM tree.
TList * GetAttributes()
Returns a list of node's attribute if any, returns 0 if no attribute.
TXMLNode * GetNextNode()
Returns the next sibling XMLNode in the DOM tree, if any return 0 if no next node.
TXMLNode * GetChildren()
Returns the node's child if any, returns 0 if no child.
const char * GetNodeName() const
Returns the node's name.
EXMLElementType GetNodeType() const
Returns the node's type.
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.