ATLAS Offline Software
Loading...
Searching...
No Matches
ThePEG::powhegLesHouchesFileReader Class Reference

powhegLesHouchesFileReader is an base class to be used for objects which reads event files from matrix element generators. More...

#include <PowhegLesHouchesFileReader.h>

Inheritance diagram for ThePEG::powhegLesHouchesFileReader:
Collaboration diagram for ThePEG::powhegLesHouchesFileReader:

Public Member Functions

Standard constructors and destructors.
 powhegLesHouchesFileReader ()
 Default constructor.
 powhegLesHouchesFileReader (const powhegLesHouchesFileReader &)
 Copy-constructor.
virtual ~powhegLesHouchesFileReader ()
 Destructor.
Virtual functions specified by the LesHouchesReader base class.
virtual void initialize (LesHouchesEventHandler &eh)
 Initialize.
virtual void open ()
 Open a file with events.
virtual void close ()
 Close the file from which events have been read.
virtual bool doReadEvent ()
 Read the next event from the file or stream into the corresponding protected variables.
string filename () const
 Return the name of the file from where to read events.
virtual vector< stringoptWeightsNamesFunc ()
 Return the optional weights information string ("Names")

Protected Member Functions

Clone Methods.
virtual IBPtr clone () const
 Make a simple clone of this object.
virtual IBPtr fullclone () const
 Make a clone of this object, possibly modifying the cloned object to make it sane.

Standard (and non-standard) Interfaced functions.

CFileLineReader m_cfile
 The wrapper around the C FILE stream from which to read.
long m_neve
 The number of events in this file.
long m_ieve
 The current event number.
string m_LHFVersion
 If the file is a standard Les Houches formatted file (LHF) this is its version number.
string m_outsideBlock
 If LHF.
string m_headerBlock
 If LHF.
string m_initComments
 If LHF.
map< string, stringm_initAttributes
 If LHF.
string m_eventComments
 If LHF.
map< string, stringm_eventAttributes
 If LHF.
string m_theFileName
 The name of the file from where to read events.
bool m_theQNumbers
 Whether or not to search for QNUMBERS stuff.
bool m_theIncludeFxFxTags
 Include/Read FxFx tags.
bool m_theIncludeCentral
 Include central weight (for backup use)
DecayerPtr m_theDecayer
 Decayer for any decay modes read from the file.
map< string, stringm_scalemap
 Further information on the weights.
map< string, double > m_optionalWeightsTemp
 Temporary holder for optional weights.
map< string, stringm_optionalWeightsLabel
static const ClassDescription< powhegLesHouchesFileReaderm_initpowhegLesHouchesFileReader
 Describe an abstract base class with persistent data.
virtual void doinit ()
 Initialize this object after the setup phase before saving an EventGenerator to disk.
virtual bool preInitialize () const
 Return true if this object needs to be initialized before all other objects because it needs to extract PDFs from the event file.
powhegLesHouchesFileReaderoperator= (const powhegLesHouchesFileReader &)
 Private and non-existent assignment operator.

Functions used by the persistent I/O system.

void persistentOutput (PersistentOStream &os) const
 Function used to write out object persistently.
void persistentInput (PersistentIStream &is, int version)
 Function used to read in object persistently.
void erase_substr (std::string &subject, const std::string &search)
 Erases all occurences of a substring from a string.
static void Init ATLAS_NOT_THREAD_SAFE ()
 Standard Init function used to initialize the interfaces.

Detailed Description

powhegLesHouchesFileReader is an base class to be used for objects which reads event files from matrix element generators.

It inherits from LesHouchesReader and extends it by defining a file handle to be read from, which is opened and closed by the open() and close() functions. Note that the file handle is a standard C filehandle and not a C++ stream. This is because there is no standard way in C++ to connect a pipe to a stream for reading eg. gzipped files. This class is able to read plain event files conforming to the Les Houches Event File accord.

See also
Th1e interfaces defined for powhegLesHouchesFileReader.
Event
LesHouchesReader

Definition at line 43 of file PowhegLesHouchesFileReader.h.

Constructor & Destructor Documentation

◆ powhegLesHouchesFileReader() [1/2]

ThePEG::powhegLesHouchesFileReader::powhegLesHouchesFileReader ( )
inline

Default constructor.

Definition at line 52 of file PowhegLesHouchesFileReader.h.

52 : m_neve(0), m_ieve(0), m_theQNumbers(false),
54 m_theIncludeCentral(false) {}
bool m_theIncludeFxFxTags
Include/Read FxFx tags.
bool m_theQNumbers
Whether or not to search for QNUMBERS stuff.
bool m_theIncludeCentral
Include central weight (for backup use)
long m_neve
The number of events in this file.

◆ powhegLesHouchesFileReader() [2/2]

powhegLesHouchesFileReader::powhegLesHouchesFileReader ( const powhegLesHouchesFileReader & x)

Copy-constructor.

Note that a file which is opened in the object copied from will have to be reopened in this.

Definition at line 42 of file PowhegLesHouchesFileReader.cxx.

44 : LesHouchesReader(x), m_neve(x.m_neve), m_ieve(0),
45 m_LHFVersion(x.m_LHFVersion), m_outsideBlock(x.m_outsideBlock),
46 m_headerBlock(x.m_headerBlock), m_initComments(x.m_initComments),
47 m_initAttributes(x.m_initAttributes), m_eventComments(x.m_eventComments),
48 m_eventAttributes(x.m_eventAttributes),
49 m_theFileName(x.m_theFileName), m_theQNumbers(x.m_theQNumbers),
50 m_theIncludeFxFxTags(x.m_theIncludeFxFxTags),
51 m_theIncludeCentral(x.m_theIncludeCentral),
52 m_theDecayer(x.m_theDecayer) {}
#define x
map< string, string > m_eventAttributes
If LHF.
map< string, string > m_initAttributes
If LHF.
string m_theFileName
The name of the file from where to read events.
string m_LHFVersion
If the file is a standard Les Houches formatted file (LHF) this is its version number.
DecayerPtr m_theDecayer
Decayer for any decay modes read from the file.

