]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliRun.cxx
Removing the hard-wired particle masses (B. Hippolyte)
[u/mrichter/AliRoot.git] / STEER / AliRun.cxx
CommitLineData
99d554c8 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
acd84897 16/* $Id$ */
99d554c8 17
fe4da5cc 18///////////////////////////////////////////////////////////////////////////////
19// //
20// Control class for Alice C++ //
21// Only one single instance of this class exists. //
22// The object is created in main program aliroot //
23// and is pointed by the global gAlice. //
24// //
8494b010 25// -Supports the list of all Alice Detectors (fModules). //
fe4da5cc 26// -Supports the list of particles (fParticles). //
27// -Supports the Trees. //
28// -Supports the geometry. //
29// -Supports the event display. //
30//Begin_Html
31/*
1439f98e 32<img src="picts/AliRunClass.gif">
fe4da5cc 33*/
34//End_Html
35//Begin_Html
36/*
1439f98e 37<img src="picts/alirun.gif">
fe4da5cc 38*/
39//End_Html
40// //
41///////////////////////////////////////////////////////////////////////////////
42
88cb7938 43#include <TCint.h>
88cb7938 44#include <TROOT.h>
88cb7938 45#include <TRandom3.h>
46#include <TSystem.h>
88cb7938 47#include <TVirtualMC.h>
178a256c 48#include <TGeoManager.h>
5d12ce38 49//
21bf7095 50#include "AliLog.h"
98490ea9 51#include "AliDetector.h"
98490ea9 52#include "AliHeader.h"
5d12ce38 53#include "AliMC.h"
aee8290b 54#include "AliMagFC.h"
55#include "AliMagFCM.h"
56#include "AliMagFDM.h"
141f90e3 57#include "AliPDG.h"
98490ea9 58#include "AliRun.h"
59#include "AliStack.h"
b3276c04 60#include "AliCDBManager.h"
995ad051 61#include "AliAlignObj.h"
3e2e3ece 62#include "AliSimulation.h"
63#include "AliLego.h"
fe4da5cc 64
fe4da5cc 65AliRun *gAlice;
66
fe4da5cc 67ClassImp(AliRun)
68
e2afb3b6 69//_______________________________________________________________________
70AliRun::AliRun():
3d45e923 71 fRun(-1),
e2afb3b6 72 fEvent(0),
3e2e3ece 73 fEventNrInRun(-1),
e2afb3b6 74 fModules(0),
5d12ce38 75 fMCApp(0),
e2afb3b6 76 fField(0),
e2afb3b6 77 fNdets(0),
4539539b 78 fConfigFunction(""),
e2afb3b6 79 fRandom(0),
fe12e09c 80 fBaseFileName(""),
4a9de4af 81 fIsRootGeometry(kFALSE),
ced249e6 82 fGeometryFromCDB(kFALSE),
4539539b 83 fGeometryFileName(""),
84 fTriggerDescriptor(""),
5d12ce38 85 fRunLoader(0x0)
fe4da5cc 86{
87 //
88 // Default constructor for AliRun
89 //
88cb7938 90 AliConfig::Instance();//skowron 29 Feb 2002
91 //ensures that the folder structure is build
3d45e923 92
e2afb3b6 93}
94
fe4da5cc 95//_____________________________________________________________________________
e2afb3b6 96AliRun::AliRun(const char *name, const char *title):
5d12ce38 97 TNamed(name,title),
3d45e923 98 fRun(-1),
e2afb3b6 99 fEvent(0),
3e2e3ece 100 fEventNrInRun(-1),
e2afb3b6 101 fModules(new TObjArray(77)), // Support list for the Detectors
3e2e3ece 102 fMCApp(new AliMC(GetName(),GetTitle())),
e2afb3b6 103 fField(0),
e2afb3b6 104 fNdets(0),
e2afb3b6 105 fConfigFunction("Config();"),
106 fRandom(new TRandom3()),
fe12e09c 107 fBaseFileName(""),
4a9de4af 108 fIsRootGeometry(kFALSE),
ced249e6 109 fGeometryFromCDB(kFALSE),
4539539b 110 fGeometryFileName(""),
111 fTriggerDescriptor(""),
b60e0f5e 112 fRunLoader(0x0)
fe4da5cc 113{
114 //
115 // Constructor for the main processor.
116 // Creates the geometry
117 // Creates the list of Detectors.
118 // Creates the list of particles.
119 //
e2afb3b6 120
fe4da5cc 121 gAlice = this;
65fb704d 122
123 // Set random number generator
e2afb3b6 124 gRandom = fRandom;
2ab0c725 125
126 if (gSystem->Getenv("CONFIG_SEED")) {
e2afb3b6 127 gRandom->SetSeed(static_cast<UInt_t>(atoi(gSystem->Getenv("CONFIG_SEED"))));
2ab0c725 128 }
e2afb3b6 129
130 // Add to list of browsable
fe4da5cc 131 gROOT->GetListOfBrowsables()->Add(this,name);
fe4da5cc 132
fe4da5cc 133 // Create default mag field
3e2e3ece 134 fField = new AliMagFC("Map1"," ",2.,1.,10.);
e2afb3b6 135
fe4da5cc 136}
137
aee8290b 138
e2afb3b6 139//_______________________________________________________________________
fe4da5cc 140AliRun::~AliRun()
141{
142 //
2ab0c725 143 // Default AliRun destructor
fe4da5cc 144 //
88cb7938 145 gROOT->GetListOfBrowsables()->Remove(this);
146
147 if (fRunLoader)
148 {
149 TFolder* evfold = fRunLoader->GetEventFolder();
150 TFolder* modfold = dynamic_cast<TFolder*>(evfold->FindObjectAny(AliConfig::GetModulesFolderName()));
151 TIter next(fModules);
152 AliModule *mod;
153 while((mod = (AliModule*)next()))
154 {
155 modfold->Remove(mod);
156 }
157 }
3e2e3ece 158
fe4da5cc 159 delete fField;
5d12ce38 160 delete fMCApp;
f5bc1485 161 delete gMC; gMC=0;
8494b010 162 if (fModules) {
163 fModules->Delete();
164 delete fModules;
fe4da5cc 165 }
88cb7938 166
fe4da5cc 167}
168
e2afb3b6 169//_______________________________________________________________________
d8408e76 170void AliRun::SetField(AliMagF* magField)
171{
2057aecb 172 //
173 // Set Magnetic Field Map
174 //
175 fField = magField;
176 fField->ReadField();
d8408e76 177}
178
4a9de4af 179//_______________________________________________________________________
180void AliRun::SetRootGeometry(Bool_t flag)
181{
182// Instruct application that the geometry is to be retreived from a root file.
183 fIsRootGeometry = flag;
e8572077 184 if (flag && gMC) gMC->SetRootGeometry();
4a9de4af 185}
ced249e6 186
187//_______________________________________________________________________
188void AliRun::SetGeometryFromCDB()
189{
190 // Set the loading of geometry from cdb instead of creating it
191 // A default CDB storage needs to be set before this method is called
3d45e923 192 if(AliCDBManager::Instance()->IsDefaultStorageSet() &&
193 AliCDBManager::Instance()->GetRun() >= 0){
ced249e6 194 SetRootGeometry();
195 fGeometryFromCDB = kTRUE;
196 }else{
197 AliError("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
198 AliError("Loading of geometry from CDB ignored. First set a default CDB storage!");
199 AliError("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
200 }
201}
202
88cb7938 203//_____________________________________________________________________________
204
205void AliRun::InitLoaders()
206{
207 //creates list of getters
21bf7095 208 AliDebug(1, "");
88cb7938 209 TIter next(fModules);
210 AliModule *mod;
211 while((mod = (AliModule*)next()))
212 {
1d6fbf6e 213 mod->SetRunLoader(fRunLoader);
88cb7938 214 AliDetector *det = dynamic_cast<AliDetector*>(mod);
215 if (det)
216 {
21bf7095 217 AliDebug(2, Form("Adding %s", det->GetName()));
88cb7938 218 fRunLoader->AddLoader(det);
219 }
220 }
21bf7095 221 AliDebug(1, "Done");
88cb7938 222}
fe4da5cc 223
eb1b8d29 224//_______________________________________________________________________
225void AliRun::Announce() const
226{
227 //
37d06d5b 228 // Announce the current version of AliRoot
229 //
230 printf("%70s",
231 "****************************************************************\n");
232 printf("%6s","*");printf("%64s","*\n");
233
234 printf("%6s","*");
88cb7938 235 printf(" You are running AliRoot version NewIO\n");
37d06d5b 236
237 printf("%6s","*");
5960f18d 238 printf(" The SVN version for the current program is $Id$\n");
37d06d5b 239
240 printf("%6s","*");printf("%64s","*\n");
241 printf("%70s",
242 "****************************************************************\n");
eb1b8d29 243}
244
e2afb3b6 245//_______________________________________________________________________
94de3818 246AliModule *AliRun::GetModule(const char *name) const
fe4da5cc 247{
248 //
249 // Return pointer to detector from name
250 //
e2afb3b6 251 return dynamic_cast<AliModule*>(fModules->FindObject(name));
fe4da5cc 252}
253
e2afb3b6 254//_______________________________________________________________________
94de3818 255AliDetector *AliRun::GetDetector(const char *name) const
a68348e9 256{
257 //
258 // Return pointer to detector from name
259 //
e2afb3b6 260 return dynamic_cast<AliDetector*>(fModules->FindObject(name));
a68348e9 261}
262
e2afb3b6 263//_______________________________________________________________________
94de3818 264Int_t AliRun::GetModuleID(const char *name) const
fe4da5cc 265{
266 //
267 // Return galice internal detector identifier from name
268 //
23370b7a 269 Int_t i=-1;
270 TObject *mod=fModules->FindObject(name);
271 if(mod) i=fModules->IndexOf(mod);
272 return i;
fe4da5cc 273}
274
e2afb3b6 275//_______________________________________________________________________
fe4da5cc 276Int_t AliRun::GetEvent(Int_t event)
277{
88cb7938 278//
279// Reloads data containers in folders # event
280// Set branch addresses
281//
282 if (fRunLoader == 0x0)
283 {
21bf7095 284 AliError("RunLoader is not set. Can not load data.");
88cb7938 285 return -1;
286 }
287/*****************************************/
288/**** P R E R E L O A D I N G ****/
289/*****************************************/
290// Reset existing structures
5d12ce38 291 fMCApp->ResetHits();
292 fMCApp->ResetTrackReferences();
3e2e3ece 293 fMCApp->ResetDigits();
294 fMCApp->ResetSDigits();
50a6540a 295
88cb7938 296/*****************************************/
297/**** R E L O A D ****/
298/*****************************************/
aab9c8d5 299
7dd2cbe4 300 AliRunLoader::GetRunLoader()->GetEvent(event);
b9d0a01d 301
88cb7938 302/*****************************************/
303/**** P O S T R E L O A D I N G ****/
304/*****************************************/
82711e7a 305
fe4da5cc 306 // Set Trees branch addresses
8494b010 307 TIter next(fModules);
07d55def 308 AliDetector *detector;
309 while((detector = dynamic_cast<AliDetector*>(next())))
88cb7938 310 {
311 detector->SetTreeAddress();
312 }
313
7dd2cbe4 314 return AliRunLoader::GetRunLoader()->GetHeader()->GetNtrack();
fe4da5cc 315}
316
e2afb3b6 317//_______________________________________________________________________
318void AliRun::SetBaseFile(const char *filename)
2ab0c725 319{
39de14fb 320 fBaseFileName = filename;
2ab0c725 321}
322
fe4da5cc 323
e2afb3b6 324//_______________________________________________________________________
2ab0c725 325void AliRun::Hits2Digits(const char *selected)
326{
9e1a0ddb 327
d47c658f 328 // Convert Hits to sumable digits
329 //
7dd2cbe4 330 for (Int_t nevent=0; nevent<AliRunLoader::GetRunLoader()->TreeE()->GetEntries(); nevent++) {
9e1a0ddb 331 GetEvent(nevent);
9e1a0ddb 332 Hits2SDigits(selected);
333 SDigits2Digits(selected);
334 }
2ab0c725 335}
336
d47c658f 337
e2afb3b6 338//_______________________________________________________________________
2ab0c725 339
d47c658f 340void AliRun::Tree2Tree(Option_t *option, const char *selected)
2ab0c725 341{
342 //
d47c658f 343 // Function to transform the content of
344 //
345 // - TreeH to TreeS (option "S")
346 // - TreeS to TreeD (option "D")
347 // - TreeD to TreeR (option "R")
348 //
349 // If multiple options are specified ("SDR"), transformation will be done in sequence for
350 // selected detector and for all detectors if none is selected (detector string
351 // can contain blank separated list of detector names).
2ab0c725 352
2ab0c725 353
5cf7bbad 354 const char *oS = strstr(option,"S");
355 const char *oD = strstr(option,"D");
356 const char *oR = strstr(option,"R");
2ab0c725 357
9e1a0ddb 358 TObjArray *detectors = Detectors();
2ab0c725 359
360 TIter next(detectors);
361
d47c658f 362 AliDetector *detector = 0;
2ab0c725 363
88cb7938 364 while((detector = dynamic_cast<AliDetector*>(next()))) {
d47c658f 365 if (selected)
2ab0c725 366 if (strcmp(detector->GetName(),selected)) continue;
88cb7938 367 if (detector->IsActive())
368 {
369
370 AliLoader* loader = detector->GetLoader();
371 if (loader == 0x0) continue;
372
373 if (oS)
374 {
21bf7095 375 AliDebug(1, Form("Processing Hits2SDigits for %s ...", detector->GetName()));
88cb7938 376 loader->LoadHits("read");
377 if (loader->TreeS() == 0x0) loader->MakeTree("S");
378 detector->MakeBranch(option);
379 detector->SetTreeAddress();
380 detector->Hits2SDigits();
381 loader->UnloadHits();
382 loader->UnloadSDigits();
383 }
384 if (oD)
385 {
21bf7095 386 AliDebug(1, Form("Processing SDigits2Digits for %s ...", detector->GetName()));
88cb7938 387 loader->LoadSDigits("read");
388 if (loader->TreeD() == 0x0) loader->MakeTree("D");
389 detector->MakeBranch(option);
390 detector->SetTreeAddress();
391 detector->SDigits2Digits();
392 loader->UnloadSDigits();
393 loader->UnloadDigits();
394 }
395 if (oR)
396 {
21bf7095 397 AliDebug(1, Form("Processing Digits2Reco for %s ...", detector->GetName()));
88cb7938 398 loader->LoadDigits("read");
399 if (loader->TreeR() == 0x0) loader->MakeTree("R");
400 detector->MakeBranch(option);
401 detector->SetTreeAddress();
402 detector->Digits2Reco();
403 loader->UnloadDigits();
404 loader->UnloadRecPoints();
405
406 }
407 }
408 }
2ab0c725 409}
410
b9d0a01d 411//
412// MC Application
413//
414
e2afb3b6 415//_______________________________________________________________________
b9d0a01d 416void AliRun::Field(const Double_t* x, Double_t *b) const
417{
2057aecb 418 //
419 // Return the value of the magnetic field
420 //
07d55def 421
3e2e3ece 422 if (Field()) Field()->Field(x,b);
07d55def 423
2057aecb 424 else {
21bf7095 425 AliError("No mag field defined!");
2057aecb 426 b[0]=b[1]=b[2]=0.;
427 }
07d55def 428
429
b9d0a01d 430}
431
432//
433// End of MC Application
434//
435
e2afb3b6 436//_______________________________________________________________________
fe4da5cc 437void AliRun::Streamer(TBuffer &R__b)
438{
eef4b160 439 // Stream an object of class AliRun.
2ab0c725 440
7e90ff59 441 if (R__b.IsReading()) {
442 if (!gAlice) gAlice = this;
7e90ff59 443 AliRun::Class()->ReadBuffer(R__b, this);
7e90ff59 444 gROOT->GetListOfBrowsables()->Add(this,"Run");
eef4b160 445
7e90ff59 446 gRandom = fRandom;
447 } else {
eef4b160 448 AliRun::Class()->WriteBuffer(R__b, this);
449 }
2ab0c725 450}
e2afb3b6 451//_______________________________________________________________________
b9d0a01d 452
27f087a9 453void AliRun::SetGenEventHeader(AliGenEventHeader* header)
454{
7dd2cbe4 455 AliRunLoader::GetRunLoader()->GetHeader()->SetGenEventHeader(header);
27f087a9 456}
7dd2cbe4 457
458
504b172d 459//_______________________________________________________________________
0592d1ca 460
88cb7938 461Int_t AliRun::GetEvNumber() const
462{
463//Returns number of current event
464 if (fRunLoader == 0x0)
465 {
21bf7095 466 AliError("RunLoader is not set. Can not load data.");
88cb7938 467 return -1;
468 }
0592d1ca 469
88cb7938 470 return fRunLoader->GetEventNumber();
0592d1ca 471}
504b172d 472//_______________________________________________________________________
b9d0a01d 473
88cb7938 474void AliRun::SetRunLoader(AliRunLoader* rloader)
0592d1ca 475{
2057aecb 476 //
477 // Set the loader of the run
478 //
88cb7938 479 fRunLoader = rloader;
480 if (fRunLoader == 0x0) return;
481
482 TString evfoldname;
483 TFolder* evfold = fRunLoader->GetEventFolder();
484 if (evfold) evfoldname = evfold->GetName();
21bf7095 485 else AliWarning("Did not get Event Folder from Run Loader");
88cb7938 486
487 if ( fRunLoader->GetAliRun() )
488 {//if alrun already exists in folder
489 if (fRunLoader->GetAliRun() != this )
490 {//and is different than this - crash
21bf7095 491 AliFatal("AliRun is already in Folder and it is not this object");
88cb7938 492 return;//pro forma
493 }//else do nothing
494 }
495 else
496 {
497 evfold->Add(this);//Post this AliRun to Folder
498 }
499
500 TIter next(fModules);
501 AliModule *module;
502 while((module = (AliModule*)next()))
503 {
504 if (evfold) AliConfig::Instance()->Add(module,evfoldname);
1d6fbf6e 505 module->SetRunLoader(fRunLoader);
88cb7938 506 AliDetector* detector = dynamic_cast<AliDetector*>(module);
507 if (detector)
508 {
509 AliLoader* loader = fRunLoader->GetLoader(detector);
510 if (loader == 0x0)
511 {
21bf7095 512 AliError(Form("Can not get loader for detector %s", detector->GetName()));
88cb7938 513 }
514 else
515 {
21bf7095 516 AliDebug(1, Form("Setting loader for detector %s", detector->GetName()));
88cb7938 517 detector->SetLoader(loader);
518 }
0592d1ca 519 }
88cb7938 520 }
0592d1ca 521}
522
88cb7938 523void AliRun::AddModule(AliModule* mod)
7a16e9cc 524{
2057aecb 525 //
526 // Add a module to the module list
527 //
88cb7938 528 if (mod == 0x0) return;
529 if (strlen(mod->GetName()) == 0) return;
530 if (GetModuleID(mod->GetName()) >= 0) return;
531
21bf7095 532 AliDebug(1, mod->GetName());
88cb7938 533 if (fRunLoader == 0x0) AliConfig::Instance()->Add(mod);
534 else AliConfig::Instance()->Add(mod,fRunLoader->GetEventFolder()->GetName());
7a16e9cc 535
88cb7938 536 Modules()->Add(mod);
67d736ee 537
538 fNdets++;
7a16e9cc 539}
21bf7095 540