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