◆ ~powhegLesHouchesFileReader()

powhegLesHouchesFileReader::~powhegLesHouchesFileReader ( )
virtual

Destructor.

Definition at line 54 of file PowhegLesHouchesFileReader.cxx.

54{}

Member Function Documentation

◆ ATLAS_NOT_THREAD_SAFE()

void Init ThePEG::powhegLesHouchesFileReader::ATLAS_NOT_THREAD_SAFE ( )
static

Standard Init function used to initialize the interfaces.

◆ clone()

IBPtr powhegLesHouchesFileReader::clone ( ) const
protectedvirtual

Make a simple clone of this object.

Returns
a pointer to the new object.

Definition at line 56 of file PowhegLesHouchesFileReader.cxx.

56 {
57 return new_ptr(*this);
58}

◆ close()

void powhegLesHouchesFileReader::close ( )
virtual

Close the file from which events have been read.

Definition at line 816 of file PowhegLesHouchesFileReader.cxx.

816 {
817 m_cfile.close();
818}
CFileLineReader m_cfile
The wrapper around the C FILE stream from which to read.

◆ doinit()

void powhegLesHouchesFileReader::doinit ( )
protectedvirtual

Initialize this object after the setup phase before saving an EventGenerator to disk.

Exceptions
InitExceptionif object could not be initialized properly.

Definition at line 68 of file PowhegLesHouchesFileReader.cxx.

