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 **************************************************************************/
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)
27 * Alla.Maevskaya@cern.ch
28 ****************************************************************/
40 #include "AliT0Digitizer.h"
43 #include "AliT0digit.h"
44 #include "AliRunDigitizer.h"
46 #include <AliLoader.h>
47 #include <AliRunLoader.h>
49 #include "AliT0Parameters.h"
51 ClassImp(AliT0Digitizer)
53 //___________________________________________
54 AliT0Digitizer::AliT0Digitizer() :AliDigitizer(),
58 ftimeCFD(new TArrayI(24)),
59 ftimeLED (new TArrayI(24)),
60 fADC(new TArrayI(24)),
61 fADC0 (new TArrayI(24)),
68 // Default ctor - don't use it
72 //___________________________________________
73 AliT0Digitizer::AliT0Digitizer(AliRunDigitizer* manager)
74 :AliDigitizer(manager),
78 ftimeCFD(new TArrayI(24)),
79 ftimeLED (new TArrayI(24)),
80 fADC(new TArrayI(24)),
81 fADC0 (new TArrayI(24)),
86 // ctor which should be used
88 AliDebug(1,"processed");
89 fParam = AliT0Parameters::Instance();
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();
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++) {
103 y1[ii]=y[np-ii-1]; x1[ii]=x[np-ii-1];
106 TGraph *grInverse = new TGraph(np,y1,x1);
107 fAmpLED.AddAtAndExpand(grInverse,i);
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]]);
120 //------------------------------------------------------------------------
121 AliT0Digitizer::~AliT0Digitizer()
134 //------------------------------------------------------------------------
135 Bool_t AliT0Digitizer::Init()
142 //---------------------------------------------------------------------
143 void AliT0Digitizer::Exec(Option_t* /*option*/)
147 Produde digits from hits
148 digits is TObject and includes
149 We are writing array if C & A TDC
150 C & A ADC (will need for slow simulation)
151 TOF first particle C & A
152 mean time and time difference (vertex position)
157 AliRunLoader *outRL = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
158 AliLoader * pOutStartLoader = outRL->GetLoader("T0Loader");
160 AliDebug(1,"start...");
163 // From hits to digits
167 Int_t volume, pmt, trCFD, trLED;
169 Int_t bestATDC, bestCTDC, qtCh;
170 Float_t time[24], besttime[24], timeGaus[24] ;
171 //Q->T-> coefficients !!!! should be asked!!!
172 Float_t timeDelayCFD[24];
173 Int_t threshold =50; //photoelectrons
174 Float_t zdetA, zdetC;
175 Int_t sumMultCoeff = 100;
178 Int_t ph2Mip = fParam->GetPh2Mip();
179 Float_t channelWidth = fParam->GetChannelWidth() ;
180 Float_t delayVertex = fParam->GetTimeDelayTVD();
182 zdetC = TMath::Abs(fParam->GetZPosition("T0/C/PMT1"));
183 zdetA = TMath::Abs(fParam->GetZPosition("T0/A/PMT15"));
188 Int_t nFiles=fManager->GetNinputs();
189 for (Int_t inputFile=0; inputFile<nFiles; inputFile++) {
190 if (inputFile < nFiles-1) {
191 AliWarning(Form("ignoring input stream %d", inputFile));
196 Float_t besttimeC=99999.;
197 Float_t besttimeA=99999.;
200 Int_t timeDiff=999, meanTime=0;
201 Int_t sumMult =0; fSumMult=0;
202 bestATDC = 99999; bestCTDC = 99999;
209 for (Int_t i0=0; i0<24; i0++)
211 time[i0]=besttime[i0]=timeGaus[i0]=99999; countE[i0]=0;
213 AliRunLoader * inRL = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(inputFile));
214 AliLoader * pInStartLoader = inRL->GetLoader("T0Loader");
215 if (!inRL->GetAliRun()) inRL->LoadgAlice();
216 fT0 = (AliT0*)inRL ->GetAliRun()->GetDetector("T0");
219 pInStartLoader->LoadHits("READ");//probably it is necessary to load them before
220 fHits = fT0->Hits ();
221 TTree *th = pInStartLoader->TreeH();
222 brHits = th->GetBranch("T0");
224 fT0->SetHitsAddressBranch(brHits);
226 AliError("Branch T0 hit not found");
229 Int_t ntracks = (Int_t) th->GetEntries();
231 if (ntracks<=0) return;
232 // Start loop on tracks in the hits containers
233 for (Int_t track=0; track<ntracks;track++) {
234 brHits->GetEntry(track);
235 nhits = fHits->GetEntriesFast();
236 for (hit=0;hit<nhits;hit++)
238 startHit = (AliT0hit*) fHits->UncheckedAt(hit);
240 AliError("The unchecked hit doesn't exist");
245 Double_t e=startHit->Etot();
246 volume = startHit->Volume();
248 // if(e>0 && RegisterPhotoE(numpmt,e)) {
251 besttime[numpmt] = startHit->Time();
252 if(besttime[numpmt]<time[numpmt])
254 time[numpmt]=besttime[numpmt];
256 } //photoelectron accept
260 //spread time A&C by 25ps && besttime
261 Float_t c = 0.0299792; // cm/ps
263 Float_t koef=(zdetA-zdetC)/c; //correction position difference by cable
264 for (Int_t ipmt=0; ipmt<12; ipmt++){
265 if(countE[ipmt] > threshold) {
266 timeGaus[ipmt]=gRandom->Gaus(time[ipmt],25)+koef;
267 if(timeGaus[ipmt]<besttimeC){
268 besttimeC=timeGaus[ipmt]; //timeC
272 for ( Int_t ipmt=12; ipmt<24; ipmt++){
273 if(countE[ipmt] > threshold) {
274 timeGaus[ipmt]=gRandom->Gaus(time[ipmt],25);
275 if(timeGaus[ipmt]<besttimeA) {
276 besttimeA=timeGaus[ipmt]; //timeA
281 timeDelayCFD[0] = fParam->GetTimeDelayCFD(0);
283 for (Int_t i=0; i<24; i++)
285 Float_t al = countE[i];
286 if (al>threshold && timeGaus[i]<50000 ) {
289 // phe -> mV 0.3; 1MIP ->500phe -> ln (amp (mV)) = 5;
290 // max 200ns, HIJING mean 50000phe -> 15000mv -> ln = 15 (s zapasom)
292 qt= 50.*al/ph2Mip; // 50mv/Mip amp in mV
294 timeDelayCFD[i] = fParam->GetTimeDelayCFD(i);
295 trCFD = Int_t (timeGaus[i]/channelWidth + timeDelayCFD[i]);
296 TGraph* gr = ((TGraph*)fAmpLED.At(i));
299 trLED = Int_t(( timeGaus[i] + 1000*sl )/channelWidth);
300 qtCh=Int_t (1000.*TMath::Log(qt) / channelWidth);
303 ftimeLED->AddAt(trLED,i);
304 // sumMult += Int_t ((al*gain[i]/ph2Mip)*50) ;
305 sumMult += Int_t (qt/sumMultCoeff) ;
308 TGraph *fu=(TGraph*) fParam ->GetWalk(i) ;
309 Float_t slew=fu->Eval(Float_t(qtCh));
311 // trCFD=trCFD-Int_t(fMaxValue[i]-slew);
312 trCFD = trCFD-Int_t(fMaxValue[i]-slew) + 2000; //for the same channel as cosmic
313 ftimeCFD->AddAt(Int_t (trCFD),i);
314 AliDebug(10,Form(" pmt %i : time in ns %f time in channels %i LEd %i ", i, timeGaus[i],trCFD, trLED ));
315 AliDebug(10,Form(" qt in mV %f qt in ns %f qt in channels %i ",qt,
316 TMath::Log(qt), qtCh));
321 //folding with alignmentz position distribution
322 if( besttimeC > 10000. && besttimeC <15000)
323 bestCTDC=Int_t ((besttimeC+timeDelayCFD[pmtBestC])
326 if( besttimeA > 10000. && besttimeA <15000)
327 bestATDC=Int_t ((besttimeA+timeDelayCFD[pmtBestA])
330 if (bestATDC < 99999 && bestCTDC < 99999)
332 timeDiff=Int_t (((besttimeC-besttimeA)+1000*delayVertex)
334 meanTime=Int_t (((besttimeC+besttimeA)/2. )/channelWidth);
336 AliDebug(10,Form(" time A& C %i %i time diff && mean time in channels %i %i",bestATDC,bestCTDC, timeDiff, meanTime));
338 if (sumMult > threshold){
339 fSumMult = Int_t (1000.* TMath::Log(Double_t(sumMult) / Double_t(sumMultCoeff))
341 AliDebug(10,Form("summult mv %i mult in chammens %i in ps %i ",
342 sumMult, fSumMult, fSumMult*channelWidth));
345 fT0->AddDigit(bestATDC,bestCTDC,meanTime,timeDiff,fSumMult, refpoint,
346 ftimeCFD,fADC0,ftimeLED,fADC);
349 AliDebug(10,Form(" Digits wrote refpoint %i bestATDC %i bestCTDC %i meanTime %i timeDiff %i fSumMult %i ",refpoint ,bestATDC,bestCTDC,meanTime,timeDiff,fSumMult ));
350 pOutStartLoader->UnloadHits();
351 } //input streams loop
354 pOutStartLoader->LoadDigits("UPDATE");
355 TTree *treeD = pOutStartLoader->TreeD();
357 pOutStartLoader->MakeTree("D");
358 treeD = pOutStartLoader->TreeD();
361 fT0 = (AliT0*)outRL ->GetAliRun()->GetDetector("T0");
362 // Make a branch in the tree
363 fT0->MakeBranch("D");
366 pOutStartLoader->WriteDigits("OVERWRITE");
369 pOutStartLoader->UnloadDigits();