]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STARLIGHT/AliGenStarLight.cxx
New MFT analysis tools
[u/mrichter/AliRoot.git] / STARLIGHT / 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()
da32329d
AM
30 , fSLgenerator(NULL) {
31}
32//----------------------------------------------------------------------
33AliGenStarLight::AliGenStarLight(Int_t npart)
34 : AliGenMC(npart)
a2de4243 35 , fSLgenerator(new TStarLight("TStarLight",
da32329d 36 "StarLight UPC Event Generator",
a2de4243 37 "")) // no config file name
38{
39 //
da32329d
AM
40}
41//----------------------------------------------------------------------
42AliGenStarLight::~AliGenStarLight() {
a2de4243 43 if (NULL != fSLgenerator) delete fSLgenerator;
da32329d
AM
44 fSLgenerator = NULL;
45}
46void AliGenStarLight::ImportConfigurationFromFile(const char* filename) {
47 if (NULL == fSLgenerator) {
48 AliFatal("AliGenStarLight class not constructed properly. ");
49 return;
50 }
51 fSLgenerator->ImportConfigurationFromFile(filename);
52}
53void AliGenStarLight::SetParameter(const char* line) {
54 if (NULL == fSLgenerator) {
55 AliFatal("AliGenStarLight class not constructed properly. ");
56 return;
57 }
58 fSLgenerator->SetParameter(line);
59}
60//----------------------------------------------------------------------
61void AliGenStarLight::Init() {
62 if (NULL == fSLgenerator) {
63 AliFatal("AliGenStarLight class not constructed properly. ");
64 return;
65 }
66 fSLgenerator->InitStarLight();
67}
68//----------------------------------------------------------------------
69void AliGenStarLight::Generate() {
a2de4243 70 Float_t vpos[4] = { 0, 0, 0, 0 };
da32329d
AM
71 if (fVertexSmear == kPerEvent) {
72 Vertex(); // get vertex
73 for (Int_t i=0; i<3; ++i)
a2de4243 74 vpos[i] = fVertex[i];
75 vpos[3] = fTime;
da32329d
AM
76 }
77
52284ebd 78 Int_t nt(0); // number of tracks
a2de4243 79 Bool_t genOK(kFALSE);
80 // generate events until all constraints are fulfilled
52284ebd 81 for (Int_t trials=0; !genOK && trials < 100*1000; ++trials) {
da32329d
AM
82 fSLgenerator->GenerateEvent();
83 fSLgenerator->BoostEvent();
84 fSLgenerator->ImportParticles(&fParticles, "ALL");
85
a2de4243 86 genOK = kTRUE;
87 for (Long64_t i(0), n(fParticles.GetEntries()); i<n && genOK; ++i) {
da32329d 88 const TParticle *part(dynamic_cast<TParticle*>(fParticles.At(i)));
a2de4243 89 if (NULL == part) {
90 AliFatal("NULL == part");
91 return;
92 }
93 genOK =
94 (part->Theta() >= fThetaMin) && (part->Theta() < fThetaMax) &&
95 (part->Phi() >= fPhiMin) && (part->Phi() < fPhiMax) &&
96 (part->Y() >= fYMin) && (part->Y() < fYMax) &&
97 (part->P() >= fPMin) && (part->P() < fPMax) &&
98 (part->Pt() >= fPtMin) && (part->Pt() < fPtMax);
99 }
100 if (kFALSE == genOK) continue;
101
102 fNprimaries = 0;
103 for (Long64_t i(0), n(fParticles.GetEntries()); i<n; ++i) {
104 const TParticle *part(dynamic_cast<TParticle*>(fParticles.At(i)));
105 if (NULL == part) {
106 AliFatal("NULL == part");
107 return;
108 }
52284ebd 109 const Int_t iparent(-1);
110 const Float_t polar[3] = { 0, 0, 0 };
111 const Float_t weight(trials+1);
a2de4243 112 PushTrack(fTrackIt, iparent, part->GetPdgCode(),
da32329d 113 part->Px(), part->Py(), part->Pz(), part->Energy(),
a2de4243 114 vpos[0], vpos[1], vpos[2], vpos[3],
115 polar[0], polar[1], polar[2],
116 kPPrimary, nt, weight, part->GetStatusCode());
52284ebd 117 AliInfo(Form("weight=%.0f nt=%d fTrackIt=%d statusCode=%d",
118 weight, nt, fTrackIt, part->GetStatusCode()));
a2de4243 119 part->Print();
da32329d 120 KeepTrack(nt);
a2de4243 121 ++fNprimaries;
da32329d 122 }
52284ebd 123 fParticles.Clear();
a2de4243 124 }
125 if (kFALSE == genOK)
126 AliFatal("Maximum number of trials reached");
da32329d 127
a2de4243 128 AliGenEventHeader* header = new AliGenEventHeader("SL");
129 const TArrayF vertexPosition(3, vpos);
130 header->SetPrimaryVertex(vertexPosition);
131 header->SetInteractionTime(vpos[3]);
132 header->SetNProduced(nt);
133 AddHeader(header);
134 SetHighWaterMark(nt);
135 AliRunLoader::Instance()->CdGAFile();
da32329d 136}