]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliRun.cxx
Using TMath::Pi() instead of kPI
[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 <Riostream.h>
94de3818 44#include <stdio.h>
98490ea9 45#include <stdlib.h>
94de3818 46#include <string.h>
47
88cb7938 48#include <TBRIK.h>
49#include <TBrowser.h>
50#include <TCint.h>
51#include <TFile.h>
52#include <TFolder.h>
53#include <TGeometry.h>
54#include <TKey.h>
55#include <TNode.h>
56#include <TObjectTable.h>
57#include <TParticle.h>
58#include <TROOT.h>
59#include <TRandom.h>
60#include <TRandom3.h>
61#include <TSystem.h>
62#include <TTree.h>
63#include <TVirtualMC.h>
98490ea9 64
65#include "AliConfig.h"
66#include "AliDetector.h"
fe4da5cc 67#include "AliDisplay.h"
88cb7938 68#include "AliGenEventHeader.h"
98490ea9 69#include "AliGenerator.h"
70#include "AliHeader.h"
88cb7938 71#include "AliHit.h"
dffd31ef 72#include "AliLego.h"
98490ea9 73#include "AliLegoGenerator.h"
88cb7938 74#include "AliLoader.h"
98490ea9 75#include "AliMCQA.h"
aee8290b 76#include "AliMagFC.h"
77#include "AliMagFCM.h"
78#include "AliMagFDM.h"
141f90e3 79#include "AliPDG.h"
98490ea9 80#include "AliRun.h"
88cb7938 81#include "AliRunLoader.h"
98490ea9 82#include "AliStack.h"
fe4da5cc 83
fe4da5cc 84AliRun *gAlice;
85
fe4da5cc 86ClassImp(AliRun)
87
e2afb3b6 88//_______________________________________________________________________
89AliRun::AliRun():
90 fRun(0),
91 fEvent(0),
92 fEventNrInRun(0),
93 fEventsPerRun(0),
94 fDebug(0),
e2afb3b6 95 fModules(0),
96 fGeometry(0),
97 fDisplay(0),
98 fTimer(),
99 fField(0),
100 fMC(0),
101 fImedia(0),
102 fNdets(0),
103 fTrRmax(1.e10),
104 fTrZmax(1.e10),
105 fGenerator(0),
106 fInitDone(kFALSE),
107 fLego(0),
108 fPDGDB(0), //Particle factory object
109 fHitLists(0),
110 fEventEnergy(0),
111 fSummEnergy(0),
112 fSum2Energy(0),
113 fConfigFunction("\0"),
114 fRandom(0),
115 fMCQA(0),
116 fTransParName("\0"),
88cb7938 117 fRunLoader(0x0)
fe4da5cc 118{
119 //
120 // Default constructor for AliRun
121 //
88cb7938 122 AliConfig::Instance();//skowron 29 Feb 2002
123 //ensures that the folder structure is build
e2afb3b6 124}
125
126//_______________________________________________________________________
127AliRun::AliRun(const AliRun& arun):
128 TVirtualMCApplication(arun),
129 fRun(0),
130 fEvent(0),
131 fEventNrInRun(0),
132 fEventsPerRun(0),
133 fDebug(0),
e2afb3b6 134 fModules(0),
135 fGeometry(0),
136 fDisplay(0),
137 fTimer(),
138 fField(0),
139 fMC(0),
140 fImedia(0),
141 fNdets(0),
142 fTrRmax(1.e10),
143 fTrZmax(1.e10),
144 fGenerator(0),
145 fInitDone(kFALSE),
146 fLego(0),
147 fPDGDB(0), //Particle factory object
148 fHitLists(0),
149 fEventEnergy(0),
150 fSummEnergy(0),
151 fSum2Energy(0),
152 fConfigFunction("\0"),
153 fRandom(0),
154 fMCQA(0),
155 fTransParName("\0"),
88cb7938 156 fRunLoader(0x0)
e2afb3b6 157{
158 //
159 // Copy constructor for AliRun
160 //
161 arun.Copy(*this);
fe4da5cc 162}
163
164//_____________________________________________________________________________
e2afb3b6 165AliRun::AliRun(const char *name, const char *title):
166 TVirtualMCApplication(name,title),
167 fRun(0),
168 fEvent(0),
169 fEventNrInRun(0),
170 fEventsPerRun(0),
171 fDebug(0),
e2afb3b6 172 fModules(new TObjArray(77)), // Support list for the Detectors
173 fGeometry(0),
174 fDisplay(0),
175 fTimer(),
176 fField(0),
177 fMC(gMC),
178 fImedia(new TArrayI(1000)),
179 fNdets(0),
180 fTrRmax(1.e10),
181 fTrZmax(1.e10),
182 fGenerator(0),
183 fInitDone(kFALSE),
184 fLego(0),
185 fPDGDB(TDatabasePDG::Instance()), //Particle factory object!
186 fHitLists(new TList()), // Create HitLists list
187 fEventEnergy(0),
188 fSummEnergy(0),
189 fSum2Energy(0),
190 fConfigFunction("Config();"),
191 fRandom(new TRandom3()),
192 fMCQA(0),
193 fTransParName("\0"),
88cb7938 194 fRunLoader(0x0)
fe4da5cc 195{
196 //
197 // Constructor for the main processor.
198 // Creates the geometry
199 // Creates the list of Detectors.
200 // Creates the list of particles.
201 //
e2afb3b6 202
fe4da5cc 203 gAlice = this;
65fb704d 204
205 // Set random number generator
e2afb3b6 206 gRandom = fRandom;
2ab0c725 207
208 if (gSystem->Getenv("CONFIG_SEED")) {
e2afb3b6 209 gRandom->SetSeed(static_cast<UInt_t>(atoi(gSystem->Getenv("CONFIG_SEED"))));
2ab0c725 210 }
e2afb3b6 211
212 // Add to list of browsable
fe4da5cc 213 gROOT->GetListOfBrowsables()->Add(this,name);
fe4da5cc 214 // Create the TNode geometry for the event display
fe4da5cc 215 BuildSimpleGeometry();
216
fe4da5cc 217 // Create default mag field
218 SetField();
e2afb3b6 219
fe4da5cc 220 // Prepare the tracking medium lists
e2afb3b6 221 for(Int_t i=0;i<1000;i++) (*fImedia)[i]=-99;
9e1a0ddb 222
e2afb3b6 223 // Add particle list to configuration
9e1a0ddb 224 AliConfig::Instance()->Add(fPDGDB);
e2afb3b6 225
226 // Set transport parameters
65fb704d 227 SetTransPar();
fe4da5cc 228}
229
aee8290b 230
e2afb3b6 231//_______________________________________________________________________
fe4da5cc 232AliRun::~AliRun()
233{
234 //
2ab0c725 235 // Default AliRun destructor
fe4da5cc 236 //
88cb7938 237 gROOT->GetListOfBrowsables()->Remove(this);
238
239 if (fRunLoader)
240 {
241 TFolder* evfold = fRunLoader->GetEventFolder();
242 TFolder* modfold = dynamic_cast<TFolder*>(evfold->FindObjectAny(AliConfig::GetModulesFolderName()));
243 TIter next(fModules);
244 AliModule *mod;
245 while((mod = (AliModule*)next()))
246 {
247 modfold->Remove(mod);
248 }
249 }
250
fe4da5cc 251 delete fImedia;
252 delete fField;
f5bc1485 253 // delete fMC;
254 delete gMC; gMC=0;
fe4da5cc 255 delete fGeometry;
256 delete fDisplay;
257 delete fGenerator;
258 delete fLego;
8494b010 259 if (fModules) {
260 fModules->Delete();
261 delete fModules;
fe4da5cc 262 }
88cb7938 263
1cedd08a 264 delete fHitLists;
c222d2b0 265 delete fPDGDB;
e460afec 266 delete fMCQA;
fe4da5cc 267}
268
e2afb3b6 269//_______________________________________________________________________
270void AliRun::Copy(AliRun &) const
271{
272 Fatal("Copy","Not implemented!\n");
273}
274
275//_______________________________________________________________________
fe4da5cc 276void AliRun::AddHit(Int_t id, Int_t track, Int_t *vol, Float_t *hits) const
277{
278 //
279 // Add a hit to detector id
280 //
8494b010 281 TObjArray &dets = *fModules;
e2afb3b6 282 if(dets[id]) dynamic_cast<AliModule*>(dets[id])->AddHit(track,vol,hits);
fe4da5cc 283}
284
e2afb3b6 285//_______________________________________________________________________
fe4da5cc 286void AliRun::AddDigit(Int_t id, Int_t *tracks, Int_t *digits) const
287{
288 //
289 // Add digit to detector id
290 //
8494b010 291 TObjArray &dets = *fModules;
e2afb3b6 292 if(dets[id]) dynamic_cast<AliModule*>(dets[id])->AddDigit(tracks,digits);
fe4da5cc 293}
294
e2afb3b6 295//_______________________________________________________________________
fe4da5cc 296void AliRun::Browse(TBrowser *b)
297{
298 //
299 // Called when the item "Run" is clicked on the left pane
300 // of the Root browser.
301 // It displays the Root Trees and all detectors.
302 //
88cb7938 303 //detectors are in folders anyway
65fb704d 304 b->Add(fMCQA,"AliMCQA");
fe4da5cc 305}
306
e2afb3b6 307//_______________________________________________________________________
fe4da5cc 308void AliRun::Build()
309{
310 //
311 // Initialize Alice geometry
312 // Dummy routine
313 //
314}
315
e2afb3b6 316//_______________________________________________________________________
fe4da5cc 317void AliRun::BuildSimpleGeometry()
318{
319 //
320 // Create a simple TNode geometry used by Root display engine
321 //
322 // Initialise geometry
323 //
324 fGeometry = new TGeometry("AliceGeom","Galice Geometry for Hits");
325 new TMaterial("void","Vacuum",0,0,0); //Everything is void
326 TBRIK *brik = new TBRIK("S_alice","alice volume","void",2000,2000,3000);
327 brik->SetVisibility(0);
328 new TNode("alice","alice","S_alice");
329}
330
e2afb3b6 331//_______________________________________________________________________
fe4da5cc 332void AliRun::CleanDetectors()
333{
334 //
335 // Clean Detectors at the end of event
336 //
88cb7938 337 fRunLoader->CleanDetectors();
fe4da5cc 338}
339
e2afb3b6 340//_______________________________________________________________________
116cbefd 341Int_t AliRun::DistancetoPrimitive(Int_t, Int_t) const
fe4da5cc 342{
343 //
344 // Return the distance from the mouse to the AliRun object
345 // Dummy routine
346 //
347 return 9999;
348}
349
e2afb3b6 350//_______________________________________________________________________
94de3818 351void AliRun::DumpPart (Int_t i) const
fe4da5cc 352{
353 //
354 // Dumps particle i in the stack
355 //
88cb7938 356 if (fRunLoader->Stack())
357 fRunLoader->Stack()->DumpPart(i);
fe4da5cc 358}
359
e2afb3b6 360//_______________________________________________________________________
94de3818 361void AliRun::DumpPStack () const
fe4da5cc 362{
363 //
364 // Dumps the particle stack
365 //
88cb7938 366 if (fRunLoader->Stack())
367 fRunLoader->Stack()->DumpPStack();
fe4da5cc 368}
369
e2afb3b6 370//_______________________________________________________________________
d8408e76 371void AliRun::SetField(AliMagF* magField)
372{
373 // Set Magnetic Field Map
374 fField = magField;
375 fField->ReadField();
376}
377
e2afb3b6 378//_______________________________________________________________________
fe4da5cc 379void AliRun::SetField(Int_t type, Int_t version, Float_t scale,
380 Float_t maxField, char* filename)
381{
382 //
383 // Set magnetic field parameters
384 // type Magnetic field transport flag 0=no field, 2=helix, 3=Runge Kutta
385 // version Magnetic field map version (only 1 active now)
386 // scale Scale factor for the magnetic field
387 // maxField Maximum value for the magnetic field
388
389 //
390 // --- Sanity check on mag field flags
fe4da5cc 391 if(fField) delete fField;
392 if(version==1) {
d8408e76 393 fField = new AliMagFC("Map1"," ",type,scale,maxField);
f1b9d7c3 394 } else if(version<=2) {
d8408e76 395 fField = new AliMagFCM("Map2-3",filename,type,scale,maxField);
fe4da5cc 396 fField->ReadField();
f1b9d7c3 397 } else if(version==3) {
d8408e76 398 fField = new AliMagFDM("Map4",filename,type,scale,maxField);
f1b9d7c3 399 fField->ReadField();
fe4da5cc 400 } else {
23370b7a 401 Warning("SetField","Invalid map %d\n",version);
fe4da5cc 402 }
403}
88cb7938 404
405//_____________________________________________________________________________
406
407void AliRun::InitLoaders()
408{
409 //creates list of getters
410 if (GetDebug()) Info("InitLoaders","");
411 TIter next(fModules);
412 AliModule *mod;
413 while((mod = (AliModule*)next()))
414 {
415 AliDetector *det = dynamic_cast<AliDetector*>(mod);
416 if (det)
417 {
418 if (GetDebug()) Info("InitLoaders"," Adding %s ",det->GetName());
419 fRunLoader->AddLoader(det);
420 }
421 }
422 if (GetDebug()) Info("InitLoaders","Done");
423}
424//_____________________________________________________________________________
425
fe4da5cc 426void AliRun::FinishRun()
427{
428 //
429 // Called at the end of the run.
430 //
88cb7938 431
88cb7938 432 if(fLego)
433 {
434 if (GetDebug()) Info("FinishRun"," Finish Lego");
435 fRunLoader->CdGAFile();
436 fLego->FinishRun();
437 }
8e70f139 438
fe4da5cc 439 // Clean detector information
8494b010 440 TIter next(fModules);
441 AliModule *detector;
e2afb3b6 442 while((detector = dynamic_cast<AliModule*>(next()))) {
88cb7938 443 if (GetDebug()) Info("FinishRun"," %s->FinishRun()",detector->GetName());
fe4da5cc 444 detector->FinishRun();
445 }
446
447 //Output energy summary tables
88cb7938 448 if (GetDebug()) Info("FinishRun"," EnergySummary()");
fe4da5cc 449 EnergySummary();
fe4da5cc 450
88cb7938 451 if (GetDebug()) Info("FinishRun"," fRunLoader->WriteHeader(OVERWRITE)");
452 fRunLoader->WriteHeader("OVERWRITE");
682a4a95 453
88cb7938 454 // Write AliRun info and all detectors parameters
455 fRunLoader->CdGAFile();
456 Write(0,TObject::kOverwrite);//write AliRun
457 fRunLoader->Write(0,TObject::kOverwrite);//write RunLoader itself
458
fe4da5cc 459 // Clean tree information
88cb7938 460 if (GetDebug()) Info("FinishRun"," fRunLoader->Stack()->FinishRun()");
461 fRunLoader->Stack()->FinishRun();
9e1a0ddb 462
88cb7938 463 // Clean detector information
464 if (GetDebug()) Info("FinishRun"," fGenerator->FinishRun()");
6df200c3 465 fGenerator->FinishRun();
f0f6f856 466
467 fRunLoader->Synchronize();
fe4da5cc 468}
469
e2afb3b6 470//_______________________________________________________________________
fe4da5cc 471void AliRun::FlagTrack(Int_t track)
472{
9e1a0ddb 473 // Delegate to stack
fe4da5cc 474 //
88cb7938 475 fRunLoader->Stack()->FlagTrack(track);
fe4da5cc 476}
477
e2afb3b6 478//_______________________________________________________________________
fe4da5cc 479void AliRun::EnergySummary()
480{
481 //
482 // Print summary of deposited energy
483 //
484
fe4da5cc 485 Int_t ndep=0;
486 Float_t edtot=0;
487 Float_t ed, ed2;
488 Int_t kn, i, left, j, id;
aee8290b 489 const Float_t kzero=0;
88cb7938 490 Int_t ievent=fRunLoader->GetHeader()->GetEvent()+1;
fe4da5cc 491 //
492 // Energy loss information
493 if(ievent) {
494 printf("***************** Energy Loss Information per event (GEV) *****************\n");
875c717b 495 for(kn=1;kn<fEventEnergy.GetSize();kn++) {
496 ed=fSummEnergy[kn];
fe4da5cc 497 if(ed>0) {
875c717b 498 fEventEnergy[ndep]=kn;
fe4da5cc 499 if(ievent>1) {
500 ed=ed/ievent;
875c717b 501 ed2=fSum2Energy[kn];
fe4da5cc 502 ed2=ed2/ievent;
aee8290b 503 ed2=100*TMath::Sqrt(TMath::Max(ed2-ed*ed,kzero))/ed;
fe4da5cc 504 } else
505 ed2=99;
875c717b 506 fSummEnergy[ndep]=ed;
e2afb3b6 507 fSum2Energy[ndep]=TMath::Min(static_cast<Float_t>(99.),TMath::Max(ed2,kzero));
fe4da5cc 508 edtot+=ed;
509 ndep++;
510 }
511 }
512 for(kn=0;kn<(ndep-1)/3+1;kn++) {
513 left=ndep-kn*3;
514 for(i=0;i<(3<left?3:left);i++) {
515 j=kn*3+i;
875c717b 516 id=Int_t (fEventEnergy[j]+0.1);
517 printf(" %s %10.3f +- %10.3f%%;",gMC->VolName(id),fSummEnergy[j],fSum2Energy[j]);
fe4da5cc 518 }
519 printf("\n");
520 }
521 //
522 // Relative energy loss in different detectors
523 printf("******************** Relative Energy Loss per event ********************\n");
524 printf("Total energy loss per event %10.3f GeV\n",edtot);
525 for(kn=0;kn<(ndep-1)/5+1;kn++) {
526 left=ndep-kn*5;
527 for(i=0;i<(5<left?5:left);i++) {
528 j=kn*5+i;
875c717b 529 id=Int_t (fEventEnergy[j]+0.1);
530 printf(" %s %10.3f%%;",gMC->VolName(id),100*fSummEnergy[j]/edtot);
fe4da5cc 531 }
532 printf("\n");
533 }
534 for(kn=0;kn<75;kn++) printf("*");
535 printf("\n");
536 }
537 //
538 // Reset the TArray's
875c717b 539 // fEventEnergy.Set(0);
540 // fSummEnergy.Set(0);
541 // fSum2Energy.Set(0);
fe4da5cc 542}
543
eb1b8d29 544//_______________________________________________________________________
545void AliRun::Announce() const
546{
547 //
37d06d5b 548 // Announce the current version of AliRoot
549 //
550 printf("%70s",
551 "****************************************************************\n");
552 printf("%6s","*");printf("%64s","*\n");
553
554 printf("%6s","*");
88cb7938 555 printf(" You are running AliRoot version NewIO\n");
37d06d5b 556
557 printf("%6s","*");
558 printf(" The cvs tag for the current program is $Name$\n");
559
560 printf("%6s","*");printf("%64s","*\n");
561 printf("%70s",
562 "****************************************************************\n");
eb1b8d29 563}
564
e2afb3b6 565//_______________________________________________________________________
94de3818 566AliModule *AliRun::GetModule(const char *name) const
fe4da5cc 567{
568 //
569 // Return pointer to detector from name
570 //
e2afb3b6 571 return dynamic_cast<AliModule*>(fModules->FindObject(name));
fe4da5cc 572}
573
e2afb3b6 574//_______________________________________________________________________
94de3818 575AliDetector *AliRun::GetDetector(const char *name) const
a68348e9 576{
577 //
578 // Return pointer to detector from name
579 //
e2afb3b6 580 return dynamic_cast<AliDetector*>(fModules->FindObject(name));
a68348e9 581}
582
e2afb3b6 583//_______________________________________________________________________
94de3818 584Int_t AliRun::GetModuleID(const char *name) const
fe4da5cc 585{
586 //
587 // Return galice internal detector identifier from name
588 //
23370b7a 589 Int_t i=-1;
590 TObject *mod=fModules->FindObject(name);
591 if(mod) i=fModules->IndexOf(mod);
592 return i;
fe4da5cc 593}
594
e2afb3b6 595//_______________________________________________________________________
fe4da5cc 596Int_t AliRun::GetEvent(Int_t event)
597{
88cb7938 598//
599// Reloads data containers in folders # event
600// Set branch addresses
601//
602 if (fRunLoader == 0x0)
603 {
604 Error("GetEvent","RunLoader is not set. Can not load data.");
605 return -1;
606 }
607/*****************************************/
608/**** P R E R E L O A D I N G ****/
609/*****************************************/
610// Reset existing structures
fe4da5cc 611 ResetHits();
aab9c8d5 612 ResetTrackReferences();
fe4da5cc 613 ResetDigits();
2ab0c725 614 ResetSDigits();
50a6540a 615
88cb7938 616/*****************************************/
617/**** R E L O A D ****/
618/*****************************************/
aab9c8d5 619
88cb7938 620 fRunLoader->GetEvent(event);
b9d0a01d 621
88cb7938 622/*****************************************/
623/**** P O S T R E L O A D I N G ****/
624/*****************************************/
82711e7a 625
fe4da5cc 626 // Set Trees branch addresses
8494b010 627 TIter next(fModules);
628 AliModule *detector;
88cb7938 629 while((detector = dynamic_cast<AliModule*>(next())))
630 {
631 detector->SetTreeAddress();
632 }
633
634 return fRunLoader->GetHeader()->GetNtrack();
fe4da5cc 635}
636
e2afb3b6 637//_______________________________________________________________________
fe4da5cc 638TGeometry *AliRun::GetGeometry()
639{
640 //
641 // Import Alice geometry from current file
642 // Return pointer to geometry object
643 //
e2afb3b6 644 if (!fGeometry) fGeometry = dynamic_cast<TGeometry*>(gDirectory->Get("AliceGeom"));
fe4da5cc 645 //
646 // Unlink and relink nodes in detectors
647 // This is bad and there must be a better way...
648 //
fe4da5cc 649
8494b010 650 TIter next(fModules);
651 AliModule *detector;
e2afb3b6 652 while((detector = dynamic_cast<AliModule*>(next()))) {
fe4da5cc 653 TList *dnodes=detector->Nodes();
654 Int_t j;
655 TNode *node, *node1;
656 for ( j=0; j<dnodes->GetSize(); j++) {
e2afb3b6 657 node = dynamic_cast<TNode*>(dnodes->At(j));
52d0ab00 658 node1 = fGeometry->GetNode(node->GetName());
fe4da5cc 659 dnodes->Remove(node);
660 dnodes->AddAt(node1,j);
661 }
662 }
663 return fGeometry;
664}
665
e2afb3b6 666//_______________________________________________________________________
9e1a0ddb 667Int_t AliRun::GetPrimary(Int_t track) const
fe4da5cc 668{
669 //
670 // return number of primary that has generated track
671 //
88cb7938 672 return fRunLoader->Stack()->GetPrimary(track);
fe4da5cc 673}
674
e2afb3b6 675//_______________________________________________________________________
fe4da5cc 676void AliRun::MediaTable()
677{
678 //
679 // Built media table to get from the media number to
680 // the detector id
681 //
88cb7938 682
ad51aeb0 683 Int_t kz, nz, idt, lz, i, k, ind;
684 // Int_t ibeg;
fe4da5cc 685 TObjArray &dets = *gAlice->Detectors();
8494b010 686 AliModule *det;
fe4da5cc 687 //
688 // For all detectors
689 for (kz=0;kz<fNdets;kz++) {
690 // If detector is defined
e2afb3b6 691 if((det=dynamic_cast<AliModule*>(dets[kz]))) {
ad51aeb0 692 TArrayI &idtmed = *(det->GetIdtmed());
693 for(nz=0;nz<100;nz++) {
fe4da5cc 694 // Find max and min material number
ad51aeb0 695 if((idt=idtmed[nz])) {
fe4da5cc 696 det->LoMedium() = det->LoMedium() < idt ? det->LoMedium() : idt;
697 det->HiMedium() = det->HiMedium() > idt ? det->HiMedium() : idt;
698 }
699 }
700 if(det->LoMedium() > det->HiMedium()) {
701 det->LoMedium() = 0;
702 det->HiMedium() = 0;
703 } else {
704 if(det->HiMedium() > fImedia->GetSize()) {
ad51aeb0 705 Error("MediaTable","Increase fImedia from %d to %d",
706 fImedia->GetSize(),det->HiMedium());
fe4da5cc 707 return;
708 }
709 // Tag all materials in rage as belonging to detector kz
710 for(lz=det->LoMedium(); lz<= det->HiMedium(); lz++) {
711 (*fImedia)[lz]=kz;
712 }
713 }
714 }
715 }
716 //
717 // Print summary table
718 printf(" Traking media ranges:\n");
719 for(i=0;i<(fNdets-1)/6+1;i++) {
720 for(k=0;k< (6<fNdets-i*6?6:fNdets-i*6);k++) {
721 ind=i*6+k;
e2afb3b6 722 det=dynamic_cast<AliModule*>(dets[ind]);
fe4da5cc 723 if(det)
724 printf(" %6s: %3d -> %3d;",det->GetName(),det->LoMedium(),
725 det->HiMedium());
726 else
727 printf(" %6s: %3d -> %3d;","NULL",0,0);
728 }
729 printf("\n");
730 }
731}
732
e2afb3b6 733//_______________________________________________________________________
fe4da5cc 734void AliRun::SetGenerator(AliGenerator *generator)
ee1dd322 735{
736 //
737 // Load the event generator
738 //
739 if(!fGenerator) fGenerator = generator;
740}
741
e2afb3b6 742//_______________________________________________________________________
ee1dd322 743void AliRun::ResetGenerator(AliGenerator *generator)
fe4da5cc 744{
745 //
746 // Load the event generator
747 //
b13db077 748 if(fGenerator)
838edcaf 749 if(generator)
750 Warning("ResetGenerator","Replacing generator %s with %s\n",
751 fGenerator->GetName(),generator->GetName());
752 else
753 Warning("ResetGenerator","Replacing generator %s with NULL\n",
754 fGenerator->GetName());
b13db077 755 fGenerator = generator;
fe4da5cc 756}
757
e2afb3b6 758//_______________________________________________________________________
759void AliRun::SetTransPar(const char *filename)
65fb704d 760{
37d06d5b 761 //
762 // Sets the file name for transport parameters
763 //
65fb704d 764 fTransParName = filename;
765}
766
e2afb3b6 767//_______________________________________________________________________
768void AliRun::SetBaseFile(const char *filename)
2ab0c725 769{
39de14fb 770 fBaseFileName = filename;
2ab0c725 771}
772
e2afb3b6 773//_______________________________________________________________________
65fb704d 774void AliRun::ReadTransPar()
fe4da5cc 775{
776 //
777 // Read filename to set the transport parameters
778 //
779
fe4da5cc 780
aee8290b 781 const Int_t kncuts=10;
782 const Int_t knflags=11;
783 const Int_t knpars=kncuts+knflags;
784 const char kpars[knpars][7] = {"CUTGAM" ,"CUTELE","CUTNEU","CUTHAD","CUTMUO",
fe4da5cc 785 "BCUTE","BCUTM","DCUTE","DCUTM","PPCUTM","ANNI",
786 "BREM","COMP","DCAY","DRAY","HADR","LOSS",
787 "MULS","PAIR","PHOT","RAYL"};
788 char line[256];
ad51aeb0 789 char detName[7];
fe4da5cc 790 char* filtmp;
aee8290b 791 Float_t cut[kncuts];
792 Int_t flag[knflags];
fe4da5cc 793 Int_t i, itmed, iret, ktmed, kz;
794 FILE *lun;
795 //
796 // See whether the file is there
65fb704d 797 filtmp=gSystem->ExpandPathName(fTransParName.Data());
fe4da5cc 798 lun=fopen(filtmp,"r");
799 delete [] filtmp;
800 if(!lun) {
65fb704d 801 Warning("ReadTransPar","File %s does not exist!\n",fTransParName.Data());
fe4da5cc 802 return;
803 }
804 //
9e1a0ddb 805 if(fDebug) {
806 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
807 printf(" *%59s\n","*");
808 printf(" * Please check carefully what you are doing!%10s\n","*");
809 printf(" *%59s\n","*");
810 }
fe4da5cc 811 //
812 while(1) {
813 // Initialise cuts and flags
aee8290b 814 for(i=0;i<kncuts;i++) cut[i]=-99;
815 for(i=0;i<knflags;i++) flag[i]=-99;
fe4da5cc 816 itmed=0;
817 for(i=0;i<256;i++) line[i]='\0';
818 // Read up to the end of line excluded
819 iret=fscanf(lun,"%[^\n]",line);
820 if(iret<0) {
821 //End of file
822 fclose(lun);
9e1a0ddb 823 if(fDebug){
824 printf(" *%59s\n","*");
825 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
826 }
fe4da5cc 827 return;
828 }
829 // Read the end of line
830 fscanf(lun,"%*c");
831 if(!iret) continue;
832 if(line[0]=='*') continue;
833 // Read the numbers
ad51aeb0 834 iret=sscanf(line,"%s %d %f %f %f %f %f %f %f %f %f %f %d %d %d %d %d %d %d %d %d %d %d",
835 detName,&itmed,&cut[0],&cut[1],&cut[2],&cut[3],&cut[4],&cut[5],&cut[6],&cut[7],&cut[8],
836 &cut[9],&flag[0],&flag[1],&flag[2],&flag[3],&flag[4],&flag[5],&flag[6],&flag[7],
837 &flag[8],&flag[9],&flag[10]);
fe4da5cc 838 if(!iret) continue;
839 if(iret<0) {
840 //reading error
65fb704d 841 Warning("ReadTransPar","Error reading file %s\n",fTransParName.Data());
fe4da5cc 842 continue;
843 }
ad51aeb0 844 // Check that the module exist
845 AliModule *mod = GetModule(detName);
846 if(mod) {
847 // Get the array of media numbers
848 TArrayI &idtmed = *mod->GetIdtmed();
849 // Check that the tracking medium code is valid
850 if(0<=itmed && itmed < 100) {
851 ktmed=idtmed[itmed];
852 if(!ktmed) {
65fb704d 853 Warning("ReadTransPar","Invalid tracking medium code %d for %s\n",itmed,mod->GetName());
ad51aeb0 854 continue;
fe4da5cc 855 }
ad51aeb0 856 // Set energy thresholds
aee8290b 857 for(kz=0;kz<kncuts;kz++) {
ad51aeb0 858 if(cut[kz]>=0) {
9e1a0ddb 859 if(fDebug) printf(" * %-6s set to %10.3E for tracking medium code %4d for %s\n",
aee8290b 860 kpars[kz],cut[kz],itmed,mod->GetName());
861 gMC->Gstpar(ktmed,kpars[kz],cut[kz]);
ad51aeb0 862 }
fe4da5cc 863 }
ad51aeb0 864 // Set transport mechanisms
aee8290b 865 for(kz=0;kz<knflags;kz++) {
ad51aeb0 866 if(flag[kz]>=0) {
9e1a0ddb 867 if(fDebug) printf(" * %-6s set to %10d for tracking medium code %4d for %s\n",
aee8290b 868 kpars[kncuts+kz],flag[kz],itmed,mod->GetName());
869 gMC->Gstpar(ktmed,kpars[kncuts+kz],Float_t(flag[kz]));
ad51aeb0 870 }
871 }
872 } else {
65fb704d 873 Warning("ReadTransPar","Invalid medium code %d *\n",itmed);
ad51aeb0 874 continue;
fe4da5cc 875 }
876 } else {
9e1a0ddb 877 if(fDebug) printf("%s::ReadTransParModule: %s not present\n",ClassName(),detName);
fe4da5cc 878 continue;
879 }
880 }
881}
88cb7938 882//_____________________________________________________________________________
fe4da5cc 883
88cb7938 884void AliRun::BeginEvent()
fe4da5cc 885{
886 //
88cb7938 887 // Clean-up previous event
888 // Energy scores
889 if (GetDebug())
890 {
891 Info("BeginEvent",">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
892 Info("BeginEvent",">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
893 Info("BeginEvent",">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
894 Info("BeginEvent"," BEGINNING EVENT ");
895 Info("BeginEvent",">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
896 Info("BeginEvent",">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
897 Info("BeginEvent",">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
898 }
899
900 /*******************************/
901 /* Clean after eventual */
902 /* previous event */
903 /*******************************/
9e1a0ddb 904
2ab0c725 905
88cb7938 906 //Set the next event in Run Loader -> Cleans trees (TreeK and all trees in detectors),
907 fRunLoader->SetEventNumber(++fEventNrInRun);// sets new files, cleans the previous event stuff, if necessary, etc.,
908 if (GetDebug()) Info("BeginEvent","EventNr is %d",fEventNrInRun);
909
910 fEventEnergy.Reset();
911 // Clean detector information
9e1a0ddb 912
88cb7938 913 if (fRunLoader->Stack())
914 fRunLoader->Stack()->Reset();//clean stack -> tree is unloaded
915 else
916 fRunLoader->MakeStack();//or make a new one
917
918 if (GetDebug()) Info("BeginEvent"," fRunLoader->MakeTree(K)");
919 fRunLoader->MakeTree("K");
920 if (GetDebug()) Info("BeginEvent"," gMC->SetStack(fRunLoader->Stack())");
921 gMC->SetStack(fRunLoader->Stack());//Was in InitMC - but was moved here
922 //because we don't have guarantee that
923 //stack pointer is not going to change from event to event
924 //since it bellobgs to header and is obtained via RunLoader
925 //
926 // Reset all Detectors & kinematics & make/reset trees
927 //
928
929 fRunLoader->GetHeader()->Reset(fRun,fEvent,fEventNrInRun);
930// fRunLoader->WriteKinematics("OVERWRITE"); is there any reason to rewrite here since MakeTree does so
aab9c8d5 931
88cb7938 932 if (GetDebug()) Info("BeginEvent"," fRunLoader->MakeTrackRefsContainer()");
933 fRunLoader->MakeTrackRefsContainer();//for insurance
aab9c8d5 934
88cb7938 935 if (GetDebug()) Info("BeginEvent"," ResetHits()");
936 ResetHits();
937 if (GetDebug()) Info("BeginEvent"," fRunLoader->MakeTree(H)");
938 fRunLoader->MakeTree("H");
9e1a0ddb 939
fe4da5cc 940 //
88cb7938 941 if(fLego)
942 {
943 fLego->BeginEvent();
944 return;
945 }
946
947 //create new branches and SetAdresses
8494b010 948 TIter next(fModules);
949 AliModule *detector;
88cb7938 950 while((detector = (AliModule*)next()))
951 {
952 if (GetDebug()) Info("BeginEvent"," %s->MakeBranch(H)",detector->GetName());
953 detector->MakeBranch("H");
954 if (GetDebug()) Info("BeginEvent"," %s->MakeBranchTR()",detector->GetName());
955 detector->MakeBranchTR();
956 if (GetDebug()) Info("BeginEvent"," %s->SetTreeAddress()",detector->GetName());
957 detector->SetTreeAddress();
958 }
fe4da5cc 959}
960
e2afb3b6 961//_______________________________________________________________________
37d06d5b 962TParticle* AliRun::Particle(Int_t i) const
2ab0c725 963{
88cb7938 964 if (fRunLoader)
965 if (fRunLoader->Stack())
966 return fRunLoader->Stack()->Particle(i);
967 return 0x0;
fe4da5cc 968}
969
e2afb3b6 970//_______________________________________________________________________
b9d0a01d 971void AliRun::ResetDigits()
fe4da5cc 972{
973 //
b9d0a01d 974 // Reset all Detectors digits
fe4da5cc 975 //
b9d0a01d 976 TIter next(fModules);
977 AliModule *detector;
e2afb3b6 978 while((detector = dynamic_cast<AliModule*>(next()))) {
b9d0a01d 979 detector->ResetDigits();
980 }
981}
982
e2afb3b6 983//_______________________________________________________________________
b9d0a01d 984void AliRun::ResetSDigits()
985{
dffd31ef 986 //
b9d0a01d 987 // Reset all Detectors digits
9e1a0ddb 988 //
b9d0a01d 989 TIter next(fModules);
990 AliModule *detector;
e2afb3b6 991 while((detector = dynamic_cast<AliModule*>(next()))) {
b9d0a01d 992 detector->ResetSDigits();
993 }
994}
dffd31ef 995
e2afb3b6 996//_______________________________________________________________________
b9d0a01d 997void AliRun::ResetHits()
998{
dffd31ef 999 //
b9d0a01d 1000 // Reset all Detectors hits
1001 //
1002 TIter next(fModules);
1003 AliModule *detector;
e2afb3b6 1004 while((detector = dynamic_cast<AliModule*>(next()))) {
b9d0a01d 1005 detector->ResetHits();
dffd31ef 1006 }
b9d0a01d 1007}
e2afb3b6 1008//_______________________________________________________________________
88cb7938 1009
b9d0a01d 1010void AliRun::ResetTrackReferences()
1011{
59fe9bd2 1012 //
b9d0a01d 1013 // Reset all Detectors hits
1014 //
1015 TIter next(fModules);
1016 AliModule *detector;
e2afb3b6 1017 while((detector = dynamic_cast<AliModule*>(next()))) {
b9d0a01d 1018 detector->ResetTrackReferences();
1019 }
1020}
e2afb3b6 1021//_______________________________________________________________________
88cb7938 1022
b9d0a01d 1023void AliRun::ResetPoints()
fe4da5cc 1024{
1025 //
b9d0a01d 1026 // Reset all Detectors points
fe4da5cc 1027 //
8494b010 1028 TIter next(fModules);
1029 AliModule *detector;
e2afb3b6 1030 while((detector = dynamic_cast<AliModule*>(next()))) {
b9d0a01d 1031 detector->ResetPoints();
fe4da5cc 1032 }
1033}
e2afb3b6 1034//_______________________________________________________________________
88cb7938 1035
b9d0a01d 1036void AliRun::InitMC(const char *setup)
2ab0c725 1037{
1038 //
b9d0a01d 1039 // Initialize the Alice setup
2ab0c725 1040 //
37d06d5b 1041 Announce();
1042
b9d0a01d 1043 if(fInitDone) {
1044 Warning("Init","Cannot initialise AliRun twice!\n");
1045 return;
fe4da5cc 1046 }
b9d0a01d 1047
1048 gROOT->LoadMacro(setup);
1049 gInterpreter->ProcessLine(fConfigFunction.Data());
fe4da5cc 1050
b9d0a01d 1051 // Register MC in configuration
1052 AliConfig::Instance()->Add(gMC);
88cb7938 1053
1054 InitLoaders();
1055
1056 fRunLoader->MakeTree("E");
1057 fRunLoader->LoadKinematics("RECREATE");
1058 fRunLoader->LoadTrackRefs("RECREATE");
1059 fRunLoader->LoadHits("all","RECREATE");
1060
1061
1062 fRunLoader->CdGAFile();
aab9c8d5 1063
b9d0a01d 1064 gMC->DefineParticles(); //Create standard MC particles
141f90e3 1065 AliPDG::AddParticlesToPdgDataBase();
aab9c8d5 1066
b9d0a01d 1067 TObject *objfirst, *objlast;
1068
1069 fNdets = fModules->GetLast()+1;
aab9c8d5 1070
fe4da5cc 1071 //
b9d0a01d 1072 //=================Create Materials and geometry
1073 gMC->Init();
1074
1075 // Added also after in case of interactive initialisation of modules
1076 fNdets = fModules->GetLast()+1;
1077
88cb7938 1078 TIter next(fModules);
1079 AliModule *detector;
1080 while((detector = dynamic_cast<AliModule*>(next())))
1081 {
1082 objlast = gDirectory->GetList()->Last();
b9d0a01d 1083
88cb7938 1084 // Add Detector histograms in Detector list of histograms
1085 if (objlast) objfirst = gDirectory->GetList()->After(objlast);
1086 else objfirst = gDirectory->GetList()->First();
1087 while (objfirst)
1088 {
b9d0a01d 1089 detector->Histograms()->Add(objfirst);
1090 objfirst = gDirectory->GetList()->After(objfirst);
1091 }
1092 }
1093 ReadTransPar(); //Read the cuts for all materials
1094
1095 MediaTable(); //Build the special IMEDIA table
1096
1097 //Initialise geometry deposition table
1098 fEventEnergy.Set(gMC->NofVolumes()+1);
1099 fSummEnergy.Set(gMC->NofVolumes()+1);
1100 fSum2Energy.Set(gMC->NofVolumes()+1);
1101
1102 //Compute cross-sections
1103 gMC->BuildPhysics();
1104
1105 //Write Geometry object to current file.
88cb7938 1106 fRunLoader->WriteGeometry();
b9d0a01d 1107
1108 fInitDone = kTRUE;
1109
1110 fMCQA = new AliMCQA(fNdets);
1111
b9d0a01d 1112 //
1113 // Save stuff at the beginning of the file to avoid file corruption
1114 Write();
88cb7938 1115 fEventNrInRun = -1; //important - we start Begin event from increasing current number in run
fe4da5cc 1116}
1117
e2afb3b6 1118//_______________________________________________________________________
88cb7938 1119
875c717b 1120void AliRun::RunMC(Int_t nevent, const char *setup)
fe4da5cc 1121{
1122 //
1123 // Main function to be called to process a galice run
1124 // example
1125 // Root > gAlice.Run();
1126 // a positive number of events will cause the finish routine
1127 // to be called
1128 //
88cb7938 1129 fEventsPerRun = nevent;
fe4da5cc 1130 // check if initialisation has been done
875c717b 1131 if (!fInitDone) InitMC(setup);
fe4da5cc 1132
fe4da5cc 1133 // Create the Root Tree with one branch per detector
88cb7938 1134 //Hits moved to begin event -> now we are crating separate tree for each event
fe4da5cc 1135
875c717b 1136 gMC->ProcessRun(nevent);
1137
fe4da5cc 1138 // End of this run, close files
80762cb1 1139 if(nevent>0) FinishRun();
fe4da5cc 1140}
1141
e2afb3b6 1142//_______________________________________________________________________
27f087a9 1143void AliRun::RunReco(const char *selected, Int_t first, Int_t last)
d47c658f 1144{
1145 //
1146 // Main function to be called to reconstruct Alice event
27f087a9 1147 //
88cb7938 1148 Int_t nev = fRunLoader->GetNumberOfEvents();
1149 if (GetDebug()) Info("RunReco","Found %d events",nev);
27f087a9 1150 Int_t nFirst = first;
88cb7938 1151 Int_t nLast = (last < 0)? nev : last;
27f087a9 1152
1153 for (Int_t nevent = nFirst; nevent <= nLast; nevent++) {
88cb7938 1154 if (GetDebug()) Info("RunReco","Processing event %d",nevent);
9e1a0ddb 1155 GetEvent(nevent);
9e1a0ddb 1156 Digits2Reco(selected);
1157 }
d47c658f 1158}
1159
e2afb3b6 1160//_______________________________________________________________________
2ab0c725 1161
1162void AliRun::Hits2Digits(const char *selected)
1163{
9e1a0ddb 1164
d47c658f 1165 // Convert Hits to sumable digits
1166 //
9e1a0ddb 1167 for (Int_t nevent=0; nevent<gAlice->TreeE()->GetEntries(); nevent++) {
1168 GetEvent(nevent);
9e1a0ddb 1169 Hits2SDigits(selected);
1170 SDigits2Digits(selected);
1171 }
2ab0c725 1172}
1173
d47c658f 1174
e2afb3b6 1175//_______________________________________________________________________
2ab0c725 1176
d47c658f 1177void AliRun::Tree2Tree(Option_t *option, const char *selected)
2ab0c725 1178{
1179 //
d47c658f 1180 // Function to transform the content of
1181 //
1182 // - TreeH to TreeS (option "S")
1183 // - TreeS to TreeD (option "D")
1184 // - TreeD to TreeR (option "R")
1185 //
1186 // If multiple options are specified ("SDR"), transformation will be done in sequence for
1187 // selected detector and for all detectors if none is selected (detector string
1188 // can contain blank separated list of detector names).
2ab0c725 1189
2ab0c725 1190
5cf7bbad 1191 const char *oS = strstr(option,"S");
1192 const char *oD = strstr(option,"D");
1193 const char *oR = strstr(option,"R");
2ab0c725 1194
9e1a0ddb 1195 TObjArray *detectors = Detectors();
2ab0c725 1196
1197 TIter next(detectors);
1198
d47c658f 1199 AliDetector *detector = 0;
2ab0c725 1200
88cb7938 1201 while((detector = dynamic_cast<AliDetector*>(next()))) {
d47c658f 1202 if (selected)
2ab0c725 1203 if (strcmp(detector->GetName(),selected)) continue;
88cb7938 1204 if (detector->IsActive())
1205 {
1206
1207 AliLoader* loader = detector->GetLoader();
1208 if (loader == 0x0) continue;
1209
1210 if (oS)
1211 {
1212 if (GetDebug()) Info("Tree2Tree","Processing Hits2SDigits for %s ...",detector->GetName());
1213 loader->LoadHits("read");
1214 if (loader->TreeS() == 0x0) loader->MakeTree("S");
1215 detector->MakeBranch(option);
1216 detector->SetTreeAddress();
1217 detector->Hits2SDigits();
1218 loader->UnloadHits();
1219 loader->UnloadSDigits();
1220 }
1221 if (oD)
1222 {
1223 if (GetDebug()) Info("Tree2Tree","Processing SDigits2Digits for %s ...",detector->GetName());
1224 loader->LoadSDigits("read");
1225 if (loader->TreeD() == 0x0) loader->MakeTree("D");
1226 detector->MakeBranch(option);
1227 detector->SetTreeAddress();
1228 detector->SDigits2Digits();
1229 loader->UnloadSDigits();
1230 loader->UnloadDigits();
1231 }
1232 if (oR)
1233 {
1234 if (GetDebug()) Info("Tree2Tree","Processing Digits2Reco for %s ...",detector->GetName());
1235 loader->LoadDigits("read");
1236 if (loader->TreeR() == 0x0) loader->MakeTree("R");
1237 detector->MakeBranch(option);
1238 detector->SetTreeAddress();
1239 detector->Digits2Reco();
1240 loader->UnloadDigits();
1241 loader->UnloadRecPoints();
1242
1243 }
1244 }
1245 }
2ab0c725 1246}
1247
e2afb3b6 1248//_______________________________________________________________________
0a520a66 1249void AliRun::RunLego(const char *setup, Int_t nc1, Float_t c1min,
1250 Float_t c1max,Int_t nc2,Float_t c2min,Float_t c2max,
1251 Float_t rmin,Float_t rmax,Float_t zmax, AliLegoGenerator* gener)
fe4da5cc 1252{
1253 //
1254 // Generates lego plots of:
1255 // - radiation length map phi vs theta
1256 // - radiation length map phi vs eta
1257 // - interaction length map
1258 // - g/cm2 length map
1259 //
1260 // ntheta bins in theta, eta
1261 // themin minimum angle in theta (degrees)
1262 // themax maximum angle in theta (degrees)
1263 // nphi bins in phi
1264 // phimin minimum angle in phi (degrees)
1265 // phimax maximum angle in phi (degrees)
1266 // rmin minimum radius
1267 // rmax maximum radius
1268 //
1269 //
1270 // The number of events generated = ntheta*nphi
1271 // run input parameters in macro setup (default="Config.C")
1272 //
1273 // Use macro "lego.C" to visualize the 3 lego plots in spherical coordinates
1274 //Begin_Html
1275 /*
1439f98e 1276 <img src="picts/AliRunLego1.gif">
fe4da5cc 1277 */
1278 //End_Html
1279 //Begin_Html
1280 /*
1439f98e 1281 <img src="picts/AliRunLego2.gif">
fe4da5cc 1282 */
1283 //End_Html
1284 //Begin_Html
1285 /*
1439f98e 1286 <img src="picts/AliRunLego3.gif">
fe4da5cc 1287 */
1288 //End_Html
1289 //
1290
1291 // check if initialisation has been done
875c717b 1292 if (!fInitDone) InitMC(setup);
838edcaf 1293 //Save current generator
1294 AliGenerator *gen=Generator();
1295
0a520a66 1296 // Set new generator
1297 if (!gener) gener = new AliLegoGenerator();
1298 ResetGenerator(gener);
1299 //
1300 // Configure Generator
1301 gener->SetRadiusRange(rmin, rmax);
1302 gener->SetZMax(zmax);
1303 gener->SetCoor1Range(nc1, c1min, c1max);
1304 gener->SetCoor2Range(nc2, c2min, c2max);
1305
1306
b13db077 1307 //Create Lego object
0a520a66 1308 fLego = new AliLego("lego",gener);
b13db077 1309
dffd31ef 1310 //Prepare MC for Lego Run
1311 gMC->InitLego();
1312
b13db077 1313 //Run Lego Object
0a520a66 1314
b9d0a01d 1315 //gMC->ProcessRun(nc1*nc2+1);
1316 gMC->ProcessRun(nc1*nc2);
fe4da5cc 1317
1318 // Create only the Root event Tree
88cb7938 1319 fRunLoader->MakeTree("E");
fe4da5cc 1320
1321 // End of this run, close files
80762cb1 1322 FinishRun();
0a520a66 1323 // Restore current generator
1324 ResetGenerator(gen);
838edcaf 1325 // Delete Lego Object
1326 delete fLego; fLego=0;
fe4da5cc 1327}
1328
e2afb3b6 1329//_______________________________________________________________________
94de3818 1330void AliRun::SetConfigFunction(const char * config)
1331{
1332 //
1333 // Set the signature of the function contained in Config.C to configure
1334 // the run
1335 //
1336 fConfigFunction=config;
1337}
1338
e2afb3b6 1339//_______________________________________________________________________
fe4da5cc 1340void AliRun::SetCurrentTrack(Int_t track)
1341{
1342 //
1343 // Set current track number
1344 //
88cb7938 1345 fRunLoader->Stack()->SetCurrentTrack(track);
fe4da5cc 1346}
1347
e2afb3b6 1348//_______________________________________________________________________
642f15cf 1349void AliRun::PushTrack(Int_t done, Int_t parent, Int_t pdg, Float_t *pmom,
88cb7938 1350 Float_t *vpos, Float_t *polar, Float_t tof,
1351 TMCProcess mech, Int_t &ntr, Float_t weight, Int_t is)
fe4da5cc 1352{
9e1a0ddb 1353// Delegate to stack
1354//
642f15cf 1355 fRunLoader->Stack()->PushTrack(done, parent, pdg, pmom, vpos, polar, tof,
88cb7938 1356 mech, ntr, weight, is);
fe4da5cc 1357}
1358
e2afb3b6 1359//_______________________________________________________________________
642f15cf 1360void AliRun::PushTrack(Int_t done, Int_t parent, Int_t pdg,
89bbad6f 1361 Double_t px, Double_t py, Double_t pz, Double_t e,
1362 Double_t vx, Double_t vy, Double_t vz, Double_t tof,
1363 Double_t polx, Double_t poly, Double_t polz,
98490ea9 1364 TMCProcess mech, Int_t &ntr, Float_t weight, Int_t is)
89bbad6f 1365{
9e1a0ddb 1366 // Delegate to stack
89bbad6f 1367 //
642f15cf 1368 fRunLoader->Stack()->PushTrack(done, parent, pdg, px, py, pz, e, vx, vy, vz, tof,
88cb7938 1369 polx, poly, polz, mech, ntr, weight, is);
89bbad6f 1370}
1371
e2afb3b6 1372//_______________________________________________________________________
4d69d91e 1373void AliRun::SetHighWaterMark(const Int_t nt)
1374{
1375 //
1376 // Set high water mark for last track in event
88cb7938 1377 fRunLoader->Stack()->SetHighWaterMark(nt);
4d69d91e 1378}
1379
e2afb3b6 1380//_______________________________________________________________________
fe4da5cc 1381void AliRun::KeepTrack(const Int_t track)
1382{
1383 //
9e1a0ddb 1384 // Delegate to stack
fe4da5cc 1385 //
88cb7938 1386 fRunLoader->Stack()->KeepTrack(track);
fe4da5cc 1387}
1388
b9d0a01d 1389//
1390// MC Application
1391//
1392
e2afb3b6 1393//_______________________________________________________________________
b9d0a01d 1394void AliRun::ConstructGeometry()
1395{
1396 //
1397 // Create modules, materials, geometry
1398 //
1399
1400 TStopwatch stw;
1401 TIter next(fModules);
1402 AliModule *detector;
88cb7938 1403 if (GetDebug()) Info("ConstructGeometry","Geometry creation:");
e2afb3b6 1404 while((detector = dynamic_cast<AliModule*>(next()))) {
b9d0a01d 1405 stw.Start();
1406 // Initialise detector materials and geometry
1407 detector->CreateMaterials();
1408 detector->CreateGeometry();
1409 printf("%10s R:%.2fs C:%.2fs\n",
88cb7938 1410 detector->GetName(),stw.RealTime(),stw.CpuTime());
b9d0a01d 1411 }
1412}
1413
e2afb3b6 1414//_______________________________________________________________________
b9d0a01d 1415void AliRun::InitGeometry()
1416{
1417 //
1418 // Initialize detectors and display geometry
1419 //
1420
1421 printf("Initialisation:\n");
1422 TStopwatch stw;
1423 TIter next(fModules);
1424 AliModule *detector;
e2afb3b6 1425 while((detector = dynamic_cast<AliModule*>(next()))) {
b9d0a01d 1426 stw.Start();
1427 // Initialise detector and display geometry
1428 detector->Init();
1429 detector->BuildGeometry();
1430 printf("%10s R:%.2fs C:%.2fs\n",
1431 detector->GetName(),stw.RealTime(),stw.CpuTime());
1432 }
1433
1434}
e2afb3b6 1435//_______________________________________________________________________
88cb7938 1436
b9d0a01d 1437void AliRun::GeneratePrimaries()
1438{
1439 //
1440 // Generate primary particles and fill them in the stack.
1441 //
1442
1443 Generator()->Generate();
1444}
e2afb3b6 1445//_______________________________________________________________________
b9d0a01d 1446
b9d0a01d 1447void AliRun::BeginPrimary()
1448{
1449 //
1450 // Called at the beginning of each primary track
1451 //
1452
1453 // Reset Hits info
1454 gAlice->ResetHits();
1455 gAlice->ResetTrackReferences();
1456
1457}
1458
e2afb3b6 1459//_______________________________________________________________________
b9d0a01d 1460void AliRun::PreTrack()
1461{
88cb7938 1462 TObjArray &dets = *fModules;
1463 AliModule *module;
1464
1465 for(Int_t i=0; i<=fNdets; i++)
1466 if((module = dynamic_cast<AliModule*>(dets[i])))
1467 module->PreTrack();
1468
1469 fMCQA->PreTrack();
b9d0a01d 1470}
1471
e2afb3b6 1472//_______________________________________________________________________
b9d0a01d 1473void AliRun::Stepping()
fe4da5cc 1474{
1475 //
1476 // Called at every step during transport
1477 //
1478
b9d0a01d 1479 Int_t id = DetFromMate(gMC->GetMedium());
1480 if (id < 0) return;
1481
fe4da5cc 1482 //
1483 // --- If lego option, do it and leave
b13db077 1484 if (fLego)
fe4da5cc 1485 fLego->StepManager();
b13db077 1486 else {
1487 Int_t copy;
1488 //Update energy deposition tables
875c717b 1489 AddEnergyDeposit(gMC->CurrentVolID(copy),gMC->Edep());
fe4da5cc 1490
b13db077 1491 //Call the appropriate stepping routine;
e2afb3b6 1492 AliModule *det = dynamic_cast<AliModule*>(fModules->At(id));
3f754d83 1493 if(det && det->StepManagerIsEnabled()) {
65fb704d 1494 fMCQA->StepManager(id);
1495 det->StepManager();
1496 }
fe4da5cc 1497 }
fe4da5cc 1498}
1499
e2afb3b6 1500//_______________________________________________________________________
b9d0a01d 1501void AliRun::PostTrack()
1502{
88cb7938 1503 TObjArray &dets = *fModules;
1504 AliModule *module;
1505
1506 for(Int_t i=0; i<=fNdets; i++)
1507 if((module = dynamic_cast<AliModule*>(dets[i])))
1508 module->PostTrack();
b9d0a01d 1509}
1510
e2afb3b6 1511//_______________________________________________________________________
b9d0a01d 1512void AliRun::FinishPrimary()
1513{
1514 //
1515 // Called at the end of each primary track
1516 //
1517
1518 // static Int_t count=0;
1519 // const Int_t times=10;
1520 // This primary is finished, purify stack
88cb7938 1521 fRunLoader->Stack()->PurifyKine();
b9d0a01d 1522
1523 TIter next(fModules);
1524 AliModule *detector;
e2afb3b6 1525 while((detector = dynamic_cast<AliModule*>(next()))) {
b9d0a01d 1526 detector->FinishPrimary();
88cb7938 1527 if(detector->GetLoader())
1528 {
1529 detector->GetLoader()->TreeH()->Fill();
1530 }
b9d0a01d 1531 }
1532
88cb7938 1533 // Write out track references if any
1534 if (fRunLoader->TreeTR())
1535 {
1536 fRunLoader->TreeTR()->Fill();
1537 }
b9d0a01d 1538}
1539
e2afb3b6 1540//_______________________________________________________________________
b9d0a01d 1541void AliRun::FinishEvent()
1542{
1543 //
1544 // Called at the end of the event.
1545 //
1546
1547 //
1548 if(fLego) fLego->FinishEvent();
1549
88cb7938 1550 TIter next(fModules);
1551 AliModule *detector;
1552 while((detector = dynamic_cast<AliModule*>(next()))) {
1553 detector->FinishEvent();
1554 }
1555
b9d0a01d 1556 //Update the energy deposit tables
1557 Int_t i;
88cb7938 1558 for(i=0;i<fEventEnergy.GetSize();i++)
1559 {
b9d0a01d 1560 fSummEnergy[i]+=fEventEnergy[i];
1561 fSum2Energy[i]+=fEventEnergy[i]*fEventEnergy[i];
88cb7938 1562 }
b9d0a01d 1563
88cb7938 1564 AliHeader* header = fRunLoader->GetHeader();
1565 AliStack* stack = fRunLoader->Stack();
1566 if ( (header == 0x0) || (stack == 0x0) )
1567 {//check if we got header and stack. If not cry and exit aliroot
1568 Fatal("AliRun","Can not get the stack or header from LOADER");
1569 return;//never reached
1570 }
b9d0a01d 1571 // Update Header information
88cb7938 1572 header->SetNprimary(stack->GetNprimary());
1573 header->SetNtrack(stack->GetNtrack());
b9d0a01d 1574
1575
1576 // Write out the kinematics
88cb7938 1577 stack->FinishEvent();
b9d0a01d 1578
1579 // Write out the event Header information
88cb7938 1580 TTree* treeE = fRunLoader->TreeE();
1581 if (treeE)
1582 {
1583 header->SetStack(stack);
1584 treeE->Fill();
1585 }
1586 else
1587 {
1588 Error("FinishEvent","Can not get TreeE from RL");
1589 }
b9d0a01d 1590
88cb7938 1591 fRunLoader->WriteKinematics("OVERWRITE");
1592 fRunLoader->WriteTrackRefs("OVERWRITE");
1593 fRunLoader->WriteHits("OVERWRITE");
1594
1595 if (GetDebug())
1596 {
1597 Info("FinishEvent","<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
1598 Info("FinishEvent","<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
1599 Info("FinishEvent","<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
1600 Info("FinishEvent"," FINISHING EVENT ");
1601 Info("FinishEvent","<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
1602 Info("FinishEvent","<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
1603 Info("FinishEvent","<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
1604 }
b9d0a01d 1605}
1606
e2afb3b6 1607//_______________________________________________________________________
b9d0a01d 1608void AliRun::Field(const Double_t* x, Double_t *b) const
1609{
88cb7938 1610 Float_t xfloat[3];
1611 for (Int_t i=0; i<3; i++) xfloat[i] = x[i];
1612
1613 if (Field()) {
1614 Float_t bfloat[3];
1615 Field()->Field(xfloat,bfloat);
1616 for (Int_t j=0; j<3; j++) b[j] = bfloat[j];
1617 }
1618 else {
1619 printf("No mag field defined!\n");
1620 b[0]=b[1]=b[2]=0.;
1621 }
b9d0a01d 1622
1623}
1624
1625//
1626// End of MC Application
1627//
1628
e2afb3b6 1629//_______________________________________________________________________
fe4da5cc 1630void AliRun::Streamer(TBuffer &R__b)
1631{
eef4b160 1632 // Stream an object of class AliRun.
2ab0c725 1633
7e90ff59 1634 if (R__b.IsReading()) {
1635 if (!gAlice) gAlice = this;
7e90ff59 1636 AliRun::Class()->ReadBuffer(R__b, this);
7e90ff59 1637 gROOT->GetListOfBrowsables()->Add(this,"Run");
eef4b160 1638
7e90ff59 1639 gRandom = fRandom;
1640 } else {
eef4b160 1641 AliRun::Class()->WriteBuffer(R__b, this);
1642 }
2ab0c725 1643}
1644
9e1a0ddb 1645
e2afb3b6 1646//_______________________________________________________________________
642f15cf 1647Int_t AliRun::GetCurrentTrackNumber() const {
9e1a0ddb 1648 //
1649 // Returns current track
1650 //
642f15cf 1651 return fRunLoader->Stack()->GetCurrentTrackNumber();
9e1a0ddb 1652}
1653
e2afb3b6 1654//_______________________________________________________________________
9e1a0ddb 1655Int_t AliRun::GetNtrack() const {
1656 //
1657 // Returns number of tracks in stack
1658 //
88cb7938 1659 return fRunLoader->Stack()->GetNtrack();
9e1a0ddb 1660}
88cb7938 1661//_______________________________________________________________________
9e1a0ddb 1662
e2afb3b6 1663//_______________________________________________________________________
37d06d5b 1664TObjArray* AliRun::Particles() const {
9e1a0ddb 1665 //
1666 // Returns pointer to Particles array
1667 //
88cb7938 1668 if (fRunLoader)
1669 if (fRunLoader->Stack())
1670 return fRunLoader->Stack()->Particles();
1671 return 0x0;
9e1a0ddb 1672}
27f087a9 1673
88cb7938 1674//___________________________________________________________________________
b9d0a01d 1675
e2afb3b6 1676//_______________________________________________________________________
27f087a9 1677void AliRun::SetGenEventHeader(AliGenEventHeader* header)
1678{
88cb7938 1679 fRunLoader->GetHeader()->SetGenEventHeader(header);
27f087a9 1680}
b9d0a01d 1681
88cb7938 1682//___________________________________________________________________________
0592d1ca 1683
88cb7938 1684Int_t AliRun::GetEvNumber() const
1685{
1686//Returns number of current event
1687 if (fRunLoader == 0x0)
1688 {
1689 Error("GetEvent","RunLoader is not set. Can not load data.");
1690 return -1;
1691 }
0592d1ca 1692
88cb7938 1693 return fRunLoader->GetEventNumber();
0592d1ca 1694}
b9d0a01d 1695
88cb7938 1696void AliRun::SetRunLoader(AliRunLoader* rloader)
0592d1ca 1697{
88cb7938 1698 fRunLoader = rloader;
1699 if (fRunLoader == 0x0) return;
1700
1701 TString evfoldname;
1702 TFolder* evfold = fRunLoader->GetEventFolder();
1703 if (evfold) evfoldname = evfold->GetName();
1704 else Warning("SetRunLoader","Did not get Event Folder from Run Loader");
1705
1706 if ( fRunLoader->GetAliRun() )
1707 {//if alrun already exists in folder
1708 if (fRunLoader->GetAliRun() != this )
1709 {//and is different than this - crash
1710 Fatal("AliRun","AliRun is already in Folder and it is not this object");
1711 return;//pro forma
1712 }//else do nothing
1713 }
1714 else
1715 {
1716 evfold->Add(this);//Post this AliRun to Folder
1717 }
1718
1719 TIter next(fModules);
1720 AliModule *module;
1721 while((module = (AliModule*)next()))
1722 {
1723 if (evfold) AliConfig::Instance()->Add(module,evfoldname);
1724 AliDetector* detector = dynamic_cast<AliDetector*>(module);
1725 if (detector)
1726 {
1727 AliLoader* loader = fRunLoader->GetLoader(detector);
1728 if (loader == 0x0)
1729 {
1730 Error("SetRunLoader","Can not get loader for detector %s",detector->GetName());
1731 }
1732 else
1733 {
1734 if (GetDebug()) Info("SetRunLoader","Setting loader for detector %s",detector->GetName());
1735 detector->SetLoader(loader);
1736 }
0592d1ca 1737 }
88cb7938 1738 }
0592d1ca 1739}
1740
88cb7938 1741void AliRun::AddModule(AliModule* mod)
7a16e9cc 1742{
88cb7938 1743 if (mod == 0x0) return;
1744 if (strlen(mod->GetName()) == 0) return;
1745 if (GetModuleID(mod->GetName()) >= 0) return;
1746
1747 if (GetDebug()) Info("AddModule","%s",mod->GetName());
1748 if (fRunLoader == 0x0) AliConfig::Instance()->Add(mod);
1749 else AliConfig::Instance()->Add(mod,fRunLoader->GetEventFolder()->GetName());
7a16e9cc 1750
88cb7938 1751 Modules()->Add(mod);
7a16e9cc 1752}