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