Skip to content

Commit f7e61c0

Browse files
authored
Add switch for synthetic flow in standard gap triggered LF generator (#1968)
Co-authored-by: David Dobrigkeit Chinellato <david.dobrigkeit.chinellato.cern.ch>
1 parent 506cec9 commit f7e61c0

File tree

2 files changed

+112
-7
lines changed

2 files changed

+112
-7
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[GeneratorExternal]
2+
fileName=${O2DPG_MC_CONFIG_ROOT}/MC/config/PWGLF/pythia8/generator_pythia8_longlived_gaptriggered_flow.C
3+
funcName=generateLongLivedGapTriggered("${O2DPG_MC_CONFIG_ROOT}/MC/config/PWGLF/pythia8/generator/hypernuclei_pbpb.gun", 1, 1, 1)
4+
5+
[GeneratorPythia8]
6+
config=${O2_ROOT}/share/Generators/egconfig/pythia8_hi.cfg
7+

MC/config/PWGLF/pythia8/generator_pythia8_longlived_gaptriggered.C

Lines changed: 105 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11

2-
#if !defined(__CLING__) || defined(__ROOTCLING__)
32
#include "Pythia8/Pythia.h"
3+
#include "Pythia8/HeavyIons.h" // for event plane angle
4+
5+
#if !defined(__CLING__) || defined(__ROOTCLING__)
46
#include "FairGenerator.h"
57
#include "FairPrimaryGenerator.h"
68
#include "Generators/GeneratorPythia8.h"
79
#include "fairlogger/Logger.h"
10+
#include "CCDB/BasicCCDBManager.h"
811
#include "TRandom3.h"
912
#include "TParticlePDG.h"
1013
#include "TDatabasePDG.h"
@@ -21,7 +24,7 @@ class GeneratorPythia8LongLivedGapTriggered : public o2::eventgen::GeneratorPyth
2124
{
2225
public:
2326
/// Constructor
24-
GeneratorPythia8LongLivedGapTriggered(std::vector<int> input_pdg, int input_trigger_ratio = 1, int n_injected = 1, float pt_min = 1, float pt_max = 10, float y_min = -1, float y_max = 1)
27+
GeneratorPythia8LongLivedGapTriggered(std::vector<int> input_pdg, int input_trigger_ratio = 1, int n_injected = 1, float pt_min = 1, float pt_max = 10, float y_min = -1, float y_max = 1, bool addSyntheticFlow = false)
2528
{
2629
mPdg = input_pdg;
2730
setNinjected(n_injected);
@@ -31,10 +34,38 @@ public:
3134
mMass = getMass(input_pdg);
3235
mGeneratedEvents = 0;
3336
mAlternatingPDGsign = true;
37+
mAddSyntheticFlow = addSyntheticFlow;
38+
39+
if(mAddSyntheticFlow){
40+
lutGen = new o2::eventgen::FlowMapper();
41+
42+
// -------- CONFIGURE SYNTHETIC FLOW ------------
43+
// establish connection to ccdb
44+
o2::ccdb::CcdbApi ccdb_api;
45+
ccdb_api.init("https://alice-ccdb.cern.ch");
46+
47+
// config was placed at midpoint of run 544122, retrieve that
48+
std::map<string, string> metadataRCT, headers;
49+
headers = ccdb_api.retrieveHeaders("RCT/Info/RunInformation/544122", metadataRCT, -1);
50+
int64_t tsSOR = atol(headers["SOR"].c_str());
51+
int64_t tsEOR = atol(headers["EOR"].c_str());
52+
int64_t midRun = 0.5*tsSOR+0.5*tsEOR;
53+
54+
map<string, string> metadata; // can be empty
55+
auto list = ccdb_api.retrieveFromTFileAny<TList>("Users/d/ddobrigk/syntheflow", metadata, midRun);
56+
57+
TH1D *hv2vspT = (TH1D*) list->FindObject("hFlowVsPt_ins1116150_v1_Table_1");
58+
TH1D *heccvsb = (TH1D*) list->FindObject("hEccentricityVsB");
59+
60+
cout<<"Generating LUT for flow test"<<endl;
61+
lutGen->CreateLUT(hv2vspT, heccvsb);
62+
cout<<"Finished creating LUT!"<<endl;
63+
// -------- END CONFIGURE SYNTHETIC FLOW ------------
64+
}
3465
}
3566

3667
/// Constructor from config file
37-
GeneratorPythia8LongLivedGapTriggered(std::string file_name, int input_trigger_ratio = 1)
68+
GeneratorPythia8LongLivedGapTriggered(std::string file_name, int input_trigger_ratio = 1, bool addSyntheticFlow = false)
3869
{
3970
auto expanded_file_name = gSystem->ExpandPathName(file_name.c_str());
4071
std::ifstream config_file(expanded_file_name);
@@ -65,6 +96,34 @@ public:
6596
mMass = getMass(mPdg);
6697
mGeneratedEvents = 0;
6798
mAlternatingPDGsign = true;
99+
mAddSyntheticFlow = addSyntheticFlow;
100+
101+
if(mAddSyntheticFlow){
102+
lutGen = new o2::eventgen::FlowMapper();
103+
104+
// -------- CONFIGURE SYNTHETIC FLOW ------------
105+
// establish connection to ccdb
106+
o2::ccdb::CcdbApi ccdb_api;
107+
ccdb_api.init("https://alice-ccdb.cern.ch");
108+
109+
// config was placed at midpoint of run 544122, retrieve that
110+
std::map<string, string> metadataRCT, headers;
111+
headers = ccdb_api.retrieveHeaders("RCT/Info/RunInformation/544122", metadataRCT, -1);
112+
int64_t tsSOR = atol(headers["SOR"].c_str());
113+
int64_t tsEOR = atol(headers["EOR"].c_str());
114+
int64_t midRun = 0.5*tsSOR+0.5*tsEOR;
115+
116+
map<string, string> metadata; // can be empty
117+
auto list = ccdb_api.retrieveFromTFileAny<TList>("Users/d/ddobrigk/syntheflow", metadata, midRun);
118+
119+
TH1D *hv2vspT = (TH1D*) list->FindObject("hFlowVsPt_ins1116150_v1_Table_1");
120+
TH1D *heccvsb = (TH1D*) list->FindObject("hEccentricityVsB");
121+
122+
cout<<"Generating LUT for flow test"<<endl;
123+
lutGen->CreateLUT(hv2vspT, heccvsb);
124+
cout<<"Finished creating LUT!"<<endl;
125+
// -------- END CONFIGURE SYNTHETIC FLOW ------------
126+
}
68127
}
69128

70129
/// Destructor
@@ -155,6 +214,42 @@ public:
155214
o2::mcutils::MCGenHelper::encodeParticleStatusAndTracking(mParticles.back());
156215
}
157216
}
217+
218+
if(mAddSyntheticFlow){
219+
//+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
220+
// loop over the entire event record and rotate all particles
221+
// synthetic flow exercise
222+
// first: get event plane
223+
float eventPlaneAngle = mPythia.info.hiInfo->phi();
224+
float impactParameter = mPythia.info.hiInfo->b();
225+
226+
for ( Long_t j=0; j < mPythia.event.size(); j++ ) {
227+
float pyphi = mPythia.event[j].phi();
228+
float pypT = mPythia.event[j].pT();
229+
230+
// calculate delta with EP
231+
float deltaPhiEP = pyphi - eventPlaneAngle;
232+
float shift = 0.0;
233+
while(deltaPhiEP<0.0){
234+
deltaPhiEP += 2*TMath::Pi();
235+
shift += 2*TMath::Pi();
236+
}
237+
while(deltaPhiEP>2*TMath::Pi()){
238+
deltaPhiEP -= 2*TMath::Pi();
239+
shift -= 2*TMath::Pi();
240+
}
241+
float newDeltaPhiEP = lutGen->MapPhi(deltaPhiEP, impactParameter, pypT);
242+
float pyphiNew = newDeltaPhiEP - shift + eventPlaneAngle;
243+
244+
if(pyphiNew>TMath::Pi())
245+
pyphiNew -= 2.0*TMath::Pi();
246+
if(pyphiNew<-TMath::Pi())
247+
pyphiNew += 2.0*TMath::Pi();
248+
mPythia.event[j].rot(0.0, pyphiNew-pyphi);
249+
}
250+
}
251+
//+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
252+
158253
mGeneratedEvents++;
159254
return true;
160255
}
@@ -169,18 +264,21 @@ private:
169264
std::vector<double> mYmax; /// maximum rapidity for generated particles
170265

