Additional protection
[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);
ede9aff7 60}
61
62//------------------------------------------------------------------------
63AliSTARTDigitizer::~AliSTARTDigitizer()
64{
65// Destructor
e4da63c2 66
67 AliDebug(1,"START");
68 delete ftimeTDC;
69 delete fADC;
ede9aff7 70}
71
72 //------------------------------------------------------------------------
73Bool_t AliSTARTDigitizer::Init()
74{
75// Initialization
e4da63c2 76 AliDebug(1," Init");
ede9aff7 77 return kTRUE;
78}
79
80
81//---------------------------------------------------------------------
82
dc63cec5 83void AliSTARTDigitizer::Exec(Option_t* /*option*/)
ede9aff7 84{
85
affef71b 86 /*
87 Produde digits from hits
88 digits is TObject and includes
89 We are writing array if left & right TDC
90 left & right ADC (will need for slow simulation)
91 TOF first particle left & right
92 mean time and time difference (vertex position)
93
94 */
88cb7938 95
96 AliRunLoader *inRL, *outRL;//in and out Run Loaders
affef71b 97 AliLoader *pInStartLoader, *pOutStartLoader;// in and out STARTLoaders
88cb7938 98
99 outRL = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
affef71b 100 pOutStartLoader = outRL->GetLoader("STARTLoader");
88cb7938 101
e4da63c2 102 AliDebug(1,"start...");
103
ede9aff7 104 //
105 // From hits to digits
106 //
e73d68f2 107 Int_t hit, nhits;
affef71b 108 Float_t meanTime;
e4da63c2 109 Int_t countE[24];
110 Int_t volume,pmt,tr,sumRight;
111 Int_t bestRightTDC,bestLeftTDC;
112 Float_t time[24]={24*0};
113 Float_t besttime[24]={24*0};
114 Float_t timeGaus[37]={24*0};
115 Float_t channelWidth=25.; //ps
e73d68f2 116
ede9aff7 117 AliSTARThit *startHit;
118 TBranch *brHits=0;
e4da63c2 119
6fc133d2 120 pOutStartLoader->LoadDigits("UPDATE");//probably it is necessary to load them before
ede9aff7 121 fdigits= new AliSTARTdigit();
6fc133d2 122 pOutStartLoader->GetDigitsDataLoader()->GetBaseLoader(0)->Post(fdigits);
ede9aff7 123
124 Int_t nFiles=fManager->GetNinputs();
125 for (Int_t inputFile=0; inputFile<nFiles; inputFile++) {
6fc133d2 126 if (inputFile < nFiles-1) {
e4da63c2 127 AliWarning(Form("ignoring input stream %d", inputFile));
6fc133d2 128 continue;
e4da63c2 129
6fc133d2 130 }
e73d68f2 131
affef71b 132 Float_t besttimeright=9999.;
133 Float_t besttimeleft=9999.;
e4da63c2 134 Float_t timeDiff;
e73d68f2 135 sumRight=0;
e4da63c2 136 for (Int_t i0=0; i0<24; i0++)
e73d68f2 137 {
e4da63c2 138 time[i0]=9999; besttime[i0]=9999; countE[i0]=0;
e73d68f2 139 }
88cb7938 140
141 inRL = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(inputFile));
6fc133d2 142 if (!inRL->GetAliRun()) inRL->LoadgAlice();
143 AliSTART *fSTART = (AliSTART*) inRL->GetAliRun()->GetDetector("START");
affef71b 144 pInStartLoader = inRL->GetLoader("STARTLoader");
145 pInStartLoader->LoadHits("READ");//probably it is necessary to load them before
affef71b 146 TClonesArray *fHits = fSTART->Hits ();
ede9aff7 147
affef71b 148 TTree *th = pInStartLoader->TreeH();
ede9aff7 149 brHits = th->GetBranch("START");
150 if (brHits) {
e4da63c2 151 fSTART->SetHitsAddressBranch(brHits);
ede9aff7 152 }else{
e4da63c2 153 AliError("Branch START hit not found");
00907af4 154 exit(111);
ede9aff7 155 }
156 Int_t ntracks = (Int_t) th->GetEntries();
e4da63c2 157
158 if (ntracks<=0) return;
ede9aff7 159 // Start loop on tracks in the hits containers
160 for (Int_t track=0; track<ntracks;track++) {
161 brHits->GetEntry(track);
7a68e0ef 162 nhits = fHits->GetEntriesFast();
e4da63c2 163 for (hit=0;hit<nhits;hit++)
164 {
165 startHit = (AliSTARThit*) fHits->UncheckedAt(hit);
166 if (!startHit) {
167 AliError("The unchecked hit doesn't exist");
168 break;
169 }
170 pmt=startHit->Pmt();
171 Int_t numpmt=pmt-1;
172 Float_t e=startHit->Etot();
173 volume = startHit->Volume();
174 if(RegisterPhotoE(e)) countE[numpmt]++;
175 besttime[numpmt] = startHit->Time();
176 if(besttime[numpmt]<time[numpmt])
e73d68f2 177 {
e4da63c2 178 time[numpmt]=besttime[numpmt];
179 }
180
181 } //hits loop
ede9aff7 182 } //track loop
e4da63c2 183
184 //best time right&left
185 for (Int_t ipmt=0; ipmt<12; ipmt++)
186 {
187 timeGaus[ipmt]=gRandom->Gaus(time[ipmt],0.025);
188 if(timeGaus[ipmt]<besttimeleft) besttimeleft=timeGaus[ipmt]; //timeleft
189 }
190 for ( Int_t ipmt=12; ipmt<24; ipmt++)
191 {
192 timeGaus[ipmt]=gRandom->Gaus(time[ipmt],0.025);
193 if(timeGaus[ipmt]<besttimeright) besttimeright=timeGaus[ipmt]; //timeright
194 }// besttime
195
ede9aff7 196 //folding with experimental time distribution
e4da63c2 197 Float_t c = 29.9792; // mm/ns
198 Float_t koef=(350.-69.7)/c;
199 Float_t besttimeleftR= besttimeleft;
200 besttimeleft=koef+besttimeleft;
201 bestLeftTDC=Int_t (besttimeleftR*1000/channelWidth);
202 bestRightTDC=Int_t (besttimeright*1000/channelWidth);
203 timeDiff=(c*(besttimeright-besttimeleftR)-(350.-69.7))/(2*c);
204 meanTime=(besttimeright+besttimeleftR)/2.;
205 Float_t ds=(c*(besttimeright-besttimeleftR)-(350.-69.7))/2;
206 AliDebug(2,Form(" timediff in ns %f z= %f real point%f",timeDiff,timeDiff*c,ds));
207
208
209 // Time to TDC signal
210 Int_t iTimeAv=Int_t (meanTime*1000/channelWidth);
211 // time channel numbres
212 // fill digits
213 fdigits->SetTimeBestLeft(bestLeftTDC);
214 fdigits->SetTimeBestRight(bestRightTDC);
215 fdigits->SetMeanTime(iTimeAv);
e73d68f2 216
e4da63c2 217 //ADC features
218
219 for (Int_t i=0; i<24; i++)
e73d68f2 220 {
e4da63c2 221
222 // fill TDC
223 tr= Int_t (timeGaus[i]*1000/channelWidth);
224 if(timeGaus[i]>100) tr=0;
225 ftimeTDC->AddAt(tr,i);
e73d68f2 226
e4da63c2 227 //fill ADC
228 Int_t al= countE[i]; //1024 - channel width shoul be change
229 fADC->AddAt(al,i);
230 } //pmt loop
88cb7938 231
e4da63c2 232 fdigits->SetTime(*ftimeTDC);
233 fdigits->SetADC(*fADC);
234
affef71b 235 pInStartLoader->UnloadHits();
e4da63c2 236
6fc133d2 237 } //input streams loop
e4da63c2 238
6fc133d2 239 pOutStartLoader->WriteDigits("OVERWRITE");
240 pOutStartLoader->UnloadDigits();
ede9aff7 241}
242
243
e73d68f2 244//------------------------------------------------------------------------
e4da63c2 245Bool_t AliSTARTDigitizer::RegisterPhotoE(Float_t e)
e73d68f2 246{
e4da63c2 247
248
249 // Float_t hc=197.326960*1.e6; //mev*nm
250 Float_t hc=1.973*1.e-6; //gev*nm
251 Float_t lambda=hc/e;
252 Char_t filename[80];
253 TH1F *hEff;
254 Char_t *dirname=getenv("ALICE_ROOT");
255 sprintf(filename,"%s/START/PMTefficiency.root",dirname);
256 TFile *file= new TFile(filename);
257 file->cd();
258 hEff = (TH1F*)file->Get("hEff");
259 Int_t bin= hEff->GetXaxis()->FindBin(lambda);
260 Float_t eff=hEff->GetBinContent(bin);
261 file->Close();
262 Double_t p = gRandom->Rndm();
263 if (p > eff)
264 return kFALSE;
265
266 return kTRUE;
e73d68f2 267}
7a68e0ef 268//----------------------------------------------------------------------------