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