prevent running if CDB snapshot setting failed
[u/mrichter/AliRoot.git] / STEER / STEER / AliTransportMonitor.cxx
index b86eff3..9f2135f 100644 (file)
@@ -29,6 +29,7 @@
 #include "TH2F.h"
 #include "TGeoManager.h"
 #include "AliPDG.h"
+#include "TVirtualMC.h"
 
 ClassImp(AliTransportMonitor)
 ClassImp(AliTransportMonitor::AliTransportMonitorVol)
@@ -41,6 +42,7 @@ AliTransportMonitor::AliTransportMonitorVol::AliTransportMonitorVol()
                     :TNamed(),
                      fNtypes(0),
                      fTotalTime(0),
+                     fNSteps(0),
                      fPData(0),
                      fTimeRZ(0),
                      fParticles()
@@ -68,6 +70,7 @@ void AliTransportMonitor::AliTransportMonitorVol::StepInfo(
   data.fEdt += energy*dt;
   data.fTime += dt;
   fTotalTime += dt;
+  fNSteps += 1.;
   if (!fTimeRZ) {
     Bool_t status = TH1::AddDirectoryStatus();
     TH1::AddDirectory(kFALSE);
@@ -86,6 +89,20 @@ PMonData &AliTransportMonitor::AliTransportMonitorVol::GetPMonData(Int_t pdg)
 
   // The object could have been retrieved from file, in which case we have to 
   // build the map.
+  //
+  // unknown heavy fragment ?
+  //  TParticlePDG* pdgP = (TDatabasePDG::Instance())->GetParticle(pdg);
+  Int_t apdg = TMath::Abs(pdg);
+  if ((apdg > 10000) 
+      && (apdg != 1000010020)
+      && (apdg != 1000010030)
+      && (apdg != 1000020030)
+      && (apdg != 1000020040)
+      && (apdg != 50000050)
+      && (apdg != 50000051)
+      ) 
+    pdg = 1111111111; 
+
   PMonData *data;
   if (fNtypes) {
     if (fParticles.empty()) {
@@ -106,7 +123,9 @@ PMonData &AliTransportMonitor::AliTransportMonitorVol::GetPMonData(Int_t pdg)
      TDatabasePDG *pdgDB = TDatabasePDG::Instance();
      if (!pdgDB->ParticleList()) AliPDG::AddParticlesToPdgDataBase();
      Int_t size = pdgDB->ParticleList()->GetSize();
-     fPData = new PMonData[size];
+     // account for heavy fragments coded as "1111111111"
+     //
+     fPData = new PMonData[size+10];
      data = &fPData[fNtypes];
      data->fPDG = pdg;
      fParticles[pdg] = fNtypes++;
@@ -116,7 +135,9 @@ PMonData &AliTransportMonitor::AliTransportMonitorVol::GetPMonData(Int_t pdg)
 
 void AliTransportMonitor::AliTransportMonitorVol::Merge(AliTransportMonitorVol* volM) 
 {
+  //
   // Merging
+  //
   fTotalTime = (fTotalTime + volM->GetTotalTime());
   if (fTimeRZ && volM->GetHistogram()) {
     fTimeRZ->Add(volM->GetHistogram()); 
@@ -125,13 +146,11 @@ void AliTransportMonitor::AliTransportMonitorVol::Merge(AliTransportMonitorVol*
   }
 
   Int_t ntypes = volM->GetNtypes();
-  Int_t ntypes2 = GetNtypes();
   for (Int_t i = 0; i < ntypes; i++) {
     Int_t pdg = volM->GetPDG(i);
-    //PMonData &data  = GetPMonData(pdg);
-    //PMonData &dataM = volM->GetPMonData(pdg);
-    //data.fEdt  += dataM.fEdt;
-    //data.fTime += dataM.fTime;
+     PMonData &data  = GetPMonData(pdg);
+     data.fEdt  += (volM->GetEmed(i) * volM->GetTotalTime());
+     data.fTime += (volM->GetTime(i));
   }
 }
 
@@ -159,7 +178,7 @@ AliTransportMonitor::AliTransportMonitor(Int_t nvolumes)
   fVolumeMon->SetOwner();
   for (Int_t i=0; i<nvolumes; i++) {
     AliTransportMonitorVol *volMon = new AliTransportMonitorVol();
-    if (gGeoManager) volMon->SetName(gGeoManager->GetListOfUVolumes()->At(i)->GetName());
+    if (TVirtualMC::GetMC()) volMon->SetName(TVirtualMC::GetMC()->VolName(i));
     fVolumeMon->Add(volMon);
   }   
 }
@@ -203,14 +222,20 @@ void AliTransportMonitor::Print(Option_t *volName) const
       timeperpart[i] = volMon->GetTime(i); 
       timepervol += timeperpart[i];
     }
-    printf("Volume %s: Transport time: %g%% of %g [s]\n", volMon->GetName(), 100.*timepervol/fTotalTime, fTotalTime);
+    printf("Volume %s: Transport time: %g%% of %g %g [s]\n", volMon->GetName(), 100.*timepervol/fTotalTime, fTotalTime,
+          volMon->GetTotalTime());
     TMath::Sort(ntypes, timeperpart, isort, kTRUE);
     TString particle;
     TDatabasePDG *pdgDB = TDatabasePDG::Instance();    
     if (!pdgDB->ParticleList()) AliPDG::AddParticlesToPdgDataBase();
     for (i=0; i<ntypes; i++)  {
        timeperpart[i] /=  timepervol;
-       particle = pdgDB->GetParticle(volMon->GetPDG(isort[i]))->GetName();
+       TParticlePDG* pdgP =  pdgDB->GetParticle(volMon->GetPDG(isort[i]));
+       if (pdgP) {
+        particle = pdgDB->GetParticle(volMon->GetPDG(isort[i]))->GetName();
+       } else {
+        particle = Form("pdg code not in DB: %d", volMon->GetPDG(isort[i]));
+       }
        printf("   %s: %g%%  mean energy: %g\n", particle.Data(), 100.*timeperpart[i], volMon->GetEmed(i));
     }
     if (volMon->GetHistogram()) {
@@ -228,7 +253,7 @@ void AliTransportMonitor::Print(Option_t *volName) const
   TIter next(fVolumeMon);
   AliTransportMonitorVol *volMon;
   Int_t ncrossed = 0;
-  TH1F *hnames = new TH1F("volume timing", "relative volume timing", 3,0,3);
+  TH1F *hnames = new TH1F("volume_timing", "relative volume timing", 3,0,3);
   hnames->SetStats(0);
   hnames->SetFillColor(38);
   hnames->SetBit(TH1::kCanRebin);
@@ -307,7 +332,22 @@ void AliTransportMonitor::Export(const char *fname)
 //______________________________________________________________________________
 void AliTransportMonitor::Merge(AliTransportMonitor* mergeMon)
 {
+
   // merge with monitor 
+  if (!fVolumeMon) 
+    {
+      TObjArray* arr = mergeMon->GetVolumes();
+      Int_t nvol = arr->GetEntriesFast();
+      fVolumeMon = new TObjArray(nvol);
+      fVolumeMon->SetOwner();
+      for (Int_t i = 0; i < nvol; i++) {
+       AliTransportMonitorVol *volMon = new AliTransportMonitorVol();
+       volMon->SetName(arr->At(i)->GetName());
+       fVolumeMon->Add(volMon);
+      }
+    } // first time
+
+
   Int_t n = fVolumeMon->GetEntriesFast();
   TObjArray* mergeVols = mergeMon->GetVolumes();
   fTotalTime = 0;