// Author: F.Carminati
// Federico.Carminati@cern.ch
+#include <RVersion.h>
#include <TBrowser.h>
+#include <TClonesArray.h>
+#include <TGeoManager.h>
#include <TStopwatch.h>
#include <TSystem.h>
#include <TVirtualMC.h>
+#include "AliLog.h"
#include "AliDetector.h"
#include "AliGenerator.h"
#include "AliHeader.h"
#include "AliMCQA.h"
#include "AliRun.h"
#include "AliStack.h"
+#include "AliMagF.h"
#include "AliTrackReference.h"
fSum2Energy(0),
fTrRmax(1.e10),
fTrZmax(1.e10),
- fDebug(0),
+ fRDecayMax(1.e10),
+ fRDecayMin(-1.),
+ fDecayPdg(0),
fImedia(0),
fTransParName("\0"),
fMCQA(0),
{
//default constructor
+ DecayLimits();
}
//_______________________________________________________________________
fSum2Energy(0),
fTrRmax(1.e10),
fTrZmax(1.e10),
- fDebug(0),
+ fRDecayMax(1.e10),
+ fRDecayMin(-1.),
+ fDecayPdg(0),
fImedia(new TArrayI(1000)),
fTransParName("\0"),
fMCQA(0),
//constructor
// Set transport parameters
SetTransPar();
-
+ DecayLimits();
// Prepare the tracking medium lists
for(Int_t i=0;i<1000;i++) (*fImedia)[i]=-99;
-
}
//_______________________________________________________________________
fSum2Energy(0),
fTrRmax(1.e10),
fTrZmax(1.e10),
- fDebug(0),
+ fRDecayMax(1.e10),
+ fRDecayMin(-1.),
+ fDecayPdg(0),
fImedia(0),
fTransParName("\0"),
fMCQA(0),
fTrackReferences(0)
{
//
- // Copy constructor for AliRun
+ // Copy constructor for AliMC
//
mc.Copy(*this);
}
void AliMC::Copy(TObject &) const
{
//dummy Copy function
- Fatal("Copy","Not implemented!\n");
+ AliFatal("Not implemented!");
}
//_______________________________________________________________________
void AliMC::ConstructGeometry()
{
//
- // Create modules, materials, geometry
+ // Either load geometry from file or create it through usual
+ // loop on detectors. In the first case the method
+ // AliModule::CreateMaterials() only builds fIdtmed and is postponed
+ // at InitGeometry().
//
+ if(gAlice->IsRootGeometry()){
+ // Load geometry
+ const char *geomfilename = gAlice->GetGeometryFileName();
+ if(gSystem->ExpandPathName(geomfilename)){
+ AliInfo(Form("Loading geometry from file:\n %40s\n\n",geomfilename));
+ TGeoManager::Import(geomfilename);
+ }else{
+ AliInfo(Form("Geometry file %40s not found!\n",geomfilename));
+ return;
+ }
+ }else{
+ // Create modules, materials, geometry
TStopwatch stw;
TIter next(gAlice->Modules());
AliModule *detector;
- if (GetDebug()) Info("ConstructGeometry","Geometry creation:");
+ AliDebug(1, "Geometry creation:");
while((detector = dynamic_cast<AliModule*>(next()))) {
stw.Start();
// Initialise detector materials and geometry
detector->CreateMaterials();
detector->CreateGeometry();
- printf("%10s R:%.2fs C:%.2fs\n",
- detector->GetName(),stw.RealTime(),stw.CpuTime());
+ AliInfo(Form("%10s R:%.2fs C:%.2fs",
+ detector->GetName(),stw.RealTime(),stw.CpuTime()));
}
+ }
+
+}
+
+//_______________________________________________________________________
+void AliMC::ConstructOpGeometry()
+{
+ //
+ // Loop all detector modules and call DefineOpticalProperties() method
+ //
+
+ TIter next(gAlice->Modules());
+ AliModule *detector;
+ AliInfo("Optical properties definition");
+ while((detector = dynamic_cast<AliModule*>(next()))) {
+ // Initialise detector optical properties
+ detector->DefineOpticalProperties();
+ }
}
//_______________________________________________________________________
void AliMC::InitGeometry()
{
//
- // Initialize detectors and display geometry
+ // Initialize detectors
//
- printf("Initialisation:\n");
- TStopwatch stw;
- TIter next(gAlice->Modules());
- AliModule *detector;
- while((detector = dynamic_cast<AliModule*>(next()))) {
- stw.Start();
- // Initialise detector and display geometry
- detector->Init();
- detector->BuildGeometry();
- printf("%10s R:%.2fs C:%.2fs\n",
- detector->GetName(),stw.RealTime(),stw.CpuTime());
- }
-
+ AliInfo("Initialisation:");
+ TStopwatch stw;
+ TIter next(gAlice->Modules());
+ AliModule *detector;
+ while((detector = dynamic_cast<AliModule*>(next()))) {
+ stw.Start();
+ // Initialise detector geometry
+ if(gAlice->IsRootGeometry()) detector->CreateMaterials();
+ detector->Init();
+ AliInfo(Form("%10s R:%.2fs C:%.2fs",
+ detector->GetName(),stw.RealTime(),stw.CpuTime()));
+ }
+}
+
+//_______________________________________________________________________
+void AliMC::SetAllAlignableVolumes()
+{
+ //
+ // Add alignable volumes (TGeoPNEntries) looping on all
+ // active modules
+ //
+
+ AliInfo(Form("Setting entries for all alignable volumes of active detectors"));
+ AliModule *detector;
+ TIter next(gAlice->Modules());
+ while((detector = dynamic_cast<AliModule*>(next()))) {
+ detector->AddAlignableVolumes();
+ }
}
//_______________________________________________________________________
//
if(fGenerator)
if(generator)
- Warning("ResetGenerator","Replacing generator %s with %s\n",
- fGenerator->GetName(),generator->GetName());
+ AliWarning(Form("Replacing generator %s with %s",
+ fGenerator->GetName(),generator->GetName()))
else
- Warning("ResetGenerator","Replacing generator %s with NULL\n",
- fGenerator->GetName());
+ AliWarning(Form("Replacing generator %s with NULL",
+ fGenerator->GetName()));
fGenerator = generator;
}
void AliMC::FinishRun()
{
// Clean generator information
- if (GetDebug()) Info("FinishRun"," fGenerator->FinishRun()");
+ AliDebug(1, "fGenerator->FinishRun()");
fGenerator->FinishRun();
//Output energy summary tables
- if (GetDebug()) {
- Info("FinishRun"," EnergySummary()");
- EnergySummary();
- }
-
+ AliDebug(1, "EnergySummary()");
+ ToAliDebug(1, EnergySummary());
}
//_______________________________________________________________________
//
// Called at every step during transport
//
-
- Int_t id = DetFromMate(gMC->GetMedium());
+
+ Int_t id = DetFromMate(gMC->CurrentMedium());
if (id < 0) return;
+
+ if ( gMC->IsNewTrack() &&
+ gMC->TrackTime() == 0. &&
+ fRDecayMin >= 0. &&
+ fRDecayMax > fRDecayMin &&
+ gMC->TrackPid() == fDecayPdg )
+ {
+ FixParticleDecaytime();
+ }
+
+
+
//
// --- If lego option, do it and leave
if (gAlice->Lego())
//Call the appropriate stepping routine;
AliModule *det = dynamic_cast<AliModule*>(gAlice->Modules()->At(id));
if(det && det->StepManagerIsEnabled()) {
- fMCQA->StepManager(id);
+ if(AliLog::GetGlobalDebugLevel()>0) fMCQA->StepManager(id);
det->StepManager();
}
}
//
// Clean-up previous event
// Energy scores
- if (GetDebug())
- {
- Info("BeginEvent",">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
- Info("BeginEvent",">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
- Info("BeginEvent",">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
- Info("BeginEvent"," BEGINNING EVENT ");
- Info("BeginEvent",">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
- Info("BeginEvent",">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
- Info("BeginEvent",">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
- }
+ AliDebug(1, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
+ AliDebug(1, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
+ AliDebug(1, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
+ AliDebug(1, " BEGINNING EVENT ");
+ AliDebug(1, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
+ AliDebug(1, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
+ AliDebug(1, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
AliRunLoader *runloader=gAlice->GetRunLoader();
//Set the next event in Run Loader -> Cleans trees (TreeK and all trees in detectors),
gAlice->SetEventNrInRun(gAlice->GetEventNrInRun()+1);
runloader->SetEventNumber(gAlice->GetEventNrInRun());// sets new files, cleans the previous event stuff, if necessary, etc.,
- if (GetDebug()) Info("BeginEvent","EventNr is %d",gAlice->GetEventNrInRun());
+ AliDebug(1, Form("EventNr is %d",gAlice->GetEventNrInRun()));
fEventEnergy.Reset();
// Clean detector information
if(gAlice->Lego() == 0x0)
{
- if (GetDebug()) Info("BeginEvent"," fRunLoader->MakeTree(K)");
+ AliDebug(1, "fRunLoader->MakeTree(K)");
runloader->MakeTree("K");
}
- if (GetDebug()) Info("BeginEvent"," gMC->SetStack(fRunLoader->Stack())");
+ AliDebug(1, "gMC->SetStack(fRunLoader->Stack())");
gMC->SetStack(gAlice->GetRunLoader()->Stack());//Was in InitMC - but was moved here
//because we don't have guarantee that
//stack pointer is not going to change from event to event
}
- if (GetDebug()) Info("BeginEvent"," ResetHits()");
+ AliDebug(1, "ResetHits()");
ResetHits();
- if (GetDebug()) Info("BeginEvent"," fRunLoader->MakeTree(H)");
+ AliDebug(1, "fRunLoader->MakeTree(H)");
runloader->MakeTree("H");
- if (GetDebug()) Info("BeginEvent"," fRunLoader->MakeTrackRefsContainer()");
+ AliDebug(1, "fRunLoader->MakeTrackRefsContainer()");
runloader->MakeTrackRefsContainer();//for insurance
AliModule *detector;
while((detector = (AliModule*)next()))
{
- if (GetDebug()) Info("BeginEvent"," %s->MakeBranch(H)",detector->GetName());
+ AliDebug(2, Form("%s->MakeBranch(H)",detector->GetName()));
detector->MakeBranch("H");
- if (GetDebug()) Info("BeginEvent"," %s->MakeBranchTR()",detector->GetName());
+ AliDebug(2, Form("%s->MakeBranchTR()",detector->GetName()));
detector->MakeBranchTR();
- if (GetDebug()) Info("BeginEvent"," %s->SetTreeAddress()",detector->GetName());
+ AliDebug(2, Form("%s->SetTreeAddress()",detector->GetName()));
detector->SetTreeAddress();
}
// make branch for AliRun track References
void AliMC::PostTrack()
{
// Posts tracks for each module
- TObjArray &dets = *gAlice->Modules();
- AliModule *module;
-
- for(Int_t i=0; i<=gAlice->GetNdets(); i++)
- if((module = dynamic_cast<AliModule*>(dets[i])))
- module->PostTrack();
+ TObjArray &dets = *gAlice->Modules();
+ AliModule *module;
+
+ for(Int_t i=0; i<=gAlice->GetNdets(); i++)
+ if((module = dynamic_cast<AliModule*>(dets[i])))
+ module->PostTrack();
}
//_______________________________________________________________________
// static Int_t count=0;
// const Int_t times=10;
// This primary is finished, purify stack
+#if ROOT_VERSION_CODE > 262152
if (!(gMC->SecondariesAreOrdered()))
runloader->Stack()->ReorderKine();
+#endif
runloader->Stack()->PurifyKine();
TIter next(gAlice->Modules());
//
//
+
if(gAlice->Lego()) gAlice->Lego()->FinishEvent();
TIter next(gAlice->Modules());
AliStack* stack = runloader->Stack();
if ( (header == 0x0) || (stack == 0x0) )
{//check if we got header and stack. If not cry and exit aliroot
- Fatal("AliRun","Can not get the stack or header from LOADER");
+ AliFatal("Can not get the stack or header from LOADER");
return;//never reached
}
// Update Header information
// Write out the kinematics
- stack->FinishEvent();
+ if (!gAlice->Lego()) stack->FinishEvent();
// Write out the event Header information
TTree* treeE = runloader->TreeE();
}
else
{
- Error("FinishEvent","Can not get TreeE from RL");
+ AliError("Can not get TreeE from RL");
}
if(gAlice->Lego() == 0x0)
runloader->WriteHits("OVERWRITE");
}
- if (GetDebug())
- {
- Info("FinishEvent","<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
- Info("FinishEvent","<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
- Info("FinishEvent","<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
- Info("FinishEvent"," FINISHING EVENT ");
- Info("FinishEvent","<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
- Info("FinishEvent","<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
- Info("FinishEvent","<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
- }
+ AliDebug(1, "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
+ AliDebug(1, "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
+ AliDebug(1, "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
+ AliDebug(1, " FINISHING EVENT ");
+ AliDebug(1, "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
+ AliDebug(1, "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
+ AliDebug(1, "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
}
//_______________________________________________________________________
//=================Create Materials and geometry
gMC->Init();
+ //Set alignable volumes for the whole geometry
+ SetAllAlignableVolumes();
//Read the cuts for all materials
ReadTransPar();
//Build the special IMEDIA table
//Compute cross-sections
gMC->BuildPhysics();
- //Write Geometry object to current file.
- gAlice->GetRunLoader()->WriteGeometry();
-
//Initialise geometry deposition table
fEventEnergy.Set(gMC->NofVolumes()+1);
fSummEnergy.Set(gMC->NofVolumes()+1);
if((det=dynamic_cast<AliModule*>(dets[kz]))) {
TArrayI &idtmed = *(det->GetIdtmed());
for(nz=0;nz<100;nz++) {
+
// Find max and min material number
if((idt=idtmed[nz])) {
det->LoMedium() = det->LoMedium() < idt ? det->LoMedium() : idt;
det->HiMedium() = 0;
} else {
if(det->HiMedium() > fImedia->GetSize()) {
- Error("MediaTable","Increase fImedia from %d to %d",
- fImedia->GetSize(),det->HiMedium());
+ AliError(Form("Increase fImedia from %d to %d",
+ fImedia->GetSize(),det->HiMedium()));
return;
}
// Tag all materials in rage as belonging to detector kz
}
//
// Print summary table
- printf(" Traking media ranges:\n");
+ AliInfo("Tracking media ranges:");
+ ToAliInfo(
for(i=0;i<(ndets-1)/6+1;i++) {
for(k=0;k< (6<ndets-i*6?6:ndets-i*6);k++) {
ind=i*6+k;
}
printf("\n");
}
+ )
}
//_______________________________________________________________________
lun=fopen(filtmp,"r");
delete [] filtmp;
if(!lun) {
- Warning("ReadTransPar","File %s does not exist!\n",fTransParName.Data());
+ AliWarning(Form("File %s does not exist!",fTransParName.Data()));
return;
}
//
- if(fDebug) {
- printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
- printf(" *%59s\n","*");
- printf(" * Please check carefully what you are doing!%10s\n","*");
- printf(" *%59s\n","*");
- }
- //
while(1) {
// Initialise cuts and flags
for(i=0;i<kncuts;i++) cut[i]=-99;
if(iret<0) {
//End of file
fclose(lun);
- if(fDebug){
- printf(" *%59s\n","*");
- printf(" "); for(i=0;i<60;i++) printf("*"); printf("\n");
- }
return;
}
// Read the end of line
if(!iret) continue;
if(iret<0) {
//reading error
- Warning("ReadTransPar","Error reading file %s\n",fTransParName.Data());
+ AliWarning(Form("Error reading file %s",fTransParName.Data()));
continue;
}
// Check that the module exist
if(0<=itmed && itmed < 100) {
ktmed=idtmed[itmed];
if(!ktmed) {
- Warning("ReadTransPar","Invalid tracking medium code %d for %s\n",itmed,mod->GetName());
+ AliWarning(Form("Invalid tracking medium code %d for %s",itmed,mod->GetName()));
continue;
}
// Set energy thresholds
for(kz=0;kz<kncuts;kz++) {
if(cut[kz]>=0) {
- if(fDebug) printf(" * %-6s set to %10.3E for tracking medium code %4d for %s\n",
- kpars[kz],cut[kz],itmed,mod->GetName());
+ AliDebug(2, Form("%-6s set to %10.3E for tracking medium code %4d for %s",
+ kpars[kz],cut[kz],itmed,mod->GetName()));
gMC->Gstpar(ktmed,kpars[kz],cut[kz]);
}
}
// Set transport mechanisms
for(kz=0;kz<knflags;kz++) {
if(flag[kz]>=0) {
- if(fDebug) printf(" * %-6s set to %10d for tracking medium code %4d for %s\n",
- kpars[kncuts+kz],flag[kz],itmed,mod->GetName());
+ AliDebug(2, Form("%-6s set to %10d for tracking medium code %4d for %s",
+ kpars[kncuts+kz],flag[kz],itmed,mod->GetName()));
gMC->Gstpar(ktmed,kpars[kncuts+kz],Float_t(flag[kz]));
}
}
} else {
- Warning("ReadTransPar","Invalid medium code %d *\n",itmed);
+ AliWarning(Form("Invalid medium code %d",itmed));
continue;
}
} else {
- if(fDebug) printf("%s::ReadTransParModule: %s not present\n",ClassName(),detName);
+ AliDebug(1, Form("%s not present",detName));
continue;
}
}
b->Add(fMCQA,"AliMCQA");
}
-//PH
//_______________________________________________________________________
void AliMC::AddHit(Int_t id, Int_t track, Int_t *vol, Float_t *hits) const
{
//
// add a trackrefernce to the list
if (!fTrackReferences) {
- cerr<<"Container trackrefernce not active\n";
+ AliError("Container trackrefernce not active");
return;
}
Int_t nref = fTrackReferences->GetEntriesFast();
// Called at finish primary
//
if (!fTrackReferences) return;
- for (Int_t i=0;i<fTrackReferences->GetEntries();i++){
- AliTrackReference * ref = dynamic_cast<AliTrackReference*>(fTrackReferences->UncheckedAt(i));
- if (ref) {
- Int_t newID = map[ref->GetTrack()];
- if (newID>=0) ref->SetTrack(newID);
- else {
- //ref->SetTrack(-1);
- ref->SetBit(kNotDeleted,kFALSE);
- fTrackReferences->RemoveAt(i);
- }
- }
+ Int_t nEntries = fTrackReferences->GetEntries();
+ for (Int_t i=0; i < nEntries; i++){
+ AliTrackReference * ref = dynamic_cast<AliTrackReference*>(fTrackReferences->UncheckedAt(i));
+ if (ref) {
+ Int_t newID = map[ref->GetTrack()];
+ if (newID>=0) ref->SetTrack(newID);
+ else {
+ ref->SetBit(kNotDeleted,kFALSE);
+ fTrackReferences->RemoveAt(i);
+ }
+ } // if ref
}
fTrackReferences->Compress();
}
+
+void AliMC::FixParticleDecaytime()
+{
+ //
+ // Fix the particle decay time according to rmin and rmax for decays
+ //
+
+ TLorentzVector p;
+ gMC->TrackMomentum(p);
+ Double_t tmin, tmax;
+ Double_t b;
+
+ // Transverse velocity
+ Double_t vt = p.Pt() / p.E();
+
+ if ((b = gAlice->Field()->SolenoidField()) > 0.) { // [kG]
+
+ // Radius of helix
+
+ Double_t rho = p.Pt() / 0.0003 / b; // [cm]
+
+ // Revolution frequency
+
+ Double_t omega = vt / rho;
+
+ // Maximum and minimum decay time
+ //
+ // Check for curlers first
+ if (fRDecayMax * fRDecayMax / rho / rho / 2. > 1.) return;
+
+ //
+
+ tmax = TMath::ACos(1. - fRDecayMax * fRDecayMax / rho / rho / 2.) / omega; // [ct]
+ tmin = TMath::ACos(1. - fRDecayMin * fRDecayMin / rho / rho / 2.) / omega; // [ct]
+ } else {
+ tmax = fRDecayMax / vt; // [ct]
+ tmin = fRDecayMin / vt; // [ct]
+ }
+
+ //
+ // Dial t using the two limits
+ Double_t t = tmin + (tmax - tmin) * gRandom->Rndm(); // [ct]
+ //
+ //
+ // Force decay time in transport code
+ //
+ gMC->ForceDecayTime(t / 2.99792458e10);
+}