a Code for the Combination of Indirect and Direct Constraints on High Energy Physics Models Logo
SlhaValuePlotter.hpp
Go to the documentation of this file.
1/*
2 * SlhaValuePlotter.hpp
3 *
4 * Created on: Mar 22, 2015
5 * Author: Ben O'Leary (benjamin.oleary@gmail.com)
6 * Copyright 2015 Ben O'Leary
7 *
8 * This file is part of LesHouchesParserClasses, released under the
9 * GNU General Public License. Please see the accompanying
10 * README.LHPC_CPP.txt file for a full list of files, brief documentation
11 * on how to use these classes, and further details on the license.
12 */
13
14#ifndef SLHAVALUEPLOTTER_HPP_
15#define SLHAVALUEPLOTTER_HPP_
16
17#include <cstdlib>
18#include <exception>
19#include <fstream>
20#include <string>
21#include <vector>
22#include <list>
23#include <map>
25#include "../SLHA/BlockTypes.hpp"
26#include "../SSP/LineData.hpp"
27#include "SlhaValuePlotLine.hpp"
31
32namespace LHPC
33{
34 namespace SLHA
35 {
37 {
38 public:
39 SlhaValuePlotter(std::string const& xmlInputFilename);
41
42 // This parses the child elements from the XML elements parsed from the
43 // file given to the constructor, and then plots the values from the SLHA
44 // file given by the XML file.
45 void plotValues( std::string slhaFilename,
46 std::string plotFilename,
47 bool const shouldCleanUp );
48
49
50 protected:
51 static std::string const gnuplotDataFileName;
52 static std::string const gnuplotCommandFileName;
53 static std::string const gnuplotTexBaseName;
54 static std::string const fullLatexBaseName;
55 static double const flatBitWidth;
56 static double const automaticScaleFactor;
57 static double const labelSeparationShuffleFactor;
59
60 std::string generalControlsXml;
62
67 std::string verticalAxisLabel;
72 double labelWidth;
73
74 std::string gnuplotCommand;
75 std::string latexCommand;
76 std::string dvipsCommand;
77 std::string ps2epsCommand;
78 std::string deleteCommand;
79 std::string moveCommand;
80
81 std::vector< std::list< SlhaValuePlotLine > > columnSet;
85
86 std::vector< SlhaValueLineColoring* > lineColoringPointers;
87
88 // This parses the SLHA file and the plot output file names from
89 // specificInputXml.
91
92 // This parses the label settings and commands from generalControlsXml.
94
95 // This parses the column definitions into columnSet.
96 void createColumns( std::string slhaFilename );
97
98 // This sorts every column in columnSet to arrange the lines in order,
99 // and returns the largest vertical value found.
100 double sortColumns();
101
102 // This sets up the maximum vertical range, and takes care of labels for
103 // lines which would be above the upper limit.
104 void setUpVerticalRange( double const largestValueFound );
105
106 // This tries to move all the labels up or down until they are all
107 // separated by ( labelHeightFractionOfRange * verticalAxisUpperRange ).
108 void floatLabels();
109
110 // This prepares input files for gnuplot to plot the lines.
112
113 // This executes the commands to run gnuplot etc. on the prepared input
114 // files.
115 void executeCommands( std::string plotFilename,
116 bool const shouldCleanUp );
117
118 // This adds a new column to columnSet based on the given definition.
119 void addNewColumn( std::string columnDefinitionXml,
121
122 // This adds a new column line to the last column in columnSet based on
123 // the given definition.
124 void addColumnLine( std::string lineDefinitionXml,
126
127 // This creates an instance of a class derived from SlhaValueLineColoring
128 // with "new" and returns a pointer to it, also storing it in
129 // lineColoringPointers so that it can be correctly deleted later.
131 getNewLineColoring( std::string const& drawType,
132 std::string const& xmlBody,
134
135 // This tries to move all the labels up or down until they are all
136 // separated by ( labelHeightFractionOfRange * verticalAxisUpperRange ).
137 void
138 floatLabelsFromOneSide( std::vector< SlhaValuePlotLine* >& labelSet );
139 };
140
141
142
143
144
145 // This parses the child elements from the XML elements parsed from the
146 // file given to the constructor, and then plots the values from the SLHA
147 // file given by the XML file.
148 inline void SlhaValuePlotter::plotValues( std::string slhaFilename,
149 std::string plotFilename,
150 bool const shouldCleanUp )
151 {
153 createColumns( slhaFilename );
154 double const largestValue( sortColumns() );
155 setUpVerticalRange( largestValue );
156 floatLabels();
158 executeCommands( plotFilename,
159 shouldCleanUp );
160 }
161
162 // This parses the column definitions into columnSet.
163 inline void SlhaValuePlotter::createColumns( std::string slhaFilename )
164 {
165 LHPC::SlhaSimplisticInterpreter slhaParser( slhaFilename );
166
167 BOL::AsciiXmlParser xmlParser;
168 if( xmlParser.loadString( columnDefinitionsXml ) )
169 {
170 while( xmlParser.readNextElement() )
171 {
172 if( xmlParser.currentElementNameMatches( "ColumnDefinition" ) )
173 {
175 slhaParser );
176 }
177 }
178 }
179 else
180 {
181 throw std::runtime_error( "Could not parse <ColumnDefinitions>." );
182 }
183 }
184
185 // This sorts every column in columnSet to arrange the lines in order,
186 // and then notes the largest vertical value found.
188 {
189 double largestValue( 0.0 );
190 for( std::vector< std::list< SlhaValuePlotLine > >::iterator
191 whichColumn( columnSet.begin() );
192 whichColumn < columnSet.end();
193 ++whichColumn )
194 {
195 whichColumn->sort(&(SlhaValuePlotLine::lowToHigh));
196 if( whichColumn->back().getValue() > largestValue )
197 {
198 largestValue = whichColumn->back().getValue();
199 }
200 }
201 return largestValue;
202 }
203
204 // This creates an instance of a class derived from SlhaValueLineColoring
205 // with "new" and returns a pointer to it, also storing it in
206 // lineColoringPointers so that it can be correctly deleted later.
208 SlhaValuePlotter::getNewLineColoring( std::string const& drawType,
209 std::string const& xmlBody,
211 {
212 if( drawType.compare( "SingleColor" ) == 0 )
213 {
214 lineColoringPointers.push_back( new SlhaValueSingleColor( xmlBody ) );
215 }
216 else if( drawType.compare( "ColoredSegments" ) == 0 )
217 {
218 lineColoringPointers.push_back( new SlhaValueColoredSegments( xmlBody,
220 slhaParser ) );
221 }
222 else
223 {
224 throw std::runtime_error( "Unknown \"DrawType\" in <LineColor> ("
225 + drawType + ")." );
226 }
227 return lineColoringPointers.back();
228 }
229
230 } /* namespace SLHA */
231} /* namespace LHPC */
232
233#endif /* SLHAVALUEPLOTTER_HPP_ */
bool loadString(std::string const stringToParse)
bool currentElementNameMatches(std::string const &comparisonString) const
std::string getTrimmedCurrentElementContent() const
static bool lowToHigh(SlhaValuePlotLine const &firstLine, SlhaValuePlotLine const &secondLine)
static double const flatBitWidth
void addColumnLine(std::string lineDefinitionXml, LHPC::SlhaSimplisticInterpreter &slhaParser)
void createColumns(std::string slhaFilename)
static double const labelSeparationShuffleFactor
static std::string const fullLatexBaseName
SlhaValuePlotter(std::string const &xmlInputFilename)
std::vector< SlhaValueLineColoring * > lineColoringPointers
static std::string const gnuplotDataFileName
void executeCommands(std::string plotFilename, bool const shouldCleanUp)
static int const maximumLabelFloatingShuffles
void plotValues(std::string slhaFilename, std::string plotFilename, bool const shouldCleanUp)
static std::string const gnuplotTexBaseName
static double const automaticScaleFactor
static std::string const gnuplotCommandFileName
SlhaValueLineColoring * getNewLineColoring(std::string const &drawType, std::string const &xmlBody, LHPC::SlhaSimplisticInterpreter &slhaParser)
void addNewColumn(std::string columnDefinitionXml, LHPC::SlhaSimplisticInterpreter &slhaParser)
void setUpVerticalRange(double const largestValueFound)
std::vector< std::list< SlhaValuePlotLine > > columnSet
void floatLabelsFromOneSide(std::vector< SlhaValuePlotLine * > &labelSet)