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