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