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)
81 //------------------------------------------------------------------------
82 AliTOFDigitizer::~AliTOFDigitizer()
87 //---------------------------------------------------------------------
89 void AliTOFDigitizer::Exec(Option_t* /*option*/)
92 // Perform digitization and merging.
93 // The algorithm is the following:
94 // - a hitmap is created to check if a pad is already activated;
95 // - an sdigits container is created to collect all sdigits from
97 // - sdigits are summed using the hitmap;
98 // - the sdigits container is used to create the array of AliTOFdigit.
104 // get the ptr to TOF detector
105 AliTOF * tof = (AliTOF *) gAlice->GetDetector("TOF") ;
109 sprintf (branchname, "%s", tof->GetName ());
111 fDigits=new TClonesArray("AliTOFdigit",4000);
113 AliRunLoader* outrl = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
116 AliError("Can not find Run Loader in output folder.");
121 TFile *in=(TFile*)gFile;
122 TDirectory *savedir=gDirectory;
125 AliWarning("Geometry file is not open default TOF geometry will be used");
126 fGeom = new AliTOFGeometryV5();
130 fGeom = (AliTOFGeometry*)in->Get("TOFgeometry");
135 AliLoader* outgime = outrl->GetLoader("TOFLoader");
138 AliError("Can not get TOF Loader from Output Run Loader.");
142 TTree* treeD = outgime->TreeD();
145 outgime->MakeTree("D");
146 treeD = outgime->TreeD();
148 //Make branch for digits (to be created in Init())
149 tof->MakeBranchInTree(treeD,branchname,&fDigits,4000);
151 // container for all summed sdigits (to be created in Init())
152 fSDigitsArray=new TClonesArray("AliTOFSDigit",1000);
154 // create hit map (to be created in Init())
155 fhitMap = new AliTOFHitMap(fSDigitsArray, fGeom);
157 // Loop over files to digitize
159 for (Int_t inputFile=0; inputFile<fManager->GetNinputs();
161 ReadSDigit(inputFile);
167 // free used memory for Hit Map in current event
169 fSDigitsArray->Delete();
170 delete fSDigitsArray;
174 outgime->WriteDigits("OVERWRITE");
175 outgime->UnloadDigits();
181 //---------------------------------------------------------------------
183 void AliTOFDigitizer::CreateDigits()
185 // loop on sdigits container to fill the AliTOFdigit TClonesArray
186 // start digitizing all the collected sdigits
188 Int_t ndump=0; // dump the first ndump created digits for each event
190 // get the total number of collected sdigits
191 Int_t ndig = fSDigitsArray->GetEntriesFast();
193 for (Int_t k = 0; k < ndig; k++) {
195 Int_t vol[5]; // location for a digit
196 for (Int_t i=0; i<5; i++) vol[i] = -1;
198 // Get the information for this digit
199 AliTOFSDigit *tofsdigit = (AliTOFSDigit *) fSDigitsArray->UncheckedAt(k);
201 Int_t nslot=tofsdigit->GetNDigits(); // get the number of slots
202 // for current sdigit
204 // TOF sdigit volumes (always the same for all slots)
205 Int_t sector = tofsdigit->GetSector(); // range [0-17]
206 Int_t plate = tofsdigit->GetPlate(); // range [0- 4]
207 Int_t strip = tofsdigit->GetStrip(); // range [0-14/18/19]
208 Int_t padz = tofsdigit->GetPadz(); // range [0- 1]
209 Int_t padx = tofsdigit->GetPadx(); // range [0-47]
217 //--------------------- QA section ----------------------
218 // in the while, I perform QA
219 Bool_t isSDigitBad = (sector<0 || sector>17 || plate<0 || plate >4 || padz<0 || padz>1 || padx<0 || padx>47);
222 //AliFatal("strange sdigit found");
223 AliFatal(Form("strange sdigit found %3i %2i %2i %3i %3i", sector, plate, padz, padx, strip));
225 //-------------------------------------------------------
227 //------------------- Dump section ----------------------
229 cout << k << "-th | " << "Sector " << sector << " | Plate " << plate << " | Strip " << strip << " | PadZ " << padz << " | PadX " << padx << endl;
230 cout << k << "-th sdigit" << endl;
231 cout << "----------------------------------------------------"<< endl;
233 // ------------------------------------------------------
235 // start loop on number of slots for current sdigit
236 for (Int_t islot = 0; islot < nslot; islot++) {
237 Float_t digit[2]; // TOF digit variables
238 Int_t tracknum[kMAXDIGITS]; // contributing tracks for the current slot
240 Float_t tdc=tofsdigit->GetTdc(islot); digit[0]=tdc;
241 Float_t adc=tofsdigit->GetAdc(islot); digit[1]=adc;
243 tracknum[0]=tofsdigit->GetTrack(islot,0);
244 tracknum[1]=tofsdigit->GetTrack(islot,1);
245 tracknum[2]=tofsdigit->GetTrack(islot,2);
247 // new with placement must be used
248 // adding a TOF digit for each slot
249 TClonesArray &aDigits = *fDigits;
250 Int_t last=fDigits->GetEntriesFast();
251 new (aDigits[last]) AliTOFdigit(tracknum, vol, digit);
255 } // end loop on sdigits - end digitizing all collected sdigits
257 //Insert Decalibration
259 AliTOFcalib * calib = new AliTOFcalib(fGeom);
260 InitDecalibration(calib);
261 DecalibrateTOFSignal(calib);
265 //---------------------------------------------------------------------
267 void AliTOFDigitizer::ReadSDigit(Int_t inputFile )
269 // Read sdigits for current event and inputFile;
270 // store them into the sdigits container
271 // and update the hit map
272 // SDigits from different files are assumed to
273 // be created with the same simulation parameters.
275 // get the treeS from manager
276 AliRunLoader* rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(inputFile));
279 AliError(Form("Can not find Run Loader in input %d folder.",inputFile));
283 AliLoader* gime = rl->GetLoader("TOFLoader");
286 AliError(Form("Can not get TOF Loader from Input %d Run Loader.",inputFile));
290 TTree* currentTreeS=gime->TreeS();
291 if (currentTreeS == 0x0)
293 Int_t retval = gime->LoadSDigits();
296 AliError(Form("Error occured while loading S. Digits for Input %d",inputFile));
299 currentTreeS=gime->TreeS();
300 if (currentTreeS == 0x0)
302 AliError(Form("Can not get S. Digits Tree for Input %d",inputFile));
306 // get the branch TOF inside the treeS
307 TClonesArray * sdigitsDummyContainer= new TClonesArray("AliTOFSDigit", 1000);
309 // check if the branch exist
310 TBranch* tofBranch=currentTreeS->GetBranch("TOF");
313 AliFatal(Form("TOF branch not found for input %d",inputFile));
316 tofBranch->SetAddress(&sdigitsDummyContainer);
318 Int_t nEntries = (Int_t)tofBranch->GetEntries();
320 // Loop through all entries in the tree
323 for (Int_t iEntry = 0; iEntry < nEntries; iEntry++) {
326 nbytes += tofBranch->GetEvent(iEntry);
328 // Get the number of sdigits
329 Int_t ndig = sdigitsDummyContainer->GetEntriesFast();
331 for (Int_t k=0; k<ndig; k++) {
332 AliTOFSDigit *tofSdigit= (AliTOFSDigit*) sdigitsDummyContainer->UncheckedAt(k);
334 Int_t vol[5]; // location for a sdigit
335 for (Int_t i=0; i<5; i++) vol[i] = -1;
337 // check the sdigit volume
338 vol[0] = tofSdigit->GetSector();
339 vol[1] = tofSdigit->GetPlate();
340 vol[2] = tofSdigit->GetStrip();
341 vol[3] = tofSdigit->GetPadx();
342 vol[4] = tofSdigit->GetPadz();
344 if (fhitMap->TestHit(vol) != kEmpty) {
345 AliTOFSDigit *sdig = static_cast<AliTOFSDigit*>(fhitMap->GetHit(vol));
346 sdig->Update(tofSdigit);
350 CollectSDigit(tofSdigit); // collect the current sdigit
351 fhitMap->SetHit(vol); // update the hitmap for location vol
353 } // if (hitMap->TestHit(vol) != kEmpty)
355 } // for (Int_t k=0; k<ndig; k++)
356 sdigitsDummyContainer->Delete();
358 } // end loop on entries
360 delete sdigitsDummyContainer;
365 //_____________________________________________________________________________
366 void AliTOFDigitizer::CollectSDigit(AliTOFSDigit * sdigit)
369 // Add a TOF sdigit in container
370 // new with placement must be used
371 TClonesArray &aSDigitsArray = *fSDigitsArray;
372 Int_t last=fSDigitsArray->GetEntriesFast();
373 // make a copy of the current sdigit and
374 // put it into tmp array
375 new (aSDigitsArray[last]) AliTOFSDigit(*sdigit);
378 //_____________________________________________________________________________
379 void AliTOFDigitizer::InitDecalibration( AliTOFcalib *calib){
380 calib->ReadSimParFromCDB("TOF/Calib", 0);
382 //---------------------------------------------------------------------
383 void AliTOFDigitizer::DecalibrateTOFSignal( AliTOFcalib *calib){
385 // Read Calibration parameters from the CDB
387 AliTOFCal * cal= calib->GetTOFCalSimArray();
389 AliInfo(Form("Size of AliTOFCal = %i",cal->NPads()));
390 for (Int_t ipad = 0 ; ipad<cal->NPads(); ipad++){
391 AliTOFChannel *CalChannel = cal->GetChannel(ipad);
393 for (Int_t j = 0; j<6; j++){
394 par[j]=CalChannel->GetSlewPar(j);
398 // Initialize Quantities to Simulate ToT Spectra
401 TH1F * hToT= calib->GetTOFSimToT();
402 Int_t nbins = hToT->GetNbinsX();
403 Float_t Delta = hToT->GetBinWidth(1);
404 Float_t maxch = hToT->GetBinLowEdge(nbins)+Delta;
405 Float_t minch = hToT->GetBinLowEdge(1);
406 Float_t max=0,min=0; //maximum and minimum value of the distribution
407 Int_t maxbin=0,minbin=0; //maximum and minimum bin of the distribution
408 for (Int_t ii=nbins; ii>0; ii--){
409 if (hToT->GetBinContent(ii)!= 0) {
410 max = maxch - (nbins-ii-1)*Delta;
414 for (Int_t j=1; j<nbins; j++){
415 if (hToT->GetBinContent(j)!= 0) {
416 min = minch + (j-1)*Delta;
422 Float_t MaxToTDistr=hToT->GetMaximum();
425 // Loop on TOF Digits
427 Bool_t dbEntry=kFALSE;
428 Int_t ndigits = fDigits->GetEntriesFast();
429 for (Int_t i=0;i<ndigits;i++){
430 AliTOFdigit * dig = (AliTOFdigit*)fDigits->At(i);
432 detId[0] = dig->GetSector();
433 detId[1] = dig->GetPlate();
434 detId[2] = dig->GetStrip();
435 detId[3] = dig->GetPadz();
436 detId[4] = dig->GetPadx();
437 // For Data with no Miscalibration, set ToT signal == Adc
438 dig->SetToT(dig->GetAdc());
439 if(hToT->GetEntries()>0){
443 while (SimToT <= triy){
444 trix = gRandom->Rndm(i);
445 triy = gRandom->Rndm(i);
446 trix = (MaxToT-MinToT)*trix + MinToT;
447 triy = MaxToTDistr*triy;
448 Int_t binx=hToT->FindBin(trix);
449 SimToT=hToT->GetBinContent(binx);
451 // Setting realistic ToT signal (only for Miscalibrated Data)
454 Int_t index = calib->GetIndex(detId);
455 AliTOFChannel *CalChannel = cal->GetChannel(index);
457 for (Int_t j = 0; j<6; j++){
458 par[j]=CalChannel->GetSlewPar(j);
459 if(par[j]!=0)dbEntry=kTRUE;
462 Float_t ToT= dig->GetToT();
463 dig->SetTdcND(dig->GetTdc());
464 Float_t tdc = ((dig->GetTdc())*AliTOFGeometry::TdcBinWidth()+32)*1.E-3; //tof signal in ns
465 Float_t timeoffset=par[0] + ToT*par[1] +ToT*ToT*par[2] +ToT*ToT*ToT*par[3] +ToT*ToT*ToT*ToT*par[4] +ToT*ToT*ToT*ToT*ToT*par[5];
466 Float_t timeSlewed = tdc + timeoffset;
467 // Setting Decalibrated Time signal
468 dig->SetTdc((timeSlewed*1E3-32)/AliTOFGeometry::TdcBinWidth());
471 if(hToT->GetEntries()<=0 || !dbEntry){
472 AliInfo("Standard Production, no miscalibrated digits");
474 AliInfo("Miscalibrated digits");