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 //_________________________________________________________________________//
18 // This is a TTask that makes TOF-Digits out of TOF-SDigits. //
19 // The simulation of the detector is performed at sdigits level: //
20 // during digitization the unique task is the sum of all sdigits in the //
22 // Digits are written to TreeD in branch "TOF". //
24 // -- Author : F. Pierella (Bologna University) pierella@bo.infn.it //
26 //_________________________________________________________________________//
28 #include "Riostream.h"
34 #include "AliLoader.h"
36 #include "AliRunDigitizer.h"
37 #include "AliRunLoader.h"
40 #include "AliTOFCal.h"
41 #include "AliTOFcalib.h"
42 #include "AliTOFChannel.h"
43 #include "AliTOFDigitizer.h"
44 #include "AliTOFdigit.h"
45 #include "AliTOFHitMap.h"
46 #include "AliTOFGeometryV5.h"
47 #include "AliTOFSDigit.h"
50 extern TDirectory *gDirectory;
52 extern TRandom *gRandom;
54 extern AliRun *gAlice;
57 ClassImp(AliTOFDigitizer)
59 //___________________________________________
60 AliTOFDigitizer::AliTOFDigitizer() :
67 // Default ctor - don't use it
70 //___________________________________________
71 AliTOFDigitizer::AliTOFDigitizer(AliRunDigitizer* manager):
72 AliDigitizer(manager),
78 //ctor with RunDigitizer
81 //------------------------------------------------------------------------
82 AliTOFDigitizer::AliTOFDigitizer(const AliTOFDigitizer &source):
90 this->fDigits=source.fDigits;
91 this->fSDigitsArray=source.fSDigitsArray;
92 this->fhitMap=source.fhitMap;
93 this->fGeom=source.fGeom;
97 //------------------------------------------------------------------------
98 AliTOFDigitizer& AliTOFDigitizer::operator=(const AliTOFDigitizer &source)
101 this->fDigits=source.fDigits;
102 this->fSDigitsArray=source.fSDigitsArray;
103 this->fhitMap=source.fhitMap;
104 this->fGeom=source.fGeom;
109 //------------------------------------------------------------------------
110 AliTOFDigitizer::~AliTOFDigitizer()
115 //---------------------------------------------------------------------
117 void AliTOFDigitizer::Exec(Option_t* /*option*/)
120 // Perform digitization and merging.
121 // The algorithm is the following:
122 // - a hitmap is created to check if a pad is already activated;
123 // - an sdigits container is created to collect all sdigits from
125 // - sdigits are summed using the hitmap;
126 // - the sdigits container is used to create the array of AliTOFdigit.
132 // get the ptr to TOF detector
133 AliTOF * tof = (AliTOF *) gAlice->GetDetector("TOF") ;
137 sprintf (branchname, "%s", tof->GetName ());
139 fDigits=new TClonesArray("AliTOFdigit",4000);
141 AliRunLoader* outrl = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
144 AliError("Can not find Run Loader in output folder.");
149 TFile *in=(TFile*)gFile;
150 TDirectory *savedir=gDirectory;
153 AliWarning("Geometry file is not open default TOF geometry will be used");
154 fGeom = new AliTOFGeometryV5();
158 fGeom = (AliTOFGeometry*)in->Get("TOFgeometry");
163 AliLoader* outgime = outrl->GetLoader("TOFLoader");
166 AliError("Can not get TOF Loader from Output Run Loader.");
170 TTree* treeD = outgime->TreeD();
173 outgime->MakeTree("D");
174 treeD = outgime->TreeD();
176 //Make branch for digits (to be created in Init())
177 tof->MakeBranchInTree(treeD,branchname,&fDigits,4000);
179 // container for all summed sdigits (to be created in Init())
180 fSDigitsArray=new TClonesArray("AliTOFSDigit",1000);
182 // create hit map (to be created in Init())
183 fhitMap = new AliTOFHitMap(fSDigitsArray, fGeom);
185 // Loop over files to digitize
187 for (Int_t inputFile=0; inputFile<fManager->GetNinputs();
189 ReadSDigit(inputFile);
195 // free used memory for Hit Map in current event
197 fSDigitsArray->Delete();
198 delete fSDigitsArray;
202 outgime->WriteDigits("OVERWRITE");
203 outgime->UnloadDigits();
209 //---------------------------------------------------------------------
211 void AliTOFDigitizer::CreateDigits()
213 // loop on sdigits container to fill the AliTOFdigit TClonesArray
214 // start digitizing all the collected sdigits
216 Int_t ndump=0; // dump the first ndump created digits for each event
218 // get the total number of collected sdigits
219 Int_t ndig = fSDigitsArray->GetEntriesFast();
221 for (Int_t k = 0; k < ndig; k++) {
223 Int_t vol[5]; // location for a digit
224 for (Int_t i=0; i<5; i++) vol[i] = -1;
226 // Get the information for this digit
227 AliTOFSDigit *tofsdigit = (AliTOFSDigit *) fSDigitsArray->UncheckedAt(k);
229 Int_t nslot=tofsdigit->GetNDigits(); // get the number of slots
230 // for current sdigit
232 // TOF sdigit volumes (always the same for all slots)
233 Int_t sector = tofsdigit->GetSector(); // range [0-17]
234 Int_t plate = tofsdigit->GetPlate(); // range [0- 4]
235 Int_t strip = tofsdigit->GetStrip(); // range [0-14/18/19]
236 Int_t padz = tofsdigit->GetPadz(); // range [0- 1]
237 Int_t padx = tofsdigit->GetPadx(); // range [0-47]
245 //--------------------- QA section ----------------------
246 // in the while, I perform QA
247 Bool_t isSDigitBad = (sector<0 || sector>17 || plate<0 || plate >4 || padz<0 || padz>1 || padx<0 || padx>47);
250 //AliFatal("strange sdigit found");
251 AliFatal(Form("strange sdigit found %3i %2i %2i %3i %3i", sector, plate, padz, padx, strip));
253 //-------------------------------------------------------
255 //------------------- Dump section ----------------------
257 cout << k << "-th | " << "Sector " << sector << " | Plate " << plate << " | Strip " << strip << " | PadZ " << padz << " | PadX " << padx << endl;
258 cout << k << "-th sdigit" << endl;
259 cout << "----------------------------------------------------"<< endl;
261 // ------------------------------------------------------
263 // start loop on number of slots for current sdigit
264 for (Int_t islot = 0; islot < nslot; islot++) {
265 Float_t digit[4] = {-1.,-1.,-1.,-1.}; // TOF digit variables
266 Int_t tracknum[AliTOFSDigit::kMAXDIGITS]; // contributing tracks for the current slot
268 Float_t tdc=tofsdigit->GetTdc(islot); digit[0]=tdc;
269 Float_t adc=tofsdigit->GetAdc(islot); digit[1]=adc;
271 tracknum[0]=tofsdigit->GetTrack(islot,0);
272 tracknum[1]=tofsdigit->GetTrack(islot,1);
273 tracknum[2]=tofsdigit->GetTrack(islot,2);
275 // new with placement must be used
276 // adding a TOF digit for each slot
277 TClonesArray &aDigits = *fDigits;
278 Int_t last=fDigits->GetEntriesFast();
279 new (aDigits[last]) AliTOFdigit(tracknum, vol, digit);
283 } // end loop on sdigits - end digitizing all collected sdigits
285 //Insert Decalibration
287 AliTOFcalib * calib = new AliTOFcalib(fGeom);
288 InitDecalibration(calib);
289 DecalibrateTOFSignal(calib);
293 //---------------------------------------------------------------------
295 void AliTOFDigitizer::ReadSDigit(Int_t inputFile )
297 // Read sdigits for current event and inputFile;
298 // store them into the sdigits container
299 // and update the hit map
300 // SDigits from different files are assumed to
301 // be created with the same simulation parameters.
303 // get the treeS from manager
304 AliRunLoader* rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(inputFile));
307 AliError(Form("Can not find Run Loader in input %d folder.",inputFile));
311 AliLoader* gime = rl->GetLoader("TOFLoader");
314 AliError(Form("Can not get TOF Loader from Input %d Run Loader.",inputFile));
318 TTree* currentTreeS=gime->TreeS();
319 if (currentTreeS == 0x0)
321 Int_t retval = gime->LoadSDigits();
324 AliError(Form("Error occured while loading S. Digits for Input %d",inputFile));
327 currentTreeS=gime->TreeS();
328 if (currentTreeS == 0x0)
330 AliError(Form("Can not get S. Digits Tree for Input %d",inputFile));
334 // get the branch TOF inside the treeS
335 TClonesArray * sdigitsDummyContainer= new TClonesArray("AliTOFSDigit", 1000);
337 // check if the branch exist
338 TBranch* tofBranch=currentTreeS->GetBranch("TOF");
341 AliFatal(Form("TOF branch not found for input %d",inputFile));
344 tofBranch->SetAddress(&sdigitsDummyContainer);
346 Int_t nEntries = (Int_t)tofBranch->GetEntries();
348 // Loop through all entries in the tree
351 for (Int_t iEntry = 0; iEntry < nEntries; iEntry++) {
354 nbytes += tofBranch->GetEvent(iEntry);
356 // Get the number of sdigits
357 Int_t ndig = sdigitsDummyContainer->GetEntriesFast();
359 for (Int_t k=0; k<ndig; k++) {
360 AliTOFSDigit *tofSdigit= (AliTOFSDigit*) sdigitsDummyContainer->UncheckedAt(k);
362 Int_t vol[5]; // location for a sdigit
363 for (Int_t i=0; i<5; i++) vol[i] = -1;
365 // check the sdigit volume
366 vol[0] = tofSdigit->GetSector();
367 vol[1] = tofSdigit->GetPlate();
368 vol[2] = tofSdigit->GetStrip();
369 vol[3] = tofSdigit->GetPadx();
370 vol[4] = tofSdigit->GetPadz();
372 if (fhitMap->TestHit(vol) != kEmpty) {
373 AliTOFSDigit *sdig = static_cast<AliTOFSDigit*>(fhitMap->GetHit(vol));
374 sdig->Update(tofSdigit);
378 CollectSDigit(tofSdigit); // collect the current sdigit
379 fhitMap->SetHit(vol); // update the hitmap for location vol
381 } // if (hitMap->TestHit(vol) != kEmpty)
383 } // for (Int_t k=0; k<ndig; k++)
384 sdigitsDummyContainer->Delete();
386 } // end loop on entries
388 delete sdigitsDummyContainer;
393 //_____________________________________________________________________________
394 void AliTOFDigitizer::CollectSDigit(AliTOFSDigit * sdigit)
397 // Add a TOF sdigit in container
398 // new with placement must be used
399 TClonesArray &aSDigitsArray = *fSDigitsArray;
400 Int_t last=fSDigitsArray->GetEntriesFast();
401 // make a copy of the current sdigit and
402 // put it into tmp array
403 new (aSDigitsArray[last]) AliTOFSDigit(*sdigit);
406 //_____________________________________________________________________________
407 void AliTOFDigitizer::InitDecalibration( AliTOFcalib *calib) const {
408 // calib->ReadSimParFromCDB("TOF/Calib", 0); // original
409 calib->ReadSimParFromCDB("TOF/Calib", -1); // use AliCDBManager's number
411 //---------------------------------------------------------------------
412 void AliTOFDigitizer::DecalibrateTOFSignal( AliTOFcalib *calib){
414 // Read Calibration parameters from the CDB
416 AliTOFCal * cal= calib->GetTOFCalSimArray();
418 AliInfo(Form("Size of AliTOFCal = %i",cal->NPads()));
419 for (Int_t ipad = 0 ; ipad<cal->NPads(); ipad++){
420 AliTOFChannel *calChannel = cal->GetChannel(ipad);
422 for (Int_t j = 0; j<6; j++){
423 par[j]=calChannel->GetSlewPar(j);
427 // Initialize Quantities to Simulate ToT Spectra
430 TH1F * hToT= calib->GetTOFSimToT();
431 Int_t nbins = hToT->GetNbinsX();
432 Float_t delta = hToT->GetBinWidth(1);
433 Float_t maxch = hToT->GetBinLowEdge(nbins)+delta;
434 Float_t minch = hToT->GetBinLowEdge(1);
435 Float_t max=0,min=0; //maximum and minimum value of the distribution
436 Int_t maxbin=0,minbin=0; //maximum and minimum bin of the distribution
437 for (Int_t ii=nbins; ii>0; ii--){
438 if (hToT->GetBinContent(ii)!= 0) {
439 max = maxch - (nbins-ii-1)*delta;
443 for (Int_t j=1; j<nbins; j++){
444 if (hToT->GetBinContent(j)!= 0) {
445 min = minch + (j-1)*delta;
451 Float_t maxToTDistr=hToT->GetMaximum();
454 // Loop on TOF Digits
456 Bool_t dbEntry=kFALSE;
457 Int_t ndigits = fDigits->GetEntriesFast();
458 for (Int_t i=0;i<ndigits;i++){
459 AliTOFdigit * dig = (AliTOFdigit*)fDigits->At(i);
461 detId[0] = dig->GetSector();
462 detId[1] = dig->GetPlate();
463 detId[2] = dig->GetStrip();
464 detId[3] = dig->GetPadz();
465 detId[4] = dig->GetPadx();
466 // For Data with no Miscalibration, set ToT signal == Adc
467 dig->SetToT(dig->GetAdc());
468 if(hToT->GetEntries()>0){
472 while (simToT <= triy){
473 trix = gRandom->Rndm(i);
474 triy = gRandom->Rndm(i);
475 trix = (maxToT-minToT)*trix + minToT;
476 triy = maxToTDistr*triy;
477 Int_t binx=hToT->FindBin(trix);
478 simToT=hToT->GetBinContent(binx);
480 // Setting realistic ToT signal (only for Miscalibrated Data)
483 Int_t index = calib->GetIndex(detId);
484 AliTOFChannel *calChannel = cal->GetChannel(index);
485 // time slewing parameters
487 for (Int_t j = 0; j<6; j++){
488 par[j]=calChannel->GetSlewPar(j);
489 if(par[j]!=0)dbEntry=kTRUE;
491 // the global time shift
492 Float_t timedelay = calChannel->GetDelay();
493 Float_t tToT= dig->GetToT();
494 dig->SetTdcND(dig->GetTdc());
495 Float_t tdc = ((dig->GetTdc())*AliTOFGeometry::TdcBinWidth()+32)*1.E-3; //tof signal in ns
496 // add slewing effect
497 Float_t timeoffset=par[0] + tToT*(par[1] +tToT*(par[2] +tToT*(par[3] +tToT*(par[4] +tToT*par[5]))));
498 Float_t timeSlewed = tdc+timeoffset;
499 // add global time shift
500 timeSlewed = timeSlewed + timedelay;
502 // Setting Decalibrated Time signal
503 dig->SetTdc((timeSlewed*1E3-32)/AliTOFGeometry::TdcBinWidth());
506 if(hToT->GetEntries()<=0 || !dbEntry){
507 AliInfo("Standard Production, no miscalibrated digits");
509 AliInfo("Miscalibrated digits");