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