a Code for the Combination of Indirect and Direct Constraints on High Energy Physics Models Logo
LhefEvent.cpp
Go to the documentation of this file.
1/*
2 * LhefEvent.cpp
3 *
4 * Created on: Jan 26, 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#include "LHEF.hpp"
15
16namespace LHPC
17{
18 namespace LHEF
19 {
20 std::string const LhefEvent::trimmingChars( " \t\r\n" );
21 bool const LhefEvent::trueForVerbosity( true );
22
23 LhefEvent::LhefEvent( bool const isVerbose ) :
24 numberOfParticles( (int)BOL::UsefulStuff::notANumber ),
25 eventId( (int)BOL::UsefulStuff::notANumber ),
26 eventWeight( BOL::UsefulStuff::notANumber ),
27 eventScale( BOL::UsefulStuff::notANumber ),
28 alphaQed( BOL::UsefulStuff::notANumber ),
29 alphaQcd( BOL::UsefulStuff::notANumber ),
30 particleLines(),
31 eventNumberInFile( 0 ),
32 eventAsLines( 5 ),
33 lineAsNumbersAsStrings( 6 ),
34 recordingSucceeded( false ),
35 headerLine( "" ),
36 motherLineNumber( 0 ),
37 primaryMotherLinePointer( NULL ),
38 secondaryMotherLinePointer( NULL ),
39 isVerbose( isVerbose ),
40 eventAsString( "" ),
41 optionalInformation( "" )
42 {
43 // just an initialization list.
44 }
45
46 LhefEvent::LhefEvent( LhefEvent const& copySource ) :
47 numberOfParticles( copySource.numberOfParticles ),
48 eventId( copySource.eventId ),
49 eventWeight( copySource.eventWeight ),
50 eventScale( copySource.eventScale ),
51 alphaQed( copySource.alphaQed ),
52 alphaQcd( copySource.alphaQcd ),
53 particleLines( copySource.particleLines,
54 &ParticleLine::copyParticleLine ),
55 eventNumberInFile( copySource.eventNumberInFile ),
56 eventAsLines( 5 ),
57 lineAsNumbersAsStrings( 6 ),
58 recordingSucceeded( copySource.recordingSucceeded ),
59 headerLine( "" ),
60 motherLineNumber( 0 ),
61 primaryMotherLinePointer( NULL ),
62 secondaryMotherLinePointer( NULL ),
63 isVerbose( trueForVerbosity ),
64 eventAsString( copySource.eventAsString ),
65 optionalInformation( copySource.optionalInformation )
66 {
67 /* the copy constructors of particleLines cannot get their mother &
68 * daughter pointers by themselves, so this constructor has to sort them
69 * out:
70 */
72 }
73
75 {
76 // does nothing.
77 }
78
79
80 bool
81 LhefEvent::recordEvent( std::string const& eventAsString )
82 /* this interprets a string as the data it is meant to correspond to, &
83 * ensures that the ParticleLine instances correctly point to each other.
84 * if any of the lines had the wrong number of data entries, or if the
85 * header number of particles didn't correspond to the number of
86 * particle lines, setAsInvalid() is called & then false is returned.
87 * true is returned if all the entries were filled as expected.
88 */
89 {
90 this->eventAsString.assign( BOL::StringParser::trimFromFrontAndBack(
92 trimmingChars ) );
94 eventAsLines.clearEntries();
95 size_t startOfOptionalInformation( this->eventAsString.find( '#' ) );
96 if( std::string::npos != startOfOptionalInformation )
97 {
99 this->eventAsString.substr( startOfOptionalInformation ) );
102 this->eventAsString.substr( 0,
103 startOfOptionalInformation ),
107 }
108 else
109 {
110 optionalInformation.assign( "" );
111 BOL::StringParser::parseByChar( this->eventAsString,
114 }
115 // now lineParser should be 1 string for the header line &
116 // ( lineParser.getSize() - 1 ) strings for the particle lines.
117 if( 1 >= eventAsLines.getSize() )
118 // if the wrong number of data was given (header line & at least 1
119 // particle line are required)...
120 {
121 if( isVerbose )
122 {
123 std::cout
124 << std::endl
125 << "LHPC::warning! recording event " << eventNumberInFile
126 << " as invalid because only " << eventAsLines.getSize()
127 << " lines were found in the event, which is not enough for a header"
128 << " line + at least 1 particle line.";
129 std::cout << std::endl;
130 }
131 setAsInvalid();
132 return false;
133 }
134 else
135 {
136 // 1st the header line is set up:
137 headerLine.assign( eventAsLines.getFront() );
138 lineAsNumbersAsStrings.clearEntries();
142
143 if( 6 != lineAsNumbersAsStrings.getSize() )
144 // if the wrong number of data was given (a header line & at least 1
145 // particle line are required)...
146 {
147 if( isVerbose )
148 {
149 std::cout
150 << std::endl
151 << "LHPC::warning! recording event " << eventNumberInFile
152 << " as invalid because " << lineAsNumbersAsStrings.getSize()
153 << " numbers were found for the header line, instead of exactly 6"
154 << " numbers, as required.";
155 std::cout << std::endl;
156 }
157 setAsInvalid();
158 return false;
159 }
160 else
161 {
164 if( numberOfParticles != ( eventAsLines.getSize() - 1 ) )
165 // if the header is wrong about how many particle lines there
166 // are...
167 {
168 if( isVerbose )
169 {
170 std::cout
171 << std::endl
172 << "LHPC::warning! recording event " << eventNumberInFile
173 << " as invalid because the header line declared "
174 << numberOfParticles << " particles in the event, but "
175 << ( eventAsLines.getSize() - 1 ) << " lines were found for the"
176 << " particles.";
177 std::cout << std::endl;
178 }
179 setAsInvalid();
180 return false;
181 }
182 else
183 {
184 eventId
194
195 // then the ParticleLines are set up:
197 recordingSucceeded = true;
198 for( int lineCount( 1 );
200 &&
201 ( lineCount <= numberOfParticles ) );
202 ++lineCount )
203 {
205 = particleLines[ lineCount - 1 ].recordLine( lineCount,
206 eventAsLines[ lineCount ] );
208 &&
209 isVerbose )
210 {
214 std::cout
215 << std::endl
216 << "LHPC::warning! recording event " << eventNumberInFile
217 << " as invalid because particle line " << lineCount
218 << " consisted of " << lineAsNumbersAsStrings.getSize()
219 << " numbers rather than the required 13 numbers.";
220 std::cout << std::endl;
221 }
222 }
223 if( !recordingSucceeded )
224 {
225 // the warning about an invalid event is given in the loop rather
226 // than here so that it can state which line was problematic.
227 setAsInvalid();
228 return false;
229 }
230 else
231 {
233 return true;
234 }
235 // end of if-else to finally set up the ParticleLines after
236 // checking that they all recorded properly.
237
238 }
239 // end of if-else checking that the number of particles in the header
240 // matches the number of lines for particles in the event.
241 } // end of if-else checking that the header is correctly formed.
242 }
243 // end of if-else checking that there were enough lines to form an event.
244 }
245
246 void
248 // this sets up the mother & daughter pointers for each ParticleLine in
249 // particleLines.
250 {
251 for( int lineCount( 0 );
252 lineCount < numberOfParticles;
253 ++lineCount )
254 {
256 = particleLines[ lineCount ].getPrimaryMotherLineNumber();
257 if( motherLineNumber > 0 )
258 {
260 = particleLines.getPointer( motherLineNumber - 1 );
261 }
262 else
263 {
265 }
267 = particleLines[ lineCount ].getSecondaryMotherLineNumber();
268 if( motherLineNumber > 0 )
269 {
271 = particleLines.getPointer( motherLineNumber - 1 );
272 }
273 else
274 {
276 }
277 particleLines[ lineCount ].setMotherLines( primaryMotherLinePointer,
279 }
280 }
281
282 }
283
284}
static std::string const whitespaceChars
static std::string const newlineChars
static std::string trimFromFrontAndBack(std::string const &stringToTrim, std::string const &charsToTrim=whitespaceAndNewlineChars)
static double stringToDouble(std::string const &stringToInterpret)
static int stringToInt(std::string const &stringToInterpret)
static void parseByChar(std::string const &stringToParse, VectorlikeArray< std::string > &destinationArray, std::string const &divisionCharSet=whitespaceChars)
std::string eventAsString
Definition: LhefEvent.hpp:119
ParticleLine * secondaryMotherLinePointer
Definition: LhefEvent.hpp:117
BOL::VectorlikeArray< ParticleLine > particleLines
Definition: LhefEvent.hpp:104
void setUpPointersBetweenParticleLines()
Definition: LhefEvent.cpp:247
BOL::VectorlikeArray< std::string > eventAsLines
Definition: LhefEvent.hpp:111
bool recordEvent(std::string const &eventAsString)
Definition: LhefEvent.cpp:81
std::string headerLine
Definition: LhefEvent.hpp:114
std::string optionalInformation
Definition: LhefEvent.hpp:120
LhefEvent(bool const isVerbose)
Definition: LhefEvent.cpp:23
static bool const trueForVerbosity
Definition: LhefEvent.hpp:85
static std::string const trimmingChars
Definition: LhefEvent.hpp:84
ParticleLine * primaryMotherLinePointer
Definition: LhefEvent.hpp:116
BOL::VectorlikeArray< std::string > lineAsNumbersAsStrings
Definition: LhefEvent.hpp:112