]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliRun.cxx
Additional protection in case of very slow particles
[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{
471 //
472 // Import Alice geometry from current file
473 // Return pointer to geometry object
474 //
70760df0 475 //PH if (!fGeometry) fGeometry = dynamic_cast<TGeometry*>(gDirectory->Get("AliceGeom"));
476
477 // Create the TNode geometry for the event display
478 if (!fGeometry) BuildSimpleGeometry();
fe4da5cc 479 //
480 // Unlink and relink nodes in detectors
481 // This is bad and there must be a better way...
482 //
fe4da5cc 483
8494b010 484 TIter next(fModules);
485 AliModule *detector;
e2afb3b6 486 while((detector = dynamic_cast<AliModule*>(next()))) {
fe4da5cc 487 TList *dnodes=detector->Nodes();
488 Int_t j;
489 TNode *node, *node1;
490 for ( j=0; j<dnodes->GetSize(); j++) {
e2afb3b6 491 node = dynamic_cast<TNode*>(dnodes->At(j));
52d0ab00 492 node1 = fGeometry->GetNode(node->GetName());
fe4da5cc 493 dnodes->Remove(node);
494 dnodes->AddAt(node1,j);
495 }
496 }
497 return fGeometry;
498}
499
e2afb3b6 500//_______________________________________________________________________
501void AliRun::SetBaseFile(const char *filename)
2ab0c725 502{
39de14fb 503 fBaseFileName = filename;
2ab0c725 504}
505
e2afb3b6 506//_______________________________________________________________________
b9d0a01d 507void AliRun::ResetDigits()
fe4da5cc 508{
509 //
b9d0a01d 510 // Reset all Detectors digits
fe4da5cc 511 //
b9d0a01d 512 TIter next(fModules);
513 AliModule *detector;
e2afb3b6 514 while((detector = dynamic_cast<AliModule*>(next()))) {
b9d0a01d 515 detector->ResetDigits();
516 }
517}
518
e2afb3b6 519//_______________________________________________________________________
b9d0a01d 520void AliRun::ResetSDigits()
521{
dffd31ef 522 //
b9d0a01d 523 // Reset all Detectors digits
9e1a0ddb 524 //
b9d0a01d 525 TIter next(fModules);
526 AliModule *detector;
e2afb3b6 527 while((detector = dynamic_cast<AliModule*>(next()))) {
b9d0a01d 528 detector->ResetSDigits();
529 }
530}
dffd31ef 531
2b22f272 532
e2afb3b6 533//_______________________________________________________________________
88cb7938 534
b9d0a01d 535void AliRun::ResetPoints()
fe4da5cc 536{
537 //
b9d0a01d 538 // Reset all Detectors points
fe4da5cc 539 //
8494b010 540 TIter next(fModules);
541 AliModule *detector;
e2afb3b6 542 while((detector = dynamic_cast<AliModule*>(next()))) {
b9d0a01d 543 detector->ResetPoints();
fe4da5cc 544 }
545}
e2afb3b6 546//_______________________________________________________________________
88cb7938 547
b9d0a01d 548void AliRun::InitMC(const char *setup)
2ab0c725 549{
550 //
5d12ce38 551 // Initialize ALICE Simulation run
2ab0c725 552 //
37d06d5b 553 Announce();
554
b9d0a01d 555 if(fInitDone) {
21bf7095 556 AliWarning("Cannot initialise AliRun twice!");
b9d0a01d 557 return;
fe4da5cc 558 }
b9d0a01d 559
67d736ee 560 if (!fMCApp)
561 fMCApp=new AliMC(GetName(),GetTitle());
5d12ce38 562
b9d0a01d 563 gROOT->LoadMacro(setup);
564 gInterpreter->ProcessLine(fConfigFunction.Data());
fe4da5cc 565
88cb7938 566 fRunLoader->CdGAFile();
aab9c8d5 567
141f90e3 568 AliPDG::AddParticlesToPdgDataBase();
aab9c8d5 569
b9d0a01d 570 fNdets = fModules->GetLast()+1;
aab9c8d5 571
88cb7938 572 TIter next(fModules);
5d12ce38 573 for(Int_t i=0; i<fNdets; ++i)
88cb7938 574 {
5d12ce38 575 TObject *objfirst, *objlast;
576 AliModule *detector=dynamic_cast<AliModule*>(fModules->At(i));
88cb7938 577 objlast = gDirectory->GetList()->Last();
b9d0a01d 578
88cb7938 579 // Add Detector histograms in Detector list of histograms
580 if (objlast) objfirst = gDirectory->GetList()->After(objlast);
581 else objfirst = gDirectory->GetList()->First();
582 while (objfirst)
583 {
b9d0a01d 584 detector->Histograms()->Add(objfirst);
585 objfirst = gDirectory->GetList()->After(objfirst);
586 }
587 }
b9d0a01d 588
5d12ce38 589 fMCApp->Init();
b9d0a01d 590
504b172d 591 //Must be here because some MCs (G4) adds detectors here and not in Config.C
592 InitLoaders();
593 fRunLoader->MakeTree("E");
594 if (fLego == 0x0)
595 {
596 fRunLoader->LoadKinematics("RECREATE");
597 fRunLoader->LoadTrackRefs("RECREATE");
598 fRunLoader->LoadHits("all","RECREATE");
599 }
b9d0a01d 600 fInitDone = kTRUE;
b9d0a01d 601 //
602 // Save stuff at the beginning of the file to avoid file corruption
504b172d 603 fRunLoader->CdGAFile();
b9d0a01d 604 Write();
88cb7938 605 fEventNrInRun = -1; //important - we start Begin event from increasing current number in run
fe4da5cc 606}
607
e2afb3b6 608//_______________________________________________________________________
88cb7938 609
875c717b 610void AliRun::RunMC(Int_t nevent, const char *setup)
fe4da5cc 611{
612 //
613 // Main function to be called to process a galice run
614 // example
615 // Root > gAlice.Run();
616 // a positive number of events will cause the finish routine
617 // to be called
618 //
88cb7938 619 fEventsPerRun = nevent;
fe4da5cc 620 // check if initialisation has been done
875c717b 621 if (!fInitDone) InitMC(setup);
fe4da5cc 622
fe4da5cc 623 // Create the Root Tree with one branch per detector
88cb7938 624 //Hits moved to begin event -> now we are crating separate tree for each event
fe4da5cc 625
875c717b 626 gMC->ProcessRun(nevent);
627
fe4da5cc 628 // End of this run, close files
80762cb1 629 if(nevent>0) FinishRun();
fe4da5cc 630}
631
e2afb3b6 632//_______________________________________________________________________
27f087a9 633void AliRun::RunReco(const char *selected, Int_t first, Int_t last)
d47c658f 634{
635 //
636 // Main function to be called to reconstruct Alice event
27f087a9 637 //
88cb7938 638 Int_t nev = fRunLoader->GetNumberOfEvents();
21bf7095 639 AliDebug(1, Form("Found %d events", nev));
27f087a9 640 Int_t nFirst = first;
88cb7938 641 Int_t nLast = (last < 0)? nev : last;
27f087a9 642
643 for (Int_t nevent = nFirst; nevent <= nLast; nevent++) {
21bf7095 644 AliDebug(1, Form("Processing event %d", nevent));
9e1a0ddb 645 GetEvent(nevent);
9e1a0ddb 646 Digits2Reco(selected);
647 }
d47c658f 648}
649
e2afb3b6 650//_______________________________________________________________________
2ab0c725 651
652void AliRun::Hits2Digits(const char *selected)
653{
9e1a0ddb 654
d47c658f 655 // Convert Hits to sumable digits
656 //
9e1a0ddb 657 for (Int_t nevent=0; nevent<gAlice->TreeE()->GetEntries(); nevent++) {
658 GetEvent(nevent);
9e1a0ddb 659 Hits2SDigits(selected);
660 SDigits2Digits(selected);
661 }
2ab0c725 662}
663
d47c658f 664
e2afb3b6 665//_______________________________________________________________________
2ab0c725 666
d47c658f 667void AliRun::Tree2Tree(Option_t *option, const char *selected)
2ab0c725 668{
669 //
d47c658f 670 // Function to transform the content of
671 //
672 // - TreeH to TreeS (option "S")
673 // - TreeS to TreeD (option "D")
674 // - TreeD to TreeR (option "R")
675 //
676 // If multiple options are specified ("SDR"), transformation will be done in sequence for
677 // selected detector and for all detectors if none is selected (detector string
678 // can contain blank separated list of detector names).
2ab0c725 679
2ab0c725 680
5cf7bbad 681 const char *oS = strstr(option,"S");
682 const char *oD = strstr(option,"D");
683 const char *oR = strstr(option,"R");
2ab0c725 684
9e1a0ddb 685 TObjArray *detectors = Detectors();
2ab0c725 686
687 TIter next(detectors);
688
d47c658f 689 AliDetector *detector = 0;
2ab0c725 690
88cb7938 691 while((detector = dynamic_cast<AliDetector*>(next()))) {
d47c658f 692 if (selected)
2ab0c725 693 if (strcmp(detector->GetName(),selected)) continue;
88cb7938 694 if (detector->IsActive())
695 {
696
697 AliLoader* loader = detector->GetLoader();
698 if (loader == 0x0) continue;
699
700 if (oS)
701 {
21bf7095 702 AliDebug(1, Form("Processing Hits2SDigits for %s ...", detector->GetName()));
88cb7938 703 loader->LoadHits("read");
704 if (loader->TreeS() == 0x0) loader->MakeTree("S");
705 detector->MakeBranch(option);
706 detector->SetTreeAddress();
707 detector->Hits2SDigits();
708 loader->UnloadHits();
709 loader->UnloadSDigits();
710 }
711 if (oD)
712 {
21bf7095 713 AliDebug(1, Form("Processing SDigits2Digits for %s ...", detector->GetName()));
88cb7938 714 loader->LoadSDigits("read");
715 if (loader->TreeD() == 0x0) loader->MakeTree("D");
716 detector->MakeBranch(option);
717 detector->SetTreeAddress();
718 detector->SDigits2Digits();
719 loader->UnloadSDigits();
720 loader->UnloadDigits();
721 }
722 if (oR)
723 {
21bf7095 724 AliDebug(1, Form("Processing Digits2Reco for %s ...", detector->GetName()));
88cb7938 725 loader->LoadDigits("read");
726 if (loader->TreeR() == 0x0) loader->MakeTree("R");
727 detector->MakeBranch(option);
728 detector->SetTreeAddress();
729 detector->Digits2Reco();
730 loader->UnloadDigits();
731 loader->UnloadRecPoints();
732
733 }
734 }
735 }
2ab0c725 736}
737
e2afb3b6 738//_______________________________________________________________________
0a520a66 739void AliRun::RunLego(const char *setup, Int_t nc1, Float_t c1min,
740 Float_t c1max,Int_t nc2,Float_t c2min,Float_t c2max,
741 Float_t rmin,Float_t rmax,Float_t zmax, AliLegoGenerator* gener)
fe4da5cc 742{
743 //
744 // Generates lego plots of:
745 // - radiation length map phi vs theta
746 // - radiation length map phi vs eta
747 // - interaction length map
748 // - g/cm2 length map
749 //
750 // ntheta bins in theta, eta
751 // themin minimum angle in theta (degrees)
752 // themax maximum angle in theta (degrees)
753 // nphi bins in phi
754 // phimin minimum angle in phi (degrees)
755 // phimax maximum angle in phi (degrees)
756 // rmin minimum radius
757 // rmax maximum radius
758 //
759 //
760 // The number of events generated = ntheta*nphi
761 // run input parameters in macro setup (default="Config.C")
762 //
763 // Use macro "lego.C" to visualize the 3 lego plots in spherical coordinates
764 //Begin_Html
765 /*
1439f98e 766 <img src="picts/AliRunLego1.gif">
fe4da5cc 767 */
768 //End_Html
769 //Begin_Html
770 /*
1439f98e 771 <img src="picts/AliRunLego2.gif">
fe4da5cc 772 */
773 //End_Html
774 //Begin_Html
775 /*
1439f98e 776 <img src="picts/AliRunLego3.gif">
fe4da5cc 777 */
778 //End_Html
779 //
780
781 // check if initialisation has been done
2cacde38 782 // If runloader has been initialized, set the number of events per file to nc1 * nc2
5d12ce38 783
0a520a66 784 // Set new generator
785 if (!gener) gener = new AliLegoGenerator();
0a520a66 786 //
787 // Configure Generator
788 gener->SetRadiusRange(rmin, rmax);
789 gener->SetZMax(zmax);
790 gener->SetCoor1Range(nc1, c1min, c1max);
791 gener->SetCoor2Range(nc2, c2min, c2max);
792
793
b13db077 794 //Create Lego object
0a520a66 795 fLego = new AliLego("lego",gener);
b13db077 796
504b172d 797 if (!fInitDone) InitMC(setup);
798 //Save current generator
799
800 AliGenerator *gen=fMCApp->Generator();
801 fMCApp->ResetGenerator(gener);
dffd31ef 802 //Prepare MC for Lego Run
803 gMC->InitLego();
804
b13db077 805 //Run Lego Object
0a520a66 806
504b172d 807 if (fRunLoader) fRunLoader->SetNumberOfEventsPerFile(nc1 * nc2);
b9d0a01d 808 //gMC->ProcessRun(nc1*nc2+1);
809 gMC->ProcessRun(nc1*nc2);
fe4da5cc 810
fe4da5cc 811 // End of this run, close files
80762cb1 812 FinishRun();
0a520a66 813 // Restore current generator
5d12ce38 814 fMCApp->ResetGenerator(gen);
838edcaf 815 // Delete Lego Object
816 delete fLego; fLego=0;
fe4da5cc 817}
818
e2afb3b6 819//_______________________________________________________________________
94de3818 820void AliRun::SetConfigFunction(const char * config)
821{
822 //
823 // Set the signature of the function contained in Config.C to configure
824 // the run
825 //
826 fConfigFunction=config;
827}
828
b9d0a01d 829//
830// MC Application
831//
832
e2afb3b6 833//_______________________________________________________________________
b9d0a01d 834void AliRun::Field(const Double_t* x, Double_t *b) const
835{
2057aecb 836 //
837 // Return the value of the magnetic field
838 //
839 Float_t xfloat[3];
840 for (Int_t i=0; i<3; i++) xfloat[i] = x[i];
841
842 if (Field()) {
843 Float_t bfloat[3];
844 Field()->Field(xfloat,bfloat);
845 for (Int_t j=0; j<3; j++) b[j] = bfloat[j];
846 }
847 else {
21bf7095 848 AliError("No mag field defined!");
2057aecb 849 b[0]=b[1]=b[2]=0.;
850 }
b9d0a01d 851}
852
853//
854// End of MC Application
855//
856
e2afb3b6 857//_______________________________________________________________________
fe4da5cc 858void AliRun::Streamer(TBuffer &R__b)
859{
eef4b160 860 // Stream an object of class AliRun.
2ab0c725 861
7e90ff59 862 if (R__b.IsReading()) {
863 if (!gAlice) gAlice = this;
7e90ff59 864 AliRun::Class()->ReadBuffer(R__b, this);
7e90ff59 865 gROOT->GetListOfBrowsables()->Add(this,"Run");
eef4b160 866
7e90ff59 867 gRandom = fRandom;
868 } else {
eef4b160 869 AliRun::Class()->WriteBuffer(R__b, this);
870 }
2ab0c725 871}
e2afb3b6 872//_______________________________________________________________________
b9d0a01d 873
27f087a9 874void AliRun::SetGenEventHeader(AliGenEventHeader* header)
875{
88cb7938 876 fRunLoader->GetHeader()->SetGenEventHeader(header);
27f087a9 877}
504b172d 878//_______________________________________________________________________
0592d1ca 879
88cb7938 880Int_t AliRun::GetEvNumber() const
881{
882//Returns number of current event
883 if (fRunLoader == 0x0)
884 {
21bf7095 885 AliError("RunLoader is not set. Can not load data.");
88cb7938 886 return -1;
887 }
0592d1ca 888
88cb7938 889 return fRunLoader->GetEventNumber();
0592d1ca 890}
504b172d 891//_______________________________________________________________________
b9d0a01d 892
88cb7938 893void AliRun::SetRunLoader(AliRunLoader* rloader)
0592d1ca 894{
2057aecb 895 //
896 // Set the loader of the run
897 //
88cb7938 898 fRunLoader = rloader;
899 if (fRunLoader == 0x0) return;
900
901 TString evfoldname;
902 TFolder* evfold = fRunLoader->GetEventFolder();
903 if (evfold) evfoldname = evfold->GetName();
21bf7095 904 else AliWarning("Did not get Event Folder from Run Loader");
88cb7938 905
906 if ( fRunLoader->GetAliRun() )
907 {//if alrun already exists in folder
908 if (fRunLoader->GetAliRun() != this )
909 {//and is different than this - crash
21bf7095 910 AliFatal("AliRun is already in Folder and it is not this object");
88cb7938 911 return;//pro forma
912 }//else do nothing
913 }
914 else
915 {
916 evfold->Add(this);//Post this AliRun to Folder
917 }
918
919 TIter next(fModules);
920 AliModule *module;
921 while((module = (AliModule*)next()))
922 {
923 if (evfold) AliConfig::Instance()->Add(module,evfoldname);
1d6fbf6e 924 module->SetRunLoader(fRunLoader);
88cb7938 925 AliDetector* detector = dynamic_cast<AliDetector*>(module);
926 if (detector)
927 {
928 AliLoader* loader = fRunLoader->GetLoader(detector);
929 if (loader == 0x0)
930 {
21bf7095 931 AliError(Form("Can not get loader for detector %s", detector->GetName()));
88cb7938 932 }
933 else
934 {
21bf7095 935 AliDebug(1, Form("Setting loader for detector %s", detector->GetName()));
88cb7938 936 detector->SetLoader(loader);
937 }
0592d1ca 938 }
88cb7938 939 }
0592d1ca 940}
941
88cb7938 942void AliRun::AddModule(AliModule* mod)
7a16e9cc 943{
2057aecb 944 //
945 // Add a module to the module list
946 //
88cb7938 947 if (mod == 0x0) return;
948 if (strlen(mod->GetName()) == 0) return;
949 if (GetModuleID(mod->GetName()) >= 0) return;
950
21bf7095 951 AliDebug(1, mod->GetName());
88cb7938 952 if (fRunLoader == 0x0) AliConfig::Instance()->Add(mod);
953 else AliConfig::Instance()->Add(mod,fRunLoader->GetEventFolder()->GetName());
7a16e9cc 954
88cb7938 955 Modules()->Add(mod);
67d736ee 956
957 fNdets++;
7a16e9cc 958}
21bf7095 959
4d81e5e7 960// added by Alberto Colla
961//_____________________________________________________________________________
962/*inline*/ Bool_t AliRun::IsFileAccessible(const char* fnam, EAccessMode mode)
963{ return !gSystem->AccessPathName(fnam,mode);}
964
965//______________________________________________________
966/*inline*/ Bool_t AliRun::IsFileAccessible(Char_t* name,EAccessMode mode)
967{
968 TString str = name; gSystem->ExpandPathName(str);
969 return !gSystem->AccessPathName(str.Data(),mode);
970}