1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 // This class is extracted from the AliRun class
19 // and contains all the MC-related functionality
20 // The number of dependencies has to be reduced...
21 // Author: F.Carminati
22 // Federico.Carminati@cern.ch
26 #include <TClonesArray.h>
27 #include <TGeoManager.h>
28 #include <TStopwatch.h>
30 #include <TVirtualMC.h>
33 #include "AliDetector.h"
34 #include "AliGenerator.h"
35 #include "AliHeader.h"
42 #include "AliTrackReference.h"
43 #include "AliSimulation.h"
48 //_______________________________________________________________________
70 //_______________________________________________________________________
71 AliMC::AliMC(const char *name, const char *title) :
72 TVirtualMCApplication(name, title),
82 fImedia(new TArrayI(1000)),
85 fHitLists(new TList()),
86 fTrackReferences(new TClonesArray("AliTrackReference", 100))
89 // Set transport parameters
92 // Prepare the tracking medium lists
93 for(Int_t i=0;i<1000;i++) (*fImedia)[i]=-99;
96 //_______________________________________________________________________
97 AliMC::AliMC(const AliMC &mc) :
98 TVirtualMCApplication(mc),
115 // Copy constructor for AliMC
120 //_______________________________________________________________________
128 // Delete track references
129 if (fTrackReferences) {
130 fTrackReferences->Delete();
131 delete fTrackReferences;
132 fTrackReferences = 0;
137 //_______________________________________________________________________
138 void AliMC::Copy(TObject &) const
140 //dummy Copy function
141 AliFatal("Not implemented!");
144 //_______________________________________________________________________
145 void AliMC::ConstructGeometry()
148 // Either load geometry from file or create it through usual
149 // loop on detectors. In the first case the method
150 // AliModule::CreateMaterials() only builds fIdtmed and is postponed
151 // at InitGeometry().
154 if(gAlice->IsRootGeometry()){
156 const char *geomfilename = gAlice->GetGeometryFileName();
157 if(gSystem->ExpandPathName(geomfilename)){
158 AliInfo(Form("Loading geometry from file:\n %40s\n\n",geomfilename));
159 TGeoManager::Import(geomfilename);
161 AliInfo(Form("Geometry file %40s not found!\n",geomfilename));
165 // Create modules, materials, geometry
167 TIter next(gAlice->Modules());
169 AliDebug(1, "Geometry creation:");
170 while((detector = dynamic_cast<AliModule*>(next()))) {
172 // Initialise detector materials and geometry
173 detector->CreateMaterials();
174 detector->CreateGeometry();
175 AliInfo(Form("%10s R:%.2fs C:%.2fs",
176 detector->GetName(),stw.RealTime(),stw.CpuTime()));
182 //_______________________________________________________________________
183 Bool_t AliMC::MisalignGeometry()
185 // Call misalignment code if AliSimulation object was defined.
186 if (!AliSimulation::GetInstance()) return kFALSE;
187 return AliSimulation::GetInstance()->MisalignGeometry(gAlice->GetRunLoader());
190 //_______________________________________________________________________
191 void AliMC::ConstructOpGeometry()
194 // Loop all detector modules and call DefineOpticalProperties() method
197 TIter next(gAlice->Modules());
199 AliInfo("Optical properties definition");
200 while((detector = dynamic_cast<AliModule*>(next()))) {
201 // Initialise detector optical properties
202 detector->DefineOpticalProperties();
206 //_______________________________________________________________________
207 void AliMC::InitGeometry()
210 // Initialize detectors
213 AliInfo("Initialisation:");
215 TIter next(gAlice->Modules());
217 while((detector = dynamic_cast<AliModule*>(next()))) {
219 // Initialise detector geometry
220 if(gAlice->IsRootGeometry()) detector->CreateMaterials();
222 AliInfo(Form("%10s R:%.2fs C:%.2fs",
223 detector->GetName(),stw.RealTime(),stw.CpuTime()));
227 //_______________________________________________________________________
228 void AliMC::SetAllAlignableVolumes()
231 // Add alignable volumes (TGeoPNEntries) looping on all
235 AliInfo(Form("Setting entries for all alignable volumes of active detectors"));
237 TIter next(gAlice->Modules());
238 while((detector = dynamic_cast<AliModule*>(next()))) {
239 detector->AddAlignableVolumes();
243 //_______________________________________________________________________
244 void AliMC::GeneratePrimaries()
247 // Generate primary particles and fill them in the stack.
250 Generator()->Generate();
253 //_______________________________________________________________________
254 void AliMC::SetGenerator(AliGenerator *generator)
257 // Load the event generator
259 if(!fGenerator) fGenerator = generator;
262 //_______________________________________________________________________
263 void AliMC::ResetGenerator(AliGenerator *generator)
266 // Load the event generator
270 AliWarning(Form("Replacing generator %s with %s",
271 fGenerator->GetName(),generator->GetName()));
274 AliWarning(Form("Replacing generator %s with NULL",
275 fGenerator->GetName()));
278 fGenerator = generator;
281 //_______________________________________________________________________
282 void AliMC::FinishRun()
284 // Clean generator information
285 AliDebug(1, "fGenerator->FinishRun()");
286 fGenerator->FinishRun();
288 //Output energy summary tables
289 AliDebug(1, "EnergySummary()");
290 ToAliDebug(1, EnergySummary());
293 //_______________________________________________________________________
294 void AliMC::BeginPrimary()
297 // Called at the beginning of each primary track
302 ResetTrackReferences();
306 //_______________________________________________________________________
307 void AliMC::PreTrack()
309 // Actions before the track's transport
310 TObjArray &dets = *gAlice->Modules();
313 for(Int_t i=0; i<=gAlice->GetNdets(); i++)
314 if((module = dynamic_cast<AliModule*>(dets[i])))
320 //_______________________________________________________________________
321 void AliMC::Stepping()
324 // Called at every step during transport
327 Int_t id = DetFromMate(gMC->CurrentMedium());
331 if ( gMC->IsNewTrack() &&
332 gMC->TrackTime() == 0. &&
334 fRDecayMax > fRDecayMin &&
335 gMC->TrackPid() == fDecayPdg )
337 FixParticleDecaytime();
343 // --- If lego option, do it and leave
345 gAlice->Lego()->StepManager();
348 //Update energy deposition tables
349 AddEnergyDeposit(gMC->CurrentVolID(copy),gMC->Edep());
351 // write tracke reference for track which is dissapearing - MI
352 if (gMC->IsTrackDisappeared()) {
353 if (gMC->Etot()>0.05) AddTrackReference(GetCurrentTrackNumber());
356 //Call the appropriate stepping routine;
357 AliModule *det = dynamic_cast<AliModule*>(gAlice->Modules()->At(id));
358 if(det && det->StepManagerIsEnabled()) {
359 if(AliLog::GetGlobalDebugLevel()>0) fMCQA->StepManager(id);
365 //_______________________________________________________________________
366 void AliMC::EnergySummary()
369 // Print summary of deposited energy
375 Int_t kn, i, left, j, id;
376 const Float_t kzero=0;
377 Int_t ievent=gAlice->GetRunLoader()->GetHeader()->GetEvent()+1;
379 // Energy loss information
381 printf("***************** Energy Loss Information per event (GEV) *****************\n");
382 for(kn=1;kn<fEventEnergy.GetSize();kn++) {
385 fEventEnergy[ndep]=kn;
390 ed2=100*TMath::Sqrt(TMath::Max(ed2-ed*ed,kzero))/ed;
393 fSummEnergy[ndep]=ed;
394 fSum2Energy[ndep]=TMath::Min(static_cast<Float_t>(99.),TMath::Max(ed2,kzero));
399 for(kn=0;kn<(ndep-1)/3+1;kn++) {
401 for(i=0;i<(3<left?3:left);i++) {
403 id=Int_t (fEventEnergy[j]+0.1);
404 printf(" %s %10.3f +- %10.3f%%;",gMC->VolName(id),fSummEnergy[j],fSum2Energy[j]);
409 // Relative energy loss in different detectors
410 printf("******************** Relative Energy Loss per event ********************\n");
411 printf("Total energy loss per event %10.3f GeV\n",edtot);
412 for(kn=0;kn<(ndep-1)/5+1;kn++) {
414 for(i=0;i<(5<left?5:left);i++) {
416 id=Int_t (fEventEnergy[j]+0.1);
417 printf(" %s %10.3f%%;",gMC->VolName(id),100*fSummEnergy[j]/edtot);
421 for(kn=0;kn<75;kn++) printf("*");
425 // Reset the TArray's
426 // fEventEnergy.Set(0);
427 // fSummEnergy.Set(0);
428 // fSum2Energy.Set(0);
431 //_____________________________________________________________________________
432 void AliMC::BeginEvent()
435 // Clean-up previous event
437 AliDebug(1, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
438 AliDebug(1, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
439 AliDebug(1, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
440 AliDebug(1, " BEGINNING EVENT ");
441 AliDebug(1, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
442 AliDebug(1, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
443 AliDebug(1, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
445 AliRunLoader *runloader=gAlice->GetRunLoader();
447 /*******************************/
448 /* Clean after eventual */
450 /*******************************/
453 //Set the next event in Run Loader -> Cleans trees (TreeK and all trees in detectors),
454 gAlice->SetEventNrInRun(gAlice->GetEventNrInRun()+1);
455 runloader->SetEventNumber(gAlice->GetEventNrInRun());// sets new files, cleans the previous event stuff, if necessary, etc.,
456 AliDebug(1, Form("EventNr is %d",gAlice->GetEventNrInRun()));
458 fEventEnergy.Reset();
459 // Clean detector information
461 if (runloader->Stack())
462 runloader->Stack()->Reset();//clean stack -> tree is unloaded
464 runloader->MakeStack();//or make a new one
466 if(gAlice->Lego() == 0x0)
468 AliDebug(1, "fRunLoader->MakeTree(K)");
469 runloader->MakeTree("K");
472 AliDebug(1, "gMC->SetStack(fRunLoader->Stack())");
473 gMC->SetStack(gAlice->GetRunLoader()->Stack());//Was in InitMC - but was moved here
474 //because we don't have guarantee that
475 //stack pointer is not going to change from event to event
476 //since it bellobgs to header and is obtained via RunLoader
478 // Reset all Detectors & kinematics & make/reset trees
481 runloader->GetHeader()->Reset(gAlice->GetRunNumber(),gAlice->GetEvNumber(),
482 gAlice->GetEventNrInRun());
483 // fRunLoader->WriteKinematics("OVERWRITE"); is there any reason to rewrite here since MakeTree does so
487 gAlice->Lego()->BeginEvent();
492 AliDebug(1, "ResetHits()");
495 AliDebug(1, "fRunLoader->MakeTree(H)");
496 runloader->MakeTree("H");
498 AliDebug(1, "fRunLoader->MakeTrackRefsContainer()");
499 runloader->MakeTrackRefsContainer();//for insurance
502 //create new branches and SetAdresses
503 TIter next(gAlice->Modules());
505 while((detector = (AliModule*)next()))
507 AliDebug(2, Form("%s->MakeBranch(H)",detector->GetName()));
508 detector->MakeBranch("H");
509 AliDebug(2, Form("%s->MakeBranchTR()",detector->GetName()));
510 detector->MakeBranchTR();
511 AliDebug(2, Form("%s->SetTreeAddress()",detector->GetName()));
512 detector->SetTreeAddress();
514 // make branch for AliRun track References
515 TTree * treeTR = runloader->TreeTR();
517 // make branch for central track references
518 if (!fTrackReferences) fTrackReferences = new TClonesArray("AliTrackReference",0);
520 branch = treeTR->Branch("AliRun",&fTrackReferences);
521 branch->SetAddress(&fTrackReferences);
526 //_______________________________________________________________________
527 void AliMC::ResetHits()
530 // Reset all Detectors hits
532 TIter next(gAlice->Modules());
534 while((detector = dynamic_cast<AliModule*>(next()))) {
535 detector->ResetHits();
539 //_______________________________________________________________________
540 void AliMC::PostTrack()
542 // Posts tracks for each module
543 TObjArray &dets = *gAlice->Modules();
546 for(Int_t i=0; i<=gAlice->GetNdets(); i++)
547 if((module = dynamic_cast<AliModule*>(dets[i])))
551 //_______________________________________________________________________
552 void AliMC::FinishPrimary()
555 // Called at the end of each primary track
557 AliRunLoader *runloader=gAlice->GetRunLoader();
558 // static Int_t count=0;
559 // const Int_t times=10;
560 // This primary is finished, purify stack
561 #if ROOT_VERSION_CODE > 262152
562 if (!(gMC->SecondariesAreOrdered()))
563 runloader->Stack()->ReorderKine();
565 runloader->Stack()->PurifyKine();
567 TIter next(gAlice->Modules());
569 while((detector = dynamic_cast<AliModule*>(next()))) {
570 detector->FinishPrimary();
571 AliLoader* loader = detector->GetLoader();
574 TTree* treeH = loader->TreeH();
575 if (treeH) treeH->Fill(); //can be Lego run and treeH can not exist
579 // Write out track references if any
580 if (runloader->TreeTR()) runloader->TreeTR()->Fill();
583 //_______________________________________________________________________
584 void AliMC::FinishEvent()
587 // Called at the end of the event.
592 if(gAlice->Lego()) gAlice->Lego()->FinishEvent();
594 TIter next(gAlice->Modules());
596 while((detector = dynamic_cast<AliModule*>(next()))) {
597 detector->FinishEvent();
600 //Update the energy deposit tables
602 for(i=0;i<fEventEnergy.GetSize();i++)
604 fSummEnergy[i]+=fEventEnergy[i];
605 fSum2Energy[i]+=fEventEnergy[i]*fEventEnergy[i];
608 AliRunLoader *runloader=gAlice->GetRunLoader();
610 AliHeader* header = runloader->GetHeader();
611 AliStack* stack = runloader->Stack();
612 if ( (header == 0x0) || (stack == 0x0) )
613 {//check if we got header and stack. If not cry and exit aliroot
614 AliFatal("Can not get the stack or header from LOADER");
615 return;//never reached
617 // Update Header information
618 header->SetNprimary(stack->GetNprimary());
619 header->SetNtrack(stack->GetNtrack());
622 // Write out the kinematics
623 if (!gAlice->Lego()) stack->FinishEvent();
625 // Write out the event Header information
626 TTree* treeE = runloader->TreeE();
629 header->SetStack(stack);
634 AliError("Can not get TreeE from RL");
637 if(gAlice->Lego() == 0x0)
639 runloader->WriteKinematics("OVERWRITE");
640 runloader->WriteTrackRefs("OVERWRITE");
641 runloader->WriteHits("OVERWRITE");
644 AliDebug(1, "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
645 AliDebug(1, "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
646 AliDebug(1, "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
647 AliDebug(1, " FINISHING EVENT ");
648 AliDebug(1, "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
649 AliDebug(1, "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
650 AliDebug(1, "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
653 //_______________________________________________________________________
654 void AliMC::Field(const Double_t* x, Double_t* b) const
656 // Calculates field "b" at point "x"
660 //_______________________________________________________________________
665 //=================Create Materials and geometry
667 //Set alignable volumes for the whole geometry
668 SetAllAlignableVolumes();
669 //Read the cuts for all materials
671 //Build the special IMEDIA table
674 //Compute cross-sections
677 //Initialise geometry deposition table
678 fEventEnergy.Set(gMC->NofVolumes()+1);
679 fSummEnergy.Set(gMC->NofVolumes()+1);
680 fSum2Energy.Set(gMC->NofVolumes()+1);
683 fMCQA = new AliMCQA(gAlice->GetNdets());
685 // Register MC in configuration
686 AliConfig::Instance()->Add(gMC);
690 //_______________________________________________________________________
691 void AliMC::MediaTable()
694 // Built media table to get from the media number to
698 Int_t kz, nz, idt, lz, i, k, ind;
700 TObjArray &dets = *gAlice->Detectors();
702 Int_t ndets=gAlice->GetNdets();
705 for (kz=0;kz<ndets;kz++) {
706 // If detector is defined
707 if((det=dynamic_cast<AliModule*>(dets[kz]))) {
708 TArrayI &idtmed = *(det->GetIdtmed());
709 for(nz=0;nz<100;nz++) {
711 // Find max and min material number
712 if((idt=idtmed[nz])) {
713 det->LoMedium() = det->LoMedium() < idt ? det->LoMedium() : idt;
714 det->HiMedium() = det->HiMedium() > idt ? det->HiMedium() : idt;
717 if(det->LoMedium() > det->HiMedium()) {
721 if(det->HiMedium() > fImedia->GetSize()) {
722 AliError(Form("Increase fImedia from %d to %d",
723 fImedia->GetSize(),det->HiMedium()));
726 // Tag all materials in rage as belonging to detector kz
727 for(lz=det->LoMedium(); lz<= det->HiMedium(); lz++) {
734 // Print summary table
735 AliInfo("Tracking media ranges:");
737 for(i=0;i<(ndets-1)/6+1;i++) {
738 for(k=0;k< (6<ndets-i*6?6:ndets-i*6);k++) {
740 det=dynamic_cast<AliModule*>(dets[ind]);
742 printf(" %6s: %3d -> %3d;",det->GetName(),det->LoMedium(),
745 printf(" %6s: %3d -> %3d;","NULL",0,0);
752 //_______________________________________________________________________
753 void AliMC::ReadTransPar()
756 // Read filename to set the transport parameters
760 const Int_t kncuts=10;
761 const Int_t knflags=11;
762 const Int_t knpars=kncuts+knflags;
763 const char kpars[knpars][7] = {"CUTGAM" ,"CUTELE","CUTNEU","CUTHAD","CUTMUO",
764 "BCUTE","BCUTM","DCUTE","DCUTM","PPCUTM","ANNI",
765 "BREM","COMP","DCAY","DRAY","HADR","LOSS",
766 "MULS","PAIR","PHOT","RAYL"};
772 Int_t i, itmed, iret, ktmed, kz;
775 // See whether the file is there
776 filtmp=gSystem->ExpandPathName(fTransParName.Data());
777 lun=fopen(filtmp,"r");
780 AliWarning(Form("File %s does not exist!",fTransParName.Data()));
785 // Initialise cuts and flags
786 for(i=0;i<kncuts;i++) cut[i]=-99;
787 for(i=0;i<knflags;i++) flag[i]=-99;
789 for(i=0;i<256;i++) line[i]='\0';
790 // Read up to the end of line excluded
791 iret=fscanf(lun,"%[^\n]",line);
797 // Read the end of line
800 if(line[0]=='*') continue;
802 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",
803 detName,&itmed,&cut[0],&cut[1],&cut[2],&cut[3],&cut[4],&cut[5],&cut[6],&cut[7],&cut[8],
804 &cut[9],&flag[0],&flag[1],&flag[2],&flag[3],&flag[4],&flag[5],&flag[6],&flag[7],
805 &flag[8],&flag[9],&flag[10]);
809 AliWarning(Form("Error reading file %s",fTransParName.Data()));
812 // Check that the module exist
813 AliModule *mod = gAlice->GetModule(detName);
815 // Get the array of media numbers
816 TArrayI &idtmed = *mod->GetIdtmed();
817 // Check that the tracking medium code is valid
818 if(0<=itmed && itmed < 100) {
821 AliWarning(Form("Invalid tracking medium code %d for %s",itmed,mod->GetName()));
824 // Set energy thresholds
825 for(kz=0;kz<kncuts;kz++) {
827 AliDebug(2, Form("%-6s set to %10.3E for tracking medium code %4d for %s",
828 kpars[kz],cut[kz],itmed,mod->GetName()));
829 gMC->Gstpar(ktmed,kpars[kz],cut[kz]);
832 // Set transport mechanisms
833 for(kz=0;kz<knflags;kz++) {
835 AliDebug(2, Form("%-6s set to %10d for tracking medium code %4d for %s",
836 kpars[kncuts+kz],flag[kz],itmed,mod->GetName()));
837 gMC->Gstpar(ktmed,kpars[kncuts+kz],Float_t(flag[kz]));
841 AliWarning(Form("Invalid medium code %d",itmed));
845 AliDebug(1, Form("%s not present",detName));
851 //_______________________________________________________________________
852 void AliMC::SetTransPar(const char *filename)
855 // Sets the file name for transport parameters
857 fTransParName = filename;
860 //_______________________________________________________________________
861 void AliMC::Browse(TBrowser *b)
864 // Called when the item "Run" is clicked on the left pane
865 // of the Root browser.
866 // It displays the Root Trees and all detectors.
868 //detectors are in folders anyway
869 b->Add(fMCQA,"AliMCQA");
872 //_______________________________________________________________________
873 void AliMC::AddHit(Int_t id, Int_t track, Int_t *vol, Float_t *hits) const
876 // Add a hit to detector id
878 TObjArray &dets = *gAlice->Modules();
879 if(dets[id]) dynamic_cast<AliModule*>(dets[id])->AddHit(track,vol,hits);
882 //_______________________________________________________________________
883 void AliMC::AddDigit(Int_t id, Int_t *tracks, Int_t *digits) const
886 // Add digit to detector id
888 TObjArray &dets = *gAlice->Modules();
889 if(dets[id]) dynamic_cast<AliModule*>(dets[id])->AddDigit(tracks,digits);
892 //_______________________________________________________________________
893 Int_t AliMC::GetCurrentTrackNumber() const {
895 // Returns current track
897 return gAlice->GetRunLoader()->Stack()->GetCurrentTrackNumber();
900 //_______________________________________________________________________
901 void AliMC::DumpPart (Int_t i) const
904 // Dumps particle i in the stack
906 AliRunLoader * runloader = gAlice->GetRunLoader();
907 if (runloader->Stack())
908 runloader->Stack()->DumpPart(i);
911 //_______________________________________________________________________
912 void AliMC::DumpPStack () const
915 // Dumps the particle stack
917 AliRunLoader * runloader = gAlice->GetRunLoader();
918 if (runloader->Stack())
919 runloader->Stack()->DumpPStack();
922 //_______________________________________________________________________
923 Int_t AliMC::GetNtrack() const {
925 // Returns number of tracks in stack
928 AliRunLoader * runloader = gAlice->GetRunLoader();
929 if (runloader->Stack())
930 ntracks = runloader->Stack()->GetNtrack();
934 //_______________________________________________________________________
935 Int_t AliMC::GetPrimary(Int_t track) const
938 // return number of primary that has generated track
940 Int_t nprimary = -999;
941 AliRunLoader * runloader = gAlice->GetRunLoader();
942 if (runloader->Stack())
943 nprimary = runloader->Stack()->GetPrimary(track);
947 //_______________________________________________________________________
948 TParticle* AliMC::Particle(Int_t i) const
950 // Returns the i-th particle from the stack taking into account
951 // the remaping done by PurifyKine
952 AliRunLoader * runloader = gAlice->GetRunLoader();
954 if (runloader->Stack())
955 return runloader->Stack()->Particle(i);
959 //_______________________________________________________________________
960 TObjArray* AliMC::Particles() const {
962 // Returns pointer to Particles array
964 AliRunLoader * runloader = gAlice->GetRunLoader();
966 if (runloader->Stack())
967 return runloader->Stack()->Particles();
971 //_______________________________________________________________________
972 void AliMC::PushTrack(Int_t done, Int_t parent, Int_t pdg, Float_t *pmom,
973 Float_t *vpos, Float_t *polar, Float_t tof,
974 TMCProcess mech, Int_t &ntr, Float_t weight, Int_t is) const
978 AliRunLoader * runloader = gAlice->GetRunLoader();
980 if (runloader->Stack())
981 runloader->Stack()->PushTrack(done, parent, pdg, pmom, vpos, polar, tof,
982 mech, ntr, weight, is);
985 //_______________________________________________________________________
986 void AliMC::PushTrack(Int_t done, Int_t parent, Int_t pdg,
987 Double_t px, Double_t py, Double_t pz, Double_t e,
988 Double_t vx, Double_t vy, Double_t vz, Double_t tof,
989 Double_t polx, Double_t poly, Double_t polz,
990 TMCProcess mech, Int_t &ntr, Float_t weight, Int_t is) const
994 AliRunLoader * runloader = gAlice->GetRunLoader();
996 if (runloader->Stack())
997 runloader->Stack()->PushTrack(done, parent, pdg, px, py, pz, e, vx, vy, vz, tof,
998 polx, poly, polz, mech, ntr, weight, is);
1001 //_______________________________________________________________________
1002 void AliMC::SetHighWaterMark(Int_t nt) const
1005 // Set high water mark for last track in event
1006 AliRunLoader * runloader = gAlice->GetRunLoader();
1008 if (runloader->Stack())
1009 runloader->Stack()->SetHighWaterMark(nt);
1012 //_______________________________________________________________________
1013 void AliMC::KeepTrack(Int_t track) const
1016 // Delegate to stack
1018 AliRunLoader * runloader = gAlice->GetRunLoader();
1020 if (runloader->Stack())
1021 runloader->Stack()->KeepTrack(track);
1024 //_______________________________________________________________________
1025 void AliMC::FlagTrack(Int_t track) const
1027 // Delegate to stack
1029 AliRunLoader * runloader = gAlice->GetRunLoader();
1031 if (runloader->Stack())
1032 runloader->Stack()->FlagTrack(track);
1035 //_______________________________________________________________________
1036 void AliMC::SetCurrentTrack(Int_t track) const
1039 // Set current track number
1041 AliRunLoader * runloader = gAlice->GetRunLoader();
1043 if (runloader->Stack())
1044 runloader->Stack()->SetCurrentTrack(track);
1047 //_______________________________________________________________________
1048 void AliMC::AddTrackReference(Int_t label){
1050 // add a trackrefernce to the list
1051 if (!fTrackReferences) {
1052 AliError("Container trackrefernce not active");
1055 Int_t nref = fTrackReferences->GetEntriesFast();
1056 TClonesArray &lref = *fTrackReferences;
1057 new(lref[nref]) AliTrackReference(label);
1062 //_______________________________________________________________________
1063 void AliMC::ResetTrackReferences()
1066 // Reset all references
1068 if (fTrackReferences) fTrackReferences->Clear();
1070 TIter next(gAlice->Modules());
1071 AliModule *detector;
1072 while((detector = dynamic_cast<AliModule*>(next()))) {
1073 detector->ResetTrackReferences();
1077 void AliMC::RemapTrackReferencesIDs(Int_t *map)
1080 // Remapping track reference
1081 // Called at finish primary
1083 if (!fTrackReferences) return;
1084 Int_t nEntries = fTrackReferences->GetEntries();
1085 for (Int_t i=0; i < nEntries; i++){
1086 AliTrackReference * ref = dynamic_cast<AliTrackReference*>(fTrackReferences->UncheckedAt(i));
1088 Int_t newID = map[ref->GetTrack()];
1089 if (newID>=0) ref->SetTrack(newID);
1091 ref->SetBit(kNotDeleted,kFALSE);
1092 fTrackReferences->RemoveAt(i);
1096 fTrackReferences->Compress();
1099 void AliMC::FixParticleDecaytime()
1102 // Fix the particle decay time according to rmin and rmax for decays
1106 gMC->TrackMomentum(p);
1107 Double_t tmin, tmax;
1110 // Transverse velocity
1111 Double_t vt = p.Pt() / p.E();
1113 if ((b = gAlice->Field()->SolenoidField()) > 0.) { // [kG]
1117 Double_t rho = p.Pt() / 0.0003 / b; // [cm]
1119 // Revolution frequency
1121 Double_t omega = vt / rho;
1123 // Maximum and minimum decay time
1125 // Check for curlers first
1126 if (fRDecayMax * fRDecayMax / rho / rho / 2. > 1.) return;
1130 tmax = TMath::ACos(1. - fRDecayMax * fRDecayMax / rho / rho / 2.) / omega; // [ct]
1131 tmin = TMath::ACos(1. - fRDecayMin * fRDecayMin / rho / rho / 2.) / omega; // [ct]
1133 tmax = fRDecayMax / vt; // [ct]
1134 tmin = fRDecayMin / vt; // [ct]
1138 // Dial t using the two limits
1139 Double_t t = tmin + (tmax - tmin) * gRandom->Rndm(); // [ct]
1142 // Force decay time in transport code
1144 gMC->ForceDecayTime(t / 2.99792458e10);