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