]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliRun.cxx
Reverting to version 1.6.2
[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
16/*
17$Log$
dffd31ef 18Revision 1.30 2000/04/18 19:11:40 fca
19Introduce variable Config.C function signature
20
45189757 21Revision 1.29 2000/04/07 11:12:34 fca
22G4 compatibility changes
23
875c717b 24Revision 1.28 2000/04/05 06:51:06 fca
25Workaround for an HP compiler problem
26
5eb58812 27Revision 1.27 2000/03/22 18:08:07 fca
28Rationalisation of the virtual MC interfaces
29
80762cb1 30Revision 1.26 2000/03/22 13:42:26 fca
31SetGenerator does not replace an existing generator, ResetGenerator does
32
ee1dd322 33Revision 1.25 2000/02/23 16:25:22 fca
34AliVMC and AliGeant3 classes introduced
35ReadEuclid moved from AliRun to AliModule
36
b13db077 37Revision 1.24 2000/01/19 17:17:20 fca
38Introducing a list of lists of hits -- more hits allowed for detector now
39
1cedd08a 40Revision 1.23 1999/12/03 11:14:31 fca
41Fixing previous wrong checking
42
00719c1b 43Revision 1.21 1999/11/25 10:40:08 fca
44Fixing daughters information also in primary tracks
45
ae23d366 46Revision 1.20 1999/10/04 18:08:49 fca
47Adding protection against inconsistent Euclid files
48
3fcc96a1 49Revision 1.19 1999/09/29 07:50:40 fca
50Introduction of the Copyright and cvs Log
51
99d554c8 52*/
53
fe4da5cc 54///////////////////////////////////////////////////////////////////////////////
55// //
56// Control class for Alice C++ //
57// Only one single instance of this class exists. //
58// The object is created in main program aliroot //
59// and is pointed by the global gAlice. //
60// //
8494b010 61// -Supports the list of all Alice Detectors (fModules). //
fe4da5cc 62// -Supports the list of particles (fParticles). //
63// -Supports the Trees. //
64// -Supports the geometry. //
65// -Supports the event display. //
66//Begin_Html
67/*
1439f98e 68<img src="picts/AliRunClass.gif">
fe4da5cc 69*/
70//End_Html
71//Begin_Html
72/*
1439f98e 73<img src="picts/alirun.gif">
fe4da5cc 74*/
75//End_Html
76// //
77///////////////////////////////////////////////////////////////////////////////
78
79#include <TFile.h>
80#include <TRandom.h>
81#include <TBRIK.h>
82#include <TNode.h>
fe4da5cc 83#include <TCint.h>
84#include <TSystem.h>
a8f1fb7c 85#include <TObjectTable.h>
fe4da5cc 86
1578254f 87#include "TParticle.h"
fe4da5cc 88#include "AliRun.h"
fe4da5cc 89#include "AliDisplay.h"
875c717b 90#include "AliMC.h"
dffd31ef 91#include "AliLego.h"
fe4da5cc 92
fe4da5cc 93#include <stdlib.h>
94#include <stdio.h>
95#include <string.h>
96
97AliRun *gAlice;
98
99static AliHeader *header;
100
fe4da5cc 101ClassImp(AliRun)
102
103//_____________________________________________________________________________
104AliRun::AliRun()
105{
106 //
107 // Default constructor for AliRun
108 //
109 header=&fHeader;
110 fRun = 0;
111 fEvent = 0;
112 fCurrent = -1;
8494b010 113 fModules = 0;
fe4da5cc 114 fGenerator = 0;
115 fTreeD = 0;
116 fTreeK = 0;
117 fTreeH = 0;
118 fTreeE = 0;
119 fTreeR = 0;
120 fParticles = 0;
121 fGeometry = 0;
122 fDisplay = 0;
123 fField = 0;
875c717b 124 fMC = 0;
fe4da5cc 125 fNdets = 0;
126 fImedia = 0;
127 fTrRmax = 1.e10;
128 fTrZmax = 1.e10;
fe4da5cc 129 fInitDone = kFALSE;
130 fLego = 0;
1578254f 131 fPDGDB = 0; //Particle factory object!
1cedd08a 132 fHitLists = 0;
45189757 133 fConfigFunction = "\0";
fe4da5cc 134}
135
136//_____________________________________________________________________________
137AliRun::AliRun(const char *name, const char *title)
138 : TNamed(name,title)
139{
140 //
141 // Constructor for the main processor.
142 // Creates the geometry
143 // Creates the list of Detectors.
144 // Creates the list of particles.
145 //
146 Int_t i;
147
148 gAlice = this;
149 fTreeD = 0;
150 fTreeK = 0;
151 fTreeH = 0;
152 fTreeE = 0;
153 fTreeR = 0;
154 fTrRmax = 1.e10;
155 fTrZmax = 1.e10;
1141f8e4 156 fGenerator = 0;
fe4da5cc 157 fInitDone = kFALSE;
158 fLego = 0;
159 fField = 0;
45189757 160 fConfigFunction = "Config();";
fe4da5cc 161
162 gROOT->GetListOfBrowsables()->Add(this,name);
163 //
164 // create the support list for the various Detectors
8494b010 165 fModules = new TObjArray(77);
fe4da5cc 166 //
167 // Create the TNode geometry for the event display
168
169 BuildSimpleGeometry();
170
171
172 fNtrack=0;
173 fHgwmk=0;
174 fCurrent=-1;
175 header=&fHeader;
176 fRun = 0;
177 fEvent = 0;
178 //
179 // Create the particle stack
1578254f 180 fParticles = new TClonesArray("TParticle",100);
fe4da5cc 181
182 fDisplay = 0;
183 //
184 // Create default mag field
185 SetField();
186 //
875c717b 187 fMC = gMC;
fe4da5cc 188 //
189 // Prepare the tracking medium lists
190 fImedia = new TArrayI(1000);
191 for(i=0;i<1000;i++) (*fImedia)[i]=-99;
1578254f 192 //
193 // Make particles
194 fPDGDB = TDatabasePDG::Instance(); //Particle factory object!
1cedd08a 195 //
196 // Create HitLists list
197 fHitLists = new TList();
fe4da5cc 198}
199
200//_____________________________________________________________________________
201AliRun::~AliRun()
202{
203 //
204 // Defaullt AliRun destructor
205 //
fe4da5cc 206 delete fImedia;
207 delete fField;
875c717b 208 delete fMC;
fe4da5cc 209 delete fGeometry;
210 delete fDisplay;
211 delete fGenerator;
212 delete fLego;
213 delete fTreeD;
214 delete fTreeK;
215 delete fTreeH;
216 delete fTreeE;
217 delete fTreeR;
8494b010 218 if (fModules) {
219 fModules->Delete();
220 delete fModules;
fe4da5cc 221 }
222 if (fParticles) {
223 fParticles->Delete();
224 delete fParticles;
225 }
1cedd08a 226 delete fHitLists;
fe4da5cc 227}
228
229//_____________________________________________________________________________
230void AliRun::AddHit(Int_t id, Int_t track, Int_t *vol, Float_t *hits) const
231{
232 //
233 // Add a hit to detector id
234 //
8494b010 235 TObjArray &dets = *fModules;
236 if(dets[id]) ((AliModule*) dets[id])->AddHit(track,vol,hits);
fe4da5cc 237}
238
239//_____________________________________________________________________________
240void AliRun::AddDigit(Int_t id, Int_t *tracks, Int_t *digits) const
241{
242 //
243 // Add digit to detector id
244 //
8494b010 245 TObjArray &dets = *fModules;
246 if(dets[id]) ((AliModule*) dets[id])->AddDigit(tracks,digits);
fe4da5cc 247}
248
249//_____________________________________________________________________________
250void AliRun::Browse(TBrowser *b)
251{
252 //
253 // Called when the item "Run" is clicked on the left pane
254 // of the Root browser.
255 // It displays the Root Trees and all detectors.
256 //
257 if (fTreeK) b->Add(fTreeK,fTreeK->GetName());
258 if (fTreeH) b->Add(fTreeH,fTreeH->GetName());
259 if (fTreeD) b->Add(fTreeD,fTreeD->GetName());
260 if (fTreeE) b->Add(fTreeE,fTreeE->GetName());
261 if (fTreeR) b->Add(fTreeR,fTreeR->GetName());
262
8494b010 263 TIter next(fModules);
264 AliModule *detector;
265 while((detector = (AliModule*)next())) {
fe4da5cc 266 b->Add(detector,detector->GetName());
267 }
268}
269
270//_____________________________________________________________________________
271void AliRun::Build()
272{
273 //
274 // Initialize Alice geometry
275 // Dummy routine
276 //
277}
278
279//_____________________________________________________________________________
280void AliRun::BuildSimpleGeometry()
281{
282 //
283 // Create a simple TNode geometry used by Root display engine
284 //
285 // Initialise geometry
286 //
287 fGeometry = new TGeometry("AliceGeom","Galice Geometry for Hits");
288 new TMaterial("void","Vacuum",0,0,0); //Everything is void
289 TBRIK *brik = new TBRIK("S_alice","alice volume","void",2000,2000,3000);
290 brik->SetVisibility(0);
291 new TNode("alice","alice","S_alice");
292}
293
294//_____________________________________________________________________________
295void AliRun::CleanDetectors()
296{
297 //
298 // Clean Detectors at the end of event
299 //
8494b010 300 TIter next(fModules);
301 AliModule *detector;
302 while((detector = (AliModule*)next())) {
fe4da5cc 303 detector->FinishEvent();
304 }
305}
306
307//_____________________________________________________________________________
308void AliRun::CleanParents()
309{
310 //
311 // Clean Particles stack.
1578254f 312 // Set parent/daughter relations
fe4da5cc 313 //
314 TClonesArray &particles = *(gAlice->Particles());
1578254f 315 TParticle *part;
fe4da5cc 316 int i;
317 for(i=0; i<fNtrack; i++) {
1578254f 318 part = (TParticle *)particles.UncheckedAt(i);
319 if(!part->TestBit(Daughters_Bit)) {
320 part->SetFirstDaughter(-1);
321 part->SetLastDaughter(-1);
fe4da5cc 322 }
323 }
324}
325
326//_____________________________________________________________________________
327Int_t AliRun::DistancetoPrimitive(Int_t, Int_t)
328{
329 //
330 // Return the distance from the mouse to the AliRun object
331 // Dummy routine
332 //
333 return 9999;
334}
335
336//_____________________________________________________________________________
337void AliRun::DumpPart (Int_t i)
338{
339 //
340 // Dumps particle i in the stack
341 //
342 TClonesArray &particles = *fParticles;
1578254f 343 ((TParticle*) particles[i])->Print();
fe4da5cc 344}
345
346//_____________________________________________________________________________
347void AliRun::DumpPStack ()
348{
349 //
350 // Dumps the particle stack
351 //
352 TClonesArray &particles = *fParticles;
353 printf(
354 "\n\n=======================================================================\n");
355 for (Int_t i=0;i<fNtrack;i++)
356 {
1578254f 357 printf("-> %d ",i); ((TParticle*) particles[i])->Print();
fe4da5cc 358 printf("--------------------------------------------------------------\n");
359 }
360 printf(
361 "\n=======================================================================\n\n");
362}
363
364//_____________________________________________________________________________
365void AliRun::SetField(Int_t type, Int_t version, Float_t scale,
366 Float_t maxField, char* filename)
367{
368 //
369 // Set magnetic field parameters
370 // type Magnetic field transport flag 0=no field, 2=helix, 3=Runge Kutta
371 // version Magnetic field map version (only 1 active now)
372 // scale Scale factor for the magnetic field
373 // maxField Maximum value for the magnetic field
374
375 //
376 // --- Sanity check on mag field flags
377 if(type<0 || type > 2) {
23370b7a 378 Warning("SetField",
379 "Invalid magnetic field flag: %5d; Helix tracking chosen instead\n"
fe4da5cc 380 ,type);
381 type=2;
382 }
383 if(fField) delete fField;
384 if(version==1) {
385 fField = new AliMagFC("Map1"," ",type,version,scale,maxField);
386 } else if(version<=3) {
387 fField = new AliMagFCM("Map2-3",filename,type,version,scale,maxField);
388 fField->ReadField();
389 } else {
23370b7a 390 Warning("SetField","Invalid map %d\n",version);
fe4da5cc 391 }
392}
393
394//_____________________________________________________________________________
395void AliRun::FillTree()
396{
397 //
398 // Fills all AliRun TTrees
399 //
400 if (fTreeK) fTreeK->Fill();
401 if (fTreeH) fTreeH->Fill();
402 if (fTreeD) fTreeD->Fill();
403 if (fTreeR) fTreeR->Fill();
404}
405
406//_____________________________________________________________________________
407void AliRun::FinishPrimary()
408{
409 //
410 // Called at the end of each primary track
411 //
412
6c9704e6 413 // static Int_t count=0;
414 // const Int_t times=10;
fe4da5cc 415 // This primary is finished, purify stack
80762cb1 416 PurifyKine();
fe4da5cc 417
418 // Write out hits if any
419 if (gAlice->TreeH()) {
420 gAlice->TreeH()->Fill();
421 }
422
423 // Reset Hits info
424 gAlice->ResetHits();
a8f1fb7c 425
426 //
427 // if(++count%times==1) gObjectTable->Print();
fe4da5cc 428}
429
430//_____________________________________________________________________________
431void AliRun::FinishEvent()
432{
433 //
434 // Called at the end of the event.
435 //
7fb01480 436
dffd31ef 437 //
438 if(fLego) fLego->FinishEvent();
439
fe4da5cc 440 //Update the energy deposit tables
441 Int_t i;
875c717b 442 for(i=0;i<fEventEnergy.GetSize();i++) {
443 fSummEnergy[i]+=fEventEnergy[i];
444 fSum2Energy[i]+=fEventEnergy[i]*fEventEnergy[i];
fe4da5cc 445 }
875c717b 446 fEventEnergy.Reset();
fe4da5cc 447
448 // Clean detector information
449 CleanDetectors();
450
451 // Write out the kinematics
452 if (fTreeK) {
453 CleanParents();
454 fTreeK->Fill();
455 }
456
457 // Write out the digits
458 if (fTreeD) {
459 fTreeD->Fill();
460 ResetDigits();
461 }
462
463 // Write out reconstructed clusters
464 if (fTreeR) {
465 fTreeR->Fill();
466 }
467
468 // Write out the event Header information
469 if (fTreeE) fTreeE->Fill();
470
471 // Reset stack info
472 ResetStack();
473
474 // Write Tree headers
59fe9bd2 475 // Int_t ievent = fHeader.GetEvent();
476 // char hname[30];
477 // sprintf(hname,"TreeK%d",ievent);
478 if (fTreeK) fTreeK->Write();
479 // sprintf(hname,"TreeH%d",ievent);
480 if (fTreeH) fTreeH->Write();
481 // sprintf(hname,"TreeD%d",ievent);
482 if (fTreeD) fTreeD->Write();
483 // sprintf(hname,"TreeR%d",ievent);
484 if (fTreeR) fTreeR->Write();
875c717b 485
486 ++fEvent;
fe4da5cc 487}
488
489//_____________________________________________________________________________
490void AliRun::FinishRun()
491{
492 //
493 // Called at the end of the run.
494 //
495
dffd31ef 496 //
497 if(fLego) fLego->FinishRun();
498
fe4da5cc 499 // Clean detector information
8494b010 500 TIter next(fModules);
501 AliModule *detector;
502 while((detector = (AliModule*)next())) {
fe4da5cc 503 detector->FinishRun();
504 }
505
506 //Output energy summary tables
507 EnergySummary();
508
509 // file is retrieved from whatever tree
510 TFile *File = 0;
511 if (fTreeK) File = fTreeK->GetCurrentFile();
512 if ((!File) && (fTreeH)) File = fTreeH->GetCurrentFile();
513 if ((!File) && (fTreeD)) File = fTreeD->GetCurrentFile();
514 if ((!File) && (fTreeE)) File = fTreeE->GetCurrentFile();
515 if( NULL==File ) {
516 Error("FinishRun","There isn't root file!");
517 exit(1);
518 }
519 File->cd();
520 fTreeE->Write();
521
522 // Clean tree information
523 delete fTreeK; fTreeK = 0;
524 delete fTreeH; fTreeH = 0;
525 delete fTreeD; fTreeD = 0;
526 delete fTreeR; fTreeR = 0;
527 delete fTreeE; fTreeE = 0;
528
529 // Write AliRun info and all detectors parameters
530 Write();
531
532 // Close output file
533 File->Write();
fe4da5cc 534}
535
536//_____________________________________________________________________________
537void AliRun::FlagTrack(Int_t track)
538{
539 //
540 // Flags a track and all its family tree to be kept
541 //
542 int curr;
1578254f 543 TParticle *particle;
fe4da5cc 544
545 curr=track;
546 while(1) {
1578254f 547 particle=(TParticle*)fParticles->UncheckedAt(curr);
fe4da5cc 548
549 // If the particle is flagged the three from here upward is saved already
550 if(particle->TestBit(Keep_Bit)) return;
551
552 // Save this particle
553 particle->SetBit(Keep_Bit);
554
555 // Move to father if any
1578254f 556 if((curr=particle->GetFirstMother())==-1) return;
fe4da5cc 557 }
558}
559
560//_____________________________________________________________________________
561void AliRun::EnergySummary()
562{
563 //
564 // Print summary of deposited energy
565 //
566
fe4da5cc 567 Int_t ndep=0;
568 Float_t edtot=0;
569 Float_t ed, ed2;
570 Int_t kn, i, left, j, id;
571 const Float_t zero=0;
572 Int_t ievent=fHeader.GetEvent()+1;
573 //
574 // Energy loss information
575 if(ievent) {
576 printf("***************** Energy Loss Information per event (GEV) *****************\n");
875c717b 577 for(kn=1;kn<fEventEnergy.GetSize();kn++) {
578 ed=fSummEnergy[kn];
fe4da5cc 579 if(ed>0) {
875c717b 580 fEventEnergy[ndep]=kn;
fe4da5cc 581 if(ievent>1) {
582 ed=ed/ievent;
875c717b 583 ed2=fSum2Energy[kn];
fe4da5cc 584 ed2=ed2/ievent;
585 ed2=100*TMath::Sqrt(TMath::Max(ed2-ed*ed,zero))/ed;
586 } else
587 ed2=99;
875c717b 588 fSummEnergy[ndep]=ed;
589 fSum2Energy[ndep]=TMath::Min((Float_t) 99.,TMath::Max(ed2,zero));
fe4da5cc 590 edtot+=ed;
591 ndep++;
592 }
593 }
594 for(kn=0;kn<(ndep-1)/3+1;kn++) {
595 left=ndep-kn*3;
596 for(i=0;i<(3<left?3:left);i++) {
597 j=kn*3+i;
875c717b 598 id=Int_t (fEventEnergy[j]+0.1);
599 printf(" %s %10.3f +- %10.3f%%;",gMC->VolName(id),fSummEnergy[j],fSum2Energy[j]);
fe4da5cc 600 }
601 printf("\n");
602 }
603 //
604 // Relative energy loss in different detectors
605 printf("******************** Relative Energy Loss per event ********************\n");
606 printf("Total energy loss per event %10.3f GeV\n",edtot);
607 for(kn=0;kn<(ndep-1)/5+1;kn++) {
608 left=ndep-kn*5;
609 for(i=0;i<(5<left?5:left);i++) {
610 j=kn*5+i;
875c717b 611 id=Int_t (fEventEnergy[j]+0.1);
612 printf(" %s %10.3f%%;",gMC->VolName(id),100*fSummEnergy[j]/edtot);
fe4da5cc 613 }
614 printf("\n");
615 }
616 for(kn=0;kn<75;kn++) printf("*");
617 printf("\n");
618 }
619 //
620 // Reset the TArray's
875c717b 621 // fEventEnergy.Set(0);
622 // fSummEnergy.Set(0);
623 // fSum2Energy.Set(0);
fe4da5cc 624}
625
626//_____________________________________________________________________________
8494b010 627AliModule *AliRun::GetModule(const char *name)
fe4da5cc 628{
629 //
630 // Return pointer to detector from name
631 //
8494b010 632 return (AliModule*)fModules->FindObject(name);
fe4da5cc 633}
634
a68348e9 635//_____________________________________________________________________________
636AliDetector *AliRun::GetDetector(const char *name)
637{
638 //
639 // Return pointer to detector from name
640 //
641 return (AliDetector*)fModules->FindObject(name);
642}
643
fe4da5cc 644//_____________________________________________________________________________
8494b010 645Int_t AliRun::GetModuleID(const char *name)
fe4da5cc 646{
647 //
648 // Return galice internal detector identifier from name
649 //
23370b7a 650 Int_t i=-1;
651 TObject *mod=fModules->FindObject(name);
652 if(mod) i=fModules->IndexOf(mod);
653 return i;
fe4da5cc 654}
655
656//_____________________________________________________________________________
657Int_t AliRun::GetEvent(Int_t event)
658{
659 //
660 // Connect the Trees Kinematics and Hits for event # event
661 // Set branch addresses
662 //
fe4da5cc 663
664 // Reset existing structures
665 ResetStack();
666 ResetHits();
667 ResetDigits();
668
669 // Delete Trees already connected
670 if (fTreeK) delete fTreeK;
671 if (fTreeH) delete fTreeH;
672 if (fTreeD) delete fTreeD;
673 if (fTreeR) delete fTreeR;
59fe9bd2 674
675 // Get header from file
676 if(fTreeE) fTreeE->GetEntry(event);
677 else Error("GetEvent","Cannot file Header Tree\n");
fe4da5cc 678
679 // Get Kine Tree from file
680 char treeName[20];
681 sprintf(treeName,"TreeK%d",event);
682 fTreeK = (TTree*)gDirectory->Get(treeName);
683 if (fTreeK) fTreeK->SetBranchAddress("Particles", &fParticles);
23370b7a 684 else Error("GetEvent","cannot find Kine Tree for event:%d\n",event);
fe4da5cc 685
686 // Get Hits Tree header from file
687 sprintf(treeName,"TreeH%d",event);
688 fTreeH = (TTree*)gDirectory->Get(treeName);
689 if (!fTreeH) {
23370b7a 690 Error("GetEvent","cannot find Hits Tree for event:%d\n",event);
fe4da5cc 691 }
692
693 // Get Digits Tree header from file
694 sprintf(treeName,"TreeD%d",event);
695 fTreeD = (TTree*)gDirectory->Get(treeName);
696 if (!fTreeD) {
07a68c1d 697 Warning("GetEvent","cannot find Digits Tree for event:%d\n",event);
fe4da5cc 698 }
699
700
701 // Get Reconstruct Tree header from file
702 sprintf(treeName,"TreeR%d",event);
703 fTreeR = (TTree*)gDirectory->Get(treeName);
704 if (!fTreeR) {
705 // printf("WARNING: cannot find Reconstructed Tree for event:%d\n",event);
706 }
707
708 // Set Trees branch addresses
8494b010 709 TIter next(fModules);
710 AliModule *detector;
711 while((detector = (AliModule*)next())) {
fe4da5cc 712 detector->SetTreeAddress();
713 }
714
715 if (fTreeK) fTreeK->GetEvent(0);
716 fNtrack = Int_t (fParticles->GetEntries());
717 return fNtrack;
718}
719
720//_____________________________________________________________________________
721TGeometry *AliRun::GetGeometry()
722{
723 //
724 // Import Alice geometry from current file
725 // Return pointer to geometry object
726 //
727 if (!fGeometry) fGeometry = (TGeometry*)gDirectory->Get("AliceGeom");
728 //
729 // Unlink and relink nodes in detectors
730 // This is bad and there must be a better way...
731 //
fe4da5cc 732
8494b010 733 TIter next(fModules);
734 AliModule *detector;
735 while((detector = (AliModule*)next())) {
fe4da5cc 736 detector->SetTreeAddress();
737 TList *dnodes=detector->Nodes();
738 Int_t j;
739 TNode *node, *node1;
740 for ( j=0; j<dnodes->GetSize(); j++) {
741 node = (TNode*) dnodes->At(j);
52d0ab00 742 node1 = fGeometry->GetNode(node->GetName());
fe4da5cc 743 dnodes->Remove(node);
744 dnodes->AddAt(node1,j);
745 }
746 }
747 return fGeometry;
748}
749
750//_____________________________________________________________________________
751void AliRun::GetNextTrack(Int_t &mtrack, Int_t &ipart, Float_t *pmom,
752 Float_t &e, Float_t *vpos, Float_t *polar,
753 Float_t &tof)
754{
755 //
756 // Return next track from stack of particles
757 //
a8f1fb7c 758 TVector3 pol;
fe4da5cc 759 fCurrent=-1;
1578254f 760 TParticle *track;
fe4da5cc 761 for(Int_t i=fNtrack-1; i>=0; i--) {
1578254f 762 track=(TParticle*) fParticles->UncheckedAt(i);
fe4da5cc 763 if(!track->TestBit(Done_Bit)) {
764 //
765 // The track has not yet been processed
766 fCurrent=i;
1578254f 767 ipart=track->GetPdgCode();
768 pmom[0]=track->Px();
769 pmom[1]=track->Py();
770 pmom[2]=track->Pz();
771 e =track->Energy();
772 vpos[0]=track->Vx();
773 vpos[1]=track->Vy();
774 vpos[2]=track->Vz();
a8f1fb7c 775 track->GetPolarisation(pol);
776 polar[0]=pol.X();
777 polar[1]=pol.Y();
778 polar[2]=pol.Z();
1578254f 779 tof=track->T();
fe4da5cc 780 track->SetBit(Done_Bit);
781 break;
782 }
783 }
784 mtrack=fCurrent;
785 //
786 // stop and start timer when we start a primary track
787 Int_t nprimaries = fHeader.GetNprimary();
788 if (fCurrent >= nprimaries) return;
789 if (fCurrent < nprimaries-1) {
790 fTimer.Stop();
1578254f 791 track=(TParticle*) fParticles->UncheckedAt(fCurrent+1);
792 // track->SetProcessTime(fTimer.CpuTime());
fe4da5cc 793 }
794 fTimer.Start();
795}
796
797//_____________________________________________________________________________
798Int_t AliRun::GetPrimary(Int_t track)
799{
800 //
801 // return number of primary that has generated track
802 //
803 int current, parent;
1578254f 804 TParticle *part;
fe4da5cc 805 //
806 parent=track;
807 while (1) {
808 current=parent;
1578254f 809 part = (TParticle *)fParticles->UncheckedAt(current);
810 parent=part->GetFirstMother();
fe4da5cc 811 if(parent<0) return current;
812 }
813}
814
815//_____________________________________________________________________________
875c717b 816void AliRun::InitMC(const char *setup)
fe4da5cc 817{
818 //
819 // Initialize the Alice setup
820 //
821
822 gROOT->LoadMacro(setup);
45189757 823 gInterpreter->ProcessLine(fConfigFunction.Data());
fe4da5cc 824
cfce8870 825 gMC->DefineParticles(); //Create standard MC particles
fe4da5cc 826
827 TObject *objfirst, *objlast;
828
23370b7a 829 fNdets = fModules->GetLast()+1;
830
fe4da5cc 831 //
875c717b 832 //=================Create Materials and geometry
833 gMC->Init();
834
8494b010 835 TIter next(fModules);
836 AliModule *detector;
837 while((detector = (AliModule*)next())) {
fe4da5cc 838 detector->SetTreeAddress();
839 objlast = gDirectory->GetList()->Last();
840
fe4da5cc 841 // Add Detector histograms in Detector list of histograms
842 if (objlast) objfirst = gDirectory->GetList()->After(objlast);
843 else objfirst = gDirectory->GetList()->First();
844 while (objfirst) {
845 detector->Histograms()->Add(objfirst);
846 objfirst = gDirectory->GetList()->After(objfirst);
847 }
848 }
849 SetTransPar(); //Read the cuts for all materials
850
851 MediaTable(); //Build the special IMEDIA table
852
fe4da5cc 853 //Initialise geometry deposition table
875c717b 854 fEventEnergy.Set(gMC->NofVolumes()+1);
855 fSummEnergy.Set(gMC->NofVolumes()+1);
856 fSum2Energy.Set(gMC->NofVolumes()+1);
fe4da5cc 857
fe4da5cc 858 //Compute cross-sections
875c717b 859 gMC->BuildPhysics();
fe4da5cc 860
861 //Write Geometry object to current file.
862 fGeometry->Write();
863
864 fInitDone = kTRUE;
865}
866
867//_____________________________________________________________________________
868void AliRun::MediaTable()
869{
870 //
871 // Built media table to get from the media number to
872 // the detector id
873 //
ad51aeb0 874 Int_t kz, nz, idt, lz, i, k, ind;
875 // Int_t ibeg;
fe4da5cc 876 TObjArray &dets = *gAlice->Detectors();
8494b010 877 AliModule *det;
fe4da5cc 878 //
879 // For all detectors
880 for (kz=0;kz<fNdets;kz++) {
881 // If detector is defined
8494b010 882 if((det=(AliModule*) dets[kz])) {
ad51aeb0 883 TArrayI &idtmed = *(det->GetIdtmed());
884 for(nz=0;nz<100;nz++) {
fe4da5cc 885 // Find max and min material number
ad51aeb0 886 if((idt=idtmed[nz])) {
fe4da5cc 887 det->LoMedium() = det->LoMedium() < idt ? det->LoMedium() : idt;
888 det->HiMedium() = det->HiMedium() > idt ? det->HiMedium() : idt;
889 }
890 }
891 if(det->LoMedium() > det->HiMedium()) {
892 det->LoMedium() = 0;
893 det->HiMedium() = 0;
894 } else {
895 if(det->HiMedium() > fImedia->GetSize()) {
ad51aeb0 896 Error("MediaTable","Increase fImedia from %d to %d",
897 fImedia->GetSize(),det->HiMedium());
fe4da5cc 898 return;
899 }
900 // Tag all materials in rage as belonging to detector kz
901 for(lz=det->LoMedium(); lz<= det->HiMedium(); lz++) {
902 (*fImedia)[lz]=kz;
903 }
904 }
905 }
906 }
907 //
908 // Print summary table
909 printf(" Traking media ranges:\n");
910 for(i=0;i<(fNdets-1)/6+1;i++) {
911 for(k=0;k< (6<fNdets-i*6?6:fNdets-i*6);k++) {
912 ind=i*6+k;
8494b010 913 det=(AliModule*)dets[ind];
fe4da5cc 914 if(det)
915 printf(" %6s: %3d -> %3d;",det->GetName(),det->LoMedium(),
916 det->HiMedium());
917 else
918 printf(" %6s: %3d -> %3d;","NULL",0,0);
919 }
920 printf("\n");
921 }
922}
923
924//____________________________________________________________________________
925void AliRun::SetGenerator(AliGenerator *generator)
ee1dd322 926{
927 //
928 // Load the event generator
929 //
930 if(!fGenerator) fGenerator = generator;
931}
932
933//____________________________________________________________________________
934void AliRun::ResetGenerator(AliGenerator *generator)
fe4da5cc 935{
936 //
937 // Load the event generator
938 //
b13db077 939 if(fGenerator)
ee1dd322 940 Warning("ResetGenerator","Replacing generator %s with %s\n",
b13db077 941 fGenerator->GetName(),generator->GetName());
942 fGenerator = generator;
fe4da5cc 943}
944
945//____________________________________________________________________________
946void AliRun::SetTransPar(char* filename)
947{
948 //
949 // Read filename to set the transport parameters
950 //
951
fe4da5cc 952
953 const Int_t ncuts=10;
954 const Int_t nflags=11;
955 const Int_t npars=ncuts+nflags;
956 const char pars[npars][7] = {"CUTGAM" ,"CUTELE","CUTNEU","CUTHAD","CUTMUO",
957 "BCUTE","BCUTM","DCUTE","DCUTM","PPCUTM","ANNI",
958 "BREM","COMP","DCAY","DRAY","HADR","LOSS",
959 "MULS","PAIR","PHOT","RAYL"};
960 char line[256];
ad51aeb0 961 char detName[7];
fe4da5cc 962 char* filtmp;
963 Float_t cut[ncuts];
964 Int_t flag[nflags];
965 Int_t i, itmed, iret, ktmed, kz;
966 FILE *lun;
967 //
968 // See whether the file is there
969 filtmp=gSystem->ExpandPathName(filename);
970 lun=fopen(filtmp,"r");
971 delete [] filtmp;
972 if(!lun) {
ad51aeb0 973 Warning("SetTransPar","File %s does not exist!\n",filename);
fe4da5cc 974 return;
975 }
976 //
977 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
978 printf(" *%59s\n","*");
979 printf(" * Please check carefully what you are doing!%10s\n","*");
980 printf(" *%59s\n","*");
981 //
982 while(1) {
983 // Initialise cuts and flags
984 for(i=0;i<ncuts;i++) cut[i]=-99;
985 for(i=0;i<nflags;i++) flag[i]=-99;
986 itmed=0;
987 for(i=0;i<256;i++) line[i]='\0';
988 // Read up to the end of line excluded
989 iret=fscanf(lun,"%[^\n]",line);
990 if(iret<0) {
991 //End of file
992 fclose(lun);
993 printf(" *%59s\n","*");
994 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
995 return;
996 }
997 // Read the end of line
998 fscanf(lun,"%*c");
999 if(!iret) continue;
1000 if(line[0]=='*') continue;
1001 // Read the numbers
ad51aeb0 1002 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",
1003 detName,&itmed,&cut[0],&cut[1],&cut[2],&cut[3],&cut[4],&cut[5],&cut[6],&cut[7],&cut[8],
1004 &cut[9],&flag[0],&flag[1],&flag[2],&flag[3],&flag[4],&flag[5],&flag[6],&flag[7],
1005 &flag[8],&flag[9],&flag[10]);
fe4da5cc 1006 if(!iret) continue;
1007 if(iret<0) {
1008 //reading error
ad51aeb0 1009 Warning("SetTransPar","Error reading file %s\n",filename);
fe4da5cc 1010 continue;
1011 }
ad51aeb0 1012 // Check that the module exist
1013 AliModule *mod = GetModule(detName);
1014 if(mod) {
1015 // Get the array of media numbers
1016 TArrayI &idtmed = *mod->GetIdtmed();
1017 // Check that the tracking medium code is valid
1018 if(0<=itmed && itmed < 100) {
1019 ktmed=idtmed[itmed];
1020 if(!ktmed) {
1021 Warning("SetTransPar","Invalid tracking medium code %d for %s\n",itmed,mod->GetName());
1022 continue;
fe4da5cc 1023 }
ad51aeb0 1024 // Set energy thresholds
1025 for(kz=0;kz<ncuts;kz++) {
1026 if(cut[kz]>=0) {
23370b7a 1027 printf(" * %-6s set to %10.3E for tracking medium code %4d for %s\n",
ad51aeb0 1028 pars[kz],cut[kz],itmed,mod->GetName());
cfce8870 1029 gMC->Gstpar(ktmed,pars[kz],cut[kz]);
ad51aeb0 1030 }
fe4da5cc 1031 }
ad51aeb0 1032 // Set transport mechanisms
1033 for(kz=0;kz<nflags;kz++) {
1034 if(flag[kz]>=0) {
1035 printf(" * %-6s set to %10d for tracking medium code %4d for %s\n",
1036 pars[ncuts+kz],flag[kz],itmed,mod->GetName());
cfce8870 1037 gMC->Gstpar(ktmed,pars[ncuts+kz],Float_t(flag[kz]));
ad51aeb0 1038 }
1039 }
1040 } else {
1041 Warning("SetTransPar","Invalid medium code %d *\n",itmed);
1042 continue;
fe4da5cc 1043 }
1044 } else {
ad51aeb0 1045 Warning("SetTransPar","Module %s not present\n",detName);
fe4da5cc 1046 continue;
1047 }
1048 }
1049}
1050
1051//_____________________________________________________________________________
1052void AliRun::MakeTree(Option_t *option)
1053{
1054 //
1055 // Create the ROOT trees
1056 // Loop on all detectors to create the Root branch (if any)
1057 //
1058
b13db077 1059 char hname[30];
fe4da5cc 1060 //
1061 // Analyse options
1062 char *K = strstr(option,"K");
1063 char *H = strstr(option,"H");
1064 char *E = strstr(option,"E");
1065 char *D = strstr(option,"D");
1066 char *R = strstr(option,"R");
1067 //
b13db077 1068 if (K && !fTreeK) {
1069 sprintf(hname,"TreeK%d",fEvent);
1070 fTreeK = new TTree(hname,"Kinematics");
1071 // Create a branch for particles
1072 fTreeK->Branch("Particles",&fParticles,4000);
1073 }
1074 if (H && !fTreeH) {
1075 sprintf(hname,"TreeH%d",fEvent);
1076 fTreeH = new TTree(hname,"Hits");
1077 fTreeH->SetAutoSave(1000000000); //no autosave
1078 }
1079 if (D && !fTreeD) {
1080 sprintf(hname,"TreeD%d",fEvent);
1081 fTreeD = new TTree(hname,"Digits");
1082 }
1083 if (R && !fTreeR) {
1084 sprintf(hname,"TreeR%d",fEvent);
1085 fTreeR = new TTree(hname,"Reconstruction");
1086 }
1087 if (E && !fTreeE) {
1088 fTreeE = new TTree("TE","Header");
1089 // Create a branch for Header
1090 fTreeE->Branch("Header","AliHeader",&header,4000);
1091 }
fe4da5cc 1092 //
1093 // Create a branch for hits/digits for each detector
1094 // Each branch is a TClonesArray. Each data member of the Hits classes
1095 // will be in turn a subbranch of the detector master branch
8494b010 1096 TIter next(fModules);
1097 AliModule *detector;
1098 while((detector = (AliModule*)next())) {
fe4da5cc 1099 if (H || D || R) detector->MakeBranch(option);
1100 }
fe4da5cc 1101}
1102
1103//_____________________________________________________________________________
1104Int_t AliRun::PurifyKine(Int_t lastSavedTrack, Int_t nofTracks)
1105{
1106 //
1107 // PurifyKine with external parameters
1108 //
1109 fHgwmk = lastSavedTrack;
1110 fNtrack = nofTracks;
1111 PurifyKine();
1112 return fHgwmk;
1113}
1114
1115//_____________________________________________________________________________
1116void AliRun::PurifyKine()
1117{
1118 //
1119 // Compress kinematic tree keeping only flagged particles
1120 // and renaming the particle id's in all the hits
1121 //
1122 TClonesArray &particles = *fParticles;
1123 int nkeep=fHgwmk+1, parent, i;
1578254f 1124 TParticle *part, *partnew, *father;
fe4da5cc 1125 int *map = new int[particles.GetEntries()];
1126
1127 // Save in Header total number of tracks before compression
1128 fHeader.SetNtrack(fHeader.GetNtrack()+fNtrack-fHgwmk);
1129
1130 // Preset map, to be removed later
1131 for(i=0; i<fNtrack; i++) {
1132 if(i<=fHgwmk) map[i]=i ; else map[i] = -99 ;}
1133 // Second pass, build map between old and new numbering
1134 for(i=fHgwmk+1; i<fNtrack; i++) {
1578254f 1135 part = (TParticle *)particles.UncheckedAt(i);
fe4da5cc 1136 if(part->TestBit(Keep_Bit)) {
1137
1138 // This particle has to be kept
1139 map[i]=nkeep;
1140 if(i!=nkeep) {
1141
1142 // Old and new are different, have to copy
1578254f 1143 partnew = (TParticle *)particles.UncheckedAt(nkeep);
5eb58812 1144 // Change due to a bug in the HP compiler
1145 // *partnew = *part;
1146 memcpy(partnew,part,sizeof(TParticle));
fe4da5cc 1147 } else partnew = part;
1148
1149 // as the parent is always *before*, it must be already
1150 // in place. This is what we are checking anyway!
1578254f 1151 if((parent=partnew->GetFirstMother())>fHgwmk) {
fe4da5cc 1152 if(map[parent]==-99) printf("map[%d] = -99!\n",parent);
1578254f 1153 partnew->SetFirstMother(map[parent]);
fe4da5cc 1154 }
1155 nkeep++;
1156 }
1157 }
1158 fNtrack=nkeep;
1159
1578254f 1160 // Fix daughters information
ae23d366 1161 for (i=0; i<fNtrack; i++) {
1578254f 1162 part = (TParticle *)particles.UncheckedAt(i);
1163 parent = part->GetFirstMother();
ae23d366 1164 if(parent>=0) {
1165 father = (TParticle *)particles.UncheckedAt(parent);
1166 if(father->TestBit(Daughters_Bit)) {
fe4da5cc 1167
ae23d366 1168 if(i<father->GetFirstDaughter()) father->SetFirstDaughter(i);
1169 if(i>father->GetLastDaughter()) father->SetLastDaughter(i);
1170 } else {
1171 // Iitialise daughters info for first pass
1172 father->SetFirstDaughter(i);
1173 father->SetLastDaughter(i);
1174 father->SetBit(Daughters_Bit);
1175 }
fe4da5cc 1176 }
1177 }
1178
1cedd08a 1179#ifdef old
fe4da5cc 1180 // Now loop on all detectors and reset the hits
b13db077 1181 AliHit *OneHit;
8494b010 1182 TIter next(fModules);
1183 AliModule *detector;
1184 while((detector = (AliModule*)next())) {
fe4da5cc 1185 if (!detector->Hits()) continue;
1186 TClonesArray &vHits=*(detector->Hits());
1187 if(vHits.GetEntries() != detector->GetNhits())
1188 printf("vHits.GetEntries()!=detector->GetNhits(): %d != %d\n",
1189 vHits.GetEntries(),detector->GetNhits());
1190 for (i=0; i<detector->GetNhits(); i++) {
1191 OneHit = (AliHit *)vHits.UncheckedAt(i);
1192 OneHit->SetTrack(map[OneHit->GetTrack()]);
1193 }
1194 }
1cedd08a 1195#else
1196
1197 // Now loop on all registered hit lists
1198 TIter next(fHitLists);
1199 TCollection *hitList;
1200 while((hitList = (TCollection*)next())) {
1201 TIter nexthit(hitList);
1202 AliHit *hit;
1203 while((hit = (AliHit*)nexthit())) {
1204 hit->SetTrack(map[hit->GetTrack()]);
1205 }
1206 }
1207#endif
fe4da5cc 1208
1209 fHgwmk=nkeep-1;
1210 particles.SetLast(fHgwmk);
1211 delete [] map;
1212}
1213
1214//_____________________________________________________________________________
dffd31ef 1215void AliRun::BeginEvent()
fe4da5cc 1216{
1217 //
1218 // Reset all Detectors & kinematics & trees
1219 //
59fe9bd2 1220 char hname[30];
dffd31ef 1221 //
1222
1223 //
1224 if(fLego) {
1225 fLego->BeginEvent();
1226 return;
1227 }
1228
59fe9bd2 1229 //
fe4da5cc 1230 ResetStack();
1231 ResetHits();
1232 ResetDigits();
1233
1234 // Initialise event header
875c717b 1235 fHeader.Reset(fRun,fEvent);
fe4da5cc 1236
59fe9bd2 1237 if(fTreeK) {
1238 fTreeK->Reset();
875c717b 1239 sprintf(hname,"TreeK%d",fEvent);
59fe9bd2 1240 fTreeK->SetName(hname);
1241 }
1242 if(fTreeH) {
1243 fTreeH->Reset();
875c717b 1244 sprintf(hname,"TreeH%d",fEvent);
59fe9bd2 1245 fTreeH->SetName(hname);
1246 }
1247 if(fTreeD) {
1248 fTreeD->Reset();
875c717b 1249 sprintf(hname,"TreeD%d",fEvent);
59fe9bd2 1250 fTreeD->SetName(hname);
1251 }
1252 if(fTreeR) {
1253 fTreeR->Reset();
875c717b 1254 sprintf(hname,"TreeR%d",fEvent);
59fe9bd2 1255 fTreeR->SetName(hname);
1256 }
fe4da5cc 1257}
1258
1259//_____________________________________________________________________________
1260void AliRun::ResetDigits()
1261{
1262 //
1263 // Reset all Detectors digits
1264 //
8494b010 1265 TIter next(fModules);
1266 AliModule *detector;
1267 while((detector = (AliModule*)next())) {
fe4da5cc 1268 detector->ResetDigits();
1269 }
1270}
1271
1272//_____________________________________________________________________________
1273void AliRun::ResetHits()
1274{
1275 //
1276 // Reset all Detectors hits
1277 //
8494b010 1278 TIter next(fModules);
1279 AliModule *detector;
1280 while((detector = (AliModule*)next())) {
fe4da5cc 1281 detector->ResetHits();
1282 }
1283}
1284
1285//_____________________________________________________________________________
1286void AliRun::ResetPoints()
1287{
1288 //
1289 // Reset all Detectors points
1290 //
8494b010 1291 TIter next(fModules);
1292 AliModule *detector;
1293 while((detector = (AliModule*)next())) {
fe4da5cc 1294 detector->ResetPoints();
1295 }
1296}
1297
1298//_____________________________________________________________________________
875c717b 1299void AliRun::RunMC(Int_t nevent, const char *setup)
fe4da5cc 1300{
1301 //
1302 // Main function to be called to process a galice run
1303 // example
1304 // Root > gAlice.Run();
1305 // a positive number of events will cause the finish routine
1306 // to be called
1307 //
1308
fe4da5cc 1309 // check if initialisation has been done
875c717b 1310 if (!fInitDone) InitMC(setup);
fe4da5cc 1311
fe4da5cc 1312 // Create the Root Tree with one branch per detector
80762cb1 1313 MakeTree("KHDER");
fe4da5cc 1314
875c717b 1315 gMC->ProcessRun(nevent);
1316
fe4da5cc 1317 // End of this run, close files
80762cb1 1318 if(nevent>0) FinishRun();
fe4da5cc 1319}
1320
1321//_____________________________________________________________________________
1322void AliRun::RunLego(const char *setup,Int_t ntheta,Float_t themin,
1323 Float_t themax,Int_t nphi,Float_t phimin,Float_t phimax,
1324 Float_t rmin,Float_t rmax,Float_t zmax)
1325{
1326 //
1327 // Generates lego plots of:
1328 // - radiation length map phi vs theta
1329 // - radiation length map phi vs eta
1330 // - interaction length map
1331 // - g/cm2 length map
1332 //
1333 // ntheta bins in theta, eta
1334 // themin minimum angle in theta (degrees)
1335 // themax maximum angle in theta (degrees)
1336 // nphi bins in phi
1337 // phimin minimum angle in phi (degrees)
1338 // phimax maximum angle in phi (degrees)
1339 // rmin minimum radius
1340 // rmax maximum radius
1341 //
1342 //
1343 // The number of events generated = ntheta*nphi
1344 // run input parameters in macro setup (default="Config.C")
1345 //
1346 // Use macro "lego.C" to visualize the 3 lego plots in spherical coordinates
1347 //Begin_Html
1348 /*
1439f98e 1349 <img src="picts/AliRunLego1.gif">
fe4da5cc 1350 */
1351 //End_Html
1352 //Begin_Html
1353 /*
1439f98e 1354 <img src="picts/AliRunLego2.gif">
fe4da5cc 1355 */
1356 //End_Html
1357 //Begin_Html
1358 /*
1439f98e 1359 <img src="picts/AliRunLego3.gif">
fe4da5cc 1360 */
1361 //End_Html
1362 //
1363
1364 // check if initialisation has been done
875c717b 1365 if (!fInitDone) InitMC(setup);
b13db077 1366
1367 //Create Lego object
1368 fLego = new AliLego("lego",ntheta,themin,themax,nphi,phimin,phimax,rmin,rmax,zmax);
1369
dffd31ef 1370 //Prepare MC for Lego Run
1371 gMC->InitLego();
1372
b13db077 1373 //Run Lego Object
dffd31ef 1374 gMC->ProcessRun(ntheta*nphi+1);
fe4da5cc 1375
1376 // Create only the Root event Tree
80762cb1 1377 MakeTree("E");
fe4da5cc 1378
1379 // End of this run, close files
80762cb1 1380 FinishRun();
fe4da5cc 1381}
1382
1383//_____________________________________________________________________________
1384void AliRun::SetCurrentTrack(Int_t track)
1385{
1386 //
1387 // Set current track number
1388 //
1389 fCurrent = track;
1390}
1391
1392//_____________________________________________________________________________
1578254f 1393void AliRun::SetTrack(Int_t done, Int_t parent, Int_t pdg, Float_t *pmom,
fe4da5cc 1394 Float_t *vpos, Float_t *polar, Float_t tof,
1395 const char *mecha, Int_t &ntr, Float_t weight)
1396{
1397 //
1398 // Load a track on the stack
1399 //
1400 // done 0 if the track has to be transported
1401 // 1 if not
1402 // parent identifier of the parent track. -1 for a primary
1578254f 1403 // pdg particle code
fe4da5cc 1404 // pmom momentum GeV/c
1405 // vpos position
1406 // polar polarisation
1407 // tof time of flight in seconds
1408 // mecha production mechanism
1409 // ntr on output the number of the track stored
1410 //
1411 TClonesArray &particles = *fParticles;
1578254f 1412 TParticle *particle;
fe4da5cc 1413 Float_t mass;
1578254f 1414 const Int_t firstdaughter=-1;
1415 const Int_t lastdaughter=-1;
fe4da5cc 1416 const Int_t KS=0;
1578254f 1417 // const Float_t tlife=0;
fe4da5cc 1418
1578254f 1419 //
1420 // Here we get the static mass
1421 // For MC is ok, but a more sophisticated method could be necessary
1422 // if the calculated mass is required
1423 // also, this method is potentially dangerous if the mass
1424 // used in the MC is not the same of the PDG database
1425 //
1426 mass = TDatabasePDG::Instance()->GetParticle(pdg)->Mass();
fe4da5cc 1427 Float_t e=TMath::Sqrt(mass*mass+pmom[0]*pmom[0]+
1428 pmom[1]*pmom[1]+pmom[2]*pmom[2]);
1429
1430 //printf("Loading particle %s mass %f ene %f No %d ip %d pos %f %f %f mom %f %f %f KS %d m %s\n",
1578254f 1431 //pname,mass,e,fNtrack,pdg,vpos[0],vpos[1],vpos[2],pmom[0],pmom[1],pmom[2],KS,mecha);
fe4da5cc 1432
1578254f 1433 particle=new(particles[fNtrack]) TParticle(pdg,KS,parent,-1,firstdaughter,
1434 lastdaughter,pmom[0],pmom[1],pmom[2],
1435 e,vpos[0],vpos[1],vpos[2],tof);
1436 // polar[0],polar[1],polar[2],tof,
1437 // mecha,weight);
1438 ((TParticle*)particles[fNtrack])->SetPolarisation(TVector3(polar[0],polar[1],polar[2]));
1439 ((TParticle*)particles[fNtrack])->SetWeight(weight);
fe4da5cc 1440 if(!done) particle->SetBit(Done_Bit);
1441
1442 if(parent>=0) {
1578254f 1443 particle=(TParticle*) fParticles->UncheckedAt(parent);
1444 particle->SetLastDaughter(fNtrack);
1445 if(particle->GetFirstDaughter()<0) particle->SetFirstDaughter(fNtrack);
fe4da5cc 1446 } else {
1447 //
1448 // This is a primary track. Set high water mark for this event
1449 fHgwmk=fNtrack;
1450 //
1451 // Set also number if primary tracks
1452 fHeader.SetNprimary(fHgwmk+1);
1453 fHeader.SetNtrack(fHgwmk+1);
1454 }
1455 ntr = fNtrack++;
1456}
1457
1458//_____________________________________________________________________________
1459void AliRun::KeepTrack(const Int_t track)
1460{
1461 //
1462 // flags a track to be kept
1463 //
1464 TClonesArray &particles = *fParticles;
1578254f 1465 ((TParticle*)particles[track])->SetBit(Keep_Bit);
fe4da5cc 1466}
1467
1468//_____________________________________________________________________________
875c717b 1469void AliRun::StepManager(Int_t id)
fe4da5cc 1470{
1471 //
1472 // Called at every step during transport
1473 //
1474
fe4da5cc 1475 //
1476 // --- If lego option, do it and leave
b13db077 1477 if (fLego)
fe4da5cc 1478 fLego->StepManager();
b13db077 1479 else {
1480 Int_t copy;
1481 //Update energy deposition tables
875c717b 1482 AddEnergyDeposit(gMC->CurrentVolID(copy),gMC->Edep());
fe4da5cc 1483
b13db077 1484 //Call the appropriate stepping routine;
1485 AliModule *det = (AliModule*)fModules->At(id);
1486 if(det) det->StepManager();
fe4da5cc 1487 }
fe4da5cc 1488}
1489
fe4da5cc 1490//_____________________________________________________________________________
1491void AliRun::Streamer(TBuffer &R__b)
1492{
1493 //
1494 // Stream an object of class AliRun.
1495 //
1496 if (R__b.IsReading()) {
1497 Version_t R__v = R__b.ReadVersion(); if (R__v) { }
1498 TNamed::Streamer(R__b);
1499 if (!gAlice) gAlice = this;
1500 gROOT->GetListOfBrowsables()->Add(this,"Run");
59fe9bd2 1501 fTreeE = (TTree*)gDirectory->Get("TE");
1502 if (fTreeE) fTreeE->SetBranchAddress("Header", &header);
1503 else Error("Streamer","cannot find Header Tree\n");
fe4da5cc 1504 R__b >> fNtrack;
1505 R__b >> fHgwmk;
1506 R__b >> fDebug;
1507 fHeader.Streamer(R__b);
8494b010 1508 R__b >> fModules;
fe4da5cc 1509 R__b >> fParticles;
1510 R__b >> fField;
875c717b 1511 // R__b >> fMC;
fe4da5cc 1512 R__b >> fNdets;
1513 R__b >> fTrRmax;
1514 R__b >> fTrZmax;
1515 R__b >> fGenerator;
59fe9bd2 1516 if(R__v>1) {
1517 R__b >> fPDGDB; //Particle factory object!
1518 fTreeE->GetEntry(0);
1519 } else {
1520 fHeader.SetEvent(0);
1521 fPDGDB = TDatabasePDG::Instance(); //Particle factory object!
1522 }
45189757 1523 if(R__v>2) {
1524 fConfigFunction.Streamer(R__b);
1525 } else {
1526 fConfigFunction="Config();";
1527 }
fe4da5cc 1528 } else {
1529 R__b.WriteVersion(AliRun::IsA());
1530 TNamed::Streamer(R__b);
1531 R__b << fNtrack;
1532 R__b << fHgwmk;
1533 R__b << fDebug;
1534 fHeader.Streamer(R__b);
8494b010 1535 R__b << fModules;
fe4da5cc 1536 R__b << fParticles;
1537 R__b << fField;
875c717b 1538 // R__b << fMC;
fe4da5cc 1539 R__b << fNdets;
1540 R__b << fTrRmax;
1541 R__b << fTrZmax;
1542 R__b << fGenerator;
1578254f 1543 R__b << fPDGDB; //Particle factory object!
45189757 1544 fConfigFunction.Streamer(R__b);
fe4da5cc 1545 }
1546}