// Federico.Carminati@cern.ch
#include <RVersion.h>
-#include <TBrowser.h>
+#include <TArrayI.h>
#include <TClonesArray.h>
+#include <TFile.h>
+#include <TGeoGlobalMagField.h>
#include <TGeoManager.h>
+#include <TParticle.h>
+#include <TROOT.h>
#include <TStopwatch.h>
#include <TSystem.h>
#include <TVirtualMC.h>
-#include <TParticle.h>
-#include <TROOT.h>
-#include <TFile.h>
-#include "AliLog.h"
+#include "AliCDBEntry.h"
+#include "AliCDBManager.h"
+#include "AliCDBStorage.h"
#include "AliDetector.h"
#include "AliGenerator.h"
+#include "AliGeomManager.h"
#include "AliHeader.h"
+#include "AliHit.h"
#include "AliLego.h"
+#include "AliLog.h"
#include "AliMC.h"
-#include "AliMCQA.h"
+#include "AliMagF.h"
#include "AliRun.h"
-#include "AliHit.h"
+#include "AliSimulation.h"
#include "AliStack.h"
-#include "AliMagF.h"
#include "AliTrackReference.h"
-#include "AliSimulation.h"
-#include "AliGeomManager.h"
-#include "AliCDBManager.h"
-#include "AliCDBStorage.h"
-#include "AliCDBEntry.h"
-
ClassImp(AliMC)
fDecayPdg(0),
fImedia(0),
fTransParName("\0"),
- fMCQA(0),
fHitLists(0),
fTmpTreeTR(0),
fTmpFileTR(0),
- fTrackReferences(0),
- fTmpTrackReferences(0)
+ fTrackReferences(),
+ fTmpTrackReferences()
{
//default constructor
fDecayPdg(0),
fImedia(new TArrayI(1000)),
fTransParName("\0"),
- fMCQA(0),
fHitLists(new TList()),
fTmpTreeTR(0),
fTmpFileTR(0),
- fTrackReferences(new TClonesArray("AliTrackReference", 100)),
- fTmpTrackReferences(new TClonesArray("AliTrackReference", 100))
+ fTrackReferences("AliTrackReference", 100),
+ fTmpTrackReferences("AliTrackReference", 100)
{
//constructor
// Set transport parameters
for(Int_t i=0;i<1000;i++) (*fImedia)[i]=-99;
}
-//_______________________________________________________________________
-AliMC::AliMC(const AliMC &mc) :
- TVirtualMCApplication(mc),
- fGenerator(0),
- fEventEnergy(0),
- fSummEnergy(0),
- fSum2Energy(0),
- fTrRmax(1.e10),
- fTrZmax(1.e10),
- fRDecayMax(1.e10),
- fRDecayMin(-1.),
- fDecayPdg(0),
- fImedia(0),
- fTransParName("\0"),
- fMCQA(0),
- fHitLists(0),
- fTmpTreeTR(0),
- fTmpFileTR(0),
- fTrackReferences(0),
- fTmpTrackReferences(0)
-{
- //
- // Copy constructor for AliMC
- //
- mc.Copy(*this);
-}
-
//_______________________________________________________________________
AliMC::~AliMC()
{
//destructor
delete fGenerator;
delete fImedia;
- delete fMCQA;
delete fHitLists;
// Delete track references
- if (fTrackReferences) {
- fTrackReferences->Delete();
- delete fTrackReferences;
- fTrackReferences = 0;
- }
-
-if (fTmpTrackReferences) {
- fTmpTrackReferences->Delete();
- delete fTmpTrackReferences;
- fTmpTrackReferences = 0;
- }
-
-}
-
-//_______________________________________________________________________
-void AliMC::Copy(TObject &) const
-{
- //dummy Copy function
- AliFatal("Not implemented!");
}
//_______________________________________________________________________
}
}else{
// Create modules, materials, geometry
+ if (!gGeoManager) new TGeoManager("ALICE", "ALICE geometry");
TStopwatch stw;
TIter next(gAlice->Modules());
AliModule *detector;
SetAllAlignableVolumes();
}
// Misalign geometry via AliSimulation instance
- if (!AliSimulation::GetInstance()) return kFALSE;
+ if (!AliSimulation::Instance()) return kFALSE;
AliGeomManager::SetGeometry(gGeoManager);
- return AliSimulation::GetInstance()->MisalignGeometry(gAlice->GetRunLoader());
+ if(!AliGeomManager::CheckSymNamesLUT("ALL"))
+ AliFatal("Current loaded geometry differs in the definition of symbolic names!");
+
+ return AliSimulation::Instance()->MisalignGeometry(AliRunLoader::Instance());
}
//_______________________________________________________________________
if((module = dynamic_cast<AliModule*>(dets[i])))
module->PreTrack();
- fMCQA->PreTrack();
}
//_______________________________________________________________________
//
// Called at every step during transport
//
-
Int_t id = DetFromMate(gMC->CurrentMedium());
if (id < 0) return;
//
// --- If lego option, do it and leave
- if (gAlice->Lego())
- gAlice->Lego()->StepManager();
+ if (AliSimulation::Instance()->Lego())
+ AliSimulation::Instance()->Lego()->StepManager();
else {
Int_t copy;
//Update energy deposition tables
AddEnergyDeposit(gMC->CurrentVolID(copy),gMC->Edep());
//
// write tracke reference for track which is dissapearing - MI
- if (gMC->IsTrackDisappeared()) {
- if (gMC->Etot()>0.05) AddTrackReference(GetCurrentTrackNumber(),
+
+ if (gMC->IsTrackDisappeared() && !(gMC->IsTrackAlive())) {
+ if (gMC->Etot() > 0.05) AddTrackReference(GetCurrentTrackNumber(),
AliTrackReference::kDisappeared);
+
+
}
-
+
//Call the appropriate stepping routine;
AliModule *det = dynamic_cast<AliModule*>(gAlice->Modules()->At(id));
if(det && det->StepManagerIsEnabled()) {
- if(AliLog::GetGlobalDebugLevel()>0) fMCQA->StepManager(id);
det->StepManager();
}
}
Float_t ed, ed2;
Int_t kn, i, left, j, id;
const Float_t kzero=0;
- Int_t ievent=gAlice->GetRunLoader()->GetHeader()->GetEvent()+1;
+ Int_t ievent=AliRunLoader::Instance()->GetHeader()->GetEvent()+1;
//
// Energy loss information
if(ievent) {
AliDebug(1, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
AliDebug(1, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
- AliRunLoader *runloader=gAlice->GetRunLoader();
+ AliRunLoader *runloader=AliRunLoader::Instance();
/*******************************/
/* Clean after eventual */
runloader->MakeStack();//or make a new one
- if(gAlice->Lego() == 0x0)
+ if(AliSimulation::Instance()->Lego() == 0x0)
{
AliDebug(1, "fRunLoader->MakeTree(K)");
runloader->MakeTree("K");
}
AliDebug(1, "gMC->SetStack(fRunLoader->Stack())");
- gMC->SetStack(gAlice->GetRunLoader()->Stack());//Was in InitMC - but was moved here
+ gMC->SetStack(runloader->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
//since it bellobgs to header and is obtained via RunLoader
// Reset all Detectors & kinematics & make/reset trees
//
- runloader->GetHeader()->Reset(gAlice->GetRunNumber(),gAlice->GetEvNumber(),
+ runloader->GetHeader()->Reset(AliCDBManager::Instance()->GetRun(),gAlice->GetEvNumber(),
gAlice->GetEventNrInRun());
// fRunLoader->WriteKinematics("OVERWRITE"); is there any reason to rewrite here since MakeTree does so
- if(gAlice->Lego())
+ if(AliSimulation::Instance()->Lego())
{
- gAlice->Lego()->BeginEvent();
+ AliSimulation::Instance()->Lego()->BeginEvent();
return;
}
}
}
+//_______________________________________________________________________
+void AliMC::ResetDigits()
+{
+ //
+ // Reset all Detectors digits
+ //
+ TIter next(gAlice->Modules());
+ AliModule *detector;
+ while((detector = dynamic_cast<AliModule*>(next()))) {
+ detector->ResetDigits();
+ }
+}
+
+//_______________________________________________________________________
+void AliMC::ResetSDigits()
+{
+ //
+ // Reset all Detectors digits
+ //
+ TIter next(gAlice->Modules());
+ AliModule *detector;
+ while((detector = dynamic_cast<AliModule*>(next()))) {
+ detector->ResetSDigits();
+ }
+}
+
//_______________________________________________________________________
void AliMC::PostTrack()
{
//
// Called at the end of each primary track
//
- AliRunLoader *runloader=gAlice->GetRunLoader();
+ AliRunLoader *runloader=AliRunLoader::Instance();
// 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();
- RemapHits();
+ if (runloader->Stack()->ReorderKine()) RemapHits();
}
#endif
- runloader->Stack()->PurifyKine();
-
- RemapHits();
+ if (runloader->Stack()->PurifyKine()) RemapHits();
TIter next(gAlice->Modules());
AliModule *detector;
{
//
// Remaps the track labels of the hits
- AliRunLoader *runloader=gAlice->GetRunLoader();
+ AliRunLoader *runloader=AliRunLoader::Instance();
AliStack* stack = runloader->Stack();
TList* hitLists = GetHitLists();
TIter next(hitLists);
//
- if(gAlice->Lego()) gAlice->Lego()->FinishEvent();
+ if(AliSimulation::Instance()->Lego()) AliSimulation::Instance()->Lego()->FinishEvent();
TIter next(gAlice->Modules());
AliModule *detector;
fSum2Energy[i]+=fEventEnergy[i]*fEventEnergy[i];
}
- AliRunLoader *runloader=gAlice->GetRunLoader();
+ AliRunLoader *runloader=AliRunLoader::Instance();
AliHeader* header = runloader->GetHeader();
AliStack* stack = runloader->Stack();
header->SetNtrack(stack->GetNtrack());
// Write out the kinematics
- if (!gAlice->Lego()) stack->FinishEvent();
+ if (!AliSimulation::Instance()->Lego()) stack->FinishEvent();
// Synchronize the TreeTR with TreeK
if (fTmpTreeTR) ReorderAndExpandTreeTR();
AliError("Can not get TreeE from RL");
}
- if(gAlice->Lego() == 0x0)
+ if(AliSimulation::Instance()->Lego() == 0x0)
{
runloader->WriteKinematics("OVERWRITE");
runloader->WriteTrackRefs("OVERWRITE");
AliDebug(1, "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
}
-//_______________________________________________________________________
-void AliMC::Field(const Double_t* x, Double_t* b) const
-{
- // Calculates field "b" at point "x"
- gAlice->Field(x,b);
-}
-
//_______________________________________________________________________
void AliMC::Init()
{
fSummEnergy.Set(gMC->NofVolumes()+1);
fSum2Energy.Set(gMC->NofVolumes()+1);
- //
- fMCQA = new AliMCQA(gAlice->GetNdets());
-
// Register MC in configuration
AliConfig::Instance()->Add(gMC);
fTransParName = filename;
}
-//_______________________________________________________________________
-void AliMC::Browse(TBrowser *b)
-{
- //
- // Called when the item "Run" is clicked on the left pane
- // of the Root browser.
- // It displays the Root Trees and all detectors.
- //
- //detectors are in folders anyway
- b->Add(fMCQA,"AliMCQA");
-}
-
//_______________________________________________________________________
void AliMC::AddHit(Int_t id, Int_t track, Int_t *vol, Float_t *hits) const
{
//
// Returns current track
//
- return gAlice->GetRunLoader()->Stack()->GetCurrentTrackNumber();
+ return AliRunLoader::Instance()->Stack()->GetCurrentTrackNumber();
}
//_______________________________________________________________________
//
// Dumps particle i in the stack
//
- AliRunLoader * runloader = gAlice->GetRunLoader();
+ AliRunLoader * runloader = AliRunLoader::Instance();
if (runloader->Stack())
runloader->Stack()->DumpPart(i);
}
//
// Dumps the particle stack
//
- AliRunLoader * runloader = gAlice->GetRunLoader();
+ AliRunLoader * runloader = AliRunLoader::Instance();
if (runloader->Stack())
runloader->Stack()->DumpPStack();
}
// Returns number of tracks in stack
//
Int_t ntracks = -1;
- AliRunLoader * runloader = gAlice->GetRunLoader();
+ AliRunLoader * runloader = AliRunLoader::Instance();
if (runloader->Stack())
ntracks = runloader->Stack()->GetNtrack();
return ntracks;
// return number of primary that has generated track
//
Int_t nprimary = -999;
- AliRunLoader * runloader = gAlice->GetRunLoader();
+ AliRunLoader * runloader = AliRunLoader::Instance();
if (runloader->Stack())
nprimary = runloader->Stack()->GetPrimary(track);
return nprimary;
{
// Returns the i-th particle from the stack taking into account
// the remaping done by PurifyKine
- AliRunLoader * runloader = gAlice->GetRunLoader();
+ AliRunLoader * runloader = AliRunLoader::Instance();
if (runloader)
if (runloader->Stack())
return runloader->Stack()->Particle(i);
}
//_______________________________________________________________________
-TObjArray* AliMC::Particles() const {
+const TObjArray* AliMC::Particles() const {
//
// Returns pointer to Particles array
//
- AliRunLoader * runloader = gAlice->GetRunLoader();
+ AliRunLoader * runloader = AliRunLoader::Instance();
if (runloader)
if (runloader->Stack())
return runloader->Stack()->Particles();
}
//_______________________________________________________________________
-void AliMC::PushTrack(Int_t done, Int_t parent, Int_t pdg, Float_t *pmom,
- Float_t *vpos, Float_t *polar, Float_t tof,
+void AliMC::PushTrack(Int_t done, Int_t parent, Int_t pdg, const Float_t *pmom,
+ const Float_t *vpos, const Float_t *polar, Float_t tof,
TMCProcess mech, Int_t &ntr, Float_t weight, Int_t is) const
{
// Delegate to stack
//
- AliRunLoader * runloader = gAlice->GetRunLoader();
+ AliRunLoader * runloader = AliRunLoader::Instance();
if (runloader)
if (runloader->Stack())
runloader->Stack()->PushTrack(done, parent, pdg, pmom, vpos, polar, tof,
{
// Delegate to stack
//
- AliRunLoader * runloader = gAlice->GetRunLoader();
+ AliRunLoader * runloader = AliRunLoader::Instance();
if (runloader)
if (runloader->Stack())
runloader->Stack()->PushTrack(done, parent, pdg, px, py, pz, e, vx, vy, vz, tof,
{
//
// Set high water mark for last track in event
- AliRunLoader * runloader = gAlice->GetRunLoader();
+ AliRunLoader * runloader = AliRunLoader::Instance();
if (runloader)
if (runloader->Stack())
runloader->Stack()->SetHighWaterMark(nt);
//
// Delegate to stack
//
- AliRunLoader * runloader = gAlice->GetRunLoader();
+ AliRunLoader * runloader = AliRunLoader::Instance();
if (runloader)
if (runloader->Stack())
runloader->Stack()->KeepTrack(track);
{
// Delegate to stack
//
- AliRunLoader * runloader = gAlice->GetRunLoader();
+ AliRunLoader * runloader = AliRunLoader::Instance();
if (runloader)
if (runloader->Stack())
runloader->Stack()->FlagTrack(track);
//
// Set current track number
//
- AliRunLoader * runloader = gAlice->GetRunLoader();
+ AliRunLoader * runloader = AliRunLoader::Instance();
if (runloader)
if (runloader->Stack())
runloader->Stack()->SetCurrentTrack(track);
{
//
// add a trackrefernce to the list
- if (!fTrackReferences) {
- AliError("Container trackrefernce not active");
- return NULL;
- }
Int_t primary = GetPrimary(label);
Particle(primary)->SetBit(kKeepBit);
- Int_t nref = fTmpTrackReferences->GetEntriesFast();
- TClonesArray &lref = *fTmpTrackReferences;
- return new(lref[nref]) AliTrackReference(label, id);
+ Int_t nref = fTmpTrackReferences.GetEntriesFast();
+ return new(fTmpTrackReferences[nref]) AliTrackReference(label, id);
}
//
// Reset all references
//
- if (fTmpTrackReferences) fTmpTrackReferences->Clear();
+ fTmpTrackReferences.Clear();
}
void AliMC::RemapTrackReferencesIDs(Int_t *map)
// Remapping track reference
// Called at finish primary
//
- if (!fTmpTrackReferences) return;
- Int_t nEntries = fTmpTrackReferences->GetEntries();
+
+ Int_t nEntries = fTmpTrackReferences.GetEntries();
for (Int_t i=0; i < nEntries; i++){
- AliTrackReference * ref = dynamic_cast<AliTrackReference*>(fTmpTrackReferences->UncheckedAt(i));
+ AliTrackReference * ref = dynamic_cast<AliTrackReference*>(fTmpTrackReferences.UncheckedAt(i));
if (ref) {
Int_t newID = map[ref->GetTrack()];
if (newID>=0) ref->SetTrack(newID);
else {
ref->SetBit(kNotDeleted,kFALSE);
- fTmpTrackReferences->RemoveAt(i);
+ fTmpTrackReferences.RemoveAt(i);
}
} // if ref
}
- fTmpTrackReferences->Compress();
+ fTmpTrackReferences.Compress();
}
void AliMC::FixParticleDecaytime()
// Transverse velocity
Double_t vt = p.Pt() / p.E();
- if ((b = gAlice->Field()->SolenoidField()) > 0.) { // [kG]
+ if ((b = ((AliMagF*)TGeoGlobalMagField::Instance()->GetField())->SolenoidField()) > 0.) { // [kG]
// Radius of helix
// Make the temporary track reference tree
fTmpFileTR = new TFile("TrackRefsTmp.root", "recreate");
fTmpTreeTR = new TTree("TreeTR", "Track References");
- if (!fTmpTrackReferences) fTmpTrackReferences = new TClonesArray("AliTrackReference", 100);
- fTmpTreeTR->Branch("TrackReferences", "TClonesArray", &fTmpTrackReferences, 4000);
+ TClonesArray* pRef = &fTmpTrackReferences;
+ fTmpTreeTR->Branch("TrackReferences", "TClonesArray", &pRef, 4000);
}
void AliMC::ReorderAndExpandTreeTR()
// Reorder and expand the temporary track reference tree in order to match the kinematics tree
//
- AliRunLoader *rl = gAlice->GetRunLoader();
+ AliRunLoader *rl = AliRunLoader::Instance();
//
// TreeTR
AliDebug(1, "fRunLoader->MakeTrackRefsContainer()");
TTree * treeTR = rl->TreeTR();
if (treeTR){
// make branch for central track references
- if (!fTrackReferences) fTrackReferences = new TClonesArray("AliTrackReference",0);
TBranch *branch;
- branch = treeTR->Branch("TrackReferences",&fTrackReferences);
- branch->SetAddress(&fTrackReferences);
+ TClonesArray* pRef = &fTrackReferences;
+ branch = treeTR->Branch("TrackReferences", &pRef);
+ branch->SetAddress(&pRef);
}
AliStack* stack = rl->Stack();
Int_t it = 0;
for (Int_t ip = np - 1; ip > -1; ip--) {
TParticle *part = stack->Particle(ip);
-// printf("Particle %5d %5d %5d %5d %5d \n", ip, part->GetPdgCode(), part->GetFirstMother(), part->GetFirstDaughter(), part->GetLastDaughter());
+ //printf("Particle %5d %5d %5d %5d %5d \n", ip, part->GetPdgCode(), part->GetFirstMother(), part->GetFirstDaughter(), part->GetLastDaughter());
// Skip primaries that have not been transported
Int_t dau1 = part->GetFirstDaughter();
Int_t dau2 = -1;
- // if ((dau1 > -1 && dau1 < np) || part->GetStatusCode() > 1) continue;
if (!part->TestBit(kTransportBit)) continue;
//
fTmpTreeTR->GetEntry(it++);
- Int_t nh = fTmpTrackReferences->GetEntries();
+ Int_t nh = fTmpTrackReferences.GetEntries();
// Determine range of secondaries produced by this primary
if (dau1 > -1) {
Int_t inext = ip - 1;
if (inext >= 0) {
part = stack->Particle(inext);
dau2 = part->GetFirstDaughter();
- if (dau2 == -1 || dau2 < np) {
+ if (!(part->TestBit(kTransportBit)) || dau2 == -1 || dau2 < np) {
+// if (dau2 == -1 || dau2 < np) {
dau2 = -1;
} else {
dau2--;
} // find upper bound
} // dau2 < 0
// printf("Check (1) %5d %5d %5d %5d %5d \n", ip, np, it, dau1, dau2);
-
//
// Loop over reference hits and find secondary label
for (Int_t id = dau1; (id <= dau2) && (dau1 > -1); id++) {
for (Int_t ih = 0; ih < nh; ih++) {
- AliTrackReference* tr = (AliTrackReference*) fTmpTrackReferences->At(ih);
+ AliTrackReference* tr = (AliTrackReference*) fTmpTrackReferences.At(ih);
Int_t label = tr->Label();
// Skip primaries
if (label == ip) continue;
AliWarning(Form("Track Reference Label out of range !: %5d %5d %5d \n", label, dau1, dau2));
if (label == id) {
// secondary found
- Int_t nref = fTrackReferences->GetEntriesFast();
- TClonesArray &lref = *fTrackReferences;
- new(lref[nref]) AliTrackReference(*tr);
+ Int_t nref = fTrackReferences.GetEntriesFast();
+ new(fTrackReferences[nref]) AliTrackReference(*tr);
}
} // hits
treeTR->Fill();
- fTrackReferences->Clear();
+ fTrackReferences.Clear();
ifills++;
} // daughters
} // tracks
{
// Skip particles that have not been transported
fTmpTreeTR->GetEntry(it--);
- Int_t nh = fTmpTrackReferences->GetEntries();
+ Int_t nh = fTmpTrackReferences.GetEntries();
//
// Loop over reference hits and find primary labels
for (Int_t ih = 0; ih < nh; ih++) {
- AliTrackReference* tr = (AliTrackReference*) fTmpTrackReferences->At(ih);
+ AliTrackReference* tr = (AliTrackReference*) fTmpTrackReferences.At(ih);
Int_t label = tr->Label();
if (label == ip) {
- Int_t nref = fTrackReferences->GetEntriesFast();
- TClonesArray &lref = *fTrackReferences;
- new(lref[nref]) AliTrackReference(*tr);
+ Int_t nref = fTrackReferences.GetEntriesFast();
+ new(fTrackReferences[nref]) AliTrackReference(*tr);
}
}
}
treeTR->Fill();
- fTrackReferences->Clear();
+ fTrackReferences.Clear();
ifills++;
} // tracks
// Check
delete fTmpTreeTR;
fTmpFileTR->Close();
delete fTmpFileTR;
- delete fTmpTrackReferences;
- fTmpTrackReferences = 0;
+ fTmpTrackReferences.Clear();
gSystem->Exec("rm -rf TrackRefsTmp.root");
}