1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
16 // $Id: AliCollider.cxx,v 1.4 2002/12/11 14:45:12 nick Exp $
18 ///////////////////////////////////////////////////////////////////////////
20 // Pythia based universal physics event generator.
21 // This class is derived from TPythia6 and has some extensions to
22 // support also generation of nucleus-nucleus interactions and to allow
23 // investigation of the effect of detector resolving power.
24 // Furthermore, the produced event information is provided in a format
25 // using the AliEvent structure.
26 // For the produced AliTrack objects, the particle ID code is set to the
27 // Pythia KF value, which is compatible with the PDG identifier.
28 // This will allow a direct analysis of the produced data using the
29 // Ralice physics analysis tools.
31 // For further details concerning the produced output structure,
32 // see the docs of the memberfunctions SetVertexMode and SetResolution.
34 // Example job of minimum biased Pb+Pb interactions :
35 // --------------------------------------------------
37 // gSystem->Load("libEG");
38 // gSystem->Load("libEGPythia6");
39 // gSystem->Load("ralice");
41 // AliCollider* gen=new AliCollider();
43 // gen->SetOutputFile("test.root");
44 // gen->SetVertexMode(3);
45 // gen->SetResolution(1e-4); // 1 micron vertex resolution
47 // gen->SetRunNumber(1);
54 // gen->Init("fixt",zp,ap,zt,at,158);
59 // Float_t* rans=new Float_t[nevents];
60 // rndm.Uniform(rans,nevents,2,ap+at);
62 // for (Int_t i=0; i<nevents; i++)
65 // gen->MakeEvent(npart);
67 // AliEvent* evt=gen->GetEvent();
76 // Example job of a cosmic nu+p atmospheric interaction.
77 // -----------------------------------------------------
79 // gSystem->Load("libEG");
80 // gSystem->Load("libEGPythia6");
81 // gSystem->Load("ralice");
83 // AliCollider* gen=new AliCollider();
85 // gen->SetOutputFile("test.root");
87 // gen->SetRunNumber(1);
89 // gen->Init("fixt","nu_mu","p",1e11);
93 // for (Int_t i=0; i<nevents; i++)
95 // gen->MakeEvent(0,1);
97 // AliEvent* evt=gen->GetEvent();
106 //--- Author: Nick van Eijndhoven 22-nov-2002 Utrecht University
107 //- Modified: NvE $Date: 2002/12/11 14:45:12 $ Utrecht University
108 ///////////////////////////////////////////////////////////////////////////
110 #include "AliCollider.h"
112 ClassImp(AliCollider) // Class implementation to enable ROOT I/O
114 AliCollider::AliCollider()
116 // Default constructor.
117 // All variables initialised to default values.
118 fVertexmode=0; // No vertex structure creation
119 fResolution=1e-5; // Standard resolution is 0.1 micron
142 ///////////////////////////////////////////////////////////////////////////
143 AliCollider::~AliCollider()
145 // Default destructor
162 ///////////////////////////////////////////////////////////////////////////
163 void AliCollider::SetOutputFile(TString s)
165 // Create the output file containing all the data in ROOT output format.
171 fOutFile=new TFile(s.Data(),"RECREATE","AliCollider data");
178 fOutTree=new TTree("T","AliCollider event data");
182 fOutTree->Branch("Events","AliEvent",&fEvent,bsize,split);
184 ///////////////////////////////////////////////////////////////////////////
185 void AliCollider::SetVertexMode(Int_t mode)
187 // Set the mode of the vertex structure creation.
189 // By default all generated tracks will only appear in the AliEvent
190 // structure without any primary (and secondary) vertex structure.
191 // The user can build the vertex structure if he/she wants by means
192 // of the beginpoint location of each AliTrack.
194 // However, one can also let AliCollider automatically create
195 // the primary (and secondary) vertex structure(s).
196 // In this case the primary vertex is given Id=1 and all sec. vertices
197 // are given Id's 2,3,4,....
198 // All vertices are created as standalone entities in the AliEvent structure
199 // without any linking between the various vertices.
200 // For this automated process, the user-selected resolution
201 // (see SetResolution) is used to decide whether or not certain vertex
202 // locations can be resolved.
203 // In case no vertex creation is selected (i.e. the default mode=0),
204 // the value of the resolution is totally irrelevant.
206 // The user can also let AliCollider automatically connect the sec. vertices
207 // to the primary vertex (i.e. mode=3). This process will also automatically
208 // generate the tracks connecting the vertices.
209 // Note that the result of the mode=3 operation may be very sensitive to
210 // the resolution parameter. Therefore, no attempt is made to distinguish
211 // between secondary, tertiary etc... vertices. All sec. vertices are
212 // linked to the primary one.
214 // Irrespective of the selected mode, all generated tracks can be obtained
215 // directly from the AliEvent structure.
216 // In case (sec.) vertex creation is selected, all generated vertices can
217 // also be obtained directly from the AliEvent structure.
218 // These (sec.) vertices contain only the corresponding pointers to the various
219 // tracks which are stored in the AliEvent structure.
221 // Overview of vertex creation modes :
222 // -----------------------------------
223 // mode = 0 ==> No vertex structure will be created
224 // 1 ==> Only primary vertex structure will be created
225 // 2 ==> Unconnected primary and secondary vertices will be created
226 // 3 ==> Primary and secondary vertices will be created where all the
227 // sec. vertices will be connected to the primary vertex.
228 // Also the vertex connecting tracks will be automatically
231 if (mode<0 || mode >3)
233 cout << " *AliCollider::SetVertexMode* Invalid argument mode : " << mode << endl;
241 ///////////////////////////////////////////////////////////////////////////
242 Int_t AliCollider::GetVertexMode()
244 // Provide the current mode for vertex structure creation.
247 ///////////////////////////////////////////////////////////////////////////
248 void AliCollider::SetResolution(Double_t res)
250 // Set the resolution (in cm) for resolving (sec.) vertices.
251 // By default this resolution is set to 0.1 micron.
252 // Note : In case no vertex creation has been selected, the value of
253 // the resolution is totally irrelevant.
254 fResolution=fabs(res);
256 ///////////////////////////////////////////////////////////////////////////
257 Double_t AliCollider::GetResolution()
259 // Provide the current resolution (in cm) for resolving (sec.) vertices.
262 ///////////////////////////////////////////////////////////////////////////
263 void AliCollider::SetRunNumber(Int_t run)
265 // Set the user defined run number.
266 // By default the run number is set to 0.
269 ///////////////////////////////////////////////////////////////////////////
270 Int_t AliCollider::GetRunNumber()
272 // Provide the user defined run number.
275 ///////////////////////////////////////////////////////////////////////////
276 void AliCollider::SetPrintFreq(Int_t n)
278 // Set the print frequency for every 'n' events.
279 // By default the printfrequency is set to 1 (i.e. every event).
282 ///////////////////////////////////////////////////////////////////////////
283 Int_t AliCollider::GetPrintFreq()
285 // Provide the user selected print frequency.
288 ///////////////////////////////////////////////////////////////////////////
289 void AliCollider::Init(char* frame,char* beam,char* target,Float_t win)
291 // Initialisation of the underlying Pythia generator package.
292 // This routine just invokes TPythia6::Initialize(...) and the arguments
293 // have the corresponding meaning.
294 // The event number is reset to 0.
299 Initialize(frame,beam,target,win);
301 ///////////////////////////////////////////////////////////////////////////
302 void AliCollider::Init(char* frame,Int_t zp,Int_t ap,Int_t zt,Int_t at,Float_t win)
304 // Initialisation of the underlying Pythia generator package for the generation
305 // of nucleus-nucleus interactions.
306 // In addition to the Pythia standard arguments 'frame' and 'win', the user
307 // can specify here (Z,A) values of the projectile and target nuclei.
309 // Note : The 'win' value denotes either the cms energy per nucleon-nucleon collision
310 // (i.e. frame="cms") or the momentum per nucleon in all other cases.
312 // The event number is reset to 0.
326 if (ap<1 || at<1 || zp>ap || zt>at)
328 cout << " *AliCollider::Init* Invalid input value(s). Zproj = " << zp
329 << " Aproj = " << ap << " Ztarg = " << zt << " Atarg = " << at << endl;
338 cout << " *AliCollider::Init* Nucleus-Nucleus generator initialisation." << endl;
339 cout << " Zproj = " << zp << " Aproj = " << ap << " Ztarg = " << zt << " Atarg = " << at
340 << " Frame = " << frame << " Energy = " << win
343 ///////////////////////////////////////////////////////////////////////////
344 void AliCollider::GetFractions(Float_t zp,Float_t ap,Float_t zt,Float_t at)
346 // Determine the fractions for the various N-N collision processes.
347 // The various processes are : p+p, n+p, p+n and n+n.
358 fFracpp=(zp/ap)*(zt/at);
359 fFracnp=(1.-zp/ap)*(zt/at);
360 fFracpn=(zp/ap)*(1.-zt/at);
361 fFracnn=(1.-zp/ap)*(1.-zt/at);
364 ///////////////////////////////////////////////////////////////////////////
365 void AliCollider::MakeEvent(Int_t npt,Int_t mlist,Int_t medit)
367 // Generate one event.
368 // In case of a nucleus-nucleus interaction, the argument 'npt' denotes
369 // the number of participant nucleons.
370 // In case of a standard Pythia run for 'elementary' particle interactions,
371 // the value of npt is totally irrelevant.
373 // The argument 'medit' denotes the edit mode used for Pyedit().
374 // Note : medit<0 suppresses the invokation of Pyedit().
375 // By default, only 'stable' final particles are kept (i.e. medit=1).
377 // The argument 'mlist' denotes the list mode used for Pylist().
378 // Note : mlist<0 suppresses the invokation of Pylist().
379 // By default, no listing is produced (i.e. mlist=-1).
381 // In the case of a standard Pythia run concerning 'elementary' particle
382 // interactions, the projectile and target particle ID's for the created
383 // event structure are set to the corresponding Pythia KF codes.
384 // All the A and Z values are in that case set to zero.
385 // In case of a nucleus-nucleus interaction, the proper A and Z values for
386 // the projectile and target particles are set in the event structure.
387 // However, in this case both particle ID's are set to zero.
391 // Counters for the various (proj,targ) combinations : p+p, n+p, p+n and n+n
392 Int_t ncols[4]={0,0,0,0};
396 if (npt<1 || npt>(fAproj+fAtarg))
398 cout << " *AliCollider::MakeEvent* Invalid input value. npt = " << npt
399 << " Aproj = " << fAproj << " Atarg = " << fAtarg << endl;
403 // Determine the number of nucleon-nucleon collisions
405 if (npt%2 && fRan.Uniform()>0.5) ncol+=1;
407 // Determine the number of the various types of N+N interactions
412 Int_t maxa=2; // Indicator whether proj (1) or target (2) has maximal A left
414 Float_t* rans=new Float_t[ncol];
415 fRan.Uniform(rans,ncol);
417 for (Int_t i=0; i<ncol; i++)
419 GetFractions(zp,ap,zt,at);
421 if (rndm<=fFracpp) // p+p interaction
435 if (rndm>fFracpp && rndm<=(fFracpp+fFracnp)) // n+p interaction
448 if (rndm>(fFracpp+fFracnp) && rndm<=(fFracpp+fFracnp+fFracpn)) // p+n interaction
461 if (rndm>(fFracpp+fFracnp+fFracpn)) // n+n interaction
476 if (!(fEventnum%fPrintfreq))
478 cout << " *AliCollider::MakeEvent* Run : " << fRunnum << " Event : " << fEventnum
480 cout << " npart = " << npt << " ncol = " << ncol
481 << " ncolpp = " << ncols[0] << " ncolnp = " << ncols[1]
482 << " ncolpn = " << ncols[2] << " ncolnn = " << ncols[3] << endl;
489 fEvent=new AliEvent();
494 fEvent->SetRunNumber(fRunnum);
495 fEvent->SetEventNumber(fEventnum);
505 // Make sure the primary vertex gets correct location and Id=1
509 r.SetPosition(v,"car");
513 r.SetPositionErrors(v,"car");
516 vert.SetTrackCopy(0);
517 vert.SetVertexCopy(0);
519 fEvent->AddVertex(vert,0);
523 Float_t charge=0,mass=0;
529 // Singular settings for a normal Pythia elementary particle interation
536 // Generate all the various collisions
537 Int_t first=1; // Flag to indicate the first collision process
541 for (Int_t itype=0; itype<ntypes; itype++)
545 if (itype==0 && ncols[itype]) Initialize(fFrame,"p","p",fWin);
546 if (itype==1 && ncols[itype]) Initialize(fFrame,"n","p",fWin);
547 if (itype==2 && ncols[itype]) Initialize(fFrame,"p","n",fWin);
548 if (itype==3 && ncols[itype]) Initialize(fFrame,"n","n",fWin);
550 for (Int_t jcol=0; jcol<ncols[itype]; jcol++)
554 if (first) // Store projectile and target information in the event structure
561 pnucl=sqrt(v[0]*v[0]+v[1]*v[1]+v[2]*v[2]);
562 fEvent->SetProjectile(fAproj,fZproj,pnucl);
566 pnucl=sqrt(v[0]*v[0]+v[1]*v[1]+v[2]*v[2]);
567 fEvent->SetTarget(fAtarg,fZtarg,pnucl);
574 pnucl=sqrt(v[0]*v[0]+v[1]*v[1]+v[2]*v[2]);
576 fEvent->SetProjectile(0,0,pnucl,kf);
580 pnucl=sqrt(v[0]*v[0]+v[1]*v[1]+v[2]*v[2]);
582 fEvent->SetTarget(0,0,pnucl,kf);
587 if (medit >= 0) Pyedit(medit); // Define which particles are to be kept
589 if (mlist >= 0) Pylist(mlist);
593 if (fParticles) npart=fParticles->GetEntries();
595 for (Int_t jpart=0; jpart<npart; jpart++)
597 part=(TMCParticle*)fParticles->At(jpart);
603 charge=GetKCHG(kc,1)/3.;
604 if (kf<0) charge*=-1;
607 // 3-momentum in GeV/c
611 p.SetVector(v,"car");
613 // Production location in cm.
614 v[0]=(part->GetVx())/10;
615 v[1]=(part->GetVy())/10;
616 v[2]=(part->GetVz())/10;
617 r.SetPosition(v,"car");
623 t.SetParticleCode(kf);
631 // Build the vertex structures if requested
634 // Check if track belongs within the resolution to an existing vertex
636 for (Int_t jv=1; jv<=fEvent->GetNvertices(); jv++)
638 AliVertex* vx=fEvent->GetVertex(jv);
641 rx=vx->GetPosition();
642 dist=rx.GetDistance(r);
643 if (dist < fResolution)
645 AliTrack* tx=fEvent->GetIdTrack(ntk);
653 if (add) break; // No need to look further for vertex candidates
656 // If track was not close enough to an existing vertex
657 // a new secondary vertex is created
658 if (!add && fVertexmode>1)
660 AliTrack* tx=fEvent->GetIdTrack(ntk);
666 r.SetPositionErrors(v,"car");
668 vert.SetTrackCopy(0);
669 vert.SetVertexCopy(0);
670 vert.SetId((fEvent->GetNvertices())+1);
673 fEvent->AddVertex(vert,0);
677 } // End of loop over the produced particles for each collision
678 } // End of loop over number of collisions for each type
679 } // End of loop over collision types
681 // Link sec. vertices to primary if requested
682 // Note that also the connecting tracks are automatically created
685 AliVertex* vp=fEvent->GetIdVertex(1); // Primary vertex
688 for (Int_t i=2; i<=fEvent->GetNvertices(); i++)
690 AliVertex* vx=fEvent->GetVertex(i);
693 if (vx->GetId() != 1) vp->AddVertex(vx);
699 if (mlist) cout << endl; // Create empty output line after the event
700 if (fOutTree) fOutTree->Fill();
702 ///////////////////////////////////////////////////////////////////////////
703 AliEvent* AliCollider::GetEvent()
705 // Provide pointer to the generated event structure.
708 ///////////////////////////////////////////////////////////////////////////
709 void AliCollider::EndRun()
711 // Properly close the output file (if needed).
716 cout << " *AliCollider::EndRun* Output file correctly closed." << endl;
719 ///////////////////////////////////////////////////////////////////////////