68 {
69 LesHouchesReader::doinit();
70
71 // are we using QNUMBERS
72 if(!m_theQNumbers) return;
73 // parse the header block and create
74 // any new particles needed in QNUMBERS blocks
75 string block = m_headerBlock;
76 string line = "";
77 bool readingSLHA = false;
78 int (*pf)(int) = tolower;
79 unsigned int newNumber(0);
80 do {
81 line = StringUtils::car(block,"\r\n");
82 block = StringUtils::cdr(block,"\r\n");
83 if(line[0]=='#') continue;
84 // are we reading the SLHA block
85 if(readingSLHA) {
86 // reached the end of slha block
87 if(line.find("</slha") != string::npos) {
88 readingSLHA = false;
89 break;
90 }
91 // remove trailing comment from line
92 vector<string> split = StringUtils::split(line,"#");
93 // check for a qnumbers block
94 transform(split[0].begin(), split[0].end(), split[0].begin(), pf);
95 // if not contine
96 if(split[0].find("block qnumbers")==string::npos)
97 continue;
98 // get name from comment
99 string name;
100 if(split.size()>=2) {
101 name = StringUtils::stripws(split[1]);
102 }
103 else {
104 ++newNumber;
105 ostringstream tname;
106 tname << "NP" << newNumber;
107 name = tname.str();
108 }
109 // extract the PDG code
110 split = StringUtils::split(split[0]," ");
111 istringstream is(split[2]);
112 long PDGCode(0);
113 is >> PDGCode;
114 // get the charge, spin, colour and whether an antiparticle
115 int charge(0),spin(0),colour(0),anti(0);
116 for(unsigned int ix=0;ix<4;++ix) {
117 line = StringUtils::car(block,"\r\n");
118 block = StringUtils::cdr(block,"\r\n");
119 int dummy[2];
120 istringstream is(line);
121 is >> dummy[0] >> dummy[1];
122 switch (dummy[0]) {
123 case 1:
124 charge = dummy[1];
125 break;
126 case 2:
127 spin = dummy[1];
128 break;
129 case 3:
130 colour = dummy[1];
131 break;
132 case 4:
133 anti = dummy[1];
134 break;
135 default:
136 assert(false);
137 }
138 }
139 // check if particles already exist
140 PDPair newParticle;
141 newParticle.first = getParticleData(PDGCode);
142 if(newParticle.first) Throw<SetupException>()
143 << "Particle with PDG code " << PDGCode
144 << " whose creation was requested in a QNUMBERS Block"
145 << " already exists. Retaining the original particle"
146 << Exception::warning;
147 if(anti) {
148 newParticle.second = getParticleData(-PDGCode);
149 if(newParticle.second) Throw<SetupException>()
150 << "Anti-particle with PDG code " << -PDGCode
151 << " whose creation was requested in a QNUMBERS Block"
152 << " already exists. Retaining the original particle"
153 << Exception::warning;
154 if(( newParticle.first && !newParticle.second ) ||
155 ( newParticle.second && !newParticle.first ) )
156 Throw<SetupException>()
157 << "Either particle or anti-particle with PDG code " << PDGCode
158 << " whose creation was requested in a QNUMBERS Block"
159 << " already exists, but not both the particle and antiparticle. "
160 << " Something dodgy here stopping"
161 << Exception::runerror;
162 }
163 // already exists continue
164 if(newParticle.first) continue;
165 // create the particles
166 // particle with no anti particle
167 if( anti == 0 ) {
168 // construct the name
169 if(name=="") {
170 ostringstream temp;
171 temp << PDGCode;
172 name = temp.str();
173 }
174 // create the ParticleData object
175 newParticle.first = ParticleData::Create(PDGCode,name);
176 }
177 // particle anti-particle pair
178 else {
179 // construct the names
180 string nameAnti;
181 if(name=="") {
182 ostringstream temp;
183 temp << PDGCode;
184 name = temp.str();
185 ostringstream temp2;
186 temp << -PDGCode;
187 nameAnti = temp2.str();
188 }
189 else {
190 nameAnti=name;
191 auto swapSign=[](char & t){
192 if (t=='-') t= '+';
193 else if (t=='+') t= '-';
194 };
195 std::for_each(nameAnti.begin(),nameAnti.end(), swapSign);
196 if(nameAnti==name) nameAnti += "bar";
197 }
198 // create the ParticleData objects
199 newParticle = ParticleData::Create(PDGCode,name,nameAnti);
200 }
201 // set the particle properties
202 if(colour==1) colour = 0;
203 newParticle.first->iColour(PDT::Colour(colour));
204 newParticle.first->iSpin (PDT::Spin (spin ));
205 newParticle.first->iCharge(PDT::Charge(charge));
206 // register it
207 generator()->preinitRegister(newParticle.first,
208 "/Herwig/Particles/"+newParticle.first->PDGName());
209 // set the antiparticle properties
210 if(newParticle.second) {
211 if(colour==3||colour==6) colour *= -1;
212 charge = -charge;
213 newParticle.second->iColour(PDT::Colour(colour));
214 newParticle.second->iSpin (PDT::Spin (spin ));
215 newParticle.second->iCharge(PDT::Charge(charge));
216 // register it
217 generator()->preinitRegister(newParticle.second,
218 "/Herwig/Particles/"+newParticle.second->PDGName());
219 }
220 }
221 // start of SLHA block ?
222 else if(line.find("<slha") != string::npos) {
223 readingSLHA = true;
224 }
225 }
226 while(line!="");
227 // now set any masses/decay modes
228 block = m_headerBlock;
229 line="";
230 readingSLHA=false;
231 bool ok=true;
232 do {
233 line = StringUtils::car(block,"\r\n");
234 block = StringUtils::cdr(block,"\r\n");
235 // are we reading the SLHA block
236 if(readingSLHA) {
237 // reached the end?
238 if(line.starts_with("</slha")) {
239 readingSLHA = false;
240 break;
241 }
242 // make lower case
243 transform(line.begin(),line.end(),line.begin(), pf);
244 // found the mass block ?
245 if(line.find("block mass")!=string::npos) {
246 // read it
247 line = StringUtils::car(block,"\r\n");
248 // check not at end
249 while(line[0] != 'D' && line[0] != 'B' &&
250 line[0] != 'd' && line[0] != 'b' &&
251 line != "") {
252 // skip comment lines
253 if(line[0] == '#') {
254 block = StringUtils::cdr(block,"\r\n");
255 line = StringUtils::car(block,"\r\n");
256 continue;
257 }
258 // get the mass and PGD code
259 istringstream temp(line);
260 long id;
261 double mass;
262 temp >> id >> mass;
263 // skip resetting masses on SM particles
264 // as it can cause problems later on in event generation
265 if(std::abs(id) <= 6 || (std::abs(id) >= 11 && std::abs(id) <= 16) ||
266 std::abs(id) == 23 || std::abs(id) == 24) {
267 block = StringUtils::cdr(block,"\r\n");
268 line = StringUtils::car(block,"\r\n");
269 continue;
270 }
271 // magnitude of mass for susy models
272 mass = abs(mass);
273 // set the mass
274 tPDPtr particle = getParticleData(id);
275 if(!particle) throw SetupException()
276 << "powhegLesHouchesFileReader::doinit() - Particle with PDG code not"
277 << id << " not found." << Exception::runerror;
278 const InterfaceBase * ifb = BaseRepository::FindInterface(particle,
279 "NominalMass");
280 ostringstream os;
281 os << mass;
282 ifb->exec(*particle, "set", os.str());
283 // read the next line
284 block = StringUtils::cdr(block,"\r\n");
285 line = StringUtils::car(block,"\r\n");
286 };
287 }
288 // found a decay block
289 else if(line.starts_with("decay")) {
290 // get PGD code and width
291 istringstream iss(line);
292 string dummy;
293 long parent(0);
294 Energy width(ZERO);
295 iss >> dummy >> parent >> iunit(width, GeV);
296 // get the ParticleData object
297 PDPtr inpart = getParticleData(parent);
298 if(!inpart) {
299 throw SetupException()
300 << "powhegLesHouchesFileReader::doinit() - A ParticleData object with the PDG code "
301 << parent << " does not exist. " << Exception::runerror;
302 return;
303 }
304 if ( std::abs(inpart->id()) == 6 ||
305 std::abs(inpart->id()) == 15 ||
306 std::abs(inpart->id()) == 23 ||
307 std::abs(inpart->id()) == 24 ||
308 std::abs(inpart->id()) == 25 ) {
309 Throw<SetupException>() << "\n"
310 "************************************************************************\n"
311 "* Your LHE file changes the width of " << inpart->PDGName() << ".\n"
312 "* This can cause serious problems in the event generation!\n"
313 "************************************************************************\n"
314 "\n" << Exception::warning;
315 }
316 else if (inpart->width() > ZERO && width <= ZERO) {
317 Throw<SetupException>() << "\n"
318 "************************************************************************\n"
319 "* Your LHE file zeroes the non-zero width of " << inpart->PDGName() << ".\n"
320 "* If " << inpart->PDGName() << " is a decaying SM particle,\n"
321 "* this can cause serious problems in the event generation!\n"
322 "************************************************************************\n"
323 "\n" << Exception::warning;
324 }
325 // set the width
326 inpart->width(width);
327 if( width > ZERO ) {
328 inpart->cTau(hbarc/width);
329 inpart->widthCut(5.*width);
330 inpart->stable(false);
331 }
332 // construct prefix for DecayModes
333 string prefix(inpart->name() + "->"), tag(prefix),line("");
334 unsigned int nmode(0);
335 // read any decay modes
336 line = StringUtils::car(block,"\r\n");
337 while(line[0] != 'D' && line[0] != 'B' &&
338 line[0] != 'd' && line[0] != 'b' &&
339 line[0] != '<' && line != "") {
340 // skip comments
341 if(line[0] == '#') {
342 block = StringUtils::cdr(block,"\r\n");
343 line = StringUtils::car(block,"\r\n");
344 continue;
345 }
346 // read decay mode and construct the tag
347 istringstream is(line);
348 double brat(0.);
349 unsigned int nda(0),npr(0);
350 is >> brat >> nda;
351 while( true ) {
352 long t;
353 is >> t;
354 if( is.fail() ) break;
355 if( t == std::abs(parent) )
356 throw SetupException()
357 << "An error occurred while read a decay of the "
358 << inpart->PDGName() << ". One of its products has the same PDG code "
359 << "as the parent particle in powhegLesHouchesFileReader::doinit()."
360 << " Please check the Les Houches file.\n"
361 << Exception::runerror;
362 tcPDPtr p = getParticleData(t);
363 if( !p )
364 throw SetupException()
365 << "powhegLesHouchesFileReader::doinit() -"
366 << " An unknown PDG code has been encounterd "
367 << "while reading a decay mode. ID: " << t
368 << Exception::runerror;
369 ++npr;
370 tag += p->name() + ",";
371 }
372 if( npr != nda )
373 throw SetupException()
374 << "powhegLesHouchesFileReader::doinit() - While reading a decay of the "
375 << inpart->PDGName() << " from an SLHA file, an inconsistency "
376 << "between the number of decay products and the value in "
377 << "the 'NDA' column was found. Please check if the spectrum "
378 << "file is correct.\n"
379 << Exception::warning;
380 // create the DecayMode
381 if( npr > 1 ) {
382 if( nmode==0 ) {
383 generator()->preinitInterface(inpart, "VariableRatio" , "set","false");
384 if(inpart->massGenerator()) {
385 ok = false;
386 Throw<SetupException>()
387 << inpart->PDGName() << " already has a MassGenerator set"
388 << " this is incompatible with using QNUMBERS "
389 << "Use\n"
390 << "set " << inpart->fullName() << ":Mass_generator NULL\n"
391 << "to fix this." << Exception::warning;
392 }
393 if(inpart->widthGenerator()) {
394 ok = false;
395 Throw<SetupException>()
396 << inpart->PDGName() << " already has a WidthGenerator set"
397 << " this is incompatible with using QNUMBERS "
398 << "Use\n"
399 << "set " << inpart->fullName() << ":Width_generator NULL\n"
400 << "to fix this." << Exception::warning;
401 }
402 unsigned int ntemp=0;
403 for(DecaySet::const_iterator dit = inpart->decayModes().begin();
404 dit != inpart->decayModes().end(); ++dit ) {
405 if((**dit).on()) ++ntemp;
406 }
407 if(ntemp!=0) {
408 ok = false;
409 Throw<SetupException>()
410 << inpart->PDGName() << " already has DecayModes"
411 << " this is incompatible with using QNUMBERS "
412 << "Use\n"
413 << "do " << inpart->fullName() << ":SelectDecayModes none\n"
414 << " to fix this." << Exception::warning;
415 }
416 }
417 inpart->stable(false);
418 tag.replace(tag.size() - 1, 1, ";");
419 DMPtr dm = generator()->findDecayMode(tag);
420 if(!m_theDecayer) Throw<SetupException>()
421 << "powhegLesHouchesFileReader::doinit() Decayer must be set using the "
422 << "powhegLesHouchesFileReader:Decayer"
423 << " must be set to allow the creation of new"
424 << " decay modes."
425 << Exception::runerror;
426 if(!dm) {
427 dm = generator()->preinitCreateDecayMode(tag);
428 if(!dm)
429 Throw<SetupException>()
430 << "powhegLesHouchesFileReader::doinit() - Needed to create "
431 << "new decaymode but one could not be created for the tag "
432 << tag << Exception::warning;
433 }
434 generator()->preinitInterface(dm, "Decayer", "set",
435 m_theDecayer->fullName());
436 ostringstream br;
437 br << setprecision(13) << brat;
438 generator()->preinitInterface(dm, "BranchingRatio", "set", br.str());
439 generator()->preinitInterface(dm, "Active", "set", "Yes");
440 if(dm->CC()) {
441 generator()->preinitInterface(dm->CC(), "BranchingRatio", "set", br.str());
442 generator()->preinitInterface(dm->CC(), "Active", "set", "Yes");
443 }
444 ++nmode;
445 }
446 tag=prefix;
447 // read the next line
448 block = StringUtils::cdr(block,"\r\n");
449 line = StringUtils::car(block,"\r\n");
450 };
451 if(nmode>0) {
452 inpart->update();
453 if(inpart->CC())
454 inpart->CC()->update();
455 }
456 }
457 }
458 // start of SLHA block ?
459 else if(line.find("<slha") != string::npos) {
460 readingSLHA = true;
461 }
462 }
463 while(line!="");
464 if(!ok)
465 throw SetupException() << "Problem reading QNUMBERS blocks in powhegLesHouchesFileReader::doinit()"
466 << Exception::runerror;
467}
void tolower(std::string &s)
double spin(const T &p)
Definition AtlasPID.h:1147
double charge(const T &p)
Definition AtlasPID.h:997
std::vector< double > Energy
const double width
std::string find(const std::string &s)
return a remapped string
Definition hcg.cxx:138
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:177
Amg::Vector3D transform(Amg::Vector3D &v, Amg::Transform3D &tr)
Transform a point from a Trasformation3D.
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
generator
Configure Herwig7 These are the commands corresponding to what would go into the regular Herwig infil...

