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)),
69 // Default ctor - don't use it
73 //___________________________________________
74 AliT0Digitizer::AliT0Digitizer(AliRunDigitizer* manager)
75 :AliDigitizer(manager),
79 ftimeCFD(new TArrayI(24)),
80 ftimeLED (new TArrayI(24)),
81 fADC(new TArrayI(24)),
82 fADC0 (new TArrayI(24)),
88 // ctor which should be used
90 AliDebug(1,"processed");
91 fParam = AliT0Parameters::Instance();
94 for (Int_t i=0; i<24; i++){
95 TGraph* gr = fParam ->GetAmpLED(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++) {
107 TGraph *grInverse = new TGraph(np,y1,x1);
108 fAmpLED.AddAtAndExpand(grInverse,i);
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++) {
121 TGraph *grInverseQTC = new TGraph(npq,y1q,x1q);
122 fAmpQTC.AddAtAndExpand(grInverseQTC,i);
126 //------------------------------------------------------------------------
127 AliT0Digitizer::~AliT0Digitizer()
140 //------------------------------------------------------------------------
141 Bool_t AliT0Digitizer::Init()
148 //---------------------------------------------------------------------
149 void AliT0Digitizer::Exec(Option_t* /*option*/)
153 Produde digits from hits
154 digits is TObject and includes
155 We are writing array if C & A TDC
156 C & A ADC (will need for slow simulation)
157 TOF first particle C & A
158 mean time and time difference (vertex position)
163 AliRunLoader *outRL = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
164 AliLoader * pOutStartLoader = outRL->GetLoader("T0Loader");
166 AliDebug(1,"start...");
169 // From hits to digits
173 Int_t volume, pmt, trCFD, trLED;
178 Float_t time[24], besttime[24], timeGaus[24] ;
179 //Q->T-> coefficients !!!! should be asked!!!
180 Float_t timeDelayCFD[24];
181 Int_t threshold =50; //photoelectrons
182 Float_t zdetA, zdetC;
183 Int_t sumMultCoeff = 100;
186 Int_t ph2Mip = fParam->GetPh2Mip();
187 Float_t channelWidth = fParam->GetChannelWidth() ;
188 Float_t delayVertex = fParam->GetTimeDelayTVD();
191 zdetC = TMath::Abs(fParam->GetZPosition("T0/C/PMT1"));
192 zdetA = TMath::Abs(fParam->GetZPosition("T0/A/PMT15"));
194 // printf(" !!!!!Z det A = %f C = % f",zdetA,zdetC);
198 Int_t nFiles=fManager->GetNinputs();
199 for (Int_t inputFile=0; inputFile<nFiles; inputFile++) {
200 if (inputFile < nFiles-1) {
201 AliWarning(Form("ignoring input stream %d", inputFile));
206 Float_t besttimeC=99999.;
207 Float_t besttimeA=99999.;
208 Int_t pmtBestC=99999;
209 Int_t pmtBestA=99999;
210 Int_t timeDiff=99999, meanTime=99999;
211 Int_t sumMult =0; fSumMult=0;
212 bestATDC = 99999; bestCTDC = 99999;
219 for (Int_t i0=0; i0<24; i0++)
221 time[i0]=besttime[i0]=timeGaus[i0]=999999; countE[i0]=0;
223 AliRunLoader * inRL = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(inputFile));
224 AliLoader * pInStartLoader = inRL->GetLoader("T0Loader");
225 if (!inRL->GetAliRun()) inRL->LoadgAlice();
226 fT0 = (AliT0*)inRL ->GetAliRun()->GetDetector("T0");
229 pInStartLoader->LoadHits("READ");//probably it is necessary to load them before
230 fHits = fT0->Hits ();
231 TTree *th = pInStartLoader->TreeH();
232 brHits = th->GetBranch("T0");
234 fT0->SetHitsAddressBranch(brHits);
236 AliWarning("Branch T0 hit not found for this event");
237 // fT0->AddDigit(bestATDC,bestCTDC,meanTime,timeDiff,fSumMult, refpoint,
238 // ftimeCFD,fADC0,ftimeLED,fADC);
241 Int_t ntracks = (Int_t) th->GetEntries();
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++)
250 startHit = (AliT0hit*) fHits->UncheckedAt(hit);
252 AliError("The unchecked hit doesn't exist");
257 Double_t e=startHit->Etot();
258 volume = startHit->Volume();
262 besttime[numpmt] = startHit->Time();
263 if(besttime[numpmt]<time[numpmt])
265 time[numpmt]=besttime[numpmt];
267 } //photoelectron accept
271 //spread time A&C by 25ps && besttime
272 Float_t c = 0.0299792; // cm/ps
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;
278 if(timeGaus[ipmt]<besttimeC){
279 besttimeC=timeGaus[ipmt]; //timeC
283 for ( Int_t ipmt=12; ipmt<24; ipmt++){
284 if(countE[ipmt] > threshold) {
285 timeGaus[ipmt]=gRandom->Gaus(time[ipmt],25);
286 if(timeGaus[ipmt]<besttimeA) {
287 besttimeA=timeGaus[ipmt]; //timeA
292 timeDelayCFD[0] = fParam->GetTimeDelayCFD(0);
294 for (Int_t i=0; i<24; i++)
296 Float_t al = countE[i];
297 if (al>threshold && timeGaus[i]<50000 ) {
300 // phe -> mV 0.3; 1MIP ->500phe -> ln (amp (mV)) = 5;
301 // max 200ns, HIJING mean 50000phe -> 15000mv -> ln = 15 (s zapasom)
303 qt= al/ph2Mip; // 50mv/Mip amp in mV
304 // before will we have calibration for high multiplicity
305 // if (qt > 115.) qt =115.; //must be fix!!!
307 timeDelayCFD[i] = fParam->GetTimeDelayCFD(i);
308 trCFD = Int_t (timeGaus[i]/channelWidth + timeDelayCFD[i]);
310 TGraph* gr = ((TGraph*)fAmpLED.At(i));
313 TGraph* gr1 = ((TGraph*)fAmpQTC.At(i));
314 qtCh = gr1->Eval(qt);
318 // sumMult += Int_t ((al*gain[i]/ph2Mip)*50) ;
319 sumMult += Int_t (qtCh/sumMultCoeff) ;
322 TGraph *fu=(TGraph*) fParam ->GetWalk(i);
323 Float_t slew=fu->Eval(Float_t(qtCh));
325 // trCFD=trCFD-Int_t(fMaxValue[i]-slew);
326 trCFD = trCFD + slew; //for the same channel as cosmic
327 ftimeCFD->AddAt(Int_t (trCFD),i);
328 trLED = Int_t(trCFD + sl );
329 ftimeLED->AddAt(trLED,i);
330 AliDebug(10,Form(" pmt %i : time in ns %f time in channels %i LEd %i ", i, timeGaus[i],trCFD, trLED ));
331 AliDebug(10,Form(" qt in MIP %f led-cfd in %f qt in channels %f ",qt, sl, qtCh));
336 //folding with alignmentz position distribution
337 if( besttimeC > 10000. && besttimeC <15000)
338 bestCTDC=Int_t ((besttimeC+timeDelayCFD[pmtBestC])
341 if( besttimeA > 10000. && besttimeA <15000)
342 bestATDC=Int_t ((besttimeA+timeDelayCFD[pmtBestA])
345 if (bestATDC < 99999 && bestCTDC < 99999)
347 timeDiff=Int_t (((besttimeC-besttimeA)+1000*delayVertex)
349 meanTime=Int_t (((besttimeC+besttimeA)/2. )/channelWidth);
352 if (sumMult > threshold){
353 fSumMult = Int_t (1000.* TMath::Log(Double_t(sumMult) / Double_t(sumMultCoeff))
355 AliDebug(10,Form("summult mv %i mult in chammens %i in ps %i ",
356 sumMult, fSumMult, fSumMult*channelWidth));
359 fT0->AddDigit(bestATDC,bestCTDC,meanTime,timeDiff,fSumMult, refpoint,
360 ftimeCFD,fADC0,ftimeLED,fADC);
363 AliDebug(10,Form(" Digits wrote refpoint %i bestATDC %i bestCTDC %i meanTime %i timeDiff %i fSumMult %i ",refpoint ,bestATDC,bestCTDC,meanTime,timeDiff,fSumMult ));
364 pOutStartLoader->UnloadHits();
365 } //input streams loop
368 pOutStartLoader->LoadDigits("UPDATE");
369 TTree *treeD = pOutStartLoader->TreeD();
371 pOutStartLoader->MakeTree("D");
372 treeD = pOutStartLoader->TreeD();
375 fT0 = (AliT0*)outRL ->GetAliRun()->GetDetector("T0");
376 // Make a branch in the tree
377 fT0->MakeBranch("D");
380 pOutStartLoader->WriteDigits("OVERWRITE");
383 pOutStartLoader->UnloadDigits();