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