◆ doReadEvent()

bool powhegLesHouchesFileReader::doReadEvent ( )
virtual

Read the next event from the file or stream into the corresponding protected variables.

Return false if there is no more events or if this was not a LHF event file.

Definition at line 624 of file PowhegLesHouchesFileReader.cxx.

624 {
625 if ( !m_cfile ) return false;
626 if ( m_LHFVersion.empty() ) return false;
627 if ( heprup.NPRUP < 0 ) return false;
628 m_eventComments = "";
629 m_outsideBlock = "";
630 hepeup.NUP = 0;
631 hepeup.XPDWUP.first = hepeup.XPDWUP.second = 0.0;
632 optionalWeights.clear();
633 m_optionalWeightsTemp.clear();
634 // Keep reading lines until we hit the next event or the end of
635 // the event block. Save any inbetween lines. Exit if we didn't
636 // find an event.
637 while ( m_cfile.readline() && !m_cfile.find("<event") )
638 m_outsideBlock += m_cfile.getline() + "\n";
639
640 // We found an event. First scan for attributes.
641 m_eventAttributes = StringUtils::xmlAttributes("event", m_cfile.getline());
642
643 /* information necessary for FxFx merging:
644 * the npLO and npNLO tags
645 */
646 istringstream ievat(m_cfile.getline());
647 int we(0), npLO(-99), npNLO(-99);
648 do {
649 string sub; ievat >> sub;
650 if(we==2) { npLO = atoi(sub.c_str()); }
651 if(we==5) { npNLO = atoi(sub.c_str()); }
652 ++we;
653 } while (ievat);
654 optionalnpLO = npLO;
655 optionalnpNLO = npNLO;
656 std::stringstream npstringstream;
657 npstringstream << "np " << npLO << " " << npNLO;
658 std::string npstrings = npstringstream.str();
659 /* the FxFx merging information
660 * becomes part of the optionalWeights, labelled -999
661 * for future reference
662 */
663
664 if(m_theIncludeFxFxTags) optionalWeights[npstrings.c_str()] = -999;
665
666 if ( !m_cfile.readline() ) return false;
667
668 // The first line determines how many subsequent particle lines we
669 // have.
670 if ( !( m_cfile >> hepeup.NUP >> hepeup.IDPRUP >> hepeup.XWGTUP
671 >> hepeup.SCALUP >> hepeup.AQEDUP >> hepeup.AQCDUP ) )
672 return false;
673 hepeup.resize();
674 // Read all particle lines.
675 for ( int i = 0; i < hepeup.NUP; ++i ) {
676 if ( !m_cfile.readline() ) return false;
677 if ( !( m_cfile >> hepeup.IDUP[i] >> hepeup.ISTUP[i]
678 >> hepeup.MOTHUP[i].first >> hepeup.MOTHUP[i].second
679 >> hepeup.ICOLUP[i].first >> hepeup.ICOLUP[i].second
680 >> hepeup.PUP[i][0] >> hepeup.PUP[i][1] >> hepeup.PUP[i][2]
681 >> hepeup.PUP[i][3] >> hepeup.PUP[i][4]
682 >> hepeup.VTIMUP[i] >> hepeup.SPINUP[i] ) )
683 return false;
684 //print momenta for debugging
685 if(std::isnan(hepeup.PUP[i][0])||std::isnan(hepeup.PUP[i][1])||
686 std::isnan(hepeup.PUP[i][2])||std::isnan(hepeup.PUP[i][3])||
687 std::isnan(hepeup.PUP[i][4]))
688 throw Exception()
689 << "nan's as momenta in Les Houches file "
690 << Exception::eventerror;
691 if(hepeup.MOTHUP[i].first -1==i ||
692 hepeup.MOTHUP[i].second-1==i) {
693 throw Exception()
694 << "Particle has itself as a mother in Les Houches "
695 << "file, this is not allowed\n"
696 << Exception::eventerror;
697 }
698 }
699
700 // Now read any additional comments and named weights.
701 // read until the end of rwgt is found
702 bool readingWeights = false, readingaMCFast = false, readingMG5ClusInfo = false;
703 while ( m_cfile.readline() && !m_cfile.find("</event>")) {
704
705 if(m_cfile.find("</applgrid")) { readingaMCFast=false; } //aMCFast weights end
706 if(m_cfile.find("</rwgt")) { readingWeights=false; } //optional weights end
707 if(m_cfile.find("</clustering")) { readingMG5ClusInfo=false; } // mg5 mclustering scale info end
708
709 /* reading of optional weights
710 */
711
712 /* BEGIN MOD*/
713 if(readingWeights) {
714 if(!m_cfile.find("<wgt")) { continue; }
715 istringstream iss(m_cfile.getline());
716 double weightValue(0);
717 std::string hs=m_cfile.getline();
718 hs.erase(std::remove(hs.begin(), hs.end(), ' '), hs.end());
719 std::string IdLabel = hs.substr(0, hs.find(">", 0));
720 IdLabel = std::regex_replace(IdLabel, std::regex(R"([\D])"), "");
721 std::string weightName = m_optionalWeightsLabel[IdLabel];
722 std::string value=std::move(hs);
723 erase_substr(value, "<wgtid='"+IdLabel+"'>");
724 erase_substr(value, "<wgtid=\""+IdLabel+"\">");
725 erase_substr(value, "</wgt>");
726 erase_substr(value, "\n");
727 weightValue=std::stod(value);
728 m_optionalWeightsTemp[weightName] = weightValue;
729 optionalWeights[weightName] = weightValue;
730 }
731 /* END MOD */
732
733 /* reading of aMCFast weights
734 */
735 if(readingaMCFast) {
736 std::stringstream amcfstringstream;
737 amcfstringstream << "aMCFast " << m_cfile.getline();
738 std::string amcfstrings = amcfstringstream.str();
739 string str_newline = "\n";
740 erase_substr(amcfstrings,str_newline);
741 optionalWeights[amcfstrings.c_str()] = -111; //for the aMCFast we give them a weight -111 for future identification
742 }
743
744 /* read additional MG5 Clustering information
745 * used in LO merging
746 */
747 if(readingMG5ClusInfo) {
748 string hs = m_cfile.getline();
749 string startDEL = "<clus scale="; //starting delimiter
750 string stopDEL = "</clus>"; //end delimiter
751 unsigned firstLim = hs.find(startDEL); //find start of delimiter
752 string mg5clusinfo = hs.substr(firstLim); //define the information for the scale
753 erase_substr(mg5clusinfo,stopDEL);
754 erase_substr(mg5clusinfo,startDEL);
755 string str_arrow = ">";
756 erase_substr(mg5clusinfo,str_arrow);
757 string str_quotation = "\"";
758 erase_substr(mg5clusinfo,str_quotation);
759 optionalWeights[mg5clusinfo.c_str()] = -222; //for the mg5 scale info weights we give them a weight -222 for future identification
760 }
761
762 //store MG5 clustering information
763 if(m_cfile.find("<scales")) {
764 string hs = m_cfile.getline();
765 string startDEL = "<scales"; //starting delimiter
766 string stopDEL = "</scales>"; //end delimiter
767 unsigned firstLim = hs.find(startDEL); //find start of delimiter
768 string mg5scinfo = hs.substr(firstLim); //define the information for the scale
769 erase_substr(mg5scinfo,stopDEL);
770 erase_substr(mg5scinfo,startDEL);
771 string str_arrow = ">";
772 erase_substr(mg5scinfo,str_arrow);
773 optionalWeights[mg5scinfo.c_str()] = -333; //for the mg5 scale info weights we give them a weight -333 for future identification
774 }
775
776 //determine start of aMCFast weights
777 if(m_cfile.find("<applgrid")) { readingaMCFast = true;}
778 //determine start of optional weights
779 if(m_cfile.find("<rwgt")) { readingWeights = true; }
780 //determine start of MG5 clustering scale information
781 if(m_cfile.find("<clustering")) { readingMG5ClusInfo = true;}
782 }
783 string str_quote = "'";
784 string str_doublequote = "\"";
785 // loop over the optional weights and add the extra information as found in the init
786 for (map<string,double>::const_iterator it=m_optionalWeightsTemp.begin(); it!=m_optionalWeightsTemp.end(); ++it){
787 //to avoid issues with inconsistencies of defining the weight ids, remove "" and ''
788 string id_1 = it->first;
789 erase_substr(id_1, str_quote);
790 erase_substr(id_1, str_doublequote);
791 for (map<string,string>::const_iterator it2=m_scalemap.begin(); it2!=m_scalemap.end(); ++it2){
792 //find the scale id in the scale information and add this information
793 string id_2 = it2->first;
794 erase_substr(id_2, str_quote);
795 erase_substr(id_2, str_doublequote);
796 if(id_1==id_2) {
797 string info = it2->second;
798 string str_newline = "\n";
799 erase_substr(info, str_newline);
800 //set the optional weights
801 optionalWeights[info] = it->second;
802 }
803 }
804 }
805 /* additionally, we set the "central" scale
806 * this is actually the default event weight
807 */
808 string central = "central";
809 if (m_theIncludeCentral) optionalWeights[central] = hepeup.XWGTUP;
810
811 if ( !m_cfile ) return false;
812 return true;
813
814}
map< string, double > m_optionalWeightsTemp
Temporary holder for optional weights.
void erase_substr(std::string &subject, const std::string &search)
Erases all occurences of a substring from a string.
map< string, string > m_scalemap
Further information on the weights.
int atoi(std::string_view str)
Helper functions to unpack numbers decoded in string into integers and doubles The strings are requir...
DataModel_detail::iterator< DVL > remove(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end, const T &value)
Specialization of remove for DataVector/List.