171266
bool mAlternatingPDGsign = true; /// bool to randomize the PDG code of the core particle
267+
bool mAddSyntheticFlow = false; /// switch to add synthetic flow (requires EP angle from PYTHIA)
172268

173269
std::vector<int> mNinjected; /// Number of injected particles
174270

175271
// Control gap-triggering
176272
unsigned long long mGeneratedEvents; /// number of events generated so far
177273
int mInverseTriggerRatio; /// injection gap
274+
275+
o2::eventgen::FlowMapper *lutGen; // for mapping phi angles
178276
};
179277

180278
///___________________________________________________________
181-
FairGenerator *generateLongLivedGapTriggered(std::vector<int> mPdg, int input_trigger_ratio, int n_injected = 1, float pt_min = 1, float pt_max = 10, float y_min = -1, float y_max = 1, bool alternate_sign = true)
279+
FairGenerator *generateLongLivedGapTriggered(std::vector<int> mPdg, int input_trigger_ratio, int n_injected = 1, float pt_min = 1, float pt_max = 10, float y_min = -1, float y_max = 1, bool alternate_sign = true, bool addSyntheticFlow = false)
182280
{
183-
auto myGen = new GeneratorPythia8LongLivedGapTriggered(mPdg, input_trigger_ratio, n_injected, pt_min, pt_max, y_min, y_max);
281+
auto myGen = new GeneratorPythia8LongLivedGapTriggered(mPdg, input_trigger_ratio, n_injected, pt_min, pt_max, y_min, y_max, addSyntheticFlow);
184282
myGen->setAlternatingPDGsign(alternate_sign);
185283
auto seed = (gRandom->TRandom::GetSeed() % 900000000);
186284
myGen->readString("Random:setSeed on");
@@ -189,9 +287,9 @@ FairGenerator *generateLongLivedGapTriggered(std::vector<int> mPdg, int input_tr
189287
}
190288

191289
///___________________________________________________________
192-
FairGenerator *generateLongLivedGapTriggered(std::string config_file_name, int input_trigger_ratio, bool alternate_sign = true)
290+
FairGenerator *generateLongLivedGapTriggered(std::string config_file_name, int input_trigger_ratio, bool alternate_sign = true, bool addSyntheticFlow = false)
193291
{
194-
auto myGen = new GeneratorPythia8LongLivedGapTriggered(config_file_name, input_trigger_ratio);
292+
auto myGen = new GeneratorPythia8LongLivedGapTriggered(config_file_name, input_trigger_ratio, addSyntheticFlow);
195293
myGen->setAlternatingPDGsign(alternate_sign);
196294
auto seed = (gRandom->TRandom::GetSeed() % 900000000);
197295
myGen->readString("Random:setSeed on");

0 commit comments

Comments
 (0)