Protection in Physical node
[u/mrichter/AliRoot.git] / HMPID / AliHMPIDParam.cxx
index b8822a541811a065f6408ead39c33e7861bb96e0..5ae43cbbb16eb60e592a160a5d37b0a1a569d29a 100644 (file)
 #include <AliRunLoader.h>  //Stack()
 #include <AliStack.h>      //Stack()
 #include <TParticle.h>     //Stack()    
+#include <TGeoPhysicalNode.h> //ctor
 
 ClassImp(AliHMPIDParam)
 
 AliHMPIDParam* AliHMPIDParam::fgInstance=0x0;        //singleton pointer               
 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-AliHMPIDParam::AliHMPIDParam():TNamed("RichParam","default version") 
+AliHMPIDParam::AliHMPIDParam():TNamed("HmpidParam","default version") 
 {
 // Here all the intitializition is taken place when AliHMPIDParam::Instance() is invoked for the first time.
 // In particulare, matrices to be used for LORS<->MARS trasnformations are initialized from TGeo structure.    
 // Note that TGeoManager should be already initialized from geometry.root file  
   fX=0.5*AliHMPIDDigit::SizeAllX();
   fY=0.5*AliHMPIDDigit::SizeAllY();
-  for(Int_t i=0;i<7;i++) 
-    if(gGeoManager)
-      fM[i]=(TGeoHMatrix*)gGeoManager->GetVolume("ALIC")->GetNode(Form("HMPID_%i",i))->GetMatrix();
-    else{
+  for(Int_t i=AliHMPIDDigit::kMinCh;i<=AliHMPIDDigit::kMaxCh;i++) 
+    if(gGeoManager && gGeoManager->IsClosed()) {
+//      fM[i]=(TGeoHMatrix*)gGeoManager->GetVolume("ALIC")->GetNode(Form("HMPID_%i",i))->GetMatrix(); // previous style
+      TGeoPNEntry* pne = gGeoManager->GetAlignableEntry(Form("/HMPID/Chamber%i",i));
+      if (!pne) {
+        AliErrorClass(Form("The symbolic volume %s does not correspond to any physical entry!",Form("HMPID_%i",i)));
+        fM[i]=new TGeoHMatrix;
+        IdealPosition(i,fM[i]);
+      } else {
+        TGeoPhysicalNode *pnode = pne->GetPhysicalNode();
+        if(pnode) fM[i]=pnode->GetMatrix();
+        else {
+          fM[i]=new TGeoHMatrix;
+          IdealPosition(i,fM[i]);
+        }
+      }
+    } else{
       fM[i]=new TGeoHMatrix;
       IdealPosition(i,fM[i]);
     }