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