◆ erase_substr()

void powhegLesHouchesFileReader::erase_substr ( std::string & subject,
const std::string & search )

Erases all occurences of a substring from a string.

Definition at line 913 of file PowhegLesHouchesFileReader.cxx.

913 {
914 size_t pos = 0;
915 while((pos = subject.find(search, pos)) != std::string::npos) {
916 subject.erase( pos, search.length() );
917 }
918}
void search(TDirectory *td, const std::string &s, std::string cwd, node *n)
recursive directory search for TH1 and TH2 and TProfiles
Definition hcg.cxx:739

◆ filename()

string ThePEG::powhegLesHouchesFileReader::filename ( ) const
inline

Return the name of the file from where to read events.

Definition at line 102 of file PowhegLesHouchesFileReader.h.

102{ return m_theFileName; }

◆ fullclone()

IBPtr powhegLesHouchesFileReader::fullclone ( ) const
protectedvirtual

Make a clone of this object, possibly modifying the cloned object to make it sane.

Returns
a pointer to the new object.

Definition at line 60 of file PowhegLesHouchesFileReader.cxx.

60 {
61 return new_ptr(*this);
62}

◆ initialize()

void powhegLesHouchesFileReader::initialize ( LesHouchesEventHandler & eh)
virtual

Initialize.

