Skip to content

Commit c498cde

Browse files
authored
Merge pull request #68 from JETSCAPE/vertexInformation
add vertex information to final state hadron and partons
2 parents 54c7f5d + a2f4304 commit c498cde

9 files changed

+94
-16
lines changed

config/jetscape_main.xml

+2
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,11 @@
4646
<!-- -9999 corresponds to skipping no status code. It needs to have some entry to be avoid a segfault w/ empty values in tinyxml -->
4747
<FinalStateHadrons>
4848
<statusToSkip>-9999</statusToSkip>
49+
<headerVersion>2</headerVersion>
4950
</FinalStateHadrons>
5051
<FinalStatePartons>
5152
<statusToSkip>-9999</statusToSkip>
53+
<headerVersion>2</headerVersion>
5254
</FinalStatePartons>
5355
</Writer>
5456

examples/FinalStateHadrons.cc

+14-6
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,13 @@ int main(int argc, char** argv)
4848
// //If you want to suppress it: use SetVerboseLevel(0) or max SetVerboseLevel(9) or 10
4949
JetScapeLogger::Instance()->SetVerboseLevel(0);
5050

51-
// Whether to write the new header (ie. v2), including xsec info.
52-
// To enable, pass anything as the third argument to enable this option.
53-
// Default: version 1.
54-
int headerVersion = 1;
51+
// Whether to write a particular header version (eg. v2), including xsec info.
52+
// To enable, pass the desired version (just the number) as the third argument.
53+
// Default: v1
54+
unsigned int headerVersion = 1;
5555
if (argc > 3) {
5656
headerVersion = std::atoi(argv[3]);
57+
std::cout << "NOTE: Writing header v" << headerVersion << ", and final cross section and error at EOF.\n";
5758
}
5859
std::cout << "NOTE: Writing with output version v" << headerVersion << "\n";
5960

