ATLAS Offline Software
Loading...
Searching...
No Matches
AddFlowByShifting.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5// File: Generators/FlowAfterburner/AddFlowByShifting.cxx
6// Description:
7// This code is used to introduce particle flow
8// to particles from generated events
9//
10// AuthorList:
11// Andrzej Olszewski: Initial Code February 2006
12// 11.10.2006: Add predefined flow function by name
13
15
16#include <set>
17#include <cmath>
18
19// For the Athena-based random numbers
21#include "CLHEP/Random/RandomEngine.h"
22#include "CLHEP/Random/RandFlat.h"
23#include "CLHEP/Random/RandGaussQ.h"
24#include "CLHEP/Vector/LorentzVector.h"
25//
28#include "AtlasHepMC/Relatives.h" //descendant_vertices
29// gnus scientific library
30#include <gsl/gsl_errno.h>
31#include <gsl/gsl_math.h>
32#include <gsl/gsl_roots.h>
33
34#include "GaudiKernel/PhysicalConstants.h"
35
37
38#include "TGraph.h"
39
40double AddFlowByShifting::vn_func(double x, void *params)
41{
42 float *par_float = (float*) params;
43 double phi_0 = par_float[0];
44 float *vn = par_float+1;
45 float *psi_n = vn+Harmonic::NumHar;
46 double val=x +2*( vn[Harmonic::v1]*sin(1*(x-psi_n[Harmonic::v1]))/1.0 +
47 vn[Harmonic::v2]*sin(2*(x-psi_n[Harmonic::v2]))/2.0 +
48 vn[Harmonic::v3]*sin(3*(x-psi_n[Harmonic::v3]))/3.0 +
49 vn[Harmonic::v4]*sin(4*(x-psi_n[Harmonic::v4]))/4.0 +
50 vn[Harmonic::v5]*sin(5*(x-psi_n[Harmonic::v5]))/5.0 +
51 vn[Harmonic::v6]*sin(6*(x-psi_n[Harmonic::v6]))/6.0 );
52 return val-phi_0;
53}
54
55
56AddFlowByShifting::AddFlowByShifting(const std::string& name, ISvcLocator* pSvcLocator) :
57 AthAlgorithm(name, pSvcLocator)
58{
59 m_flow_function= NULL;
60 for(int ihar = 0; ihar< Harmonic::NumHar; ihar++){
61 m_psi_n[ihar] =0.0;
62 m_v_n [ihar] =0.0;
63 m_EbE_Multiplier_vn[ihar]=1.0;
64 }
65}
66
67
69 ATH_MSG_INFO(">>> AddFlowByShifting from Initialize <<<");
70
71 ATH_CHECK(m_rndmSvc.retrieve());
72
73 ATH_MSG_INFO("**********Settings for Afterburner************");
74 ATH_MSG_INFO("McTruthKey : " << m_inkey );
75 ATH_MSG_INFO("McFlowKey : " << m_outkey );
76
77 ATH_MSG_INFO("FlowFunctionName : " << m_flow_function_name );
78 ATH_MSG_INFO("FlowInplementation : " << m_flow_implementation);
79 ATH_MSG_INFO("FlowFluctuations : " << m_flow_fluctuations );
80
81 ATH_MSG_INFO("RandomizePhi : " << m_ranphi_sw );
82
83 ATH_MSG_INFO("FlowEtaSwitch : " << m_floweta_sw );
84 ATH_MSG_INFO("FlowMinEtaCut : " << m_flow_mineta );
85 ATH_MSG_INFO("FlowMaxEtaCut : " << m_flow_maxeta );
86
87 ATH_MSG_INFO("FlowPtSwitch : " << m_flowpt_sw );
88 ATH_MSG_INFO("FlowMinPtCut : " << m_flow_minpt );
89 ATH_MSG_INFO("FlowMaxPtCut : " << m_flow_maxpt );
90
91 ATH_MSG_INFO("FlowV1 : " << m_custom_v1 );
92 ATH_MSG_INFO("FlowV2 : " << m_custom_v2 );
93 ATH_MSG_INFO("FlowV3 : " << m_custom_v3 );
94 ATH_MSG_INFO("FlowV4 : " << m_custom_v4 );
95 ATH_MSG_INFO("FlowV5 : " << m_custom_v5 );
96 ATH_MSG_INFO("FlowV6 : " << m_custom_v6 );
97 ATH_MSG_INFO("FlowBSwitch : " << m_flowb_sw );
98 ATH_MSG_INFO("********************************r*************");
99
100
101 // Select the flow-implementing function based of the function-choice variable
112 else{
113 ATH_MSG_ERROR("Unimplemented option for setting 'FlowFunctionName' : " << m_flow_function_name);
114 return StatusCode::FAILURE;
115 }
116
117
119 if (m_flow_implementation=="approximate"){
121 ATH_MSG_WARNING("'FlowInplementation=\"approximate\"' is obsolete, please switch to 'FlowInplementation=\"exact\"' ");
122 }
123 else if(m_flow_implementation=="exact" ){
125 }
126 else{
127 ATH_MSG_ERROR("Unimplemented option for setting 'FlowInplementation' : " << m_flow_implementation);
128 return StatusCode::FAILURE;
129 }
130
131
132
133 //TGraph storing the v2_RP/delta Vs b_imp values to be used in implementing the EbyE fluctuations
134 //the values below are b_imp-low,b_imp-high, delta/v2_RP for different centralities
135 //underflow and overflow bins are added for smooth extrapolation
137 //Fluctuations for Pb+Pb
138 if(m_flow_function_name=="jjia_minbias_new" ||
139 m_flow_function_name=="jjia_minbias_new_v2only")
140 {
141 //The delta/v2_RP values are taken from Fig15 of EbE vn paper (arXiv:1305.2942)
142 // <0 , 0-1 , 1-2 , 2-3 , 3-4 , 4-5 , 5-10 , 10-15, 15-20, 20-25, 25-30,
143 float b_lo[21]={ -1.00, 0.000, 1.483, 2.098, 2.569, 2.966, 3.317, 4.687, 5.739, 6.627, 7.409,
144 8.117, 8.767, 9.373, 9.943,10.479,10.991,11.479,11.947,15.00 ,100.0};
145 // 30-35, 35-40, 40-45, 45-50, 50-55, 55-60, 60-65, 65-70, 70-
146 float b_hi[21]={ -1.00 , 1.483, 2.098, 2.569, 2.966, 3.317, 4.687, 5.739, 6.627, 7.409, 8.117,//bimp_high
147 8.767, 9.373, 9.943,10.479,10.991,11.479,11.947,12.399,15.00 ,100.0};
148 float val [21]={ 5.600, 5.600, 5.600,1.175 ,0.8253,0.7209,0.5324,0.4431,0.3984,0.3844,0.3847,
149 0.3935,0.4106,0.4310,0.4574,0.4674,0.4873,0.4796,0.4856,0.5130,0.5130};
150 float bimp_vals[21];
151
152 for(int i=0;i<21;i++){
153 bimp_vals[i]=(b_lo[i]+b_hi[i])/2.0f;
154 val [i]=1.0f/val[i];//change to v2_RP/delta
155 val [i]=1.0/val[i];//change to v2_RP/delta
156 }
157
158 m_graph_fluc=new TGraph(21,bimp_vals,val);
159 }
160
161 //Fluctuations for O+O
162 if(m_flow_function_name=="OO_eta_indep")
163 {
164 //The v2{2} and v2{4} values are taken from the OO paper (arXiv:2509.05171)
165 //The v2{4} values beyond the 50-60% bin are put in by hand
166 //The v2{2} values beyond the 75-80% bin are put in by hand
167 //The impact parameters are obtained from HIJING
168
169 //4-particle cumulant v2 (v2{4})
170 // <0, 0-1, 1-2, 2-3, 3-4, 4-5, 5-10, 10-15, 15-20, 20-25, 25-30,
171 // 30-35, 35-40, 40-50, 50-60, 60-80, 80-100, >100,
172 float v2_4 [18]={ 0.0444322, 0.0444322, 0.0476009, 0.0495882, 0.0513053, 0.0527020, 0.0563533, 0.0614435, 0.0650522, 0.0675199, 0.0693970,
173 0.0705456, 0.0706748, 0.0686654, 0.0571383, 0.04 , 0.02 , 0.0 };//last three bins are put in by hand
174 float bimp4[18]={-1 , 0.481843, 0.886609 , 1.13462 , 1.33981 , 1.52064 , 1.95342 , 2.51881 , 2.97665 , 3.37416 , 3.72876 ,
175 4.05377 , 4.35564 , 4.77463 , 5.30719 , 6.08296 , 7.6415 , 15 };
176
177
178 // template-fit v2 (v2{2})
179 // <0, 0-1, 1-2, 2-3, 3-4, 4-5, 5-10, 10-15, 15-20, 20-25, 25-30,
180 // 30-35, 35-40, 40-45, 45-50, 50-55, 55-60, 60-65, 65-70, 70-75, 75-80, 80-100,>100
181 float v2_2 [23]={ 0.0749381, 0.0749381, 0.0782992, 0.0801742, 0.0814646, 0.0826611, 0.0853616, 0.0889407, 0.0913229, 0.0928072, 0.0933774,
182 0.0933299, 0.0926254, 0.0910148, 0.0889322, 0.086161 , 0.0828212, 0.0793132, 0.0755036, 0.0714726, 0.0668264, 0.055 , 0.05};//last two bins are put in by hand
183 float bimp2[23]={-1 , 0.481843, 0.886609 , 1.13462 , 1.33981 , 1.52064 , 1.95342 , 2.51881 , 2.97665 , 3.37416 , 3.72876 ,
184 4.05377 , 4.35564 , 4.63868 , 4.91057 , 5.17773 , 5.43665 , 5.68739 , 5.94258 , 6.20668 , 6.49519 , 7.6415 , 15};
185
186
187 //Evaluate ratio of v2{4}/delta
188 TGraph *graph_v2_4=new TGraph(18,bimp4,v2_4);
189 TGraph *graph_v2_2=new TGraph(23,bimp2,v2_2);
190 float ratio[23]={0};
191 for(int i=0;i<23;i++){
192 double vn_RP=graph_v2_4->Eval(bimp2[i]);
193 double vn_2 =graph_v2_2->Eval(bimp2[i]);
194 double delta=vn_2*vn_2 - vn_RP*vn_RP;
195 if(delta>0){
196 ratio[i]= vn_RP/sqrt(delta/2.0);
197 }
198 else{
199 ATH_MSG_ERROR("vn{2}<vn{4} for b_imp = " << bimp2[i]);
200 return StatusCode::FAILURE;
201 }
202 }
203
204 m_graph_fluc=new TGraph(23,bimp2,ratio);
205 delete graph_v2_4;
206 delete graph_v2_2;
207 }
208 //Fluctuations for Ne+Ne (TODO)
209
210 else{
211 ATH_MSG_ERROR("Flow fluctuations are not implemented for the following case: " << m_flow_function_name);
212 }
213 }
214
215
216 // Initialization terminated
217 return StatusCode::SUCCESS;
218}
219
220
221CLHEP::HepRandomEngine* AddFlowByShifting::getRandomEngine(const std::string& streamName,
222 const EventContext& ctx) const
223{
224 ATHRNG::RNGWrapper* rngWrapper = m_rndmSvc->getEngine(this, streamName);
225 std::string rngName = name()+streamName;
226 rngWrapper->setSeed( rngName, ctx );
227 return rngWrapper->getEngine(ctx);
228}
229
230
232 ATH_MSG_INFO(">>> AddFlowByShifting from execute");
233
234 const EventContext& ctx = Gaudi::Hive::currentContext();
235 CLHEP::HepRandomEngine *rndmEngine = getRandomEngine("FLOW", ctx);
236 // Get hijing event parameters
237 const HijingEventParams *hijing_pars;
238 if( evtStore()->retrieve(hijing_pars, "Hijing_event_params").isFailure() ) {
239 ATH_MSG_ERROR("Could not retrieve Hijing_event_params");
240 return StatusCode::FAILURE;
241 }
242 ATH_MSG_INFO("Event parameters: B = " << hijing_pars->get_b()<<
243 " BPhi = " << hijing_pars->get_bphi());
244
245
246 // FIXME: changing data in the event store
247 HijingEventParams *hijing_pars_nc = const_cast<HijingEventParams*> (hijing_pars);
248
249
250 // Read Data from Transient Store
251 const McEventCollection* mcCollptr;
252 if ( evtStore()->retrieve(mcCollptr, m_inkey).isFailure() ) {
253 ATH_MSG_ERROR("Could not retrieve truth McEventCollection");
254 return StatusCode::FAILURE;
255 }
256
257
258 // Loop over all events in original McEventCollection and
259 // Copy to a new (modifiable) collection
261 McEventCollection* mcFlowCollptr = new McEventCollection();
262 for (citr = mcCollptr->begin(); citr!=mcCollptr->end(); ++citr) {
263 mcFlowCollptr->push_back(new HepMC::GenEvent(*(*citr)));
264 }
265
266
267 //Geneate the event-plane angles (some of them may or may not be used later on)
268 //Store the angles into the hijing event parameters
269 for(int ihar=0;ihar<6;ihar++){
270 m_psi_n[ihar] =(CLHEP::RandFlat::shoot(rndmEngine)-0.5)*2*M_PI / (ihar+1); //Principal value must be within -PI/n to PI/n
271 hijing_pars_nc->set_psi(ihar+1,m_psi_n[ihar]);
272 }
273 m_psi_n[1]=hijing_pars->get_bphi() ;//the psi2 plane is aligned with the impact parameter
274 m_psi_n[1]=std::atan2(std::sin(2*m_psi_n[1]),std::cos(2*m_psi_n[1]))/2.0;//ensure that Psi2 is within [-PI/2,PI/2]
275 hijing_pars_nc->set_psi(2,m_psi_n[1]);
276 ATH_MSG_DEBUG(" Psi2 for event : "<<(*hijing_pars).get_psi(2));
277
278
279 // Add flow by phi angle shifting
281 for (itr = mcFlowCollptr->begin(); itr!=mcFlowCollptr->end(); ++itr) {
282 ATH_MSG_DEBUG("Next event in the bag ...");
283
284
285
286#ifdef HEPMC3
287 auto mainvtx=(*itr)->vertices().front();
288 if(m_flow_fluctuations) Set_EbE_Fluctuation_Multipliers(mainvtx,hijing_pars->get_b(),rndmEngine);
289 int particles_in_event = (*itr)->particles().size();
291 for ( auto parent: mainvtx->particles_out())
292#else
293 auto mainvtx=*((*itr)->vertices_begin());
294 if(m_flow_fluctuations) Set_EbE_Fluctuation_Multipliers(mainvtx,hijing_pars->get_b(),rndmEngine);
295 int particles_in_event = (*itr)->particles_size();
297 for ( auto parent: *mainvtx)
298#endif
299 {
300 // Process particles from main vertex
301 CLHEP::HepLorentzVector momentum(parent->momentum().px(),
302 parent->momentum().py(),
303 parent->momentum().pz(),
304 parent->momentum().e());
305 ATH_MSG_DEBUG("Parent particle: " << parent <<
306 " Eta = " << momentum.pseudoRapidity()<<
307 " Phi = " << momentum.phi() );
308
309 //skip particle if eta is outside implementation range
310 if(m_floweta_sw){
311 float eta=std::abs(momentum.pseudoRapidity());
313 }
314
315 //skip particle if pT is outside implementation range
316 if(m_flowpt_sw){
317 float pT=momentum.perp();
318 if (pT<m_flow_minpt || pT> m_flow_maxpt) continue;
319 }
320
321 // Randomize phi if explicitely requested
322 if(m_ranphi_sw) {
323 double phishift = SetParentToRanPhi(parent, rndmEngine);
324 MoveDescendantsToParent(parent, phishift) ;// adjust descendants to parent position
325 }
326
327 // Add flow to particles from main vertex
328 double phishift = AddFlowToParent(parent, hijing_pars);
329 MoveDescendantsToParent(std::move(parent), phishift);// adjust descendants to parent position
330 }
331
332 // correct for double counting
334 // correct for incoming particles
335 ATH_MSG_INFO( " Particles in event: " << particles_in_event <<
336 " Processed for flow: " << m_particles_processed+2);
337 if(particles_in_event != (m_particles_processed+2)){
338 ATH_MSG_WARNING( " Particles in event: " << particles_in_event <<
339 " Processed for flow: " << m_particles_processed+2);
340 }
341 }
342
343 if(evtStore()->record(mcFlowCollptr, m_outkey).isFailure()){
344 ATH_MSG_ERROR("Could not record flow McEventCollection");
345 return StatusCode::FAILURE;
346 }
347 return StatusCode::SUCCESS;
348}
349
350
352 ATH_MSG_INFO(">>> AddFlowByShifting from finalize <<<");
353 if(m_graph_fluc){
354 delete m_graph_fluc ;
355 m_graph_fluc=nullptr;
356 }
357
358 // End of finalization step
359 return StatusCode::SUCCESS;
360}
361
362
364 CLHEP::HepRandomEngine *rndmEngine)
365{
366 // Set particle to random phi
367 // Return phi shift
369
370 double phi, phishift;
371 CLHEP::HepLorentzVector momentum(parent->momentum().px(),
372 parent->momentum().py(),
373 parent->momentum().pz(),
374 parent->momentum().e());
375 phi = momentum.phi();
376
377 double rannum = CLHEP::RandFlat::shoot(rndmEngine);
378 double ranphi = (rannum-0.5)*2*M_PI;
379 phishift = ranphi - phi;
380
381 momentum.setPhi(ranphi*Gaudi::Units::rad);
382 parent->set_momentum( HepMC::FourVector(momentum.px(),momentum.py(),momentum.pz(),momentum.e()) );
383
384 ATH_MSG_DEBUG("Parent phi randomized = " << momentum.phi());
385
386 return phishift;
387}
388
389
391(HepMC::GenParticlePtr parent, double phishift)
392{
393 // Move the branch of descendant vertices and particles
394 // by phishift to parent particle position
395 auto endvtx = parent->end_vertex();
396 if ( endvtx ) {
397 ATH_MSG_DEBUG("Processing branch of parent particle "<< parent);
398
399 //Added October 2025
400 // --- Rotate the parent’s end vertex itself ---
401 if (std::abs(phishift) > 1e-7) {
402 CLHEP::HepLorentzVector pos(endvtx->position().x(),
403 endvtx->position().y(),
404 endvtx->position().z(),
405 endvtx->position().t());
406 pos.rotateZ(phishift * Gaudi::Units::rad);
407 endvtx->set_position(HepMC::FourVector(pos.x(), pos.y(), pos.z(), pos.t()));
408 }
409
410
411 //Added October 2025
412 // --- Rotate the parent’s immediate daughters (outgoing of endvtx) ---
413 #ifdef HEPMC3
414 for (auto child : endvtx->particles_out())
415 #else
416 for (auto child : *endvtx)
417 #endif
418 {
419 CLHEP::HepLorentzVector p(child->momentum().px(),
420 child->momentum().py(),
421 child->momentum().pz(),
422 child->momentum().e());
423 if (std::abs(phishift) > 1e-7) {
424 p.rotateZ(phishift * Gaudi::Units::rad);
425 child->set_momentum(HepMC::FourVector(p.px(), p.py(), p.pz(), p.e()));
426 }
428 }
429
430
431 // now rotate descendant vertices
432 #ifdef HEPMC3
433 for (HepMC::GenVertexPtr descvtx: HepMC::descendant_vertices(endvtx)) { //}
434 #else
435 for ( HepMC::GenVertex::vertex_iterator
436 descvtxit = endvtx->vertices_begin(HepMC::descendants);
437 descvtxit != endvtx->vertices_end(HepMC::descendants);
438 ++descvtxit) {
439 auto descvtx = (*descvtxit);
440 #endif
441
442 ATH_MSG_DEBUG("Processing vertex " << descvtx);
443
444 // rotate vertex
445 if(std::abs(phishift) > 1e-7) {
446 CLHEP::HepLorentzVector position(descvtx->position().x(),
447 descvtx->position().y(),
448 descvtx->position().z(),
449 descvtx->position().t());
450 position.rotateZ(phishift*Gaudi::Units::rad);
451 descvtx->set_position(HepMC::FourVector( position.x(),position.y(),position.z(),position.t()) );
452 }
453
454 // now rotate their associated particles
455 #ifdef HEPMC3
456 for (auto descpart: descvtx->particles_out())
457 #else
458 for (auto descpart: *descvtx)
459 #endif
460 {
461 CLHEP::HepLorentzVector momentum(descpart->momentum().px(),
462 descpart->momentum().py(),
463 descpart->momentum().pz(),
464 descpart->momentum().e());
465 ATH_MSG_DEBUG("Descendant particle: " << descpart <<
466 " Eta = " << descpart->momentum().pseudoRapidity() <<
467 " Phi = " << descpart->momentum().phi() );
469 // rotate particle
470 if(std::abs(phishift) > 1e-7) {
471 momentum.rotateZ(phishift*Gaudi::Units::rad);
472 descpart->set_momentum( HepMC::FourVector(momentum.px(),momentum.py(),momentum.pz(),momentum.e()) );
473 ATH_MSG_DEBUG(" Phi shift = " << phishift<<
474 " Phi shifted = " << momentum.phi());
475 }
476 }
477 }
478 }
479 return;
480}
481
482
484{
486 CLHEP::HepLorentzVector momentum(parent->momentum().px(),
487 parent->momentum().py(),
488 parent->momentum().pz(),
489 parent->momentum().e());
490 double pt = parent->momentum().perp();
491 double eta = parent->momentum().pseudoRapidity();
492 double phi_0 = parent->momentum().phi();
493
494 int error_=0;
495 if(pt !=pt) {ATH_MSG_ERROR("ERROR pt of track is not defined");error_=1;} //true if pt==nan
496 if(eta !=eta) {ATH_MSG_ERROR("ERROR eta of track is not defined");error_=1;}
497 if(phi_0 !=phi_0) {ATH_MSG_ERROR("ERROR phi of track is not defined");error_=1;}
498 if(error_==1){
499 ATH_MSG_ERROR("Original Particle Momentum(px,py,pz,e,m)="<<parent->momentum().px()<<" "
500 <<parent->momentum().py()<<" "
501 <<parent->momentum().pz()<<" "
502 <<parent->momentum().e() <<" "
503 <<parent->momentum().m() <<" ");
504 }
505
506
507
508
509 //Call the appropriate function to set the vn values
510 for(int ihar = 0; ihar< Harmonic::NumHar; ihar++){m_v_n [ihar]=0.0;} //reset the vn for this particle
511 double b = hijing_pars->get_b();
512 (*this.*m_flow_function)(b,eta,pt);//Set the vn for this particle
513
514 //add EbE fluctuations
516 for(int ihar = 0; ihar< Harmonic::NumHar; ihar++){
517 m_v_n[ihar] *= m_EbE_Multiplier_vn[ihar];
518 if(m_v_n[ihar]>0.5){
519 ATH_MSG_WARNING(" Vn Too large "<<ihar+1<<" "<<m_EbE_Multiplier_vn[ihar]<<" "<<m_v_n[ihar]);m_v_n[ihar]=0.5;
520 }
521 }
522 }
523
524 double phishift=0;
525
526 // Old fashioned rotation(approximate)
528 float phi=phi_0;
529 phishift= -2*( m_v_n[Harmonic::v1]*sin(1*(phi-m_psi_n[Harmonic::v1]))/1.0 +
530 m_v_n[Harmonic::v2]*sin(2*(phi-m_psi_n[Harmonic::v2]))/2.0 +
531 m_v_n[Harmonic::v3]*sin(3*(phi-m_psi_n[Harmonic::v3]))/3.0 +
532 m_v_n[Harmonic::v4]*sin(4*(phi-m_psi_n[Harmonic::v4]))/4.0 +
533 m_v_n[Harmonic::v5]*sin(5*(phi-m_psi_n[Harmonic::v5]))/5.0 +
534 m_v_n[Harmonic::v6]*sin(6*(phi-m_psi_n[Harmonic::v6]))/6.0 );
535
536 }
537
538 // New fashioned rotation(exact)
539 else if (m_flow_implementation_type==1){
540 // Thread-safe according to https://www.gnu.org/software/gsl/doc/html/roots.html
541 const gsl_root_fsolver_type *T ATLAS_THREAD_SAFE = gsl_root_fsolver_brent;
542 gsl_root_fsolver *s = gsl_root_fsolver_alloc (T);
543 double x_lo=-2*M_PI,x_hi=2*M_PI;
544 float params[13];
545 for(int ipar=0;ipar<13;ipar++) {params[ipar]=0;}
546 gsl_function F;
547 F.function = &(AddFlowByShifting::vn_func);
548 F.params =&params;
549 gsl_root_fsolver_set (s, &F, x_lo, x_hi);
550 int iter=0;
551 params[ 0]=phi_0;
552 params[ 1]=m_v_n [Harmonic::v1];
553 params[ 2]=m_v_n [Harmonic::v2];
554 params[ 3]=m_v_n [Harmonic::v3];
555 params[ 4]=m_v_n [Harmonic::v4];
556 params[ 5]=m_v_n [Harmonic::v5];
557 params[ 6]=m_v_n [Harmonic::v6];
558 params[ 7]=m_psi_n[Harmonic::v1];
559 params[ 8]=m_psi_n[Harmonic::v2];
560 params[ 9]=m_psi_n[Harmonic::v3];
561 params[10]=m_psi_n[Harmonic::v4];
562 params[11]=m_psi_n[Harmonic::v5];
563 params[12]=m_psi_n[Harmonic::v6];
564 int status;
565 double phi=phi_0;
566 do
567 {
568 iter++;
569 status = gsl_root_fsolver_iterate (s);
570 phi = gsl_root_fsolver_root (s);
571 x_lo = gsl_root_fsolver_x_lower (s);
572 x_hi = gsl_root_fsolver_x_upper (s);
573 status = gsl_root_test_interval (x_lo, x_hi,0, 0.00001);
574 }
575 while (status == GSL_CONTINUE && iter < 1000);
576 gsl_root_fsolver_free (s);
577
578 if (iter>=1000) return 0;
579
580 phishift = phi-phi_0;
581 }
582
583 if(std::abs(phishift) > 1e-7) {
584 momentum.rotateZ(phishift*Gaudi::Units::rad);
585 parent->set_momentum( HepMC::FourVector(momentum.px(),momentum.py(),momentum.pz(),momentum.e()) );
586 }
587 ATH_MSG_DEBUG( "Parent particle:" <<
588 " V1 = " << m_v_n[Harmonic::v1] <<
589 " V2 = " << m_v_n[Harmonic::v2] <<
590 " V3 = " << m_v_n[Harmonic::v3] <<
591 " V4 = " << m_v_n[Harmonic::v4] <<
592 " V5 = " << m_v_n[Harmonic::v5] <<
593 " V6 = " << m_v_n[Harmonic::v6] <<
594 " Phi shift = " << phishift <<
595 " Phi shifted = " << momentum.phi() );
596
597 return phishift;
598}
599
600
601
602// New parameterization for Pb+Pb vn
603void AddFlowByShifting::jjia_minbias_new(double b, double eta, double pt)
604{
605 pt=pt/1000.0; //convert to GeV
606
607 float a1,a2,a3,a4;
608 a1=0.4397*std::exp(-(b-4.526)*(b-4.526)/72.0) + 0.636;
609 a2=1.916/(b+2) +0.1;
610 a3=4.79*0.0001*(b-0.621)*(b-10.172)*(b-23)+1.2; // this is >0 for b>0
611 a4=0.135*std::exp(-0.5*(b-10.855)*(b-10.855)/4.607/4.607) +0.0120;
612
613 float temp1 = std::pow(pt , a1) / (1+std::exp( (pt-3.0)/a3));
614 float temp2 = std::pow(pt+0.1,-a2) / (1+std::exp(-(pt-4.5)/a3));
615 float temp3 = 0.01 / (1+std::exp(-(pt-4.5)/a3));
616
617 m_v_n[Harmonic::v2] = ( a4*(temp1+temp2) + temp3 )* std::exp(-0.5* eta*eta /6.27/6.27) ;
618
619 float fb=0.97 +1.06*std::exp(-0.5*b*b/3.2/3.2);
620 m_v_n[Harmonic::v3]=std::pow(fb*std::sqrt(m_v_n[1]),3);
621
622 float gb= 1.096 +1.36 *std::exp(-0.5*b*b/3.0/3.0);
623 gb=gb*sqrt(m_v_n[1]);
624 m_v_n[Harmonic::v4]=pow(gb,4);
625 m_v_n[Harmonic::v5]=pow(gb,5);
626 m_v_n[Harmonic::v6]=pow(gb,6);
628}
629
630
631// New parameterization for Pb+Pb vn (v2 only)
632void AddFlowByShifting::jjia_minbias_new_v2only(double b, double eta, double pt)
633{
634 jjia_minbias_new(b, eta, pt);
635 //Set all harmonics except v2 to 0
636 m_v_n[Harmonic::v1] = 0;
637 m_v_n[Harmonic::v3] = 0;
638 m_v_n[Harmonic::v4] = 0;
639 m_v_n[Harmonic::v5] = 0;
640 m_v_n[Harmonic::v6] = 0;
641}
642
643
644// Fixed vn
645void AddFlowByShifting::fixed_vn(double /*b*/, double /*eta*/, double /*pt*/)
646{
647 m_v_n[Harmonic::v1]=0.0000;
648 m_v_n[Harmonic::v2]=0.0500;
649 m_v_n[Harmonic::v3]=0.0280;
650 m_v_n[Harmonic::v4]=0.0130;
651 m_v_n[Harmonic::v5]=0.0045;
652 m_v_n[Harmonic::v6]=0.0015;
653}
654
655
656// Fixed 5% v2 (other vn=0)
657void AddFlowByShifting::fixed_v2(double /*b*/, double /*eta*/, double /*pt*/)
658{
659 for(int ihar=0;ihar<Harmonic::NumHar;ihar++){
660 m_v_n[ihar]=0.0;
661 }
662 m_v_n[Harmonic::v2]=0.0500;
663}
664
665
666// Old parameterization for Pb+Pb v2
667void AddFlowByShifting::jjia_minbias_old(double b, double eta, double pt)
668{
669 m_v_n[Harmonic::v1] = 0;
670 m_v_n[Harmonic::v2] = 0.03968 * b
671 * (1 - 2.1/(1 + std::exp(1.357*(pt/1000))))
672 * std::exp(-(eta*eta)/(2*6.37*6.37));
673 m_v_n[Harmonic::v3]=0.0000;
674 m_v_n[Harmonic::v4]=0.0000;
675 m_v_n[Harmonic::v5]=0.0000;
676 m_v_n[Harmonic::v6]=0.0000;
677}
678
679
680void AddFlowByShifting::ao_test (double b, double /*eta*/, double pt)
681{
682 for(int ihar=0;ihar<Harmonic::NumHar;ihar++){
683 m_v_n[ihar]=0.0;
684 }
685
686 pt/=1000;
687 if(pt>2) pt = 2; // flat max at pt > 2
688
689 m_v_n[Harmonic::v2] = 0.02 * b * pt;
690}
691
692
702
703// p_Pb vn
704void AddFlowByShifting::p_Pb_cent_eta_indep(double /*b*/, double /*eta*/, double pt)
705{
706 pt=pt/1000.0; //convert to GeV
707
708 float an_val[4][3];
709
710 an_val[0][0] = 0.1149;
711 an_val[0][1] = 1.181;
712 an_val[0][2] = 0.3767;
713
714 an_val[1][0] = 0.0498;
715 an_val[1][1] = 1.688;
716 an_val[1][2] = 0.5046;
717
718 an_val[2][0] = 0.02095;
719 an_val[2][1] = 2.196;
720 an_val[2][2] = 0.6259;
721
722 an_val[3][0] = 0.00682*0.5;//added in 0.5 factor by hand
723 an_val[3][1] = 4.938;
724 an_val[3][2] = 1.237;
725
727 m_v_n[Harmonic::v2]=an_val[0][0]*std::pow(pt,an_val[0][1])*std::exp(-an_val[0][2]*pt);
728 m_v_n[Harmonic::v3]=an_val[1][0]*std::pow(pt,an_val[1][1])*std::exp(-an_val[1][2]*pt);
729 m_v_n[Harmonic::v4]=an_val[2][0]*std::pow(pt,an_val[2][1])*std::exp(-an_val[2][2]*pt);
730 m_v_n[Harmonic::v5]=an_val[3][0]*std::pow(pt,an_val[3][1])*std::exp(-an_val[3][2]*pt);
732}
733
734//OO
735void AddFlowByShifting::OO_eta_indep(double b, double /*eta*/, double pt){
736 pt=pt/1000.0; //convert to GeV
737
738
739 //For Testing
740 /*
741 m_v_n[Harmonic::v1]=0;
742 m_v_n[Harmonic::v2]=0.1;
743 m_v_n[Harmonic::v3]=0.05;
744 m_v_n[Harmonic::v4]=0.03;
745 m_v_n[Harmonic::v5]=0;
746 m_v_n[Harmonic::v6]=0;
747 return;
748 */
749
750
751 //pT differential vn for 0-5% centrality
752 static TGraph gr_v2pt;
753 static TGraph gr_v3pt;
754 static TGraph gr_v4pt;
755 //centrality dependent scale-factors for other centralities
756 static TGraph gr_v2_cent_scale;
757 static TGraph gr_v3_cent_scale;
758 static TGraph gr_v4_cent_scale;
759
760 static bool is_initialized=false;
761 if(is_initialized==false){
762 //----------------------------------------------------------------------------------
763 //The pt Dependent v2,v3,v4 for the 0-5% centrality interval from template-fit method
764 //https://atlas.web.cern.ch/Atlas/GROUPS/PHYSICS/PAPERS/HION-2025-02/fig_05.png
765 const int NumPtBins=23;
766 float v2_pt[NumPtBins]={
767 0.0 ,//extrapolation
768 0.049533 ,0.0622719,0.0776591,0.0906141,0.101341 ,0.110451 ,0.117545,
769 0.123217 ,0.126643 ,0.129142 ,0.129176 ,0.128795 ,0.126009 ,0.120966,
770 0.109416 ,0.0966881,0.0825195,0.0708585,0.0615164,0.0508748,
771 0.015 ,0.015 //extrapolation to 1.5% v2 at high-pT
772 };
773 float v3_pt[NumPtBins]={
774 0.0 ,//extrapolation
775 0.0186328,0.0262968,0.0366394,0.0467804,0.0562739,0.0639566,0.0714195,
776 0.0783429,0.0838629,0.0886202,0.0907969,0.0922756,0.0948961,0.0947266,
777 0.0898434,0.0839913,0.0801961,0.0685197,0.0648406,0.0600871,
778 0.00 ,0.00//extrapolation
779 };
780 //----------------------------------------------------
781 //For v3, we use the average of the template and 2PC values
782 float v3_pt_2PC[NumPtBins]={
783 0.0 ,//extrapolation
784 0.0182106,0.0255873,0.0355349,0.0451583,0.0537545,0.0611133,0.0675791,
785 0.0732434,0.0778371,0.0812549,0.0823093,0.0826907,0.082954 ,0.0800712,
786 0.0719686,0.062255 ,0.0498296,0.0370541,0.027638 ,0.0139785,
787 0.00 ,0.00//extrapolation
788 };
789 for(int i=0;i<NumPtBins;i++) v3_pt[i]=(v3_pt[i]+v3_pt_2PC[i])/2.0;
790 //----------------------------------------------------
791
792 float v4_pt[NumPtBins]={
793 0.0 ,//extrapolation
794 0.00446155,0.00710366,0.0117637,0.0158203,0.01931 ,0.0234234,0.0268995,
795 0.0299693 ,0.0321662 ,0.0335182,0.0358789,0.0374195,0.0359359,0.0327255,
796 0.0254762 ,0.0273239 ,0.0212901,0.0152591, -0 ,-0 ,//-ve values replaced by -0
797 0.0 , 0.00//extrapolation
798 };
799 float pt_bins[NumPtBins]={
800 0.0 ,//extrapolation
801 0.55 ,0.7 ,0.9 ,1.1 , 1.3, 1.5, 1.7,
802 1.9 ,2.1 ,2.3 ,2.5 , 2.7, 2.9, 3.25,
803 3.75 ,4.25 ,4.75 ,5.25 , 5.75, 6.5,
804 10.0 ,10000 //extrapolation
805 };
806 gr_v2pt=TGraph(NumPtBins,pt_bins,v2_pt);
807 gr_v3pt=TGraph(NumPtBins,pt_bins,v3_pt);
808 gr_v4pt=TGraph(NumPtBins,pt_bins,v4_pt);
809 gr_v2pt.SetBit(TGraph::kIsSortedX);//For faster return From Eval()
810 gr_v3pt.SetBit(TGraph::kIsSortedX);//For faster return From Eval()
811 gr_v4pt.SetBit(TGraph::kIsSortedX);//For faster return From Eval()
812 //----------------------------------------------------------------------------------
813
814
815 //----------------------------------------------------------------------------------
816 //centrality dependent v2, v3, v4 (template-fit method)
817 //https://atlas.web.cern.ch/Atlas/GROUPS/PHYSICS/PAPERS/HION-2025-02/figaux_03.png
818 const int NumCentBins=23;
819 float v2_cent[NumCentBins]={
820 0.0749381,//underflow
821 0.0749381,0.0782992,0.0801742,0.0814646,0.0826611,0.0853616,0.0889407,
822 0.0913229,0.0928072,0.0933774,0.0933299,0.0926254,0.0910148,0.0889322,
823 0.086161 ,0.0828212,0.0793132,0.0755036,0.0714726,0.0668264,
824 0.055 , 0.05 //80-100 and overflow, put by hand ; using 5% v2 asymptotically
825 };
826 float v3_cent[NumCentBins]={
827 0.0409694,//underflow
828 0.0409694,0.0399241,0.0394262,0.0388545,0.0385726,0.0375281,0.0360179,
829 0.0345174,0.0330085,0.0314149,0.0298081,0.0282141,0.02664 ,0.0253094,
830 0.0239221,0.0220779,0.0213821,0.0203176,0.0175276,0.0151146,
831 0.010 , 0.0 //80-100 and overflow, put by hand; using 0% v3 asymptotically
832 };
833 float v4_cent[NumCentBins]={
834 0.0131927 ,//underflow
835 0.0131927 ,0.0129838,0.0135232 ,0.0132689 ,0.0130435 ,0.0134254 ,0.013706 ,
836 0.0136456 ,0.0136656,0.013245 ,0.0130861 ,0.0125356 ,0.0118006 ,0.0110316,
837 0.00987005,0.0106963,0.00933145,0.00784534,0.00393584,0.00308131,
838 0.003 , 0.0 //80-100 and overflow, put by hand; using 0% v4 asymptotically
839 };
840 //b_imp values for differen centralities
841 float b_imp[NumCentBins]={
842 -1 , //underflow
843 0.481843 ,0.886609 , 1.13462 , 1.33981 , 1.52064 , 1.95342 , 2.51881 ,
844 2.97665 ,3.37416 , 3.72876 , 4.05377 , 4.35564 , 4.63868 , 4.91057 ,
845 5.17773 ,5.43665 , 5.68739 , 5.94258 , 6.20668 , 6.49519 ,
846 7.6415 , 15 , //80-100 and overflow
847 };
848
849 //Integrated v2, v3, v4, for 0-5% centrality bin
850 float vn_0_5[3]={0.078963056, 0.039746672, 0.013202649};
851 //divide by integrated vn for 0-5% centrality
852 for(int i=0;i<NumCentBins;i++){
853 v2_cent[i]/=vn_0_5[0];
854 v3_cent[i]/=vn_0_5[1];
855 v4_cent[i]/=vn_0_5[2];
856 }
857 gr_v2_cent_scale=TGraph(NumCentBins, b_imp, v2_cent);
858 gr_v3_cent_scale=TGraph(NumCentBins, b_imp, v3_cent);
859 gr_v4_cent_scale=TGraph(NumCentBins, b_imp, v4_cent);
860 gr_v2_cent_scale.SetBit(TGraph::kIsSortedX);//For faster return From Eval()
861 gr_v3_cent_scale.SetBit(TGraph::kIsSortedX);//For faster return From Eval()
862 gr_v4_cent_scale.SetBit(TGraph::kIsSortedX);//For faster return From Eval()
863 //----------------------------------------------------------------------------------
864 is_initialized=true;
865 }
866
867
869 m_v_n[Harmonic::v2]=gr_v2pt.Eval(pt) * gr_v2_cent_scale.Eval(b);
870 m_v_n[Harmonic::v3]=gr_v3pt.Eval(pt) * gr_v3_cent_scale.Eval(b);
871 m_v_n[Harmonic::v4]=gr_v4pt.Eval(pt) * gr_v4_cent_scale.Eval(b);
874}
875
876void AddFlowByShifting::Set_EbE_Fluctuation_Multipliers(HepMC::GenVertexPtr /*mainvtx*/,float b, CLHEP::HepRandomEngine *rndmEngine){
877 for(int ihar=0;ihar<Harmonic::NumHar;ihar++){
878 m_EbE_Multiplier_vn[ihar]=1.0;
879 }
880
881
882 for(int ihar=0;ihar<Harmonic::NumHar;ihar++){
883 float vn_rp=0,delta=0;//BG parameterizations
884
885 //in the following we assume that the vn in the event is sqrt(<vn^2>)
886 //This is because the vn(pT) were tuned to 2PC/EP measurements
887 //then : vn_evt=vn_rp^2 + 2*(delta^2)
888 //which is used together with the "alpha" to get the "vn_rp" and "delta"
889
890 //No EbE fluctuation for v1
891 if (ihar==Harmonic::v1) continue;
892 //v2
893 else if(ihar==Harmonic::v2){
894 //alpha stores ratio of V2_RP over delta
895 float alpha=m_graph_fluc->Eval(b);
896 delta=1.0f/sqrt(2.0f+alpha*alpha); //stores delta /v2{2}
897 vn_rp=alpha*delta ; //stores v2^{RP}/v2{2}
898 }
899 //v3-v6
900 else{
901 vn_rp =0;
902 delta=1.0f/sqrt(2.0f);
903 }
904 float X=CLHEP::RandGaussQ::shoot(rndmEngine,vn_rp,delta);
905 float Y=CLHEP::RandGaussQ::shoot(rndmEngine,0.0 ,delta);
906 m_EbE_Multiplier_vn[ihar]=sqrt(X*X+ Y*Y);
907 ATH_MSG_INFO("EbE_Multiplier_v"<<ihar+1<<"="<<m_EbE_Multiplier_vn[ihar]);
908 }
909}
910
#define M_PI
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
#define F(x, y, z)
Definition MD5.cxx:112
#define x
constexpr int pow(int base, int exp) noexcept
Define macros for attributes used to control the static checker.
#define ATLAS_THREAD_SAFE
A wrapper class for event-slot-local random engines.
Definition RNGWrapper.h:56
void setSeed(const std::string &algName, const EventContext &ctx)
Set the random seed using a string (e.g.
Definition RNGWrapper.h:169
CLHEP::HepRandomEngine * getEngine(const EventContext &ctx) const
Retrieve the random engine corresponding to the provided EventContext.
Definition RNGWrapper.h:134
StringProperty m_flow_function_name
StringProperty m_outkey
IntegerProperty m_flowpt_sw
AddFlowByShifting(const std::string &name, ISvcLocator *pSvcLocator)
FloatProperty m_flow_mineta
void Set_EbE_Fluctuation_Multipliers(HepMC::GenVertexPtr mainvtx, float b, CLHEP::HepRandomEngine *rndmEngine)
static double vn_func(double x, void *params)
double AddFlowToParent(HepMC::GenParticlePtr parent, const HijingEventParams *hijing_pars)
FloatProperty m_custom_v3
void jjia_minbias_new(double b, double eta, double pt)
void ao_test(double b, double eta, double pt)
double SetParentToRanPhi(HepMC::GenParticlePtr parent, CLHEP::HepRandomEngine *rndmEngine)
ServiceHandle< IAthRNGSvc > m_rndmSvc
FloatProperty m_custom_v6
StringProperty m_flow_implementation
FloatProperty m_custom_v1
FloatProperty m_custom_v2
IntegerProperty m_floweta_sw
void p_Pb_cent_eta_indep(double b, double eta, double pt)
FloatProperty m_flow_minpt
FloatProperty m_flow_maxeta
IntegerProperty m_flowb_sw
void jjia_minbias_new_v2only(double b, double eta, double pt)
void MoveDescendantsToParent(HepMC::GenParticlePtr parent, double phishift)
CLHEP::HepRandomEngine * getRandomEngine(const std::string &streamName, const EventContext &ctx) const
void jjia_minbias_old(double b, double eta, double pt)
void fixed_v2(double b, double eta, double pt)
StringProperty m_inkey
IntegerProperty m_ranphi_sw
FloatProperty m_flow_maxpt
BooleanProperty m_flow_fluctuations
void OO_eta_indep(double b, double eta, double pt)
void custom_vn(double b, double eta, double pt)
float m_psi_n[Harmonic::NumHar]
void fixed_vn(double b, double eta, double pt)
void(AddFlowByShifting::* m_flow_function)(double b, double eta, double pt)
float m_EbE_Multiplier_vn[Harmonic::NumHar]
FloatProperty m_custom_v4
FloatProperty m_custom_v5
float m_v_n[Harmonic::NumHar]
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
value_type push_back(value_type pElem)
Add an element to the end of the collection.
DataModel_detail::iterator< DataVector > iterator
Definition DataVector.h:842
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
void set_psi(int ihar, float psi)
float get_bphi() const
This defines the McEventCollection, which is really just an ObjectVector of McEvent objectsFile: Gene...
HepMC::GenVertex * GenVertexPtr
Definition GenVertex.h:59
GenParticle * GenParticlePtr
Definition GenParticle.h:37