]>
Commit | Line | Data |
---|---|---|
99d554c8 | 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 | ||
acd84897 | 16 | /* $Id$ */ |
99d554c8 | 17 | |
fe4da5cc | 18 | /////////////////////////////////////////////////////////////////////////////// |
19 | // // | |
20 | // Control class for Alice C++ // | |
21 | // Only one single instance of this class exists. // | |
22 | // The object is created in main program aliroot // | |
23 | // and is pointed by the global gAlice. // | |
24 | // // | |
8494b010 | 25 | // -Supports the list of all Alice Detectors (fModules). // |
fe4da5cc | 26 | // -Supports the list of particles (fParticles). // |
27 | // -Supports the Trees. // | |
28 | // -Supports the geometry. // | |
29 | // -Supports the event display. // | |
30 | //Begin_Html | |
31 | /* | |
1439f98e | 32 | <img src="picts/AliRunClass.gif"> |
fe4da5cc | 33 | */ |
34 | //End_Html | |
35 | //Begin_Html | |
36 | /* | |
1439f98e | 37 | <img src="picts/alirun.gif"> |
fe4da5cc | 38 | */ |
39 | //End_Html | |
40 | // // | |
41 | /////////////////////////////////////////////////////////////////////////////// | |
42 | ||
88cb7938 | 43 | #include <TCint.h> |
88cb7938 | 44 | #include <TROOT.h> |
88cb7938 | 45 | #include <TRandom3.h> |
46 | #include <TSystem.h> | |
88cb7938 | 47 | #include <TVirtualMC.h> |
178a256c | 48 | #include <TGeoManager.h> |
5d12ce38 | 49 | // |
21bf7095 | 50 | #include "AliLog.h" |
98490ea9 | 51 | #include "AliDetector.h" |
98490ea9 | 52 | #include "AliHeader.h" |
5d12ce38 | 53 | #include "AliMC.h" |
141f90e3 | 54 | #include "AliPDG.h" |
98490ea9 | 55 | #include "AliRun.h" |
56 | #include "AliStack.h" | |
b3276c04 | 57 | #include "AliCDBManager.h" |
995ad051 | 58 | #include "AliAlignObj.h" |
3e2e3ece | 59 | #include "AliSimulation.h" |
60 | #include "AliLego.h" | |
fe4da5cc | 61 | |
fe4da5cc | 62 | AliRun *gAlice; |
63 | ||
fe4da5cc | 64 | ClassImp(AliRun) |
65 | ||
e2afb3b6 | 66 | //_______________________________________________________________________ |
67 | AliRun::AliRun(): | |
33c3c91a | 68 | // fRun(-1), |
3e2e3ece | 69 | fEventNrInRun(-1), |
e2afb3b6 | 70 | fModules(0), |
5d12ce38 | 71 | fMCApp(0), |
e2afb3b6 | 72 | fNdets(0), |
4539539b | 73 | fConfigFunction(""), |
e2afb3b6 | 74 | fRandom(0), |
fe12e09c | 75 | fBaseFileName(""), |
4539539b | 76 | fTriggerDescriptor(""), |
5d12ce38 | 77 | fRunLoader(0x0) |
fe4da5cc | 78 | { |
79 | // | |
80 | // Default constructor for AliRun | |
81 | // | |
88cb7938 | 82 | AliConfig::Instance();//skowron 29 Feb 2002 |
83 | //ensures that the folder structure is build | |
3d45e923 | 84 | |
e2afb3b6 | 85 | } |
86 | ||
fe4da5cc | 87 | //_____________________________________________________________________________ |
e2afb3b6 | 88 | AliRun::AliRun(const char *name, const char *title): |
5d12ce38 | 89 | TNamed(name,title), |
3e2e3ece | 90 | fEventNrInRun(-1), |
e2afb3b6 | 91 | fModules(new TObjArray(77)), // Support list for the Detectors |
3e2e3ece | 92 | fMCApp(new AliMC(GetName(),GetTitle())), |
e2afb3b6 | 93 | fNdets(0), |
e2afb3b6 | 94 | fConfigFunction("Config();"), |
95 | fRandom(new TRandom3()), | |
fe12e09c | 96 | fBaseFileName(""), |
4539539b | 97 | fTriggerDescriptor(""), |
b60e0f5e | 98 | fRunLoader(0x0) |
fe4da5cc | 99 | { |
100 | // | |
101 | // Constructor for the main processor. | |
102 | // Creates the geometry | |
103 | // Creates the list of Detectors. | |
104 | // Creates the list of particles. | |
105 | // | |
e2afb3b6 | 106 | |
fe4da5cc | 107 | gAlice = this; |
65fb704d | 108 | |
109 | // Set random number generator | |
e2afb3b6 | 110 | gRandom = fRandom; |
2ab0c725 | 111 | |
112 | if (gSystem->Getenv("CONFIG_SEED")) { | |
e2afb3b6 | 113 | gRandom->SetSeed(static_cast<UInt_t>(atoi(gSystem->Getenv("CONFIG_SEED")))); |
2ab0c725 | 114 | } |
e2afb3b6 | 115 | |
116 | // Add to list of browsable | |
fe4da5cc | 117 | gROOT->GetListOfBrowsables()->Add(this,name); |
fe4da5cc | 118 | |
fe4da5cc | 119 | } |
120 | ||
aee8290b | 121 | |
e2afb3b6 | 122 | //_______________________________________________________________________ |
fe4da5cc | 123 | AliRun::~AliRun() |
124 | { | |
125 | // | |
2ab0c725 | 126 | // Default AliRun destructor |
fe4da5cc | 127 | // |
88cb7938 | 128 | gROOT->GetListOfBrowsables()->Remove(this); |
129 | ||
130 | if (fRunLoader) | |
131 | { | |
132 | TFolder* evfold = fRunLoader->GetEventFolder(); | |
133 | TFolder* modfold = dynamic_cast<TFolder*>(evfold->FindObjectAny(AliConfig::GetModulesFolderName())); | |
134 | TIter next(fModules); | |
135 | AliModule *mod; | |
136 | while((mod = (AliModule*)next())) | |
137 | { | |
138 | modfold->Remove(mod); | |
139 | } | |
140 | } | |
3e2e3ece | 141 | |
5d12ce38 | 142 | delete fMCApp; |
f5bc1485 | 143 | delete gMC; gMC=0; |
8494b010 | 144 | if (fModules) { |
145 | fModules->Delete(); | |
146 | delete fModules; | |
fe4da5cc | 147 | } |
88cb7938 | 148 | |
fe4da5cc | 149 | } |
150 | ||
d8408e76 | 151 | |
88cb7938 | 152 | //_____________________________________________________________________________ |
153 | ||
154 | void AliRun::InitLoaders() | |
155 | { | |
156 | //creates list of getters | |
21bf7095 | 157 | AliDebug(1, ""); |
88cb7938 | 158 | TIter next(fModules); |
159 | AliModule *mod; | |
160 | while((mod = (AliModule*)next())) | |
161 | { | |
1d6fbf6e | 162 | mod->SetRunLoader(fRunLoader); |
88cb7938 | 163 | AliDetector *det = dynamic_cast<AliDetector*>(mod); |
164 | if (det) | |
165 | { | |
21bf7095 | 166 | AliDebug(2, Form("Adding %s", det->GetName())); |
88cb7938 | 167 | fRunLoader->AddLoader(det); |
168 | } | |
169 | } | |
21bf7095 | 170 | AliDebug(1, "Done"); |
88cb7938 | 171 | } |
fe4da5cc | 172 | |
eb1b8d29 | 173 | //_______________________________________________________________________ |
174 | void AliRun::Announce() const | |
175 | { | |
176 | // | |
37d06d5b | 177 | // Announce the current version of AliRoot |
178 | // | |
179 | printf("%70s", | |
180 | "****************************************************************\n"); | |
181 | printf("%6s","*");printf("%64s","*\n"); | |
182 | ||
183 | printf("%6s","*"); | |
88cb7938 | 184 | printf(" You are running AliRoot version NewIO\n"); |
37d06d5b | 185 | |
186 | printf("%6s","*"); | |
5960f18d | 187 | printf(" The SVN version for the current program is $Id$\n"); |
37d06d5b | 188 | |
189 | printf("%6s","*");printf("%64s","*\n"); | |
190 | printf("%70s", | |
191 | "****************************************************************\n"); | |
eb1b8d29 | 192 | } |
193 | ||
e2afb3b6 | 194 | //_______________________________________________________________________ |
94de3818 | 195 | AliModule *AliRun::GetModule(const char *name) const |
fe4da5cc | 196 | { |
197 | // | |
198 | // Return pointer to detector from name | |
199 | // | |
e2afb3b6 | 200 | return dynamic_cast<AliModule*>(fModules->FindObject(name)); |
fe4da5cc | 201 | } |
202 | ||
e2afb3b6 | 203 | //_______________________________________________________________________ |
94de3818 | 204 | AliDetector *AliRun::GetDetector(const char *name) const |
a68348e9 | 205 | { |
206 | // | |
207 | // Return pointer to detector from name | |
208 | // | |
e2afb3b6 | 209 | return dynamic_cast<AliDetector*>(fModules->FindObject(name)); |
a68348e9 | 210 | } |
211 | ||
e2afb3b6 | 212 | //_______________________________________________________________________ |
94de3818 | 213 | Int_t AliRun::GetModuleID(const char *name) const |
fe4da5cc | 214 | { |
215 | // | |
216 | // Return galice internal detector identifier from name | |
217 | // | |
23370b7a | 218 | Int_t i=-1; |
219 | TObject *mod=fModules->FindObject(name); | |
220 | if(mod) i=fModules->IndexOf(mod); | |
221 | return i; | |
fe4da5cc | 222 | } |
223 | ||
e2afb3b6 | 224 | //_______________________________________________________________________ |
fe4da5cc | 225 | Int_t AliRun::GetEvent(Int_t event) |
226 | { | |
88cb7938 | 227 | // |
228 | // Reloads data containers in folders # event | |
229 | // Set branch addresses | |
230 | // | |
231 | if (fRunLoader == 0x0) | |
232 | { | |
21bf7095 | 233 | AliError("RunLoader is not set. Can not load data."); |
88cb7938 | 234 | return -1; |
235 | } | |
236 | /*****************************************/ | |
237 | /**** P R E R E L O A D I N G ****/ | |
238 | /*****************************************/ | |
239 | // Reset existing structures | |
5d12ce38 | 240 | fMCApp->ResetHits(); |
241 | fMCApp->ResetTrackReferences(); | |
3e2e3ece | 242 | fMCApp->ResetDigits(); |
243 | fMCApp->ResetSDigits(); | |
50a6540a | 244 | |
88cb7938 | 245 | /*****************************************/ |
246 | /**** R E L O A D ****/ | |
247 | /*****************************************/ | |
aab9c8d5 | 248 | |
33c3c91a | 249 | AliRunLoader::Instance()->GetEvent(event); |
b9d0a01d | 250 | |
88cb7938 | 251 | /*****************************************/ |
252 | /**** P O S T R E L O A D I N G ****/ | |
253 | /*****************************************/ | |
82711e7a | 254 | |
fe4da5cc | 255 | // Set Trees branch addresses |
8494b010 | 256 | TIter next(fModules); |
07d55def | 257 | AliDetector *detector; |
258 | while((detector = dynamic_cast<AliDetector*>(next()))) | |
88cb7938 | 259 | { |
260 | detector->SetTreeAddress(); | |
261 | } | |
262 | ||
33c3c91a | 263 | return AliRunLoader::Instance()->GetHeader()->GetNtrack(); |
fe4da5cc | 264 | } |
265 | ||
e2afb3b6 | 266 | //_______________________________________________________________________ |
267 | void AliRun::SetBaseFile(const char *filename) | |
2ab0c725 | 268 | { |
39de14fb | 269 | fBaseFileName = filename; |
2ab0c725 | 270 | } |
271 | ||
fe4da5cc | 272 | |
e2afb3b6 | 273 | //_______________________________________________________________________ |
2ab0c725 | 274 | void AliRun::Hits2Digits(const char *selected) |
275 | { | |
9e1a0ddb | 276 | |
d47c658f | 277 | // Convert Hits to sumable digits |
278 | // | |
33c3c91a | 279 | for (Int_t nevent=0; nevent<AliRunLoader::Instance()->TreeE()->GetEntries(); nevent++) { |
9e1a0ddb | 280 | GetEvent(nevent); |
9e1a0ddb | 281 | Hits2SDigits(selected); |
282 | SDigits2Digits(selected); | |
283 | } | |
2ab0c725 | 284 | } |
285 | ||
d47c658f | 286 | |
e2afb3b6 | 287 | //_______________________________________________________________________ |
2ab0c725 | 288 | |
d47c658f | 289 | void AliRun::Tree2Tree(Option_t *option, const char *selected) |
2ab0c725 | 290 | { |
291 | // | |
d47c658f | 292 | // Function to transform the content of |
293 | // | |
294 | // - TreeH to TreeS (option "S") | |
295 | // - TreeS to TreeD (option "D") | |
296 | // - TreeD to TreeR (option "R") | |
297 | // | |
298 | // If multiple options are specified ("SDR"), transformation will be done in sequence for | |
299 | // selected detector and for all detectors if none is selected (detector string | |
300 | // can contain blank separated list of detector names). | |
2ab0c725 | 301 | |
2ab0c725 | 302 | |
5cf7bbad | 303 | const char *oS = strstr(option,"S"); |
304 | const char *oD = strstr(option,"D"); | |
305 | const char *oR = strstr(option,"R"); | |
2ab0c725 | 306 | |
9e1a0ddb | 307 | TObjArray *detectors = Detectors(); |
2ab0c725 | 308 | |
309 | TIter next(detectors); | |
310 | ||
d47c658f | 311 | AliDetector *detector = 0; |
2ab0c725 | 312 | |
88cb7938 | 313 | while((detector = dynamic_cast<AliDetector*>(next()))) { |
d47c658f | 314 | if (selected) |
2ab0c725 | 315 | if (strcmp(detector->GetName(),selected)) continue; |
88cb7938 | 316 | if (detector->IsActive()) |
317 | { | |
318 | ||
319 | AliLoader* loader = detector->GetLoader(); | |
320 | if (loader == 0x0) continue; | |
321 | ||
322 | if (oS) | |
323 | { | |
21bf7095 | 324 | AliDebug(1, Form("Processing Hits2SDigits for %s ...", detector->GetName())); |
88cb7938 | 325 | loader->LoadHits("read"); |
326 | if (loader->TreeS() == 0x0) loader->MakeTree("S"); | |
327 | detector->MakeBranch(option); | |
328 | detector->SetTreeAddress(); | |
329 | detector->Hits2SDigits(); | |
330 | loader->UnloadHits(); | |
331 | loader->UnloadSDigits(); | |
332 | } | |
333 | if (oD) | |
334 | { | |
21bf7095 | 335 | AliDebug(1, Form("Processing SDigits2Digits for %s ...", detector->GetName())); |
88cb7938 | 336 | loader->LoadSDigits("read"); |
337 | if (loader->TreeD() == 0x0) loader->MakeTree("D"); | |
338 | detector->MakeBranch(option); | |
339 | detector->SetTreeAddress(); | |
340 | detector->SDigits2Digits(); | |
341 | loader->UnloadSDigits(); | |
342 | loader->UnloadDigits(); | |
343 | } | |
344 | if (oR) | |
345 | { | |
21bf7095 | 346 | AliDebug(1, Form("Processing Digits2Reco for %s ...", detector->GetName())); |
88cb7938 | 347 | loader->LoadDigits("read"); |
348 | if (loader->TreeR() == 0x0) loader->MakeTree("R"); | |
349 | detector->MakeBranch(option); | |
350 | detector->SetTreeAddress(); | |
351 | detector->Digits2Reco(); | |
352 | loader->UnloadDigits(); | |
353 | loader->UnloadRecPoints(); | |
354 | ||
355 | } | |
356 | } | |
357 | } | |
2ab0c725 | 358 | } |
359 | ||
b9d0a01d | 360 | |
e2afb3b6 | 361 | //_______________________________________________________________________ |
fe4da5cc | 362 | void AliRun::Streamer(TBuffer &R__b) |
363 | { | |
eef4b160 | 364 | // Stream an object of class AliRun. |
2ab0c725 | 365 | |
7e90ff59 | 366 | if (R__b.IsReading()) { |
367 | if (!gAlice) gAlice = this; | |
7e90ff59 | 368 | AliRun::Class()->ReadBuffer(R__b, this); |
7e90ff59 | 369 | gROOT->GetListOfBrowsables()->Add(this,"Run"); |
eef4b160 | 370 | |
7e90ff59 | 371 | gRandom = fRandom; |
372 | } else { | |
eef4b160 | 373 | AliRun::Class()->WriteBuffer(R__b, this); |
374 | } | |
2ab0c725 | 375 | } |
e2afb3b6 | 376 | //_______________________________________________________________________ |
b9d0a01d | 377 | |
27f087a9 | 378 | void AliRun::SetGenEventHeader(AliGenEventHeader* header) |
379 | { | |
33c3c91a | 380 | AliRunLoader::Instance()->GetHeader()->SetGenEventHeader(header); |
27f087a9 | 381 | } |
7dd2cbe4 | 382 | |
383 | ||
504b172d | 384 | //_______________________________________________________________________ |
0592d1ca | 385 | |
88cb7938 | 386 | Int_t AliRun::GetEvNumber() const |
387 | { | |
388 | //Returns number of current event | |
389 | if (fRunLoader == 0x0) | |
390 | { | |
21bf7095 | 391 | AliError("RunLoader is not set. Can not load data."); |
88cb7938 | 392 | return -1; |
393 | } | |
0592d1ca | 394 | |
88cb7938 | 395 | return fRunLoader->GetEventNumber(); |
0592d1ca | 396 | } |
504b172d | 397 | //_______________________________________________________________________ |
b9d0a01d | 398 | |
88cb7938 | 399 | void AliRun::SetRunLoader(AliRunLoader* rloader) |
0592d1ca | 400 | { |
2057aecb | 401 | // |
402 | // Set the loader of the run | |
403 | // | |
88cb7938 | 404 | fRunLoader = rloader; |
405 | if (fRunLoader == 0x0) return; | |
406 | ||
407 | TString evfoldname; | |
408 | TFolder* evfold = fRunLoader->GetEventFolder(); | |
409 | if (evfold) evfoldname = evfold->GetName(); | |
21bf7095 | 410 | else AliWarning("Did not get Event Folder from Run Loader"); |
88cb7938 | 411 | |
412 | if ( fRunLoader->GetAliRun() ) | |
413 | {//if alrun already exists in folder | |
414 | if (fRunLoader->GetAliRun() != this ) | |
415 | {//and is different than this - crash | |
21bf7095 | 416 | AliFatal("AliRun is already in Folder and it is not this object"); |
88cb7938 | 417 | return;//pro forma |
418 | }//else do nothing | |
419 | } | |
420 | else | |
421 | { | |
422 | evfold->Add(this);//Post this AliRun to Folder | |
423 | } | |
424 | ||
425 | TIter next(fModules); | |
426 | AliModule *module; | |
427 | while((module = (AliModule*)next())) | |
428 | { | |
429 | if (evfold) AliConfig::Instance()->Add(module,evfoldname); | |
1d6fbf6e | 430 | module->SetRunLoader(fRunLoader); |
88cb7938 | 431 | AliDetector* detector = dynamic_cast<AliDetector*>(module); |
432 | if (detector) | |
433 | { | |
434 | AliLoader* loader = fRunLoader->GetLoader(detector); | |
435 | if (loader == 0x0) | |
436 | { | |
21bf7095 | 437 | AliError(Form("Can not get loader for detector %s", detector->GetName())); |
88cb7938 | 438 | } |
439 | else | |
440 | { | |
21bf7095 | 441 | AliDebug(1, Form("Setting loader for detector %s", detector->GetName())); |
88cb7938 | 442 | detector->SetLoader(loader); |
443 | } | |
0592d1ca | 444 | } |
88cb7938 | 445 | } |
0592d1ca | 446 | } |
447 | ||
88cb7938 | 448 | void AliRun::AddModule(AliModule* mod) |
7a16e9cc | 449 | { |
2057aecb | 450 | // |
451 | // Add a module to the module list | |
452 | // | |
88cb7938 | 453 | if (mod == 0x0) return; |
454 | if (strlen(mod->GetName()) == 0) return; | |
455 | if (GetModuleID(mod->GetName()) >= 0) return; | |
456 | ||
21bf7095 | 457 | AliDebug(1, mod->GetName()); |
88cb7938 | 458 | if (fRunLoader == 0x0) AliConfig::Instance()->Add(mod); |
459 | else AliConfig::Instance()->Add(mod,fRunLoader->GetEventFolder()->GetName()); | |
7a16e9cc | 460 | |
88cb7938 | 461 | Modules()->Add(mod); |
67d736ee | 462 | |
463 | fNdets++; | |
7a16e9cc | 464 | } |
21bf7095 | 465 |