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