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