]>
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 | ||
68861244 | 16 | //_________________________________________________________________________ |
8e72349e | 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 | |
20 | // same pad. | |
68861244 | 21 | // Digits are written to TreeD in branch "TOF". |
68861244 | 22 | // |
23 | // -- Author : F. Pierella (Bologna University) pierella@bo.infn.it | |
24 | ////////////////////////////////////////////////////////////////////////////// | |
25 | ||
55cb22a1 | 26 | |
d3c7bfac | 27 | #include <stdlib.h> |
28 | #include <Riostream.h> | |
8e72349e | 29 | #include <TTree.h> |
30 | #include <TVector.h> | |
31 | #include <TObjArray.h> | |
32 | #include <TFile.h> | |
33 | #include <TDirectory.h> | |
34 | #include <TRandom.h> | |
55cb22a1 | 35 | #include "TF1.h" |
36 | #include "TH1F.h" | |
37 | #include "TList.h" | |
38 | #include "TRandom.h" | |
68861244 | 39 | |
d3c7bfac | 40 | #include "AliLog.h" |
41 | #include "AliRun.h" | |
42 | #include "AliRunLoader.h" | |
43 | #include "AliLoader.h" | |
44 | #include "AliDigitizer.h" | |
45 | #include "AliRunDigitizer.h" | |
46 | #include "AliPDG.h" | |
68861244 | 47 | |
0efc163f | 48 | #include "AliTOF.h" |
55cb22a1 | 49 | #include "AliTOFDigitizer.h" |
8e72349e | 50 | #include "AliTOFSDigitizer.h" |
68861244 | 51 | #include "AliTOFhit.h" |
8e72349e | 52 | #include "AliTOFdigit.h" |
53 | #include "AliTOFSDigit.h" | |
54 | #include "AliTOFHitMap.h" | |
55cb22a1 | 55 | #include "AliTOFChannel.h" |
56 | #include "AliTOFCal.h" | |
57 | #include "AliTOFGeometryV5.h" | |
68861244 | 58 | |
59 | ClassImp(AliTOFDigitizer) | |
60 | ||
8e72349e | 61 | //___________________________________________ |
62 | AliTOFDigitizer::AliTOFDigitizer() :AliDigitizer() | |
68861244 | 63 | { |
8e72349e | 64 | // Default ctor - don't use it |
65 | fDigits=0; | |
66 | fSDigitsArray=0; | |
67 | fhitMap=0; | |
55cb22a1 | 68 | fGeom=0x0; |
68861244 | 69 | } |
70 | ||
8e72349e | 71 | //___________________________________________ |
72 | AliTOFDigitizer::AliTOFDigitizer(AliRunDigitizer* manager) | |
73 | :AliDigitizer(manager) | |
68861244 | 74 | { |
340693af | 75 | //ctor with RunDigitizer |
8e72349e | 76 | fDigits=0; |
77 | fSDigitsArray=0; | |
78 | fhitMap=0; | |
55cb22a1 | 79 | fGeom=0x0; |
68861244 | 80 | } |
81 | ||
8e72349e | 82 | //------------------------------------------------------------------------ |
68861244 | 83 | AliTOFDigitizer::~AliTOFDigitizer() |
84 | { | |
8e72349e | 85 | // Destructor |
68861244 | 86 | } |
8e72349e | 87 | |
88 | //--------------------------------------------------------------------- | |
89 | ||
d076c8d5 | 90 | void AliTOFDigitizer::Exec(Option_t* /*option*/) |
68861244 | 91 | { |
8e72349e | 92 | // |
93 | // Perform digitization and merging. | |
94 | // The algorithm is the following: | |
95 | // - a hitmap is created to check if a pad is already activated; | |
96 | // - an sdigits container is created to collect all sdigits from | |
97 | // different files; | |
98 | // - sdigits are summed using the hitmap; | |
99 | // - the sdigits container is used to create the array of AliTOFdigit. | |
100 | // | |
68861244 | 101 | |
d076c8d5 | 102 | AliDebug(1, ""); |
68861244 | 103 | |
68861244 | 104 | |
8e72349e | 105 | // get the ptr to TOF detector |
106 | AliTOF * tof = (AliTOF *) gAlice->GetDetector("TOF") ; | |
68861244 | 107 | |
8e72349e | 108 | //Make branches |
109 | char branchname[20]; | |
110 | sprintf (branchname, "%s", tof->GetName ()); | |
111 | ||
112 | fDigits=new TClonesArray("AliTOFdigit",4000); | |
88cb7938 | 113 | |
114 | AliRunLoader* outrl = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName()); | |
115 | if (outrl == 0x0) | |
116 | { | |
d076c8d5 | 117 | AliError("Can not find Run Loader in output folder."); |
88cb7938 | 118 | return; |
119 | } | |
120 | ||
d3c7bfac | 121 | outrl->CdGAFile(); |
122 | TFile *in=(TFile*)gFile; | |
123 | TDirectory *savedir=gDirectory; | |
124 | ||
d3c7bfac | 125 | if (!in->IsOpen()) { |
126 | AliWarning("Geometry file is not open default TOF geometry will be used"); | |
55cb22a1 | 127 | fGeom = new AliTOFGeometryV5(); |
d3c7bfac | 128 | } |
129 | else { | |
130 | in->cd(); | |
55cb22a1 | 131 | fGeom = (AliTOFGeometry*)in->Get("TOFgeometry"); |
d3c7bfac | 132 | } |
133 | ||
134 | savedir->cd(); | |
135 | ||
88cb7938 | 136 | AliLoader* outgime = outrl->GetLoader("TOFLoader"); |
137 | if (outgime == 0x0) | |
138 | { | |
d076c8d5 | 139 | AliError("Can not get TOF Loader from Output Run Loader."); |
88cb7938 | 140 | return; |
141 | } | |
142 | ||
143 | TTree* treeD = outgime->TreeD(); | |
144 | if (treeD == 0x0) | |
145 | { | |
146 | outgime->MakeTree("D"); | |
147 | treeD = outgime->TreeD(); | |
148 | } | |
8e72349e | 149 | //Make branch for digits (to be created in Init()) |
150 | tof->MakeBranchInTree(treeD,branchname,&fDigits,4000); | |
151 | ||
152 | // container for all summed sdigits (to be created in Init()) | |
153 | fSDigitsArray=new TClonesArray("AliTOFSDigit",1000); | |
68861244 | 154 | |
8e72349e | 155 | // create hit map (to be created in Init()) |
55cb22a1 | 156 | fhitMap = new AliTOFHitMap(fSDigitsArray, fGeom); |
68861244 | 157 | |
8e72349e | 158 | // Loop over files to digitize |
159 | ||
160 | for (Int_t inputFile=0; inputFile<fManager->GetNinputs(); | |
161 | inputFile++) { | |
162 | ReadSDigit(inputFile); | |
88cb7938 | 163 | } |
8e72349e | 164 | |
165 | // create digits | |
166 | CreateDigits(); | |
167 | ||
168 | // free used memory for Hit Map in current event | |
169 | delete fhitMap; | |
170 | fSDigitsArray->Delete(); | |
a5c70f8e | 171 | delete fSDigitsArray; |
172 | ||
8e72349e | 173 | treeD->Fill(); |
174 | ||
88cb7938 | 175 | outgime->WriteDigits("OVERWRITE"); |
176 | outgime->UnloadDigits(); | |
8e72349e | 177 | fDigits->Delete(); |
178 | delete fDigits; | |
179 | ||
180 | } | |
181 | ||
182 | //--------------------------------------------------------------------- | |
183 | ||
55cb22a1 | 184 | void AliTOFDigitizer::CreateDigits() |
8e72349e | 185 | { |
186 | // loop on sdigits container to fill the AliTOFdigit TClonesArray | |
187 | // start digitizing all the collected sdigits | |
188 | ||
c7764ee9 | 189 | Int_t ndump=0; // dump the first ndump created digits for each event |
8e72349e | 190 | |
191 | // get the total number of collected sdigits | |
192 | Int_t ndig = fSDigitsArray->GetEntriesFast(); | |
193 | ||
194 | for (Int_t k = 0; k < ndig; k++) { | |
68861244 | 195 | |
da3d3acd | 196 | Int_t vol[5]; // location for a digit |
7e6dce66 | 197 | for (Int_t i=0; i<5; i++) vol[i] = -1; |
68861244 | 198 | |
8e72349e | 199 | // Get the information for this digit |
200 | AliTOFSDigit *tofsdigit = (AliTOFSDigit *) fSDigitsArray->UncheckedAt(k); | |
68861244 | 201 | |
8e72349e | 202 | Int_t nslot=tofsdigit->GetNDigits(); // get the number of slots |
203 | // for current sdigit | |
68861244 | 204 | |
8e72349e | 205 | // TOF sdigit volumes (always the same for all slots) |
da3d3acd | 206 | Int_t sector = tofsdigit->GetSector(); // range [0-17] |
207 | Int_t plate = tofsdigit->GetPlate(); // range [0- 4] | |
d3c7bfac | 208 | Int_t strip = tofsdigit->GetStrip(); // range [0-14/18/19] |
da3d3acd | 209 | Int_t padz = tofsdigit->GetPadz(); // range [0- 1] |
210 | Int_t padx = tofsdigit->GetPadx(); // range [0-47] | |
68861244 | 211 | |
8e72349e | 212 | vol[0] = sector; |
213 | vol[1] = plate; | |
214 | vol[2] = strip; | |
215 | vol[3] = padx; | |
216 | vol[4] = padz; | |
68861244 | 217 | |
8e72349e | 218 | //--------------------- QA section ---------------------- |
219 | // in the while, I perform QA | |
7e6dce66 | 220 | Bool_t isSDigitBad = (sector<0 || sector>17 || plate<0 || plate >4 || padz<0 || padz>1 || padx<0 || padx>47); |
68861244 | 221 | |
8e72349e | 222 | if (isSDigitBad) { |
d3c7bfac | 223 | //AliFatal("strange sdigit found"); |
224 | AliFatal(Form("strange sdigit found %3i %2i %2i %3i %3i", sector, plate, padz, padx, strip)); | |
68861244 | 225 | } |
8e72349e | 226 | //------------------------------------------------------- |
68861244 | 227 | |
8e72349e | 228 | //------------------- Dump section ---------------------- |
229 | if(k<ndump){ | |
230 | cout << k << "-th | " << "Sector " << sector << " | Plate " << plate << " | Strip " << strip << " | PadZ " << padz << " | PadX " << padx << endl; | |
231 | cout << k << "-th sdigit" << endl; | |
232 | cout << "----------------------------------------------------"<< endl; | |
68861244 | 233 | } |
8e72349e | 234 | // ------------------------------------------------------ |
68861244 | 235 | |
8e72349e | 236 | // start loop on number of slots for current sdigit |
237 | for (Int_t islot = 0; islot < nslot; islot++) { | |
238 | Float_t digit[2]; // TOF digit variables | |
239 | Int_t tracknum[kMAXDIGITS]; // contributing tracks for the current slot | |
240 | ||
241 | Float_t tdc=tofsdigit->GetTdc(islot); digit[0]=tdc; | |
242 | Float_t adc=tofsdigit->GetAdc(islot); digit[1]=adc; | |
243 | ||
244 | tracknum[0]=tofsdigit->GetTrack(islot,0); | |
245 | tracknum[1]=tofsdigit->GetTrack(islot,1); | |
246 | tracknum[2]=tofsdigit->GetTrack(islot,2); | |
68861244 | 247 | |
7f1e928b | 248 | // new with placement must be used |
8e72349e | 249 | // adding a TOF digit for each slot |
7f1e928b | 250 | TClonesArray &aDigits = *fDigits; |
251 | Int_t last=fDigits->GetEntriesFast(); | |
252 | new (aDigits[last]) AliTOFdigit(tracknum, vol, digit); | |
253 | ||
68861244 | 254 | } |
68861244 | 255 | |
8e72349e | 256 | } // end loop on sdigits - end digitizing all collected sdigits |
55cb22a1 | 257 | |
258 | //Insert Decalibration | |
259 | ||
260 | AliTOFcalib * calib = new AliTOFcalib(fGeom); | |
261 | InitDecalibration(calib); | |
262 | DecalibrateTOFSignal(calib); | |
263 | delete calib; | |
68861244 | 264 | } |
8e72349e | 265 | |
266 | //--------------------------------------------------------------------- | |
267 | ||
268 | void AliTOFDigitizer::ReadSDigit(Int_t inputFile ) | |
68861244 | 269 | { |
8e72349e | 270 | // Read sdigits for current event and inputFile; |
271 | // store them into the sdigits container | |
272 | // and update the hit map | |
273 | // SDigits from different files are assumed to | |
274 | // be created with the same simulation parameters. | |
68861244 | 275 | |
8e72349e | 276 | // get the treeS from manager |
88cb7938 | 277 | AliRunLoader* rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(inputFile)); |
278 | if (rl == 0x0) | |
279 | { | |
d076c8d5 | 280 | AliError(Form("Can not find Run Loader in input %d folder.",inputFile)); |
88cb7938 | 281 | return; |
282 | } | |
283 | ||
284 | AliLoader* gime = rl->GetLoader("TOFLoader"); | |
285 | if (gime == 0x0) | |
286 | { | |
d076c8d5 | 287 | AliError(Form("Can not get TOF Loader from Input %d Run Loader.",inputFile)); |
88cb7938 | 288 | return; |
289 | } | |
290 | ||
291 | TTree* currentTreeS=gime->TreeS(); | |
292 | if (currentTreeS == 0x0) | |
293 | { | |
294 | Int_t retval = gime->LoadSDigits(); | |
295 | if (retval) | |
296 | { | |
d076c8d5 | 297 | AliError(Form("Error occured while loading S. Digits for Input %d",inputFile)); |
88cb7938 | 298 | return; |
299 | } | |
300 | currentTreeS=gime->TreeS(); | |
301 | if (currentTreeS == 0x0) | |
302 | { | |
d076c8d5 | 303 | AliError(Form("Can not get S. Digits Tree for Input %d",inputFile)); |
88cb7938 | 304 | return; |
305 | } | |
306 | } | |
8e72349e | 307 | // get the branch TOF inside the treeS |
308 | TClonesArray * sdigitsDummyContainer= new TClonesArray("AliTOFSDigit", 1000); | |
309 | ||
310 | // check if the branch exist | |
311 | TBranch* tofBranch=currentTreeS->GetBranch("TOF"); | |
312 | ||
313 | if(!tofBranch){ | |
d076c8d5 | 314 | AliFatal(Form("TOF branch not found for input %d",inputFile)); |
8e72349e | 315 | } |
68861244 | 316 | |
8e72349e | 317 | tofBranch->SetAddress(&sdigitsDummyContainer); |
68861244 | 318 | |
8e72349e | 319 | Int_t nEntries = (Int_t)tofBranch->GetEntries(); |
320 | ||
321 | // Loop through all entries in the tree | |
b020b05f | 322 | Int_t nbytes = 0; |
8e72349e | 323 | |
324 | for (Int_t iEntry = 0; iEntry < nEntries; iEntry++) { | |
68861244 | 325 | |
8e72349e | 326 | // Import the tree |
327 | nbytes += tofBranch->GetEvent(iEntry); | |
68861244 | 328 | |
8e72349e | 329 | // Get the number of sdigits |
330 | Int_t ndig = sdigitsDummyContainer->GetEntriesFast(); | |
331 | ||
332 | for (Int_t k=0; k<ndig; k++) { | |
333 | AliTOFSDigit *tofSdigit= (AliTOFSDigit*) sdigitsDummyContainer->UncheckedAt(k); | |
334 | ||
da3d3acd | 335 | Int_t vol[5]; // location for a sdigit |
7e6dce66 | 336 | for (Int_t i=0; i<5; i++) vol[i] = -1; |
da3d3acd | 337 | |
8e72349e | 338 | // check the sdigit volume |
339 | vol[0] = tofSdigit->GetSector(); | |
340 | vol[1] = tofSdigit->GetPlate(); | |
341 | vol[2] = tofSdigit->GetStrip(); | |
342 | vol[3] = tofSdigit->GetPadx(); | |
343 | vol[4] = tofSdigit->GetPadz(); | |
344 | ||
345 | if (fhitMap->TestHit(vol) != kEmpty) { | |
346 | AliTOFSDigit *sdig = static_cast<AliTOFSDigit*>(fhitMap->GetHit(vol)); | |
347 | sdig->Update(tofSdigit); | |
348 | ||
349 | } else { | |
350 | ||
351 | CollectSDigit(tofSdigit); // collect the current sdigit | |
352 | fhitMap->SetHit(vol); // update the hitmap for location vol | |
353 | ||
354 | } // if (hitMap->TestHit(vol) != kEmpty) | |
355 | ||
356 | } // for (Int_t k=0; k<ndig; k++) | |
a5c70f8e | 357 | sdigitsDummyContainer->Delete(); |
8e72349e | 358 | |
359 | } // end loop on entries | |
360 | ||
a5c70f8e | 361 | delete sdigitsDummyContainer; |
8e72349e | 362 | |
363 | } | |
364 | ||
365 | ||
366 | //_____________________________________________________________________________ | |
367 | void AliTOFDigitizer::CollectSDigit(AliTOFSDigit * sdigit) | |
368 | { | |
369 | // | |
7f1e928b | 370 | // Add a TOF sdigit in container |
371 | // new with placement must be used | |
372 | TClonesArray &aSDigitsArray = *fSDigitsArray; | |
373 | Int_t last=fSDigitsArray->GetEntriesFast(); | |
374 | // make a copy of the current sdigit and | |
375 | // put it into tmp array | |
376 | new (aSDigitsArray[last]) AliTOFSDigit(*sdigit); | |
68861244 | 377 | } |
55cb22a1 | 378 | |
379 | //_____________________________________________________________________________ | |
340693af | 380 | void AliTOFDigitizer::InitDecalibration( AliTOFcalib *calib) const { |
28dd10b6 | 381 | calib->ReadSimParFromCDB("TOF/Calib", 0); |
55cb22a1 | 382 | } |
383 | //--------------------------------------------------------------------- | |
384 | void AliTOFDigitizer::DecalibrateTOFSignal( AliTOFcalib *calib){ | |
385 | ||
386 | // Read Calibration parameters from the CDB | |
387 | ||
388 | AliTOFCal * cal= calib->GetTOFCalSimArray(); | |
389 | ||
390 | AliInfo(Form("Size of AliTOFCal = %i",cal->NPads())); | |
391 | for (Int_t ipad = 0 ; ipad<cal->NPads(); ipad++){ | |
340693af | 392 | AliTOFChannel *calChannel = cal->GetChannel(ipad); |
55cb22a1 | 393 | Float_t par[6]; |
394 | for (Int_t j = 0; j<6; j++){ | |
340693af | 395 | par[j]=calChannel->GetSlewPar(j); |
55cb22a1 | 396 | } |
397 | } | |
398 | ||
399 | // Initialize Quantities to Simulate ToT Spectra | |
400 | ||
401 | ||
402 | TH1F * hToT= calib->GetTOFSimToT(); | |
403 | Int_t nbins = hToT->GetNbinsX(); | |
340693af | 404 | Float_t delta = hToT->GetBinWidth(1); |
405 | Float_t maxch = hToT->GetBinLowEdge(nbins)+delta; | |
55cb22a1 | 406 | Float_t minch = hToT->GetBinLowEdge(1); |
407 | Float_t max=0,min=0; //maximum and minimum value of the distribution | |
408 | Int_t maxbin=0,minbin=0; //maximum and minimum bin of the distribution | |
409 | for (Int_t ii=nbins; ii>0; ii--){ | |
410 | if (hToT->GetBinContent(ii)!= 0) { | |
340693af | 411 | max = maxch - (nbins-ii-1)*delta; |
55cb22a1 | 412 | maxbin = ii; |
413 | break;} | |
414 | } | |
415 | for (Int_t j=1; j<nbins; j++){ | |
416 | if (hToT->GetBinContent(j)!= 0) { | |
340693af | 417 | min = minch + (j-1)*delta; |
55cb22a1 | 418 | minbin = j; |
419 | break;} | |
420 | } | |
340693af | 421 | Float_t maxToT=max; |
422 | Float_t minToT=min; | |
423 | Float_t maxToTDistr=hToT->GetMaximum(); | |
55cb22a1 | 424 | |
425 | ||
426 | // Loop on TOF Digits | |
427 | ||
428 | Bool_t dbEntry=kFALSE; | |
429 | Int_t ndigits = fDigits->GetEntriesFast(); | |
430 | for (Int_t i=0;i<ndigits;i++){ | |
431 | AliTOFdigit * dig = (AliTOFdigit*)fDigits->At(i); | |
432 | Int_t detId[5]; | |
433 | detId[0] = dig->GetSector(); | |
434 | detId[1] = dig->GetPlate(); | |
435 | detId[2] = dig->GetStrip(); | |
436 | detId[3] = dig->GetPadz(); | |
437 | detId[4] = dig->GetPadx(); | |
438 | // For Data with no Miscalibration, set ToT signal == Adc | |
439 | dig->SetToT(dig->GetAdc()); | |
440 | if(hToT->GetEntries()>0){ | |
441 | Float_t trix = 0; | |
442 | Float_t triy = 0; | |
340693af | 443 | Float_t simToT = 0; |
444 | while (simToT <= triy){ | |
55cb22a1 | 445 | trix = gRandom->Rndm(i); |
446 | triy = gRandom->Rndm(i); | |
340693af | 447 | trix = (maxToT-minToT)*trix + minToT; |
448 | triy = maxToTDistr*triy; | |
55cb22a1 | 449 | Int_t binx=hToT->FindBin(trix); |
340693af | 450 | simToT=hToT->GetBinContent(binx); |
55cb22a1 | 451 | } |
452 | // Setting realistic ToT signal (only for Miscalibrated Data) | |
453 | dig->SetToT(trix); | |
454 | } | |
455 | Int_t index = calib->GetIndex(detId); | |
340693af | 456 | AliTOFChannel *calChannel = cal->GetChannel(index); |
55cb22a1 | 457 | Float_t par[6]; |
458 | for (Int_t j = 0; j<6; j++){ | |
340693af | 459 | par[j]=calChannel->GetSlewPar(j); |
55cb22a1 | 460 | if(par[j]!=0)dbEntry=kTRUE; |
461 | } | |
462 | ||
340693af | 463 | Float_t tToT= dig->GetToT(); |
55cb22a1 | 464 | dig->SetTdcND(dig->GetTdc()); |
465 | Float_t tdc = ((dig->GetTdc())*AliTOFGeometry::TdcBinWidth()+32)*1.E-3; //tof signal in ns | |
340693af | 466 | Float_t timeoffset=par[0] + tToT*par[1] +tToT*tToT*par[2] +tToT*tToT*tToT*par[3] +tToT*tToT*tToT*tToT*par[4] +tToT*tToT*tToT*tToT*tToT*par[5]; |
55cb22a1 | 467 | Float_t timeSlewed = tdc + timeoffset; |
468 | // Setting Decalibrated Time signal | |
469 | dig->SetTdc((timeSlewed*1E3-32)/AliTOFGeometry::TdcBinWidth()); | |
470 | } | |
471 | ||
472 | if(hToT->GetEntries()<=0 || !dbEntry){ | |
473 | AliInfo("Standard Production, no miscalibrated digits"); | |
474 | }else{ | |
475 | AliInfo("Miscalibrated digits"); | |
476 | } | |
477 | ||
478 | return; | |
479 | } | |
480 |