2 /**************************************************************************
3 * Copyright(c) 1998-2000, ALICE Experiment at CERN, All rights reserved. *
5 * Author: The ALICE Off-line Project. *
6 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
20 #include <TDirectory.h>
30 #include "AliT0Digitizer.h"
33 #include "AliT0digit.h"
34 #include "AliRunDigitizer.h"
35 #include <AliDetector.h>
37 #include <AliLoader.h>
38 #include <AliRunLoader.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"
48 ClassImp(AliT0Digitizer)
50 //___________________________________________
51 AliT0Digitizer::AliT0Digitizer() :AliDigitizer(),
55 ftimeCFD(new TArrayI(24)),
56 ftimeLED (new TArrayI(24)),
57 fADC(new TArrayI(24)),
58 fADC0 (new TArrayI(24)),
65 // Default ctor - don't use it
69 //___________________________________________
70 AliT0Digitizer::AliT0Digitizer(AliRunDigitizer* manager)
71 :AliDigitizer(manager),
75 ftimeCFD(new TArrayI(24)),
76 ftimeLED (new TArrayI(24)),
77 fADC(new TArrayI(24)),
78 fADC0 (new TArrayI(24)),
82 // ctor which should be used
84 AliDebug(1,"processed");
89 //------------------------------------------------------------------------
90 AliT0Digitizer::~AliT0Digitizer()
102 //------------------------------------------------------------------------
103 Bool_t AliT0Digitizer::Init()
111 //---------------------------------------------------------------------
113 void AliT0Digitizer::Exec(Option_t* /*option*/)
117 Produde digits from hits
118 digits is TObject and includes
119 We are writing array if C & A TDC
120 C & A ADC (will need for slow simulation)
121 TOF first particle C & A
122 mean time and time difference (vertex position)
127 AliRunLoader *outRL = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
128 AliLoader * pOutStartLoader = outRL->GetLoader("T0Loader");
130 AliDebug(1,"start...");
133 // From hits to digits
137 Int_t volume, pmt, trCFD, trLED;
139 Int_t bestATDC, bestCTDC, qtCh;
140 Float_t time[24], besttime[24], timeGaus[24] ;
141 //Q->T-> coefficients !!!! should be asked!!!
142 Float_t timeDelayCFD[24], timeDelayLED[24];
143 Int_t threshold =50; //photoelectrons
144 Float_t zdetA, zdetC;
145 Int_t sumMultCoeff = 100;
146 TObjArray slewingLED;
150 AliT0Parameters* param = AliT0Parameters::Instance();
153 Int_t ph2Mip = param->GetPh2Mip();
154 Int_t channelWidth = param->GetChannelWidth() ;
155 Float_t delayVertex = param->GetTimeDelayTVD();
156 for (Int_t i=0; i<24; i++){
157 timeDelayCFD[i] = param->GetTimeDelayCFD(i);
158 timeDelayLED[i] = param->GetTimeDelayLED(i);
159 TGraph* gr = param ->GetSlew(i);
160 slewingLED.AddAtAndExpand(gr,i);
162 TGraph* fu = param ->GetWalk(i);
163 walk.AddAtAndExpand(fu,i);
165 TGraph* grEff = param ->GetPMTeff(i);
166 fEffPMT.AddAtAndExpand(grEff,i);
170 zdetC = TMath::Abs(param->GetZPosition("T0/C/PMT1"));
171 zdetA = TMath::Abs(param->GetZPosition("T0/A/PMT15"));
176 Int_t nFiles=fManager->GetNinputs();
177 for (Int_t inputFile=0; inputFile<nFiles; inputFile++) {
178 if (inputFile < nFiles-1) {
179 AliWarning(Form("ignoring input stream %d", inputFile));
184 Float_t besttimeC=99999.;
185 Float_t besttimeA=99999.;
188 Int_t timeDiff=999, meanTime=0;
189 Int_t sumMult =0; fSumMult=0;
190 bestATDC = 99999; bestCTDC = 99999;
197 for (Int_t i0=0; i0<24; i0++)
199 time[i0]=besttime[i0]=timeGaus[i0]=99999; countE[i0]=0;
201 AliRunLoader * inRL = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(inputFile));
202 AliLoader * pInStartLoader = inRL->GetLoader("T0Loader");
203 if (!inRL->GetAliRun()) inRL->LoadgAlice();
204 AliT0 *fT0 = (AliT0*)inRL ->GetAliRun()->GetDetector("T0");
207 pInStartLoader->LoadHits("READ");//probably it is necessary to load them before
208 TClonesArray *fHits = fT0->Hits ();
209 TTree *th = pInStartLoader->TreeH();
210 brHits = th->GetBranch("T0");
212 fT0->SetHitsAddressBranch(brHits);
214 AliError("Branch T0 hit not found");
217 Int_t ntracks = (Int_t) th->GetEntries();
219 if (ntracks<=0) return;
220 // Start loop on tracks in the hits containers
221 for (Int_t track=0; track<ntracks;track++) {
222 brHits->GetEntry(track);
223 nhits = fHits->GetEntriesFast();
224 for (hit=0;hit<nhits;hit++)
226 startHit = (AliT0hit*) fHits->UncheckedAt(hit);
228 AliError("The unchecked hit doesn't exist");
233 Double_t e=startHit->Etot();
234 volume = startHit->Volume();
236 // if(e>0 && RegisterPhotoE(numpmt,e)) {
239 besttime[numpmt] = startHit->Time();
240 if(besttime[numpmt]<time[numpmt])
242 time[numpmt]=besttime[numpmt];
244 } //photoelectron accept
248 //spread time A&C by 25ps && besttime
249 Float_t c = 0.0299792; // cm/ps
251 Float_t koef=(zdetA-zdetC)/c; //correction position difference by cable
252 for (Int_t ipmt=0; ipmt<12; ipmt++){
253 if(countE[ipmt] > threshold) {
254 timeGaus[ipmt]=gRandom->Gaus(time[ipmt],25)+koef;
255 if(timeGaus[ipmt]<besttimeC){
256 besttimeC=timeGaus[ipmt]; //timeC
260 for ( Int_t ipmt=12; ipmt<24; ipmt++){
261 if(countE[ipmt] > threshold) {
262 timeGaus[ipmt]=gRandom->Gaus(time[ipmt],25);
263 if(timeGaus[ipmt]<besttimeA) {
264 besttimeA=timeGaus[ipmt]; //timeA
268 //folding with alignmentz position distribution
269 if( besttimeC > 10000. && besttimeC <15000)
270 bestCTDC=Int_t ((besttimeC+timeDelayCFD[pmtBestC])
273 if( besttimeA > 10000. && besttimeA <15000)
274 bestATDC=Int_t ((besttimeA+timeDelayCFD[pmtBestA])
277 if (bestATDC < 99999 && bestCTDC < 99999)
279 timeDiff=Int_t (((besttimeC-besttimeA)+1000*delayVertex)
281 meanTime=Int_t (((besttimeC+timeDelayCFD[pmtBestC]+
282 besttimeA+timeDelayCFD[pmtBestA])/2.)
285 AliDebug(10,Form(" time A& C %i %i time diff && mean time in channels %i %i",bestATDC,bestCTDC, timeDiff, meanTime));
286 for (Int_t i=0; i<24; i++)
288 Float_t al = countE[i];
289 if (al>threshold && timeGaus[i]<50000 ) {
292 // phe -> mV 0.3; 1MIP ->500phe -> ln (amp (mV)) = 5;
293 // max 200ns, HIJING mean 50000phe -> 15000mv -> ln = 15 (s zapasom)
295 qt= 50.*al/ph2Mip; // 50mv/Mip amp in mV
297 trCFD = Int_t (timeGaus[i]/channelWidth + (timeDelayCFD[i]-timeDelayCFD[0]));
298 trLED= Int_t (timeGaus[i] + timeDelayLED[i]);
299 sl = ((TGraph*)slewingLED.At(i))->Eval(qt);
300 trLED = Int_t(( trLED + 1000*sl )/channelWidth);
301 qtCh=Int_t (1000.*TMath::Log(qt)) / channelWidth;
304 ftimeLED->AddAt(trLED,i);
305 // sumMult += Int_t ((al*gain[i]/ph2Mip)*50) ;
306 sumMult += Int_t (qt/sumMultCoeff) ;
308 AliDebug(10,Form(" pmt %i : time in ns %f time in channels %i ",
309 i, timeGaus[i],trCFD ));
310 AliDebug(10,Form(" qt in mV %f qt in ns %f qt in channels %i ",qt,
311 TMath::Log(qt), qtCh));
313 TGraph *fu1=(TGraph*) walk.At(i);
314 Float_t slew=fu1->Eval(Float_t(qtCh));
315 hr=fu1->GetHistogram();
316 Float_t maxValue=hr->GetMaximum(50);
317 trCFD=trCFD-Int_t((maxValue-slew)/channelWidth);
318 ftimeCFD->AddAt(Int_t (trCFD),i);
322 if (sumMult > threshold){
323 fSumMult = Int_t (1000.* TMath::Log(Double_t(sumMult) / Double_t(sumMultCoeff))
325 AliDebug(10,Form("summult mv %i mult in chammens %i in ps %i ",
326 sumMult, fSumMult, fSumMult*channelWidth));
329 fT0->AddDigit(bestATDC,bestCTDC,meanTime,timeDiff,fSumMult,
330 ftimeCFD,fADC0,ftimeLED,fADC);
332 AliDebug(10,Form(" Digits wrote bestATDC %i bestCTDC %i meanTime %i timeDiff %i fSumMult %i ", bestATDC,bestCTDC,meanTime,timeDiff,fSumMult ));
333 pOutStartLoader->UnloadHits();
334 } //input streams loop
337 pOutStartLoader->LoadDigits("UPDATE");
338 TTree *treeD = pOutStartLoader->TreeD();
340 pOutStartLoader->MakeTree("D");
341 treeD = pOutStartLoader->TreeD();
344 fT0 = (AliT0*)outRL ->GetAliRun()->GetDetector("T0");
345 // Make a branch in the tree
346 fT0->MakeBranch("D");
349 pOutStartLoader->WriteDigits("OVERWRITE");
352 pOutStartLoader->UnloadDigits();