Use enum constants for particle selection.
[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$
5cf7bbad 18Revision 1.58 2001/03/09 14:27:26 morsch
19Fix for multiple events per file: inhibit decrease of size of fParticleFileMap.
20
6781433e 21Revision 1.57 2001/02/23 17:40:23 buncic
22All trees needed for simulation created in RunMC(). TreeR and its branches
23are now created in new RunReco() method.
24
d47c658f 25Revision 1.56 2001/02/14 15:45:20 hristov
26Algorithmic way of getting entry index in fParticleMap. Protection of fParticleFileMap (I.Hrivnacova)
27
a41d61a9 28Revision 1.55 2001/02/12 15:52:54 buncic
29Removed OpenBaseFile().
30
39de14fb 31Revision 1.54 2001/02/07 10:39:05 hristov
32Remove default value for argument
33
1d994b80 34Revision 1.53 2001/02/06 11:02:26 hristov
35New SetTrack interface added, added check for unfilled particles in FinishEvent (I.Hrivnacova)
36
89bbad6f 37Revision 1.52 2001/02/05 16:22:25 buncic
38Added TreeS to GetEvent().
39
82711e7a 40Revision 1.51 2001/02/02 15:16:20 morsch
41SetHighWaterMark method added to mark last particle in event.
42
4d69d91e 43Revision 1.50 2001/01/27 10:32:00 hristov
44Leave the loop when primaries are filled (I.Hrivnacova)
45
cb94ac2a 46Revision 1.49 2001/01/26 19:58:48 hristov
47Major upgrade of AliRoot code
48
2ab0c725 49Revision 1.48 2001/01/17 10:50:50 hristov
50Corrections to destructors
51
e460afec 52Revision 1.47 2000/12/18 10:44:01 morsch
53Possibility to set field map by passing pointer to objet of type AliMagF via
54SetField().
55Example:
56gAlice->SetField(new AliMagFCM("Map2", "$(ALICE_ROOT)/data/field01.dat",2,1.,10.));
57
d8408e76 58Revision 1.46 2000/12/14 19:29:27 fca
59galice.cuts was not read any more
60
327136d2 61Revision 1.45 2000/11/30 07:12:49 alibrary
62Introducing new Rndm and QA classes
63
65fb704d 64Revision 1.44 2000/10/26 13:58:59 morsch
65Add possibility to choose the lego generator (of type AliGeneratorLego or derived) when running
66RunLego(). Default is the base class AliGeneratorLego.
67
0a520a66 68Revision 1.43 2000/10/09 09:43:17 fca
69Special remapping of hits for TPC and TRD. End-of-primary action introduced
70
24de2263 71Revision 1.42 2000/10/02 21:28:14 fca
72Removal of useless dependecies via forward declarations
73
94de3818 74Revision 1.41 2000/07/13 16:19:09 fca
75Mainly coding conventions + some small bug fixes
76
ef42d733 77Revision 1.40 2000/07/12 08:56:25 fca
78Coding convention correction and warning removal
79
8918e700 80Revision 1.39 2000/07/11 18:24:59 fca
81Coding convention corrections + few minor bug fixes
82
aee8290b 83Revision 1.38 2000/06/20 13:05:45 fca
84Writing down the TREE headers before job starts
85
51e0e89d 86Revision 1.37 2000/06/09 20:05:11 morsch
87Introduce possibility to chose magnetic field version 3: AliMagFDM + field02.dat
88
f1b9d7c3 89Revision 1.36 2000/06/08 14:03:58 hristov
90Only one initializer for a default argument
91
d33c0226 92Revision 1.35 2000/06/07 10:13:14 hristov
93Delete only existent objects.
94
d2ecd553 95Revision 1.34 2000/05/18 10:45:38 fca
96Delete Particle Factory properly
97
c222d2b0 98Revision 1.33 2000/05/16 13:10:40 fca
99New method IsNewTrack and fix for a problem in Father-Daughter relations
100
a01a8b12 101Revision 1.32 2000/04/27 10:38:21 fca
102Correct termination of Lego Run and introduce Lego getter in AliRun
103
838edcaf 104Revision 1.31 2000/04/26 10:17:32 fca
105Changes in Lego for G4 compatibility
106
dffd31ef 107Revision 1.30 2000/04/18 19:11:40 fca
108Introduce variable Config.C function signature
109
45189757 110Revision 1.29 2000/04/07 11:12:34 fca
111G4 compatibility changes
112
875c717b 113Revision 1.28 2000/04/05 06:51:06 fca
114Workaround for an HP compiler problem
115
5eb58812 116Revision 1.27 2000/03/22 18:08:07 fca
117Rationalisation of the virtual MC interfaces
118
80762cb1 119Revision 1.26 2000/03/22 13:42:26 fca
120SetGenerator does not replace an existing generator, ResetGenerator does
121
ee1dd322 122Revision 1.25 2000/02/23 16:25:22 fca
123AliVMC and AliGeant3 classes introduced
124ReadEuclid moved from AliRun to AliModule
125
b13db077 126Revision 1.24 2000/01/19 17:17:20 fca
127Introducing a list of lists of hits -- more hits allowed for detector now
128
1cedd08a 129Revision 1.23 1999/12/03 11:14:31 fca
130Fixing previous wrong checking
131
00719c1b 132Revision 1.21 1999/11/25 10:40:08 fca
133Fixing daughters information also in primary tracks
134
ae23d366 135Revision 1.20 1999/10/04 18:08:49 fca
136Adding protection against inconsistent Euclid files
137
3fcc96a1 138Revision 1.19 1999/09/29 07:50:40 fca
139Introduction of the Copyright and cvs Log
140
99d554c8 141*/
142
fe4da5cc 143///////////////////////////////////////////////////////////////////////////////
144// //
145// Control class for Alice C++ //
146// Only one single instance of this class exists. //
147// The object is created in main program aliroot //
148// and is pointed by the global gAlice. //
149// //
8494b010 150// -Supports the list of all Alice Detectors (fModules). //
fe4da5cc 151// -Supports the list of particles (fParticles). //
152// -Supports the Trees. //
153// -Supports the geometry. //
154// -Supports the event display. //
155//Begin_Html
156/*
1439f98e 157<img src="picts/AliRunClass.gif">
fe4da5cc 158*/
159//End_Html
160//Begin_Html
161/*
1439f98e 162<img src="picts/alirun.gif">
fe4da5cc 163*/
164//End_Html
165// //
166///////////////////////////////////////////////////////////////////////////////
167
94de3818 168#include <stdlib.h>
169#include <stdio.h>
170#include <string.h>
2ab0c725 171#include <iostream.h>
94de3818 172
fe4da5cc 173#include <TFile.h>
174#include <TRandom.h>
175#include <TBRIK.h>
176#include <TNode.h>
fe4da5cc 177#include <TCint.h>
178#include <TSystem.h>
a8f1fb7c 179#include <TObjectTable.h>
94de3818 180#include <TTree.h>
181#include <TGeometry.h>
182#include <TROOT.h>
183#include "TBrowser.h"
fe4da5cc 184
1578254f 185#include "TParticle.h"
fe4da5cc 186#include "AliRun.h"
fe4da5cc 187#include "AliDisplay.h"
875c717b 188#include "AliMC.h"
dffd31ef 189#include "AliLego.h"
aee8290b 190#include "AliMagFC.h"
191#include "AliMagFCM.h"
192#include "AliMagFDM.h"
94de3818 193#include "AliHit.h"
65fb704d 194#include "TRandom3.h"
195#include "AliMCQA.h"
196#include "AliGenerator.h"
197#include "AliLegoGenerator.h"
94de3818 198
199#include "AliDetector.h"
fe4da5cc 200
fe4da5cc 201AliRun *gAlice;
202
aee8290b 203static AliHeader *gAliHeader;
fe4da5cc 204
fe4da5cc 205ClassImp(AliRun)
206
207//_____________________________________________________________________________
208AliRun::AliRun()
209{
210 //
211 // Default constructor for AliRun
212 //
aee8290b 213 gAliHeader=&fHeader;
fe4da5cc 214 fRun = 0;
215 fEvent = 0;
216 fCurrent = -1;
8494b010 217 fModules = 0;
fe4da5cc 218 fGenerator = 0;
219 fTreeD = 0;
220 fTreeK = 0;
221 fTreeH = 0;
222 fTreeE = 0;
223 fTreeR = 0;
2ab0c725 224 fTreeS = 0;
fe4da5cc 225 fParticles = 0;
226 fGeometry = 0;
227 fDisplay = 0;
228 fField = 0;
875c717b 229 fMC = 0;
fe4da5cc 230 fNdets = 0;
231 fImedia = 0;
232 fTrRmax = 1.e10;
233 fTrZmax = 1.e10;
fe4da5cc 234 fInitDone = kFALSE;
235 fLego = 0;
1578254f 236 fPDGDB = 0; //Particle factory object!
1cedd08a 237 fHitLists = 0;
45189757 238 fConfigFunction = "\0";
65fb704d 239 fRandom = 0;
240 fMCQA = 0;
241 fTransParName = "\0";
39de14fb 242 fBaseFileName = ".\0";
2ab0c725 243 fParticleBuffer = 0;
244 fParticleMap = new TObjArray(10000);
fe4da5cc 245}
246
247//_____________________________________________________________________________
248AliRun::AliRun(const char *name, const char *title)
249 : TNamed(name,title)
250{
251 //
252 // Constructor for the main processor.
253 // Creates the geometry
254 // Creates the list of Detectors.
255 // Creates the list of particles.
256 //
257 Int_t i;
258
259 gAlice = this;
260 fTreeD = 0;
261 fTreeK = 0;
262 fTreeH = 0;
263 fTreeE = 0;
264 fTreeR = 0;
2ab0c725 265 fTreeS = 0;
fe4da5cc 266 fTrRmax = 1.e10;
267 fTrZmax = 1.e10;
1141f8e4 268 fGenerator = 0;
fe4da5cc 269 fInitDone = kFALSE;
270 fLego = 0;
271 fField = 0;
45189757 272 fConfigFunction = "Config();";
65fb704d 273
274 // Set random number generator
275 gRandom = fRandom = new TRandom3();
2ab0c725 276
277 if (gSystem->Getenv("CONFIG_SEED")) {
278 gRandom->SetSeed((UInt_t)atoi(gSystem->Getenv("CONFIG_SEED")));
279 }
fe4da5cc 280
281 gROOT->GetListOfBrowsables()->Add(this,name);
282 //
283 // create the support list for the various Detectors
8494b010 284 fModules = new TObjArray(77);
fe4da5cc 285 //
286 // Create the TNode geometry for the event display
287
288 BuildSimpleGeometry();
289
290
291 fNtrack=0;
292 fHgwmk=0;
293 fCurrent=-1;
aee8290b 294 gAliHeader=&fHeader;
fe4da5cc 295 fRun = 0;
296 fEvent = 0;
297 //
298 // Create the particle stack
2ab0c725 299 fParticles = new TClonesArray("TParticle",1000);
fe4da5cc 300
301 fDisplay = 0;
302 //
303 // Create default mag field
304 SetField();
305 //
875c717b 306 fMC = gMC;
fe4da5cc 307 //
308 // Prepare the tracking medium lists
309 fImedia = new TArrayI(1000);
310 for(i=0;i<1000;i++) (*fImedia)[i]=-99;
1578254f 311 //
312 // Make particles
313 fPDGDB = TDatabasePDG::Instance(); //Particle factory object!
1cedd08a 314 //
315 // Create HitLists list
316 fHitLists = new TList();
65fb704d 317 //
318 SetTransPar();
39de14fb 319 fBaseFileName = ".\0";
2ab0c725 320 fParticleBuffer = 0;
321 fParticleMap = new TObjArray(10000);
fe4da5cc 322}
323
aee8290b 324
fe4da5cc 325//_____________________________________________________________________________
326AliRun::~AliRun()
327{
328 //
2ab0c725 329 // Default AliRun destructor
fe4da5cc 330 //
fe4da5cc 331 delete fImedia;
332 delete fField;
875c717b 333 delete fMC;
fe4da5cc 334 delete fGeometry;
335 delete fDisplay;
336 delete fGenerator;
337 delete fLego;
338 delete fTreeD;
339 delete fTreeK;
340 delete fTreeH;
341 delete fTreeE;
342 delete fTreeR;
2ab0c725 343 delete fTreeS;
8494b010 344 if (fModules) {
345 fModules->Delete();
346 delete fModules;
fe4da5cc 347 }
348 if (fParticles) {
349 fParticles->Delete();
350 delete fParticles;
351 }
1cedd08a 352 delete fHitLists;
c222d2b0 353 delete fPDGDB;
e460afec 354 delete fMCQA;
fe4da5cc 355}
356
357//_____________________________________________________________________________
358void AliRun::AddHit(Int_t id, Int_t track, Int_t *vol, Float_t *hits) const
359{
360 //
361 // Add a hit to detector id
362 //
8494b010 363 TObjArray &dets = *fModules;
364 if(dets[id]) ((AliModule*) dets[id])->AddHit(track,vol,hits);
fe4da5cc 365}
366
367//_____________________________________________________________________________
368void AliRun::AddDigit(Int_t id, Int_t *tracks, Int_t *digits) const
369{
370 //
371 // Add digit to detector id
372 //
8494b010 373 TObjArray &dets = *fModules;
374 if(dets[id]) ((AliModule*) dets[id])->AddDigit(tracks,digits);
fe4da5cc 375}
376
377//_____________________________________________________________________________
378void AliRun::Browse(TBrowser *b)
379{
380 //
381 // Called when the item "Run" is clicked on the left pane
382 // of the Root browser.
383 // It displays the Root Trees and all detectors.
384 //
385 if (fTreeK) b->Add(fTreeK,fTreeK->GetName());
386 if (fTreeH) b->Add(fTreeH,fTreeH->GetName());
387 if (fTreeD) b->Add(fTreeD,fTreeD->GetName());
388 if (fTreeE) b->Add(fTreeE,fTreeE->GetName());
389 if (fTreeR) b->Add(fTreeR,fTreeR->GetName());
2ab0c725 390 if (fTreeS) b->Add(fTreeS,fTreeS->GetName());
fe4da5cc 391
8494b010 392 TIter next(fModules);
393 AliModule *detector;
394 while((detector = (AliModule*)next())) {
fe4da5cc 395 b->Add(detector,detector->GetName());
396 }
65fb704d 397 b->Add(fMCQA,"AliMCQA");
fe4da5cc 398}
399
400//_____________________________________________________________________________
401void AliRun::Build()
402{
403 //
404 // Initialize Alice geometry
405 // Dummy routine
406 //
407}
408
409//_____________________________________________________________________________
410void AliRun::BuildSimpleGeometry()
411{
412 //
413 // Create a simple TNode geometry used by Root display engine
414 //
415 // Initialise geometry
416 //
417 fGeometry = new TGeometry("AliceGeom","Galice Geometry for Hits");
418 new TMaterial("void","Vacuum",0,0,0); //Everything is void
419 TBRIK *brik = new TBRIK("S_alice","alice volume","void",2000,2000,3000);
420 brik->SetVisibility(0);
421 new TNode("alice","alice","S_alice");
422}
423
424//_____________________________________________________________________________
425void AliRun::CleanDetectors()
426{
427 //
428 // Clean Detectors at the end of event
429 //
8494b010 430 TIter next(fModules);
431 AliModule *detector;
432 while((detector = (AliModule*)next())) {
fe4da5cc 433 detector->FinishEvent();
434 }
435}
436
437//_____________________________________________________________________________
438void AliRun::CleanParents()
439{
440 //
441 // Clean Particles stack.
1578254f 442 // Set parent/daughter relations
fe4da5cc 443 //
2ab0c725 444 TObjArray &particles = *fParticleMap;
1578254f 445 TParticle *part;
fe4da5cc 446 int i;
2ab0c725 447 for(i=0; i<fHgwmk+1; i++) {
448 part = (TParticle *)particles.At(i);
449 if(part) if(!part->TestBit(kDaughtersBit)) {
1578254f 450 part->SetFirstDaughter(-1);
451 part->SetLastDaughter(-1);
fe4da5cc 452 }
453 }
454}
455
456//_____________________________________________________________________________
457Int_t AliRun::DistancetoPrimitive(Int_t, Int_t)
458{
459 //
460 // Return the distance from the mouse to the AliRun object
461 // Dummy routine
462 //
463 return 9999;
464}
465
466//_____________________________________________________________________________
94de3818 467void AliRun::DumpPart (Int_t i) const
fe4da5cc 468{
469 //
470 // Dumps particle i in the stack
471 //
2ab0c725 472 ((TParticle*) (*fParticleMap)[i])->Print();
fe4da5cc 473}
474
475//_____________________________________________________________________________
94de3818 476void AliRun::DumpPStack () const
fe4da5cc 477{
478 //
479 // Dumps the particle stack
480 //
2ab0c725 481 TObjArray &particles = *fParticleMap;
fe4da5cc 482 printf(
483 "\n\n=======================================================================\n");
484 for (Int_t i=0;i<fNtrack;i++)
485 {
1578254f 486 printf("-> %d ",i); ((TParticle*) particles[i])->Print();
fe4da5cc 487 printf("--------------------------------------------------------------\n");
488 }
489 printf(
490 "\n=======================================================================\n\n");
491}
492
d8408e76 493void AliRun::SetField(AliMagF* magField)
494{
495 // Set Magnetic Field Map
496 fField = magField;
497 fField->ReadField();
498}
499
fe4da5cc 500//_____________________________________________________________________________
501void AliRun::SetField(Int_t type, Int_t version, Float_t scale,
502 Float_t maxField, char* filename)
503{
504 //
505 // Set magnetic field parameters
506 // type Magnetic field transport flag 0=no field, 2=helix, 3=Runge Kutta
507 // version Magnetic field map version (only 1 active now)
508 // scale Scale factor for the magnetic field
509 // maxField Maximum value for the magnetic field
510
511 //
512 // --- Sanity check on mag field flags
fe4da5cc 513 if(fField) delete fField;
514 if(version==1) {
d8408e76 515 fField = new AliMagFC("Map1"," ",type,scale,maxField);
f1b9d7c3 516 } else if(version<=2) {
d8408e76 517 fField = new AliMagFCM("Map2-3",filename,type,scale,maxField);
fe4da5cc 518 fField->ReadField();
f1b9d7c3 519 } else if(version==3) {
d8408e76 520 fField = new AliMagFDM("Map4",filename,type,scale,maxField);
f1b9d7c3 521 fField->ReadField();
fe4da5cc 522 } else {
23370b7a 523 Warning("SetField","Invalid map %d\n",version);
fe4da5cc 524 }
525}
fe4da5cc 526
65fb704d 527//_____________________________________________________________________________
528void AliRun::PreTrack()
529{
530 TObjArray &dets = *fModules;
531 AliModule *module;
532
533 for(Int_t i=0; i<=fNdets; i++)
534 if((module = (AliModule*)dets[i]))
535 module->PreTrack();
536
537 fMCQA->PreTrack();
538}
539
540//_____________________________________________________________________________
541void AliRun::PostTrack()
542{
543 TObjArray &dets = *fModules;
544 AliModule *module;
545
546 for(Int_t i=0; i<=fNdets; i++)
547 if((module = (AliModule*)dets[i]))
548 module->PostTrack();
549}
550
fe4da5cc 551//_____________________________________________________________________________
552void AliRun::FinishPrimary()
553{
554 //
555 // Called at the end of each primary track
556 //
557
6c9704e6 558 // static Int_t count=0;
559 // const Int_t times=10;
fe4da5cc 560 // This primary is finished, purify stack
80762cb1 561 PurifyKine();
fe4da5cc 562
24de2263 563 TIter next(fModules);
564 AliModule *detector;
565 while((detector = (AliModule*)next())) {
566 detector->FinishPrimary();
567 }
568
fe4da5cc 569 // Write out hits if any
570 if (gAlice->TreeH()) {
571 gAlice->TreeH()->Fill();
572 }
573
574 // Reset Hits info
575 gAlice->ResetHits();
a8f1fb7c 576
577 //
578 // if(++count%times==1) gObjectTable->Print();
fe4da5cc 579}
580
581//_____________________________________________________________________________
582void AliRun::FinishEvent()
583{
584 //
585 // Called at the end of the event.
586 //
7fb01480 587
dffd31ef 588 //
589 if(fLego) fLego->FinishEvent();
590
fe4da5cc 591 //Update the energy deposit tables
592 Int_t i;
875c717b 593 for(i=0;i<fEventEnergy.GetSize();i++) {
594 fSummEnergy[i]+=fEventEnergy[i];
595 fSum2Energy[i]+=fEventEnergy[i]*fEventEnergy[i];
fe4da5cc 596 }
875c717b 597 fEventEnergy.Reset();
fe4da5cc 598
599 // Clean detector information
600 CleanDetectors();
601
602 // Write out the kinematics
603 if (fTreeK) {
604 CleanParents();
a41d61a9 605 if(fTreeK->GetEntries() ==0) {
606 // set the fParticleFileMap size for the first time
6781433e 607 if (fHgwmk+1 > fParticleFileMap.GetSize())
a41d61a9 608 fParticleFileMap.Set(fHgwmk+1);
609 }
610 // fTreeK->Fill();
89bbad6f 611 Bool_t allFilled = kFALSE;
2ab0c725 612 TObject *part;
613 for(i=0; i<fHgwmk+1; ++i) if((part=fParticleMap->At(i))) {
614 fParticleBuffer = (TParticle*) part;
615 fParticleFileMap[i]= (Int_t) fTreeK->GetEntries();
616 fTreeK->Fill();
89bbad6f 617 (*fParticleMap)[i]=0;
618
619 // When all primaries were filled no particle!=0
620 // should be left => to be removed later.
621 if (allFilled) printf("Why != 0 part # %d?\n",i);
622 }
623 else {
624 // // printf("Why = 0 part # %d?\n",i); => We know.
625 // break;
626 // we don't break now in order to be sure there is no
627 // particle !=0 left.
628 // To be removed later and replaced with break.
629 if(!allFilled) allFilled = kTRUE;
630 }
fe4da5cc 631 }
632
a41d61a9 633 // Set number of tracks to event header
634 fHeader.SetNtrack(fNtrack);
635
fe4da5cc 636 // Write out the digits
637 if (fTreeD) {
638 fTreeD->Fill();
639 ResetDigits();
640 }
2ab0c725 641
642 if (fTreeS) {
643 fTreeS->Fill();
644 ResetSDigits();
645 }
646
fe4da5cc 647 // Write out reconstructed clusters
648 if (fTreeR) {
649 fTreeR->Fill();
650 }
651
652 // Write out the event Header information
653 if (fTreeE) fTreeE->Fill();
654
655 // Reset stack info
656 ResetStack();
657
658 // Write Tree headers
51e0e89d 659 if (fTreeK) fTreeK->Write(0,TObject::kOverwrite);
51e0e89d 660 if (fTreeH) fTreeH->Write(0,TObject::kOverwrite);
51e0e89d 661 if (fTreeD) fTreeD->Write(0,TObject::kOverwrite);
51e0e89d 662 if (fTreeR) fTreeR->Write(0,TObject::kOverwrite);
2ab0c725 663 if (fTreeS) fTreeS->Write(0,TObject::kOverwrite);
664
875c717b 665 ++fEvent;
fe4da5cc 666}
667
668//_____________________________________________________________________________
669void AliRun::FinishRun()
670{
671 //
672 // Called at the end of the run.
673 //
674
dffd31ef 675 //
676 if(fLego) fLego->FinishRun();
677
fe4da5cc 678 // Clean detector information
8494b010 679 TIter next(fModules);
680 AliModule *detector;
681 while((detector = (AliModule*)next())) {
fe4da5cc 682 detector->FinishRun();
683 }
684
685 //Output energy summary tables
686 EnergySummary();
2ab0c725 687
688 TFile *file = fTreeE->GetCurrentFile();
689
aee8290b 690 file->cd();
2ab0c725 691
51e0e89d 692 fTreeE->Write(0,TObject::kOverwrite);
fe4da5cc 693
2ab0c725 694 // Write AliRun info and all detectors parameters
d47c658f 695 Write(0,TObject::kOverwrite);
2ab0c725 696
fe4da5cc 697 // Clean tree information
d2ecd553 698 if (fTreeK) {
699 delete fTreeK; fTreeK = 0;
700 }
701 if (fTreeH) {
702 delete fTreeH; fTreeH = 0;
703 }
704 if (fTreeD) {
705 delete fTreeD; fTreeD = 0;
706 }
707 if (fTreeR) {
708 delete fTreeR; fTreeR = 0;
709 }
710 if (fTreeE) {
711 delete fTreeE; fTreeE = 0;
712 }
2ab0c725 713
fe4da5cc 714 // Close output file
aee8290b 715 file->Write();
fe4da5cc 716}
717
718//_____________________________________________________________________________
719void AliRun::FlagTrack(Int_t track)
720{
721 //
722 // Flags a track and all its family tree to be kept
723 //
724 int curr;
1578254f 725 TParticle *particle;
fe4da5cc 726
727 curr=track;
728 while(1) {
2ab0c725 729 particle=(TParticle*)fParticleMap->At(curr);
fe4da5cc 730
731 // If the particle is flagged the three from here upward is saved already
aee8290b 732 if(particle->TestBit(kKeepBit)) return;
fe4da5cc 733
734 // Save this particle
aee8290b 735 particle->SetBit(kKeepBit);
fe4da5cc 736
737 // Move to father if any
1578254f 738 if((curr=particle->GetFirstMother())==-1) return;
fe4da5cc 739 }
740}
741
742//_____________________________________________________________________________
743void AliRun::EnergySummary()
744{
745 //
746 // Print summary of deposited energy
747 //
748
fe4da5cc 749 Int_t ndep=0;
750 Float_t edtot=0;
751 Float_t ed, ed2;
752 Int_t kn, i, left, j, id;
aee8290b 753 const Float_t kzero=0;
fe4da5cc 754 Int_t ievent=fHeader.GetEvent()+1;
755 //
756 // Energy loss information
757 if(ievent) {
758 printf("***************** Energy Loss Information per event (GEV) *****************\n");
875c717b 759 for(kn=1;kn<fEventEnergy.GetSize();kn++) {
760 ed=fSummEnergy[kn];
fe4da5cc 761 if(ed>0) {
875c717b 762 fEventEnergy[ndep]=kn;
fe4da5cc 763 if(ievent>1) {
764 ed=ed/ievent;
875c717b 765 ed2=fSum2Energy[kn];
fe4da5cc 766 ed2=ed2/ievent;
aee8290b 767 ed2=100*TMath::Sqrt(TMath::Max(ed2-ed*ed,kzero))/ed;
fe4da5cc 768 } else
769 ed2=99;
875c717b 770 fSummEnergy[ndep]=ed;
aee8290b 771 fSum2Energy[ndep]=TMath::Min((Float_t) 99.,TMath::Max(ed2,kzero));
fe4da5cc 772 edtot+=ed;
773 ndep++;
774 }
775 }
776 for(kn=0;kn<(ndep-1)/3+1;kn++) {
777 left=ndep-kn*3;
778 for(i=0;i<(3<left?3:left);i++) {
779 j=kn*3+i;
875c717b 780 id=Int_t (fEventEnergy[j]+0.1);
781 printf(" %s %10.3f +- %10.3f%%;",gMC->VolName(id),fSummEnergy[j],fSum2Energy[j]);
fe4da5cc 782 }
783 printf("\n");
784 }
785 //
786 // Relative energy loss in different detectors
787 printf("******************** Relative Energy Loss per event ********************\n");
788 printf("Total energy loss per event %10.3f GeV\n",edtot);
789 for(kn=0;kn<(ndep-1)/5+1;kn++) {
790 left=ndep-kn*5;
791 for(i=0;i<(5<left?5:left);i++) {
792 j=kn*5+i;
875c717b 793 id=Int_t (fEventEnergy[j]+0.1);
794 printf(" %s %10.3f%%;",gMC->VolName(id),100*fSummEnergy[j]/edtot);
fe4da5cc 795 }
796 printf("\n");
797 }
798 for(kn=0;kn<75;kn++) printf("*");
799 printf("\n");
800 }
801 //
802 // Reset the TArray's
875c717b 803 // fEventEnergy.Set(0);
804 // fSummEnergy.Set(0);
805 // fSum2Energy.Set(0);
fe4da5cc 806}
807
808//_____________________________________________________________________________
94de3818 809AliModule *AliRun::GetModule(const char *name) const
fe4da5cc 810{
811 //
812 // Return pointer to detector from name
813 //
8494b010 814 return (AliModule*)fModules->FindObject(name);
fe4da5cc 815}
816
a68348e9 817//_____________________________________________________________________________
94de3818 818AliDetector *AliRun::GetDetector(const char *name) const
a68348e9 819{
820 //
821 // Return pointer to detector from name
822 //
823 return (AliDetector*)fModules->FindObject(name);
824}
825
fe4da5cc 826//_____________________________________________________________________________
94de3818 827Int_t AliRun::GetModuleID(const char *name) const
fe4da5cc 828{
829 //
830 // Return galice internal detector identifier from name
831 //
23370b7a 832 Int_t i=-1;
833 TObject *mod=fModules->FindObject(name);
834 if(mod) i=fModules->IndexOf(mod);
835 return i;
fe4da5cc 836}
837
838//_____________________________________________________________________________
839Int_t AliRun::GetEvent(Int_t event)
840{
841 //
842 // Connect the Trees Kinematics and Hits for event # event
843 // Set branch addresses
844 //
fe4da5cc 845
846 // Reset existing structures
2ab0c725 847 // ResetStack();
fe4da5cc 848 ResetHits();
849 ResetDigits();
2ab0c725 850 ResetSDigits();
fe4da5cc 851
852 // Delete Trees already connected
853 if (fTreeK) delete fTreeK;
854 if (fTreeH) delete fTreeH;
855 if (fTreeD) delete fTreeD;
856 if (fTreeR) delete fTreeR;
2ab0c725 857 if (fTreeS) delete fTreeS;
59fe9bd2 858
859 // Get header from file
860 if(fTreeE) fTreeE->GetEntry(event);
861 else Error("GetEvent","Cannot file Header Tree\n");
2ab0c725 862 TFile *file = fTreeE->GetCurrentFile();
863
864 file->cd();
fe4da5cc 865
866 // Get Kine Tree from file
867 char treeName[20];
868 sprintf(treeName,"TreeK%d",event);
869 fTreeK = (TTree*)gDirectory->Get(treeName);
2ab0c725 870 if (fTreeK) fTreeK->SetBranchAddress("Particles", &fParticleBuffer);
23370b7a 871 else Error("GetEvent","cannot find Kine Tree for event:%d\n",event);
2ab0c725 872 // Create the particle stack
873 if(!fParticles) fParticles = new TClonesArray("TParticle",1000);
874 // Build the pointer list
875 if(fParticleMap) {
876 fParticleMap->Clear();
877 fParticleMap->Expand(fTreeK->GetEntries());
878 } else
879 fParticleMap = new TObjArray(fTreeK->GetEntries());
fe4da5cc 880
2ab0c725 881 file->cd();
882
fe4da5cc 883 // Get Hits Tree header from file
884 sprintf(treeName,"TreeH%d",event);
885 fTreeH = (TTree*)gDirectory->Get(treeName);
886 if (!fTreeH) {
23370b7a 887 Error("GetEvent","cannot find Hits Tree for event:%d\n",event);
fe4da5cc 888 }
889
2ab0c725 890 file->cd();
891
fe4da5cc 892 // Get Digits Tree header from file
893 sprintf(treeName,"TreeD%d",event);
894 fTreeD = (TTree*)gDirectory->Get(treeName);
895 if (!fTreeD) {
2ab0c725 896 // Warning("GetEvent","cannot find Digits Tree for event:%d\n",event);
fe4da5cc 897 }
82711e7a 898
899 file->cd();
900
901 // Get SDigits Tree header from file
902 sprintf(treeName,"TreeS%d",event);
903 fTreeS = (TTree*)gDirectory->Get(treeName);
904 if (!fTreeS) {
905 // Warning("GetEvent","cannot find SDigits Tree for event:%d\n",event);
906 }
907
2ab0c725 908 file->cd();
fe4da5cc 909
910 // Get Reconstruct Tree header from file
911 sprintf(treeName,"TreeR%d",event);
912 fTreeR = (TTree*)gDirectory->Get(treeName);
913 if (!fTreeR) {
914 // printf("WARNING: cannot find Reconstructed Tree for event:%d\n",event);
915 }
2ab0c725 916
917 file->cd();
fe4da5cc 918
919 // Set Trees branch addresses
8494b010 920 TIter next(fModules);
921 AliModule *detector;
922 while((detector = (AliModule*)next())) {
fe4da5cc 923 detector->SetTreeAddress();
924 }
925
2ab0c725 926 fNtrack = Int_t (fTreeK->GetEntries());
fe4da5cc 927 return fNtrack;
928}
929
930//_____________________________________________________________________________
931TGeometry *AliRun::GetGeometry()
932{
933 //
934 // Import Alice geometry from current file
935 // Return pointer to geometry object
936 //
937 if (!fGeometry) fGeometry = (TGeometry*)gDirectory->Get("AliceGeom");
938 //
939 // Unlink and relink nodes in detectors
940 // This is bad and there must be a better way...
941 //
fe4da5cc 942
8494b010 943 TIter next(fModules);
944 AliModule *detector;
945 while((detector = (AliModule*)next())) {
fe4da5cc 946 TList *dnodes=detector->Nodes();
947 Int_t j;
948 TNode *node, *node1;
949 for ( j=0; j<dnodes->GetSize(); j++) {
950 node = (TNode*) dnodes->At(j);
52d0ab00 951 node1 = fGeometry->GetNode(node->GetName());
fe4da5cc 952 dnodes->Remove(node);
953 dnodes->AddAt(node1,j);
954 }
955 }
956 return fGeometry;
957}
958
959//_____________________________________________________________________________
960void AliRun::GetNextTrack(Int_t &mtrack, Int_t &ipart, Float_t *pmom,
961 Float_t &e, Float_t *vpos, Float_t *polar,
962 Float_t &tof)
963{
964 //
965 // Return next track from stack of particles
966 //
a8f1fb7c 967 TVector3 pol;
fe4da5cc 968 fCurrent=-1;
1578254f 969 TParticle *track;
fe4da5cc 970 for(Int_t i=fNtrack-1; i>=0; i--) {
2ab0c725 971 track=(TParticle*) fParticleMap->At(i);
972 if(track) if(!track->TestBit(kDoneBit)) {
fe4da5cc 973 //
2ab0c725 974 // The track exists and has not yet been processed
fe4da5cc 975 fCurrent=i;
1578254f 976 ipart=track->GetPdgCode();
977 pmom[0]=track->Px();
978 pmom[1]=track->Py();
979 pmom[2]=track->Pz();
980 e =track->Energy();
981 vpos[0]=track->Vx();
982 vpos[1]=track->Vy();
983 vpos[2]=track->Vz();
a8f1fb7c 984 track->GetPolarisation(pol);
985 polar[0]=pol.X();
986 polar[1]=pol.Y();
987 polar[2]=pol.Z();
1578254f 988 tof=track->T();
aee8290b 989 track->SetBit(kDoneBit);
fe4da5cc 990 break;
991 }
992 }
993 mtrack=fCurrent;
994 //
995 // stop and start timer when we start a primary track
996 Int_t nprimaries = fHeader.GetNprimary();
997 if (fCurrent >= nprimaries) return;
998 if (fCurrent < nprimaries-1) {
999 fTimer.Stop();
2ab0c725 1000 track=(TParticle*) fParticleMap->At(fCurrent+1);
1578254f 1001 // track->SetProcessTime(fTimer.CpuTime());
fe4da5cc 1002 }
1003 fTimer.Start();
1004}
1005
1006//_____________________________________________________________________________
94de3818 1007Int_t AliRun::GetPrimary(Int_t track) const
fe4da5cc 1008{
1009 //
1010 // return number of primary that has generated track
1011 //
1012 int current, parent;
1578254f 1013 TParticle *part;
fe4da5cc 1014 //
1015 parent=track;
1016 while (1) {
1017 current=parent;
2ab0c725 1018 part = (TParticle *)fParticleMap->At(current);
1578254f 1019 parent=part->GetFirstMother();
fe4da5cc 1020 if(parent<0) return current;
1021 }
1022}
1023
1024//_____________________________________________________________________________
875c717b 1025void AliRun::InitMC(const char *setup)
fe4da5cc 1026{
1027 //
1028 // Initialize the Alice setup
1029 //
1030
51e0e89d 1031 if(fInitDone) {
1032 Warning("Init","Cannot initialise AliRun twice!\n");
1033 return;
1034 }
2ab0c725 1035
fe4da5cc 1036 gROOT->LoadMacro(setup);
45189757 1037 gInterpreter->ProcessLine(fConfigFunction.Data());
fe4da5cc 1038
2ab0c725 1039
cfce8870 1040 gMC->DefineParticles(); //Create standard MC particles
fe4da5cc 1041
1042 TObject *objfirst, *objlast;
1043
23370b7a 1044 fNdets = fModules->GetLast()+1;
1045
fe4da5cc 1046 //
875c717b 1047 //=================Create Materials and geometry
1048 gMC->Init();
1049
65fb704d 1050 // Added also after in case of interactive initialisation of modules
1051 fNdets = fModules->GetLast()+1;
1052
8494b010 1053 TIter next(fModules);
1054 AliModule *detector;
1055 while((detector = (AliModule*)next())) {
fe4da5cc 1056 detector->SetTreeAddress();
1057 objlast = gDirectory->GetList()->Last();
1058
fe4da5cc 1059 // Add Detector histograms in Detector list of histograms
1060 if (objlast) objfirst = gDirectory->GetList()->After(objlast);
1061 else objfirst = gDirectory->GetList()->First();
1062 while (objfirst) {
1063 detector->Histograms()->Add(objfirst);
1064 objfirst = gDirectory->GetList()->After(objfirst);
1065 }
1066 }
327136d2 1067 ReadTransPar(); //Read the cuts for all materials
fe4da5cc 1068
1069 MediaTable(); //Build the special IMEDIA table
1070
fe4da5cc 1071 //Initialise geometry deposition table
875c717b 1072 fEventEnergy.Set(gMC->NofVolumes()+1);
1073 fSummEnergy.Set(gMC->NofVolumes()+1);
1074 fSum2Energy.Set(gMC->NofVolumes()+1);
fe4da5cc 1075
fe4da5cc 1076 //Compute cross-sections
875c717b 1077 gMC->BuildPhysics();
fe4da5cc 1078
1079 //Write Geometry object to current file.
1080 fGeometry->Write();
1081
1082 fInitDone = kTRUE;
51e0e89d 1083
65fb704d 1084 fMCQA = new AliMCQA(fNdets);
1085
51e0e89d 1086 //
1087 // Save stuff at the beginning of the file to avoid file corruption
1088 Write();
fe4da5cc 1089}
1090
1091//_____________________________________________________________________________
1092void AliRun::MediaTable()
1093{
1094 //
1095 // Built media table to get from the media number to
1096 // the detector id
1097 //
ad51aeb0 1098 Int_t kz, nz, idt, lz, i, k, ind;
1099 // Int_t ibeg;
fe4da5cc 1100 TObjArray &dets = *gAlice->Detectors();
8494b010 1101 AliModule *det;
fe4da5cc 1102 //
1103 // For all detectors
1104 for (kz=0;kz<fNdets;kz++) {
1105 // If detector is defined
8494b010 1106 if((det=(AliModule*) dets[kz])) {
ad51aeb0 1107 TArrayI &idtmed = *(det->GetIdtmed());
1108 for(nz=0;nz<100;nz++) {
fe4da5cc 1109 // Find max and min material number
ad51aeb0 1110 if((idt=idtmed[nz])) {
fe4da5cc 1111 det->LoMedium() = det->LoMedium() < idt ? det->LoMedium() : idt;
1112 det->HiMedium() = det->HiMedium() > idt ? det->HiMedium() : idt;
1113 }
1114 }
1115 if(det->LoMedium() > det->HiMedium()) {
1116 det->LoMedium() = 0;
1117 det->HiMedium() = 0;
1118 } else {
1119 if(det->HiMedium() > fImedia->GetSize()) {
ad51aeb0 1120 Error("MediaTable","Increase fImedia from %d to %d",
1121 fImedia->GetSize(),det->HiMedium());
fe4da5cc 1122 return;
1123 }
1124 // Tag all materials in rage as belonging to detector kz
1125 for(lz=det->LoMedium(); lz<= det->HiMedium(); lz++) {
1126 (*fImedia)[lz]=kz;
1127 }
1128 }
1129 }
1130 }
1131 //
1132 // Print summary table
1133 printf(" Traking media ranges:\n");
1134 for(i=0;i<(fNdets-1)/6+1;i++) {
1135 for(k=0;k< (6<fNdets-i*6?6:fNdets-i*6);k++) {
1136 ind=i*6+k;
8494b010 1137 det=(AliModule*)dets[ind];
fe4da5cc 1138 if(det)
1139 printf(" %6s: %3d -> %3d;",det->GetName(),det->LoMedium(),
1140 det->HiMedium());
1141 else
1142 printf(" %6s: %3d -> %3d;","NULL",0,0);
1143 }
1144 printf("\n");
1145 }
1146}
1147
1148//____________________________________________________________________________
1149void AliRun::SetGenerator(AliGenerator *generator)
ee1dd322 1150{
1151 //
1152 // Load the event generator
1153 //
1154 if(!fGenerator) fGenerator = generator;
1155}
1156
1157//____________________________________________________________________________
1158void AliRun::ResetGenerator(AliGenerator *generator)
fe4da5cc 1159{
1160 //
1161 // Load the event generator
1162 //
b13db077 1163 if(fGenerator)
838edcaf 1164 if(generator)
1165 Warning("ResetGenerator","Replacing generator %s with %s\n",
1166 fGenerator->GetName(),generator->GetName());
1167 else
1168 Warning("ResetGenerator","Replacing generator %s with NULL\n",
1169 fGenerator->GetName());
b13db077 1170 fGenerator = generator;
fe4da5cc 1171}
1172
1173//____________________________________________________________________________
65fb704d 1174void AliRun::SetTransPar(char *filename)
1175{
1176 fTransParName = filename;
1177}
1178
2ab0c725 1179//____________________________________________________________________________
1180void AliRun::SetBaseFile(char *filename)
1181{
39de14fb 1182 fBaseFileName = filename;
2ab0c725 1183}
1184
65fb704d 1185//____________________________________________________________________________
1186void AliRun::ReadTransPar()
fe4da5cc 1187{
1188 //
1189 // Read filename to set the transport parameters
1190 //
1191
fe4da5cc 1192
aee8290b 1193 const Int_t kncuts=10;
1194 const Int_t knflags=11;
1195 const Int_t knpars=kncuts+knflags;
1196 const char kpars[knpars][7] = {"CUTGAM" ,"CUTELE","CUTNEU","CUTHAD","CUTMUO",
fe4da5cc 1197 "BCUTE","BCUTM","DCUTE","DCUTM","PPCUTM","ANNI",
1198 "BREM","COMP","DCAY","DRAY","HADR","LOSS",
1199 "MULS","PAIR","PHOT","RAYL"};
1200 char line[256];
ad51aeb0 1201 char detName[7];
fe4da5cc 1202 char* filtmp;
aee8290b 1203 Float_t cut[kncuts];
1204 Int_t flag[knflags];
fe4da5cc 1205 Int_t i, itmed, iret, ktmed, kz;
1206 FILE *lun;
1207 //
1208 // See whether the file is there
65fb704d 1209 filtmp=gSystem->ExpandPathName(fTransParName.Data());
fe4da5cc 1210 lun=fopen(filtmp,"r");
1211 delete [] filtmp;
1212 if(!lun) {
65fb704d 1213 Warning("ReadTransPar","File %s does not exist!\n",fTransParName.Data());
fe4da5cc 1214 return;
1215 }
1216 //
1217 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
1218 printf(" *%59s\n","*");
1219 printf(" * Please check carefully what you are doing!%10s\n","*");
1220 printf(" *%59s\n","*");
1221 //
1222 while(1) {
1223 // Initialise cuts and flags
aee8290b 1224 for(i=0;i<kncuts;i++) cut[i]=-99;
1225 for(i=0;i<knflags;i++) flag[i]=-99;
fe4da5cc 1226 itmed=0;
1227 for(i=0;i<256;i++) line[i]='\0';
1228 // Read up to the end of line excluded
1229 iret=fscanf(lun,"%[^\n]",line);
1230 if(iret<0) {
1231 //End of file
1232 fclose(lun);
1233 printf(" *%59s\n","*");
1234 printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
1235 return;
1236 }
1237 // Read the end of line
1238 fscanf(lun,"%*c");
1239 if(!iret) continue;
1240 if(line[0]=='*') continue;
1241 // Read the numbers
ad51aeb0 1242 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",
1243 detName,&itmed,&cut[0],&cut[1],&cut[2],&cut[3],&cut[4],&cut[5],&cut[6],&cut[7],&cut[8],
1244 &cut[9],&flag[0],&flag[1],&flag[2],&flag[3],&flag[4],&flag[5],&flag[6],&flag[7],
1245 &flag[8],&flag[9],&flag[10]);
fe4da5cc 1246 if(!iret) continue;
1247 if(iret<0) {
1248 //reading error
65fb704d 1249 Warning("ReadTransPar","Error reading file %s\n",fTransParName.Data());
fe4da5cc 1250 continue;
1251 }
ad51aeb0 1252 // Check that the module exist
1253 AliModule *mod = GetModule(detName);
1254 if(mod) {
1255 // Get the array of media numbers
1256 TArrayI &idtmed = *mod->GetIdtmed();
1257 // Check that the tracking medium code is valid
1258 if(0<=itmed && itmed < 100) {
1259 ktmed=idtmed[itmed];
1260 if(!ktmed) {
65fb704d 1261 Warning("ReadTransPar","Invalid tracking medium code %d for %s\n",itmed,mod->GetName());
ad51aeb0 1262 continue;
fe4da5cc 1263 }
ad51aeb0 1264 // Set energy thresholds
aee8290b 1265 for(kz=0;kz<kncuts;kz++) {
ad51aeb0 1266 if(cut[kz]>=0) {
23370b7a 1267 printf(" * %-6s set to %10.3E for tracking medium code %4d for %s\n",
aee8290b 1268 kpars[kz],cut[kz],itmed,mod->GetName());
1269 gMC->Gstpar(ktmed,kpars[kz],cut[kz]);
ad51aeb0 1270 }
fe4da5cc 1271 }
ad51aeb0 1272 // Set transport mechanisms
aee8290b 1273 for(kz=0;kz<knflags;kz++) {
ad51aeb0 1274 if(flag[kz]>=0) {
1275 printf(" * %-6s set to %10d for tracking medium code %4d for %s\n",
aee8290b 1276 kpars[kncuts+kz],flag[kz],itmed,mod->GetName());
1277 gMC->Gstpar(ktmed,kpars[kncuts+kz],Float_t(flag[kz]));
ad51aeb0 1278 }
1279 }
1280 } else {
65fb704d 1281 Warning("ReadTransPar","Invalid medium code %d *\n",itmed);
ad51aeb0 1282 continue;
fe4da5cc 1283 }
1284 } else {
65fb704d 1285 Warning("ReadTransPar","Module %s not present\n",detName);
fe4da5cc 1286 continue;
1287 }
1288 }
1289}
1290
1291//_____________________________________________________________________________
2ab0c725 1292void AliRun::MakeBranchInTree(TTree *tree, const char* name, void* address, Int_t size, char *file)
1293{
d47c658f 1294 //
1295 // Makes branch in given tree and diverts them to a separate file
1296 //
2ab0c725 1297 if (GetDebug()>1)
1298 printf("* MakeBranch * Making Branch %s \n",name);
1299
1300 TBranch *branch = tree->Branch(name,address,size);
1301
1302 if (file) {
39de14fb 1303 char * outFile = new char[strlen(gAlice->GetBaseFile())+strlen(file)+2];
1304 sprintf(outFile,"%s/%s",gAlice->GetBaseFile(),file);
2ab0c725 1305 TDirectory *cwd = gDirectory;
39de14fb 1306 branch->SetFile(outFile);
2ab0c725 1307 TIter next( branch->GetListOfBranches());
1308 while ((branch=(TBranch*)next())) {
39de14fb 1309 branch->SetFile(outFile);
2ab0c725 1310 }
1311 if (GetDebug()>1)
1312 printf("* MakeBranch * Diverting Branch %s to file %s\n",name,file);
1313 cwd->cd();
39de14fb 1314 delete outFile;
2ab0c725 1315 }
1316}
1317
1318//_____________________________________________________________________________
1319void AliRun::MakeBranchInTree(TTree *tree, const char* name, const char *classname, void* address, Int_t size, Int_t splitlevel, char *file)
1320{
d47c658f 1321 //
1322 // Makes branch in given tree and diverts them to a separate file
1323 //
2ab0c725 1324 TDirectory *cwd = gDirectory;
1325 TBranch *branch = tree->Branch(name,classname,address,size,splitlevel);
1326 if (GetDebug()>1)
1327 printf("* MakeBranch * Making Branch %s \n",name);
1328 if (file) {
39de14fb 1329 char * outFile = new char[strlen(gAlice->GetBaseFile())+strlen(file)+2];
1330 sprintf(outFile,"%s/%s",gAlice->GetBaseFile(),file);
1331 branch->SetFile(outFile);
2ab0c725 1332 TIter next( branch->GetListOfBranches());
1333 while ((branch=(TBranch*)next())) {
39de14fb 1334 branch->SetFile(outFile);
2ab0c725 1335 }
1336 if (GetDebug()>1)
1337 printf("* MakeBranch * Diverting Branch %s to file %s\n",name,file);
1338 cwd->cd();
39de14fb 1339 delete outFile;
2ab0c725 1340 }
1341}
1342//_____________________________________________________________________________
1343void AliRun::MakeTree(Option_t *option, char *file)
fe4da5cc 1344{
1345 //
1346 // Create the ROOT trees
1347 // Loop on all detectors to create the Root branch (if any)
1348 //
1349
b13db077 1350 char hname[30];
fe4da5cc 1351 //
1352 // Analyse options
5cf7bbad 1353 const char *oK = strstr(option,"K");
1354 const char *oH = strstr(option,"H");
1355 const char *oE = strstr(option,"E");
1356 const char *oD = strstr(option,"D");
1357 const char *oR = strstr(option,"R");
1358 const char *oS = strstr(option,"S");
fe4da5cc 1359 //
2ab0c725 1360
aee8290b 1361 if (oK && !fTreeK) {
b13db077 1362 sprintf(hname,"TreeK%d",fEvent);
1363 fTreeK = new TTree(hname,"Kinematics");
1364 // Create a branch for particles
2ab0c725 1365 MakeBranchInTree(fTreeK,
1366 "Particles", "TParticle", &fParticleBuffer, 4000, 1, file) ;
51e0e89d 1367 fTreeK->Write();
b13db077 1368 }
aee8290b 1369 if (oH && !fTreeH) {
b13db077 1370 sprintf(hname,"TreeH%d",fEvent);
1371 fTreeH = new TTree(hname,"Hits");
1372 fTreeH->SetAutoSave(1000000000); //no autosave
51e0e89d 1373 fTreeH->Write();
b13db077 1374 }
aee8290b 1375 if (oD && !fTreeD) {
b13db077 1376 sprintf(hname,"TreeD%d",fEvent);
1377 fTreeD = new TTree(hname,"Digits");
51e0e89d 1378 fTreeD->Write();
b13db077 1379 }
2ab0c725 1380 if (oS && !fTreeS) {
1381 sprintf(hname,"TreeS%d",fEvent);
1382 fTreeS = new TTree(hname,"SDigits");
1383 fTreeS->Write();
1384 }
aee8290b 1385 if (oR && !fTreeR) {
b13db077 1386 sprintf(hname,"TreeR%d",fEvent);
1387 fTreeR = new TTree(hname,"Reconstruction");
51e0e89d 1388 fTreeR->Write();
b13db077 1389 }
aee8290b 1390 if (oE && !fTreeE) {
b13db077 1391 fTreeE = new TTree("TE","Header");
1392 // Create a branch for Header
2ab0c725 1393 MakeBranchInTree(fTreeE,
1394 "Header", "AliHeader", &gAliHeader, 4000, 1, file) ;
51e0e89d 1395 fTreeE->Write();
b13db077 1396 }
2ab0c725 1397
fe4da5cc 1398 //
1399 // Create a branch for hits/digits for each detector
1400 // Each branch is a TClonesArray. Each data member of the Hits classes
1401 // will be in turn a subbranch of the detector master branch
8494b010 1402 TIter next(fModules);
1403 AliModule *detector;
1404 while((detector = (AliModule*)next())) {
d47c658f 1405 if (oH) detector->MakeBranch(option,file);
fe4da5cc 1406 }
fe4da5cc 1407}
1408
1409//_____________________________________________________________________________
1410Int_t AliRun::PurifyKine(Int_t lastSavedTrack, Int_t nofTracks)
1411{
1412 //
1413 // PurifyKine with external parameters
1414 //
1415 fHgwmk = lastSavedTrack;
1416 fNtrack = nofTracks;
1417 PurifyKine();
1418 return fHgwmk;
1419}
1420
2ab0c725 1421//_____________________________________________________________________________
1422TParticle* AliRun::Particle(Int_t i)
1423{
1424 if(!(*fParticleMap)[i]) {
1425 Int_t nentries = fParticles->GetEntries();
a41d61a9 1426
1427 // algorithmic way of getting entry index
1428 // (primary particles are filled after secondaries)
1429 Int_t entry;
1430 if (i<fHeader.GetNprimary())
1431 entry = i+fHeader.GetNsecondary();
1432 else
1433 entry = i-fHeader.GetNprimary();
1434
1435 // only check the algorithmic way and give
1436 // the fatal error if it is wrong
1437 if (entry != fParticleFileMap[i]) {
1438 Fatal("Particle",
1439 "!!!! The algorithmic way is WRONG: !!!\n entry: %d map: %d",
1440 entry, fParticleFileMap[i]);
1441 }
1442
2ab0c725 1443 fTreeK->GetEntry(fParticleFileMap[i]);
1444 new ((*fParticles)[nentries]) TParticle(*fParticleBuffer);
1445 fParticleMap->AddAt((*fParticles)[nentries],i);
1446 }
1447 return (TParticle *) (*fParticleMap)[i];
1448}
1449
fe4da5cc 1450//_____________________________________________________________________________
1451void AliRun::PurifyKine()
1452{
1453 //
1454 // Compress kinematic tree keeping only flagged particles
1455 // and renaming the particle id's in all the hits
1456 //
2ab0c725 1457 // TClonesArray &particles = *fParticles;
1458 TObjArray &particles = *fParticleMap;
fe4da5cc 1459 int nkeep=fHgwmk+1, parent, i;
2ab0c725 1460 TParticle *part, *father;
1461 TArrayI map(particles.GetLast()+1);
fe4da5cc 1462
1463 // Save in Header total number of tracks before compression
1464 fHeader.SetNtrack(fHeader.GetNtrack()+fNtrack-fHgwmk);
1465
2ab0c725 1466 // If no tracks generated return now
1467 if(fHgwmk+1 == fNtrack) return;
1468
1469 Int_t toshrink = fNtrack-fHgwmk-1;
1470
a01a8b12 1471 // First pass, invalid Daughter information
fe4da5cc 1472 for(i=0; i<fNtrack; i++) {
a01a8b12 1473 // Preset map, to be removed later
2ab0c725 1474 if(i<=fHgwmk) map[i]=i ;
1475 else {
1476 map[i] = -99;
1477 // particles.UncheckedAt(i)->ResetBit(kDaughtersBit);
1478 if((part=(TParticle*) particles.At(i))) part->ResetBit(kDaughtersBit);
1479 }
a01a8b12 1480 }
2ab0c725 1481 // Invalid daughter information for the parent of the first particle
1482 // generated. This may or may not be the current primary according to
1483 // whether decays have been recorded among the primaries
1484 part = (TParticle *)particles.At(fHgwmk+1);
1485 particles.At(part->GetFirstMother())->ResetBit(kDaughtersBit);
fe4da5cc 1486 // Second pass, build map between old and new numbering
1487 for(i=fHgwmk+1; i<fNtrack; i++) {
2ab0c725 1488 if(particles.At(i)->TestBit(kKeepBit)) {
fe4da5cc 1489
1490 // This particle has to be kept
1491 map[i]=nkeep;
2ab0c725 1492 // If old and new are different, have to move the pointer
1493 if(i!=nkeep) particles[nkeep]=particles.At(i);
1494 part = (TParticle*) particles.At(nkeep);
fe4da5cc 1495
1496 // as the parent is always *before*, it must be already
1497 // in place. This is what we are checking anyway!
2ab0c725 1498 if((parent=part->GetFirstMother())>fHgwmk)
1499 if(map[parent]==-99) Fatal("PurifyKine","map[%d] = -99!\n",parent);
1500 else part->SetFirstMother(map[parent]);
1501
fe4da5cc 1502 nkeep++;
1503 }
1504 }
fe4da5cc 1505
1578254f 1506 // Fix daughters information
2ab0c725 1507 for (i=fHgwmk+1; i<nkeep; i++) {
1508 part = (TParticle *)particles.At(i);
1578254f 1509 parent = part->GetFirstMother();
ae23d366 1510 if(parent>=0) {
2ab0c725 1511 father = (TParticle *)particles.At(parent);
aee8290b 1512 if(father->TestBit(kDaughtersBit)) {
fe4da5cc 1513
ae23d366 1514 if(i<father->GetFirstDaughter()) father->SetFirstDaughter(i);
1515 if(i>father->GetLastDaughter()) father->SetLastDaughter(i);
1516 } else {
2ab0c725 1517 // Initialise daughters info for first pass
ae23d366 1518 father->SetFirstDaughter(i);
1519 father->SetLastDaughter(i);
aee8290b 1520 father->SetBit(kDaughtersBit);
ae23d366 1521 }
fe4da5cc 1522 }
1523 }
1524
1cedd08a 1525 // Now loop on all registered hit lists
1526 TIter next(fHitLists);
1527 TCollection *hitList;
1528 while((hitList = (TCollection*)next())) {
1529 TIter nexthit(hitList);
1530 AliHit *hit;
1531 while((hit = (AliHit*)nexthit())) {
1532 hit->SetTrack(map[hit->GetTrack()]);
1533 }
1534 }
fe4da5cc 1535
24de2263 1536 //
1537 // This for detectors which have a special mapping mechanism
1538 // for hits, such as TPC and TRD
1539 //
1540
1541 TIter nextmod(fModules);
1542 AliModule *detector;
1543 while((detector = (AliModule*)nextmod())) {
2ab0c725 1544 detector->RemapTrackHitIDs(map.GetArray());
24de2263 1545 }
1546
2ab0c725 1547 // Now the output bit, from fHgwmk to nkeep we write everything and we erase
1548 if(nkeep>fParticleFileMap.GetSize()) fParticleFileMap.Set(Int_t (nkeep*1.5));
1549
24de2263 1550
2ab0c725 1551 for (i=fHgwmk+1; i<nkeep; ++i) {
1552 fParticleBuffer = (TParticle*) particles.At(i);
1553 fParticleFileMap[i]=(Int_t) fTreeK->GetEntries();
1554 fTreeK->Fill();
1555 particles[i]=0;
1556 }
1557
1558 for (i=nkeep; i<fNtrack; ++i) particles[i]=0;
1559
1560 fLoadPoint-=toshrink;
1561 for(i=fLoadPoint; i<fLoadPoint+toshrink; ++i) fParticles->RemoveAt(i);
1562
1563 fNtrack=nkeep;
1564 fHgwmk=nkeep-1;
1565 // delete [] map;
fe4da5cc 1566}
1567
1568//_____________________________________________________________________________
dffd31ef 1569void AliRun::BeginEvent()
fe4da5cc 1570{
1571 //
1572 // Reset all Detectors & kinematics & trees
1573 //
59fe9bd2 1574 char hname[30];
dffd31ef 1575 //
1576
1577 //
1578 if(fLego) {
1579 fLego->BeginEvent();
1580 return;
1581 }
1582
59fe9bd2 1583 //
fe4da5cc 1584 ResetStack();
1585 ResetHits();
1586 ResetDigits();
2ab0c725 1587 ResetSDigits();
fe4da5cc 1588
1589 // Initialise event header
875c717b 1590 fHeader.Reset(fRun,fEvent);
fe4da5cc 1591
59fe9bd2 1592 if(fTreeK) {
1593 fTreeK->Reset();
875c717b 1594 sprintf(hname,"TreeK%d",fEvent);
59fe9bd2 1595 fTreeK->SetName(hname);
1596 }
1597 if(fTreeH) {
1598 fTreeH->Reset();
875c717b 1599 sprintf(hname,"TreeH%d",fEvent);
59fe9bd2 1600 fTreeH->SetName(hname);
1601 }
1602 if(fTreeD) {
1603 fTreeD->Reset();
875c717b 1604 sprintf(hname,"TreeD%d",fEvent);
59fe9bd2 1605 fTreeD->SetName(hname);
1606 }
2ab0c725 1607 if(fTreeS) {
1608 fTreeS->Reset();
1609 sprintf(hname,"TreeS%d",fEvent);
1610 fTreeS->SetName(hname);
1611 }
59fe9bd2 1612 if(fTreeR) {
1613 fTreeR->Reset();
875c717b 1614 sprintf(hname,"TreeR%d",fEvent);
59fe9bd2 1615 fTreeR->SetName(hname);
1616 }
fe4da5cc 1617}
fe4da5cc 1618//_____________________________________________________________________________
1619void AliRun::ResetDigits()
1620{
1621 //
1622 // Reset all Detectors digits
1623 //
8494b010 1624 TIter next(fModules);
1625 AliModule *detector;
1626 while((detector = (AliModule*)next())) {
fe4da5cc 1627 detector->ResetDigits();
1628 }
1629}
1630
2ab0c725 1631//_____________________________________________________________________________
1632void AliRun::ResetSDigits()
1633{
1634 //
1635 // Reset all Detectors digits
1636 //
1637 TIter next(fModules);
1638 AliModule *detector;
1639 while((detector = (AliModule*)next())) {
1640 detector->ResetSDigits();
1641 }
1642}
1643
fe4da5cc 1644//_____________________________________________________________________________
1645void AliRun::ResetHits()
1646{
1647 //
1648 // Reset all Detectors hits
1649 //
8494b010 1650 TIter next(fModules);
1651 AliModule *detector;
1652 while((detector = (AliModule*)next())) {
fe4da5cc 1653 detector->ResetHits();
1654 }
1655}
1656
1657//_____________________________________________________________________________
1658void AliRun::ResetPoints()
1659{
1660 //
1661 // Reset all Detectors points
1662 //
8494b010 1663 TIter next(fModules);
1664 AliModule *detector;
1665 while((detector = (AliModule*)next())) {
fe4da5cc 1666 detector->ResetPoints();
1667 }
1668}
1669
1670//_____________________________________________________________________________
875c717b 1671void AliRun::RunMC(Int_t nevent, const char *setup)
fe4da5cc 1672{
1673 //
1674 // Main function to be called to process a galice run
1675 // example
1676 // Root > gAlice.Run();
1677 // a positive number of events will cause the finish routine
1678 // to be called
1679 //
1680
fe4da5cc 1681 // check if initialisation has been done
875c717b 1682 if (!fInitDone) InitMC(setup);
fe4da5cc 1683
fe4da5cc 1684 // Create the Root Tree with one branch per detector
2ab0c725 1685
d47c658f 1686 MakeTree("ESD");
1687
2ab0c725 1688 if (gSystem->Getenv("CONFIG_SPLIT_FILE")) {
39de14fb 1689 MakeTree("K","Kine.root");
1690 MakeTree("H","Hits.root");
2ab0c725 1691 } else {
d47c658f 1692 MakeTree("KH");
2ab0c725 1693 }
fe4da5cc 1694
875c717b 1695 gMC->ProcessRun(nevent);
1696
fe4da5cc 1697 // End of this run, close files
80762cb1 1698 if(nevent>0) FinishRun();
fe4da5cc 1699}
1700
d47c658f 1701//_____________________________________________________________________________
1702void AliRun::RunReco(const char *detector)
1703{
1704 //
1705 // Main function to be called to reconstruct Alice event
1706 //
1707
1708 MakeTree("R");
1709 Digits2Reco(detector);
1710}
1711
2ab0c725 1712//_____________________________________________________________________________
1713
1714void AliRun::Hits2Digits(const char *selected)
1715{
d47c658f 1716 // Convert Hits to sumable digits
1717 //
2ab0c725 1718 Hits2SDigits(selected);
1719 SDigits2Digits(selected);
1720}
1721
d47c658f 1722
2ab0c725 1723//_____________________________________________________________________________
1724
d47c658f 1725void AliRun::Tree2Tree(Option_t *option, const char *selected)
2ab0c725 1726{
1727 //
d47c658f 1728 // Function to transform the content of
1729 //
1730 // - TreeH to TreeS (option "S")
1731 // - TreeS to TreeD (option "D")
1732 // - TreeD to TreeR (option "R")
1733 //
1734 // If multiple options are specified ("SDR"), transformation will be done in sequence for
1735 // selected detector and for all detectors if none is selected (detector string
1736 // can contain blank separated list of detector names).
2ab0c725 1737
2ab0c725 1738
5cf7bbad 1739 const char *oS = strstr(option,"S");
1740 const char *oD = strstr(option,"D");
1741 const char *oR = strstr(option,"R");
2ab0c725 1742
2ab0c725 1743 gAlice->GetEvent(0);
1744
1745 TObjArray *detectors = gAlice->Detectors();
1746
1747 TIter next(detectors);
1748
d47c658f 1749 AliDetector *detector = 0;
2ab0c725 1750
1751 TDirectory *cwd = gDirectory;
1752
d47c658f 1753 char outFile[32];
2ab0c725 1754
1755 while((detector = (AliDetector*)next())) {
d47c658f 1756 if (selected)
2ab0c725 1757 if (strcmp(detector->GetName(),selected)) continue;
2ab0c725 1758 if (detector->IsActive()){
d47c658f 1759 if (GetDebug()>0)
2ab0c725 1760 cout << "Processing " << detector->GetName() << "..." << endl;
d47c658f 1761 if (gSystem->Getenv("CONFIG_SPLIT_FILE")) {
1762 if (oS) {
1763 sprintf(outFile,"SDigits.%s.root",detector->GetName());
1764 detector->MakeBranch("S",outFile);
1765 }
1766 if (oD) {
1767 sprintf(outFile,"Digits.%s.root",detector->GetName());
1768 detector->MakeBranch("D",outFile);
1769 }
1770 if (oR) {
1771 sprintf(outFile,"Reco.%s.root",detector->GetName());
1772 detector->MakeBranch("R",outFile);
1773 }
2ab0c725 1774 } else {
d47c658f 1775 detector->MakeBranch(option);
1776 }
1777
1778 cwd->cd();
1779
1780 if (oS)
1781 detector->Hits2SDigits();
1782 if (oD)
1783 detector->SDigits2Digits();
1784 if (oR)
1785 detector->Digits2Reco();
1786
1787 cwd->cd();
1788
2ab0c725 1789 }
1790 }
1791}
1792
d47c658f 1793
fe4da5cc 1794//_____________________________________________________________________________
0a520a66 1795void AliRun::RunLego(const char *setup, Int_t nc1, Float_t c1min,
1796 Float_t c1max,Int_t nc2,Float_t c2min,Float_t c2max,
1797 Float_t rmin,Float_t rmax,Float_t zmax, AliLegoGenerator* gener)
fe4da5cc 1798{
1799 //
1800 // Generates lego plots of:
1801 // - radiation length map phi vs theta
1802 // - radiation length map phi vs eta
1803 // - interaction length map
1804 // - g/cm2 length map
1805 //
1806 // ntheta bins in theta, eta
1807 // themin minimum angle in theta (degrees)
1808 // themax maximum angle in theta (degrees)
1809 // nphi bins in phi
1810 // phimin minimum angle in phi (degrees)
1811 // phimax maximum angle in phi (degrees)
1812 // rmin minimum radius
1813 // rmax maximum radius
1814 //
1815 //
1816 // The number of events generated = ntheta*nphi
1817 // run input parameters in macro setup (default="Config.C")
1818 //
1819 // Use macro "lego.C" to visualize the 3 lego plots in spherical coordinates
1820 //Begin_Html
1821 /*
1439f98e 1822 <img src="picts/AliRunLego1.gif">
fe4da5cc 1823 */
1824 //End_Html
1825 //Begin_Html
1826 /*
1439f98e 1827 <img src="picts/AliRunLego2.gif">
fe4da5cc 1828 */
1829 //End_Html
1830 //Begin_Html
1831 /*
1439f98e 1832 <img src="picts/AliRunLego3.gif">
fe4da5cc 1833 */
1834 //End_Html
1835 //
1836
1837 // check if initialisation has been done
875c717b 1838 if (!fInitDone) InitMC(setup);
838edcaf 1839 //Save current generator
1840 AliGenerator *gen=Generator();
1841
0a520a66 1842 // Set new generator
1843 if (!gener) gener = new AliLegoGenerator();
1844 ResetGenerator(gener);
1845 //
1846 // Configure Generator
1847 gener->SetRadiusRange(rmin, rmax);
1848 gener->SetZMax(zmax);
1849 gener->SetCoor1Range(nc1, c1min, c1max);
1850 gener->SetCoor2Range(nc2, c2min, c2max);
1851
1852
b13db077 1853 //Create Lego object
0a520a66 1854 fLego = new AliLego("lego",gener);
b13db077 1855
dffd31ef 1856 //Prepare MC for Lego Run
1857 gMC->InitLego();
1858
b13db077 1859 //Run Lego Object
0a520a66 1860
1861 gMC->ProcessRun(nc1*nc2+1);
fe4da5cc 1862
1863 // Create only the Root event Tree
80762cb1 1864 MakeTree("E");
fe4da5cc 1865
1866 // End of this run, close files
80762cb1 1867 FinishRun();
0a520a66 1868 // Restore current generator
1869 ResetGenerator(gen);
838edcaf 1870 // Delete Lego Object
1871 delete fLego; fLego=0;
fe4da5cc 1872}
1873
94de3818 1874//_____________________________________________________________________________
1875void AliRun::SetConfigFunction(const char * config)
1876{
1877 //
1878 // Set the signature of the function contained in Config.C to configure
1879 // the run
1880 //
1881 fConfigFunction=config;
1882}
1883
fe4da5cc 1884//_____________________________________________________________________________
1885void AliRun::SetCurrentTrack(Int_t track)
1886{
1887 //
1888 // Set current track number
1889 //
1890 fCurrent = track;
1891}
1892
1893//_____________________________________________________________________________
1578254f 1894void AliRun::SetTrack(Int_t done, Int_t parent, Int_t pdg, Float_t *pmom,
fe4da5cc 1895 Float_t *vpos, Float_t *polar, Float_t tof,
65fb704d 1896 AliMCProcess mech, Int_t &ntr, Float_t weight)
fe4da5cc 1897{
1898 //
1899 // Load a track on the stack
1900 //
1901 // done 0 if the track has to be transported
1902 // 1 if not
1903 // parent identifier of the parent track. -1 for a primary
1578254f 1904 // pdg particle code
fe4da5cc 1905 // pmom momentum GeV/c
1906 // vpos position
1907 // polar polarisation
1908 // tof time of flight in seconds
1909 // mecha production mechanism
1910 // ntr on output the number of the track stored
1911 //
1912 TClonesArray &particles = *fParticles;
1578254f 1913 TParticle *particle;
fe4da5cc 1914 Float_t mass;
aee8290b 1915 const Int_t kfirstdaughter=-1;
1916 const Int_t klastdaughter=-1;
1917 const Int_t kS=0;
1578254f 1918 // const Float_t tlife=0;
fe4da5cc 1919
1578254f 1920 //
1921 // Here we get the static mass
1922 // For MC is ok, but a more sophisticated method could be necessary
1923 // if the calculated mass is required
1924 // also, this method is potentially dangerous if the mass
1925 // used in the MC is not the same of the PDG database
1926 //
1927 mass = TDatabasePDG::Instance()->GetParticle(pdg)->Mass();
fe4da5cc 1928 Float_t e=TMath::Sqrt(mass*mass+pmom[0]*pmom[0]+
1929 pmom[1]*pmom[1]+pmom[2]*pmom[2]);
1930
aee8290b 1931 //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",
1932 //pname,mass,e,fNtrack,pdg,vpos[0],vpos[1],vpos[2],pmom[0],pmom[1],pmom[2],kS,mecha);
2ab0c725 1933
1934 particle=new(particles[fLoadPoint++]) TParticle(pdg,kS,parent,-1,kfirstdaughter,
aee8290b 1935 klastdaughter,pmom[0],pmom[1],pmom[2],
1578254f 1936 e,vpos[0],vpos[1],vpos[2],tof);
2ab0c725 1937 particle->SetPolarisation(TVector3(polar[0],polar[1],polar[2]));
1938 particle->SetWeight(weight);
65fb704d 1939 particle->SetUniqueID(mech);
aee8290b 1940 if(!done) particle->SetBit(kDoneBit);
2ab0c725 1941 // Declare that the daughter information is valid
1942 particle->SetBit(kDaughtersBit);
1943 // Add the particle to the stack
1944 fParticleMap->AddAtAndExpand(particle,fNtrack);
1945
fe4da5cc 1946 if(parent>=0) {
2ab0c725 1947 particle=(TParticle*) fParticleMap->At(parent);
1578254f 1948 particle->SetLastDaughter(fNtrack);
1949 if(particle->GetFirstDaughter()<0) particle->SetFirstDaughter(fNtrack);
fe4da5cc 1950 } else {
1951 //
1952 // This is a primary track. Set high water mark for this event
1953 fHgwmk=fNtrack;
1954 //
1955 // Set also number if primary tracks
1956 fHeader.SetNprimary(fHgwmk+1);
1957 fHeader.SetNtrack(fHgwmk+1);
1958 }
1959 ntr = fNtrack++;
89bbad6f 1960
1961/*
1962 //
1963 // Here we get the static mass
1964 // For MC is ok, but a more sophisticated method could be necessary
1965 // if the calculated mass is required
1966 // also, this method is potentially dangerous if the mass
1967 // used in the MC is not the same of the PDG database
1968 //
1969 Float_t mass = TDatabasePDG::Instance()->GetParticle(pdg)->Mass();
1970 Float_t e=TMath::Sqrt(mass*mass+pmom[0]*pmom[0]+
1971 pmom[1]*pmom[1]+pmom[2]*pmom[2]);
1972
1973 SetTrack(done, parent, pdg, pmom[0], pmom[1], pmom[2], e,
1974 vpos[0], vpos[1], vpos[2], tof, polar[0],polar[1],polar[2],
1975 mech, ntr, weight);
1976*/
fe4da5cc 1977}
1978
89bbad6f 1979//_____________________________________________________________________________
1980void AliRun::SetTrack(Int_t done, Int_t parent, Int_t pdg,
1981 Double_t px, Double_t py, Double_t pz, Double_t e,
1982 Double_t vx, Double_t vy, Double_t vz, Double_t tof,
1983 Double_t polx, Double_t poly, Double_t polz,
1d994b80 1984 AliMCProcess mech, Int_t &ntr, Float_t weight)
89bbad6f 1985{
1986 //
1987 // Load a track on the stack
1988 //
1989 // done 0 if the track has to be transported
1990 // 1 if not
1991 // parent identifier of the parent track. -1 for a primary
1992 // pdg particle code
1993 // kS generation status code
1994 // px, py, pz momentum GeV/c
1995 // vx, vy, vz position
1996 // polar polarisation
1997 // tof time of flight in seconds
1998 // mech production mechanism
1999 // ntr on output the number of the track stored
2000 //
2001 // New method interface:
2002 // arguments were changed to be in correspondence with TParticle
2003 // constructor.
2004 // Note: the energy is not calculated from the static mass but
2005 // it is passed by argument e.
2006
2007 TClonesArray &particles = *fParticles;
2008
2009 const Int_t kS=0;
2010 const Int_t kFirstDaughter=-1;
2011 const Int_t kLastDaughter=-1;
2012
2013 TParticle* particle
2014 = new(particles[fLoadPoint++]) TParticle(pdg, kS, parent, -1,
2015 kFirstDaughter, kLastDaughter,
2016 px, py, pz, e, vx, vy, vz, tof);
2017
2018 particle->SetPolarisation(polx, poly, polz);
2019 particle->SetWeight(weight);
2020 particle->SetUniqueID(mech);
2021
2022 if(!done) particle->SetBit(kDoneBit);
2023
2024 // Declare that the daughter information is valid
2025 particle->SetBit(kDaughtersBit);
2026 // Add the particle to the stack
2027 fParticleMap->AddAtAndExpand(particle,fNtrack);
2028
2029 if(parent>=0) {
2030 particle=(TParticle*) fParticleMap->At(parent);
2031 particle->SetLastDaughter(fNtrack);
2032 if(particle->GetFirstDaughter()<0) particle->SetFirstDaughter(fNtrack);
2033 } else {
2034 //
2035 // This is a primary track. Set high water mark for this event
2036 fHgwmk=fNtrack;
2037 //
2038 // Set also number if primary tracks
2039 fHeader.SetNprimary(fHgwmk+1);
2040 fHeader.SetNtrack(fHgwmk+1);
2041 }
2042 ntr = fNtrack++;
2043}
2044
2045//_____________________________________________________________________________
4d69d91e 2046void AliRun::SetHighWaterMark(const Int_t nt)
2047{
2048 //
2049 // Set high water mark for last track in event
2050 fHgwmk=fNtrack-1;
2051 //
2052 // Set also number if primary tracks
2053 fHeader.SetNprimary(fHgwmk+1);
2054 fHeader.SetNtrack(fHgwmk+1);
2055}
2056
fe4da5cc 2057//_____________________________________________________________________________
2058void AliRun::KeepTrack(const Int_t track)
2059{
2060 //
2061 // flags a track to be kept
2062 //
2ab0c725 2063 fParticleMap->At(track)->SetBit(kKeepBit);
fe4da5cc 2064}
2065
2066//_____________________________________________________________________________
875c717b 2067void AliRun::StepManager(Int_t id)
fe4da5cc 2068{
2069 //
2070 // Called at every step during transport
2071 //
2072
fe4da5cc 2073 //
2074 // --- If lego option, do it and leave
b13db077 2075 if (fLego)
fe4da5cc 2076 fLego->StepManager();
b13db077 2077 else {
2078 Int_t copy;
2079 //Update energy deposition tables
875c717b 2080 AddEnergyDeposit(gMC->CurrentVolID(copy),gMC->Edep());
fe4da5cc 2081
b13db077 2082 //Call the appropriate stepping routine;
2083 AliModule *det = (AliModule*)fModules->At(id);
65fb704d 2084 if(det) {
2085 fMCQA->StepManager(id);
2086 det->StepManager();
2087 }
fe4da5cc 2088 }
fe4da5cc 2089}
2090
fe4da5cc 2091//_____________________________________________________________________________
2092void AliRun::Streamer(TBuffer &R__b)
2093{
2ab0c725 2094 // Stream an object of class AliRun.
2095
2096 if (R__b.IsReading()) {
2097 if (!gAlice) gAlice = this;
2098
2099 AliRun::Class()->ReadBuffer(R__b, this);
2100 //
2101 gROOT->GetListOfBrowsables()->Add(this,"Run");
2102
2103 fTreeE = (TTree*)gDirectory->Get("TE");
2104 if (fTreeE) fTreeE->SetBranchAddress("Header", &gAliHeader);
2105 else Error("Streamer","cannot find Header Tree\n");
59fe9bd2 2106 fTreeE->GetEntry(0);
2ab0c725 2107
65fb704d 2108 gRandom = fRandom;
2ab0c725 2109 } else {
2110 AliRun::Class()->WriteBuffer(R__b, this);
2111 }
2112}
2113