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