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