This function is called by the LesHouchesEventHandler to which this object is assigned.

Definition at line 469 of file PowhegLesHouchesFileReader.cxx.

469 {
470 LesHouchesReader::initialize(eh);
471 if ( m_LHFVersion.empty() )
472 Throw<powhegLesHouchesFileError>()
473 << "The file associated with '" << name() << "' does not contain a "
474 << "proper formatted Les Houches event file. The events may not be "
475 << "properly sampled." << Exception::warning;
476}

◆ open()

void powhegLesHouchesFileReader::open ( )
virtual

Open a file with events.

Derived classes should overwrite it and first calling it before reading in the run information into the corresponding protected variables.

Definition at line 480 of file PowhegLesHouchesFileReader.cxx.

480 {
481 if ( filename().empty() )
482 throw powhegLesHouchesFileError()
483 << "No Les Houches file name. "
484 << "Use 'set " << name() << ":FileName'."
485 << Exception::runerror;
486 m_cfile.open(filename());
487 if ( !m_cfile )
488 throw powhegLesHouchesFileError()
489 << "The powhegLesHouchesFileReader '" << name() << "' could not open the "
490 << "event file called '" << m_theFileName << "'."
491 << Exception::runerror;
492
493
494 m_cfile.readline();
495 if ( !m_cfile.find("<LesHouchesEvents") ) return;
496 map<string,string> attributes =
497 StringUtils::xmlAttributes("LesHouchesEvents", m_cfile.getline());
498 m_LHFVersion = attributes["version"];
499 if ( m_LHFVersion.empty() ) return;
500
501 bool readingHeader = false;
502 bool readingInit = false;
503 m_headerBlock = "";
504 string hs;
505
506 // Loop over all lines until we hit the </init> tag.
507 bool readingInitWeights = false, readingInitWeights_sc = false;
508 string weightinfo;
509 while ( m_cfile.readline() ) {
510 // found the init block for multiple weights
511 if(m_cfile.find("<initrwgt")) readingInitWeights = true;
512
513 // found end of init block for multiple weights: end the while loop
514 if(m_cfile.find("</initrwgt")) {
515 readingInitWeights = false;
516 readingInitWeights_sc = false;
517 continue;
518 }
519
520 // found the end of init block
521 if(m_cfile.find("</init")) {
522 readingInit = false;
523 break;
524 }
525
526 /* read the weight information block
527 * optionalWeightNames will contain information about the weights
528 * this will be appended to the weight information
529 */
530 if(readingInitWeights) {
531 string scalename = "";
532 if(m_cfile.find("<weightgroup")) {
533 /* we found a weight group
534 * start reading the information
535 * within it
536 */
537 readingInitWeights_sc = true;
538 weightinfo = m_cfile.getline();
539 /* to make it shorter, erase some stuff
540 */
541 string str_weightgroup = "<weightgroup";
542 string str_arrow = ">";
543 string str_newline = "\n";
544 erase_substr(weightinfo, str_weightgroup);
545 erase_substr(weightinfo, str_arrow);
546 erase_substr(weightinfo, str_newline);
547 continue;
548 }
549 /* if we are reading a new weightgroup, go on
550 * until we find the end of it
551 */
552 /* BEGIN MOD*/
553 if(readingInitWeights_sc && !m_cfile.find("</weightgroup")) {
554 hs = m_cfile.getline();
555 hs.erase(std::remove(hs.begin(), hs.end(), ' '), hs.end());
556 std::string IdLabel = hs.substr(0, hs.find(">", 0));
557 IdLabel = std::regex_replace(IdLabel, std::regex(R"([\D])"), "");
558 std::string name = hs;
559 erase_substr(name, "<weightid='"+IdLabel+"'>");
560 name.erase(name.find('<'));
562 optionalWeightsNames.push_back(std::move(name));
563 }
564 /*END MOD*/
565 }
566
567 if ( m_cfile.find("<header") ) {
568 // We have hit the header block, so we should dump this and all
569 // following lines to m_headerBlock until we hit the end of it.
570 readingHeader = true;
571 m_headerBlock = m_cfile.getline() + "\n";
572 }
573 if ( (m_cfile.find("<init ") && !m_cfile.find("<initrwgt")) || m_cfile.find("<init>") ) {
574 // We have hit the init block, so we should expect to find the
575 // standard information in the following. But first check for
576 // attributes.
577 m_initAttributes = StringUtils::xmlAttributes("init", m_cfile.getline());
578 readingInit = true;
579 m_cfile.readline();
580 if ( !( m_cfile >> heprup.IDBMUP.first >> heprup.IDBMUP.second
581 >> heprup.EBMUP.first >> heprup.EBMUP.second
582 >> heprup.PDFGUP.first >> heprup.PDFGUP.second
583 >> heprup.PDFSUP.first >> heprup.PDFSUP.second
584 >> heprup.IDWTUP >> heprup.NPRUP ) ) {
585 heprup.NPRUP = -42;
586 m_LHFVersion = "";
587 return;
588 }
589 heprup.resize();
590 for ( int i = 0; i < heprup.NPRUP; ++i ) {
591 m_cfile.readline();
592 if ( !( m_cfile >> heprup.XSECUP[i] >> heprup.XERRUP[i]
593 >> heprup.XMAXUP[i] >> heprup.LPRUP[i] ) ) {
594 heprup.NPRUP = -42;
595 m_LHFVersion = "";
596 return;
597 }
598 }
599 }
600 if ( m_cfile.find("</header") ) {
601 readingHeader = false;
602 m_headerBlock += m_cfile.getline() + "\n";
603 }
604 if ( readingHeader ) {
605 /* We are in the process of reading the header block. Dump the
606 line to m_headerBlock.*/
607 m_headerBlock += m_cfile.getline() + "\n";
608 }
609 if ( readingInit ) {
610 // Here we found a comment line. Dump it to m_initComments.
611 m_initComments += m_cfile.getline() + "\n";
612 }
613 }
614
615 optionalWeightsNames.emplace_back("central");
616
617 if ( !m_cfile ) {
618 heprup.NPRUP = -42;
619 m_LHFVersion = "";
620 return;
621 }
622}
static const Attributes_t empty
string filename() const
Return the name of the file from where to read events.

