]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STARLIGHT/AliGenStarLight.cxx
add h-jet jet mass analysis class
[u/mrichter/AliRoot.git] / STARLIGHT / AliGenStarLight.cxx
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"
22 #include "AliRunLoader.h"
23 #include "AliGenEventHeader.h"
24 #include "AliGenStarLight.h"
25
26 ClassImp(AliGenStarLight);
27
28 AliGenStarLight::AliGenStarLight()
29   : AliGenMC()
30   , fSLgenerator(NULL) {
31 }
32 //----------------------------------------------------------------------
33 AliGenStarLight::AliGenStarLight(Int_t npart)
34   : AliGenMC(npart)
35   , fSLgenerator(new TStarLight("TStarLight",
36                                 "StarLight UPC Event Generator",
37                                 ""))  // no config file name  
38 {
39   //
40 }
41 //----------------------------------------------------------------------
42 AliGenStarLight::~AliGenStarLight() {
43   if (NULL != fSLgenerator) delete fSLgenerator;
44   fSLgenerator = NULL;
45 }
46 void AliGenStarLight::ImportConfigurationFromFile(const char* filename) {
47   if (NULL == fSLgenerator) {
48     AliFatal("AliGenStarLight class not constructed properly. ");
49     return;
50   }
51   fSLgenerator->ImportConfigurationFromFile(filename);
52 }
53 void 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 //----------------------------------------------------------------------
61 void AliGenStarLight::Init() {
62   if (NULL == fSLgenerator) {
63     AliFatal("AliGenStarLight class not constructed properly. ");
64     return;
65   }
66   fSLgenerator->InitStarLight();
67 }
68 //----------------------------------------------------------------------
69 void AliGenStarLight::Generate() {
70   Float_t vpos[4] = { 0, 0, 0, 0 };
71   if (fVertexSmear == kPerEvent) {
72     Vertex(); // get vertex
73     for (Int_t i=0; i<3; ++i)
74       vpos[i] = fVertex[i];
75     vpos[3] = fTime;
76   }
77
78   Int_t   nt(0);     // number of tracks
79   Bool_t  genOK(kFALSE);  
80   // generate events until all constraints are fulfilled
81   for (Int_t trials=0; !genOK && trials < 100*1000; ++trials) {
82     fSLgenerator->GenerateEvent();
83     fSLgenerator->BoostEvent();
84     fSLgenerator->ImportParticles(&fParticles, "ALL");
85     
86     genOK = kTRUE;
87     for (Long64_t i(0), n(fParticles.GetEntries()); i<n && genOK; ++i) {
88       const TParticle *part(dynamic_cast<TParticle*>(fParticles.At(i)));
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       }
109       const Int_t   iparent(-1);
110       const Float_t polar[3] = { 0, 0, 0 };
111       const Float_t weight(trials+1);
112       PushTrack(fTrackIt, iparent, part->GetPdgCode(), 
113                 part->Px(), part->Py(), part->Pz(), part->Energy(),
114                 vpos[0],    vpos[1],    vpos[2],    vpos[3],
115                 polar[0],   polar[1],   polar[2], 
116                 kPPrimary, nt, weight, part->GetStatusCode());
117       AliInfo(Form("weight=%.0f nt=%d fTrackIt=%d statusCode=%d",
118                    weight, nt, fTrackIt, part->GetStatusCode()));
119       part->Print();
120       KeepTrack(nt);
121       ++fNprimaries;
122     }
123     fParticles.Clear();
124   }
125   if (kFALSE == genOK)
126     AliFatal("Maximum number of trials reached");
127
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();
136 }