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