◆ operator=()

powhegLesHouchesFileReader & ThePEG::powhegLesHouchesFileReader::operator= ( const powhegLesHouchesFileReader & )
private

Private and non-existent assignment operator.

◆ optWeightsNamesFunc()

vector< string > powhegLesHouchesFileReader::optWeightsNamesFunc ( )
virtual

Return the optional weights information string ("Names")

Definition at line 478 of file PowhegLesHouchesFileReader.cxx.

478{ return optionalWeightsNames; }

◆ persistentInput()

void powhegLesHouchesFileReader::persistentInput ( PersistentIStream & is,
int version )

Function used to read in object persistently.

Parameters
isthe persistent input stream read from.
versionthe version number of the object when written.

Definition at line 826 of file PowhegLesHouchesFileReader.cxx.

◆ persistentOutput()

void powhegLesHouchesFileReader::persistentOutput ( PersistentOStream & os) const

Function used to write out object persistently.

Parameters
osthe persistent output stream written to.

Definition at line 820 of file PowhegLesHouchesFileReader.cxx.

◆ preInitialize()

bool powhegLesHouchesFileReader::preInitialize ( ) const
protectedvirtual

Return true if this object needs to be initialized before all other objects because it needs to extract PDFs from the event file.

Definition at line 64 of file PowhegLesHouchesFileReader.cxx.

