]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STARLIGHT/AliStarLight/AliGenStarLight.cxx
STARTLIGHT
[u/mrichter/AliRoot.git] / STARLIGHT / AliStarLight / AliGenStarLight.cxx
CommitLineData
da32329d
AM
1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
16/* $Id: $ */
17#include <Riostream.h>
18#include "AliLog.h"
19#include "TStarLight.h"
20#include "starlight.h"
21#include "upcevent.h"
a2de4243 22#include "AliRunLoader.h"
23#include "AliGenEventHeader.h"
da32329d
AM
24#include "AliGenStarLight.h"
25
a2de4243 26ClassImp(AliGenStarLight);
27
da32329d
AM
28AliGenStarLight::AliGenStarLight()
29 : AliGenMC()
7b8392f4 30 , fRapidityMotherMin( 1) // Max < Min: no cut
31 , fRapidityMotherMax(-1)
32 , fEtaChildMin( 1) // Max < Min: no cut
33 , fEtaChildMax(-1)
34 , fSLgenerator(NULL)
35{
da32329d
AM
36}
37//----------------------------------------------------------------------
38AliGenStarLight::AliGenStarLight(Int_t npart)
39 : AliGenMC(npart)
7b8392f4 40 , fRapidityMotherMin( 1) // Max < Min: no cut
41 , fRapidityMotherMax(-1)
42 , fEtaChildMin( 1) // Max < Min: no cut
43 , fEtaChildMax(-1)
a2de4243 44 , fSLgenerator(new TStarLight("TStarLight",
da32329d 45 "StarLight UPC Event Generator",
a2de4243 46 "")) // no config file name
47{
48 //
da32329d
AM
49}
50//----------------------------------------------------------------------
51AliGenStarLight::~AliGenStarLight() {
a2de4243 52 if (NULL != fSLgenerator) delete fSLgenerator;
da32329d
AM
53 fSLgenerator = NULL;
54}
55void AliGenStarLight::ImportConfigurationFromFile(const char* filename) {
56 if (NULL == fSLgenerator) {
57 AliFatal("AliGenStarLight class not constructed properly. ");
58 return;
59 }
60 fSLgenerator->ImportConfigurationFromFile(filename);
61}
62void AliGenStarLight::SetParameter(const char* line) {
63 if (NULL == fSLgenerator) {
64 AliFatal("AliGenStarLight class not constructed properly. ");
65 return;
66 }
67 fSLgenerator->SetParameter(line);
68}
69//----------------------------------------------------------------------
70void AliGenStarLight::Init() {
71 if (NULL == fSLgenerator) {
72 AliFatal("AliGenStarLight class not constructed properly. ");
73 return;
74 }
75 fSLgenerator->InitStarLight();
76}
77//----------------------------------------------------------------------
78void AliGenStarLight::Generate() {
a2de4243 79 Float_t vpos[4] = { 0, 0, 0, 0 };
da32329d
AM
80 if (fVertexSmear == kPerEvent) {
81 Vertex(); // get vertex
82 for (Int_t i=0; i<3; ++i)
a2de4243 83 vpos[i] = fVertex[i];
84 vpos[3] = fTime;
da32329d
AM
85 }
86
52284ebd 87 Int_t nt(0); // number of tracks
a2de4243 88 Bool_t genOK(kFALSE);
89 // generate events until all constraints are fulfilled
52284ebd 90 for (Int_t trials=0; !genOK && trials < 100*1000; ++trials) {
da32329d
AM
91 fSLgenerator->GenerateEvent();
92 fSLgenerator->BoostEvent();
93 fSLgenerator->ImportParticles(&fParticles, "ALL");
94
7b8392f4 95 TLorentzVector vSum;
a2de4243 96 genOK = kTRUE;
7b8392f4 97 const Long64_t n(fParticles.GetEntries());
98 if (n == 0) {
99 AliFatal("no particles generated");
100 return;
101 }
102 for (Long64_t i(0); i<n; ++i) {
103 TParticle *part(dynamic_cast<TParticle*>(fParticles.At(i)));
a2de4243 104 if (NULL == part) {
105 AliFatal("NULL == part");
106 return;
107 }
108 genOK =
109 (part->Theta() >= fThetaMin) && (part->Theta() < fThetaMax) &&
110 (part->Phi() >= fPhiMin) && (part->Phi() < fPhiMax) &&
111 (part->Y() >= fYMin) && (part->Y() < fYMax) &&
112 (part->P() >= fPMin) && (part->P() < fPMax) &&
113 (part->Pt() >= fPtMin) && (part->Pt() < fPtMax);
7b8392f4 114 if (fEtaChildMin <= fEtaChildMax) // no cut if Max < Min
115 genOK = genOK && (part->Eta() >= fEtaChildMin &&
116 part->Eta() < fEtaChildMax);
117 if (kFALSE == genOK)
118 break;
119
120 TLorentzVector v;
121 part->Momentum(v);
122 vSum += v;
a2de4243 123 }
7b8392f4 124
125 if (fRapidityMotherMin <= fRapidityMotherMax) // no cut if Max < Min
126 genOK = (genOK
127 ? (vSum.Rapidity() > fRapidityMotherMin &&
128 vSum.Rapidity() < fRapidityMotherMax)
129 : kFALSE);
130
a2de4243 131 if (kFALSE == genOK) continue;
132
133 fNprimaries = 0;
134 for (Long64_t i(0), n(fParticles.GetEntries()); i<n; ++i) {
135 const TParticle *part(dynamic_cast<TParticle*>(fParticles.At(i)));
136 if (NULL == part) {
137 AliFatal("NULL == part");
138 return;
139 }
52284ebd 140 const Int_t iparent(-1);
141 const Float_t polar[3] = { 0, 0, 0 };
142 const Float_t weight(trials+1);
a2de4243 143 PushTrack(fTrackIt, iparent, part->GetPdgCode(),
da32329d 144 part->Px(), part->Py(), part->Pz(), part->Energy(),
a2de4243 145 vpos[0], vpos[1], vpos[2], vpos[3],
146 polar[0], polar[1], polar[2],
147 kPPrimary, nt, weight, part->GetStatusCode());
52284ebd 148 AliInfo(Form("weight=%.0f nt=%d fTrackIt=%d statusCode=%d",
149 weight, nt, fTrackIt, part->GetStatusCode()));
a2de4243 150 part->Print();
da32329d 151 KeepTrack(nt);
a2de4243 152 ++fNprimaries;
da32329d 153 }
52284ebd 154 fParticles.Clear();
a2de4243 155 }
156 if (kFALSE == genOK)
157 AliFatal("Maximum number of trials reached");
da32329d 158
a2de4243 159 AliGenEventHeader* header = new AliGenEventHeader("SL");
160 const TArrayF vertexPosition(3, vpos);
161 header->SetPrimaryVertex(vertexPosition);
162 header->SetInteractionTime(vpos[3]);
163 header->SetNProduced(nt);
164 AddHeader(header);
165 SetHighWaterMark(nt);
166 AliRunLoader::Instance()->CdGAFile();
da32329d 167}