]>
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 | ||
d3c7bfac | 26 | #include <stdlib.h> |
27 | #include <Riostream.h> | |
28 | ||
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> | |
68861244 | 35 | |
d3c7bfac | 36 | #include "AliLog.h" |
37 | #include "AliRun.h" | |
38 | #include "AliRunLoader.h" | |
39 | #include "AliLoader.h" | |
40 | #include "AliDigitizer.h" | |
41 | #include "AliRunDigitizer.h" | |
42 | #include "AliPDG.h" | |
68861244 | 43 | |
8e72349e | 44 | #include "AliTOFDigitizer.h" |
0efc163f | 45 | #include "AliTOF.h" |
8e72349e | 46 | #include "AliTOFSDigitizer.h" |
68861244 | 47 | #include "AliTOFhit.h" |
8e72349e | 48 | #include "AliTOFdigit.h" |
49 | #include "AliTOFSDigit.h" | |
50 | #include "AliTOFHitMap.h" | |
6dc9348d | 51 | #include "AliTOFcalib.h" |
68861244 | 52 | |
53 | ClassImp(AliTOFDigitizer) | |
54 | ||
8e72349e | 55 | //___________________________________________ |
56 | AliTOFDigitizer::AliTOFDigitizer() :AliDigitizer() | |
68861244 | 57 | { |
8e72349e | 58 | // Default ctor - don't use it |
59 | fDigits=0; | |
60 | fSDigitsArray=0; | |
61 | fhitMap=0; | |
68861244 | 62 | } |
63 | ||
8e72349e | 64 | //___________________________________________ |
65 | AliTOFDigitizer::AliTOFDigitizer(AliRunDigitizer* manager) | |
66 | :AliDigitizer(manager) | |
68861244 | 67 | { |
8e72349e | 68 | fDigits=0; |
69 | fSDigitsArray=0; | |
70 | fhitMap=0; | |
68861244 | 71 | } |
72 | ||
8e72349e | 73 | //------------------------------------------------------------------------ |
68861244 | 74 | AliTOFDigitizer::~AliTOFDigitizer() |
75 | { | |
8e72349e | 76 | // Destructor |
68861244 | 77 | } |
8e72349e | 78 | |
79 | //--------------------------------------------------------------------- | |
80 | ||
d076c8d5 | 81 | void AliTOFDigitizer::Exec(Option_t* /*option*/) |
68861244 | 82 | { |
8e72349e | 83 | // |
84 | // Perform digitization and merging. | |
85 | // The algorithm is the following: | |
86 | // - a hitmap is created to check if a pad is already activated; | |
87 | // - an sdigits container is created to collect all sdigits from | |
88 | // different files; | |
89 | // - sdigits are summed using the hitmap; | |
90 | // - the sdigits container is used to create the array of AliTOFdigit. | |
91 | // | |
68861244 | 92 | |
d076c8d5 | 93 | AliDebug(1, ""); |
68861244 | 94 | |
68861244 | 95 | |
8e72349e | 96 | // get the ptr to TOF detector |
97 | AliTOF * tof = (AliTOF *) gAlice->GetDetector("TOF") ; | |
68861244 | 98 | |
8e72349e | 99 | //Make branches |
100 | char branchname[20]; | |
101 | sprintf (branchname, "%s", tof->GetName ()); | |
102 | ||
103 | fDigits=new TClonesArray("AliTOFdigit",4000); | |
88cb7938 | 104 | |
105 | AliRunLoader* outrl = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName()); | |
106 | if (outrl == 0x0) | |
107 | { | |
d076c8d5 | 108 | AliError("Can not find Run Loader in output folder."); |
88cb7938 | 109 | return; |
110 | } | |
111 | ||
d3c7bfac | 112 | outrl->CdGAFile(); |
113 | TFile *in=(TFile*)gFile; | |
114 | TDirectory *savedir=gDirectory; | |
115 | ||
116 | AliTOFGeometry *tofGeometry; | |
117 | if (!in->IsOpen()) { | |
118 | AliWarning("Geometry file is not open default TOF geometry will be used"); | |
119 | tofGeometry = new AliTOFGeometry(); | |
120 | } | |
121 | else { | |
122 | in->cd(); | |
123 | tofGeometry = (AliTOFGeometry*)in->Get("TOFgeometry"); | |
124 | } | |
125 | ||
126 | savedir->cd(); | |
127 | ||
88cb7938 | 128 | AliLoader* outgime = outrl->GetLoader("TOFLoader"); |
129 | if (outgime == 0x0) | |
130 | { | |
d076c8d5 | 131 | AliError("Can not get TOF Loader from Output Run Loader."); |
88cb7938 | 132 | return; |
133 | } | |
134 | ||
135 | TTree* treeD = outgime->TreeD(); | |
136 | if (treeD == 0x0) | |
137 | { | |
138 | outgime->MakeTree("D"); | |
139 | treeD = outgime->TreeD(); | |
140 | } | |
8e72349e | 141 | //Make branch for digits (to be created in Init()) |
142 | tof->MakeBranchInTree(treeD,branchname,&fDigits,4000); | |
143 | ||
144 | // container for all summed sdigits (to be created in Init()) | |
145 | fSDigitsArray=new TClonesArray("AliTOFSDigit",1000); | |
68861244 | 146 | |
8e72349e | 147 | // create hit map (to be created in Init()) |
d3c7bfac | 148 | fhitMap = new AliTOFHitMap(fSDigitsArray, tofGeometry); |
68861244 | 149 | |
8e72349e | 150 | // Loop over files to digitize |
151 | ||
152 | for (Int_t inputFile=0; inputFile<fManager->GetNinputs(); | |
153 | inputFile++) { | |
154 | ReadSDigit(inputFile); | |
88cb7938 | 155 | } |
8e72349e | 156 | |
157 | // create digits | |
158 | CreateDigits(); | |
159 | ||
160 | // free used memory for Hit Map in current event | |
161 | delete fhitMap; | |
162 | fSDigitsArray->Delete(); | |
a5c70f8e | 163 | delete fSDigitsArray; |
164 | ||
8e72349e | 165 | treeD->Fill(); |
166 | ||
88cb7938 | 167 | outgime->WriteDigits("OVERWRITE"); |
168 | outgime->UnloadDigits(); | |
8e72349e | 169 | fDigits->Delete(); |
170 | delete fDigits; | |
171 | ||
172 | } | |
173 | ||
174 | //--------------------------------------------------------------------- | |
175 | ||
6dc9348d | 176 | void AliTOFDigitizer::CreateDigits(Option_t *option) |
8e72349e | 177 | { |
178 | // loop on sdigits container to fill the AliTOFdigit TClonesArray | |
179 | // start digitizing all the collected sdigits | |
180 | ||
c7764ee9 | 181 | Int_t ndump=0; // dump the first ndump created digits for each event |
8e72349e | 182 | |
183 | // get the total number of collected sdigits | |
184 | Int_t ndig = fSDigitsArray->GetEntriesFast(); | |
185 | ||
186 | for (Int_t k = 0; k < ndig; k++) { | |
68861244 | 187 | |
da3d3acd | 188 | Int_t vol[5]; // location for a digit |
7e6dce66 | 189 | for (Int_t i=0; i<5; i++) vol[i] = -1; |
68861244 | 190 | |
8e72349e | 191 | // Get the information for this digit |
192 | AliTOFSDigit *tofsdigit = (AliTOFSDigit *) fSDigitsArray->UncheckedAt(k); | |
68861244 | 193 | |
8e72349e | 194 | Int_t nslot=tofsdigit->GetNDigits(); // get the number of slots |
195 | // for current sdigit | |
68861244 | 196 | |
8e72349e | 197 | // TOF sdigit volumes (always the same for all slots) |
da3d3acd | 198 | Int_t sector = tofsdigit->GetSector(); // range [0-17] |
199 | Int_t plate = tofsdigit->GetPlate(); // range [0- 4] | |
d3c7bfac | 200 | Int_t strip = tofsdigit->GetStrip(); // range [0-14/18/19] |
da3d3acd | 201 | Int_t padz = tofsdigit->GetPadz(); // range [0- 1] |
202 | Int_t padx = tofsdigit->GetPadx(); // range [0-47] | |
68861244 | 203 | |
8e72349e | 204 | vol[0] = sector; |
205 | vol[1] = plate; | |
206 | vol[2] = strip; | |
207 | vol[3] = padx; | |
208 | vol[4] = padz; | |
68861244 | 209 | |
8e72349e | 210 | //--------------------- QA section ---------------------- |
211 | // in the while, I perform QA | |
7e6dce66 | 212 | Bool_t isSDigitBad = (sector<0 || sector>17 || plate<0 || plate >4 || padz<0 || padz>1 || padx<0 || padx>47); |
68861244 | 213 | |
8e72349e | 214 | if (isSDigitBad) { |
d3c7bfac | 215 | //AliFatal("strange sdigit found"); |
216 | AliFatal(Form("strange sdigit found %3i %2i %2i %3i %3i", sector, plate, padz, padx, strip)); | |
68861244 | 217 | } |
8e72349e | 218 | //------------------------------------------------------- |
68861244 | 219 | |
8e72349e | 220 | //------------------- Dump section ---------------------- |
221 | if(k<ndump){ | |
222 | cout << k << "-th | " << "Sector " << sector << " | Plate " << plate << " | Strip " << strip << " | PadZ " << padz << " | PadX " << padx << endl; | |
223 | cout << k << "-th sdigit" << endl; | |
224 | cout << "----------------------------------------------------"<< endl; | |
68861244 | 225 | } |
8e72349e | 226 | // ------------------------------------------------------ |
68861244 | 227 | |
8e72349e | 228 | // start loop on number of slots for current sdigit |
229 | for (Int_t islot = 0; islot < nslot; islot++) { | |
230 | Float_t digit[2]; // TOF digit variables | |
231 | Int_t tracknum[kMAXDIGITS]; // contributing tracks for the current slot | |
232 | ||
233 | Float_t tdc=tofsdigit->GetTdc(islot); digit[0]=tdc; | |
234 | Float_t adc=tofsdigit->GetAdc(islot); digit[1]=adc; | |
235 | ||
236 | tracknum[0]=tofsdigit->GetTrack(islot,0); | |
237 | tracknum[1]=tofsdigit->GetTrack(islot,1); | |
238 | tracknum[2]=tofsdigit->GetTrack(islot,2); | |
68861244 | 239 | |
7f1e928b | 240 | // new with placement must be used |
8e72349e | 241 | // adding a TOF digit for each slot |
7f1e928b | 242 | TClonesArray &aDigits = *fDigits; |
243 | Int_t last=fDigits->GetEntriesFast(); | |
244 | new (aDigits[last]) AliTOFdigit(tracknum, vol, digit); | |
245 | ||
68861244 | 246 | } |
68861244 | 247 | |
8e72349e | 248 | } // end loop on sdigits - end digitizing all collected sdigits |
6dc9348d | 249 | if(strstr(option,"DECALIB")){ |
250 | AliTOFcalib * cal = new AliTOFcalib(); | |
251 | cal->Init(); | |
252 | cal->DecalibrateDigits(fDigits); | |
253 | } | |
68861244 | 254 | } |
8e72349e | 255 | |
256 | //--------------------------------------------------------------------- | |
257 | ||
258 | void AliTOFDigitizer::ReadSDigit(Int_t inputFile ) | |
68861244 | 259 | { |
8e72349e | 260 | // Read sdigits for current event and inputFile; |
261 | // store them into the sdigits container | |
262 | // and update the hit map | |
263 | // SDigits from different files are assumed to | |
264 | // be created with the same simulation parameters. | |
68861244 | 265 | |
8e72349e | 266 | // get the treeS from manager |
88cb7938 | 267 | AliRunLoader* rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(inputFile)); |
268 | if (rl == 0x0) | |
269 | { | |
d076c8d5 | 270 | AliError(Form("Can not find Run Loader in input %d folder.",inputFile)); |
88cb7938 | 271 | return; |
272 | } | |
273 | ||
274 | AliLoader* gime = rl->GetLoader("TOFLoader"); | |
275 | if (gime == 0x0) | |
276 | { | |
d076c8d5 | 277 | AliError(Form("Can not get TOF Loader from Input %d Run Loader.",inputFile)); |
88cb7938 | 278 | return; |
279 | } | |
280 | ||
281 | TTree* currentTreeS=gime->TreeS(); | |
282 | if (currentTreeS == 0x0) | |
283 | { | |
284 | Int_t retval = gime->LoadSDigits(); | |
285 | if (retval) | |
286 | { | |
d076c8d5 | 287 | AliError(Form("Error occured while loading S. Digits for Input %d",inputFile)); |
88cb7938 | 288 | return; |
289 | } | |
290 | currentTreeS=gime->TreeS(); | |
291 | if (currentTreeS == 0x0) | |
292 | { | |
d076c8d5 | 293 | AliError(Form("Can not get S. Digits Tree for Input %d",inputFile)); |
88cb7938 | 294 | return; |
295 | } | |
296 | } | |
8e72349e | 297 | // get the branch TOF inside the treeS |
298 | TClonesArray * sdigitsDummyContainer= new TClonesArray("AliTOFSDigit", 1000); | |
299 | ||
300 | // check if the branch exist | |
301 | TBranch* tofBranch=currentTreeS->GetBranch("TOF"); | |
302 | ||
303 | if(!tofBranch){ | |
d076c8d5 | 304 | AliFatal(Form("TOF branch not found for input %d",inputFile)); |
8e72349e | 305 | } |
68861244 | 306 | |
8e72349e | 307 | tofBranch->SetAddress(&sdigitsDummyContainer); |
68861244 | 308 | |
8e72349e | 309 | Int_t nEntries = (Int_t)tofBranch->GetEntries(); |
310 | ||
311 | // Loop through all entries in the tree | |
b020b05f | 312 | Int_t nbytes = 0; |
8e72349e | 313 | |
314 | for (Int_t iEntry = 0; iEntry < nEntries; iEntry++) { | |
68861244 | 315 | |
8e72349e | 316 | // Import the tree |
317 | nbytes += tofBranch->GetEvent(iEntry); | |
68861244 | 318 | |
8e72349e | 319 | // Get the number of sdigits |
320 | Int_t ndig = sdigitsDummyContainer->GetEntriesFast(); | |
321 | ||
322 | for (Int_t k=0; k<ndig; k++) { | |
323 | AliTOFSDigit *tofSdigit= (AliTOFSDigit*) sdigitsDummyContainer->UncheckedAt(k); | |
324 | ||
da3d3acd | 325 | Int_t vol[5]; // location for a sdigit |
7e6dce66 | 326 | for (Int_t i=0; i<5; i++) vol[i] = -1; |
da3d3acd | 327 | |
8e72349e | 328 | // check the sdigit volume |
329 | vol[0] = tofSdigit->GetSector(); | |
330 | vol[1] = tofSdigit->GetPlate(); | |
331 | vol[2] = tofSdigit->GetStrip(); | |
332 | vol[3] = tofSdigit->GetPadx(); | |
333 | vol[4] = tofSdigit->GetPadz(); | |
334 | ||
335 | if (fhitMap->TestHit(vol) != kEmpty) { | |
336 | AliTOFSDigit *sdig = static_cast<AliTOFSDigit*>(fhitMap->GetHit(vol)); | |
337 | sdig->Update(tofSdigit); | |
338 | ||
339 | } else { | |
340 | ||
341 | CollectSDigit(tofSdigit); // collect the current sdigit | |
342 | fhitMap->SetHit(vol); // update the hitmap for location vol | |
343 | ||
344 | } // if (hitMap->TestHit(vol) != kEmpty) | |
345 | ||
346 | } // for (Int_t k=0; k<ndig; k++) | |
a5c70f8e | 347 | sdigitsDummyContainer->Delete(); |
8e72349e | 348 | |
349 | } // end loop on entries | |
350 | ||
a5c70f8e | 351 | delete sdigitsDummyContainer; |
8e72349e | 352 | |
353 | } | |
354 | ||
355 | ||
356 | //_____________________________________________________________________________ | |
357 | void AliTOFDigitizer::CollectSDigit(AliTOFSDigit * sdigit) | |
358 | { | |
359 | // | |
7f1e928b | 360 | // Add a TOF sdigit in container |
361 | // new with placement must be used | |
362 | TClonesArray &aSDigitsArray = *fSDigitsArray; | |
363 | Int_t last=fSDigitsArray->GetEntriesFast(); | |
364 | // make a copy of the current sdigit and | |
365 | // put it into tmp array | |
366 | new (aSDigitsArray[last]) AliTOFSDigit(*sdigit); | |
68861244 | 367 | } |