]>
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" |
3a3ece53 | 31 | #include "TH1F.h" |
32 | #include "TTree.h" | |
33 | #include "TRandom.h" | |
10056aa6 | 34 | #include "TObjArray.h" |
68861244 | 35 | |
d3c7bfac | 36 | #include "AliLoader.h" |
0e46b9ae | 37 | #include "AliLog.h" |
d3c7bfac | 38 | #include "AliRunDigitizer.h" |
0e46b9ae | 39 | #include "AliRunLoader.h" |
40 | #include "AliRun.h" | |
68861244 | 41 | |
0e46b9ae | 42 | #include "AliTOFcalib.h" |
5c7c93fa | 43 | //#include "AliTOFChannelOnline.h" |
10056aa6 | 44 | #include "AliTOFChannelOffline.h" |
55cb22a1 | 45 | #include "AliTOFDigitizer.h" |
8e72349e | 46 | #include "AliTOFdigit.h" |
8e72349e | 47 | #include "AliTOFHitMap.h" |
10056aa6 | 48 | #include "AliTOFGeometry.h" |
0e46b9ae | 49 | #include "AliTOFSDigit.h" |
50 | #include "AliTOF.h" | |
51 | ||
3a3ece53 | 52 | extern TDirectory *gDirectory; |
5c7c93fa | 53 | //extern TFile *gFile; |
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 | //___________________________________________ |
655e379f | 74 | AliTOFDigitizer::AliTOFDigitizer(AliRunDigitizer* manager): |
75 | AliDigitizer(manager), | |
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 | ||
d076c8d5 | 132 | void AliTOFDigitizer::Exec(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 |
151 | char branchname[20]; | |
152 | sprintf (branchname, "%s", tof->GetName ()); | |
88cb7938 | 153 | |
154 | AliRunLoader* outrl = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName()); | |
155 | if (outrl == 0x0) | |
156 | { | |
d076c8d5 | 157 | AliError("Can not find Run Loader in output folder."); |
88cb7938 | 158 | return; |
159 | } | |
160 | ||
10056aa6 | 161 | /* |
d3c7bfac | 162 | outrl->CdGAFile(); |
163 | TFile *in=(TFile*)gFile; | |
164 | TDirectory *savedir=gDirectory; | |
165 | ||
10056aa6 | 166 | |
167 | //when fGeom was needed | |
168 | ||
d3c7bfac | 169 | if (!in->IsOpen()) { |
170 | AliWarning("Geometry file is not open default TOF geometry will be used"); | |
10056aa6 | 171 | fGeom = new AliTOFGeometry(); |
d3c7bfac | 172 | } |
173 | else { | |
174 | in->cd(); | |
55cb22a1 | 175 | fGeom = (AliTOFGeometry*)in->Get("TOFgeometry"); |
d3c7bfac | 176 | } |
10056aa6 | 177 | |
d3c7bfac | 178 | savedir->cd(); |
10056aa6 | 179 | */ |
88cb7938 | 180 | AliLoader* outgime = outrl->GetLoader("TOFLoader"); |
181 | if (outgime == 0x0) | |
182 | { | |
d076c8d5 | 183 | AliError("Can not get TOF Loader from Output Run Loader."); |
88cb7938 | 184 | return; |
185 | } | |
186 | ||
187 | TTree* treeD = outgime->TreeD(); | |
188 | if (treeD == 0x0) | |
189 | { | |
190 | outgime->MakeTree("D"); | |
191 | treeD = outgime->TreeD(); | |
192 | } | |
8e72349e | 193 | //Make branch for digits (to be created in Init()) |
194 | tof->MakeBranchInTree(treeD,branchname,&fDigits,4000); | |
195 | ||
196 | // container for all summed sdigits (to be created in Init()) | |
95b42457 | 197 | //fSDigitsArray=new TClonesArray("AliTOFSDigit",1000); |
68861244 | 198 | |
8e72349e | 199 | // create hit map (to be created in Init()) |
10056aa6 | 200 | fhitMap = new AliTOFHitMap(fSDigitsArray); |
68861244 | 201 | |
8e72349e | 202 | // Loop over files to digitize |
203 | ||
204 | for (Int_t inputFile=0; inputFile<fManager->GetNinputs(); | |
205 | inputFile++) { | |
206 | ReadSDigit(inputFile); | |
88cb7938 | 207 | } |
8e72349e | 208 | |
209 | // create digits | |
210 | CreateDigits(); | |
211 | ||
212 | // free used memory for Hit Map in current event | |
213 | delete fhitMap; | |
95b42457 | 214 | fSDigitsArray->Clear(); |
a5c70f8e | 215 | |
8e72349e | 216 | treeD->Fill(); |
217 | ||
88cb7938 | 218 | outgime->WriteDigits("OVERWRITE"); |
219 | outgime->UnloadDigits(); | |
b24266ca | 220 | fDigits->Clear(); |
8e72349e | 221 | |
222 | } | |
223 | ||
224 | //--------------------------------------------------------------------- | |
225 | ||
55cb22a1 | 226 | void AliTOFDigitizer::CreateDigits() |
8e72349e | 227 | { |
228 | // loop on sdigits container to fill the AliTOFdigit TClonesArray | |
229 | // start digitizing all the collected sdigits | |
230 | ||
c7764ee9 | 231 | Int_t ndump=0; // dump the first ndump created digits for each event |
8e72349e | 232 | |
233 | // get the total number of collected sdigits | |
234 | Int_t ndig = fSDigitsArray->GetEntriesFast(); | |
235 | ||
236 | for (Int_t k = 0; k < ndig; k++) { | |
68861244 | 237 | |
da3d3acd | 238 | Int_t vol[5]; // location for a digit |
7e6dce66 | 239 | for (Int_t i=0; i<5; i++) vol[i] = -1; |
68861244 | 240 | |
8e72349e | 241 | // Get the information for this digit |
242 | AliTOFSDigit *tofsdigit = (AliTOFSDigit *) fSDigitsArray->UncheckedAt(k); | |
68861244 | 243 | |
8e72349e | 244 | Int_t nslot=tofsdigit->GetNDigits(); // get the number of slots |
245 | // for current sdigit | |
68861244 | 246 | |
8e72349e | 247 | // TOF sdigit volumes (always the same for all slots) |
da3d3acd | 248 | Int_t sector = tofsdigit->GetSector(); // range [0-17] |
249 | Int_t plate = tofsdigit->GetPlate(); // range [0- 4] | |
d3c7bfac | 250 | Int_t strip = tofsdigit->GetStrip(); // range [0-14/18/19] |
da3d3acd | 251 | Int_t padz = tofsdigit->GetPadz(); // range [0- 1] |
252 | Int_t padx = tofsdigit->GetPadx(); // range [0-47] | |
68861244 | 253 | |
8e72349e | 254 | vol[0] = sector; |
255 | vol[1] = plate; | |
256 | vol[2] = strip; | |
257 | vol[3] = padx; | |
258 | vol[4] = padz; | |
68861244 | 259 | |
8e72349e | 260 | //--------------------- QA section ---------------------- |
261 | // in the while, I perform QA | |
7e6dce66 | 262 | Bool_t isSDigitBad = (sector<0 || sector>17 || plate<0 || plate >4 || padz<0 || padz>1 || padx<0 || padx>47); |
68861244 | 263 | |
8e72349e | 264 | if (isSDigitBad) { |
d3c7bfac | 265 | //AliFatal("strange sdigit found"); |
266 | AliFatal(Form("strange sdigit found %3i %2i %2i %3i %3i", sector, plate, padz, padx, strip)); | |
68861244 | 267 | } |
8e72349e | 268 | //------------------------------------------------------- |
68861244 | 269 | |
8e72349e | 270 | //------------------- Dump section ---------------------- |
271 | if(k<ndump){ | |
3a3ece53 | 272 | AliInfo(Form("%2i-th | Sector %2i | Plate %1i | Strip %2i | PadZ %1i | PadX %2i ", k, sector, plate, strip, padz, padx)); |
273 | AliInfo(Form("%2i-th", k)); | |
274 | AliInfo("----------------------------------------------------"); | |
68861244 | 275 | } |
8e72349e | 276 | // ------------------------------------------------------ |
68861244 | 277 | |
8e72349e | 278 | // start loop on number of slots for current sdigit |
279 | for (Int_t islot = 0; islot < nslot; islot++) { | |
bf33f8f0 | 280 | Int_t digit[4] = {-1,-1,-1,-1}; // TOF digit variables |
7aeeaf38 | 281 | Int_t tracknum[AliTOFSDigit::kMAXDIGITS]; // contributing tracks for the current slot |
8e72349e | 282 | |
bf33f8f0 | 283 | Int_t tdc=tofsdigit->GetTdc(islot); digit[0]=tdc; |
284 | Int_t adc=tofsdigit->GetAdc(islot); digit[1]=adc; | |
3e2f0097 | 285 | |
286 | //if (tdc>=8192) continue;//AdC | |
287 | ||
8e72349e | 288 | tracknum[0]=tofsdigit->GetTrack(islot,0); |
289 | tracknum[1]=tofsdigit->GetTrack(islot,1); | |
290 | tracknum[2]=tofsdigit->GetTrack(islot,2); | |
68861244 | 291 | |
7f1e928b | 292 | // new with placement must be used |
8e72349e | 293 | // adding a TOF digit for each slot |
7f1e928b | 294 | TClonesArray &aDigits = *fDigits; |
295 | Int_t last=fDigits->GetEntriesFast(); | |
296 | new (aDigits[last]) AliTOFdigit(tracknum, vol, digit); | |
297 | ||
68861244 | 298 | } |
68861244 | 299 | |
8e72349e | 300 | } // end loop on sdigits - end digitizing all collected sdigits |
55cb22a1 | 301 | |
302 | //Insert Decalibration | |
10056aa6 | 303 | AliInfo("in digitizer, create digits"); |
8fc02d6f | 304 | DecalibrateTOFSignal(); |
68861244 | 305 | } |
8e72349e | 306 | |
307 | //--------------------------------------------------------------------- | |
308 | ||
309 | void AliTOFDigitizer::ReadSDigit(Int_t inputFile ) | |
68861244 | 310 | { |
8e72349e | 311 | // Read sdigits for current event and inputFile; |
312 | // store them into the sdigits container | |
313 | // and update the hit map | |
314 | // SDigits from different files are assumed to | |
315 | // be created with the same simulation parameters. | |
68861244 | 316 | |
b24266ca | 317 | // creating the TClonesArray to store the digits |
318 | static TClonesArray sdigitsClonesArray("AliTOFSDigit", 1000); | |
319 | sdigitsClonesArray.Clear(); | |
320 | ||
8e72349e | 321 | // get the treeS from manager |
88cb7938 | 322 | AliRunLoader* rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(inputFile)); |
323 | if (rl == 0x0) | |
324 | { | |
d076c8d5 | 325 | AliError(Form("Can not find Run Loader in input %d folder.",inputFile)); |
88cb7938 | 326 | return; |
327 | } | |
328 | ||
329 | AliLoader* gime = rl->GetLoader("TOFLoader"); | |
330 | if (gime == 0x0) | |
331 | { | |
d076c8d5 | 332 | AliError(Form("Can not get TOF Loader from Input %d Run Loader.",inputFile)); |
88cb7938 | 333 | return; |
334 | } | |
335 | ||
336 | TTree* currentTreeS=gime->TreeS(); | |
337 | if (currentTreeS == 0x0) | |
338 | { | |
339 | Int_t retval = gime->LoadSDigits(); | |
340 | if (retval) | |
341 | { | |
d076c8d5 | 342 | AliError(Form("Error occured while loading S. Digits for Input %d",inputFile)); |
88cb7938 | 343 | return; |
344 | } | |
345 | currentTreeS=gime->TreeS(); | |
346 | if (currentTreeS == 0x0) | |
347 | { | |
d076c8d5 | 348 | AliError(Form("Can not get S. Digits Tree for Input %d",inputFile)); |
88cb7938 | 349 | return; |
350 | } | |
351 | } | |
8e72349e | 352 | // get the branch TOF inside the treeS |
b24266ca | 353 | TClonesArray * sdigitsDummyContainer=&sdigitsClonesArray; |
8e72349e | 354 | // check if the branch exist |
355 | TBranch* tofBranch=currentTreeS->GetBranch("TOF"); | |
356 | ||
357 | if(!tofBranch){ | |
d076c8d5 | 358 | AliFatal(Form("TOF branch not found for input %d",inputFile)); |
8e72349e | 359 | } |
68861244 | 360 | |
8e72349e | 361 | tofBranch->SetAddress(&sdigitsDummyContainer); |
68861244 | 362 | |
8e72349e | 363 | Int_t nEntries = (Int_t)tofBranch->GetEntries(); |
364 | ||
365 | // Loop through all entries in the tree | |
b020b05f | 366 | Int_t nbytes = 0; |
8e72349e | 367 | |
368 | for (Int_t iEntry = 0; iEntry < nEntries; iEntry++) { | |
68861244 | 369 | |
8e72349e | 370 | // Import the tree |
371 | nbytes += tofBranch->GetEvent(iEntry); | |
68861244 | 372 | |
8e72349e | 373 | // Get the number of sdigits |
374 | Int_t ndig = sdigitsDummyContainer->GetEntriesFast(); | |
375 | ||
376 | for (Int_t k=0; k<ndig; k++) { | |
377 | AliTOFSDigit *tofSdigit= (AliTOFSDigit*) sdigitsDummyContainer->UncheckedAt(k); | |
378 | ||
da3d3acd | 379 | Int_t vol[5]; // location for a sdigit |
7e6dce66 | 380 | for (Int_t i=0; i<5; i++) vol[i] = -1; |
da3d3acd | 381 | |
8e72349e | 382 | // check the sdigit volume |
383 | vol[0] = tofSdigit->GetSector(); | |
384 | vol[1] = tofSdigit->GetPlate(); | |
385 | vol[2] = tofSdigit->GetStrip(); | |
386 | vol[3] = tofSdigit->GetPadx(); | |
387 | vol[4] = tofSdigit->GetPadz(); | |
388 | ||
389 | if (fhitMap->TestHit(vol) != kEmpty) { | |
390 | AliTOFSDigit *sdig = static_cast<AliTOFSDigit*>(fhitMap->GetHit(vol)); | |
391 | sdig->Update(tofSdigit); | |
392 | ||
393 | } else { | |
394 | ||
395 | CollectSDigit(tofSdigit); // collect the current sdigit | |
396 | fhitMap->SetHit(vol); // update the hitmap for location vol | |
397 | ||
398 | } // if (hitMap->TestHit(vol) != kEmpty) | |
399 | ||
400 | } // for (Int_t k=0; k<ndig; k++) | |
401 | ||
402 | } // end loop on entries | |
403 | ||
8e72349e | 404 | } |
405 | ||
406 | ||
407 | //_____________________________________________________________________________ | |
408 | void AliTOFDigitizer::CollectSDigit(AliTOFSDigit * sdigit) | |
409 | { | |
410 | // | |
7f1e928b | 411 | // Add a TOF sdigit in container |
412 | // new with placement must be used | |
413 | TClonesArray &aSDigitsArray = *fSDigitsArray; | |
414 | Int_t last=fSDigitsArray->GetEntriesFast(); | |
415 | // make a copy of the current sdigit and | |
416 | // put it into tmp array | |
417 | new (aSDigitsArray[last]) AliTOFSDigit(*sdigit); | |
68861244 | 418 | } |
55cb22a1 | 419 | |
420 | //_____________________________________________________________________________ | |
8fc02d6f | 421 | void AliTOFDigitizer::InitDecalibration() const { |
8a7fda6f | 422 | // |
423 | // | |
424 | // | |
425 | ||
8fc02d6f | 426 | fCalib->CreateCalArrays(); |
427 | fCalib->ReadSimHistoFromCDB("TOF/Calib", -1); // use AliCDBManager's number | |
428 | fCalib->ReadParOfflineFromCDB("TOF/Calib", -1); // use AliCDBManager's number | |
55cb22a1 | 429 | } |
430 | //--------------------------------------------------------------------- | |
8fc02d6f | 431 | void AliTOFDigitizer::DecalibrateTOFSignal(){ |
55cb22a1 | 432 | |
433 | // Read Calibration parameters from the CDB | |
434 | ||
8fc02d6f | 435 | TObjArray * calOffline= fCalib->GetTOFCalArrayOffline(); |
55cb22a1 | 436 | |
10056aa6 | 437 | AliDebug(2,Form("Size of array for Offline Calibration = %i",calOffline->GetEntries())); |
55cb22a1 | 438 | |
439 | // Initialize Quantities to Simulate ToT Spectra | |
440 | ||
8fc02d6f | 441 | TH1F * hToT= fCalib->GetTOFSimToT(); |
55cb22a1 | 442 | Int_t nbins = hToT->GetNbinsX(); |
340693af | 443 | Float_t delta = hToT->GetBinWidth(1); |
444 | Float_t maxch = hToT->GetBinLowEdge(nbins)+delta; | |
55cb22a1 | 445 | Float_t minch = hToT->GetBinLowEdge(1); |
446 | Float_t max=0,min=0; //maximum and minimum value of the distribution | |
447 | Int_t maxbin=0,minbin=0; //maximum and minimum bin of the distribution | |
b97b1350 | 448 | |
55cb22a1 | 449 | for (Int_t ii=nbins; ii>0; ii--){ |
450 | if (hToT->GetBinContent(ii)!= 0) { | |
340693af | 451 | max = maxch - (nbins-ii-1)*delta; |
55cb22a1 | 452 | maxbin = ii; |
453 | break;} | |
454 | } | |
455 | for (Int_t j=1; j<nbins; j++){ | |
456 | if (hToT->GetBinContent(j)!= 0) { | |
340693af | 457 | min = minch + (j-1)*delta; |
55cb22a1 | 458 | minbin = j; |
459 | break;} | |
460 | } | |
b97b1350 | 461 | |
340693af | 462 | Float_t maxToT=max; |
463 | Float_t minToT=min; | |
bf33f8f0 | 464 | |
340693af | 465 | Float_t maxToTDistr=hToT->GetMaximum(); |
bf33f8f0 | 466 | |
467 | AliDebug (1, Form(" The minimum ToT = %f", minToT)); | |
468 | AliDebug (1, Form(" The maximum ToT = %f", maxToT)); | |
469 | AliDebug (1, Form(" The maximum peak in ToT = %f", maxToTDistr)); | |
55cb22a1 | 470 | |
55cb22a1 | 471 | // Loop on TOF Digits |
472 | ||
b97b1350 | 473 | Bool_t isToTSimulated=kFALSE; |
474 | Bool_t misCalibPars=kFALSE; | |
475 | if(hToT->GetEntries()>0)isToTSimulated=kTRUE; | |
10056aa6 | 476 | Int_t ndigits = fDigits->GetEntriesFast(); |
55cb22a1 | 477 | for (Int_t i=0;i<ndigits;i++){ |
478 | AliTOFdigit * dig = (AliTOFdigit*)fDigits->At(i); | |
479 | Int_t detId[5]; | |
480 | detId[0] = dig->GetSector(); | |
481 | detId[1] = dig->GetPlate(); | |
482 | detId[2] = dig->GetStrip(); | |
483 | detId[3] = dig->GetPadz(); | |
484 | detId[4] = dig->GetPadx(); | |
b97b1350 | 485 | dig->SetTdcND(dig->GetTdc()); // save the non decalibrated time |
486 | if(isToTSimulated){ | |
487 | ||
488 | //A realistic ToT Spectrum was found in input, | |
489 | //decalibrated TOF Digits likely to be simulated.... | |
490 | ||
10056aa6 | 491 | Int_t index = AliTOFGeometry::GetIndex(detId); // The channel index |
10056aa6 | 492 | AliTOFChannelOffline *calChannelOffline = (AliTOFChannelOffline *)calOffline->At(index); //retrieve the info for time slewing |
10056aa6 | 493 | Double_t par[6]; // time slewing parameters |
b97b1350 | 494 | |
495 | //check whether we actually ask for miscalibration | |
496 | ||
b97b1350 | 497 | for (Int_t j = 0; j<6; j++){ |
10056aa6 | 498 | par[j]=(Double_t)calChannelOffline->GetSlewPar(j); |
b97b1350 | 499 | if(par[j]!=0)misCalibPars=kTRUE; |
500 | } | |
40212801 | 501 | 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])); |
502 | ||
b97b1350 | 503 | // Now generate Realistic ToT distribution from TestBeam Data. |
504 | // Tot is in ns, assuming a Matching Window of 10 ns. | |
505 | ||
506 | Float_t simToT = 0; | |
55cb22a1 | 507 | Float_t trix = 0; |
508 | Float_t triy = 0; | |
72fb5d2e | 509 | Double_t timeCorr; |
510 | Double_t tToT; | |
340693af | 511 | while (simToT <= triy){ |
55cb22a1 | 512 | trix = gRandom->Rndm(i); |
513 | triy = gRandom->Rndm(i); | |
340693af | 514 | trix = (maxToT-minToT)*trix + minToT; |
515 | triy = maxToTDistr*triy; | |
55cb22a1 | 516 | Int_t binx=hToT->FindBin(trix); |
340693af | 517 | simToT=hToT->GetBinContent(binx); |
55cb22a1 | 518 | } |
b97b1350 | 519 | // the generated ToT (ns) |
72fb5d2e | 520 | tToT= (Double_t) trix; // to apply slewing we start from ns.. |
521 | // transform TOF signal in ns | |
522 | AliDebug(2,Form(" The Initial Time (counts): %i: ",dig->GetTdc())); | |
10056aa6 | 523 | AliDebug(2,Form(" Time before miscalibration (ps) %e: ",dig->GetTdc()*(Double_t)AliTOFGeometry::TdcBinWidth())); |
b97b1350 | 524 | // add slewing effect |
72fb5d2e | 525 | timeCorr=par[0] + tToT*(par[1] +tToT*(par[2] +tToT*(par[3] +tToT*(par[4] +tToT*par[5])))); |
40212801 | 526 | AliDebug(2,Form(" The Time slewing + delay (ns): %f: ",timeCorr)); |
b97b1350 | 527 | // add global time shift |
72fb5d2e | 528 | //convert to ps |
54d4fb19 | 529 | timeCorr*=1E3; |
10056aa6 | 530 | Double_t timeMis = (Double_t)(dig->GetTdc())*(Double_t)AliTOFGeometry::TdcBinWidth(); |
72fb5d2e | 531 | timeMis = timeMis+timeCorr; |
532 | AliDebug(2,Form(" The Miscalibrated time (ps): %e: ",timeMis)); | |
533 | ||
534 | // now update the digit info | |
535 | ||
536 | Int_t tdcCorr= (Int_t)(timeMis/AliTOFGeometry::TdcBinWidth()); | |
537 | AliDebug(2,Form(" Final Time (counts): %i: ",tdcCorr)); | |
bf33f8f0 | 538 | // Setting Decalibrated Time signal (TDC counts) |
72fb5d2e | 539 | dig->SetTdc(tdcCorr); |
540 | // Setting realistic ToT signal (TDC counts) | |
541 | tToT*=1E3; //back to ps | |
542 | Int_t tot=(Int_t)(tToT/AliTOFGeometry::ToTBinWidth());//(factor 1E3 as input ToT is in ns) | |
bf33f8f0 | 543 | dig->SetToT(tot); |
10056aa6 | 544 | AliDebug(2,Form(" Final Time and ToT (counts): %i: , %i:",dig->GetTdc(),dig->GetToT())); |
72fb5d2e | 545 | if(tdcCorr<0){ |
546 | AliWarning (Form(" The bad Slewed Time(TDC counts)= %i ", tdcCorr)); | |
bf33f8f0 | 547 | AliWarning(Form(" The bad ToT (TDC counts)= %i ", tot)); |
548 | } | |
55cb22a1 | 549 | } |
b97b1350 | 550 | else{ |
551 | // For Data with no Miscalibration, set ToT signal == Adc | |
bf33f8f0 | 552 | 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 | 553 | } |
55cb22a1 | 554 | } |
555 | ||
b97b1350 | 556 | if(!isToTSimulated){ |
ba795372 | 557 | AliDebug(1,"Standard Production, no miscalibrated digits"); |
55cb22a1 | 558 | }else{ |
b97b1350 | 559 | if(!misCalibPars){ |
560 | AliDebug(1,"Standard Production, no miscalibrated digits"); | |
561 | } | |
562 | else { | |
563 | AliDebug(1,"Simulating miscalibrated digits"); | |
564 | } | |
55cb22a1 | 565 | } |
55cb22a1 | 566 | return; |
567 | } | |
568 |