Page Menu
Home
HEPForge
Search
Configure Global Search
Log In
Files
F19252203
LesHouchesWriter.cc
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
LesHouchesWriter.cc
View Options
/**
* \authors The HEJ collaboration (see AUTHORS for details)
* \date 2019
* \copyright GPLv2 or later
*/
#include
<cassert>
#include
<utility>
#include
<vector>
#include
"HEJ/Event.hh"
#include
"HEJ/event_types.hh"
#include
"HEJ/LesHouchesWriter.hh"
#include
"HEJ/utility.hh"
namespace
HEJ
{
namespace
{
template
<
class
T
,
class
...
Args
>
std
::
unique_ptr
<
T
>
make_unique
(
Args
&&
...
a
){
return
std
::
unique_ptr
<
T
>
{
new
T
{
std
::
forward
<
Args
>
(
a
)...}};
}
size_t
to_index
(
event_type
::
EventType
const
type
){
return
type
==
0
?
0
:
floor
(
log2
(
type
))
+
1
;
}
}
LesHouchesWriter
::
LesHouchesWriter
(
std
::
string
const
&
file
,
LHEF
::
HEPRUP
heprup
)
:
out_
{
file
,
std
::
fstream
::
in
|
std
::
fstream
::
out
|
std
::
fstream
::
trunc
},
writer_
{
HEJ
::
make_unique
<
LHEF
::
Writer
>
(
out_
)}
{
if
(
!
out_
.
is_open
()){
throw
std
::
ios_base
::
failure
(
"Failed to open "
+
file
);
};
writer_
->
heprup
=
std
::
move
(
heprup
);
// lhe Stardard: IDWTUP (negative => weights = +/-)
// 1: weighted events, xs = mean(weight), XMAXUP given
// 2: weighted events, xs = XSECUP, XMAXUP given
// 3: unweighted events, no additional information given
// 4: unweighted events, xs = mean(weight), no additional information given
writer_
->
heprup
.
IDWTUP
=
2
;
const
int
max_number_types
=
to_index
(
event_type
::
last_type
)
+
1
;
writer_
->
heprup
.
NPRUP
=
max_number_types
;
// ids of event types
writer_
->
heprup
.
LPRUP
.
clear
();
writer_
->
heprup
.
LPRUP
.
reserve
(
max_number_types
);
writer_
->
heprup
.
LPRUP
.
emplace_back
(
0
);
for
(
size_t
i
=
event_type
::
first_type
+
1
;
i
<=
event_type
::
last_type
;
i
*=
2
)
writer_
->
heprup
.
LPRUP
.
emplace_back
(
i
);
// use placeholders for unknown init block values
// we can overwrite them after processing all events
writer_
->
heprup
.
XSECUP
=
std
::
vector
<
double
>
(
max_number_types
,
0.
);
writer_
->
heprup
.
XERRUP
=
std
::
vector
<
double
>
(
max_number_types
,
0.
);
writer_
->
heprup
.
XMAXUP
=
std
::
vector
<
double
>
(
max_number_types
,
0.
);
write_init
();
}
void
LesHouchesWriter
::
write
(
Event
const
&
ev
){
assert
(
writer_
&&
out_
.
is_open
());
const
double
wt
=
ev
.
central
().
weight
;
writer_
->
hepeup
=
HEJ
::
to_HEPEUP
(
std
::
move
(
ev
),
&
heprup
());
writer_
->
writeEvent
();
assert
(
heprup
().
XSECUP
.
size
()
>
to_index
(
ev
.
type
()));
heprup
().
XSECUP
[
to_index
(
ev
.
type
())]
+=
wt
;
heprup
().
XERRUP
[
to_index
(
ev
.
type
())]
+=
wt
*
wt
;
if
(
wt
>
heprup
().
XMAXUP
[
to_index
(
ev
.
type
())]){
heprup
().
XMAXUP
[
to_index
(
ev
.
type
())]
=
wt
;
}
}
// this function is called after overwritting the Les Houches init block
// assert that we have overwritten *exactly* the init block,
// i.e. we are at the end of the file or an intact event block is next
void
assert_next_event_intact
(
std
::
istream
&
out
){
(
void
)
out
;
// suppress compiler warnings if not in debug mode
#ifndef NDEBUG
std
::
string
line
;
getline
(
out
,
line
);
assert
(
out
.
eof
()
||
line
==
"<event>"
);
#endif
}
void
LesHouchesWriter
::
rewrite_init
(){
assert
(
writer_
&&
out_
.
is_open
());
// replace placeholder entries
const
auto
pos
=
out_
.
tellp
();
out_
.
seekp
(
0
);
writer_
->
init
();
assert_next_event_intact
(
out_
);
out_
.
seekp
(
pos
);
}
LesHouchesWriter
::~
LesHouchesWriter
(){
assert
(
writer_
&&
out_
.
is_open
());
for
(
auto
&
xs_err
:
heprup
().
XERRUP
)
{
xs_err
=
sqrt
(
xs_err
);
}
rewrite_init
();
}
}
File Metadata
Details
Attached
Mime Type
text/x-c
Expires
Tue, Sep 30, 6:15 AM (5 h, 57 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
6479393
Default Alt Text
LesHouchesWriter.cc (3 KB)
Attached To
Mode
rHEJ HEJ
Attached
Detach File
Event Timeline
Log In to Comment