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