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