]>
Commit | Line | Data |
---|---|---|
990119d6 | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
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 | ||
c093f031 | 16 | |
990119d6 | 17 | /* $Id$ */ |
18 | ||
19 | //_________________________________________________________________________ | |
7acf6008 | 20 | // This is a TTask that makes SDigits out of Hits |
7b7c1533 | 21 | // The name of the TTask is also the title of the branch that will contain |
22 | // the created SDigits | |
23 | // The title of the TTAsk is the name of the file that contains the hits from | |
24 | // which the SDigits are created | |
7acf6008 | 25 | // A Summable Digits is the sum of all hits originating |
26 | // from one primary in one active cell | |
27 | // A threshold for assignment of the primary to SDigit is applied | |
28 | // SDigits are written to TreeS, branch "PHOS" | |
29 | // AliPHOSSDigitizer with all current parameters is written | |
30 | // to TreeS branch "AliPHOSSDigitizer". | |
f035f6ce | 31 | // Both branches have the same title. If necessary one can produce |
32 | // another set of SDigits with different parameters. Two versions | |
33 | // can be distunguished using titles of the branches. | |
34 | // User case: | |
a4e98857 | 35 | // root [0] AliPHOSSDigitizer * s = new AliPHOSSDigitizer("galice.root") |
36 | // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated | |
37 | // root [1] s->ExecuteTask() | |
f035f6ce | 38 | // // Makes SDigitis for all events stored in galice.root |
a4e98857 | 39 | // root [2] s->SetPedestalParameter(0.001) |
f035f6ce | 40 | // // One can change parameters of digitization |
3de072dc | 41 | // root [3] s->SetSDigitsBranch("Pedestal 0.001") |
f035f6ce | 42 | // // and write them into the new branch |
3de072dc | 43 | // root [4] s->ExecuteTask("deb all tim") |
f035f6ce | 44 | // // available parameters: |
45 | // deb - print # of produced SDigitis | |
46 | // deb all - print # and list of produced SDigits | |
47 | // tim - print benchmarking information | |
990119d6 | 48 | // |
49 | //*-- Author : Dmitri Peressounko (SUBATECH & KI) | |
50 | ////////////////////////////////////////////////////////////////////////////// | |
51 | ||
f035f6ce | 52 | |
990119d6 | 53 | // --- ROOT system --- |
7acf6008 | 54 | #include "TFile.h" |
990119d6 | 55 | #include "TTask.h" |
56 | #include "TTree.h" | |
57 | #include "TSystem.h" | |
7acf6008 | 58 | #include "TROOT.h" |
59 | #include "TFolder.h" | |
60 | #include "TBenchmark.h" | |
106fc2fa | 61 | #include "TGeometry.h" |
62 | ||
990119d6 | 63 | // --- Standard library --- |
7acf6008 | 64 | #include <iomanip.h> |
990119d6 | 65 | |
66 | // --- AliRoot header files --- | |
7acf6008 | 67 | #include "AliRun.h" |
106fc2fa | 68 | #include "AliHeader.h" |
990119d6 | 69 | #include "AliPHOSDigit.h" |
a6eedfad | 70 | #include "AliPHOSGeometry.h" |
7b7c1533 | 71 | #include "AliPHOSGetter.h" |
990119d6 | 72 | #include "AliPHOSHit.h" |
990119d6 | 73 | #include "AliPHOSSDigitizer.h" |
74 | ||
990119d6 | 75 | ClassImp(AliPHOSSDigitizer) |
76 | ||
77 | ||
78 | //____________________________________________________________________________ | |
548f0134 | 79 | AliPHOSSDigitizer::AliPHOSSDigitizer():TTask("","") |
80 | { | |
990119d6 | 81 | // ctor |
92f521a9 | 82 | InitParameters() ; |
83 | fDefaultInit = kTRUE ; | |
990119d6 | 84 | } |
7acf6008 | 85 | |
990119d6 | 86 | //____________________________________________________________________________ |
fbf811ec | 87 | AliPHOSSDigitizer::AliPHOSSDigitizer(const char * headerFile, const char * sDigitsTitle, const Bool_t toSplit): |
88 | TTask(sDigitsTitle, headerFile) | |
990119d6 | 89 | { |
90 | // ctor | |
8d0f3f77 | 91 | InitParameters() ; |
fbf811ec | 92 | fToSplit = toSplit ; |
2bd5457f | 93 | Init(); |
92f521a9 | 94 | fDefaultInit = kFALSE ; |
990119d6 | 95 | } |
96 | ||
c093f031 | 97 | //____________________________________________________________________________ |
98 | AliPHOSSDigitizer::~AliPHOSSDigitizer() | |
99 | { | |
79bb1b62 | 100 | // dtor |
79bb1b62 | 101 | |
8d0f3f77 | 102 | fSplitFile = 0 ; |
c093f031 | 103 | } |
7b7c1533 | 104 | |
7acf6008 | 105 | //____________________________________________________________________________ |
a4e98857 | 106 | void AliPHOSSDigitizer::Init() |
107 | { | |
2bd5457f | 108 | // Initialization: open root-file, allocate arrays for hits and sdigits, |
109 | // attach task SDigitizer to the list of PHOS tasks | |
110 | // | |
a4e98857 | 111 | // Initialization can not be done in the default constructor |
7b7c1533 | 112 | //============================================================= YS |
113 | // The initialisation is now done by AliPHOSGetter | |
114 | ||
115 | if( strcmp(GetTitle(), "") == 0 ) | |
116 | SetTitle("galice.root") ; | |
85f78bbc | 117 | |
fbf811ec | 118 | AliPHOSGetter * gime = AliPHOSGetter::GetInstance(GetTitle(), GetName(),fToSplit) ; |
7b7c1533 | 119 | if ( gime == 0 ) { |
fbf811ec | 120 | cerr << "ERROR: AliPHOSSDigitizer::Init -> Could not obtain the Getter object !" |
121 | << endl ; | |
7b7c1533 | 122 | return ; |
123 | } | |
124 | ||
5ad40cd6 | 125 | gime->PostSDigits( GetName(), GetTitle() ) ; |
126 | ||
fbf811ec | 127 | fSplitFile = 0 ; |
128 | if(fToSplit){ | |
129 | // construct the name of the file as /path/PHOS.SDigits.root | |
130 | // First - extract full path if necessary | |
131 | TString sDigitsFileName(GetTitle()) ; | |
132 | Ssiz_t islash = sDigitsFileName.Last('/') ; | |
133 | if(islash<sDigitsFileName.Length()) | |
134 | sDigitsFileName.Remove(islash+1,sDigitsFileName.Length()) ; | |
135 | else | |
136 | sDigitsFileName="" ; | |
137 | // Next - append the file name | |
138 | sDigitsFileName+="PHOS.SDigits." ; | |
139 | if((strcmp(GetName(),"Default")!=0)&&(strcmp(GetName(),"")!=0)){ | |
140 | sDigitsFileName+=GetName() ; | |
141 | sDigitsFileName+="." ; | |
142 | } | |
143 | sDigitsFileName+="root" ; | |
144 | // Finally - check if the file already opened or open the file | |
145 | fSplitFile = static_cast<TFile*>(gROOT->GetFile(sDigitsFileName.Data())); | |
146 | if(!fSplitFile) | |
147 | fSplitFile = TFile::Open(sDigitsFileName.Data(),"update") ; | |
148 | } | |
149 | ||
5ad40cd6 | 150 | TString sdname(GetName() ); |
151 | sdname.Append(":") ; | |
152 | sdname.Append(GetTitle() ) ; | |
153 | SetName(sdname) ; | |
154 | gime->PostSDigitizer(this) ; | |
7acf6008 | 155 | } |
7b7c1533 | 156 | |
8d0f3f77 | 157 | //____________________________________________________________________________ |
158 | void AliPHOSSDigitizer::InitParameters() | |
159 | { | |
160 | fA = 0; | |
161 | fB = 10000000.; | |
162 | fPrimThreshold = 0.01 ; | |
163 | fSDigitsInRun = 0 ; | |
164 | fSplitFile = 0 ; | |
fbf811ec | 165 | fToSplit = kFALSE ; |
8d0f3f77 | 166 | } |
167 | ||
990119d6 | 168 | //____________________________________________________________________________ |
a4e98857 | 169 | void AliPHOSSDigitizer::Exec(Option_t *option) |
170 | { | |
171 | // Collects all hits in the same active volume into digit | |
548f0134 | 172 | |
7b7c1533 | 173 | if( strcmp(GetName(), "") == 0 ) |
7acf6008 | 174 | Init() ; |
7b7c1533 | 175 | |
176 | if (strstr(option, "print") ) { | |
177 | Print("") ; | |
178 | return ; | |
179 | } | |
990119d6 | 180 | |
7acf6008 | 181 | if(strstr(option,"tim")) |
182 | gBenchmark->Start("PHOSSDigitizer"); | |
fbf811ec | 183 | |
7b7c1533 | 184 | //Check, if this branch already exits |
fbf811ec | 185 | AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ; |
186 | if(gime->BranchExists("SDigits") ) | |
187 | return; | |
a2d8b8a4 | 188 | |
189 | TString sdname(GetName()) ; | |
190 | sdname.Remove(sdname.Index(GetTitle())-1) ; | |
fbf811ec | 191 | |
192 | Int_t nevents = gime->MaxEvent() ; | |
990119d6 | 193 | Int_t ievent ; |
7b7c1533 | 194 | for(ievent = 0; ievent < nevents; ievent++){ |
5ad40cd6 | 195 | gime->Event(ievent,"H") ; |
017addb3 | 196 | const TClonesArray * hits = gime->Hits() ; |
5ad40cd6 | 197 | TClonesArray * sdigits = gime->SDigits(sdname.Data()) ; |
7b7c1533 | 198 | sdigits->Clear(); |
990119d6 | 199 | Int_t nSdigits = 0 ; |
200 | ||
7b7c1533 | 201 | //Now make SDigits from hits, for PHOS it is the same, so just copy |
fbf811ec | 202 | Int_t nPrim = static_cast<Int_t>((gAlice->TreeH())->GetEntries()) ; |
203 | // Attention nPrim is the number of primaries tracked by Geant | |
204 | // and this number could be different to the number of Primaries in TreeK; | |
205 | Int_t iprim ; | |
206 | for (iprim = 0 ; iprim < nPrim ; iprim ++) { | |
3962b6a1 | 207 | //=========== Get the PHOS branch from Hits Tree for the Primary iprim |
208 | gime->Track(iprim) ; | |
990119d6 | 209 | Int_t i; |
7b7c1533 | 210 | for ( i = 0 ; i < hits->GetEntries() ; i++ ) { |
7a9d98f9 | 211 | AliPHOSHit * hit = dynamic_cast<AliPHOSHit *>(hits->At(i)) ; |
990119d6 | 212 | // Assign primary number only if contribution is significant |
9688c1dd | 213 | |
990119d6 | 214 | if( hit->GetEnergy() > fPrimThreshold) |
9688c1dd | 215 | new((*sdigits)[nSdigits]) AliPHOSDigit(hit->GetPrimary(),hit->GetId(), |
fbf811ec | 216 | Digitize(hit->GetEnergy()), hit->GetTime()) ; |
990119d6 | 217 | else |
9688c1dd | 218 | new((*sdigits)[nSdigits]) AliPHOSDigit( -1 , hit->GetId(), |
fbf811ec | 219 | Digitize(hit->GetEnergy()), hit->GetTime()) ; |
9688c1dd | 220 | nSdigits++ ; |
990119d6 | 221 | |
9688c1dd | 222 | } |
fbf811ec | 223 | |
3962b6a1 | 224 | } // loop over iprim |
990119d6 | 225 | |
7b7c1533 | 226 | sdigits->Sort() ; |
990119d6 | 227 | |
7b7c1533 | 228 | nSdigits = sdigits->GetEntriesFast() ; |
69866bef | 229 | fSDigitsInRun += nSdigits ; |
7b7c1533 | 230 | sdigits->Expand(nSdigits) ; |
fbf811ec | 231 | |
3962b6a1 | 232 | Int_t i ; |
990119d6 | 233 | for (i = 0 ; i < nSdigits ; i++) { |
7a9d98f9 | 234 | AliPHOSDigit * digit = dynamic_cast<AliPHOSDigit *>(sdigits->At(i)) ; |
990119d6 | 235 | digit->SetIndexInList(i) ; |
236 | } | |
3962b6a1 | 237 | |
fbf811ec | 238 | //Now write SDigits |
239 | ||
240 | if((gAlice->TreeS() == 0)|| (fSplitFile)) | |
85f78bbc | 241 | gAlice->MakeTree("S", fSplitFile); |
c093f031 | 242 | |
fbf811ec | 243 | if(fSplitFile) |
244 | fSplitFile->cd() ; | |
245 | ||
7acf6008 | 246 | //First list of sdigits |
fbf811ec | 247 | Int_t bufferSize = 32000 ; |
7b7c1533 | 248 | TBranch * sdigitsBranch = gAlice->TreeS()->Branch("PHOS",&sdigits,bufferSize); |
5ad40cd6 | 249 | sdigitsBranch->SetTitle(sdname); |
fbf811ec | 250 | |
7b7c1533 | 251 | //Next - SDigitizer |
7acf6008 | 252 | Int_t splitlevel = 0 ; |
253 | AliPHOSSDigitizer * sd = this ; | |
7b7c1533 | 254 | TBranch * sdigitizerBranch = gAlice->TreeS()->Branch("AliPHOSSDigitizer","AliPHOSSDigitizer", |
fbf811ec | 255 | &sd,bufferSize,splitlevel); |
5ad40cd6 | 256 | sdigitizerBranch->SetTitle(sdname); |
fbf811ec | 257 | |
258 | sdigitsBranch->Fill() ; | |
c093f031 | 259 | sdigitizerBranch->Fill() ; |
fbf811ec | 260 | |
42d2745f | 261 | gAlice->TreeS()->AutoSave() ; |
fbf811ec | 262 | |
7acf6008 | 263 | if(strstr(option,"deb")) |
264 | PrintSDigits(option) ; | |
990119d6 | 265 | } |
fbf811ec | 266 | |
7acf6008 | 267 | if(strstr(option,"tim")){ |
268 | gBenchmark->Stop("PHOSSDigitizer"); | |
269 | cout << "AliPHOSSDigitizer:" << endl ; | |
270 | cout << " took " << gBenchmark->GetCpuTime("PHOSSDigitizer") << " seconds for SDigitizing " | |
7b7c1533 | 271 | << gBenchmark->GetCpuTime("PHOSSDigitizer")/nevents << " seconds per event " << endl ; |
7acf6008 | 272 | cout << endl ; |
273 | } | |
990119d6 | 274 | } |
106fc2fa | 275 | |
990119d6 | 276 | //__________________________________________________________________ |
a4e98857 | 277 | void AliPHOSSDigitizer::SetSDigitsBranch(const char * title ) |
278 | { | |
279 | // Setting title to branch SDigits | |
7b7c1533 | 280 | |
281 | TString stitle(title) ; | |
282 | ||
283 | // check if branch with title already exists | |
7a9d98f9 | 284 | TBranch * sdigitsBranch = |
285 | static_cast<TBranch*>(gAlice->TreeS()->GetListOfBranches()->FindObject("PHOS")) ; | |
286 | TBranch * sdigitizerBranch = | |
287 | static_cast<TBranch*>(gAlice->TreeS()->GetListOfBranches()->FindObject("AliPHOSSDigitizer")) ; | |
7b7c1533 | 288 | const char * sdigitsTitle = sdigitsBranch ->GetTitle() ; |
289 | const char * sdigitizerTitle = sdigitizerBranch ->GetTitle() ; | |
290 | if ( stitle.CompareTo(sdigitsTitle)==0 || stitle.CompareTo(sdigitizerTitle)==0 ){ | |
291 | cerr << "ERROR: AliPHOSSdigitizer::SetSDigitsBranch -> Cannot overwrite existing branch with title " << title << endl ; | |
292 | return ; | |
293 | } | |
294 | ||
295 | cout << "AliPHOSSdigitizer::SetSDigitsBranch -> Changing SDigits file from " << GetName() << " to " << title << endl ; | |
296 | ||
297 | SetName(title) ; | |
298 | ||
299 | // Post to the WhiteBoard | |
300 | AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ; | |
5ad40cd6 | 301 | gime->PostSDigits( title, GetTitle()) ; |
990119d6 | 302 | } |
7b7c1533 | 303 | |
106fc2fa | 304 | |
990119d6 | 305 | //__________________________________________________________________ |
a4e98857 | 306 | void AliPHOSSDigitizer::Print(Option_t* option)const |
307 | { | |
308 | // Prints parameters of SDigitizer | |
990119d6 | 309 | cout << "------------------- "<< GetName() << " -------------" << endl ; |
7a9d98f9 | 310 | cout << " Writing SDigits to branch with title " << GetName() << endl ; |
7acf6008 | 311 | cout << " with digitization parameters A = " << fA << endl ; |
312 | cout << " B = " << fB << endl ; | |
313 | cout << " Threshold for Primary assignment= " << fPrimThreshold << endl ; | |
990119d6 | 314 | cout << "---------------------------------------------------"<<endl ; |
7acf6008 | 315 | |
990119d6 | 316 | } |
548f0134 | 317 | |
990119d6 | 318 | //__________________________________________________________________ |
a4e98857 | 319 | Bool_t AliPHOSSDigitizer::operator==( AliPHOSSDigitizer const &sd )const |
320 | { | |
3de072dc | 321 | // Equal operator. |
322 | // SDititizers are equal if their pedestal, slope and threshold are equal | |
323 | ||
990119d6 | 324 | if( (fA==sd.fA)&&(fB==sd.fB)&&(fPrimThreshold==sd.fPrimThreshold)) |
325 | return kTRUE ; | |
326 | else | |
327 | return kFALSE ; | |
328 | } | |
548f0134 | 329 | |
a6eedfad | 330 | //__________________________________________________________________ |
a4e98857 | 331 | void AliPHOSSDigitizer::PrintSDigits(Option_t * option) |
332 | { | |
333 | // Prints list of digits produced in the current pass of AliPHOSDigitizer | |
7b7c1533 | 334 | |
a6eedfad | 335 | |
7b7c1533 | 336 | AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ; |
5ad40cd6 | 337 | TString sdname(GetName()) ; |
338 | sdname.Remove(sdname.Index(GetTitle())-1) ; | |
017addb3 | 339 | const TClonesArray * sdigits = gime->SDigits(sdname.Data()) ; |
7b7c1533 | 340 | |
a6eedfad | 341 | cout << "AliPHOSSDigitiser: event " << gAlice->GetEvNumber() << endl ; |
342 | cout << " Number of entries in SDigits list " << sdigits->GetEntriesFast() << endl ; | |
7acf6008 | 343 | cout << endl ; |
a6eedfad | 344 | if(strstr(option,"all")||strstr(option,"EMC")){ |
7acf6008 | 345 | |
346 | //loop over digits | |
347 | AliPHOSDigit * digit; | |
a6eedfad | 348 | cout << "EMC sdigits " << endl ; |
349 | cout << "Digit Id Amplitude Index Nprim Primaries list " << endl; | |
350 | Int_t maxEmc = gime->PHOSGeometry()->GetNModules()*gime->PHOSGeometry()->GetNCristalsInModule() ; | |
7acf6008 | 351 | Int_t index ; |
a6eedfad | 352 | for (index = 0 ; (index < sdigits->GetEntriesFast()) && |
fbf811ec | 353 | ((dynamic_cast<AliPHOSDigit *> (sdigits->At(index)))->GetId() <= maxEmc) ; index++) { |
354 | digit = dynamic_cast<AliPHOSDigit *>( sdigits->At(index) ) ; | |
a6eedfad | 355 | if(digit->GetNprimary() == 0) continue; |
356 | cout << setw(6) << digit->GetId() << " " << setw(10) << digit->GetAmp() << " " | |
357 | << setw(6) << digit->GetIndexInList() << " " | |
358 | << setw(5) << digit->GetNprimary() <<" "; | |
7acf6008 | 359 | |
360 | Int_t iprimary; | |
361 | for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++) | |
a6eedfad | 362 | cout << setw(5) << digit->GetPrimary(iprimary+1) << " "; |
7acf6008 | 363 | cout << endl; |
a6eedfad | 364 | } |
365 | cout << endl; | |
366 | } | |
367 | ||
368 | if(strstr(option,"all")||strstr(option,"CPV")){ | |
7acf6008 | 369 | |
a6eedfad | 370 | //loop over CPV digits |
371 | AliPHOSDigit * digit; | |
372 | cout << "CPV sdigits " << endl ; | |
373 | cout << "Digit Id Amplitude Index Nprim Primaries list " << endl; | |
374 | Int_t maxEmc = gime->PHOSGeometry()->GetNModules()*gime->PHOSGeometry()->GetNCristalsInModule() ; | |
375 | Int_t index ; | |
376 | for (index = 0 ; index < sdigits->GetEntriesFast(); index++) { | |
fbf811ec | 377 | digit = dynamic_cast<AliPHOSDigit *>( sdigits->At(index) ) ; |
a6eedfad | 378 | if(digit->GetId() > maxEmc){ |
379 | cout << setw(6) << digit->GetId() << " " << setw(10) << digit->GetAmp() << " " | |
380 | << setw(6) << digit->GetIndexInList() << " " | |
381 | << setw(5) << digit->GetNprimary() <<" "; | |
382 | ||
383 | Int_t iprimary; | |
384 | for (iprimary=0; iprimary<digit->GetNprimary(); iprimary++) | |
385 | cout << setw(5) << digit->GetPrimary(iprimary+1) << " "; | |
386 | cout << endl; | |
387 | } | |
388 | } | |
7acf6008 | 389 | } |
a6eedfad | 390 | |
7acf6008 | 391 | } |
7b7c1533 | 392 | |
393 | //____________________________________________________________________________ | |
394 | void AliPHOSSDigitizer::UseHitsFrom(const char * filename) | |
395 | { | |
396 | SetTitle(filename) ; | |
397 | Init() ; | |
398 | } |