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