@@ -77,13 +78,20 @@ int main(int argc, char** argv)
7778
if (hadrons.size() > 0)
7879
{
7980
++SN;
80-
if (headerVersion == 2) {
81+
if (headerVersion > 1) {
8182
// NOTE: Needs consistent "\t" between all entries to simplify parsing later.
8283
dist_output << "#"
8384
<< "\t" << "Event\t" << SN
8485
<< "\t" << "weight\t" << reader->GetEventWeight()
8586
<< "\t" << "EPangle\t" << reader->GetEventPlaneAngle()
86-
<< "\t" << "N_hadrons\t" << hadrons.size()
87+
<< "\t" << "N_hadrons\t" << hadrons.size();
88+
if (headerVersion == 3) {
89+
dist_output
90+
<< "\t" << "vertex_x\t" << reader->GetVertexX()
91+
<< "\t" << "vertex_y\t" << reader->GetVertexY()
92+
<< "\t" << "vertex_z\t" << reader->GetVertexZ();
93+
}
94+
dist_output
8795
<< "\t" << "|" // As a delimiter
8896
<< "\t" << "N"
8997
<< "\t" << "pid"

examples/FinalStatePartons.cc

+14-6
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,13 @@ int main(int argc, char** argv)
4949
// //If you want to suppress it: use SetVerboseLevle(0) or max SetVerboseLevel(9) or 10
5050
JetScapeLogger::Instance()->SetVerboseLevel(0);
5151

52-
// Whether to write the new header (ie. v2), including xsec info.
53-
// To enable, pass anything as the third argument to enable this option.
54-
// Default: version 1.
55-
int headerVersion = 1;
52+
// Whether to write a particular header version (eg. v2), including xsec info.
53+
// To enable, pass the desired version (just the number) as the third argument.
54+
// Default: v1
55+
unsigned int headerVersion = 1;
5656
if (argc > 3) {
5757
headerVersion = std::atoi(argv[3]);
58+
std::cout << "NOTE: Writing header v" << headerVersion << ", and final cross section and error at EOF.\n";
5859
}
5960
std::cout << "NOTE: Writing with output version v" << headerVersion << "\n";
6061

@@ -83,13 +84,20 @@ int main(int argc, char** argv)
8384
if(TotalPartons > 0)
8485
{
8586
++SN;
86-
if (headerVersion == 2) {
87+
if (headerVersion > 1) {
8788
// NOTE: Needs consistent "\t" between all entries to simplify parsing later.
8889
dist_output << "#"
8990
<< "\t" << "Event\t" << SN
9091
<< "\t" << "weight\t" << reader->GetEventWeight()
9192
<< "\t" << "EPangle\t" << reader->GetEventPlaneAngle()
92-
<< "\t" << "N_partons\t" << TotalPartons
93+
<< "\t" << "N_partons\t" << TotalPartons;
94+
if (headerVersion == 3) {
95+
dist_output
96+
<< "\t" << "vertex_x\t" << reader->GetVertexX()
97+
<< "\t" << "vertex_y\t" << reader->GetVertexY()
98+
<< "\t" << "vertex_z\t" << reader->GetVertexZ();
99+
}
100+
dist_output
93101
<< "\t" << "|" // As a delimiter
94102
<< "\t" << "N"
95103
<< "\t" << "pid"

src/framework/HardProcess.cc

+4
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ void HardProcess::Init() {
6464
printer = GetXMLElementText({"PartonPrinter","FileName"});
6565
JSINFO << BOLDYELLOW << "Extra parton info goes to " << printer ;
6666
}
67+
6768
InitTask();
6869
InitTasks();
6970
}
@@ -122,6 +123,9 @@ void HardProcess::CollectHeader(weak_ptr<JetScapeWriter> w) {
122123
header.SetSigmaErr(GetSigmaErr());
123124
header.SetPtHat(GetPtHat());
124125
header.SetEventWeight(GetEventWeight());
126+
header.SetVertexX(hp_list[0]->x_in().x());
127+
header.SetVertexY(hp_list[0]->x_in().y());
128+
header.SetVertexZ(hp_list[0]->x_in().z());
125129
}
126130
}
127131

src/framework/JetScapeEventHeader.h

+15
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@ class JetScapeEventHeader {
5858
double GetEventWeight() { return EventWeight; };
5959
/// Initial Hard Process: Set additionally created weight (e.g. pythia.event().weight())
6060
void SetEventWeight(double d) { EventWeight = d; };
61+
/// Initial Hard Process: Get vertex X position
62+
double GetVertexX() { return vX; };
63+
/// Initial Hard Process: Set vertex X position
64+
void SetVertexX(double d) { vX = d; };
65+
/// Initial Hard Process: Get vertex Y position
66+
double GetVertexY() { return vY; };
67+
/// Initial Hard Process: Set vertex Y position
68+
void SetVertexY(double d) { vY = d; };
69+
/// Initial Hard Process: Get vertex Z position
70+
double GetVertexZ() { return vZ; };
71+
/// Initial Hard Process: Set vertex Z position
72+
void SetVertexZ(double d) { vZ = d; };
6173

6274
// ============================ Initial State =================================
6375
/// Initial State: Get number of participants
@@ -92,6 +104,9 @@ class JetScapeEventHeader {
92104
double SigmaErr = -1;
93105
double PtHat = -1;
94106
double EventWeight = 1;
107+
double vX = -999;
108+
double vY = -999;
109+
double vZ = -999;
95110

96111
// ============================ Initial State =================================
97112
double Npart = -1; // could be int, but using double to allow averaged values

src/framework/JetScapeWriterFinalStateStream.cc

+22-4
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ JetScapeWriterFinalStateStream<T>::JetScapeWriterFinalStateStream(string m_file_
6464
particles{},
6565
writeCentrality{false},
6666
writePtHat{false},
67-
particleStatusToSkip{}
67+
particleStatusToSkip{},
68+
output_file{},
69+
headerVersion{2}
6870
{
6971
SetOutputFileName(m_file_name_out);
7072
}
@@ -130,7 +132,14 @@ template <class T> void JetScapeWriterFinalStateStream<T>::WriteEvent() {
130132
<< "\t" << "Event\t" << GetCurrentEvent() + 1 // +1 to index the event count from 1
131133
<< "\t" << "weight\t" << std::setprecision(15) << GetHeader().GetEventWeight() << std::setprecision(6)
132134
<< "\t" << "EPangle\t" << (GetHeader().GetEventPlaneAngle() > -999 ? GetHeader().GetEventPlaneAngle() : 0)
133-
<< "\t" << "N_" << GetName() << "\t" << ipart
135+
<< "\t" << "N_" << GetName() << "\t" << ipart;
136+
if (headerVersion == 3) {
137+
output_file
138+
<< "\t" << "vertex_x\t" << GetHeader().GetVertexX()
139+
<< "\t" << "vertex_y\t" << GetHeader().GetVertexY()
140+
<< "\t" << "vertex_z\t" << GetHeader().GetVertexZ();
141+
}
142+
output_file
134143
<< centrality_text
135144
<< pt_hat_text
136145
<< "\n";
@@ -161,14 +170,23 @@ template <class T> void JetScapeWriterFinalStateStream<T>::InitTask() {
161170
particleStatusToSkip.erase(std::remove(particleStatusToSkip.begin(), particleStatusToSkip.end(), -9999), particleStatusToSkip.end());
162171
}
163172
if (GetActive()) {
164-
JSINFO << "JetScape Final State " << name << " Stream Writer initialized with output file = "
173+
// We need the header version to determine how to write.
174+
// NOTE: Don't require the version. If not specified, defaults to v2.
175+
int result = GetXMLElementInt({"Writer", (std::string("FinalState") + name).c_str(), "headerVersion"}, false);
176+
// If it fails to retrieve the value, it will return 0. The header version must be >= 2,
177+
// so only assign if the value is actually set.
178+
if (result) {
179+
headerVersion = static_cast<unsigned int>(result);
180+
}
181+
182+
JSINFO << "JetScape Final State " << name << " Stream Writer v" << headerVersion << " initialized with output file = "
165183
<< GetOutputFileName();
166184
output_file.open(GetOutputFileName().c_str());
167185
// NOTE: This header will only be printed once at the beginning on the file.
168186
output_file << "#"
169187
// The specifics the version number. For consistency in parsing, the string
170188
// will always be "v<number>"
171-
<< "\t" << "JETSCAPE_FINAL_STATE\t" << "v2"
189+
<< "\t" << "JETSCAPE_FINAL_STATE\t" << "v" << headerVersion
172190
<< "\t" << "|" // As a delimiter
173191
<< "\t" << "N"
174192
<< "\t" << "pid"

src/framework/JetScapeWriterFinalStateStream.h

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class JetScapeWriterFinalStateStream : public JetScapeWriter {
6464

6565
protected:
6666
T output_file; //!< Output file
67+
unsigned int headerVersion;
6768
std::vector<std::shared_ptr<JetScapeParticleBase>> particles;
6869
bool writeCentrality;
6970
bool writePtHat;

src/reader/JetScapeReader.cc

+16
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ template <class T> JetScapeReader<T>::JetScapeReader():
2222
currentEvent{-1}
2323
, sigmaGen{-1}
2424
, sigmaErr{-1}
25+
, vertexX{-999}
26+
, vertexY{-999}
27+
, vertexZ{-999}
2528
, eventWeight{-1}
2629
, EventPlaneAngle{0.0}
2730
{
@@ -39,6 +42,9 @@ template <class T> void JetScapeReader<T>::ClearTask() {
3942

4043
sigmaGen = -1;
4144
sigmaErr = -1;
45+
vertexX = -999;
46+
vertexY = -999;
47+
vertexZ = -999;
4248
eventWeight = -1;
4349
EventPlaneAngle = 0.0;
4450
}
@@ -151,6 +157,16 @@ template <class T> void JetScapeReader<T>::Next() {
151157
data >> dummy >> dummy >> dummy >> EventPlaneAngle;
152158
JSDEBUG << " EventPlaneAngle=" << EventPlaneAngle;
153159
}
160+
// vertex position of hard scattering
161+
if (line.find("HardProcess") != std::string::npos) {
162+
getline(inFile, line); // get next line to get vertex position
163+
std::stringstream data(line);
164+
double dummy;
165+
data >> dummy >> dummy >> dummy >> dummy >> dummy >> dummy >> dummy >> vertexX >> vertexY >> vertexZ;
166+
JSDEBUG << " vertexX=" << vertexX;
167+
JSDEBUG << " vertexY=" << vertexY;
168+
JSDEBUG << " vertexZ=" << vertexZ;
169+
}
154170
continue;
155171
}
156172

src/reader/JetScapeReader.h

+6
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ template <class T> class JetScapeReader {
6464
double GetSigmaErr() const { return sigmaErr; }
6565
double GetEventWeight() const { return eventWeight; }
6666
double GetEventPlaneAngle() const { return EventPlaneAngle; }
67+
double GetVertexX() const { return vertexX; }
68+
double GetVertexY() const { return vertexY; }
69+
double GetVertexZ() const { return vertexZ; }
6770

6871
private:
6972
StringTokenizer strT;
@@ -89,6 +92,9 @@ template <class T> class JetScapeReader {
8992
double sigmaErr;
9093
double eventWeight;
9194
double EventPlaneAngle;
95+
double vertexX;
96+
double vertexY;
97+
double vertexZ;
9298
};
9399

94100
typedef JetScapeReader<ifstream> JetScapeReaderAscii;

0 commit comments

Comments
 (0)