a Code for the Combination of Indirect and Direct Constraints on High Energy Physics Models Logo
SlhaBlock.hpp
Go to the documentation of this file.
1/*
2 * SlhaBlock.hpp
3 *
4 * Created on: Feb 1, 2012
5 * Author: Ben O'Leary (benjamin.oleary@gmail.com)
6 * Copyright 2012 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 SLHABLOCK_HPP_
15#define SLHABLOCK_HPP_
16
17#include <string>
22
23namespace LHPC
24{
25 namespace SLHA
26 {
27 /* issues for specific blocks:
28 * MODSEL: annoying mix of ints & doubles (everything but Q_max is an int).
29 * - set it as a string block & interpret with the general filters?
30 * - set it as a double block, but write a separate routine to
31 * write it in a way SPheno can understand?
32 * - set it as a double block, but get Werner to fix SPheno so it's
33 * not so silly?
34 * SPINFO: multiple lines with the same index.
35 * - leave it as a SlhaBlock, because it really has no useful
36 * information
37 * SPHENOINPUT: multiple lines with the same index.
38 * - leave it as a SlhaBlock, because it really has no
39 * useful information
40 * SPHENOCROSSSECTIONS: just stupid.
41 * - leave it as a SlhaBlock, to be interpreted by
42 * the general filters.
43 */
44
45
46 /* this is a class to hold a block from a file in the SLHA format, only
47 * interpreting it at the basic level: as set of strings. if multiple
48 * blocks with the same name but different scales are recorded, the copy
49 * with the lowest scale is defaulted to if no scale is given when seeking
50 * information.
51 * classes which interpret the strings further derive from this class.
52 */
53 template< class ValueClass, class BlockParser >
54 class SlhaBlock : public BaseSlhaBlock
55 {
56 public:
57 SlhaBlock( std::string const& blockName,
58 ValueClass const& defaultUnsetValue,
59 bool const isVerbose );
60 virtual
62
63 BlockParser&
64 operator[]( int whichScaleIndex );
65 /* the interpreters are indexed in the order in which they were
66 * read (or created). the index starts at 1 rather than 0, as well. if 0
67 * is given as the argument, the index corresponding to the copy with the
68 * lowest scale is used.
69 */
70 BlockParser const&
71 operator[]( int whichScaleIndex ) const;
72 // const version of above.
73 int
75 bool
76 hasRecordedScale( double const soughtScale,
77 int& indexForLowerScale,
78 int& indexForUpperScale,
79 double& fractionFromLowerScale );
80 /* this looks for the pair of blocks with energy scales closest to
81 * soughtScale.
82 * if there are no recorded copies of this block, none of the references
83 * given are changed & false is returned.
84 * if there is only one copy of the block, both indexForLowerScale &
85 * indexForUpperScale are set to 1, fractionFromLowerScale is set to NaN,
86 * & true is returned.
87 * if there are 2 or more copies of the block, indexForLowerScale &
88 * indexForUpperScale are set as described below, fractionFromLowerScale
89 * is set to be
90 * ( ( soughtScale - [ scale of copy with lower scale ] )
91 * / [ difference of copy scales ] ), & true is returned.
92 * fractionFromLowerScale will thus be between 0.0 & 1.0 if there are
93 * copies with scales above & below soughtScale, but may be negative if
94 * soughtScale is lower than the lowest scale of the copies, or greater
95 * than 1.0 if soughtScale is higher than the highest scale of the
96 * copies.
97 * since the copies of the block with different scales are not
98 * necessarily recorded in order of scale, indexForLowerScale will not
99 * necessarily be smaller in value than indexForUpperScale.
100 * indexForLowerScale & indexForUpperScale are set as follows:
101 * if soughtScale is lower than the lowest scale of the copies,
102 * indexForLowerScale is set to the index of the copy with lowest scale,
103 * & indexForUpperScale is set to the index of the copy with the next
104 * lowest scale.
105 * if soughtScale is higher than the highest scale of the copies,
106 * indexForUpperScale is set to the index of the copy with highest scale,
107 * & indexForLowerScale is set to the index of the copy with the next
108 * highest scale.
109 * otherwise, indexForLowerScale is set to the index of the copy with
110 * highest scale which is still lower than soughtScale, &
111 * indexForUpperScale is set to the index of the copy with lowest scale
112 * which is still higher than soughtScale.
113 */
114 virtual std::string const&
115 interpretAsString( bool onlyShowScalesGreaterThanZero = true );
116 /* derived classes should override this to form their strings directly
117 * from their data (because the block may be being used as a way of
118 * writing an input file in the SLHA format, or maybe because the
119 * original formatting was incorrect, as it is in most spectrum
120 * generators...). by default it just joins together the strings from
121 * blocksAsSingleStrings. each different-scale copy is concatenated. if
122 * onlyShowScalesGreaterThanZero is true, blocks with scales of 0.0 or
123 * less just do not have the "Q=" etc. printed.
124 */
125 virtual void
127 /* by default, PushedToObserver instances don't respond without a pushed
128 * value, but this is over-ridden to clear all the data that this block
129 * has interpreted or had assigned.
130 */
131 virtual void
133 // this adds a new BlockParser to dataBlocks & tells it to interpret
134 // pushedValue. it also sorts out scale indices.
135
136
137 protected:
138 bool const isVerbose;
139 ValueClass const defaultUnsetValue;
143 std::list< std::pair< int, double > > scaleOrderedIndices;
144 std::list< std::pair< int, double > >::iterator scaleIndexIterator;
146
147 virtual void
149 // derived classes can insert extra arguments to any new block
150 // interpreters by over-riding this.
151 };
152
153
154
155
156
157 template< class ValueClass, class BlockParser >
158 inline
160 std::string const& blockName,
161 ValueClass const& defaultUnsetValue,
162 bool const isVerbose ) :
163 BaseSlhaBlock( blockName ),
164 isVerbose( isVerbose ),
165 defaultUnsetValue( defaultUnsetValue ),
166 dataBlocks( 1 ),
167 lowestScaleIndex( 0 ),
168 hasHadPushSinceLastReset( true ),
169 scaleOrderedIndices(),
170 scaleIndexIterator(),
171 stringInterpretation( "" )
172 {
173 dataBlocks.getFront().setDefaultUnsetValue( defaultUnsetValue );
174 dataBlocks.getFront().setVerbosity( isVerbose );
175 }
176
177 template< class ValueClass, class BlockParser >
178 inline
180 {
181 // does nothing.
182 }
183
184
185 template< class ValueClass, class BlockParser >
186 inline BlockParser&
188 /* the interpreters are indexed in the order in which they were
189 * read (or created). the index starts at 1 rather than 0, as well. if 0
190 * is given as the argument, the index corresponding to the copy with the
191 * lowest scale is used.
192 */
193 {
194 if( 0 == whichScaleIndex )
195 {
196 return dataBlocks[ lowestScaleIndex ];
197 }
198 else
199 {
200 return dataBlocks[ (--whichScaleIndex) ];
201 }
202 }
203
204 template< class ValueClass, class BlockParser >
205 inline BlockParser const&
207 int whichScaleIndex ) const
208 // const version of above.
209 {
210 if( 0 == whichScaleIndex )
211 {
212 return dataBlocks[ lowestScaleIndex ];
213 }
214 else
215 {
216 return dataBlocks[ (--whichScaleIndex) ];
217 }
218 }
219
220 template< class ValueClass, class BlockParser >
221 inline int
223 ) const
224 {
225 if( hasHadPushSinceLastReset )
226 {
227 return dataBlocks.getSize();
228 }
229 else
230 {
231 return 0;
232 }
233 }
234
235 template< class ValueClass, class BlockParser >
236 inline bool
238 double const soughtScale,
239 int& indexForLowerScale,
240 int& indexForUpperScale,
241 double& fractionFromLowerScale )
242 /* this looks for the pair of blocks with energy scales closest to
243 * soughtScale.
244 * if there are no recorded copies of this block, none of the references
245 * given are changed & false is returned.
246 * if there is only one copy of the block, both indexForLowerScale &
247 * indexForUpperScale are set to 1, fractionFromLowerScale is set to NaN,
248 * & true is returned.
249 * if there are 2 or more copies of the block, indexForLowerScale &
250 * indexForUpperScale are set as described below, fractionFromLowerScale
251 * is set to be
252 * ( ( soughtScale - [ scale of copy with lower scale ] )
253 * / [ difference of copy scales ] ), & true is returned.
254 * fractionFromLowerScale will thus be between 0.0 & 1.0 if there are
255 * copies with scales above & below soughtScale, but may be negative if
256 * soughtScale is lower than the lowest scale of the copies, or greater
257 * than 1.0 if soughtScale is higher than the highest scale of the
258 * copies.
259 * since the copies of the block with different scales are not
260 * necessarily recorded in order of scale, indexForLowerScale will not
261 * necessarily be smaller in value than indexForUpperScale.
262 * indexForLowerScale & indexForUpperScale are set as follows:
263 * if soughtScale is lower than the lowest scale of the copies,
264 * indexForLowerScale is set to the index of the copy with lowest scale,
265 * & indexForUpperScale is set to the index of the copy with the next
266 * lowest scale.
267 * if soughtScale is higher than the highest scale of the copies,
268 * indexForUpperScale is set to the index of the copy with highest scale,
269 * & indexForLowerScale is set to the index of the copy with the next
270 * highest scale.
271 * otherwise, indexForLowerScale is set to the index of the copy with
272 * highest scale which is still lower than soughtScale, &
273 * indexForUpperScale is set to the index of the copy with lowest scale
274 * which is still higher than soughtScale.
275 */
276 {
278 scaleOrderedIndices,
279 indexForLowerScale,
280 indexForUpperScale,
281 fractionFromLowerScale );
282 }
283
284 template< class ValueClass, class BlockParser >
285 inline std::string const&
287 bool onlyShowScalesGreaterThanZero )
288 /* derived classes should override getStringForScale to form their
289 * strings directly from their data (because the block may be being used as
290 * a way of writing an input file in the SLHA format, or maybe because the
291 * original formatting was incorrect, as it is in most spectrum
292 * generators...). by default it just joins together the strings from
293 * blocksAsSingleStrings. each different-scale copy is concatenated. if
294 * onlyShowScalesGreaterThanZero is true, blocks with scales of 0.0 or
295 * less just do not have the "Q=" etc. printed.
296 */
297 {
298 stringInterpretation.clear();
299 for( int scaleIndex( 0 );
300 dataBlocks.getSize() > scaleIndex;
301 ++scaleIndex )
302 {
303 stringInterpretation.append(
305 stringInterpretation.append( " " );
306 stringInterpretation.append( blockName );
307 if( onlyShowScalesGreaterThanZero
308 ||
309 ( 0.0 > dataBlocks[ scaleIndex ].getScale() ) )
310 {
311 stringInterpretation.append( " Q= " );
312 stringInterpretation.append(
314 dataBlocks[ scaleIndex ].getScale() ) );
315 }
316 stringInterpretation.append( "\n" );
317 stringInterpretation.append( dataBlocks[ scaleIndex ].getAsString() );
318 }
319 return stringInterpretation;
320 }
321
322 template< class ValueClass, class BlockParser >
323 inline void
325 /* by default, PushedToObserver instances don't respond without a pushed
326 * value, but this is over-ridden to clear all the data that this block
327 * has interpreted or had assigned.
328 */
329 {
330 dataBlocks.setSize( 1 ).getBack().clearEntries();
331 scaleOrderedIndices.clear();
332 hasHadPushSinceLastReset = false;
333 }
334
335 template< class ValueClass, class BlockParser >
336 inline void
338 BlockClass::BaseStringBlock const& pushedValue )
339 // this adds a new BlockParser to dataBlocks & tells it to interpret
340 // pushedValue. it also sorts out scale indices.
341 {
342 if( hasHadPushSinceLastReset )
343 {
344 dataBlocks.newEnd().setDefaultUnsetValue( defaultUnsetValue );
345 dataBlocks.getBack().setVerbosity( isVerbose );
346 prepareNewDataBlock();
347 dataBlocks.getBack().interpretStringBlock( pushedValue );
348 if( pushedValue.getScale()
349 < dataBlocks[ lowestScaleIndex ].getScale() )
350 /* since hasHadPushSinceLastReset is true, lowestScaleIndex is a
351 * valid index for dataBlocks, so the comparison is valid, & if true,
352 * lowestScaleIndex is set correctly.
353 */
354 {
355 lowestScaleIndex = dataBlocks.getLastIndex();
356 }
357 }
358 else
359 {
360 dataBlocks[ 0 ].interpretStringBlock( pushedValue );
361 }
362 hasHadPushSinceLastReset = true;
363 scaleIndexIterator = scaleOrderedIndices.begin();
364 while( ( scaleIndexIterator != scaleOrderedIndices.end() )
365 &&
366 ( scaleIndexIterator->second < pushedValue.getScale() ) )
367 {
368 ++scaleIndexIterator;
369 }
370 // now scaleIndexIterator should either be at the index with scale just
371 // above blockScale, or at the end of the list.
372 scaleOrderedIndices.insert( scaleIndexIterator,
373 std::pair< int, double >( dataBlocks.getLastIndex(),
374 pushedValue.getScale() ) );
375 }
376
377 template< class ValueClass, class BlockParser >
378 inline void
380 // derived classes can insert extra arguments to any new block interpreters
381 // by over-riding this.
382 {
383 // does nothing.
384 }
385
386 }
387
388}
389
390#endif /* SLHABLOCK_HPP_ */
static bool findScaleIndices(double const soughtScale, std::list< std::pair< int, double > > const &scaleOrderedIndices, int &indexForLowerScale, int &indexForUpperScale, double &fractionFromLowerScale)
static std::string const blockIdentifierString
static BOL::StringParser const slhaDoubleMaker
BlockParser & operator[](int whichScaleIndex)
Definition: SlhaBlock.hpp:187
ValueClass const defaultUnsetValue
Definition: SlhaBlock.hpp:139
BlockParser const & operator[](int whichScaleIndex) const
Definition: SlhaBlock.hpp:206
std::list< std::pair< int, double > >::iterator scaleIndexIterator
Definition: SlhaBlock.hpp:144
SlhaBlock(std::string const &blockName, ValueClass const &defaultUnsetValue, bool const isVerbose)
Definition: SlhaBlock.hpp:159
virtual std::string const & interpretAsString(bool onlyShowScalesGreaterThanZero=true)
Definition: SlhaBlock.hpp:286
int getNumberOfCopiesWithDifferentScale() const
Definition: SlhaBlock.hpp:222
BOL::VectorlikeArray< BlockParser > dataBlocks
Definition: SlhaBlock.hpp:140
bool hasRecordedScale(double const soughtScale, int &indexForLowerScale, int &indexForUpperScale, double &fractionFromLowerScale)
Definition: SlhaBlock.hpp:237
std::list< std::pair< int, double > > scaleOrderedIndices
Definition: SlhaBlock.hpp:143
std::string stringInterpretation
Definition: SlhaBlock.hpp:145
virtual void respondToObservedSignal()
Definition: SlhaBlock.hpp:324
virtual void prepareNewDataBlock()
Definition: SlhaBlock.hpp:379
virtual void respondToPush(BlockClass::BaseStringBlock const &pushedValue)
Definition: SlhaBlock.hpp:337