ATLAS Offline Software
Loading...
Searching...
No Matches
Hijing.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// -------------------------------------------------------------
6// Generators/Hijing.cxx Description: Allows the user
7// to generate hijing events and store the result in the
8// Transient Store.
9//
10// AuthorList:
11// Georgios Stavropoulos: Initial Code October 2002
12// Brian Cole, Mikhail Leltchouk, Andrzej Olszewski: 2006, 2007
13// Modified:
14// 2007-Feb Alden Stradling: Added vertex shifting and made options settable in jO.
15// 2007-Sep Aaron Angerami: keepSpectators option.
16// 2007-Nov Brian Cole, Mikhail Leltchouk: each vertex is added to the event before particles are added to the vertex
17// - this fixed bug #30991 for release 13.1.0 and for HepMC 2.3.0 where the 'set's comparison operates
18// on the bcode rather than on the pointer.
19// 2008-Jul Borut Kersevan: randomizing the left<->right direction by mirroring momenta settable in jobOpts for beamgas
20// 2023-Aug Aaron Angerami: adding keepAllDecayVertices option to keep decay vertices for strong decays (default=true)
21
22#include "Hijing_i/Hijing.h"
24
25#include "GaudiKernel/MsgStream.h"
26
28
29#include "AtlasHepMC/GenEvent.h"
32#include "AtlasHepMC/HeavyIon.h"
33
34#include <stdlib.h>
35
36#include "CLHEP/Random/RandFlat.h"
37#include "CLHEP/Geometry/Point3D.h"
38#include <cstdint>
39
41
42namespace {
43 static CLHEP::HepRandomEngine *p_Engine;
44 static std::string hijing_stream = "HIJING_INIT";
45}
46
47
48extern "C" {
49
50 void* getaddr_(void* arg);
51 void* getaddri_(int* arg);
52
53}
54
55void* getaddr_(void* arg) {
56
57 return(arg);
58
59}
60
61// Version to be used with integer arguments, to prevent LTO warnings
62// about inconsistent parameter types.
63void* getaddri_(int* arg) {
64
65 return(arg);
66
67}
68
69// calls to fortran routines and common-block address accessors
70extern "C"
71{
72 float atl_ran_( int* )
73 {
74 return (float) CLHEP::RandFlat::shoot(p_Engine);
75 }
76
77 float ran_(int* idummy)
78 {
79 return atl_ran_(idummy);
80 }
81
82 extern char himain1_[];
83 extern char himain2_[];
84 extern char hijjet1_[];
85 extern char hijjet2_[];
86 extern char hijjet4_[];
87 extern char hiparnt_[];
88 extern char histrng_[];
89 extern char hijcrdn_[];
90 extern char ranseed_[];
91
92 uintptr_t himain1_address_() { return reinterpret_cast<uintptr_t>(himain1_); }
93 uintptr_t himain2_address_() { return reinterpret_cast<uintptr_t>(himain2_); }
94 uintptr_t hijjet1_address_() { return reinterpret_cast<uintptr_t>(hijjet1_); }
95 uintptr_t hijjet2_address_() { return reinterpret_cast<uintptr_t>(hijjet2_); }
96 uintptr_t hijjet4_address_() { return reinterpret_cast<uintptr_t>(hijjet4_); }
97 uintptr_t hiparnt_address_() { return reinterpret_cast<uintptr_t>(hiparnt_); }
98 uintptr_t histrng_address_() { return reinterpret_cast<uintptr_t>(histrng_); }
99 uintptr_t hijcrdn_address_() { return reinterpret_cast<uintptr_t>(hijcrdn_); }
100 uintptr_t ranseed_address_() { return reinterpret_cast<uintptr_t>(ranseed_); }
101
102 void hijset_(float*,
103 const char*,
104 const char*,
105 const char*,
106 int*,
107 int*,
108 int*,
109 int*,
110 long int,
111 long int,
112 long int);
113 void hijing_(const char*, float*, float*, long int);
114}
115
116Hijing::Hijing(const std::string& name,
117 ISvcLocator* pSvcLocator): GenModule(name,pSvcLocator)
118{
119 declareProperty("Initialize", m_InitializeVector);
120 declareProperty("partonStoreMinPt", m_partonStoreMinPt);
121 declareProperty("vertexOffsetCut", m_vertexOffsetCut);
122 declareProperty("randomizeVertices", m_rand); // Randomize for beam gas
123 declareProperty("selectVertex", m_sel); // Select vertex location (off for random)
124 declareProperty("wide", m_wide); // Allow randoms off the beamline (out to the pipe)
125 declareProperty("x", m_x);
126 declareProperty("y", m_y);
127 declareProperty("z", m_z);
128 declareProperty("keepSpectators", m_spec);
129 declareProperty("randomizeP", m_prand); //BPK randomizes the left<->right direction by mirroring momenta for beam gas
130 declareProperty("keepAllDecayVertices", m_keepAllDecayVertices);
131}
132
134{
135 ATH_CHECK(m_event_paramsKey.initialize());
136
137 // Initialisation of input parameters
138 std::cout << "MetaData: generator = Hijing "
139 << HIJINGVERSION << std::endl;
140 ATH_MSG_INFO( "===> Hijing initialising \n" );
141 if( m_rand ){
142 ATH_MSG_INFO( "===> Vertex randomization ON." );
143 }
144 if( m_wide ){
145 ATH_MSG_INFO( "===> Vertex rand covers whole beampipe." );
146 }
147 //BPK
148 if( m_prand ) ATH_MSG_INFO( "===> Random Momentum Mirroring enabled" );
149 if( m_keepAllDecayVertices ) ATH_MSG_INFO( "===> Keeping all decay vertices" );
150 else ATH_MSG_INFO( "===> NOT keeping all decay vertices" );
151
152 //CLHEP::HepRandomEngine* engine
153 p_Engine = getRandomEngineDuringInitialize(hijing_stream, m_randomSeed, m_dsid); // NOT THREAD-SAFE
154 hijing_stream = "HIJING";
155
156 // Set the users' initialisation parameters choices
158
159 const char* frame = m_frame.c_str();
160 const char* proj = m_proj.c_str();
161 const char* targ = m_targ.c_str();
162
163 hijset_( &m_efrm, frame, proj, targ, &m_iap, &m_izp, &m_iat, &m_izt,
164 strlen(frame), strlen(proj), strlen(targ) );
165
166 ATH_MSG_INFO( "\n=================================================\n"
167 << " HIJING initialization results: \n"
168 << " Total sigma = " << m_hiparnt.hint1(13) << " mb\n"
169 << " Inelastic sigma = " << m_hiparnt.hint1(12) << " mb\n"
170 << " Jet sigma = " << m_hiparnt.hint1(11) << " mb\n"
171 << "=================================================\n" );
172
173
174 return StatusCode::SUCCESS;
175}
176
178{
179 ATH_MSG_INFO( " HIJING generating. \n" );
180
181 // Save the random number seeds in the event
182 //Re-seed the random number stream
183 long seeds[7];
184 const EventContext& ctx = Gaudi::Hive::currentContext();
185 ATHRNG::calculateSeedsMC21(seeds, hijing_stream, ctx.eventID().event_number(), m_dsid, m_randomSeed);
186 p_Engine->setSeeds(seeds, 0); // NOT THREAD-SAFE
187 m_seeds.clear();
188 m_seeds.push_back(seeds[0]);
189 m_seeds.push_back(seeds[1]);
190
191 // Generate event
192 const char* frame = m_frame.c_str();
193 hijing_(frame, &m_bmin, &m_bmax, strlen(frame));
194
195 // Check for error using the new (custom) error return
196 //
197 int errorStatus = m_himain1.ierrstat();
198 if (errorStatus != 0) {
199 ATH_MSG_ERROR( "Error returned from HIJING, value = " << errorStatus );
200 return StatusCode::FAILURE;
201 }
202
203 // update event counter
204 ++m_events;
205
206 // store hijing event parameters
207 // -----------------------------
208 ATH_MSG_DEBUG( "New HijingEventParams" );
209 int np = m_himain1.np();
210 int nt = m_himain1.nt();
211 int n0 = m_himain1.n0();
212 int n01 = m_himain1.n01();
213 int n10 = m_himain1.n10();
214 int n11 = m_himain1.n11();
215 int natt = m_himain1.natt();
216 int jatt = m_himain1.jatt();
217 float b = m_hiparnt.hint1(19);
218 float bphi = m_hiparnt.hint1(20);
219
221 event_params = std::make_unique<HijingEventParams>(np, nt, n0, n01, n10, n11, natt, jatt, b, bphi);
222
223 ATH_MSG_INFO( "\n=================================================\n"
224 << " HIJING event description: \n"
225 << " b = " << b << " fm \n"
226 << " # proj participants = " << np << "\n"
227 << " # targ participants = " << nt << "\n"
228 << " # final particles = " << natt << "\n"
229 << "=================================================\n" );
230
231 ATH_MSG_DEBUG( " HIJING generating done. \n" );
232 return StatusCode::SUCCESS;
233}
234
235StatusCode
237{
238 ATH_MSG_INFO( " HIJING Ending. \n" );
239 return StatusCode::SUCCESS;
240}
241
242StatusCode
244{
245 // These two parameters need to be made user settable (done - AS)
246 //
247 MsgStream log(msgSvc(), name());
248 ATH_MSG_INFO( " HIJING Filing. \n" );
249
250 // Set the event number
251 evt->set_event_number( m_events );
252
253 // Set the random generator seeds
255
256 // Set the generator id
257 HepMC::set_signal_process_id(evt,50000000 + m_iap);
258
259 // Store collision parameters
260 int np = m_himain1.np();
261 int nt = m_himain1.nt();
262 int n0 = m_himain1.n0();
263 int n01 = m_himain1.n01();
264 int n10 = m_himain1.n10();
265 int n11 = m_himain1.n11();
266 //int natt = m_himain1.natt();
267 int jatt = m_himain1.jatt();
268 float b = m_hiparnt.hint1(19);
269 float bphi = m_hiparnt.hint1(20);
270
271 float sigmainel = m_hiparnt.hint1(12);
272
273 HepMC::GenHeavyIonPtr ion= std::make_shared<HepMC::GenHeavyIon>();
274 ion->Ncoll_hard=static_cast<int>(jatt);
275 ion->Npart_proj=static_cast<int>(np);
276 ion->Npart_targ=static_cast<int>(nt);
277 ion->Ncoll=static_cast<int>(n0+n10+n01+n11);
278 ion->N_Nwounded_collisions=static_cast<int>(n01);
279 ion->Nwounded_N_collisions=static_cast<int>(n10);
280 ion->Nwounded_Nwounded_collisions=static_cast<int>(n11);
281 ion->spectator_neutrons=-1;
282 ion->spectator_protons=-1;
283 ion->impact_parameter= b;
284 ion->event_plane_angle=bphi;
285 ion->event_plane_angle=-1;
286 ion->sigma_inel_NN=sigmainel;
287 evt->set_heavy_ion(std::move(ion));
288
289 // Did we keep decay history?
290 //
291 bool keptHistory = (m_hiparnt.ihpr2(21) == 1);
292
293 // The number of particles in the hijing output
294 //
295 int numHijingPart = m_himain1.natt();
296
297 // Vectors that will keep track of where particles originate from and die
298 //
299 std::vector<int> partOriginVertex_vec(numHijingPart, 0);
300 std::vector<int> partDecayVertex_vec(numHijingPart, -1);
301 std::vector<HepMC::GenParticlePtr> particleHepPartPtr_vec(numHijingPart, nullptr);
302
303 // Vector that will keep pointers to generated vertices
304 //
305 std::vector<HepMC::GenVertexPtr> vertexPtrVec;
306
307 // Create the event vertex
308 //
309 CLHEP::HepLorentzVector newVertex;
310 newVertex = CLHEP::HepLorentzVector(0.,0.,0.,0.);
311
312 if( m_rand )newVertex = randomizeVertex(p_Engine); // Create a random vertex along the pipe
313 else if(m_sel) newVertex = CLHEP::HepLorentzVector(m_x, m_y, m_z, 0.); // Create vertex at selected point - preempted by m_rand
314
315 HepMC::GenVertexPtr v1 = HepMC::newGenVertexPtr(HepMC::FourVector(newVertex.x(),newVertex.y(),newVertex.z(),newVertex.t()));
316
318 vertexPtrVec.push_back(v1);
319
320 double eproj = (double) m_efrm;
321 if ( m_frame == "CMS " ) eproj = eproj / 2.;
322
323 int proj_id = 2212;
324 if ( m_proj == "PBAR " ) {
325 proj_id = -2212;
326 } else if ( m_proj == "N " ) {
327 proj_id = 2112;
328 } else if ( m_proj == "NBAR " ) {
329 proj_id = -2112;
330 } else if ( m_proj == "PI+ " ) {
331 proj_id = 211;
332 } else if ( m_proj == "PI- " ) {
333 proj_id = -211;
334 } else if ( m_proj == "A " ) {
335 proj_id = 3000000 + m_iap;
336 }
337 HepMC::GenParticlePtr part_p = HepMC::newGenParticlePtr(HepMC::FourVector(0., 0., eproj, eproj), proj_id, 101 );
338 v1->add_particle_in( part_p );
339
340 double etarg = 0.;
341 if ( m_frame == "CMS " ) etarg = ( (double) m_efrm ) / 2.;
342
343 int targ_id = 2212;
344 if ( m_targ == "PBAR " ) {
345 targ_id = -2212;
346 } else if ( m_targ == "N " ) {
347 targ_id = 2112;
348 } else if ( m_targ == "NBAR " ) {
349 targ_id = -2112;
350 } else if ( m_targ == "PI+ " ) {
351 targ_id = 211;
352 } else if ( m_targ == "PI- " ) {
353 targ_id = -211;
354 } else if ( m_targ == "A " ) {
355 targ_id = 3000000 + m_iat;
356 }
357 HepMC::GenParticlePtr part_t = HepMC::newGenParticlePtr(HepMC::FourVector(0., 0., -etarg, etarg), targ_id, 102 );
358 v1->add_particle_in( part_t );
359
360 evt->set_beam_particles(std::move(part_p),std::move(part_t));
361
362 ATH_MSG_DEBUG( "Hijing particles for event # " << m_events << ":\n"
363 << " px, "
364 << " py, "
365 << " pz, "
366 << " Id, "
367 << " Source, "
368 << " Parent, "
369 << " Status, " );
370
371 bool inconsistency = false;
372
373 // Loop on all Hijing particles and put them all as outgoing from the event vertex
374 //
375 for (int i = 1; i <= m_himain1.natt(); ++i)
376 {
377 // Skip non-interacting projectile and target nucleons
378 //
379 if (!m_spec && ((m_himain2.katt(i, 2) == 0) || (m_himain2.katt(i, 2)) == 10)) continue;
380
381 // Find the vertex of the parent particle
382 //
383 int parentIndex = m_himain2.katt(i, 3) - 1;
384 int parentOriginIndex = 0;
385 int parentDecayIndex = -1;
386
387 // If the particle has a true parent, record its vertex info
388 //
389 if (parentIndex >= 0)
390 {
391 parentOriginIndex = partOriginVertex_vec[parentIndex];
392 parentDecayIndex = partDecayVertex_vec[parentIndex];
393 }
394
395 // A CLHEP vector containing the particle start point
396 //
397 // If the particle has been shifted, offset the particleStart accordingly
398 //
399 if( m_rand || m_sel ){ // Either way, we need to shift the particle vertex
400 m_himain2.vatt(i,1) += newVertex(0);
401 m_himain2.vatt(i,2) += newVertex(1);
402 m_himain2.vatt(i,3) += newVertex(2);
403 m_himain2.vatt(i,4) += newVertex(3);
404 }
405
406 ATH_MSG_DEBUG( std::fixed << std::setprecision(2)
407 << std::setw(5) << i << ","
408 << std::setw(7) << m_himain2.patt(i, 1) << ", "
409 << std::setw(7) << m_himain2.patt(i, 2) << ", "
410 << std::setw(7) << m_himain2.patt(i, 3) << ", "
411 << std::setw(7) << m_himain2.katt(i, 1) << ", "
412 << std::setw(7) << m_himain2.katt(i, 2) << ", "
413 << std::setw(7) << m_himain2.katt(i, 3) << ", "
414 << std::setw(7) << m_himain2.katt(i, 4) << ", "
415 << std::setw(7) << m_himain2.vatt(i, 1) << ", "
416 << std::setw(7) << m_himain2.vatt(i, 2) << ", "
417 << std::setw(7) << m_himain2.vatt(i, 3) );
418
419 CLHEP::HepLorentzVector particleStart(m_himain2.vatt(i, 1), m_himain2.vatt(i, 2),
420 m_himain2.vatt(i, 3), m_himain2.vatt(i, 4));
421
422 // By default, the particle originates from the primary vertex
423 //
424 int particleVertexIndex = 0;
425
426 // Have we kept the history?
427 //
428 if (keptHistory)
429 {
430 // Check to see if we've already generated a decay vertex for this parent
431 //
432 // std::cout << "ML-> keptHistory == True" << std::endl;
433 if (parentDecayIndex != -1)
434 {
435 // Make sure it is consistent with this track origin
436 //
437 HepGeom::Point3D<double> vertex_pos(vertexPtrVec[parentDecayIndex]->position().x(),
438 vertexPtrVec[parentDecayIndex]->position().y(),
439 vertexPtrVec[parentDecayIndex]->position().z());
440 double distance = vertex_pos.distance(particleStart.vect());
441
442 //std::cout << "ML-> distance = " << distance <<" parentDecayIndex = "<<parentDecayIndex<< std::endl;
443 if (distance > m_vertexOffsetCut)
444 {
445 // We have an inconsistency, print a message
446 //
447 ATH_MSG_WARNING( " Inconsistency in Hijing particle vertexing, particle # " << i
448 << " starting point (x,y,z) = ("
449 << particleStart.x() << ", "
450 << particleStart.y() << ", "
451 << particleStart.z() << ") "
452 << " a distance " << distance << " away from parent decay point " );
453
454
455 // Dump the parent decay vertex
456 //
457 log << MSG::WARNING << " Parent decay vertex: (x,y,z) = " << vertexPtrVec[parentDecayIndex]->position().x()
458 << ", " << vertexPtrVec[parentDecayIndex]->position().y()
459 << ", " << vertexPtrVec[parentDecayIndex]->position().z()
460 << ", associated daughter IDs = ";
461
462 auto vertexPtrVec_particles_out_const_begin=vertexPtrVec[parentDecayIndex]->particles_out().begin();
463 auto vertexPtrVec_particles_out_const_end=vertexPtrVec[parentDecayIndex]->particles_out().end();
464 for (auto iter = vertexPtrVec_particles_out_const_begin;
465 iter != vertexPtrVec_particles_out_const_end;
466 iter++)
467 {
468 log << (*iter) << ", ";
469 }
470
471 log << endmsg;
472 inconsistency = true;
473 }
474
475 // Nonetheless set the parent decay vertex to be this particle's vertex
476 //
477 particleVertexIndex = parentDecayIndex;
478 }
479 else
480 {
481 // Now compare the distance between the vertex FROM which the parent originates and the
482 // start of this particle
483 //
484 HepGeom::Point3D<double> vertex_pos(vertexPtrVec[parentOriginIndex]->position().x(),
485 vertexPtrVec[parentOriginIndex]->position().y(),
486 vertexPtrVec[parentOriginIndex]->position().z());
487 double distance = vertex_pos.distance(particleStart.vect());
488
489 if (distance > m_vertexOffsetCut && parentIndex == -1)
490 {
491 // *** Explicitly handle Hijing bug which generates particle with displaced vertex
492 // *** but no parent ????
493 //
494
495 ATH_MSG_WARNING( "HIJING BUG:: Particle found with displaced vertex but no parent " );
496 ATH_MSG_WARNING( " Particle parameters: " << std::fixed << std::setprecision(2)
497 << std::setw(5) << i << ","
498 << std::setw(7) << m_himain2.patt(i, 1) << ", "
499 << std::setw(7) << m_himain2.patt(i, 2) << ", "
500 << std::setw(7) << m_himain2.patt(i, 3) << ", "
501 << std::setw(7) << m_himain2.katt(i, 1) << ", "
502 << std::setw(7) << m_himain2.katt(i, 2) << ", "
503 << std::setw(7) << m_himain2.katt(i, 3) << ", "
504 << std::setw(7) << m_himain2.katt(i, 4) << ", "
505 << std::setw(7) << m_himain2.vatt(i, 1) << ", "
506 << std::setw(7) << m_himain2.vatt(i, 2) << ", "
507 << std::setw(7) << m_himain2.vatt(i, 3) );
508
509 // Assign the particle to its parent's vertex
510 //
511 particleVertexIndex = parentOriginIndex;
512 //std::cout << "ML-> case 2 distane = " << distance <<" particleVertexIndex = "<<particleVertexIndex<< std::endl;
513 }
514 if( parentIndex!=-1 && ((distance > m_vertexOffsetCut || parentOriginIndex !=0) || m_keepAllDecayVertices ) )
515 {
516 // We need to create a new vertex
517 //
518 HepMC::GenVertexPtr newVertex_p = HepMC::newGenVertexPtr(HepMC::FourVector(particleStart.x(),particleStart.y(),particleStart.z(),particleStart.t()));
519 evt->add_vertex(newVertex_p);
520 vertexPtrVec.push_back(newVertex_p);
521 particleVertexIndex = vertexPtrVec.size() - 1;
522
523 // Now we indicate that the parent has a decay vertex
524 //
525 partDecayVertex_vec[parentIndex] = particleVertexIndex;
526
527 // Now tell the vertex about the particle that created it
528 //
529
530 newVertex_p->add_particle_in(particleHepPartPtr_vec[parentIndex]);
531 }
532 else {
533 // Assign the particle to its parent's vertex
534 //
535 particleVertexIndex = parentOriginIndex;
536 }
537 }
538 }
539 else
540 {
541 // We have to brute-force search for a vertex that might match this particle
542 //
543 int foundVert = -1;
544 for (unsigned int ivert = 0; ivert < vertexPtrVec.size(); ivert++)
545 {
546
547 HepGeom::Point3D<double> vertex_pos(vertexPtrVec[ivert]->position().x(),
548 vertexPtrVec[ivert]->position().y(),
549 vertexPtrVec[ivert]->position().z());
550 double distance = vertex_pos.distance(particleStart.vect());
551 if (distance < m_vertexOffsetCut)
552 {
553 foundVert = ivert;
554 break;
555 }
556 }
557
558 if (foundVert == -1)
559 {
560 // We need to create a new vertex
561 //
562 HepMC::GenVertexPtr newVertex_p = HepMC::newGenVertexPtr(HepMC::FourVector(particleStart.x(),particleStart.y(),particleStart.z(),particleStart.t()));
563
564 evt->add_vertex(newVertex_p);
565 vertexPtrVec.push_back(std::move(newVertex_p));
566 particleVertexIndex = vertexPtrVec.size() - 1;
567 }
568 else
569 {
570 particleVertexIndex = foundVert;
571 }
572 //std::cout << "ML-> case 3 particleVertexIndex = "<<particleVertexIndex<< std::endl;
573 }
574
575 // If the Hijing particle has decayed, set the status appropriately
576 //
577 int particleId = m_himain2.katt(i, 1);
578 int particleStatus = 1;
579 if (m_himain2.katt(i, 4) == 11) particleStatus = 2;
580
581 // Create the new particle
582 //
583 HepMC::FourVector particleP4(m_himain2.patt(i, 1),
584 m_himain2.patt(i, 2),
585 m_himain2.patt(i, 3),
586 m_himain2.patt(i, 4));
587
588 HepMC::GenParticlePtr newParticle_p = HepMC::newGenParticlePtr(particleP4, particleId,
589 particleStatus);
590
591 // Record the particle in the vector of pointers
592 // (ostensibly we only need this when we have the
593 // history but for simplicity always do it)
594 //
595 particleHepPartPtr_vec[i-1] = newParticle_p;
596
597 // Now add the particle to its vertex
598 //
599 vertexPtrVec[particleVertexIndex]->add_particle_out(std::move(newParticle_p));
600 partOriginVertex_vec[i-1] = particleVertexIndex;
601
602 }
603
604 if (inconsistency)
605 {
606 for (int i = 1; i <= m_himain1.natt(); ++i)
607 {
608 // Skip non-interacting projectile and target nucleons
609 //
610 if (!m_spec && ((m_himain2.katt(i, 2) == 0) || (m_himain2.katt(i, 2)) == 10)) continue;
611
612 ATH_MSG_WARNING( " Hijing.cxx inconsistency: " << std::fixed << std::setprecision(2)
613 // std::cout << std::fixed << std::setprecision(2)
614 << std::setw(5) << i << ","
615 << std::setw(7) << m_himain2.patt(i, 1) << ", "
616 << std::setw(7) << m_himain2.patt(i, 2) << ", "
617 << std::setw(7) << m_himain2.patt(i, 3) << ", "
618 << std::setw(7) << m_himain2.katt(i, 1) << ", "
619 << std::setw(7) << m_himain2.katt(i, 2) << ", "
620 << std::setw(7) << m_himain2.katt(i, 3) << ", "
621 << std::setw(7) << m_himain2.katt(i, 4) << ", "
622 << std::setw(7) << m_himain2.vatt(i, 1) << ", "
623 << std::setw(7) << m_himain2.vatt(i, 2) << ", "
624 << std::setw(7) << m_himain2.vatt(i, 3) );
625 }
626 }
627
628 // Generate documentation lines for high-pt partons
629 //
630 for (int isg = 1; isg <= m_hijjet2.nsg(); isg++)
631 {
632 for (int jparton = 1; jparton <= m_hijjet2.njsg(isg); jparton++)
633 {
634 double px = m_hijjet2.pxsg(isg, jparton);
635 double py = m_hijjet2.pysg(isg, jparton);
636 double pz = m_hijjet2.pzsg(isg, jparton);
637 double mass = m_hijjet2.pmsg(isg, jparton);
638
639 double ptsq = px*px + py*py;
640 double e = std::sqrt(ptsq + pz*pz + mass*mass);
641 double mt = std::sqrt(ptsq + mass*mass);
642 double pt = std::sqrt(ptsq);
643
644 double pseud = 0.5*std::log((e + pz)/(e - pz));
645
646 int partonId = m_hijjet2.k2sg(isg, jparton);
647
648 if (mt > m_partonStoreMinPt)
649 {
650 ATH_MSG_DEBUG( "hijjet2 entry: isg = " << isg
651 << ", pt = " << pt
652 << ", mt = " << mt
653 << ", eta = " << pseud );
654
655 // Add aaa non-tracked entry in the hepmc event with status code 103 (temporary)
656 //
657 v1->add_particle_out( HepMC::newGenParticlePtr( HepMC::FourVector(px, py, pz, e), partonId, 103 ) );
658 }
659 }
660 }
661
662 // Generate documentation lines for high-pt partons
663 //
664 int iap = m_hiparnt.ihnt2(1); // # of projectile nucleons
665 int iat = m_hiparnt.ihnt2(3); // # of target nucleons
666
667 for (int iproj = 1; iproj <= iap; iproj++)
668 {
669 for (int jparton = 1; jparton <= m_hijjet1.npj(iproj); jparton++)
670 {
671 double px = m_hijjet1.pjpx(iproj, jparton);
672 double py = m_hijjet1.pjpy(iproj, jparton);
673 double pz = m_hijjet1.pjpz(iproj, jparton);
674 double mass = m_hijjet1.pjpm(iproj, jparton);
675
676 double ptsq = px*px + py*py;
677 double e = std::sqrt(ptsq + pz*pz + mass*mass);
678 double mt = std::sqrt(ptsq + mass*mass);
679 double pt = std::sqrt(ptsq);
680
681 double pseud = 0.5*std::log((e + pz)/(e - pz));
682
683 int partonId = m_hijjet1.kfpj(iproj, jparton);
684
685 if (mt > m_partonStoreMinPt)
686 {
687 ATH_MSG_DEBUG( "hijjet1 entry: iproj = " << iproj
688 << ", pt = " << pt
689 << ", mt = " << mt
690 << ", eta = " << pseud );
691
692 // Add aaa non-tracked entry in the hepmc event with status code 103 (temporary)
693 //
694 v1->add_particle_out( HepMC::newGenParticlePtr( HepMC::FourVector(px, py, pz, e), partonId, 103 ) );
695 }
696 }
697 }
698
699 // Now for target nucleons
700 //
701 for (int itarg = 1; itarg <= iat; itarg++)
702 {
703 for (int jparton = 1; jparton <= m_hijjet1.ntj(itarg); jparton++)
704 {
705 double px = m_hijjet1.pjtx(itarg, jparton);
706 double py = m_hijjet1.pjty(itarg, jparton);
707 double pz = m_hijjet1.pjtz(itarg, jparton);
708 double mass = m_hijjet1.pjtm(itarg, jparton);
709
710 double ptsq = px*px + py*py;
711 double e = std::sqrt(ptsq + pz*pz + mass*mass);
712 double mt = std::sqrt(ptsq + mass*mass);
713 double pt = std::sqrt(ptsq);
714
715 double pseud = 0.5*std::log((e + pz)/(e - pz));
716
717 int partonId = m_hijjet1.kftj(itarg, jparton);
718
719 if (mt > m_partonStoreMinPt)
720 {
721 ATH_MSG_DEBUG( "hijjet1 entry: itarg = " << itarg
722 << ", pt = " << pt
723 << ", mt = " << mt
724 << ", eta = " << pseud );
725
726 // Add aaa non-tracked entry in the hepmc event with status code 103 (temporary)
727 //
728 v1->add_particle_out( HepMC::newGenParticlePtr( HepMC::FourVector(px, py, pz, e), partonId, 103 ) );
729 }
730 }
731 }
732
733 // Convert GeV -> MeV to ensure correct units
734 evt->set_units(HepMC3::Units::MEV, HepMC3::Units::MM);
735
736 //BPK-> Loop over the particles in the event, if p needs to be mirrored:
737 if( m_prand ){
738 HepMC::FourVector tmpmom(0.,0.,0.,0.);
739 double ranz = CLHEP::RandFlat::shoot(p_Engine);
740 // std::cout <<"random="<<ranz <<std::endl;
741 if (ranz < 0.5) {
742 // std::cout <<"flip="<<ranz <<std::endl;
743 for(auto pitr: *evt){
744 tmpmom= pitr->momentum();
745 tmpmom.setX(-tmpmom.x());
746 tmpmom.setY(-tmpmom.y());
747 tmpmom.setZ(-tmpmom.z());
748 tmpmom.setT(tmpmom.t());
749 pitr->set_momentum(tmpmom);
750 }
751 }
752 }
753 //BPK-<
754
755 return StatusCode::SUCCESS;
756}
757
758CLHEP::HepLorentzVector
759Hijing::randomizeVertex(CLHEP::HepRandomEngine* engine)
760{
761 // Check the range in Z for the correct pipe diameter
762 // Definitions of constants are in VertexShift.h
763
764 using namespace VertexShift;
765
766 double ranx, rany, xmax, ymax;
767 double ranz = CLHEP::RandFlat::shoot(engine, -Zmax, Zmax);
768 if( m_wide ){ // Allow the whole pipe
769 if( std::abs(ranz) < Start1 ) {
770 xmax = Xmin + Delta1;
771 ymax = xmax;
772 } else if( std::abs(ranz) < Start2 ) {
773 xmax = Xmin + Delta2;
774 ymax = xmax;
775 } else if( std::abs(ranz) < Start3 ) {
776 xmax = Xmin + Delta3;
777 ymax = xmax;
778 } else if ( std::abs(ranz) <= Envelope ){
779 xmax = Xmin;
780 ymax = xmax;
781 } else {
782 ATH_MSG_ERROR( "**** Hijing::randomizeVertex() " << ranz << " (z) is outside the detector (units of mm). Returning a centered event." );
783 return CLHEP::HepLorentzVector(0.,0.,0.,0.);
784 }
785 } else {
786 ATH_MSG_INFO( "New Coordinates: x=0., y=0., z=" << ranz );
787 return CLHEP::HepLorentzVector(0., 0., ranz, 0); // Allow distribution just along the beam (no "width", m_wide is false (default))
788 }
789 ranx = CLHEP::RandFlat::shoot(engine, -xmax, xmax);
790 rany = CLHEP::RandFlat::shoot(engine, -ymax, ymax);
791
792 ATH_MSG_INFO( "New Coordinates: x=" << ranx << ", y=" << rany << ", z=" << ranz );
793
794 return CLHEP::HepLorentzVector(ranx, rany, ranz, 0);
795}
796
797void
799{
800 // set up the DEFAULT input parameters to hijset: these can be changed by the user ...
801 m_efrm = 14000.;
802 m_frame = "CMS ";
803 m_proj = "P ";
804 m_targ = "P ";
805 m_iap = 1;
806 m_iat = 1;
807 m_izp = 1;
808 m_izt = 1;
809 // ... and to hijing
810 m_bmin = 0.;
811 m_bmax = 0.;
812
813 // Set user Initialization parameters
814 for(CommandVector::iterator i = m_InitializeVector.begin(); i != m_InitializeVector.end(); ++i )
815 {
816 ATH_MSG_INFO( " Hijing init. Command is: " << *i );
817 StringParse mystring(*i);
818 std::string myparam = mystring.piece<std::string>(1);
819 if (myparam == "efrm")
820 {
821 m_efrm = mystring.piece<double>(2);
822 }
823 else if (myparam == "frame")
824 {
825 m_frame = mystring.piece<std::string>(2);
826 if (m_frame.size() < 8)
827 {
828 unsigned nbl = 8 - m_frame.size();
829 for (unsigned i = 0; i < nbl; ++i) m_frame += ' ';
830 }
831 }
832 else if (myparam == "proj")
833 {
834 m_proj = mystring.piece<std::string>(2);
835 if (m_proj.size() < 8)
836 {
837 unsigned nbl = 8 - m_proj.size();
838 for (unsigned i = 0; i < nbl; ++i) m_proj += ' ';
839 }
840 }
841 else if (myparam == "targ")
842 {
843 m_targ = mystring.piece<std::string>(2);
844 if (m_targ.size() < 8)
845 {
846 unsigned nbl = 8 - m_targ.size();
847 for (unsigned i = 0; i < nbl; ++i) m_targ += ' ';
848 }
849 }
850 else if (myparam == "iap")
851 {
852 m_iap = mystring.piece<int>(2);
853 }
854 else if (myparam == "izp")
855 {
856 m_izp = mystring.piece<int>(2);
857 }
858 else if (myparam == "iat")
859 {
860 m_iat = mystring.piece<int>(2);
861 }
862 else if (myparam == "izt")
863 {
864 m_izt = mystring.piece<int>(2);
865 }
866 else if (myparam == "bmin")
867 {
868 m_bmin = mystring.piece<double>(2);
869 }
870 else if (myparam == "bmax")
871 {
872 m_bmax = mystring.piece<double>(2);
873 }
874 else if (myparam == "nseed")
875 {
876 m_ranseed.nseed() = mystring.piece<int>(2);
877 }
878 else if (myparam == "hipr1")
879 {
880 int myelem = mystring.piece<int>(2);
881 m_hiparnt.hipr1(myelem) = mystring.piece<double>(3);
882 }
883 else if (myparam == "ihpr2")
884 {
885 int myelem = mystring.piece<int>(2);
886 m_hiparnt.ihpr2(myelem) = mystring.piece<int>(3);
887 }
888 else if (myparam == "hint1")
889 {
890 int myelem = mystring.piece<int>(2);
891 m_hiparnt.hint1(myelem) = mystring.piece<double>(3);
892 }
893 else if (myparam == "ihnt2")
894 {
895 int myelem = mystring.piece<int>(2);
896 m_hiparnt.ihnt2(myelem) = mystring.piece<int>(3);
897 }
898 else
899 {
900 ATH_MSG_ERROR( " ERROR in HIJING INITIALIZATION PARAMETERS " << myparam << " is an invalid parameter !" );
901 }
902 }
903}
#define endmsg
#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)
float ran_(int *idummy)
Definition Hijing.cxx:77
char histrng_[]
void * getaddri_(int *arg)
Definition Hijing.cxx:63
char hijjet4_[]
uintptr_t hijjet2_address_()
Definition Hijing.cxx:95
uintptr_t hiparnt_address_()
Definition Hijing.cxx:97
uintptr_t himain1_address_()
Definition Hijing.cxx:92
uintptr_t histrng_address_()
Definition Hijing.cxx:98
char himain1_[]
float atl_ran_(int *)
Definition Hijing.cxx:72
void * getaddr_(void *arg)
Definition Hijing.cxx:55
uintptr_t hijjet4_address_()
Definition Hijing.cxx:96
uintptr_t himain2_address_()
Definition Hijing.cxx:93
void hijing_(const char *, float *, float *, long int)
uintptr_t ranseed_address_()
Definition Hijing.cxx:100
char himain2_[]
uintptr_t hijjet1_address_()
Definition Hijing.cxx:94
char ranseed_[]
char hiparnt_[]
char hijjet2_[]
char hijcrdn_[]
char hijjet1_[]
void hijset_(float *, const char *, const char *, const char *, int *, int *, int *, int *, long int, long int, long int)
uintptr_t hijcrdn_address_()
Definition Hijing.cxx:99
#define y
#define x
#define z
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
GenModule(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition GenModule.cxx:14
CLHEP::HepRandomEngine * getRandomEngineDuringInitialize(const std::string &streamName, unsigned long int randomSeedOffset, unsigned int conditionsRun=1, unsigned int lbn=1) const
Definition GenModule.cxx:53
IntegerProperty m_randomSeed
Seed for random number engine.
Definition GenModule.h:84
HiParnt m_hiparnt
Definition Hijing.h:101
bool m_wide
Definition Hijing.h:82
std::string m_targ
Definition Hijing.h:63
std::string m_proj
Definition Hijing.h:62
bool m_sel
Definition Hijing.h:77
float m_bmax
Definition Hijing.h:70
HiMain1 m_himain1
Definition Hijing.h:107
int m_iat
Definition Hijing.h:65
HijJet1 m_hijjet1
Definition Hijing.h:109
bool m_prand
Definition Hijing.h:83
float m_y
Definition Hijing.h:75
Hijing(const std::string &name, ISvcLocator *pSvcLocator)
Definition Hijing.cxx:116
double m_vertexOffsetCut
Definition Hijing.h:88
void set_user_params(void)
Definition Hijing.cxx:798
RanSeed m_ranseed
Definition Hijing.h:104
HijJet2 m_hijjet2
Definition Hijing.h:110
virtual StatusCode genFinalize() override
For finalising the generator, if required.
Definition Hijing.cxx:236
bool m_spec
Definition Hijing.h:78
HiMain2 m_himain2
Definition Hijing.h:108
float m_x
Definition Hijing.h:74
float m_z
Definition Hijing.h:76
IntegerProperty m_dsid
Definition Hijing.h:57
float m_efrm
Definition Hijing.h:60
float m_bmin
Definition Hijing.h:69
int m_iap
Definition Hijing.h:64
int m_events
Definition Hijing.h:95
std::vector< long int > m_seeds
Definition Hijing.h:92
int m_izt
Definition Hijing.h:67
virtual StatusCode genInitialize() override
For initializing the generator, if required.
Definition Hijing.cxx:133
SG::WriteHandleKey< HijingEventParams > m_event_paramsKey
Definition Hijing.h:117
virtual CLHEP::HepLorentzVector randomizeVertex(CLHEP::HepRandomEngine *engine)
Definition Hijing.cxx:759
int m_izp
Definition Hijing.h:66
virtual StatusCode fillEvt(HepMC::GenEvent *evt) override
For filling the HepMC event object.
Definition Hijing.cxx:243
virtual StatusCode callGenerator() override
For calling the generator on each iteration of the event loop.
Definition Hijing.cxx:177
double m_partonStoreMinPt
Definition Hijing.h:87
bool m_rand
Definition Hijing.h:81
std::string m_frame
Definition Hijing.h:61
bool m_keepAllDecayVertices
Definition Hijing.h:84
CommandVector m_InitializeVector
Definition Hijing.h:98
Utility object for parsing a string into tokens and returning them as a variety of types.
Definition StringParse.h:33
T piece(size_t num) const
Templated function to get the num'th token as any numeric type.
Definition StringParse.h:44
double xmax
Definition listroot.cxx:61
double ymax
Definition listroot.cxx:64
void calculateSeedsMC21(long *seeds, const std::string &algName, uint64_t ev, uint64_t run, uint64_t offset=0)
Set the random seed using a string (e.g.
HepMC3::FourVector FourVector
HepMC3::GenHeavyIonPtr GenHeavyIonPtr
Definition HeavyIon.h:11
void set_signal_process_vertex(GenEvent *e, T &v)
Definition GenEvent.h:591
void set_signal_process_id(GenEvent *e, const int i=0)
Definition GenEvent.h:580
void set_random_states(GenEvent *e, std::vector< long int > &a)
Definition GenEvent.h:588
GenParticlePtr newGenParticlePtr(const HepMC3::FourVector &mom=HepMC3::FourVector::ZERO_VECTOR(), int pid=0, int status=0)
Definition GenParticle.h:21
HepMC3::GenParticlePtr GenParticlePtr
Definition GenParticle.h:19
GenVertexPtr newGenVertexPtr(const HepMC3::FourVector &pos=HepMC3::FourVector::ZERO_VECTOR(), const int i=0)
Definition GenVertex.h:25
HepMC3::GenVertexPtr GenVertexPtr
Definition GenVertex.h:23
HepMC3::GenEvent GenEvent
Definition GenEvent.h:39
const float Delta1
Definition VertexShift.h:29
const float Zmax
Definition VertexShift.h:26
const float Start2
Definition VertexShift.h:37
const float Xmin
Definition VertexShift.h:25
const float Delta2
Definition VertexShift.h:30
const float Start3
Definition VertexShift.h:38
const float Start1
Definition VertexShift.h:36
const float Delta3
Definition VertexShift.h:31