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