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