1 /**************************************************************************
2 * Copyright(c) 1998-2000, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 //_________________________________________________________________________
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
21 // Digits are written to TreeD in branch "TOF".
23 // -- Author : F. Pierella (Bologna University) pierella@bo.infn.it
24 //////////////////////////////////////////////////////////////////////////////
28 #include <TObjArray.h>
30 #include <TDirectory.h>
34 #include "AliTOFDigitizer.h"
36 #include "AliTOFSDigitizer.h"
37 #include "AliTOFhit.h"
38 #include "AliTOFdigit.h"
39 #include "AliTOFSDigit.h"
40 #include "AliTOFHitMap.h"
41 #include "AliDigitizer.h"
42 #include "AliRunDigitizer.h"
45 #include "AliRunLoader.h"
46 #include "AliLoader.h"
50 #include <Riostream.h>
52 ClassImp(AliTOFDigitizer)
54 //___________________________________________
55 AliTOFDigitizer::AliTOFDigitizer() :AliDigitizer()
57 // Default ctor - don't use it
63 //___________________________________________
64 AliTOFDigitizer::AliTOFDigitizer(AliRunDigitizer* manager)
65 :AliDigitizer(manager)
72 //------------------------------------------------------------------------
73 AliTOFDigitizer::~AliTOFDigitizer()
78 //---------------------------------------------------------------------
80 void AliTOFDigitizer::Exec(Option_t* option)
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
88 // - sdigits are summed using the hitmap;
89 // - the sdigits container is used to create the array of AliTOFdigit.
92 if(strstr(option,"deb")) cout<<"AliTOFDigitizer::Exec\n";
95 // get the ptr to TOF detector
96 AliTOF * tof = (AliTOF *) gAlice->GetDetector("TOF") ;
100 sprintf (branchname, "%s", tof->GetName ());
102 fDigits=new TClonesArray("AliTOFdigit",4000);
104 AliRunLoader* outrl = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());
107 Error("Exec","Can not find Run Loader in output folder.");
111 AliLoader* outgime = outrl->GetLoader("TOFLoader");
114 Error("Exec","Can not get TOF Loader from Output Run Loader.");
118 TTree* treeD = outgime->TreeD();
121 outgime->MakeTree("D");
122 treeD = outgime->TreeD();
124 //Make branch for digits (to be created in Init())
125 tof->MakeBranchInTree(treeD,branchname,&fDigits,4000);
127 // container for all summed sdigits (to be created in Init())
128 fSDigitsArray=new TClonesArray("AliTOFSDigit",1000);
130 // create hit map (to be created in Init())
131 fhitMap = new AliTOFHitMap(fSDigitsArray);
133 // Loop over files to digitize
135 for (Int_t inputFile=0; inputFile<fManager->GetNinputs();
137 ReadSDigit(inputFile);
143 // free used memory for Hit Map in current event
145 fSDigitsArray->Delete();
146 delete fSDigitsArray;
150 outgime->WriteDigits("OVERWRITE");
151 outgime->UnloadDigits();
157 //---------------------------------------------------------------------
159 void AliTOFDigitizer::CreateDigits()
161 // loop on sdigits container to fill the AliTOFdigit TClonesArray
162 // start digitizing all the collected sdigits
164 Int_t ndump=0; // dump the first ndump created digits for each event
166 // get the total number of collected sdigits
167 Int_t ndig = fSDigitsArray->GetEntriesFast();
169 for (Int_t k = 0; k < ndig; k++) {
171 Int_t vol[5]; // location for a digit
172 for (Int_t i=0; i<5; i++) vol[i] = -1; // AdC
174 // Get the information for this digit
175 AliTOFSDigit *tofsdigit = (AliTOFSDigit *) fSDigitsArray->UncheckedAt(k);
177 Int_t nslot=tofsdigit->GetNDigits(); // get the number of slots
178 // for current sdigit
180 // TOF sdigit volumes (always the same for all slots)
181 Int_t sector = tofsdigit->GetSector(); // range [0-17]
182 Int_t plate = tofsdigit->GetPlate(); // range [0- 4]
183 Int_t strip = tofsdigit->GetStrip(); // range [0-19]
184 Int_t padz = tofsdigit->GetPadz(); // range [0- 1]
185 Int_t padx = tofsdigit->GetPadx(); // range [0-47]
193 //--------------------- QA section ----------------------
194 // in the while, I perform QA
195 //Bool_t isSDigitBad = (sector<1 || sector>18 || plate<1 || plate >5 || padz<1 || padz>2 || padx<1 || padx>48);
196 Bool_t isSDigitBad = (sector<0 || sector>17 || plate<0 || plate >4 || padz<0 || padz>1 || padx<0 || padx>47); // AdC
199 cout << "<AliTOFSDigits2Digits> strange sdigit found" << endl;
202 //-------------------------------------------------------
204 //------------------- Dump section ----------------------
206 cout << k << "-th | " << "Sector " << sector << " | Plate " << plate << " | Strip " << strip << " | PadZ " << padz << " | PadX " << padx << endl;
207 cout << k << "-th sdigit" << endl;
208 cout << "----------------------------------------------------"<< endl;
210 // ------------------------------------------------------
212 // start loop on number of slots for current sdigit
213 for (Int_t islot = 0; islot < nslot; islot++) {
214 Float_t digit[2]; // TOF digit variables
215 Int_t tracknum[kMAXDIGITS]; // contributing tracks for the current slot
217 Float_t tdc=tofsdigit->GetTdc(islot); digit[0]=tdc;
218 Float_t adc=tofsdigit->GetAdc(islot); digit[1]=adc;
220 tracknum[0]=tofsdigit->GetTrack(islot,0);
221 tracknum[1]=tofsdigit->GetTrack(islot,1);
222 tracknum[2]=tofsdigit->GetTrack(islot,2);
224 // new with placement must be used
225 // adding a TOF digit for each slot
226 TClonesArray &aDigits = *fDigits;
227 Int_t last=fDigits->GetEntriesFast();
228 new (aDigits[last]) AliTOFdigit(tracknum, vol, digit);
232 } // end loop on sdigits - end digitizing all collected sdigits
236 //---------------------------------------------------------------------
238 void AliTOFDigitizer::ReadSDigit(Int_t inputFile )
240 // Read sdigits for current event and inputFile;
241 // store them into the sdigits container
242 // and update the hit map
243 // SDigits from different files are assumed to
244 // be created with the same simulation parameters.
246 // get the treeS from manager
247 AliRunLoader* rl = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(inputFile));
250 Error("ReadSDigit","Can not find Run Loader in input %d folder.",inputFile);
254 AliLoader* gime = rl->GetLoader("TOFLoader");
257 Error("ReadSDigit","Can not get TOF Loader from Input %d Run Loader.",inputFile);
261 TTree* currentTreeS=gime->TreeS();
262 if (currentTreeS == 0x0)
264 Int_t retval = gime->LoadSDigits();
267 Error("ReadSDigit","Error occured while loading S. Digits for Input %d",inputFile);
270 currentTreeS=gime->TreeS();
271 if (currentTreeS == 0x0)
273 Error("ReadSDigit","Can not get S. Digits Tree for Input %d",inputFile);
277 // get the branch TOF inside the treeS
278 TClonesArray * sdigitsDummyContainer= new TClonesArray("AliTOFSDigit", 1000);
280 // check if the branch exist
281 TBranch* tofBranch=currentTreeS->GetBranch("TOF");
284 Fatal("ReadSDigit","TOF branch not found for input %d",inputFile);
287 tofBranch->SetAddress(&sdigitsDummyContainer);
289 Int_t nEntries = (Int_t)tofBranch->GetEntries();
291 // Loop through all entries in the tree
294 for (Int_t iEntry = 0; iEntry < nEntries; iEntry++) {
297 nbytes += tofBranch->GetEvent(iEntry);
299 // Get the number of sdigits
300 Int_t ndig = sdigitsDummyContainer->GetEntriesFast();
302 for (Int_t k=0; k<ndig; k++) {
303 AliTOFSDigit *tofSdigit= (AliTOFSDigit*) sdigitsDummyContainer->UncheckedAt(k);
305 Int_t vol[5]; // location for a sdigit
306 for (Int_t i=0; i<5; i++) vol[i] = -1; // AdC
308 // check the sdigit volume
309 vol[0] = tofSdigit->GetSector();
310 vol[1] = tofSdigit->GetPlate();
311 vol[2] = tofSdigit->GetStrip();
312 vol[3] = tofSdigit->GetPadx();
313 vol[4] = tofSdigit->GetPadz();
315 if (fhitMap->TestHit(vol) != kEmpty) {
316 AliTOFSDigit *sdig = static_cast<AliTOFSDigit*>(fhitMap->GetHit(vol));
317 sdig->Update(tofSdigit);
321 CollectSDigit(tofSdigit); // collect the current sdigit
322 fhitMap->SetHit(vol); // update the hitmap for location vol
324 } // if (hitMap->TestHit(vol) != kEmpty)
326 } // for (Int_t k=0; k<ndig; k++)
327 sdigitsDummyContainer->Delete();
329 } // end loop on entries
331 delete sdigitsDummyContainer;
336 //_____________________________________________________________________________
337 void AliTOFDigitizer::CollectSDigit(AliTOFSDigit * sdigit)
340 // Add a TOF sdigit in container
341 // new with placement must be used
342 TClonesArray &aSDigitsArray = *fSDigitsArray;
343 Int_t last=fSDigitsArray->GetEntriesFast();
344 // make a copy of the current sdigit and
345 // put it into tmp array
346 new (aSDigitsArray[last]) AliTOFSDigit(*sdigit);