]> git.uio.no Git - u/mrichter/AliRoot.git/blame - T0/AliT0Digitizer.cxx
Obsolete.
[u/mrichter/AliRoot.git] / T0 / AliT0Digitizer.cxx
CommitLineData
dc7ca31d 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
9edefa04 17/* $Id$ */
dc7ca31d 18
94249139 19/******************************************************************
20 * Produde digits from hits
21 * digits is TObject and includes
22 * We are writing array if C & A TDC
23 * C & A ADC (will need for slow simulation)
24 * TOF first particle C & A
25 * mean time and time difference (vertex position)
26 *
27 * Alla.Maevskaya@cern.ch
28 ****************************************************************/
29
30
dc7ca31d 31#include <TArrayI.h>
9edefa04 32#include <TFile.h>
dc7ca31d 33#include <TGraph.h>
9edefa04 34#include <TH1F.h>
35#include <TMath.h>
36#include <TRandom.h>
37#include <TTree.h>
dc7ca31d 38
39#include "AliLog.h"
40#include "AliT0Digitizer.h"
41#include "AliT0.h"
42#include "AliT0hit.h"
43#include "AliT0digit.h"
44#include "AliRunDigitizer.h"
dc7ca31d 45#include "AliRun.h"
46#include <AliLoader.h>
47#include <AliRunLoader.h>
48#include <stdlib.h>
dc7ca31d 49#include "AliT0Parameters.h"
dc7ca31d 50
51ClassImp(AliT0Digitizer)
52
53//___________________________________________
c41ceaac 54 AliT0Digitizer::AliT0Digitizer() :AliDigitizer(),
55 fT0(0),
56 fHits(0),
57 fdigits(0),
58 ftimeCFD(new TArrayI(24)),
59 ftimeLED (new TArrayI(24)),
60 fADC(new TArrayI(24)),
61 fADC0 (new TArrayI(24)),
62 fSumMult(0),
29d3e0eb 63 fAmpLED(0),
64 fParam(0)
c41ceaac 65
66
dc7ca31d 67{
68// Default ctor - don't use it
69 ;
70}
71
72//___________________________________________
73AliT0Digitizer::AliT0Digitizer(AliRunDigitizer* manager)
74 :AliDigitizer(manager),
75 fT0(0),
76 fHits(0),
77 fdigits(0),
c41ceaac 78 ftimeCFD(new TArrayI(24)),
79 ftimeLED (new TArrayI(24)),
80 fADC(new TArrayI(24)),
81 fADC0 (new TArrayI(24)),
82 fSumMult(0),
29d3e0eb 83 fAmpLED(0),
84 fParam(0)
dc7ca31d 85{
86// ctor which should be used
87
88 AliDebug(1,"processed");
29d3e0eb 89 fParam = AliT0Parameters::Instance();
90 fParam->Init();
12e9daf9 91 Int_t index[25000];
92 Bool_t down=true;
dc7ca31d 93
29d3e0eb 94 for (Int_t i=0; i<24; i++){
95 TGraph* gr = fParam ->GetAmpLEDRec(i);
96 Int_t np = gr->GetN();
97 Double_t *x = gr->GetX();
98 Double_t *y = gr->GetY();
dc7ca31d 99
29d3e0eb 100 Double_t *x1 = new Double_t[np];
101 Double_t *y1 = new Double_t[np];
102 for (Int_t ii=0; ii<np; ii++) {
2bcc7817 103 y1[ii]=y[np-ii-1]; x1[ii]=x[np-ii-1];
29d3e0eb 104 }
105
106 TGraph *grInverse = new TGraph(np,y1,x1);
29d3e0eb 107 fAmpLED.AddAtAndExpand(grInverse,i);
12e9daf9 108
109 TGraph* grw = fParam ->GetWalk(i);
110 Int_t npw = grw->GetN();
111 Double_t *yw = grw->GetY();
112 TMath::Sort(npw, yw, index,down);
113 fMaxValue[i]=Int_t(yw[index[0]]);
29d3e0eb 114 }
12e9daf9 115
116 // delete [] x1;
117 // delete [] y1;
dc7ca31d 118}
12e9daf9 119
dc7ca31d 120//------------------------------------------------------------------------
121AliT0Digitizer::~AliT0Digitizer()
122{
123// Destructor
124
125 AliDebug(1,"T0");
126
127 delete ftimeCFD;
128 delete fADC;
129 delete ftimeLED;
130 delete fADC0;
29d3e0eb 131 // delete fAmpLED;
dc7ca31d 132}
133
29d3e0eb 134//------------------------------------------------------------------------
dc7ca31d 135Bool_t AliT0Digitizer::Init()
136{
137// Initialization
138 AliDebug(1," Init");
139 return kTRUE;
140}
141
dc7ca31d 142//---------------------------------------------------------------------
dc7ca31d 143void AliT0Digitizer::Exec(Option_t* /*option*/)
144{
145
146 /*
147 Produde digits from hits
148 digits is TObject and includes
c41ceaac 149 We are writing array if C & A TDC
150 C & A ADC (will need for slow simulation)
151 TOF first particle C & A
dc7ca31d 152 mean time and time difference (vertex position)
153
154 */
155
156 //output loader
157 AliRunLoader *outRL = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
158 AliLoader * pOutStartLoader = outRL->GetLoader("T0Loader");
159
160 AliDebug(1,"start...");
161 //input loader
162 //
163 // From hits to digits
164 //
74adb36a 165 Int_t hit, nhits;
dc7ca31d 166 Int_t countE[24];
167 Int_t volume, pmt, trCFD, trLED;
168 Float_t sl, qt;
c41ceaac 169 Int_t bestATDC, bestCTDC, qtCh;
dc7ca31d 170 Float_t time[24], besttime[24], timeGaus[24] ;
74adb36a 171 //Q->T-> coefficients !!!! should be asked!!!
172 Float_t timeDelayCFD[24];
dc7ca31d 173 Int_t threshold =50; //photoelectrons
174 Float_t zdetA, zdetC;
74adb36a 175 Int_t sumMultCoeff = 100;
740f0839 176 Int_t refpoint=0;
74adb36a 177 TH1F *hr;
c41ceaac 178
dc7ca31d 179
74adb36a 180
29d3e0eb 181 Int_t ph2Mip = fParam->GetPh2Mip();
8955c6b4 182 Float_t channelWidth = fParam->GetChannelWidth() ;
29d3e0eb 183 Float_t delayVertex = fParam->GetTimeDelayTVD();
5325480c 184
29d3e0eb 185 zdetC = TMath::Abs(fParam->GetZPosition("T0/C/PMT1"));
186 zdetA = TMath::Abs(fParam->GetZPosition("T0/A/PMT15"));
74adb36a 187
188 AliT0hit *startHit;
189 TBranch *brHits=0;
190
dc7ca31d 191 Int_t nFiles=fManager->GetNinputs();
192 for (Int_t inputFile=0; inputFile<nFiles; inputFile++) {
193 if (inputFile < nFiles-1) {
74adb36a 194 AliWarning(Form("ignoring input stream %d", inputFile));
195 continue;
196
dc7ca31d 197 }
198
c41ceaac 199 Float_t besttimeC=99999.;
200 Float_t besttimeA=99999.;
201 Int_t pmtBestC=9999;
202 Int_t pmtBestA=9999;
dc7ca31d 203 Int_t timeDiff=999, meanTime=0;
204 Int_t sumMult =0; fSumMult=0;
c41ceaac 205 bestATDC = 99999; bestCTDC = 99999;
dc7ca31d 206
c41ceaac 207
dc7ca31d 208 ftimeCFD -> Reset();
209 fADC -> Reset();
210 fADC0 -> Reset();
211 ftimeLED ->Reset();
212 for (Int_t i0=0; i0<24; i0++)
213 {
214 time[i0]=besttime[i0]=timeGaus[i0]=99999; countE[i0]=0;
215 }
216 AliRunLoader * inRL = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(inputFile));
217 AliLoader * pInStartLoader = inRL->GetLoader("T0Loader");
218 if (!inRL->GetAliRun()) inRL->LoadgAlice();
219 AliT0 *fT0 = (AliT0*)inRL ->GetAliRun()->GetDetector("T0");
220
221 //read Hits
222 pInStartLoader->LoadHits("READ");//probably it is necessary to load them before
223 TClonesArray *fHits = fT0->Hits ();
224 TTree *th = pInStartLoader->TreeH();
225 brHits = th->GetBranch("T0");
226 if (brHits) {
227 fT0->SetHitsAddressBranch(brHits);
228 }else{
229 AliError("Branch T0 hit not found");
230 exit(111);
231 }
232 Int_t ntracks = (Int_t) th->GetEntries();
233
234 if (ntracks<=0) return;
235 // Start loop on tracks in the hits containers
236 for (Int_t track=0; track<ntracks;track++) {
237 brHits->GetEntry(track);
238 nhits = fHits->GetEntriesFast();
239 for (hit=0;hit<nhits;hit++)
240 {
241 startHit = (AliT0hit*) fHits->UncheckedAt(hit);
242 if (!startHit) {
243 AliError("The unchecked hit doesn't exist");
244 break;
245 }
246 pmt=startHit->Pmt();
247 Int_t numpmt=pmt-1;
248 Double_t e=startHit->Etot();
249 volume = startHit->Volume();
250
251 // if(e>0 && RegisterPhotoE(numpmt,e)) {
252 if(e>0 ) {
253 countE[numpmt]++;
254 besttime[numpmt] = startHit->Time();
255 if(besttime[numpmt]<time[numpmt])
256 {
257 time[numpmt]=besttime[numpmt];
258 }
259 } //photoelectron accept
260 } //hits loop
261 } //track loop
262
c41ceaac 263 //spread time A&C by 25ps && besttime
dc7ca31d 264 Float_t c = 0.0299792; // cm/ps
265
266 Float_t koef=(zdetA-zdetC)/c; //correction position difference by cable
267 for (Int_t ipmt=0; ipmt<12; ipmt++){
268 if(countE[ipmt] > threshold) {
269 timeGaus[ipmt]=gRandom->Gaus(time[ipmt],25)+koef;
c41ceaac 270 if(timeGaus[ipmt]<besttimeC){
271 besttimeC=timeGaus[ipmt]; //timeC
272 pmtBestC=ipmt;}
9a5cba6d 273 }
dc7ca31d 274 }
9a5cba6d 275 for ( Int_t ipmt=12; ipmt<24; ipmt++){
dc7ca31d 276 if(countE[ipmt] > threshold) {
277 timeGaus[ipmt]=gRandom->Gaus(time[ipmt],25);
c41ceaac 278 if(timeGaus[ipmt]<besttimeA) {
279 besttimeA=timeGaus[ipmt]; //timeA
280 pmtBestA=ipmt;}
dc7ca31d 281 }
282 }
dc7ca31d 283
6bfb23c3 284 timeDelayCFD[0] = fParam->GetTimeDelayCFD(0);
2de4cb9c 285 Int_t meanTimeDelay=200;
6bfb23c3 286
dc7ca31d 287 for (Int_t i=0; i<24; i++)
288 {
289 Float_t al = countE[i];
290 if (al>threshold && timeGaus[i]<50000 ) {
291 //fill ADC
292 // QTC procedure:
293 // phe -> mV 0.3; 1MIP ->500phe -> ln (amp (mV)) = 5;
294 // max 200ns, HIJING mean 50000phe -> 15000mv -> ln = 15 (s zapasom)
295 // channel 25ps
c41ceaac 296 qt= 50.*al/ph2Mip; // 50mv/Mip amp in mV
dc7ca31d 297 // fill TDC
29d3e0eb 298 timeDelayCFD[i] = fParam->GetTimeDelayCFD(i);
12e9daf9 299 trCFD = Int_t (timeGaus[i]/channelWidth + timeDelayCFD[i]);
29d3e0eb 300 TGraph* gr = ((TGraph*)fAmpLED.At(i));
74adb36a 301 sl = gr->Eval(qt);
29d3e0eb 302
94c27e4f 303 trLED = Int_t(( timeGaus[i] + 1000*sl )/channelWidth);
8955c6b4 304 qtCh=Int_t (1000.*TMath::Log(qt) / channelWidth);
dc7ca31d 305 fADC0->AddAt(0,i);
306 fADC->AddAt(qtCh,i);
dc7ca31d 307 ftimeLED->AddAt(trLED,i);
308 // sumMult += Int_t ((al*gain[i]/ph2Mip)*50) ;
309 sumMult += Int_t (qt/sumMultCoeff) ;
310
74adb36a 311 // put slewing
29d3e0eb 312 TGraph *fu=(TGraph*) fParam ->GetWalk(i) ;
74adb36a 313 Float_t slew=fu->Eval(Float_t(qtCh));
12e9daf9 314
315 trCFD=trCFD-Int_t(fMaxValue[i]-slew);
74adb36a 316 ftimeCFD->AddAt(Int_t (trCFD),i);
317 AliDebug(10,Form(" pmt %i : time in ns %f time in channels %i ",
318 i, timeGaus[i],trCFD ));
319 AliDebug(10,Form(" qt in mV %f qt in ns %f qt in channels %i ",qt,
320 TMath::Log(qt), qtCh));
321
dc7ca31d 322 }
323 } //pmt loop
324
9a5cba6d 325 //folding with alignmentz position distribution
326 if( besttimeC > 10000. && besttimeC <15000)
327 bestCTDC=Int_t ((besttimeC+timeDelayCFD[pmtBestC])
328 /channelWidth);
329
330 if( besttimeA > 10000. && besttimeA <15000)
331 bestATDC=Int_t ((besttimeA+timeDelayCFD[pmtBestA])
332 /channelWidth);
333
334 if (bestATDC < 99999 && bestCTDC < 99999)
335 {
336 timeDiff=Int_t (((besttimeC-besttimeA)+1000*delayVertex)
337 /channelWidth);
2de4cb9c 338 meanTime=Int_t (((besttimeC+besttimeA)/2. + meanTimeDelay)/channelWidth);
9a5cba6d 339 }
340 AliDebug(10,Form(" time A& C %i %i time diff && mean time in channels %i %i",bestATDC,bestCTDC, timeDiff, meanTime));
9a5cba6d 341
dc7ca31d 342 if (sumMult > threshold){
343 fSumMult = Int_t (1000.* TMath::Log(Double_t(sumMult) / Double_t(sumMultCoeff))
344 /channelWidth);
345 AliDebug(10,Form("summult mv %i mult in chammens %i in ps %i ",
346 sumMult, fSumMult, fSumMult*channelWidth));
347 }
dc7ca31d 348
740f0839 349 fT0->AddDigit(bestATDC,bestCTDC,meanTime,timeDiff,fSumMult, refpoint,
c41ceaac 350 ftimeCFD,fADC0,ftimeLED,fADC);
dc7ca31d 351
740f0839 352
353 AliDebug(10,Form(" Digits wrote refpoint %i bestATDC %i bestCTDC %i meanTime %i timeDiff %i fSumMult %i ",refpoint ,bestATDC,bestCTDC,meanTime,timeDiff,fSumMult ));
dc7ca31d 354 pOutStartLoader->UnloadHits();
355 } //input streams loop
356
357 //load digits
358 pOutStartLoader->LoadDigits("UPDATE");
359 TTree *treeD = pOutStartLoader->TreeD();
360 if (treeD == 0x0) {
361 pOutStartLoader->MakeTree("D");
362 treeD = pOutStartLoader->TreeD();
363 }
364 treeD->Reset();
365 fT0 = (AliT0*)outRL ->GetAliRun()->GetDetector("T0");
366 // Make a branch in the tree
367 fT0->MakeBranch("D");
368 treeD->Fill();
369
370 pOutStartLoader->WriteDigits("OVERWRITE");
371
372 fT0->ResetDigits();
373 pOutStartLoader->UnloadDigits();
374
375}