1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 ///_________________________________________________________________________
20 /// This class constructs Digits out of Hits
24 // --- Standard library ---
26 // --- ROOT system ---
30 #include <TGeoManager.h>
31 #include <TGeoPhysicalNode.h>
32 #include <AliGeomManager.h>
37 // --- AliRoot header files ---
40 #include "AliVZEROhit.h"
41 #include "AliRunLoader.h"
42 #include "AliLoader.h"
43 #include "AliGRPObject.h"
44 #include "AliRunDigitizer.h"
45 #include "AliCDBManager.h"
46 #include "AliCDBStorage.h"
47 #include "AliCDBEntry.h"
48 #include "AliVZEROCalibData.h"
49 #include "AliCTPTimeParams.h"
50 #include "AliVZEROdigit.h"
51 #include "AliVZERODigitizer.h"
52 #include "AliVZEROSDigit.h"
54 ClassImp(AliVZERODigitizer)
56 AliVZERODigitizer::AliVZERODigitizer()
58 fCalibData(GetCalibData()),
59 fPhotoCathodeEfficiency(0.18),
64 fSinglePhESpectrum(NULL),
69 // default constructor
70 // Initialize OCDB and containers used in the digitization
75 //____________________________________________________________________________
76 AliVZERODigitizer::AliVZERODigitizer(AliVZERO *vzero, DigiTask_t task)
78 fCalibData(GetCalibData()),
79 fPhotoCathodeEfficiency(0.18),
84 fSinglePhESpectrum(NULL),
90 // Initialize OCDB and containers used in the digitization
95 //____________________________________________________________________________
96 AliVZERODigitizer::AliVZERODigitizer(AliRunDigitizer* manager)
97 :AliDigitizer(manager),
98 fCalibData(GetCalibData()),
99 fPhotoCathodeEfficiency(0.18),
104 fSinglePhESpectrum(NULL),
110 // Initialize OCDB and containers used in the digitization
115 //____________________________________________________________________________
116 AliVZERODigitizer::~AliVZERODigitizer()
134 if (fSinglePhESpectrum) {
135 delete fSinglePhESpectrum;
136 fSinglePhESpectrum = NULL;
139 for(Int_t i = 0 ; i < 64; ++i) {
140 if (fTime[i]) delete [] fTime[i];
144 //_____________________________________________________________________________
145 Bool_t AliVZERODigitizer::Init()
147 // Initialises the digitizer
148 // Initialize OCDB and containers used in the digitization
150 // check if the digitizer was already initialized
151 if (fSignalShape) return kTRUE;
153 fSignalShape = new TF1("VZEROSignalShape",this,&AliVZERODigitizer::SignalShape,0,200,6,"AliVZERODigitizer","SignalShape");
154 // fSignalShape->SetParameters(0,1.57345e1,-4.25603e-1,2.9,6.40982,3.69339e-01);
155 // fSignalShape->SetParameters(1.34330e+00,1.13007e+02,-4.95705e-01,
156 // 3.68911e+00,1.01040e+00, 3.94675e-01);
157 fSignalShape->SetParameters(-1.07335e+00,2.16002e+01,-1.26133e-01,
158 1.41619e+00,5.50334e-01,3.86111e-01);
159 fPMResponse = new TF1("VZEROPMResponse",this,&AliVZERODigitizer::PMResponse,-kPMRespTime,2.*kPMRespTime,0,"AliVZERODigitizer","PMResponse");
160 fSinglePhESpectrum = new TF1("VZEROSinglePhESpectrum",this,&AliVZERODigitizer::SinglePhESpectrum,0,20,0,"AliVZERODigitizer","SinglePhESpectrum");
162 // Now get the CTP L0->L1 delay
163 AliCDBEntry *entry = AliCDBManager::Instance()->Get("GRP/CTP/CTPtiming");
164 if (!entry) AliFatal("CTP timing parameters are not found in OCDB !");
165 AliCTPTimeParams *ctpParams = (AliCTPTimeParams*)entry->GetObject();
166 Float_t l1Delay = (Float_t)ctpParams->GetDelayL1L0()*25.0;
168 AliCDBEntry *entry1 = AliCDBManager::Instance()->Get("GRP/CTP/TimeAlign");
169 if (!entry1) AliFatal("CTP time-alignment is not found in OCDB !");
170 AliCTPTimeParams *ctpTimeAlign = (AliCTPTimeParams*)entry1->GetObject();
171 l1Delay += ((Float_t)ctpTimeAlign->GetDelayL1L0()*25.0);
173 AliCDBEntry *entry2 = AliCDBManager::Instance()->Get("VZERO/Calib/TimeDelays");
174 if (!entry2) AliFatal("VZERO time delays are not found in OCDB !");
175 TH1F *delays = (TH1F*)entry2->GetObject();
177 for(Int_t i = 0 ; i < 64; ++i) {
179 for(Int_t j = 0; j < kNClocks; ++j) fAdc[i][j] = 0;
180 fLeadingTime[i] = fTimeWidth[i] = 0;
182 fPmGain[i] = fCalibData->GetGain(i);
184 fAdcPedestal[i][0] = fCalibData->GetPedestal(i);
185 fAdcSigma[i][0] = fCalibData->GetSigma(i);
186 fAdcPedestal[i][1] = fCalibData->GetPedestal(i+64);
187 fAdcSigma[i][1] = fCalibData->GetSigma(i+64);
189 Int_t board = AliVZEROCalibData::GetBoardNumber(i);
190 fNBins[i] = TMath::Nint(((Float_t)(fCalibData->GetMatchWindow(board)+1)*25.0+
191 (Float_t)kMaxTDCWidth*fCalibData->GetWidthResolution(board))/
192 fCalibData->GetTimeResolution(board));
193 fNBinsLT[i] = TMath::Nint(((Float_t)(fCalibData->GetMatchWindow(board)+1)*25.0)/
194 fCalibData->GetTimeResolution(board));
195 fBinSize[i] = fCalibData->GetTimeResolution(board);
196 fHptdcOffset[i] = (((Float_t)fCalibData->GetTriggerCountOffset(board)-
197 (Float_t)fCalibData->GetRollOver(board))*25.0+
198 fCalibData->GetTimeOffset(i)-
200 delays->GetBinContent(i+1)+
203 fTime[i] = new Float_t[fNBins[i]];
204 memset(fTime[i],0,fNBins[i]*sizeof(Float_t));
210 //____________________________________________________________________________
211 void AliVZERODigitizer::Exec(Option_t* /*option*/)
213 // Creates digits from hits
216 if (fVZERO && !fManager) {
217 AliLoader *loader = fVZERO->GetLoader();
219 AliError("Can not get VZERO Loader via AliVZERO object!");
222 AliRunLoader* runLoader = AliRunLoader::Instance();
223 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); ++iEvent) {
224 runLoader->GetEvent(iEvent);
225 if (fTask == kHits2Digits) {
232 WriteSDigits(loader);
239 AliRunLoader *currentLoader = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
240 AliLoader *loader = currentLoader->GetLoader("VZEROLoader");
242 AliError("Cannot get VZERO Loader via RunDigitizer!");
248 AliFatal("Invalid digitization task! Exiting!");
252 //____________________________________________________________________________
253 void AliVZERODigitizer::AddDigit(Int_t pmnumber, Float_t time, Float_t width, Bool_t integrator, Short_t *chargeADC, Int_t *labels)
258 TClonesArray &ldigits = *fDigits;
260 new(ldigits[fNdigits++]) AliVZEROdigit(pmnumber,time,width,integrator,chargeADC,labels);
263 //____________________________________________________________________________
264 void AliVZERODigitizer::AddSDigit(Int_t pmnumber, Int_t nbins, Float_t *charges, Int_t *labels)
269 TClonesArray &ldigits = *fDigits;
271 new(ldigits[fNdigits++]) AliVZEROSDigit(pmnumber,nbins,charges,labels);
274 //____________________________________________________________________________
275 void AliVZERODigitizer::ResetDigits()
281 if (fDigits) fDigits->Clear();
284 //____________________________________________________________________________
285 AliVZEROCalibData* AliVZERODigitizer::GetCalibData() const
288 AliCDBManager *man = AliCDBManager::Instance();
290 AliCDBEntry *entry=0;
292 entry = man->Get("VZERO/Calib/Data");
295 // AliWarning("Load of calibration data from default storage failed!");
296 // AliWarning("Calibration data will be loaded from local storage ($ALICE_ROOT)");
297 // Int_t runNumber = man->GetRun();
298 // entry = man->GetStorage("local://$ALICE_ROOT/OCDB")
299 // ->Get("VZERO/Calib/Data",runNumber);
303 // Retrieval of data in directory VZERO/Calib/Data:
306 AliVZEROCalibData *calibdata = 0;
308 if (entry) calibdata = (AliVZEROCalibData*) entry->GetObject();
309 if (!calibdata) AliFatal("No calibration data from calibration database !");
315 double AliVZERODigitizer::SignalShape(double *x, double *par)
317 // this function simulates the time
318 // of arrival of the photons at the
321 if (xx <= par[0]) return 0;
322 Double_t a = 1./TMath::Power((xx-par[0])/par[1],1./par[2]);
323 if (xx <= par[3]) return a;
324 Double_t b = 1./TMath::Power((xx-par[3])/par[4],1./par[5]);
325 Double_t f = a*b/(a+b);
326 AliDebug(100,Form("x=%f func=%f",xx,f));
330 double AliVZERODigitizer::PMResponse(double *x, double * /* par */)
332 // this function describes the
333 // PM time response to a single
335 Double_t xx = x[0]+kPMRespTime;
336 return xx*xx*TMath::Exp(-xx*xx/(kPMRespTime*kPMRespTime));
339 double AliVZERODigitizer::SinglePhESpectrum(double *x, double * /* par */)
341 // this function describes the
342 // PM amplitude response to a single
345 if (xx < 0) return 0;
346 return (TMath::Poisson(xx,kPMNbOfSecElec)+kPMTransparency*TMath::Poisson(xx,1.0));
349 Int_t AliVZERODigitizer::Cell2Pmt(Int_t cell) const
351 // The method maps the scintillator
352 // indexes to the PM ones
353 if (cell < 0 || cell >= 80) {
354 AliError(Form("Wrong VZERO cell index %d",cell));
357 if (cell < 16) return cell;
358 if (cell < 48) return 8 + cell/2;
362 void AliVZERODigitizer::DigitizeHits()
364 // Digitize the hits to the level of
365 // SDigits (fTime arrays)
367 for(Int_t i = 0 ; i < 64; ++i) {
368 memset(fTime[i],0,fNBins[i]*sizeof(Float_t));
369 fLabels[i][0] = fLabels[i][1] = fLabels[i][2] = -1;
371 Float_t integral = fPMResponse->Integral(-kPMRespTime,2.*kPMRespTime);
372 Float_t meansPhE = fSinglePhESpectrum->Mean(0,20);
374 AliLoader* loader = fVZERO->GetLoader();
376 AliError("Can not get VZERO Loader!");
380 TTree* treeH = loader->TreeH();
382 AliError("Cannot get TreeH!");
385 TClonesArray* hits = fVZERO->Hits();
387 // Float_t lightYieldCorr[64] = {0.00707,0.00517,0.00520,0.00537,0.00735,0.00537,0.00733,0.00605,0.00778,0.00749,0.00701,0.00755,0.00732,0.00617,0.00669,0.00525,0.00752,0.00820,0.00797,0.01107,0.01080,0.00889,0.00880,0.01712,0.00866,0.00701,0.00811,0.00602,0.00879,0.00821,0.00861,0.01433,0.00061,0.00032,0.00099,0.00061,0.00034,0.00046,0.00031,0.00122,0.00155,0.00091,0.00032,0.00096,0.00120,0.00067,0.00113,0.00060,0.00158,0.00136,0.00340,0.00066,0.00076,0.00119,0.00129,0.00147,0.00137,0.00117,0.00088,0.00164,0.00128,0.00081,0.00121,0.00250};
388 Float_t lightYieldCorr[64] = {0.01173,0.00874,0.00878,0.00886,0.01151,0.00925,0.01167,0.00983,0.01181,0.01243,0.01115,0.01220,0.01228,0.01053,0.01021,0.00930,0.01270,0.01411,0.01316,0.01894,0.01923,0.01860,0.01738,0.00305,0.01584,0.01251,0.01344,0.00310,0.01302,0.01266,0.01407,0.00338,0.00089,0.00100,0.00130,0.00081,0.00052,0.01230,0.00059,0.02452,0.02980,0.00137,0.01421,0.00116,0.00141,0.00092,0.02480,0.00096,0.00182,0.00174,0.00218,0.00106,0.00116,0.00160,0.00162,0.03097,0.00194,0.00171,0.00132,0.00239,0.00173,0.00118,0.00163,0.00262};
389 // Now makes Digits from hits
390 Int_t nTracks = (Int_t) treeH->GetEntries();
391 for (Int_t iTrack = 0; iTrack < nTracks; iTrack++) {
393 treeH->GetEvent(iTrack);
394 Int_t nHits = hits->GetEntriesFast();
395 for (Int_t iHit = 0; iHit < nHits; iHit++) {
396 AliVZEROhit* hit = (AliVZEROhit *)hits->UncheckedAt(iHit);
397 Int_t nPhot = hit->Nphot();
398 Int_t cell = hit->Cell();
399 Int_t pmt = Cell2Pmt(cell);
400 Int_t trackLabel = hit->GetTrack();
401 for(Int_t l = 0; l < 3; ++l) {
402 if (fLabels[pmt][l] < 0) {
403 fLabels[pmt][l] = trackLabel;
407 Float_t dt_scintillator = gRandom->Gaus(0,kIntTimeRes);
408 Float_t t = dt_scintillator + 1e9*hit->Tof();
409 if (pmt < 32) t += kV0CDelayCables;
410 t += fHptdcOffset[pmt];
412 Float_t prob = lightYieldCorr[pmt]*fPhotoCathodeEfficiency; // Optical losses included!
414 nPhE = (Int_t)gRandom->Gaus(prob*Float_t(nPhot)+0.5,
415 sqrt(Float_t(nPhot)*prob*(1.-prob)));
417 nPhE = gRandom->Binomial(nPhot,prob);
418 Float_t charge = TMath::Qe()*fPmGain[pmt]*fBinSize[pmt]/integral;
419 for (Int_t iPhE = 0; iPhE < nPhE; ++iPhE) {
420 Float_t tPhE = t + fSignalShape->GetRandom(0,fBinSize[pmt]*Float_t(fNBins[pmt]));
421 Float_t gainVar = fSinglePhESpectrum->GetRandom(0,20)/meansPhE;
422 Int_t firstBin = TMath::Max(0,(Int_t)((tPhE-kPMRespTime)/fBinSize[pmt]));
423 Int_t lastBin = TMath::Min(fNBins[pmt]-1,(Int_t)((tPhE+2.*kPMRespTime)/fBinSize[pmt]));
424 for(Int_t iBin = firstBin; iBin <= lastBin; ++iBin) {
425 Float_t tempT = fBinSize[pmt]*(0.5+iBin)-tPhE;
426 fTime[pmt][iBin] += gainVar*charge*fPMResponse->Eval(tempT);
431 loader->UnloadHits();
435 void AliVZERODigitizer::DigitizeSDigits()
437 // Digitize the fTime arrays (SDigits) to the level of
438 // Digits (fAdc arrays)
439 for(Int_t i = 0 ; i < 64; ++i) {
440 for(Int_t j = 0; j < kNClocks; ++j) fAdc[i][j] = 0;
441 fLeadingTime[i] = fTimeWidth[i] = 0;
444 Float_t maximum = 0.9*fSignalShape->GetMaximum(0,200); // Not exact, one needs to do this on the convoluted
445 Float_t integral2 = fSignalShape->Integral(0,200); // function. Anyway the effect is small <10% on the 2.5 ADC thr
446 for (Int_t ipmt = 0; ipmt < 64; ++ipmt) {
447 Float_t thr = fCalibData->GetDiscriThr(ipmt)*kChargePerADC*maximum*fBinSize[ipmt]/integral2;
448 Bool_t ltFound = kFALSE, ttFound = kFALSE;
449 for (Int_t iBin = 0; iBin < fNBins[ipmt]; ++iBin) {
450 Float_t t = fBinSize[ipmt]*Float_t(iBin);
451 if (fTime[ipmt][iBin] > thr) {
452 if (!ltFound && (iBin < fNBinsLT[ipmt])) {
454 fLeadingTime[ipmt] = t;
461 fTimeWidth[ipmt] = t - fLeadingTime[ipmt];
465 Float_t tadc = t - kClockOffset - fCalibData->GetTimeOffset(ipmt);
466 Int_t clock = kNClocks/2 - Int_t(tadc/25.0);
467 if (clock >= 0 && clock < kNClocks)
468 fAdc[ipmt][clock] += fTime[ipmt][iBin]/kChargePerADC;
470 Int_t board = AliVZEROCalibData::GetBoardNumber(ipmt);
471 if (ltFound && ttFound) {
472 fTimeWidth[ipmt] = fCalibData->GetWidthResolution(board)*
473 Float_t(Int_t(fTimeWidth[ipmt]/fCalibData->GetWidthResolution(board)));
474 if (fTimeWidth[ipmt] < Float_t(kMinTDCWidth)*fCalibData->GetWidthResolution(board))
475 fTimeWidth[ipmt] = Float_t(kMinTDCWidth)*fCalibData->GetWidthResolution(board);
476 if (fTimeWidth[ipmt] > Float_t(kMaxTDCWidth)*fCalibData->GetWidthResolution(board))
477 fTimeWidth[ipmt] = Float_t(kMaxTDCWidth)*fCalibData->GetWidthResolution(board);
481 fEvenOrOdd = gRandom->Integer(2);
482 for (Int_t j=0; j<64; ++j){
483 for (Int_t iClock = 0; iClock < kNClocks; ++iClock) {
484 Int_t integrator = (iClock + fEvenOrOdd) % 2;
485 fAdc[j][iClock] += gRandom->Gaus(fAdcPedestal[j][integrator], fAdcSigma[j][integrator]);
491 void AliVZERODigitizer::WriteDigits(AliLoader *loader)
493 // Take fAdc arrays filled by the previous
494 // method and produce and add digits to the digit Tree
496 loader->LoadDigits("UPDATE");
498 if (!loader->TreeD()) loader->MakeTree("D");
499 loader->MakeDigitsContainer();
500 TTree* treeD = loader->TreeD();
502 treeD->Branch("VZERODigit", &fDigits);
504 Short_t *chargeADC = new Short_t[kNClocks];
505 for (Int_t i=0; i<64; i++) {
506 for (Int_t j = 0; j < kNClocks; ++j) {
507 Int_t tempadc = Int_t(fAdc[i][j]);
508 if (tempadc > 1023) tempadc = 1023;
509 chargeADC[j] = tempadc;
511 AddDigit(i, fLeadingTime[i], fTimeWidth[i], Bool_t((10+fEvenOrOdd)%2), chargeADC, fLabels[i]);
516 loader->WriteDigits("OVERWRITE");
517 loader->UnloadDigits();
521 void AliVZERODigitizer::WriteSDigits(AliLoader *loader)
523 // Take fTime arrays filled by the previous
524 // method and produce and add sdigits to the sdigit Tree
526 loader->LoadSDigits("UPDATE");
528 if (!loader->TreeS()) loader->MakeTree("S");
529 loader->MakeSDigitsContainer();
530 TTree* treeS = loader->TreeS();
532 treeS->Branch("VZEROSDigit", &fDigits);
534 for (Int_t ipmt = 0; ipmt < 64; ++ipmt) {
535 AddSDigit(ipmt,fNBins[ipmt],fTime[ipmt],fLabels[ipmt]);
539 loader->WriteSDigits("OVERWRITE");
540 loader->UnloadSDigits();
544 void AliVZERODigitizer::ReadSDigits()
546 // Read SDigits which are then to precessed
547 // in the following method
548 for(Int_t i = 0 ; i < 64; ++i) {
549 memset(fTime[i],0,fNBins[i]*sizeof(Float_t));
550 fLabels[i][0] = fLabels[i][1] = fLabels[i][2] = -1;
553 // Loop over input files
554 Int_t nFiles= fManager->GetNinputs();
555 for (Int_t inputFile = 0; inputFile < nFiles; inputFile++) {
556 // Get the current loader
557 AliRunLoader* currentLoader =
558 AliRunLoader::GetRunLoader(fManager->GetInputFolderName(inputFile));
560 AliLoader *loader = currentLoader->GetLoader("VZEROLoader");
561 loader->LoadSDigits("READ");
563 // Get the tree of summable digits
564 TTree* sdigitsTree = loader->TreeS();
566 AliError("No sdigit tree from manager");
571 TBranch* sdigitsBranch = sdigitsTree->GetBranch("VZEROSDigit");
572 if (!sdigitsBranch) {
573 AliError("Failed to get sdigit branch");
577 // Set the branch address
578 TClonesArray *sdigitsArray = NULL;
579 sdigitsBranch->SetAddress(&sdigitsArray);
581 // Sum contributions from the sdigits
582 // Get number of entries in the tree
583 Int_t nentries = Int_t(sdigitsBranch->GetEntries());
584 for (Int_t entry = 0; entry < nentries; ++entry) {
585 sdigitsBranch->GetEntry(entry);
586 // Get the number of sdigits
587 Int_t nsdigits = sdigitsArray->GetEntries();
588 for (Int_t sdigit = 0; sdigit < nsdigits; sdigit++) {
589 AliVZEROSDigit* sDigit = static_cast<AliVZEROSDigit*>(sdigitsArray->UncheckedAt(sdigit));
590 Int_t pmNumber = sDigit->PMNumber();
591 Int_t nbins = sDigit->GetNBins();
592 if (nbins != fNBins[pmNumber]) {
593 AliError(Form("Incompatible number of bins between digitizer (%d) and sdigit (%d) for PM %d! Skipping sdigit!",
594 fNBins[pmNumber],nbins,pmNumber));
598 Float_t *charges = sDigit->GetCharges();
599 for(Int_t iBin = 0; iBin < nbins; ++iBin) fTime[pmNumber][iBin] += charges[iBin];
601 Int_t *labels = sDigit->GetTracks();
603 for(Int_t i = 0; i < 3; ++i) {
604 if (fLabels[pmNumber][i] < 0) {
605 if (labels[j] < 0) break;
606 fLabels[pmNumber][i] = labels[j];
612 loader->UnloadSDigits();
616 //____________________________________________________________________
618 AliVZERODigitizer::DigitsArray()
620 // Initialize digit array if not already and
621 // return pointer to it.
623 fDigits = new TClonesArray("AliVZEROdigit", 64);
629 //____________________________________________________________________
631 AliVZERODigitizer::SDigitsArray()
633 // Initialize sdigit array if not already and
634 // return pointer to it.
636 fDigits = new TClonesArray("AliVZEROSDigit", 64);