]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TOF/AliTOFDigitizer.cxx
Bug fix in the bin0 loop
[u/mrichter/AliRoot.git] / TOF / AliTOFDigitizer.cxx
CommitLineData
68861244 1/**************************************************************************
8e72349e 2 * Copyright(c) 1998-2000, ALICE Experiment at CERN, All rights reserved. *
68861244 3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
0e46b9ae 16//_________________________________________________________________________//
17// //
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 //
21// same pad. //
22// Digits are written to TreeD in branch "TOF". //
23// //
24// -- Author : F. Pierella (Bologna University) pierella@bo.infn.it //
25// //
26//_________________________________________________________________________//
68861244 27
5c7c93fa 28//#include "Riostream.h"
55cb22a1 29
5c7c93fa 30//#include "TFile.h"
3495d79c 31#include "TMath.h"
3a3ece53 32#include "TH1F.h"
33#include "TTree.h"
34#include "TRandom.h"
10056aa6 35#include "TObjArray.h"
68861244 36
d3c7bfac 37#include "AliLoader.h"
0e46b9ae 38#include "AliLog.h"
d3c7bfac 39#include "AliRunDigitizer.h"
0e46b9ae 40#include "AliRunLoader.h"
41#include "AliRun.h"
68861244 42
0e46b9ae 43#include "AliTOFcalib.h"
3495d79c 44//#include "AliTOFChannelOnlineArray.h"
45//#include "AliTOFChannelOnlineStatusArray.h"
46//#include "AliTOFChannelOffline.h"
55cb22a1 47#include "AliTOFDigitizer.h"
8e72349e 48#include "AliTOFdigit.h"
8e72349e 49#include "AliTOFHitMap.h"
10056aa6 50#include "AliTOFGeometry.h"
0e46b9ae 51#include "AliTOFSDigit.h"
52#include "AliTOF.h"
53
3a3ece53 54extern TDirectory *gDirectory;
5c7c93fa 55//extern TFile *gFile;
3a3ece53 56extern TRandom *gRandom;
57
58extern AliRun *gAlice;
59
60
68861244 61ClassImp(AliTOFDigitizer)
62
8e72349e 63//___________________________________________
655e379f 64 AliTOFDigitizer::AliTOFDigitizer() :
65 AliDigitizer(),
b24266ca 66 fDigits(new TClonesArray("AliTOFdigit",4000)),
67 fSDigitsArray(new TClonesArray("AliTOFSDigit",1000)),
8fc02d6f 68 fhitMap(0x0),
69 fCalib(new AliTOFcalib())
68861244 70{
8e72349e 71 // Default ctor - don't use it
8fc02d6f 72 InitDecalibration();
68861244 73}
74
8e72349e 75//___________________________________________
655e379f 76AliTOFDigitizer::AliTOFDigitizer(AliRunDigitizer* manager):
77 AliDigitizer(manager),
b24266ca 78 fDigits(new TClonesArray("AliTOFdigit",4000)),
79 fSDigitsArray(new TClonesArray("AliTOFSDigit",1000)),
8fc02d6f 80 fhitMap(0x0),
81 fCalib(new AliTOFcalib())
68861244 82{
340693af 83 //ctor with RunDigitizer
8fc02d6f 84 InitDecalibration();
68861244 85}
86
7aeeaf38 87//------------------------------------------------------------------------
655e379f 88AliTOFDigitizer::AliTOFDigitizer(const AliTOFDigitizer &source):
89 AliDigitizer(source),
8fc02d6f 90 fDigits(source.fDigits),
91 fSDigitsArray(source.fSDigitsArray),
92 fhitMap(source.fhitMap),
93 fCalib(source.fCalib)
7aeeaf38 94{
95 // copy constructor
7aeeaf38 96}
97
98//------------------------------------------------------------------------
99 AliTOFDigitizer& AliTOFDigitizer::operator=(const AliTOFDigitizer &source)
100{
101 // ass. op.
8a190ba2 102
103 if (this == &source)
104 return *this;
105
106 AliDigitizer::operator=(source);
107 fDigits=source.fDigits;
108 fSDigitsArray=source.fSDigitsArray;
109 fhitMap=source.fhitMap;
110 fCalib=source.fCalib;
7aeeaf38 111 return *this;
112
113}
114
8e72349e 115//------------------------------------------------------------------------
68861244 116AliTOFDigitizer::~AliTOFDigitizer()
117{
8e72349e 118 // Destructor
8fc02d6f 119 delete fCalib;
b24266ca 120 if (fDigits){
121 fDigits->Delete();
122 delete fDigits;
123 fDigits=0x0;
124 }
125 if (fSDigitsArray){
126 fSDigitsArray->Delete();
127 delete fSDigitsArray;
128 fSDigitsArray=0x0;
129 }
68861244 130}
8e72349e 131
132//---------------------------------------------------------------------
133
d076c8d5 134void AliTOFDigitizer::Exec(Option_t* /*option*/)
68861244 135{
8e72349e 136 //
137 // Perform digitization and merging.
138 // The algorithm is the following:
139 // - a hitmap is created to check if a pad is already activated;
140 // - an sdigits container is created to collect all sdigits from
141 // different files;
142 // - sdigits are summed using the hitmap;
143 // - the sdigits container is used to create the array of AliTOFdigit.
144 //
68861244 145
d076c8d5 146 AliDebug(1, "");
68861244 147
68861244 148
8e72349e 149 // get the ptr to TOF detector
150 AliTOF * tof = (AliTOF *) gAlice->GetDetector("TOF") ;
68861244 151
8e72349e 152 //Make branches
1d834a1e 153
154 const Int_t kSize = 20;
155 char branchname[kSize];
156 snprintf(branchname,kSize,"%s", tof->GetName ());
88cb7938 157
158 AliRunLoader* outrl = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
159 if (outrl == 0x0)
160 {
d076c8d5 161 AliError("Can not find Run Loader in output folder.");
88cb7938 162 return;
163 }
164
165 AliLoader* outgime = outrl->GetLoader("TOFLoader");
166 if (outgime == 0x0)
167 {
d076c8d5 168 AliError("Can not get TOF Loader from Output Run Loader.");
88cb7938 169 return;
170 }
171
172 TTree* treeD = outgime->TreeD();
173 if (treeD == 0x0)
174 {
175 outgime->MakeTree("D");
176 treeD = outgime->TreeD();
177 }
8e72349e 178 //Make branch for digits (to be created in Init())
179 tof->MakeBranchInTree(treeD,branchname,&fDigits,4000);
180
181 // container for all summed sdigits (to be created in Init())
95b42457 182 //fSDigitsArray=new TClonesArray("AliTOFSDigit",1000);
68861244 183
8e72349e 184 // create hit map (to be created in Init())
10056aa6 185 fhitMap = new AliTOFHitMap(fSDigitsArray);
68861244 186
8e72349e 187 // Loop over files to digitize
188
189 for (Int_t inputFile=0; inputFile<fManager->GetNinputs();
190 inputFile++) {
191 ReadSDigit(inputFile);
88cb7938 192 }
8e72349e 193
194 // create digits
195 CreateDigits();
196
197 // free used memory for Hit Map in current event
198 delete fhitMap;
95b42457 199 fSDigitsArray->Clear();
a5c70f8e 200
8e72349e 201 treeD->Fill();
c630773f 202
4d1c7395 203 AliDebug(2,"----------------------------------------");
fda219f1 204 AliDebug(1,Form("%d digits have been created", fDigits->GetEntriesFast()));
4d1c7395 205 AliDebug(2,"----------------------------------------");
c630773f 206
88cb7938 207 outgime->WriteDigits("OVERWRITE");
208 outgime->UnloadDigits();
b24266ca 209 fDigits->Clear();
8e72349e 210
211}
212
213//---------------------------------------------------------------------
214
55cb22a1 215void AliTOFDigitizer::CreateDigits()
8e72349e 216{
217 // loop on sdigits container to fill the AliTOFdigit TClonesArray
218 // start digitizing all the collected sdigits
219
c7764ee9 220 Int_t ndump=0; // dump the first ndump created digits for each event
8e72349e 221
222 // get the total number of collected sdigits
223 Int_t ndig = fSDigitsArray->GetEntriesFast();
224
3495d79c 225 Int_t vol[5]={-1,-1,-1,-1,-1}; // location for a digit
226 Int_t digit[4] = {0,0,0,0}; // TOF digit variables
227 Int_t tracknum[AliTOFSDigit::kMAXDIGITS]; // contributing tracks for the current slot
228 for (Int_t aa=0; aa<AliTOFSDigit::kMAXDIGITS; aa++) tracknum[aa] = -1;
229
8e72349e 230 for (Int_t k = 0; k < ndig; k++) {
68861244 231
7e6dce66 232 for (Int_t i=0; i<5; i++) vol[i] = -1;
68861244 233
8e72349e 234 // Get the information for this digit
235 AliTOFSDigit *tofsdigit = (AliTOFSDigit *) fSDigitsArray->UncheckedAt(k);
68861244 236
8e72349e 237 Int_t nslot=tofsdigit->GetNDigits(); // get the number of slots
238 // for current sdigit
68861244 239
8e72349e 240 // TOF sdigit volumes (always the same for all slots)
da3d3acd 241 Int_t sector = tofsdigit->GetSector(); // range [0-17]
242 Int_t plate = tofsdigit->GetPlate(); // range [0- 4]
d3c7bfac 243 Int_t strip = tofsdigit->GetStrip(); // range [0-14/18/19]
da3d3acd 244 Int_t padz = tofsdigit->GetPadz(); // range [0- 1]
245 Int_t padx = tofsdigit->GetPadx(); // range [0-47]
68861244 246
8e72349e 247 vol[0] = sector;
248 vol[1] = plate;
249 vol[2] = strip;
250 vol[3] = padx;
251 vol[4] = padz;
68861244 252
8e72349e 253 //--------------------- QA section ----------------------
254 // in the while, I perform QA
7e6dce66 255 Bool_t isSDigitBad = (sector<0 || sector>17 || plate<0 || plate >4 || padz<0 || padz>1 || padx<0 || padx>47);
68861244 256
4d1c7395 257 if (isSDigitBad)
258 AliFatal(Form("strange sdigit found %2d %1d %2d %1d %2d", sector, plate, strip, padz, padx));
8e72349e 259 //-------------------------------------------------------
68861244 260
8e72349e 261 //------------------- Dump section ----------------------
4d1c7395 262 if (k<ndump) {
263 AliInfo(Form("%2d-th digit: Sector %2d | Plate %1d | Strip %2d | PadZ %1d | PadX %2d ", k, sector, plate, strip, padz, padx));
3a3ece53 264 AliInfo("----------------------------------------------------");
68861244 265 }
8e72349e 266 // ------------------------------------------------------
68861244 267
8e72349e 268 // start loop on number of slots for current sdigit
269 for (Int_t islot = 0; islot < nslot; islot++) {
3495d79c 270 for (Int_t aa=0; aa<4; aa++) digit[aa] = 0; // TOF digit variables
271 for (Int_t aa=0; aa<AliTOFSDigit::kMAXDIGITS; aa++) tracknum[aa] = -1;
8e72349e 272
bf33f8f0 273 Int_t tdc=tofsdigit->GetTdc(islot); digit[0]=tdc;
274 Int_t adc=tofsdigit->GetAdc(islot); digit[1]=adc;
3e2f0097 275
276 //if (tdc>=8192) continue;//AdC
277
8e72349e 278 tracknum[0]=tofsdigit->GetTrack(islot,0);
279 tracknum[1]=tofsdigit->GetTrack(islot,1);
280 tracknum[2]=tofsdigit->GetTrack(islot,2);
68861244 281
7f1e928b 282 // new with placement must be used
8e72349e 283 // adding a TOF digit for each slot
7f1e928b 284 TClonesArray &aDigits = *fDigits;
285 Int_t last=fDigits->GetEntriesFast();
286 new (aDigits[last]) AliTOFdigit(tracknum, vol, digit);
287
68861244 288 }
68861244 289
8e72349e 290 } // end loop on sdigits - end digitizing all collected sdigits
55cb22a1 291
292 //Insert Decalibration
4d1c7395 293 AliDebug(2,"in digitizer, create digits");
8fc02d6f 294 DecalibrateTOFSignal();
68861244 295}
8e72349e 296
297//---------------------------------------------------------------------
298
299void AliTOFDigitizer::ReadSDigit(Int_t inputFile )
68861244 300{
8e72349e 301 // Read sdigits for current event and inputFile;
302 // store them into the sdigits container
303 // and update the hit map
304 // SDigits from different files are assumed to
305 // be created with the same simulation parameters.
68861244 306
b24266ca 307 // creating the TClonesArray to store the digits
308 static TClonesArray sdigitsClonesArray("AliTOFSDigit", 1000);
309 sdigitsClonesArray.Clear();
310
8e72349e 311 // get the treeS from manager
88cb7938 312 AliRunLoader* rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(inputFile));
313 if (rl == 0x0)
314 {
d076c8d5 315 AliError(Form("Can not find Run Loader in input %d folder.",inputFile));
88cb7938 316 return;
317 }
318
319 AliLoader* gime = rl->GetLoader("TOFLoader");
320 if (gime == 0x0)
321 {
d076c8d5 322 AliError(Form("Can not get TOF Loader from Input %d Run Loader.",inputFile));
88cb7938 323 return;
324 }
325
326 TTree* currentTreeS=gime->TreeS();
327 if (currentTreeS == 0x0)
328 {
329 Int_t retval = gime->LoadSDigits();
330 if (retval)
331 {
d076c8d5 332 AliError(Form("Error occured while loading S. Digits for Input %d",inputFile));
88cb7938 333 return;
334 }
335 currentTreeS=gime->TreeS();
336 if (currentTreeS == 0x0)
337 {
d076c8d5 338 AliError(Form("Can not get S. Digits Tree for Input %d",inputFile));
88cb7938 339 return;
340 }
341 }
8e72349e 342 // get the branch TOF inside the treeS
b24266ca 343 TClonesArray * sdigitsDummyContainer=&sdigitsClonesArray;
8e72349e 344 // check if the branch exist
345 TBranch* tofBranch=currentTreeS->GetBranch("TOF");
346
347 if(!tofBranch){
d076c8d5 348 AliFatal(Form("TOF branch not found for input %d",inputFile));
8e72349e 349 }
68861244 350
8e72349e 351 tofBranch->SetAddress(&sdigitsDummyContainer);
68861244 352
8e72349e 353 Int_t nEntries = (Int_t)tofBranch->GetEntries();
354
355 // Loop through all entries in the tree
b020b05f 356 Int_t nbytes = 0;
8e72349e 357
3495d79c 358 Int_t vol[5]; // location for a sdigit
359 for (Int_t i=0; i<5; i++) vol[i] = -1;
360
8e72349e 361 for (Int_t iEntry = 0; iEntry < nEntries; iEntry++) {
68861244 362
8e72349e 363 // Import the tree
364 nbytes += tofBranch->GetEvent(iEntry);
68861244 365
8e72349e 366 // Get the number of sdigits
367 Int_t ndig = sdigitsDummyContainer->GetEntriesFast();
368
369 for (Int_t k=0; k<ndig; k++) {
370 AliTOFSDigit *tofSdigit= (AliTOFSDigit*) sdigitsDummyContainer->UncheckedAt(k);
371
7e6dce66 372 for (Int_t i=0; i<5; i++) vol[i] = -1;
da3d3acd 373
8e72349e 374 // check the sdigit volume
375 vol[0] = tofSdigit->GetSector();
376 vol[1] = tofSdigit->GetPlate();
377 vol[2] = tofSdigit->GetStrip();
378 vol[3] = tofSdigit->GetPadx();
379 vol[4] = tofSdigit->GetPadz();
380
381 if (fhitMap->TestHit(vol) != kEmpty) {
382 AliTOFSDigit *sdig = static_cast<AliTOFSDigit*>(fhitMap->GetHit(vol));
383 sdig->Update(tofSdigit);
384
385 } else {
386
387 CollectSDigit(tofSdigit); // collect the current sdigit
388 fhitMap->SetHit(vol); // update the hitmap for location vol
389
390 } // if (hitMap->TestHit(vol) != kEmpty)
391
392 } // for (Int_t k=0; k<ndig; k++)
393
394 } // end loop on entries
395
8e72349e 396}
397
398
399//_____________________________________________________________________________
b62cc3d6 400void AliTOFDigitizer::CollectSDigit(const AliTOFSDigit * const sdigit)
8e72349e 401{
402 //
7f1e928b 403 // Add a TOF sdigit in container
404 // new with placement must be used
405 TClonesArray &aSDigitsArray = *fSDigitsArray;
406 Int_t last=fSDigitsArray->GetEntriesFast();
407 // make a copy of the current sdigit and
408 // put it into tmp array
409 new (aSDigitsArray[last]) AliTOFSDigit(*sdigit);
68861244 410}
55cb22a1 411
412//_____________________________________________________________________________
8fc02d6f 413void AliTOFDigitizer::InitDecalibration() const {
8a7fda6f 414 //
b62cc3d6 415 // Initialize TOF digits decalibration
8a7fda6f 416 //
417
3495d79c 418 fCalib->Init();
419 /*
8fc02d6f 420 fCalib->CreateCalArrays();
421 fCalib->ReadSimHistoFromCDB("TOF/Calib", -1); // use AliCDBManager's number
422 fCalib->ReadParOfflineFromCDB("TOF/Calib", -1); // use AliCDBManager's number
3495d79c 423 */
424}
425//---------------------------------------------------------------------
426void AliTOFDigitizer::DecalibrateTOFSignal() {
427 //
428 // Decalibrate TOF signals according to OCDB parameters
429 //
430
431 Double_t time=0., tot=0., corr=0.;
432 Int_t deltaBC=0, l0l1=0, tdcBin=0;
433 Int_t index = -1;
434 Int_t detId[5] ={-1,-1,-1,-1,-1};
435 UInt_t timestamp=0;
436
437 Int_t ndigits = fDigits->GetEntriesFast();
438 // Loop on TOF Digits
439 for (Int_t i=0;i<ndigits;i++){
440 AliTOFdigit * dig = (AliTOFdigit*)fDigits->At(i);
441 detId[0] = dig->GetSector();
442 detId[1] = dig->GetPlate();
443 detId[2] = dig->GetStrip();
444 detId[3] = dig->GetPadz();
445 detId[4] = dig->GetPadx();
446 dig->SetTdcND(dig->GetTdc()); // save the non decalibrated time
447
448 index = AliTOFGeometry::GetIndex(detId); // The channel index
449
450 // Read Calibration parameters from the CDB
451 // get digit info
452 time = dig->GetTdc() * AliTOFGeometry::TdcBinWidth(); /* ps */
453 tot = dig->GetToT() * AliTOFGeometry::ToTBinWidth() * 1.e-3; /* ns */
454 deltaBC = 0;//dig->GetDeltaBC();
455 l0l1 = 0;//dig->GetL0L1Latency();
456
457 // get correction
458 corr = fCalib->GetTimeCorrection(index, tot, deltaBC, l0l1, timestamp); /* ps */
459 AliDebug(2, Form("calibrate index %d: time=%f (ps) tot=%f (ns) deltaBC=%d l0l1=%d timestamp=%d corr=%f (ps)",
460 index, time, tot, deltaBC, l0l1, timestamp, corr));
461
462 // apply time correction
463 time += corr;
464
465 // convert in TDC bins and set digit
466 //tdcBin = (Int_t)(time / AliTOFGeometry::TdcBinWidth()); //the corrected time (tdc counts)
467 tdcBin = TMath::Nint(time / AliTOFGeometry::TdcBinWidth()); //the corrected time (tdc counts)
468 dig->SetTdc(tdcBin);
469
470 }
471
472 AliDebug(1,"Simulating miscalibrated digits");
473
474 return;
55cb22a1 475}
3495d79c 476
55cb22a1 477//---------------------------------------------------------------------
3495d79c 478/*
479void AliTOFDigitizer::DecalibrateTOFSignal(){ // Old implementation
55cb22a1 480
481 // Read Calibration parameters from the CDB
482
8fc02d6f 483 TObjArray * calOffline= fCalib->GetTOFCalArrayOffline();
55cb22a1 484
10056aa6 485 AliDebug(2,Form("Size of array for Offline Calibration = %i",calOffline->GetEntries()));
55cb22a1 486
487 // Initialize Quantities to Simulate ToT Spectra
488
8fc02d6f 489 TH1F * hToT= fCalib->GetTOFSimToT();
55cb22a1 490 Int_t nbins = hToT->GetNbinsX();
340693af 491 Float_t delta = hToT->GetBinWidth(1);
492 Float_t maxch = hToT->GetBinLowEdge(nbins)+delta;
55cb22a1 493 Float_t minch = hToT->GetBinLowEdge(1);
494 Float_t max=0,min=0; //maximum and minimum value of the distribution
495 Int_t maxbin=0,minbin=0; //maximum and minimum bin of the distribution
b97b1350 496
55cb22a1 497 for (Int_t ii=nbins; ii>0; ii--){
498 if (hToT->GetBinContent(ii)!= 0) {
340693af 499 max = maxch - (nbins-ii-1)*delta;
55cb22a1 500 maxbin = ii;
501 break;}
502 }
503 for (Int_t j=1; j<nbins; j++){
504 if (hToT->GetBinContent(j)!= 0) {
340693af 505 min = minch + (j-1)*delta;
55cb22a1 506 minbin = j;
507 break;}
508 }
b97b1350 509
340693af 510 Float_t maxToT=max;
511 Float_t minToT=min;
bf33f8f0 512
340693af 513 Float_t maxToTDistr=hToT->GetMaximum();
bf33f8f0 514
515 AliDebug (1, Form(" The minimum ToT = %f", minToT));
516 AliDebug (1, Form(" The maximum ToT = %f", maxToT));
517 AliDebug (1, Form(" The maximum peak in ToT = %f", maxToTDistr));
55cb22a1 518
55cb22a1 519 // Loop on TOF Digits
520
b97b1350 521 Bool_t isToTSimulated=kFALSE;
522 Bool_t misCalibPars=kFALSE;
523 if(hToT->GetEntries()>0)isToTSimulated=kTRUE;
10056aa6 524 Int_t ndigits = fDigits->GetEntriesFast();
55cb22a1 525 for (Int_t i=0;i<ndigits;i++){
526 AliTOFdigit * dig = (AliTOFdigit*)fDigits->At(i);
527 Int_t detId[5];
528 detId[0] = dig->GetSector();
529 detId[1] = dig->GetPlate();
530 detId[2] = dig->GetStrip();
531 detId[3] = dig->GetPadz();
532 detId[4] = dig->GetPadx();
b97b1350 533 dig->SetTdcND(dig->GetTdc()); // save the non decalibrated time
534 if(isToTSimulated){
535
536 //A realistic ToT Spectrum was found in input,
537 //decalibrated TOF Digits likely to be simulated....
538
10056aa6 539 Int_t index = AliTOFGeometry::GetIndex(detId); // The channel index
10056aa6 540 AliTOFChannelOffline *calChannelOffline = (AliTOFChannelOffline *)calOffline->At(index); //retrieve the info for time slewing
10056aa6 541 Double_t par[6]; // time slewing parameters
b97b1350 542
543 //check whether we actually ask for miscalibration
544
b97b1350 545 for (Int_t j = 0; j<6; j++){
10056aa6 546 par[j]=(Double_t)calChannelOffline->GetSlewPar(j);
b97b1350 547 if(par[j]!=0)misCalibPars=kTRUE;
548 }
40212801 549 AliDebug(2,Form(" Calib Pars = %f (0-th parameter for time slewing + time delay), %f, %f, %f, %f, %f ",par[0],par[1],par[2],par[3],par[4],par[5]));
550
b97b1350 551 // Now generate Realistic ToT distribution from TestBeam Data.
552 // Tot is in ns, assuming a Matching Window of 10 ns.
553
554 Float_t simToT = 0;
55cb22a1 555 Float_t trix = 0;
556 Float_t triy = 0;
72fb5d2e 557 Double_t timeCorr;
558 Double_t tToT;
340693af 559 while (simToT <= triy){
55cb22a1 560 trix = gRandom->Rndm(i);
561 triy = gRandom->Rndm(i);
340693af 562 trix = (maxToT-minToT)*trix + minToT;
563 triy = maxToTDistr*triy;
55cb22a1 564 Int_t binx=hToT->FindBin(trix);
340693af 565 simToT=hToT->GetBinContent(binx);
55cb22a1 566 }
b97b1350 567 // the generated ToT (ns)
72fb5d2e 568 tToT= (Double_t) trix; // to apply slewing we start from ns..
569 // transform TOF signal in ns
570 AliDebug(2,Form(" The Initial Time (counts): %i: ",dig->GetTdc()));
10056aa6 571 AliDebug(2,Form(" Time before miscalibration (ps) %e: ",dig->GetTdc()*(Double_t)AliTOFGeometry::TdcBinWidth()));
b97b1350 572 // add slewing effect
72fb5d2e 573 timeCorr=par[0] + tToT*(par[1] +tToT*(par[2] +tToT*(par[3] +tToT*(par[4] +tToT*par[5]))));
40212801 574 AliDebug(2,Form(" The Time slewing + delay (ns): %f: ",timeCorr));
b97b1350 575 // add global time shift
72fb5d2e 576 //convert to ps
54d4fb19 577 timeCorr*=1E3;
10056aa6 578 Double_t timeMis = (Double_t)(dig->GetTdc())*(Double_t)AliTOFGeometry::TdcBinWidth();
72fb5d2e 579 timeMis = timeMis+timeCorr;
580 AliDebug(2,Form(" The Miscalibrated time (ps): %e: ",timeMis));
581
582 // now update the digit info
583
584 Int_t tdcCorr= (Int_t)(timeMis/AliTOFGeometry::TdcBinWidth());
585 AliDebug(2,Form(" Final Time (counts): %i: ",tdcCorr));
bf33f8f0 586 // Setting Decalibrated Time signal (TDC counts)
72fb5d2e 587 dig->SetTdc(tdcCorr);
588 // Setting realistic ToT signal (TDC counts)
589 tToT*=1E3; //back to ps
590 Int_t tot=(Int_t)(tToT/AliTOFGeometry::ToTBinWidth());//(factor 1E3 as input ToT is in ns)
bf33f8f0 591 dig->SetToT(tot);
4d1c7395 592 AliDebug(2,Form(" Final Time and ToT (counts): %d: , %d:",dig->GetTdc(),dig->GetToT()));
72fb5d2e 593 if(tdcCorr<0){
4d1c7395 594 AliWarning (Form(" The bad Slewed Time(TDC counts)= %d ", tdcCorr));
595 AliWarning(Form(" The bad ToT (TDC counts)= %d ", tot));
bf33f8f0 596 }
55cb22a1 597 }
b97b1350 598 else{
599 // For Data with no Miscalibration, set ToT signal == Adc
bf33f8f0 600 dig->SetToT((Int_t)(dig->GetAdc()/AliTOFGeometry::ToTBinWidth())); //remove the factor 10^3 just to have a reasonable ToT range for raw data simulation even in the case of non-realistic ToT distribution (n.b. fAdc is practically an arbitrary quantity, and ToT has no impact on the TOF reco for non-miscalibrated digits)
55cb22a1 601 }
55cb22a1 602 }
603
4d1c7395 604 if(!isToTSimulated)
605 AliDebug(1,"Standard Production, no miscalibrated digits");
606 else
607 if(!misCalibPars)
608 AliDebug(1,"Standard Production, no miscalibrated digits");
609 else
610 AliDebug(1,"Simulating miscalibrated digits");
611
55cb22a1 612 return;
613}
3495d79c 614*/