Little changes to run for pdc04
[u/mrichter/AliRoot.git] / START / AliSTARTDigitizer.cxx
CommitLineData
ede9aff7 1
2/**************************************************************************
3 * Copyright(c) 1998-2000, ALICE Experiment at CERN, All rights reserved. *
4 * *
5 * Author: The ALICE Off-line Project. *
6 * Contributors are mentioned in the code where appropriate. *
7 * *
8 * Permission to use, copy, modify and distribute this software and its *
9 * documentation strictly for non-commercial purposes is hereby granted *
10 * without fee, provided that the above copyright notice appears in all *
11 * copies and that both the copyright notice and this permission notice *
12 * appear in the supporting documentation. The authors make no claims *
13 * about the suitability of this software for any purpose. It is *
14 * provided "as is" without express or implied warranty. *
15 **************************************************************************/
16
17
18#include <TTree.h>
ede9aff7 19#include <TFile.h>
20#include <TDirectory.h>
21#include <TRandom.h>
e73d68f2 22#include <TArrayI.h>
2b4678e2 23#include <TError.h>
e4da63c2 24#include <TH1F.h>
ede9aff7 25
e4da63c2 26#include "AliLog.h"
ede9aff7 27#include "AliSTARTDigitizer.h"
28#include "AliSTART.h"
29#include "AliSTARThit.h"
30#include "AliSTARTdigit.h"
31#include "AliRunDigitizer.h"
affef71b 32#include <AliDetector.h>
ede9aff7 33#include "AliRun.h"
affef71b 34#include <AliLoader.h>
35#include <AliRunLoader.h>
ede9aff7 36#include <stdlib.h>
ef0750c2 37#include <Riostream.h>
38#include <Riostream.h>
ede9aff7 39
40ClassImp(AliSTARTDigitizer)
41
42//___________________________________________
43 AliSTARTDigitizer::AliSTARTDigitizer() :AliDigitizer()
44{
45// Default ctor - don't use it
46 ;
47}
48
49//___________________________________________
50AliSTARTDigitizer::AliSTARTDigitizer(AliRunDigitizer* manager)
51 :AliDigitizer(manager)
52{
f540341d 53 // cout<<"AliSTARTDigitizer::AliSTARTDigitizer"<<endl;
ede9aff7 54// ctor which should be used
e4da63c2 55
56 AliDebug(1,"processed");
57
58 ftimeTDC = new TArrayI(24);
59 fADC = new TArrayI(24);
174d209f 60
61 TFile* file = TFile::Open("$ALICE_ROOT/START/PMTefficiency.root");
62 fEff = (TH1F*) file->Get("hEff")->Clone();
63 fEff->SetDirectory(NULL);
64 file->Close();
65 delete file;
ede9aff7 66}
67
68//------------------------------------------------------------------------
69AliSTARTDigitizer::~AliSTARTDigitizer()
70{
71// Destructor
e4da63c2 72
73 AliDebug(1,"START");
74 delete ftimeTDC;
75 delete fADC;
174d209f 76 delete fEff;
ede9aff7 77}
78
79 //------------------------------------------------------------------------
80Bool_t AliSTARTDigitizer::Init()
81{
82// Initialization
e4da63c2 83 AliDebug(1," Init");
ede9aff7 84 return kTRUE;
85}
86
87
88//---------------------------------------------------------------------
89
dc63cec5 90void AliSTARTDigitizer::Exec(Option_t* /*option*/)
ede9aff7 91{
92
affef71b 93 /*
94 Produde digits from hits
95 digits is TObject and includes
96 We are writing array if left & right TDC
97 left & right ADC (will need for slow simulation)
98 TOF first particle left & right
99 mean time and time difference (vertex position)
100
101 */
88cb7938 102
103 AliRunLoader *inRL, *outRL;//in and out Run Loaders
affef71b 104 AliLoader *pInStartLoader, *pOutStartLoader;// in and out STARTLoaders
88cb7938 105
106 outRL = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
affef71b 107 pOutStartLoader = outRL->GetLoader("STARTLoader");
88cb7938 108
e4da63c2 109 AliDebug(1,"start...");
110
ede9aff7 111 //
112 // From hits to digits
113 //
e73d68f2 114 Int_t hit, nhits;
affef71b 115 Float_t meanTime;
e4da63c2 116 Int_t countE[24];
117 Int_t volume,pmt,tr,sumRight;
118 Int_t bestRightTDC,bestLeftTDC;
119 Float_t time[24]={24*0};
120 Float_t besttime[24]={24*0};
121 Float_t timeGaus[37]={24*0};
122 Float_t channelWidth=25.; //ps
e73d68f2 123
ede9aff7 124 AliSTARThit *startHit;
125 TBranch *brHits=0;
e4da63c2 126
6fc133d2 127 pOutStartLoader->LoadDigits("UPDATE");//probably it is necessary to load them before
ede9aff7 128 fdigits= new AliSTARTdigit();
6fc133d2 129 pOutStartLoader->GetDigitsDataLoader()->GetBaseLoader(0)->Post(fdigits);
ede9aff7 130
131 Int_t nFiles=fManager->GetNinputs();
132 for (Int_t inputFile=0; inputFile<nFiles; inputFile++) {
6fc133d2 133 if (inputFile < nFiles-1) {
e4da63c2 134 AliWarning(Form("ignoring input stream %d", inputFile));
6fc133d2 135 continue;
e4da63c2 136
6fc133d2 137 }
e73d68f2 138
affef71b 139 Float_t besttimeright=9999.;
140 Float_t besttimeleft=9999.;
e4da63c2 141 Float_t timeDiff;
e73d68f2 142 sumRight=0;
e4da63c2 143 for (Int_t i0=0; i0<24; i0++)
e73d68f2 144 {
e4da63c2 145 time[i0]=9999; besttime[i0]=9999; countE[i0]=0;
e73d68f2 146 }
88cb7938 147
148 inRL = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(inputFile));
6fc133d2 149 if (!inRL->GetAliRun()) inRL->LoadgAlice();
150 AliSTART *fSTART = (AliSTART*) inRL->GetAliRun()->GetDetector("START");
affef71b 151 pInStartLoader = inRL->GetLoader("STARTLoader");
152 pInStartLoader->LoadHits("READ");//probably it is necessary to load them before
affef71b 153 TClonesArray *fHits = fSTART->Hits ();
ede9aff7 154
affef71b 155 TTree *th = pInStartLoader->TreeH();
ede9aff7 156 brHits = th->GetBranch("START");
157 if (brHits) {
e4da63c2 158 fSTART->SetHitsAddressBranch(brHits);
ede9aff7 159 }else{
e4da63c2 160 AliError("Branch START hit not found");
00907af4 161 exit(111);
ede9aff7 162 }
163 Int_t ntracks = (Int_t) th->GetEntries();
e4da63c2 164
165 if (ntracks<=0) return;
ede9aff7 166 // Start loop on tracks in the hits containers
167 for (Int_t track=0; track<ntracks;track++) {
168 brHits->GetEntry(track);
7a68e0ef 169 nhits = fHits->GetEntriesFast();
e4da63c2 170 for (hit=0;hit<nhits;hit++)
171 {
172 startHit = (AliSTARThit*) fHits->UncheckedAt(hit);
173 if (!startHit) {
174 AliError("The unchecked hit doesn't exist");
175 break;
176 }
177 pmt=startHit->Pmt();
178 Int_t numpmt=pmt-1;
179 Float_t e=startHit->Etot();
180 volume = startHit->Volume();
181 if(RegisterPhotoE(e)) countE[numpmt]++;
182 besttime[numpmt] = startHit->Time();
183 if(besttime[numpmt]<time[numpmt])
e73d68f2 184 {
e4da63c2 185 time[numpmt]=besttime[numpmt];
186 }
187
188 } //hits loop
ede9aff7 189 } //track loop
e4da63c2 190
191 //best time right&left
192 for (Int_t ipmt=0; ipmt<12; ipmt++)
193 {
194 timeGaus[ipmt]=gRandom->Gaus(time[ipmt],0.025);
195 if(timeGaus[ipmt]<besttimeleft) besttimeleft=timeGaus[ipmt]; //timeleft
196 }
197 for ( Int_t ipmt=12; ipmt<24; ipmt++)
198 {
199 timeGaus[ipmt]=gRandom->Gaus(time[ipmt],0.025);
200 if(timeGaus[ipmt]<besttimeright) besttimeright=timeGaus[ipmt]; //timeright
201 }// besttime
202
ede9aff7 203 //folding with experimental time distribution
e4da63c2 204 Float_t c = 29.9792; // mm/ns
205 Float_t koef=(350.-69.7)/c;
206 Float_t besttimeleftR= besttimeleft;
207 besttimeleft=koef+besttimeleft;
208 bestLeftTDC=Int_t (besttimeleftR*1000/channelWidth);
209 bestRightTDC=Int_t (besttimeright*1000/channelWidth);
210 timeDiff=(c*(besttimeright-besttimeleftR)-(350.-69.7))/(2*c);
211 meanTime=(besttimeright+besttimeleftR)/2.;
212 Float_t ds=(c*(besttimeright-besttimeleftR)-(350.-69.7))/2;
213 AliDebug(2,Form(" timediff in ns %f z= %f real point%f",timeDiff,timeDiff*c,ds));
214
215
216 // Time to TDC signal
217 Int_t iTimeAv=Int_t (meanTime*1000/channelWidth);
218 // time channel numbres
219 // fill digits
220 fdigits->SetTimeBestLeft(bestLeftTDC);
221 fdigits->SetTimeBestRight(bestRightTDC);
222 fdigits->SetMeanTime(iTimeAv);
e73d68f2 223
e4da63c2 224 //ADC features
225
226 for (Int_t i=0; i<24; i++)
e73d68f2 227 {
e4da63c2 228
229 // fill TDC
230 tr= Int_t (timeGaus[i]*1000/channelWidth);
231 if(timeGaus[i]>100) tr=0;
232 ftimeTDC->AddAt(tr,i);
e73d68f2 233
e4da63c2 234 //fill ADC
235 Int_t al= countE[i]; //1024 - channel width shoul be change
236 fADC->AddAt(al,i);
237 } //pmt loop
88cb7938 238
e4da63c2 239 fdigits->SetTime(*ftimeTDC);
240 fdigits->SetADC(*fADC);
241
affef71b 242 pInStartLoader->UnloadHits();
e4da63c2 243
6fc133d2 244 } //input streams loop
e4da63c2 245
6fc133d2 246 pOutStartLoader->WriteDigits("OVERWRITE");
247 pOutStartLoader->UnloadDigits();
ede9aff7 248}
249
250
e73d68f2 251//------------------------------------------------------------------------
e4da63c2 252Bool_t AliSTARTDigitizer::RegisterPhotoE(Float_t e)
e73d68f2 253{
e4da63c2 254
255
256 // Float_t hc=197.326960*1.e6; //mev*nm
257 Float_t hc=1.973*1.e-6; //gev*nm
258 Float_t lambda=hc/e;
174d209f 259 Int_t bin= fEff->GetXaxis()->FindBin(lambda);
260 Float_t eff=fEff->GetBinContent(bin);
e4da63c2 261 Double_t p = gRandom->Rndm();
262 if (p > eff)
263 return kFALSE;
264
265 return kTRUE;
e73d68f2 266}
7a68e0ef 267//----------------------------------------------------------------------------