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