1 /**************************************************************************
2 * Copyright(c) 1998-1999, 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 **************************************************************************/
17 //_________________________________________________________________________
18 // This is a TTask that makes TOF-Digits out of TOF-Hits.
19 // A TOF Digit is essentially a TOF hit with the smearing for strip
20 // time resolution and simulation of the ADC correlation signal.
21 // Digits are written to TreeD in branch "TOF".
22 // AliTOFDigitizer with all current parameters used for digitization
23 // (time resolution and ADC parameter) is written
24 // to TreeD branch "AliTOFDigitizer".
25 // Both branches have the same title. If necessary one can produce
26 // another set of Digits with different parameters. Two versions
27 // can be distunguished using titles of the branches.
29 // root [0] AliTOFDigitizer * s = new AliTOFDigitizer("galice.root")
30 // Warning in <AliITSgeomSPD425Long::Default Creator>: Detector size may not be write.
31 // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
32 // root [1] s->ExecuteTask()
33 // // Makes Digits for all events stored in galice.root
34 // root [2] s->SetTimeRes(100.)
35 // // One can change parameters of digitization
36 // root [3] s->SetDigitsBranch("Time Resolution 100. ps")
37 // // and write them into the new branch
38 // root [4] s->ExecuteTask("deb all tim")
39 // // available parameters:
40 // deb - print number of produced Digits
41 // deb all - print number and list of produced Digits
42 // tim - print benchmarking information
44 // -- Author : F. Pierella (Bologna University) pierella@bo.infn.it
45 //////////////////////////////////////////////////////////////////////////////
53 #include "TBenchmark.h"
54 #include "TObjString.h"
60 #include "AliTOFdigit.h"
61 #include "AliTOFhit.h"
62 #include "AliTOFDigitizer.h"
65 ClassImp(AliTOFDigitizer)
68 //____________________________________________________________________________
69 AliTOFDigitizer::AliTOFDigitizer():TTask("AliTOFDigitizer","")
73 fChrgRes = 100.; // pC
77 fIsInitialized = kFALSE ;
81 //____________________________________________________________________________
82 AliTOFDigitizer::AliTOFDigitizer(const char* headerFile, const char *digitsTitle):TTask("AliTOFDigitizer","")
86 fChrgRes = 100.; // pC
88 fDigitsTitle = digitsTitle ;
89 fHeadersFile = headerFile ;
90 fIsInitialized = kFALSE ;
94 //____________________________________________________________________________
95 AliTOFDigitizer::~AliTOFDigitizer()
103 //____________________________________________________________________________
104 void AliTOFDigitizer::Init()
106 // Initialization: open root-file, allocate arrays for hits and digits,
107 // attach task Digitizer to the list of TOF tasks
109 // Initialization can not be done in the default constructor
113 if(fHeadersFile.IsNull())
114 fHeadersFile="galice.root" ;
116 TFile * file = (TFile*) gROOT->GetFile(fHeadersFile.Data() ) ;
118 //if file was not opened yet, read gAlice
120 if(fHeadersFile.Contains("rfio"))
121 file = TFile::Open(fHeadersFile,"update") ;
123 file = new TFile(fHeadersFile.Data(),"update") ;
124 gAlice = (AliRun *) file->Get("gAlice") ;
126 fHits = new TClonesArray("AliTOFhit" , 405);
127 fDigits = new TClonesArray("AliTOFdigit", 405);
129 //add Task to //FPAlice/tasks/(S)Digitizer/TOF
130 TList * aList = gROOT->GetListOfBrowsables();
132 TFolder * alice = (TFolder*)aList->FindObject("FPAlice") ;
134 TTask * aliceSD = (TTask*)alice->FindObject("tasks/(S)Digitizer") ;
136 TTask * tofD = (TTask*)aliceSD->GetListOfTasks()->FindObject("TOF") ;
142 fIsInitialized = kTRUE ;
145 //____________________________________________________________________________
146 void AliTOFDigitizer::Exec(Option_t *option)
148 Int_t tracks[3]; // track info
149 Int_t vol[5]; // dummy location for digit
150 Float_t digit[2]; // TOF digit variables
152 // Collects all hits in the same active volume into digit
157 if(strstr(option,"tim"))
158 gBenchmark->Start("TOFDigitizer");
160 fNevents = (Int_t) gAlice->TreeE()->GetEntries() ;
163 // start loop on events
164 for(ievent = 0; ievent < fNevents; ievent++){
165 gAlice->GetEvent(ievent) ;
166 gAlice->SetEvent(ievent) ;
168 if(gAlice->TreeH()==0){
169 cout << "AliTOFDigitizer: There is no Hit Tree" << endl;
173 //set address of the hits
174 TBranch * branch = gAlice->TreeH()->GetBranch("TOF");
176 branch->SetAddress(&fHits);
178 cout << "ERROR in AliTOFDigitizer: "<< endl ;
179 cout << " no branch TOF in TreeH"<< endl ;
180 cout << " do nothing " << endl ;
187 //Now made Digits from hits, for TOF it is the same a part for the tof smearing
188 // and some missing MC variables
190 for (itrack=0; itrack < gAlice->GetNtrack(); itrack++){
192 //=========== Get the TOF branch from Hits Tree for the Primary track itrack
193 branch->GetEntry(itrack,0);
196 for ( i = 0 ; i < fHits->GetEntries() ; i++ ) {
198 AliTOFhit * hit = (AliTOFhit*)fHits->At(i) ;
200 vol[0] = hit->GetSector();
201 vol[1] = hit->GetPlate();
202 vol[2] = hit->GetPadx();
203 vol[3] = hit->GetPadz();
204 vol[4] = hit->GetStrip();
205 // 95% of efficiency to be inserted here
206 // edge effect to be inserted here
207 // cross talk to be inserted here
208 // simulation of the detector response
209 Float_t idealtime = hit->GetTof(); // unit s
210 idealtime *= 1.E+12; // conversion from s to ps
211 // fTimeRes is given usually in ps
212 Float_t tdctime = gRandom->Gaus(idealtime, fTimeRes);
214 // typical Landau Distribution to be inserted here
215 Float_t idealcharge = hit->GetEdep();
216 Float_t adccharge = gRandom->Gaus(idealcharge, fChrgRes);
217 digit[1] = adccharge;
218 // to be added a check for overlaps
219 new((*fDigits)[ndigits]) AliTOFdigit(tracks, vol, digit);
223 } // end loop over tracks
225 ndigits = fDigits->GetEntriesFast() ;
226 printf("AliTOFDigitizer: Total number of digits %d\n",ndigits);
228 if(gAlice->TreeD() == 0)
229 gAlice->MakeTree("D") ;
231 //check, if this branch already exits
232 TBranch * digitsBranch = 0;
233 TBranch * digitizerBranch = 0;
235 TObjArray * branches = gAlice->TreeD()->GetListOfBranches() ;
237 Bool_t tofNotFound = kTRUE ;
238 Bool_t digitizerNotFound = kTRUE ;
240 for(ibranch = 0;ibranch <branches->GetEntries();ibranch++){
243 digitsBranch=(TBranch *) branches->At(ibranch) ;
244 if( (strcmp("TOF",digitsBranch->GetName())==0 ) &&
245 (fDigitsTitle.CompareTo(digitsBranch->GetTitle()) == 0) )
246 tofNotFound = kFALSE ;
248 if(digitizerNotFound){
249 digitizerBranch = (TBranch *) branches->At(ibranch) ;
250 if( (strcmp(digitizerBranch->GetName(),"AliTOFDigitizer") == 0)&&
251 (fDigitsTitle.CompareTo(digitizerBranch->GetTitle()) == 0) )
252 digitizerNotFound = kFALSE ;
256 if(!(digitizerNotFound && tofNotFound)){
257 cout << "AliTOFdigitizer error:" << endl ;
258 cout << "Can not overwrite existing branches: do not write" << endl ;
262 //Make (if necessary) branches
264 if(gSystem->Getenv("CONFIG_SPLIT_FILE")){ //generating file name
265 file = new char[strlen(gAlice->GetBaseFile())+20] ;
266 sprintf(file,"%s/TOF.Digits.root",gAlice->GetBaseFile()) ;
269 TDirectory *cwd = gDirectory;
271 //First list of digits
272 Int_t bufferSize = 32000 ;
273 digitsBranch = gAlice->TreeD()->Branch("TOF",&fDigits,bufferSize);
274 digitsBranch->SetTitle(fDigitsTitle.Data());
276 digitsBranch->SetFile(file);
277 TIter next( digitsBranch->GetListOfBranches());
279 while ((subbr=(TBranch*)next())) {
280 subbr->SetFile(file);
286 Int_t splitlevel = 0 ;
287 AliTOFDigitizer * digtz = this ;
288 digitizerBranch = gAlice->TreeD()->Branch("AliTOFDigitizer","AliTOFDigitizer",
289 &digtz,bufferSize,splitlevel);
290 digitizerBranch->SetTitle(fDigitsTitle.Data());
292 digitizerBranch->SetFile(file);
293 TIter next( digitizerBranch->GetListOfBranches());
295 while ((subbr=(TBranch*)next())) {
296 subbr->SetFile(file);
302 digitsBranch->Fill();
303 digitizerBranch->Fill();
304 gAlice->TreeD()->Write(0,TObject::kOverwrite) ;
306 if(strstr(option,"deb"))
307 PrintDigits(option) ;
311 if(strstr(option,"tim")){
312 gBenchmark->Stop("TOFDigitizer");
313 cout << "AliTOFDigitizer:" << endl ;
314 cout << " took " << gBenchmark->GetCpuTime("TOFDigitizer") << " seconds for Digitizing "
315 << gBenchmark->GetCpuTime("TOFDigitizer")/fNevents << " seconds per event " << endl ;
321 //__________________________________________________________________
322 void AliTOFDigitizer::SetDigitsBranch(const char* title )
324 // Setting title to branch Digits
325 if(!fDigitsTitle.IsNull())
326 cout << "AliTOFdigitizer: changing Digits file from " <<fDigitsTitle.Data() << " to " << title << endl ;
329 //__________________________________________________________________
330 void AliTOFDigitizer::Print(Option_t* option)const
332 // Prints parameters of Digitizer
333 cout << "------------------- "<< GetName() << " -------------" << endl ;
334 cout << " Writing Digits to branch with title " << fDigitsTitle.Data() << endl ;
335 cout << " with digitization parameters Time resolution = " << fTimeRes << endl ;
336 cout << " Adc smearing parameter = " << fChrgRes << endl ;
337 cout << "---------------------------------------------------"<<endl ;
340 //__________________________________________________________________
341 Bool_t AliTOFDigitizer::operator==( AliTOFDigitizer const &digtz )const
344 // Dititizers are equal if their time resolution and Adc
345 // smearing parameter are equal
347 if( (fTimeRes==digtz.fTimeRes)&&(fChrgRes==digtz.fChrgRes))
352 //__________________________________________________________________
353 void AliTOFDigitizer::PrintDigits(Option_t * option)
355 // Prints list of digits produced in the current pass of AliTOFDigitizer
357 cout << "AliTOFDigitizer: " << endl ;
358 cout << " Number of entries in Digits list " << fDigits->GetEntriesFast() << endl ;
361 if(strstr(option,"all")){// print all digits
365 cout << "Digit # " << " Time of flight(ps) " <<
366 " ADC(pC)" << " Sector #" << " Plate #" <<
367 " Strip #" << " Pad # (x) " << " Pad # (z) " << endl;
369 for (index = 0 ; index < fDigits->GetEntries() ; index++) {
370 digit = (AliTOFdigit * ) fDigits->At(index) ;
372 // set the width of the output with the setw(int width) manipulator
374 cout << setw(7) << index << " "
375 << setw(13) << digit->GetTdc() << " "
376 << setw(13) << digit->GetAdc() << " "
377 << setw(6) << digit->GetSector() << " "
378 << setw(6) << digit->GetPlate() << " "
379 << setw(6) << digit->GetStrip() << " "
380 << setw(7) << digit->GetPadx() << " "
381 << setw(7) << digit->GetPadz() << " " << endl;
383 } // end loop on digits
385 } // close if "all" option selected