64 {
65 return true;
66}

Member Data Documentation

◆ m_cfile

CFileLineReader ThePEG::powhegLesHouchesFileReader::m_cfile
protected

The wrapper around the C FILE stream from which to read.

Definition at line 180 of file PowhegLesHouchesFileReader.h.

◆ m_eventAttributes

map<string,string> ThePEG::powhegLesHouchesFileReader::m_eventAttributes
protected

If LHF.

Map of attributes (name-value pairs) found in the last event tag.

Definition at line 232 of file PowhegLesHouchesFileReader.h.

◆ m_eventComments

string ThePEG::powhegLesHouchesFileReader::m_eventComments
protected

If LHF.

Additional comments found with the last read event.

Definition at line 226 of file PowhegLesHouchesFileReader.h.

◆ m_headerBlock

string ThePEG::powhegLesHouchesFileReader::m_headerBlock
protected

If LHF.

All lines from the header block.

Definition at line 210 of file PowhegLesHouchesFileReader.h.

◆ m_ieve

long ThePEG::powhegLesHouchesFileReader::m_ieve
protected

The current event number.

Definition at line 192 of file PowhegLesHouchesFileReader.h.

◆ m_initAttributes

map<string,string> ThePEG::powhegLesHouchesFileReader::m_initAttributes
protected

If LHF.

Map of attributes (name-value pairs) found in the init tag.

Definition at line 221 of file PowhegLesHouchesFileReader.h.

◆ m_initComments

string ThePEG::powhegLesHouchesFileReader::m_initComments
protected

If LHF.

Additional comments found in the init block.

Definition at line 215 of file PowhegLesHouchesFileReader.h.

◆ m_initpowhegLesHouchesFileReader

const ClassDescription< powhegLesHouchesFileReader > powhegLesHouchesFileReader::m_initpowhegLesHouchesFileReader
staticprivate

Describe an abstract base class with persistent data.

Definition at line 280 of file PowhegLesHouchesFileReader.h.

◆ m_LHFVersion

string ThePEG::powhegLesHouchesFileReader::m_LHFVersion
protected

If the file is a standard Les Houches formatted file (LHF) this is its version number.

If empty, this is not a Les Houches formatted file

Definition at line 199 of file PowhegLesHouchesFileReader.h.

◆ m_neve

long ThePEG::powhegLesHouchesFileReader::m_neve
protected

The number of events in this file.

Definition at line 187 of file PowhegLesHouchesFileReader.h.

◆ m_optionalWeightsLabel

map<string,string> ThePEG::powhegLesHouchesFileReader::m_optionalWeightsLabel
private

Definition at line 272 of file PowhegLesHouchesFileReader.h.

◆ m_optionalWeightsTemp

map<string,double> ThePEG::powhegLesHouchesFileReader::m_optionalWeightsTemp
private

Temporary holder for optional weights.

Definition at line 270 of file PowhegLesHouchesFileReader.h.

◆ m_outsideBlock

string ThePEG::powhegLesHouchesFileReader::m_outsideBlock
protected

If LHF.

All lines (since the last open() or readEvent()) outside the header, init and event tags.

Definition at line 205 of file PowhegLesHouchesFileReader.h.

◆ m_scalemap

map<string,string> ThePEG::powhegLesHouchesFileReader::m_scalemap
private

Further information on the weights.

Definition at line 264 of file PowhegLesHouchesFileReader.h.

◆ m_theDecayer

DecayerPtr ThePEG::powhegLesHouchesFileReader::m_theDecayer
private

Decayer for any decay modes read from the file.

Definition at line 259 of file PowhegLesHouchesFileReader.h.

◆ m_theFileName

string ThePEG::powhegLesHouchesFileReader::m_theFileName
private

The name of the file from where to read events.

Definition at line 239 of file PowhegLesHouchesFileReader.h.

◆ m_theIncludeCentral

bool ThePEG::powhegLesHouchesFileReader::m_theIncludeCentral
private

Include central weight (for backup use)

Definition at line 254 of file PowhegLesHouchesFileReader.h.

◆ m_theIncludeFxFxTags

bool ThePEG::powhegLesHouchesFileReader::m_theIncludeFxFxTags
private

Include/Read FxFx tags.

Definition at line 249 of file PowhegLesHouchesFileReader.h.

◆ m_theQNumbers

bool ThePEG::powhegLesHouchesFileReader::m_theQNumbers
private

Whether or not to search for QNUMBERS stuff.

Definition at line 244 of file PowhegLesHouchesFileReader.h.


The documentation for this class was generated from the following files: