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 <TStopwatch.h>
28 #include <TVirtualMC.h>
29 #include <TGeoManager.h>
34 #include "AliDetector.h"
35 #include "AliGenerator.h"
36 #include "AliHeader.h"
43 #include "AliTrackReference.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 void AliMC::InitGeometry()
186 // Initialize detectors and display geometry
189 AliInfo("Initialisation:");
191 TIter next(gAlice->Modules());
193 while((detector = dynamic_cast<AliModule*>(next()))) {
195 // Initialise detector and display geometry
196 if(gAlice->IsRootGeometry()) detector->CreateMaterials();
198 detector->BuildGeometry();
199 AliInfo(Form("%10s R:%.2fs C:%.2fs",
200 detector->GetName(),stw.RealTime(),stw.CpuTime()));
205 //_______________________________________________________________________
206 void AliMC::GeneratePrimaries()
209 // Generate primary particles and fill them in the stack.
212 Generator()->Generate();
215 //_______________________________________________________________________
216 void AliMC::SetGenerator(AliGenerator *generator)
219 // Load the event generator
221 if(!fGenerator) fGenerator = generator;
224 //_______________________________________________________________________
225 void AliMC::ResetGenerator(AliGenerator *generator)
228 // Load the event generator
232 AliWarning(Form("Replacing generator %s with %s",
233 fGenerator->GetName(),generator->GetName()))
235 AliWarning(Form("Replacing generator %s with NULL",
236 fGenerator->GetName()));
237 fGenerator = generator;
240 //_______________________________________________________________________
241 void AliMC::FinishRun()
243 // Clean generator information
244 AliDebug(1, "fGenerator->FinishRun()");
245 fGenerator->FinishRun();
247 //Output energy summary tables
248 AliDebug(1, "EnergySummary()");
249 ToAliDebug(1, EnergySummary());
252 //_______________________________________________________________________
253 void AliMC::BeginPrimary()
256 // Called at the beginning of each primary track
261 ResetTrackReferences();
265 //_______________________________________________________________________
266 void AliMC::PreTrack()
268 // Actions before the track's transport
269 TObjArray &dets = *gAlice->Modules();
272 for(Int_t i=0; i<=gAlice->GetNdets(); i++)
273 if((module = dynamic_cast<AliModule*>(dets[i])))
279 //_______________________________________________________________________
280 void AliMC::Stepping()
283 // Called at every step during transport
286 Int_t id = DetFromMate(gMC->GetMedium());
290 if ( gMC->IsNewTrack() &&
291 gMC->TrackTime() == 0. &&
293 fRDecayMax > fRDecayMin &&
294 gMC->TrackPid() == fDecayPdg )
296 FixParticleDecaytime();
302 // --- If lego option, do it and leave
304 gAlice->Lego()->StepManager();
307 //Update energy deposition tables
308 AddEnergyDeposit(gMC->CurrentVolID(copy),gMC->Edep());
310 // write tracke reference for track which is dissapearing - MI
311 if (gMC->IsTrackDisappeared()) {
312 if (gMC->Etot()>0.05) AddTrackReference(GetCurrentTrackNumber());
315 //Call the appropriate stepping routine;
316 AliModule *det = dynamic_cast<AliModule*>(gAlice->Modules()->At(id));
317 if(det && det->StepManagerIsEnabled()) {
318 fMCQA->StepManager(id);
324 //_______________________________________________________________________
325 void AliMC::EnergySummary()
328 // Print summary of deposited energy
334 Int_t kn, i, left, j, id;
335 const Float_t kzero=0;
336 Int_t ievent=gAlice->GetRunLoader()->GetHeader()->GetEvent()+1;
338 // Energy loss information
340 printf("***************** Energy Loss Information per event (GEV) *****************\n");
341 for(kn=1;kn<fEventEnergy.GetSize();kn++) {
344 fEventEnergy[ndep]=kn;
349 ed2=100*TMath::Sqrt(TMath::Max(ed2-ed*ed,kzero))/ed;
352 fSummEnergy[ndep]=ed;
353 fSum2Energy[ndep]=TMath::Min(static_cast<Float_t>(99.),TMath::Max(ed2,kzero));
358 for(kn=0;kn<(ndep-1)/3+1;kn++) {
360 for(i=0;i<(3<left?3:left);i++) {
362 id=Int_t (fEventEnergy[j]+0.1);
363 printf(" %s %10.3f +- %10.3f%%;",gMC->VolName(id),fSummEnergy[j],fSum2Energy[j]);
368 // Relative energy loss in different detectors
369 printf("******************** Relative Energy Loss per event ********************\n");
370 printf("Total energy loss per event %10.3f GeV\n",edtot);
371 for(kn=0;kn<(ndep-1)/5+1;kn++) {
373 for(i=0;i<(5<left?5:left);i++) {
375 id=Int_t (fEventEnergy[j]+0.1);
376 printf(" %s %10.3f%%;",gMC->VolName(id),100*fSummEnergy[j]/edtot);
380 for(kn=0;kn<75;kn++) printf("*");
384 // Reset the TArray's
385 // fEventEnergy.Set(0);
386 // fSummEnergy.Set(0);
387 // fSum2Energy.Set(0);
390 //_____________________________________________________________________________
391 void AliMC::BeginEvent()
394 // Clean-up previous event
396 AliDebug(1, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
397 AliDebug(1, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
398 AliDebug(1, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
399 AliDebug(1, " BEGINNING EVENT ");
400 AliDebug(1, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
401 AliDebug(1, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
402 AliDebug(1, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
404 AliRunLoader *runloader=gAlice->GetRunLoader();
406 /*******************************/
407 /* Clean after eventual */
409 /*******************************/
412 //Set the next event in Run Loader -> Cleans trees (TreeK and all trees in detectors),
413 gAlice->SetEventNrInRun(gAlice->GetEventNrInRun()+1);
414 runloader->SetEventNumber(gAlice->GetEventNrInRun());// sets new files, cleans the previous event stuff, if necessary, etc.,
415 AliDebug(1, Form("EventNr is %d",gAlice->GetEventNrInRun()));
417 fEventEnergy.Reset();
418 // Clean detector information
420 if (runloader->Stack())
421 runloader->Stack()->Reset();//clean stack -> tree is unloaded
423 runloader->MakeStack();//or make a new one
425 if(gAlice->Lego() == 0x0)
427 AliDebug(1, "fRunLoader->MakeTree(K)");
428 runloader->MakeTree("K");
431 AliDebug(1, "gMC->SetStack(fRunLoader->Stack())");
432 gMC->SetStack(gAlice->GetRunLoader()->Stack());//Was in InitMC - but was moved here
433 //because we don't have guarantee that
434 //stack pointer is not going to change from event to event
435 //since it bellobgs to header and is obtained via RunLoader
437 // Reset all Detectors & kinematics & make/reset trees
440 runloader->GetHeader()->Reset(gAlice->GetRunNumber(),gAlice->GetEvNumber(),
441 gAlice->GetEventNrInRun());
442 // fRunLoader->WriteKinematics("OVERWRITE"); is there any reason to rewrite here since MakeTree does so
446 gAlice->Lego()->BeginEvent();
451 AliDebug(1, "ResetHits()");
454 AliDebug(1, "fRunLoader->MakeTree(H)");
455 runloader->MakeTree("H");
457 AliDebug(1, "fRunLoader->MakeTrackRefsContainer()");
458 runloader->MakeTrackRefsContainer();//for insurance
461 //create new branches and SetAdresses
462 TIter next(gAlice->Modules());
464 while((detector = (AliModule*)next()))
466 AliDebug(2, Form("%s->MakeBranch(H)",detector->GetName()));
467 detector->MakeBranch("H");
468 AliDebug(2, Form("%s->MakeBranchTR()",detector->GetName()));
469 detector->MakeBranchTR();
470 AliDebug(2, Form("%s->SetTreeAddress()",detector->GetName()));
471 detector->SetTreeAddress();
473 // make branch for AliRun track References
474 TTree * treeTR = runloader->TreeTR();
476 // make branch for central track references
477 if (!fTrackReferences) fTrackReferences = new TClonesArray("AliTrackReference",0);
479 branch = treeTR->Branch("AliRun",&fTrackReferences);
480 branch->SetAddress(&fTrackReferences);
485 //_______________________________________________________________________
486 void AliMC::ResetHits()
489 // Reset all Detectors hits
491 TIter next(gAlice->Modules());
493 while((detector = dynamic_cast<AliModule*>(next()))) {
494 detector->ResetHits();
498 //_______________________________________________________________________
499 void AliMC::PostTrack()
501 // Posts tracks for each module
502 TObjArray &dets = *gAlice->Modules();
505 for(Int_t i=0; i<=gAlice->GetNdets(); i++)
506 if((module = dynamic_cast<AliModule*>(dets[i])))
510 //_______________________________________________________________________
511 void AliMC::FinishPrimary()
514 // Called at the end of each primary track
516 AliRunLoader *runloader=gAlice->GetRunLoader();
517 // static Int_t count=0;
518 // const Int_t times=10;
519 // This primary is finished, purify stack
520 #if ROOT_VERSION_CODE > 262152
521 if (!(gMC->SecondariesAreOrdered()))
522 runloader->Stack()->ReorderKine();
524 runloader->Stack()->PurifyKine();
526 TIter next(gAlice->Modules());
528 while((detector = dynamic_cast<AliModule*>(next()))) {
529 detector->FinishPrimary();
530 AliLoader* loader = detector->GetLoader();
533 TTree* treeH = loader->TreeH();
534 if (treeH) treeH->Fill(); //can be Lego run and treeH can not exist
538 // Write out track references if any
539 if (runloader->TreeTR()) runloader->TreeTR()->Fill();
542 //_______________________________________________________________________
543 void AliMC::FinishEvent()
546 // Called at the end of the event.
550 if(gAlice->Lego()) gAlice->Lego()->FinishEvent();
552 TIter next(gAlice->Modules());
554 while((detector = dynamic_cast<AliModule*>(next()))) {
555 detector->FinishEvent();
558 //Update the energy deposit tables
560 for(i=0;i<fEventEnergy.GetSize();i++)
562 fSummEnergy[i]+=fEventEnergy[i];
563 fSum2Energy[i]+=fEventEnergy[i]*fEventEnergy[i];
566 AliRunLoader *runloader=gAlice->GetRunLoader();
568 AliHeader* header = runloader->GetHeader();
569 AliStack* stack = runloader->Stack();
570 if ( (header == 0x0) || (stack == 0x0) )
571 {//check if we got header and stack. If not cry and exit aliroot
572 AliFatal("Can not get the stack or header from LOADER");
573 return;//never reached
575 // Update Header information
576 header->SetNprimary(stack->GetNprimary());
577 header->SetNtrack(stack->GetNtrack());
580 // Write out the kinematics
581 stack->FinishEvent();
583 // Write out the event Header information
584 TTree* treeE = runloader->TreeE();
587 header->SetStack(stack);
592 AliError("Can not get TreeE from RL");
595 if(gAlice->Lego() == 0x0)
597 runloader->WriteKinematics("OVERWRITE");
598 runloader->WriteTrackRefs("OVERWRITE");
599 runloader->WriteHits("OVERWRITE");
602 AliDebug(1, "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
603 AliDebug(1, "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
604 AliDebug(1, "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
605 AliDebug(1, " FINISHING EVENT ");
606 AliDebug(1, "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
607 AliDebug(1, "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
608 AliDebug(1, "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
611 //_______________________________________________________________________
612 void AliMC::Field(const Double_t* x, Double_t* b) const
614 // Calculates field "b" at point "x"
618 //_______________________________________________________________________
623 //=================Create Materials and geometry
625 //Read the cuts for all materials
627 //Build the special IMEDIA table
630 //Compute cross-sections
633 //Write Geometry object to current file.
634 gAlice->GetRunLoader()->WriteGeometry();
636 //Initialise geometry deposition table
637 fEventEnergy.Set(gMC->NofVolumes()+1);
638 fSummEnergy.Set(gMC->NofVolumes()+1);
639 fSum2Energy.Set(gMC->NofVolumes()+1);
642 fMCQA = new AliMCQA(gAlice->GetNdets());
644 // Register MC in configuration
645 AliConfig::Instance()->Add(gMC);
649 //_______________________________________________________________________
650 void AliMC::MediaTable()
653 // Built media table to get from the media number to
657 Int_t kz, nz, idt, lz, i, k, ind;
659 TObjArray &dets = *gAlice->Detectors();
661 Int_t ndets=gAlice->GetNdets();
664 for (kz=0;kz<ndets;kz++) {
665 // If detector is defined
666 if((det=dynamic_cast<AliModule*>(dets[kz]))) {
667 TArrayI &idtmed = *(det->GetIdtmed());
668 for(nz=0;nz<100;nz++) {
670 // Find max and min material number
671 if((idt=idtmed[nz])) {
672 det->LoMedium() = det->LoMedium() < idt ? det->LoMedium() : idt;
673 det->HiMedium() = det->HiMedium() > idt ? det->HiMedium() : idt;
676 if(det->LoMedium() > det->HiMedium()) {
680 if(det->HiMedium() > fImedia->GetSize()) {
681 AliError(Form("Increase fImedia from %d to %d",
682 fImedia->GetSize(),det->HiMedium()));
685 // Tag all materials in rage as belonging to detector kz
686 for(lz=det->LoMedium(); lz<= det->HiMedium(); lz++) {
693 // Print summary table
694 AliInfo("Tracking media ranges:");
696 for(i=0;i<(ndets-1)/6+1;i++) {
697 for(k=0;k< (6<ndets-i*6?6:ndets-i*6);k++) {
699 det=dynamic_cast<AliModule*>(dets[ind]);
701 printf(" %6s: %3d -> %3d;",det->GetName(),det->LoMedium(),
704 printf(" %6s: %3d -> %3d;","NULL",0,0);
711 //_______________________________________________________________________
712 void AliMC::ReadTransPar()
715 // Read filename to set the transport parameters
719 const Int_t kncuts=10;
720 const Int_t knflags=11;
721 const Int_t knpars=kncuts+knflags;
722 const char kpars[knpars][7] = {"CUTGAM" ,"CUTELE","CUTNEU","CUTHAD","CUTMUO",
723 "BCUTE","BCUTM","DCUTE","DCUTM","PPCUTM","ANNI",
724 "BREM","COMP","DCAY","DRAY","HADR","LOSS",
725 "MULS","PAIR","PHOT","RAYL"};
731 Int_t i, itmed, iret, ktmed, kz;
734 // See whether the file is there
735 filtmp=gSystem->ExpandPathName(fTransParName.Data());
736 lun=fopen(filtmp,"r");
739 AliWarning(Form("File %s does not exist!",fTransParName.Data()));
744 // Initialise cuts and flags
745 for(i=0;i<kncuts;i++) cut[i]=-99;
746 for(i=0;i<knflags;i++) flag[i]=-99;
748 for(i=0;i<256;i++) line[i]='\0';
749 // Read up to the end of line excluded
750 iret=fscanf(lun,"%[^\n]",line);
756 // Read the end of line
759 if(line[0]=='*') continue;
761 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",
762 detName,&itmed,&cut[0],&cut[1],&cut[2],&cut[3],&cut[4],&cut[5],&cut[6],&cut[7],&cut[8],
763 &cut[9],&flag[0],&flag[1],&flag[2],&flag[3],&flag[4],&flag[5],&flag[6],&flag[7],
764 &flag[8],&flag[9],&flag[10]);
768 AliWarning(Form("Error reading file %s",fTransParName.Data()));
771 // Check that the module exist
772 AliModule *mod = gAlice->GetModule(detName);
774 // Get the array of media numbers
775 TArrayI &idtmed = *mod->GetIdtmed();
776 // Check that the tracking medium code is valid
777 if(0<=itmed && itmed < 100) {
780 AliWarning(Form("Invalid tracking medium code %d for %s",itmed,mod->GetName()));
783 // Set energy thresholds
784 for(kz=0;kz<kncuts;kz++) {
786 AliDebug(2, Form("%-6s set to %10.3E for tracking medium code %4d for %s",
787 kpars[kz],cut[kz],itmed,mod->GetName()));
788 gMC->Gstpar(ktmed,kpars[kz],cut[kz]);
791 // Set transport mechanisms
792 for(kz=0;kz<knflags;kz++) {
794 AliDebug(2, Form("%-6s set to %10d for tracking medium code %4d for %s",
795 kpars[kncuts+kz],flag[kz],itmed,mod->GetName()));
796 gMC->Gstpar(ktmed,kpars[kncuts+kz],Float_t(flag[kz]));
800 AliWarning(Form("Invalid medium code %d",itmed));
804 AliDebug(1, Form("%s not present",detName));
810 //_______________________________________________________________________
811 void AliMC::SetTransPar(const char *filename)
814 // Sets the file name for transport parameters
816 fTransParName = filename;
819 //_______________________________________________________________________
820 void AliMC::Browse(TBrowser *b)
823 // Called when the item "Run" is clicked on the left pane
824 // of the Root browser.
825 // It displays the Root Trees and all detectors.
827 //detectors are in folders anyway
828 b->Add(fMCQA,"AliMCQA");
832 //_______________________________________________________________________
833 void AliMC::AddHit(Int_t id, Int_t track, Int_t *vol, Float_t *hits) const
836 // Add a hit to detector id
838 TObjArray &dets = *gAlice->Modules();
839 if(dets[id]) dynamic_cast<AliModule*>(dets[id])->AddHit(track,vol,hits);
842 //_______________________________________________________________________
843 void AliMC::AddDigit(Int_t id, Int_t *tracks, Int_t *digits) const
846 // Add digit to detector id
848 TObjArray &dets = *gAlice->Modules();
849 if(dets[id]) dynamic_cast<AliModule*>(dets[id])->AddDigit(tracks,digits);
852 //_______________________________________________________________________
853 Int_t AliMC::GetCurrentTrackNumber() const {
855 // Returns current track
857 return gAlice->GetRunLoader()->Stack()->GetCurrentTrackNumber();
860 //_______________________________________________________________________
861 void AliMC::DumpPart (Int_t i) const
864 // Dumps particle i in the stack
866 AliRunLoader * runloader = gAlice->GetRunLoader();
867 if (runloader->Stack())
868 runloader->Stack()->DumpPart(i);
871 //_______________________________________________________________________
872 void AliMC::DumpPStack () const
875 // Dumps the particle stack
877 AliRunLoader * runloader = gAlice->GetRunLoader();
878 if (runloader->Stack())
879 runloader->Stack()->DumpPStack();
882 //_______________________________________________________________________
883 Int_t AliMC::GetNtrack() const {
885 // Returns number of tracks in stack
888 AliRunLoader * runloader = gAlice->GetRunLoader();
889 if (runloader->Stack())
890 ntracks = runloader->Stack()->GetNtrack();
894 //_______________________________________________________________________
895 Int_t AliMC::GetPrimary(Int_t track) const
898 // return number of primary that has generated track
900 Int_t nprimary = -999;
901 AliRunLoader * runloader = gAlice->GetRunLoader();
902 if (runloader->Stack())
903 nprimary = runloader->Stack()->GetPrimary(track);
907 //_______________________________________________________________________
908 TParticle* AliMC::Particle(Int_t i) const
910 // Returns the i-th particle from the stack taking into account
911 // the remaping done by PurifyKine
912 AliRunLoader * runloader = gAlice->GetRunLoader();
914 if (runloader->Stack())
915 return runloader->Stack()->Particle(i);
919 //_______________________________________________________________________
920 TObjArray* AliMC::Particles() const {
922 // Returns pointer to Particles array
924 AliRunLoader * runloader = gAlice->GetRunLoader();
926 if (runloader->Stack())
927 return runloader->Stack()->Particles();
931 //_______________________________________________________________________
932 void AliMC::PushTrack(Int_t done, Int_t parent, Int_t pdg, Float_t *pmom,
933 Float_t *vpos, Float_t *polar, Float_t tof,
934 TMCProcess mech, Int_t &ntr, Float_t weight, Int_t is) const
938 AliRunLoader * runloader = gAlice->GetRunLoader();
940 if (runloader->Stack())
941 runloader->Stack()->PushTrack(done, parent, pdg, pmom, vpos, polar, tof,
942 mech, ntr, weight, is);
945 //_______________________________________________________________________
946 void AliMC::PushTrack(Int_t done, Int_t parent, Int_t pdg,
947 Double_t px, Double_t py, Double_t pz, Double_t e,
948 Double_t vx, Double_t vy, Double_t vz, Double_t tof,
949 Double_t polx, Double_t poly, Double_t polz,
950 TMCProcess mech, Int_t &ntr, Float_t weight, Int_t is) const
954 AliRunLoader * runloader = gAlice->GetRunLoader();
956 if (runloader->Stack())
957 runloader->Stack()->PushTrack(done, parent, pdg, px, py, pz, e, vx, vy, vz, tof,
958 polx, poly, polz, mech, ntr, weight, is);
961 //_______________________________________________________________________
962 void AliMC::SetHighWaterMark(Int_t nt) const
965 // Set high water mark for last track in event
966 AliRunLoader * runloader = gAlice->GetRunLoader();
968 if (runloader->Stack())
969 runloader->Stack()->SetHighWaterMark(nt);
972 //_______________________________________________________________________
973 void AliMC::KeepTrack(Int_t track) const
978 AliRunLoader * runloader = gAlice->GetRunLoader();
980 if (runloader->Stack())
981 runloader->Stack()->KeepTrack(track);
984 //_______________________________________________________________________
985 void AliMC::FlagTrack(Int_t track) const
989 AliRunLoader * runloader = gAlice->GetRunLoader();
991 if (runloader->Stack())
992 runloader->Stack()->FlagTrack(track);
995 //_______________________________________________________________________
996 void AliMC::SetCurrentTrack(Int_t track) const
999 // Set current track number
1001 AliRunLoader * runloader = gAlice->GetRunLoader();
1003 if (runloader->Stack())
1004 runloader->Stack()->SetCurrentTrack(track);
1007 //_______________________________________________________________________
1008 void AliMC::AddTrackReference(Int_t label){
1010 // add a trackrefernce to the list
1011 if (!fTrackReferences) {
1012 AliError("Container trackrefernce not active");
1015 Int_t nref = fTrackReferences->GetEntriesFast();
1016 TClonesArray &lref = *fTrackReferences;
1017 new(lref[nref]) AliTrackReference(label);
1022 //_______________________________________________________________________
1023 void AliMC::ResetTrackReferences()
1026 // Reset all references
1028 if (fTrackReferences) fTrackReferences->Clear();
1030 TIter next(gAlice->Modules());
1031 AliModule *detector;
1032 while((detector = dynamic_cast<AliModule*>(next()))) {
1033 detector->ResetTrackReferences();
1037 void AliMC::RemapTrackReferencesIDs(Int_t *map)
1040 // Remapping track reference
1041 // Called at finish primary
1043 if (!fTrackReferences) return;
1044 for (Int_t i=0;i<fTrackReferences->GetEntries();i++){
1045 AliTrackReference * ref = dynamic_cast<AliTrackReference*>(fTrackReferences->UncheckedAt(i));
1047 Int_t newID = map[ref->GetTrack()];
1048 if (newID>=0) ref->SetTrack(newID);
1050 //ref->SetTrack(-1);
1051 ref->SetBit(kNotDeleted,kFALSE);
1052 fTrackReferences->RemoveAt(i);
1056 fTrackReferences->Compress();
1059 void AliMC::FixParticleDecaytime()
1062 // Fix the particle decay time according to rmin and rmax for decays
1066 gMC->TrackMomentum(p);
1067 Double_t tmin, tmax;
1070 // Transverse velocity
1071 Double_t vt = p.Pt() / p.E();
1073 if ((b = gAlice->Field()->SolenoidField()) > 0.) { // [kG]
1077 Double_t rho = p.Pt() / 0.0003 / b; // [cm]
1079 // Revolution frequency
1081 Double_t omega = vt / rho;
1083 // Maximum and minimum decay time
1085 // Check for curlers first
1086 if (fRDecayMax * fRDecayMax / rho / rho / 2. > 1.) return;
1090 tmax = TMath::ACos(1. - fRDecayMax * fRDecayMax / rho / rho / 2.) / omega; // [ct]
1091 tmin = TMath::ACos(1. - fRDecayMin * fRDecayMin / rho / rho / 2.) / omega; // [ct]
1093 tmax = fRDecayMax / vt; // [ct]
1094 tmin = fRDecayMin / vt; // [ct]
1098 // Dial t using the two limits
1099 Double_t t = tmin + (tmax - tmin) * gRandom->Rndm(); // [ct]
1102 // Force decay time in transport code
1104 TGeant3 * geant = (TGeant3*) gMC;
1105 geant->Gcphys()->sumlif = t / p.Beta() / p.Gamma();