1 /**************************************************************************
2 * Copyright(c) 1998-2000, 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 **************************************************************************/
16 //_________________________________________________________________________
17 // This is a TTask that makes TOF-Digits out of TOF-SDigits.
18 // The simulation of the detector is performed at sdigits level:
19 // during digitization the unique task is the sum of all sdigits in the
21 // Digits are written to TreeD in branch "TOF".
23 // -- Author : F. Pierella (Bologna University) pierella@bo.infn.it
24 //////////////////////////////////////////////////////////////////////////////
28 #include <Riostream.h>
31 #include <TObjArray.h>
33 #include <TDirectory.h>
42 #include "AliRunLoader.h"
43 #include "AliLoader.h"
44 #include "AliDigitizer.h"
45 #include "AliRunDigitizer.h"
49 #include "AliTOFDigitizer.h"
50 #include "AliTOFSDigitizer.h"
51 #include "AliTOFhit.h"
52 #include "AliTOFdigit.h"
53 #include "AliTOFSDigit.h"
54 #include "AliTOFHitMap.h"
55 #include "AliTOFChannel.h"
56 #include "AliTOFCal.h"
57 #include "AliTOFGeometryV5.h"
59 ClassImp(AliTOFDigitizer)
61 //___________________________________________
62 AliTOFDigitizer::AliTOFDigitizer() :AliDigitizer()
64 // Default ctor - don't use it
71 //___________________________________________
72 AliTOFDigitizer::AliTOFDigitizer(AliRunDigitizer* manager)
73 :AliDigitizer(manager)
75 //ctor with RunDigitizer
82 //------------------------------------------------------------------------
83 AliTOFDigitizer::~AliTOFDigitizer()
88 //---------------------------------------------------------------------
90 void AliTOFDigitizer::Exec(Option_t* /*option*/)
93 // Perform digitization and merging.
94 // The algorithm is the following:
95 // - a hitmap is created to check if a pad is already activated;
96 // - an sdigits container is created to collect all sdigits from
98 // - sdigits are summed using the hitmap;
99 // - the sdigits container is used to create the array of AliTOFdigit.
105 // get the ptr to TOF detector
106 AliTOF * tof = (AliTOF *) gAlice->GetDetector("TOF") ;
110 sprintf (branchname, "%s", tof->GetName ());
112 fDigits=new TClonesArray("AliTOFdigit",4000);
114 AliRunLoader* outrl = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
117 AliError("Can not find Run Loader in output folder.");
122 TFile *in=(TFile*)gFile;
123 TDirectory *savedir=gDirectory;
126 AliWarning("Geometry file is not open default TOF geometry will be used");
127 fGeom = new AliTOFGeometryV5();
131 fGeom = (AliTOFGeometry*)in->Get("TOFgeometry");
136 AliLoader* outgime = outrl->GetLoader("TOFLoader");
139 AliError("Can not get TOF Loader from Output Run Loader.");
143 TTree* treeD = outgime->TreeD();
146 outgime->MakeTree("D");
147 treeD = outgime->TreeD();
149 //Make branch for digits (to be created in Init())
150 tof->MakeBranchInTree(treeD,branchname,&fDigits,4000);
152 // container for all summed sdigits (to be created in Init())
153 fSDigitsArray=new TClonesArray("AliTOFSDigit",1000);
155 // create hit map (to be created in Init())
156 fhitMap = new AliTOFHitMap(fSDigitsArray, fGeom);
158 // Loop over files to digitize
160 for (Int_t inputFile=0; inputFile<fManager->GetNinputs();
162 ReadSDigit(inputFile);
168 // free used memory for Hit Map in current event
170 fSDigitsArray->Delete();
171 delete fSDigitsArray;
175 outgime->WriteDigits("OVERWRITE");
176 outgime->UnloadDigits();
182 //---------------------------------------------------------------------
184 void AliTOFDigitizer::CreateDigits()
186 // loop on sdigits container to fill the AliTOFdigit TClonesArray
187 // start digitizing all the collected sdigits
189 Int_t ndump=0; // dump the first ndump created digits for each event
191 // get the total number of collected sdigits
192 Int_t ndig = fSDigitsArray->GetEntriesFast();
194 for (Int_t k = 0; k < ndig; k++) {
196 Int_t vol[5]; // location for a digit
197 for (Int_t i=0; i<5; i++) vol[i] = -1;
199 // Get the information for this digit
200 AliTOFSDigit *tofsdigit = (AliTOFSDigit *) fSDigitsArray->UncheckedAt(k);
202 Int_t nslot=tofsdigit->GetNDigits(); // get the number of slots
203 // for current sdigit
205 // TOF sdigit volumes (always the same for all slots)
206 Int_t sector = tofsdigit->GetSector(); // range [0-17]
207 Int_t plate = tofsdigit->GetPlate(); // range [0- 4]
208 Int_t strip = tofsdigit->GetStrip(); // range [0-14/18/19]
209 Int_t padz = tofsdigit->GetPadz(); // range [0- 1]
210 Int_t padx = tofsdigit->GetPadx(); // range [0-47]
218 //--------------------- QA section ----------------------
219 // in the while, I perform QA
220 Bool_t isSDigitBad = (sector<0 || sector>17 || plate<0 || plate >4 || padz<0 || padz>1 || padx<0 || padx>47);
223 //AliFatal("strange sdigit found");
224 AliFatal(Form("strange sdigit found %3i %2i %2i %3i %3i", sector, plate, padz, padx, strip));
226 //-------------------------------------------------------
228 //------------------- Dump section ----------------------
230 cout << k << "-th | " << "Sector " << sector << " | Plate " << plate << " | Strip " << strip << " | PadZ " << padz << " | PadX " << padx << endl;
231 cout << k << "-th sdigit" << endl;
232 cout << "----------------------------------------------------"<< endl;
234 // ------------------------------------------------------
236 // start loop on number of slots for current sdigit
237 for (Int_t islot = 0; islot < nslot; islot++) {
238 Float_t digit[2]; // TOF digit variables
239 Int_t tracknum[kMAXDIGITS]; // contributing tracks for the current slot
241 Float_t tdc=tofsdigit->GetTdc(islot); digit[0]=tdc;
242 Float_t adc=tofsdigit->GetAdc(islot); digit[1]=adc;
244 tracknum[0]=tofsdigit->GetTrack(islot,0);
245 tracknum[1]=tofsdigit->GetTrack(islot,1);
246 tracknum[2]=tofsdigit->GetTrack(islot,2);
248 // new with placement must be used
249 // adding a TOF digit for each slot
250 TClonesArray &aDigits = *fDigits;
251 Int_t last=fDigits->GetEntriesFast();
252 new (aDigits[last]) AliTOFdigit(tracknum, vol, digit);
256 } // end loop on sdigits - end digitizing all collected sdigits
258 //Insert Decalibration
260 AliTOFcalib * calib = new AliTOFcalib(fGeom);
261 InitDecalibration(calib);
262 DecalibrateTOFSignal(calib);
266 //---------------------------------------------------------------------
268 void AliTOFDigitizer::ReadSDigit(Int_t inputFile )
270 // Read sdigits for current event and inputFile;
271 // store them into the sdigits container
272 // and update the hit map
273 // SDigits from different files are assumed to
274 // be created with the same simulation parameters.
276 // get the treeS from manager
277 AliRunLoader* rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(inputFile));
280 AliError(Form("Can not find Run Loader in input %d folder.",inputFile));
284 AliLoader* gime = rl->GetLoader("TOFLoader");
287 AliError(Form("Can not get TOF Loader from Input %d Run Loader.",inputFile));
291 TTree* currentTreeS=gime->TreeS();
292 if (currentTreeS == 0x0)
294 Int_t retval = gime->LoadSDigits();
297 AliError(Form("Error occured while loading S. Digits for Input %d",inputFile));
300 currentTreeS=gime->TreeS();
301 if (currentTreeS == 0x0)
303 AliError(Form("Can not get S. Digits Tree for Input %d",inputFile));
307 // get the branch TOF inside the treeS
308 TClonesArray * sdigitsDummyContainer= new TClonesArray("AliTOFSDigit", 1000);
310 // check if the branch exist
311 TBranch* tofBranch=currentTreeS->GetBranch("TOF");
314 AliFatal(Form("TOF branch not found for input %d",inputFile));
317 tofBranch->SetAddress(&sdigitsDummyContainer);
319 Int_t nEntries = (Int_t)tofBranch->GetEntries();
321 // Loop through all entries in the tree
324 for (Int_t iEntry = 0; iEntry < nEntries; iEntry++) {
327 nbytes += tofBranch->GetEvent(iEntry);
329 // Get the number of sdigits
330 Int_t ndig = sdigitsDummyContainer->GetEntriesFast();
332 for (Int_t k=0; k<ndig; k++) {
333 AliTOFSDigit *tofSdigit= (AliTOFSDigit*) sdigitsDummyContainer->UncheckedAt(k);
335 Int_t vol[5]; // location for a sdigit
336 for (Int_t i=0; i<5; i++) vol[i] = -1;
338 // check the sdigit volume
339 vol[0] = tofSdigit->GetSector();
340 vol[1] = tofSdigit->GetPlate();
341 vol[2] = tofSdigit->GetStrip();
342 vol[3] = tofSdigit->GetPadx();
343 vol[4] = tofSdigit->GetPadz();
345 if (fhitMap->TestHit(vol) != kEmpty) {
346 AliTOFSDigit *sdig = static_cast<AliTOFSDigit*>(fhitMap->GetHit(vol));
347 sdig->Update(tofSdigit);
351 CollectSDigit(tofSdigit); // collect the current sdigit
352 fhitMap->SetHit(vol); // update the hitmap for location vol
354 } // if (hitMap->TestHit(vol) != kEmpty)
356 } // for (Int_t k=0; k<ndig; k++)
357 sdigitsDummyContainer->Delete();
359 } // end loop on entries
361 delete sdigitsDummyContainer;
366 //_____________________________________________________________________________
367 void AliTOFDigitizer::CollectSDigit(AliTOFSDigit * sdigit)
370 // Add a TOF sdigit in container
371 // new with placement must be used
372 TClonesArray &aSDigitsArray = *fSDigitsArray;
373 Int_t last=fSDigitsArray->GetEntriesFast();
374 // make a copy of the current sdigit and
375 // put it into tmp array
376 new (aSDigitsArray[last]) AliTOFSDigit(*sdigit);
379 //_____________________________________________________________________________
380 void AliTOFDigitizer::InitDecalibration( AliTOFcalib *calib) const {
381 calib->ReadSimParFromCDB("TOF/Calib", 0);
383 //---------------------------------------------------------------------
384 void AliTOFDigitizer::DecalibrateTOFSignal( AliTOFcalib *calib){
386 // Read Calibration parameters from the CDB
388 AliTOFCal * cal= calib->GetTOFCalSimArray();
390 AliInfo(Form("Size of AliTOFCal = %i",cal->NPads()));
391 for (Int_t ipad = 0 ; ipad<cal->NPads(); ipad++){
392 AliTOFChannel *calChannel = cal->GetChannel(ipad);
394 for (Int_t j = 0; j<6; j++){
395 par[j]=calChannel->GetSlewPar(j);
399 // Initialize Quantities to Simulate ToT Spectra
402 TH1F * hToT= calib->GetTOFSimToT();
403 Int_t nbins = hToT->GetNbinsX();
404 Float_t delta = hToT->GetBinWidth(1);
405 Float_t maxch = hToT->GetBinLowEdge(nbins)+delta;
406 Float_t minch = hToT->GetBinLowEdge(1);
407 Float_t max=0,min=0; //maximum and minimum value of the distribution
408 Int_t maxbin=0,minbin=0; //maximum and minimum bin of the distribution
409 for (Int_t ii=nbins; ii>0; ii--){
410 if (hToT->GetBinContent(ii)!= 0) {
411 max = maxch - (nbins-ii-1)*delta;
415 for (Int_t j=1; j<nbins; j++){
416 if (hToT->GetBinContent(j)!= 0) {
417 min = minch + (j-1)*delta;
423 Float_t maxToTDistr=hToT->GetMaximum();
426 // Loop on TOF Digits
428 Bool_t dbEntry=kFALSE;
429 Int_t ndigits = fDigits->GetEntriesFast();
430 for (Int_t i=0;i<ndigits;i++){
431 AliTOFdigit * dig = (AliTOFdigit*)fDigits->At(i);
433 detId[0] = dig->GetSector();
434 detId[1] = dig->GetPlate();
435 detId[2] = dig->GetStrip();
436 detId[3] = dig->GetPadz();
437 detId[4] = dig->GetPadx();
438 // For Data with no Miscalibration, set ToT signal == Adc
439 dig->SetToT(dig->GetAdc());
440 if(hToT->GetEntries()>0){
444 while (simToT <= triy){
445 trix = gRandom->Rndm(i);
446 triy = gRandom->Rndm(i);
447 trix = (maxToT-minToT)*trix + minToT;
448 triy = maxToTDistr*triy;
449 Int_t binx=hToT->FindBin(trix);
450 simToT=hToT->GetBinContent(binx);
452 // Setting realistic ToT signal (only for Miscalibrated Data)
455 Int_t index = calib->GetIndex(detId);
456 AliTOFChannel *calChannel = cal->GetChannel(index);
458 for (Int_t j = 0; j<6; j++){
459 par[j]=calChannel->GetSlewPar(j);
460 if(par[j]!=0)dbEntry=kTRUE;
463 Float_t tToT= dig->GetToT();
464 dig->SetTdcND(dig->GetTdc());
465 Float_t tdc = ((dig->GetTdc())*AliTOFGeometry::TdcBinWidth()+32)*1.E-3; //tof signal in ns
466 Float_t timeoffset=par[0] + tToT*par[1] +tToT*tToT*par[2] +tToT*tToT*tToT*par[3] +tToT*tToT*tToT*tToT*par[4] +tToT*tToT*tToT*tToT*tToT*par[5];
467 Float_t timeSlewed = tdc + timeoffset;
468 // Setting Decalibrated Time signal
469 dig->SetTdc((timeSlewed*1E3-32)/AliTOFGeometry::TdcBinWidth());
472 if(hToT->GetEntries()<=0 || !dbEntry){
473 AliInfo("Standard Production, no miscalibrated digits");
475 AliInfo("Miscalibrated digits");