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