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