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