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