]>
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 | ||
8e72349e | 26 | #include <TTree.h> |
27 | #include <TVector.h> | |
28 | #include <TObjArray.h> | |
29 | #include <TFile.h> | |
30 | #include <TDirectory.h> | |
31 | #include <TRandom.h> | |
68861244 | 32 | |
68861244 | 33 | |
8e72349e | 34 | #include "AliTOFDigitizer.h" |
0efc163f | 35 | #include "AliTOF.h" |
8e72349e | 36 | #include "AliTOFSDigitizer.h" |
68861244 | 37 | #include "AliTOFhit.h" |
8e72349e | 38 | #include "AliTOFdigit.h" |
39 | #include "AliTOFSDigit.h" | |
40 | #include "AliTOFHitMap.h" | |
41 | #include "AliDigitizer.h" | |
42 | #include "AliRunDigitizer.h" | |
68861244 | 43 | |
d076c8d5 | 44 | #include "AliLog.h" |
8e72349e | 45 | #include "AliRun.h" |
88cb7938 | 46 | #include "AliRunLoader.h" |
47 | #include "AliLoader.h" | |
8e72349e | 48 | #include "AliPDG.h" |
49 | ||
50 | #include <stdlib.h> | |
f8014e68 | 51 | #include <Riostream.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 | ||
112 | AliLoader* outgime = outrl->GetLoader("TOFLoader"); | |
113 | if (outgime == 0x0) | |
114 | { | |
d076c8d5 | 115 | AliError("Can not get TOF Loader from Output Run Loader."); |
88cb7938 | 116 | return; |
117 | } | |
118 | ||
119 | TTree* treeD = outgime->TreeD(); | |
120 | if (treeD == 0x0) | |
121 | { | |
122 | outgime->MakeTree("D"); | |
123 | treeD = outgime->TreeD(); | |
124 | } | |
8e72349e | 125 | //Make branch for digits (to be created in Init()) |
126 | tof->MakeBranchInTree(treeD,branchname,&fDigits,4000); | |
127 | ||
128 | // container for all summed sdigits (to be created in Init()) | |
129 | fSDigitsArray=new TClonesArray("AliTOFSDigit",1000); | |
68861244 | 130 | |
8e72349e | 131 | // create hit map (to be created in Init()) |
132 | fhitMap = new AliTOFHitMap(fSDigitsArray); | |
68861244 | 133 | |
8e72349e | 134 | // Loop over files to digitize |
135 | ||
136 | for (Int_t inputFile=0; inputFile<fManager->GetNinputs(); | |
137 | inputFile++) { | |
138 | ReadSDigit(inputFile); | |
88cb7938 | 139 | } |
8e72349e | 140 | |
141 | // create digits | |
142 | CreateDigits(); | |
143 | ||
144 | // free used memory for Hit Map in current event | |
145 | delete fhitMap; | |
146 | fSDigitsArray->Delete(); | |
a5c70f8e | 147 | delete fSDigitsArray; |
148 | ||
8e72349e | 149 | treeD->Fill(); |
150 | ||
88cb7938 | 151 | outgime->WriteDigits("OVERWRITE"); |
152 | outgime->UnloadDigits(); | |
8e72349e | 153 | fDigits->Delete(); |
154 | delete fDigits; | |
155 | ||
156 | } | |
157 | ||
158 | //--------------------------------------------------------------------- | |
159 | ||
160 | void AliTOFDigitizer::CreateDigits() | |
161 | { | |
162 | // loop on sdigits container to fill the AliTOFdigit TClonesArray | |
163 | // start digitizing all the collected sdigits | |
164 | ||
c7764ee9 | 165 | Int_t ndump=0; // dump the first ndump created digits for each event |
8e72349e | 166 | |
167 | // get the total number of collected sdigits | |
168 | Int_t ndig = fSDigitsArray->GetEntriesFast(); | |
169 | ||
170 | for (Int_t k = 0; k < ndig; k++) { | |
68861244 | 171 | |
da3d3acd | 172 | Int_t vol[5]; // location for a digit |
7e6dce66 | 173 | for (Int_t i=0; i<5; i++) vol[i] = -1; |
68861244 | 174 | |
8e72349e | 175 | // Get the information for this digit |
176 | AliTOFSDigit *tofsdigit = (AliTOFSDigit *) fSDigitsArray->UncheckedAt(k); | |
68861244 | 177 | |
8e72349e | 178 | Int_t nslot=tofsdigit->GetNDigits(); // get the number of slots |
179 | // for current sdigit | |
68861244 | 180 | |
8e72349e | 181 | // TOF sdigit volumes (always the same for all slots) |
da3d3acd | 182 | Int_t sector = tofsdigit->GetSector(); // range [0-17] |
183 | Int_t plate = tofsdigit->GetPlate(); // range [0- 4] | |
184 | Int_t strip = tofsdigit->GetStrip(); // range [0-19] | |
185 | Int_t padz = tofsdigit->GetPadz(); // range [0- 1] | |
186 | Int_t padx = tofsdigit->GetPadx(); // range [0-47] | |
68861244 | 187 | |
8e72349e | 188 | vol[0] = sector; |
189 | vol[1] = plate; | |
190 | vol[2] = strip; | |
191 | vol[3] = padx; | |
192 | vol[4] = padz; | |
68861244 | 193 | |
8e72349e | 194 | //--------------------- QA section ---------------------- |
195 | // in the while, I perform QA | |
7e6dce66 | 196 | Bool_t isSDigitBad = (sector<0 || sector>17 || plate<0 || plate >4 || padz<0 || padz>1 || padx<0 || padx>47); |
68861244 | 197 | |
8e72349e | 198 | if (isSDigitBad) { |
d076c8d5 | 199 | AliFatal("strange sdigit found"); |
68861244 | 200 | } |
8e72349e | 201 | //------------------------------------------------------- |
68861244 | 202 | |
8e72349e | 203 | //------------------- Dump section ---------------------- |
204 | if(k<ndump){ | |
205 | cout << k << "-th | " << "Sector " << sector << " | Plate " << plate << " | Strip " << strip << " | PadZ " << padz << " | PadX " << padx << endl; | |
206 | cout << k << "-th sdigit" << endl; | |
207 | cout << "----------------------------------------------------"<< endl; | |
68861244 | 208 | } |
8e72349e | 209 | // ------------------------------------------------------ |
68861244 | 210 | |
8e72349e | 211 | // start loop on number of slots for current sdigit |
212 | for (Int_t islot = 0; islot < nslot; islot++) { | |
213 | Float_t digit[2]; // TOF digit variables | |
214 | Int_t tracknum[kMAXDIGITS]; // contributing tracks for the current slot | |
215 | ||
216 | Float_t tdc=tofsdigit->GetTdc(islot); digit[0]=tdc; | |
217 | Float_t adc=tofsdigit->GetAdc(islot); digit[1]=adc; | |
218 | ||
219 | tracknum[0]=tofsdigit->GetTrack(islot,0); | |
220 | tracknum[1]=tofsdigit->GetTrack(islot,1); | |
221 | tracknum[2]=tofsdigit->GetTrack(islot,2); | |
68861244 | 222 | |
7f1e928b | 223 | // new with placement must be used |
8e72349e | 224 | // adding a TOF digit for each slot |
7f1e928b | 225 | TClonesArray &aDigits = *fDigits; |
226 | Int_t last=fDigits->GetEntriesFast(); | |
227 | new (aDigits[last]) AliTOFdigit(tracknum, vol, digit); | |
228 | ||
68861244 | 229 | } |
68861244 | 230 | |
8e72349e | 231 | } // end loop on sdigits - end digitizing all collected sdigits |
232 | ||
68861244 | 233 | } |
8e72349e | 234 | |
235 | //--------------------------------------------------------------------- | |
236 | ||
237 | void AliTOFDigitizer::ReadSDigit(Int_t inputFile ) | |
68861244 | 238 | { |
8e72349e | 239 | // Read sdigits for current event and inputFile; |
240 | // store them into the sdigits container | |
241 | // and update the hit map | |
242 | // SDigits from different files are assumed to | |
243 | // be created with the same simulation parameters. | |
68861244 | 244 | |
8e72349e | 245 | // get the treeS from manager |
88cb7938 | 246 | AliRunLoader* rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(inputFile)); |
247 | if (rl == 0x0) | |
248 | { | |
d076c8d5 | 249 | AliError(Form("Can not find Run Loader in input %d folder.",inputFile)); |
88cb7938 | 250 | return; |
251 | } | |
252 | ||
253 | AliLoader* gime = rl->GetLoader("TOFLoader"); | |
254 | if (gime == 0x0) | |
255 | { | |
d076c8d5 | 256 | AliError(Form("Can not get TOF Loader from Input %d Run Loader.",inputFile)); |
88cb7938 | 257 | return; |
258 | } | |
259 | ||
260 | TTree* currentTreeS=gime->TreeS(); | |
261 | if (currentTreeS == 0x0) | |
262 | { | |
263 | Int_t retval = gime->LoadSDigits(); | |
264 | if (retval) | |
265 | { | |
d076c8d5 | 266 | AliError(Form("Error occured while loading S. Digits for Input %d",inputFile)); |
88cb7938 | 267 | return; |
268 | } | |
269 | currentTreeS=gime->TreeS(); | |
270 | if (currentTreeS == 0x0) | |
271 | { | |
d076c8d5 | 272 | AliError(Form("Can not get S. Digits Tree for Input %d",inputFile)); |
88cb7938 | 273 | return; |
274 | } | |
275 | } | |
8e72349e | 276 | // get the branch TOF inside the treeS |
277 | TClonesArray * sdigitsDummyContainer= new TClonesArray("AliTOFSDigit", 1000); | |
278 | ||
279 | // check if the branch exist | |
280 | TBranch* tofBranch=currentTreeS->GetBranch("TOF"); | |
281 | ||
282 | if(!tofBranch){ | |
d076c8d5 | 283 | AliFatal(Form("TOF branch not found for input %d",inputFile)); |
8e72349e | 284 | } |
68861244 | 285 | |
8e72349e | 286 | tofBranch->SetAddress(&sdigitsDummyContainer); |
68861244 | 287 | |
8e72349e | 288 | Int_t nEntries = (Int_t)tofBranch->GetEntries(); |
289 | ||
290 | // Loop through all entries in the tree | |
b020b05f | 291 | Int_t nbytes = 0; |
8e72349e | 292 | |
293 | for (Int_t iEntry = 0; iEntry < nEntries; iEntry++) { | |
68861244 | 294 | |
8e72349e | 295 | // Import the tree |
296 | nbytes += tofBranch->GetEvent(iEntry); | |
68861244 | 297 | |
8e72349e | 298 | // Get the number of sdigits |
299 | Int_t ndig = sdigitsDummyContainer->GetEntriesFast(); | |
300 | ||
301 | for (Int_t k=0; k<ndig; k++) { | |
302 | AliTOFSDigit *tofSdigit= (AliTOFSDigit*) sdigitsDummyContainer->UncheckedAt(k); | |
303 | ||
da3d3acd | 304 | Int_t vol[5]; // location for a sdigit |
7e6dce66 | 305 | for (Int_t i=0; i<5; i++) vol[i] = -1; |
da3d3acd | 306 | |
8e72349e | 307 | // check the sdigit volume |
308 | vol[0] = tofSdigit->GetSector(); | |
309 | vol[1] = tofSdigit->GetPlate(); | |
310 | vol[2] = tofSdigit->GetStrip(); | |
311 | vol[3] = tofSdigit->GetPadx(); | |
312 | vol[4] = tofSdigit->GetPadz(); | |
313 | ||
314 | if (fhitMap->TestHit(vol) != kEmpty) { | |
315 | AliTOFSDigit *sdig = static_cast<AliTOFSDigit*>(fhitMap->GetHit(vol)); | |
316 | sdig->Update(tofSdigit); | |
317 | ||
318 | } else { | |
319 | ||
320 | CollectSDigit(tofSdigit); // collect the current sdigit | |
321 | fhitMap->SetHit(vol); // update the hitmap for location vol | |
322 | ||
323 | } // if (hitMap->TestHit(vol) != kEmpty) | |
324 | ||
325 | } // for (Int_t k=0; k<ndig; k++) | |
a5c70f8e | 326 | sdigitsDummyContainer->Delete(); |
8e72349e | 327 | |
328 | } // end loop on entries | |
329 | ||
a5c70f8e | 330 | delete sdigitsDummyContainer; |
8e72349e | 331 | |
332 | } | |
333 | ||
334 | ||
335 | //_____________________________________________________________________________ | |
336 | void AliTOFDigitizer::CollectSDigit(AliTOFSDigit * sdigit) | |
337 | { | |
338 | // | |
7f1e928b | 339 | // Add a TOF sdigit in container |
340 | // new with placement must be used | |
341 | TClonesArray &aSDigitsArray = *fSDigitsArray; | |
342 | Int_t last=fSDigitsArray->GetEntriesFast(); | |
343 | // make a copy of the current sdigit and | |
344 | // put it into tmp array | |
345 | new (aSDigitsArray[last]) AliTOFSDigit(*sdigit); | |
68861244 | 346 | } |