]>
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 <TBRIK.h> |
88cb7938 | 44 | #include <TCint.h> |
5d12ce38 | 45 | #include <TDatabasePDG.h> |
88cb7938 | 46 | #include <TGeometry.h> |
88cb7938 | 47 | #include <TNode.h> |
88cb7938 | 48 | #include <TROOT.h> |
88cb7938 | 49 | #include <TRandom3.h> |
50 | #include <TSystem.h> | |
88cb7938 | 51 | #include <TVirtualMC.h> |
178a256c | 52 | #include <TGeoManager.h> |
5d12ce38 | 53 | // |
21bf7095 | 54 | #include "AliLog.h" |
98490ea9 | 55 | #include "AliDetector.h" |
fe4da5cc | 56 | #include "AliDisplay.h" |
98490ea9 | 57 | #include "AliHeader.h" |
dffd31ef | 58 | #include "AliLego.h" |
98490ea9 | 59 | #include "AliLegoGenerator.h" |
5d12ce38 | 60 | #include "AliMC.h" |
aee8290b | 61 | #include "AliMagFC.h" |
62 | #include "AliMagFCM.h" | |
63 | #include "AliMagFDM.h" | |
141f90e3 | 64 | #include "AliPDG.h" |
98490ea9 | 65 | #include "AliRun.h" |
66 | #include "AliStack.h" | |
b3276c04 | 67 | #include "AliCDBManager.h" |
995ad051 | 68 | #include "AliAlignObj.h" |
fe4da5cc | 69 | |
fe4da5cc | 70 | AliRun *gAlice; |
71 | ||
fe4da5cc | 72 | ClassImp(AliRun) |
73 | ||
e2afb3b6 | 74 | //_______________________________________________________________________ |
75 | AliRun::AliRun(): | |
3d45e923 | 76 | fRun(-1), |
e2afb3b6 | 77 | fEvent(0), |
78 | fEventNrInRun(0), | |
79 | fEventsPerRun(0), | |
e2afb3b6 | 80 | fModules(0), |
81 | fGeometry(0), | |
5d12ce38 | 82 | fMCApp(0), |
e2afb3b6 | 83 | fDisplay(0), |
e2afb3b6 | 84 | fField(0), |
e2afb3b6 | 85 | fNdets(0), |
e2afb3b6 | 86 | fInitDone(kFALSE), |
87 | fLego(0), | |
88 | fPDGDB(0), //Particle factory object | |
4539539b | 89 | fConfigFunction(""), |
e2afb3b6 | 90 | fRandom(0), |
fe12e09c | 91 | fBaseFileName(""), |
4a9de4af | 92 | fIsRootGeometry(kFALSE), |
ced249e6 | 93 | fGeometryFromCDB(kFALSE), |
4539539b | 94 | fGeometryFileName(""), |
95 | fTriggerDescriptor(""), | |
5d12ce38 | 96 | fRunLoader(0x0) |
fe4da5cc | 97 | { |
98 | // | |
99 | // Default constructor for AliRun | |
100 | // | |
88cb7938 | 101 | AliConfig::Instance();//skowron 29 Feb 2002 |
102 | //ensures that the folder structure is build | |
3d45e923 | 103 | |
e2afb3b6 | 104 | } |
105 | ||
106 | //_______________________________________________________________________ | |
107 | AliRun::AliRun(const AliRun& arun): | |
5d12ce38 | 108 | TNamed(arun), |
3d45e923 | 109 | fRun(-1), |
e2afb3b6 | 110 | fEvent(0), |
111 | fEventNrInRun(0), | |
112 | fEventsPerRun(0), | |
e2afb3b6 | 113 | fModules(0), |
114 | fGeometry(0), | |
5d12ce38 | 115 | fMCApp(0), |
e2afb3b6 | 116 | fDisplay(0), |
e2afb3b6 | 117 | fField(0), |
e2afb3b6 | 118 | fNdets(0), |
e2afb3b6 | 119 | fInitDone(kFALSE), |
120 | fLego(0), | |
121 | fPDGDB(0), //Particle factory object | |
e2afb3b6 | 122 | fConfigFunction("\0"), |
123 | fRandom(0), | |
fe12e09c | 124 | fBaseFileName(""), |
4a9de4af | 125 | fIsRootGeometry(kFALSE), |
ced249e6 | 126 | fGeometryFromCDB(kFALSE), |
4539539b | 127 | fGeometryFileName(""), |
128 | fTriggerDescriptor(""), | |
88cb7938 | 129 | fRunLoader(0x0) |
e2afb3b6 | 130 | { |
131 | // | |
132 | // Copy constructor for AliRun | |
133 | // | |
134 | arun.Copy(*this); | |
fe4da5cc | 135 | } |
136 | ||
137 | //_____________________________________________________________________________ | |
e2afb3b6 | 138 | AliRun::AliRun(const char *name, const char *title): |
5d12ce38 | 139 | TNamed(name,title), |
3d45e923 | 140 | fRun(-1), |
e2afb3b6 | 141 | fEvent(0), |
142 | fEventNrInRun(0), | |
143 | fEventsPerRun(0), | |
e2afb3b6 | 144 | fModules(new TObjArray(77)), // Support list for the Detectors |
145 | fGeometry(0), | |
5d12ce38 | 146 | fMCApp(0), |
e2afb3b6 | 147 | fDisplay(0), |
e2afb3b6 | 148 | fField(0), |
e2afb3b6 | 149 | fNdets(0), |
e2afb3b6 | 150 | fInitDone(kFALSE), |
151 | fLego(0), | |
152 | fPDGDB(TDatabasePDG::Instance()), //Particle factory object! | |
e2afb3b6 | 153 | fConfigFunction("Config();"), |
154 | fRandom(new TRandom3()), | |
fe12e09c | 155 | fBaseFileName(""), |
4a9de4af | 156 | fIsRootGeometry(kFALSE), |
ced249e6 | 157 | fGeometryFromCDB(kFALSE), |
4539539b | 158 | fGeometryFileName(""), |
159 | fTriggerDescriptor(""), | |
b60e0f5e | 160 | fRunLoader(0x0) |
fe4da5cc | 161 | { |
162 | // | |
163 | // Constructor for the main processor. | |
164 | // Creates the geometry | |
165 | // Creates the list of Detectors. | |
166 | // Creates the list of particles. | |
167 | // | |
e2afb3b6 | 168 | |
fe4da5cc | 169 | gAlice = this; |
65fb704d | 170 | |
171 | // Set random number generator | |
e2afb3b6 | 172 | gRandom = fRandom; |
2ab0c725 | 173 | |
174 | if (gSystem->Getenv("CONFIG_SEED")) { | |
e2afb3b6 | 175 | gRandom->SetSeed(static_cast<UInt_t>(atoi(gSystem->Getenv("CONFIG_SEED")))); |
2ab0c725 | 176 | } |
e2afb3b6 | 177 | |
178 | // Add to list of browsable | |
fe4da5cc | 179 | gROOT->GetListOfBrowsables()->Add(this,name); |
fe4da5cc | 180 | |
fe4da5cc | 181 | // Create default mag field |
182 | SetField(); | |
e2afb3b6 | 183 | |
e2afb3b6 | 184 | // Add particle list to configuration |
9e1a0ddb | 185 | AliConfig::Instance()->Add(fPDGDB); |
e2afb3b6 | 186 | |
fe4da5cc | 187 | } |
188 | ||
aee8290b | 189 | |
e2afb3b6 | 190 | //_______________________________________________________________________ |
fe4da5cc | 191 | AliRun::~AliRun() |
192 | { | |
193 | // | |
2ab0c725 | 194 | // Default AliRun destructor |
fe4da5cc | 195 | // |
88cb7938 | 196 | gROOT->GetListOfBrowsables()->Remove(this); |
197 | ||
198 | if (fRunLoader) | |
199 | { | |
200 | TFolder* evfold = fRunLoader->GetEventFolder(); | |
201 | TFolder* modfold = dynamic_cast<TFolder*>(evfold->FindObjectAny(AliConfig::GetModulesFolderName())); | |
202 | TIter next(fModules); | |
203 | AliModule *mod; | |
204 | while((mod = (AliModule*)next())) | |
205 | { | |
206 | modfold->Remove(mod); | |
207 | } | |
208 | } | |
5d12ce38 | 209 | |
210 | ||
fe4da5cc | 211 | delete fField; |
5d12ce38 | 212 | delete fMCApp; |
f5bc1485 | 213 | delete gMC; gMC=0; |
fe4da5cc | 214 | delete fGeometry; |
215 | delete fDisplay; | |
fe4da5cc | 216 | delete fLego; |
8494b010 | 217 | if (fModules) { |
218 | fModules->Delete(); | |
219 | delete fModules; | |
fe4da5cc | 220 | } |
88cb7938 | 221 | |
c222d2b0 | 222 | delete fPDGDB; |
fe4da5cc | 223 | } |
224 | ||
e2afb3b6 | 225 | //_______________________________________________________________________ |
6c4904c2 | 226 | void AliRun::Copy(TObject &) const |
e2afb3b6 | 227 | { |
21bf7095 | 228 | AliFatal("Not implemented!"); |
e2afb3b6 | 229 | } |
230 | ||
e2afb3b6 | 231 | //_______________________________________________________________________ |
fe4da5cc | 232 | void AliRun::Build() |
233 | { | |
234 | // | |
235 | // Initialize Alice geometry | |
236 | // Dummy routine | |
237 | // | |
238 | } | |
239 | ||
e2afb3b6 | 240 | //_______________________________________________________________________ |
fe4da5cc | 241 | void AliRun::BuildSimpleGeometry() |
242 | { | |
243 | // | |
244 | // Create a simple TNode geometry used by Root display engine | |
245 | // | |
246 | // Initialise geometry | |
247 | // | |
248 | fGeometry = new TGeometry("AliceGeom","Galice Geometry for Hits"); | |
249 | new TMaterial("void","Vacuum",0,0,0); //Everything is void | |
250 | TBRIK *brik = new TBRIK("S_alice","alice volume","void",2000,2000,3000); | |
251 | brik->SetVisibility(0); | |
252 | new TNode("alice","alice","S_alice"); | |
253 | } | |
254 | ||
e2afb3b6 | 255 | //_______________________________________________________________________ |
fe4da5cc | 256 | void AliRun::CleanDetectors() |
257 | { | |
258 | // | |
259 | // Clean Detectors at the end of event | |
260 | // | |
88cb7938 | 261 | fRunLoader->CleanDetectors(); |
fe4da5cc | 262 | } |
263 | ||
e2afb3b6 | 264 | //_______________________________________________________________________ |
5d12ce38 | 265 | void AliRun::ResetHits() |
fe4da5cc | 266 | { |
5d12ce38 | 267 | fMCApp->ResetHits(); |
fe4da5cc | 268 | } |
269 | ||
e2afb3b6 | 270 | //_______________________________________________________________________ |
5d12ce38 | 271 | AliGenerator* AliRun::Generator() const |
fe4da5cc | 272 | { |
5d12ce38 | 273 | return fMCApp->Generator(); |
fe4da5cc | 274 | } |
275 | ||
e2afb3b6 | 276 | //_______________________________________________________________________ |
d8408e76 | 277 | void AliRun::SetField(AliMagF* magField) |
278 | { | |
2057aecb | 279 | // |
280 | // Set Magnetic Field Map | |
281 | // | |
282 | fField = magField; | |
283 | fField->ReadField(); | |
d8408e76 | 284 | } |
285 | ||
4a9de4af | 286 | //_______________________________________________________________________ |
287 | void AliRun::SetRootGeometry(Bool_t flag) | |
288 | { | |
289 | // Instruct application that the geometry is to be retreived from a root file. | |
290 | fIsRootGeometry = flag; | |
e8572077 | 291 | if (flag && gMC) gMC->SetRootGeometry(); |
4a9de4af | 292 | } |
ced249e6 | 293 | |
294 | //_______________________________________________________________________ | |
295 | void AliRun::SetGeometryFromCDB() | |
296 | { | |
297 | // Set the loading of geometry from cdb instead of creating it | |
298 | // A default CDB storage needs to be set before this method is called | |
3d45e923 | 299 | if(AliCDBManager::Instance()->IsDefaultStorageSet() && |
300 | AliCDBManager::Instance()->GetRun() >= 0){ | |
ced249e6 | 301 | SetRootGeometry(); |
302 | fGeometryFromCDB = kTRUE; | |
303 | }else{ | |
304 | AliError("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); | |
305 | AliError("Loading of geometry from CDB ignored. First set a default CDB storage!"); | |
306 | AliError("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); | |
307 | } | |
308 | } | |
309 | ||
e2afb3b6 | 310 | //_______________________________________________________________________ |
fe4da5cc | 311 | void AliRun::SetField(Int_t type, Int_t version, Float_t scale, |
07c4aae4 | 312 | Float_t maxField, const char* filename) |
fe4da5cc | 313 | { |
314 | // | |
315 | // Set magnetic field parameters | |
316 | // type Magnetic field transport flag 0=no field, 2=helix, 3=Runge Kutta | |
317 | // version Magnetic field map version (only 1 active now) | |
318 | // scale Scale factor for the magnetic field | |
319 | // maxField Maximum value for the magnetic field | |
320 | ||
321 | // | |
322 | // --- Sanity check on mag field flags | |
fe4da5cc | 323 | if(fField) delete fField; |
324 | if(version==1) { | |
d8408e76 | 325 | fField = new AliMagFC("Map1"," ",type,scale,maxField); |
f1b9d7c3 | 326 | } else if(version<=2) { |
d8408e76 | 327 | fField = new AliMagFCM("Map2-3",filename,type,scale,maxField); |
fe4da5cc | 328 | fField->ReadField(); |
f1b9d7c3 | 329 | } else if(version==3) { |
d8408e76 | 330 | fField = new AliMagFDM("Map4",filename,type,scale,maxField); |
f1b9d7c3 | 331 | fField->ReadField(); |
fe4da5cc | 332 | } else { |
21bf7095 | 333 | AliWarning(Form("Invalid map %d",version)); |
fe4da5cc | 334 | } |
335 | } | |
88cb7938 | 336 | |
337 | //_____________________________________________________________________________ | |
338 | ||
339 | void AliRun::InitLoaders() | |
340 | { | |
341 | //creates list of getters | |
21bf7095 | 342 | AliDebug(1, ""); |
88cb7938 | 343 | TIter next(fModules); |
344 | AliModule *mod; | |
345 | while((mod = (AliModule*)next())) | |
346 | { | |
1d6fbf6e | 347 | mod->SetRunLoader(fRunLoader); |
88cb7938 | 348 | AliDetector *det = dynamic_cast<AliDetector*>(mod); |
349 | if (det) | |
350 | { | |
21bf7095 | 351 | AliDebug(2, Form("Adding %s", det->GetName())); |
88cb7938 | 352 | fRunLoader->AddLoader(det); |
353 | } | |
354 | } | |
21bf7095 | 355 | AliDebug(1, "Done"); |
88cb7938 | 356 | } |
357 | //_____________________________________________________________________________ | |
358 | ||
fe4da5cc | 359 | void AliRun::FinishRun() |
360 | { | |
361 | // | |
362 | // Called at the end of the run. | |
363 | // | |
07d55def | 364 | |
88cb7938 | 365 | if(fLego) |
366 | { | |
21bf7095 | 367 | AliDebug(1, "Finish Lego"); |
88cb7938 | 368 | fRunLoader->CdGAFile(); |
369 | fLego->FinishRun(); | |
370 | } | |
8e70f139 | 371 | |
fe4da5cc | 372 | // Clean detector information |
8494b010 | 373 | TIter next(fModules); |
374 | AliModule *detector; | |
e2afb3b6 | 375 | while((detector = dynamic_cast<AliModule*>(next()))) { |
21bf7095 | 376 | AliDebug(2, Form("%s->FinishRun()", detector->GetName())); |
fe4da5cc | 377 | detector->FinishRun(); |
378 | } | |
379 | ||
21bf7095 | 380 | AliDebug(1, "fRunLoader->WriteHeader(OVERWRITE)"); |
88cb7938 | 381 | fRunLoader->WriteHeader("OVERWRITE"); |
682a4a95 | 382 | |
88cb7938 | 383 | // Write AliRun info and all detectors parameters |
384 | fRunLoader->CdGAFile(); | |
385 | Write(0,TObject::kOverwrite);//write AliRun | |
386 | fRunLoader->Write(0,TObject::kOverwrite);//write RunLoader itself | |
387 | ||
07d55def | 388 | if(fMCApp) fMCApp->FinishRun(); |
5d12ce38 | 389 | fRunLoader->Synchronize(); |
fe4da5cc | 390 | } |
391 | ||
eb1b8d29 | 392 | //_______________________________________________________________________ |
393 | void AliRun::Announce() const | |
394 | { | |
395 | // | |
37d06d5b | 396 | // Announce the current version of AliRoot |
397 | // | |
398 | printf("%70s", | |
399 | "****************************************************************\n"); | |
400 | printf("%6s","*");printf("%64s","*\n"); | |
401 | ||
402 | printf("%6s","*"); | |
88cb7938 | 403 | printf(" You are running AliRoot version NewIO\n"); |
37d06d5b | 404 | |
405 | printf("%6s","*"); | |
5960f18d | 406 | printf(" The SVN version for the current program is $Id$\n"); |
37d06d5b | 407 | |
408 | printf("%6s","*");printf("%64s","*\n"); | |
409 | printf("%70s", | |
410 | "****************************************************************\n"); | |
eb1b8d29 | 411 | } |
412 | ||
e2afb3b6 | 413 | //_______________________________________________________________________ |
94de3818 | 414 | AliModule *AliRun::GetModule(const char *name) const |
fe4da5cc | 415 | { |
416 | // | |
417 | // Return pointer to detector from name | |
418 | // | |
e2afb3b6 | 419 | return dynamic_cast<AliModule*>(fModules->FindObject(name)); |
fe4da5cc | 420 | } |
421 | ||
e2afb3b6 | 422 | //_______________________________________________________________________ |
94de3818 | 423 | AliDetector *AliRun::GetDetector(const char *name) const |
a68348e9 | 424 | { |
425 | // | |
426 | // Return pointer to detector from name | |
427 | // | |
e2afb3b6 | 428 | return dynamic_cast<AliDetector*>(fModules->FindObject(name)); |
a68348e9 | 429 | } |
430 | ||
e2afb3b6 | 431 | //_______________________________________________________________________ |
94de3818 | 432 | Int_t AliRun::GetModuleID(const char *name) const |
fe4da5cc | 433 | { |
434 | // | |
435 | // Return galice internal detector identifier from name | |
436 | // | |
23370b7a | 437 | Int_t i=-1; |
438 | TObject *mod=fModules->FindObject(name); | |
439 | if(mod) i=fModules->IndexOf(mod); | |
440 | return i; | |
fe4da5cc | 441 | } |
442 | ||
e2afb3b6 | 443 | //_______________________________________________________________________ |
fe4da5cc | 444 | Int_t AliRun::GetEvent(Int_t event) |
445 | { | |
88cb7938 | 446 | // |
447 | // Reloads data containers in folders # event | |
448 | // Set branch addresses | |
449 | // | |
450 | if (fRunLoader == 0x0) | |
451 | { | |
21bf7095 | 452 | AliError("RunLoader is not set. Can not load data."); |
88cb7938 | 453 | return -1; |
454 | } | |
455 | /*****************************************/ | |
456 | /**** P R E R E L O A D I N G ****/ | |
457 | /*****************************************/ | |
458 | // Reset existing structures | |
5d12ce38 | 459 | fMCApp->ResetHits(); |
460 | fMCApp->ResetTrackReferences(); | |
fe4da5cc | 461 | ResetDigits(); |
2ab0c725 | 462 | ResetSDigits(); |
50a6540a | 463 | |
88cb7938 | 464 | /*****************************************/ |
465 | /**** R E L O A D ****/ | |
466 | /*****************************************/ | |
aab9c8d5 | 467 | |
88cb7938 | 468 | fRunLoader->GetEvent(event); |
b9d0a01d | 469 | |
88cb7938 | 470 | /*****************************************/ |
471 | /**** P O S T R E L O A D I N G ****/ | |
472 | /*****************************************/ | |
82711e7a | 473 | |
fe4da5cc | 474 | // Set Trees branch addresses |
8494b010 | 475 | TIter next(fModules); |
07d55def | 476 | AliDetector *detector; |
477 | while((detector = dynamic_cast<AliDetector*>(next()))) | |
88cb7938 | 478 | { |
479 | detector->SetTreeAddress(); | |
480 | } | |
481 | ||
482 | return fRunLoader->GetHeader()->GetNtrack(); | |
fe4da5cc | 483 | } |
484 | ||
e2afb3b6 | 485 | //_______________________________________________________________________ |
fe4da5cc | 486 | TGeometry *AliRun::GetGeometry() |
487 | { | |
07d55def | 488 | |
70760df0 | 489 | // Create the TNode geometry for the event display |
27cf3cdc | 490 | if (!fGeometry) { |
491 | BuildSimpleGeometry(); | |
492 | // | |
493 | // Unlink and relink nodes in detectors | |
494 | // This is bad and there must be a better way... | |
495 | // | |
fe4da5cc | 496 | |
27cf3cdc | 497 | TIter next(fModules); |
498 | AliModule *detector; | |
499 | while((detector = dynamic_cast<AliModule*>(next()))) { | |
500 | detector->BuildGeometry(); | |
501 | TList *dnodes=detector->Nodes(); | |
502 | Int_t j; | |
503 | TNode *node, *node1; | |
504 | for ( j=0; j<dnodes->GetSize(); j++) { | |
505 | node = dynamic_cast<TNode*>(dnodes->At(j)); | |
506 | node1 = fGeometry->GetNode(node->GetName()); | |
507 | dnodes->Remove(node); | |
508 | dnodes->AddAt(node1,j); | |
509 | } | |
fe4da5cc | 510 | } |
511 | } | |
512 | return fGeometry; | |
513 | } | |
514 | ||
e2afb3b6 | 515 | //_______________________________________________________________________ |
516 | void AliRun::SetBaseFile(const char *filename) | |
2ab0c725 | 517 | { |
39de14fb | 518 | fBaseFileName = filename; |
2ab0c725 | 519 | } |
520 | ||
e2afb3b6 | 521 | //_______________________________________________________________________ |
b9d0a01d | 522 | void AliRun::ResetDigits() |
fe4da5cc | 523 | { |
524 | // | |
b9d0a01d | 525 | // Reset all Detectors digits |
fe4da5cc | 526 | // |
b9d0a01d | 527 | TIter next(fModules); |
528 | AliModule *detector; | |
e2afb3b6 | 529 | while((detector = dynamic_cast<AliModule*>(next()))) { |
b9d0a01d | 530 | detector->ResetDigits(); |
531 | } | |
532 | } | |
533 | ||
e2afb3b6 | 534 | //_______________________________________________________________________ |
b9d0a01d | 535 | void AliRun::ResetSDigits() |
536 | { | |
dffd31ef | 537 | // |
b9d0a01d | 538 | // Reset all Detectors digits |
9e1a0ddb | 539 | // |
b9d0a01d | 540 | TIter next(fModules); |
541 | AliModule *detector; | |
e2afb3b6 | 542 | while((detector = dynamic_cast<AliModule*>(next()))) { |
b9d0a01d | 543 | detector->ResetSDigits(); |
544 | } | |
545 | } | |
dffd31ef | 546 | |
2b22f272 | 547 | |
e2afb3b6 | 548 | //_______________________________________________________________________ |
88cb7938 | 549 | |
b9d0a01d | 550 | void AliRun::ResetPoints() |
fe4da5cc | 551 | { |
552 | // | |
b9d0a01d | 553 | // Reset all Detectors points |
fe4da5cc | 554 | // |
8494b010 | 555 | TIter next(fModules); |
556 | AliModule *detector; | |
e2afb3b6 | 557 | while((detector = dynamic_cast<AliModule*>(next()))) { |
b9d0a01d | 558 | detector->ResetPoints(); |
fe4da5cc | 559 | } |
560 | } | |
e2afb3b6 | 561 | //_______________________________________________________________________ |
88cb7938 | 562 | |
b9d0a01d | 563 | void AliRun::InitMC(const char *setup) |
2ab0c725 | 564 | { |
565 | // | |
5d12ce38 | 566 | // Initialize ALICE Simulation run |
2ab0c725 | 567 | // |
37d06d5b | 568 | Announce(); |
569 | ||
b9d0a01d | 570 | if(fInitDone) { |
21bf7095 | 571 | AliWarning("Cannot initialise AliRun twice!"); |
b9d0a01d | 572 | return; |
fe4da5cc | 573 | } |
b9d0a01d | 574 | |
67d736ee | 575 | if (!fMCApp) |
576 | fMCApp=new AliMC(GetName(),GetTitle()); | |
5d12ce38 | 577 | |
b9d0a01d | 578 | gROOT->LoadMacro(setup); |
579 | gInterpreter->ProcessLine(fConfigFunction.Data()); | |
fe4da5cc | 580 | |
3d45e923 | 581 | if(AliCDBManager::Instance()->GetRun() >= 0) { |
582 | SetRunNumber(AliCDBManager::Instance()->GetRun()); | |
583 | } else { | |
584 | AliWarning("Run number not initialized!!"); | |
585 | } | |
b3276c04 | 586 | |
88cb7938 | 587 | fRunLoader->CdGAFile(); |
07d55def | 588 | |
141f90e3 | 589 | AliPDG::AddParticlesToPdgDataBase(); |
aab9c8d5 | 590 | |
b9d0a01d | 591 | fNdets = fModules->GetLast()+1; |
88cb7938 | 592 | TIter next(fModules); |
5d12ce38 | 593 | for(Int_t i=0; i<fNdets; ++i) |
88cb7938 | 594 | { |
5d12ce38 | 595 | TObject *objfirst, *objlast; |
596 | AliModule *detector=dynamic_cast<AliModule*>(fModules->At(i)); | |
88cb7938 | 597 | objlast = gDirectory->GetList()->Last(); |
b9d0a01d | 598 | |
88cb7938 | 599 | // Add Detector histograms in Detector list of histograms |
600 | if (objlast) objfirst = gDirectory->GetList()->After(objlast); | |
601 | else objfirst = gDirectory->GetList()->First(); | |
602 | while (objfirst) | |
603 | { | |
b9d0a01d | 604 | detector->Histograms()->Add(objfirst); |
605 | objfirst = gDirectory->GetList()->After(objfirst); | |
606 | } | |
607 | } | |
b9d0a01d | 608 | |
5d12ce38 | 609 | fMCApp->Init(); |
b9d0a01d | 610 | |
504b172d | 611 | //Must be here because some MCs (G4) adds detectors here and not in Config.C |
612 | InitLoaders(); | |
613 | fRunLoader->MakeTree("E"); | |
614 | if (fLego == 0x0) | |
615 | { | |
616 | fRunLoader->LoadKinematics("RECREATE"); | |
617 | fRunLoader->LoadTrackRefs("RECREATE"); | |
618 | fRunLoader->LoadHits("all","RECREATE"); | |
619 | } | |
b9d0a01d | 620 | fInitDone = kTRUE; |
b9d0a01d | 621 | // |
622 | // Save stuff at the beginning of the file to avoid file corruption | |
504b172d | 623 | fRunLoader->CdGAFile(); |
b9d0a01d | 624 | Write(); |
88cb7938 | 625 | fEventNrInRun = -1; //important - we start Begin event from increasing current number in run |
fe4da5cc | 626 | } |
627 | ||
e2afb3b6 | 628 | //_______________________________________________________________________ |
88cb7938 | 629 | |
875c717b | 630 | void AliRun::RunMC(Int_t nevent, const char *setup) |
fe4da5cc | 631 | { |
632 | // | |
633 | // Main function to be called to process a galice run | |
634 | // example | |
635 | // Root > gAlice.Run(); | |
636 | // a positive number of events will cause the finish routine | |
637 | // to be called | |
638 | // | |
88cb7938 | 639 | fEventsPerRun = nevent; |
fe4da5cc | 640 | // check if initialisation has been done |
875c717b | 641 | if (!fInitDone) InitMC(setup); |
fe4da5cc | 642 | |
fe4da5cc | 643 | // Create the Root Tree with one branch per detector |
88cb7938 | 644 | //Hits moved to begin event -> now we are crating separate tree for each event |
fe4da5cc | 645 | |
875c717b | 646 | gMC->ProcessRun(nevent); |
647 | ||
fe4da5cc | 648 | // End of this run, close files |
80762cb1 | 649 | if(nevent>0) FinishRun(); |
fe4da5cc | 650 | } |
651 | ||
e2afb3b6 | 652 | //_______________________________________________________________________ |
27f087a9 | 653 | void AliRun::RunReco(const char *selected, Int_t first, Int_t last) |
d47c658f | 654 | { |
655 | // | |
656 | // Main function to be called to reconstruct Alice event | |
27f087a9 | 657 | // |
88cb7938 | 658 | Int_t nev = fRunLoader->GetNumberOfEvents(); |
21bf7095 | 659 | AliDebug(1, Form("Found %d events", nev)); |
27f087a9 | 660 | Int_t nFirst = first; |
88cb7938 | 661 | Int_t nLast = (last < 0)? nev : last; |
27f087a9 | 662 | |
663 | for (Int_t nevent = nFirst; nevent <= nLast; nevent++) { | |
21bf7095 | 664 | AliDebug(1, Form("Processing event %d", nevent)); |
9e1a0ddb | 665 | GetEvent(nevent); |
9e1a0ddb | 666 | Digits2Reco(selected); |
667 | } | |
d47c658f | 668 | } |
669 | ||
e2afb3b6 | 670 | //_______________________________________________________________________ |
2ab0c725 | 671 | |
672 | void AliRun::Hits2Digits(const char *selected) | |
673 | { | |
9e1a0ddb | 674 | |
d47c658f | 675 | // Convert Hits to sumable digits |
676 | // | |
9e1a0ddb | 677 | for (Int_t nevent=0; nevent<gAlice->TreeE()->GetEntries(); nevent++) { |
678 | GetEvent(nevent); | |
9e1a0ddb | 679 | Hits2SDigits(selected); |
680 | SDigits2Digits(selected); | |
681 | } | |
2ab0c725 | 682 | } |
683 | ||
d47c658f | 684 | |
e2afb3b6 | 685 | //_______________________________________________________________________ |
2ab0c725 | 686 | |
d47c658f | 687 | void AliRun::Tree2Tree(Option_t *option, const char *selected) |
2ab0c725 | 688 | { |
689 | // | |
d47c658f | 690 | // Function to transform the content of |
691 | // | |
692 | // - TreeH to TreeS (option "S") | |
693 | // - TreeS to TreeD (option "D") | |
694 | // - TreeD to TreeR (option "R") | |
695 | // | |
696 | // If multiple options are specified ("SDR"), transformation will be done in sequence for | |
697 | // selected detector and for all detectors if none is selected (detector string | |
698 | // can contain blank separated list of detector names). | |
2ab0c725 | 699 | |
2ab0c725 | 700 | |
5cf7bbad | 701 | const char *oS = strstr(option,"S"); |
702 | const char *oD = strstr(option,"D"); | |
703 | const char *oR = strstr(option,"R"); | |
2ab0c725 | 704 | |
9e1a0ddb | 705 | TObjArray *detectors = Detectors(); |
2ab0c725 | 706 | |
707 | TIter next(detectors); | |
708 | ||
d47c658f | 709 | AliDetector *detector = 0; |
2ab0c725 | 710 | |
88cb7938 | 711 | while((detector = dynamic_cast<AliDetector*>(next()))) { |
d47c658f | 712 | if (selected) |
2ab0c725 | 713 | if (strcmp(detector->GetName(),selected)) continue; |
88cb7938 | 714 | if (detector->IsActive()) |
715 | { | |
716 | ||
717 | AliLoader* loader = detector->GetLoader(); | |
718 | if (loader == 0x0) continue; | |
719 | ||
720 | if (oS) | |
721 | { | |
21bf7095 | 722 | AliDebug(1, Form("Processing Hits2SDigits for %s ...", detector->GetName())); |
88cb7938 | 723 | loader->LoadHits("read"); |
724 | if (loader->TreeS() == 0x0) loader->MakeTree("S"); | |
725 | detector->MakeBranch(option); | |
726 | detector->SetTreeAddress(); | |
727 | detector->Hits2SDigits(); | |
728 | loader->UnloadHits(); | |
729 | loader->UnloadSDigits(); | |
730 | } | |
731 | if (oD) | |
732 | { | |
21bf7095 | 733 | AliDebug(1, Form("Processing SDigits2Digits for %s ...", detector->GetName())); |
88cb7938 | 734 | loader->LoadSDigits("read"); |
735 | if (loader->TreeD() == 0x0) loader->MakeTree("D"); | |
736 | detector->MakeBranch(option); | |
737 | detector->SetTreeAddress(); | |
738 | detector->SDigits2Digits(); | |
739 | loader->UnloadSDigits(); | |
740 | loader->UnloadDigits(); | |
741 | } | |
742 | if (oR) | |
743 | { | |
21bf7095 | 744 | AliDebug(1, Form("Processing Digits2Reco for %s ...", detector->GetName())); |
88cb7938 | 745 | loader->LoadDigits("read"); |
746 | if (loader->TreeR() == 0x0) loader->MakeTree("R"); | |
747 | detector->MakeBranch(option); | |
748 | detector->SetTreeAddress(); | |
749 | detector->Digits2Reco(); | |
750 | loader->UnloadDigits(); | |
751 | loader->UnloadRecPoints(); | |
752 | ||
753 | } | |
754 | } | |
755 | } | |
2ab0c725 | 756 | } |
757 | ||
e2afb3b6 | 758 | //_______________________________________________________________________ |
0a520a66 | 759 | void AliRun::RunLego(const char *setup, Int_t nc1, Float_t c1min, |
760 | Float_t c1max,Int_t nc2,Float_t c2min,Float_t c2max, | |
93dccc77 | 761 | Float_t rmin,Float_t rmax,Float_t zmax, AliLegoGenerator* gener, Int_t nev) |
fe4da5cc | 762 | { |
763 | // | |
764 | // Generates lego plots of: | |
765 | // - radiation length map phi vs theta | |
766 | // - radiation length map phi vs eta | |
767 | // - interaction length map | |
768 | // - g/cm2 length map | |
769 | // | |
770 | // ntheta bins in theta, eta | |
771 | // themin minimum angle in theta (degrees) | |
772 | // themax maximum angle in theta (degrees) | |
773 | // nphi bins in phi | |
774 | // phimin minimum angle in phi (degrees) | |
775 | // phimax maximum angle in phi (degrees) | |
776 | // rmin minimum radius | |
777 | // rmax maximum radius | |
778 | // | |
779 | // | |
780 | // The number of events generated = ntheta*nphi | |
781 | // run input parameters in macro setup (default="Config.C") | |
782 | // | |
783 | // Use macro "lego.C" to visualize the 3 lego plots in spherical coordinates | |
784 | //Begin_Html | |
785 | /* | |
1439f98e | 786 | <img src="picts/AliRunLego1.gif"> |
fe4da5cc | 787 | */ |
788 | //End_Html | |
789 | //Begin_Html | |
790 | /* | |
1439f98e | 791 | <img src="picts/AliRunLego2.gif"> |
fe4da5cc | 792 | */ |
793 | //End_Html | |
794 | //Begin_Html | |
795 | /* | |
1439f98e | 796 | <img src="picts/AliRunLego3.gif"> |
fe4da5cc | 797 | */ |
798 | //End_Html | |
799 | // | |
93dccc77 | 800 | // Number of events |
801 | if (nev == -1) nev = nc1 * nc2; | |
802 | ||
fe4da5cc | 803 | // check if initialisation has been done |
2cacde38 | 804 | // If runloader has been initialized, set the number of events per file to nc1 * nc2 |
93dccc77 | 805 | |
0a520a66 | 806 | // Set new generator |
807 | if (!gener) gener = new AliLegoGenerator(); | |
0a520a66 | 808 | // |
809 | // Configure Generator | |
07d55def | 810 | |
0a520a66 | 811 | gener->SetRadiusRange(rmin, rmax); |
812 | gener->SetZMax(zmax); | |
813 | gener->SetCoor1Range(nc1, c1min, c1max); | |
814 | gener->SetCoor2Range(nc2, c2min, c2max); | |
815 | ||
816 | ||
b13db077 | 817 | //Create Lego object |
0a520a66 | 818 | fLego = new AliLego("lego",gener); |
b13db077 | 819 | |
504b172d | 820 | if (!fInitDone) InitMC(setup); |
821 | //Save current generator | |
822 | ||
823 | AliGenerator *gen=fMCApp->Generator(); | |
824 | fMCApp->ResetGenerator(gener); | |
dffd31ef | 825 | //Prepare MC for Lego Run |
826 | gMC->InitLego(); | |
827 | ||
b13db077 | 828 | //Run Lego Object |
0a520a66 | 829 | |
07d55def | 830 | |
93dccc77 | 831 | if (fRunLoader) fRunLoader->SetNumberOfEventsPerFile(nev); |
93dccc77 | 832 | gMC->ProcessRun(nev); |
fe4da5cc | 833 | |
fe4da5cc | 834 | // End of this run, close files |
80762cb1 | 835 | FinishRun(); |
0a520a66 | 836 | // Restore current generator |
5d12ce38 | 837 | fMCApp->ResetGenerator(gen); |
838edcaf | 838 | // Delete Lego Object |
839 | delete fLego; fLego=0; | |
fe4da5cc | 840 | } |
841 | ||
e2afb3b6 | 842 | //_______________________________________________________________________ |
94de3818 | 843 | void AliRun::SetConfigFunction(const char * config) |
844 | { | |
845 | // | |
846 | // Set the signature of the function contained in Config.C to configure | |
847 | // the run | |
848 | // | |
849 | fConfigFunction=config; | |
850 | } | |
851 | ||
b9d0a01d | 852 | // |
853 | // MC Application | |
854 | // | |
855 | ||
e2afb3b6 | 856 | //_______________________________________________________________________ |
b9d0a01d | 857 | void AliRun::Field(const Double_t* x, Double_t *b) const |
858 | { | |
2057aecb | 859 | // |
860 | // Return the value of the magnetic field | |
861 | // | |
07d55def | 862 | |
2057aecb | 863 | Float_t xfloat[3]; |
864 | for (Int_t i=0; i<3; i++) xfloat[i] = x[i]; | |
865 | ||
866 | if (Field()) { | |
07d55def | 867 | |
2057aecb | 868 | Float_t bfloat[3]; |
869 | Field()->Field(xfloat,bfloat); | |
870 | for (Int_t j=0; j<3; j++) b[j] = bfloat[j]; | |
871 | } | |
872 | else { | |
21bf7095 | 873 | AliError("No mag field defined!"); |
2057aecb | 874 | b[0]=b[1]=b[2]=0.; |
875 | } | |
07d55def | 876 | |
877 | ||
b9d0a01d | 878 | } |
879 | ||
880 | // | |
881 | // End of MC Application | |
882 | // | |
883 | ||
e2afb3b6 | 884 | //_______________________________________________________________________ |
fe4da5cc | 885 | void AliRun::Streamer(TBuffer &R__b) |
886 | { | |
eef4b160 | 887 | // Stream an object of class AliRun. |
2ab0c725 | 888 | |
7e90ff59 | 889 | if (R__b.IsReading()) { |
890 | if (!gAlice) gAlice = this; | |
7e90ff59 | 891 | AliRun::Class()->ReadBuffer(R__b, this); |
7e90ff59 | 892 | gROOT->GetListOfBrowsables()->Add(this,"Run"); |
eef4b160 | 893 | |
7e90ff59 | 894 | gRandom = fRandom; |
895 | } else { | |
eef4b160 | 896 | AliRun::Class()->WriteBuffer(R__b, this); |
897 | } | |
2ab0c725 | 898 | } |
e2afb3b6 | 899 | //_______________________________________________________________________ |
b9d0a01d | 900 | |
27f087a9 | 901 | void AliRun::SetGenEventHeader(AliGenEventHeader* header) |
902 | { | |
88cb7938 | 903 | fRunLoader->GetHeader()->SetGenEventHeader(header); |
27f087a9 | 904 | } |
504b172d | 905 | //_______________________________________________________________________ |
0592d1ca | 906 | |
88cb7938 | 907 | Int_t AliRun::GetEvNumber() const |
908 | { | |
909 | //Returns number of current event | |
910 | if (fRunLoader == 0x0) | |
911 | { | |
21bf7095 | 912 | AliError("RunLoader is not set. Can not load data."); |
88cb7938 | 913 | return -1; |
914 | } | |
0592d1ca | 915 | |
88cb7938 | 916 | return fRunLoader->GetEventNumber(); |
0592d1ca | 917 | } |
504b172d | 918 | //_______________________________________________________________________ |
b9d0a01d | 919 | |
88cb7938 | 920 | void AliRun::SetRunLoader(AliRunLoader* rloader) |
0592d1ca | 921 | { |
2057aecb | 922 | // |
923 | // Set the loader of the run | |
924 | // | |
88cb7938 | 925 | fRunLoader = rloader; |
926 | if (fRunLoader == 0x0) return; | |
927 | ||
928 | TString evfoldname; | |
929 | TFolder* evfold = fRunLoader->GetEventFolder(); | |
930 | if (evfold) evfoldname = evfold->GetName(); | |
21bf7095 | 931 | else AliWarning("Did not get Event Folder from Run Loader"); |
88cb7938 | 932 | |
933 | if ( fRunLoader->GetAliRun() ) | |
934 | {//if alrun already exists in folder | |
935 | if (fRunLoader->GetAliRun() != this ) | |
936 | {//and is different than this - crash | |
21bf7095 | 937 | AliFatal("AliRun is already in Folder and it is not this object"); |
88cb7938 | 938 | return;//pro forma |
939 | }//else do nothing | |
940 | } | |
941 | else | |
942 | { | |
943 | evfold->Add(this);//Post this AliRun to Folder | |
944 | } | |
945 | ||
946 | TIter next(fModules); | |
947 | AliModule *module; | |
948 | while((module = (AliModule*)next())) | |
949 | { | |
950 | if (evfold) AliConfig::Instance()->Add(module,evfoldname); | |
1d6fbf6e | 951 | module->SetRunLoader(fRunLoader); |
88cb7938 | 952 | AliDetector* detector = dynamic_cast<AliDetector*>(module); |
953 | if (detector) | |
954 | { | |
955 | AliLoader* loader = fRunLoader->GetLoader(detector); | |
956 | if (loader == 0x0) | |
957 | { | |
21bf7095 | 958 | AliError(Form("Can not get loader for detector %s", detector->GetName())); |
88cb7938 | 959 | } |
960 | else | |
961 | { | |
21bf7095 | 962 | AliDebug(1, Form("Setting loader for detector %s", detector->GetName())); |
88cb7938 | 963 | detector->SetLoader(loader); |
964 | } | |
0592d1ca | 965 | } |
88cb7938 | 966 | } |
0592d1ca | 967 | } |
968 | ||
88cb7938 | 969 | void AliRun::AddModule(AliModule* mod) |
7a16e9cc | 970 | { |
2057aecb | 971 | // |
972 | // Add a module to the module list | |
973 | // | |
88cb7938 | 974 | if (mod == 0x0) return; |
975 | if (strlen(mod->GetName()) == 0) return; | |
976 | if (GetModuleID(mod->GetName()) >= 0) return; | |
977 | ||
21bf7095 | 978 | AliDebug(1, mod->GetName()); |
88cb7938 | 979 | if (fRunLoader == 0x0) AliConfig::Instance()->Add(mod); |
980 | else AliConfig::Instance()->Add(mod,fRunLoader->GetEventFolder()->GetName()); | |
7a16e9cc | 981 | |
88cb7938 | 982 | Modules()->Add(mod); |
67d736ee | 983 | |
984 | fNdets++; | |
7a16e9cc | 985 | } |
21bf7095 | 986 | |
4d81e5e7 | 987 | //_____________________________________________________________________________ |
988 | /*inline*/ Bool_t AliRun::IsFileAccessible(const char* fnam, EAccessMode mode) | |
989 | { return !gSystem->AccessPathName(fnam,mode);} | |
990 | ||
991 | //______________________________________________________ | |
992 | /*inline*/ Bool_t AliRun::IsFileAccessible(Char_t* name,EAccessMode mode) | |
993 | { | |
994 | TString str = name; gSystem->ExpandPathName(str); | |
995 | return !gSystem->AccessPathName(str.Data(),mode); | |
996 | } |