138using std::ofstream, std::stringstream;
151 <<
"<!ELEMENT TUnfoldBinning (BinningNode)+ >\n"
152 <<
"<!ELEMENT BinningNode ((Bins?,BinningNode*)|(Binfactorlist?,Axis,BinningNode*)) >\n"
153 <<
"<!ATTLIST BinningNode name ID #REQUIRED firstbin CDATA \"-1\"\n"
154 <<
" factor CDATA \"1.\">\n"
155 <<
"<!ELEMENT Axis ((Bin+,Axis?)|(Axis)) >\n"
156 <<
"<!ATTLIST Axis name CDATA #REQUIRED lowEdge CDATA #REQUIRED>\n"
157 <<
"<!ELEMENT Binfactorlist (#PCDATA)>\n"
158 <<
"<!ATTLIST Binfactorlist length CDATA #REQUIRED>\n"
159 <<
"<!ELEMENT Bin EMPTY>\n"
160 <<
"<!ATTLIST Bin width CDATA #REQUIRED location CDATA #IMPLIED\n"
161 <<
" center CDATA #IMPLIED repeat CDATA #IMPLIED>\n"
162 <<
"<!ELEMENT Bins (BinLabel)* >\n"
163 <<
"<!ATTLIST Bins nbin CDATA #REQUIRED>\n"
164 <<
"<!ELEMENT BinLabel EMPTY>\n"
165 <<
"<!ATTLIST BinLabel index CDATA #REQUIRED name CDATA #REQUIRED>\n";
200 node->GetAttributes()) {
202 TIterator *i=node->GetAttributes()->MakeIterator();
231 const char *
name=
nullptr;
235 const char *binNames=
nullptr;
258 if(
child->GetAttributes()) {
259 i=
child->GetAttributes()->MakeIterator();
271 binName=binName->GetNextNode()) {
274 i=binName->GetAttributes()->MakeIterator();
275 const char *binLabelName=
nullptr;
283 binLabelName=
attr->GetValue();
286 if((
index>=0)&&(binLabelName)) {
296 if(theBinNames.
At(ii)) {
297 for(
Int_t k=0;k<emptyName;k++) binNameList+=
";";
304 if(binNameList.
Length()>0) {
305 binNames=binNameList;
322 i=
child->GetAttributes()->MakeIterator();
330 if(
length==
r->GetDistributionNumberOfBins()) {
334 stringstream readFactors(
text);
335 for(;nread<
length;nread++) {
336 readFactors>> (*perBinFactors)(nread);
337 if(readFactors.fail())
break;
342 child->Error(
"ImportXMLNode",
"while reading per-bin factors"
343 " node=%s length=%d (expected %d)",
r->GetName(),
344 length,
r->GetDistributionNumberOfBins());
345 }
else if(nread!=
length) {
346 child->Error(
"ImportXMLNode",
"while reading per-bin factors"
347 " TUnfoldBinning=%s expected %d found %d",
349 delete perBinFactors;
350 perBinFactors=
nullptr;
356 r->SetBinFactor(factor,perBinFactors);
363 child->GetAttributes()) {
365 r->AddBinning(childBinning);
388 const char *axisName=
nullptr;
395 axisName=
attr->GetValue();
411 i=
child->GetAttributes()->MakeIterator();
416 isUnderflow= !attText.
CompareTo(
"underflow");
417 isOverflow= !attText.
CompareTo(
"overflow");
420 repeat=attText.
Atof();
425 "attribute repeat=%d changed to repeat=1",
429 if((isUnderflow || isOverflow)&&(repeat!=1)) {
430 node->
Error(
"AddAxisXML",
431 "underflow/overflow can not have repeat!=1 attribute");
433 if(isUnderflow || isOverflow) {
434 underflow |= isUnderflow;
435 overflow |= isOverflow;
438 Int_t iBin1=iBin0+repeat;
441 i=
child->GetAttributes()->MakeIterator();
449 node->
Error(
"AddAxisXML",
450 "bin withd can not be smaller than zero");
452 for(
int iBin=iBin0;iBin<iBin1;iBin++) {
453 binEdges[iBin]=binEdges[iBin0-1]+(iBin-iBin0+1)*binWidth;
484 out<<
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"
485 <<
"<!DOCTYPE TUnfoldBinning SYSTEM \"tunfoldbinning.dtd\">\n"
486 <<
"<TUnfoldBinning>\n";
489 out<<trailer<<
"<BinningNode name=\""<<binning.
GetName()<<
"\" firstbin=\""
495 out<<trailer<<
" <Binfactorlist length=\""
498 if(!(i % 10)) out<<trailer<<
" ";
503 out<<trailer<<
" </Binfactorlist>\n";
511 out<<trailer<<
" <BinLabel index=\""<<i<<
"\" name=\""
512 <<
name->GetString()<<
"\" />\n";
514 out<<trailer<<
" </Bins>\n";
520 <<
"\" lowEdge=\""<<(*edges)[0]<<
"\">\n";
522 out<<axisTrailer<<
" <Bin location=\"underflow\" width=\""
530 for(
Int_t j=i+1;j<edges->GetNrows()-1;j++) {
531 double xEnd=(j-i+1)*
width+(*edges)[i];
532 double xCent=center+(j-i)*
width;
542 out<<axisTrailer<<
" <Bin width=\""
543 <<
width<<
"\" center=\""<<center<<
"\" />\n";
545 out<<axisTrailer<<
" <Bin repeat=\""<<repeat
546 <<
"\" width=\""<<
width<<
"\" center=\""<<center<<
"\" />\n";
551 out<<axisTrailer<<
" <Bin location=\"overflow\" width=\""
558 out<<axisTrailer<<
"</Axis>\n";
565 out<<trailer<<
"</BinningNode>\n";
567 out<<
"</TUnfoldBinning>\n";
569 return out.fail() ? 0 : 1;
581 ofstream outFile(fileName);
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.
XML interfate to binning schemes, for use with the unfolding algorithm TUnfoldDensity.
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
Binning schemes for use with the unfolding algorithm TUnfoldDensity.
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 * 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.