Cosmetics, init values provided in c'tor
[u/mrichter/AliRoot.git] / STEER / AliGeomManager.cxx
index 07373de..10be86c 100644 (file)
 #include <TGeoMatrix.h>
 #include <TGeoPhysicalNode.h>
 #include <TSystem.h>
+#include <TStopwatch.h>
+#include <TGeoOverlap.h>
+#include <TPluginManager.h>
+#include <TROOT.h>
 
 #include "AliGeomManager.h"
 #include "AliLog.h"
 #include "AliAlignObj.h"
-#include "AliAlignObjAngles.h"
+#include "AliAlignObjParams.h"
 #include "AliCDBManager.h"
 #include "AliCDBStorage.h"
 #include "AliCDBEntry.h"
@@ -48,7 +52,8 @@ Int_t AliGeomManager::fgLayerSize[kLastLayer - kFirstLayer] = {
   1638,     // TOF
   5, 5,     // PHOS,CPV
   7,        // HMPID ??
-  1         // MUON ??
+  1,         // MUON ??
+  12        // EMCAL
 };
 
 const char* AliGeomManager::fgLayerName[kLastLayer - kFirstLayer] = {
@@ -60,8 +65,9 @@ const char* AliGeomManager::fgLayerName[kLastLayer - kFirstLayer] = {
   "TRD chambers layer 4", "TRD chambers layer 5", "TRD chambers layer 6",
   "TOF layer",
   "PHOS EMC layer","PHOS CPV layer",
-  "HMPID layer",
-  "?"
+  "HMPID layer", 
+  "MUON ?",
+  "EMCAL layer"
 };
 
 TString* AliGeomManager::fgSymName[kLastLayer - kFirstLayer] = {
@@ -74,6 +80,7 @@ TString* AliGeomManager::fgSymName[kLastLayer - kFirstLayer] = {
   0x0,
   0x0,0x0,
   0x0,
+  0x0,
   0x0
 };
 
@@ -87,6 +94,7 @@ TGeoPNEntry** AliGeomManager::fgPNEntry[kLastLayer - kFirstLayer] = {
   0x0,
   0x0,0x0,
   0x0,
+  0x0,
   0x0
 };
 
@@ -100,6 +108,7 @@ TGeoHMatrix** AliGeomManager::fgOrigMatrix[kLastLayer - kFirstLayer] = {
   0x0,
   0x0,0x0,
   0x0,
+  0x0,
   0x0
 };
 
@@ -113,6 +122,7 @@ AliAlignObj** AliGeomManager::fgAlignObjs[kLastLayer - kFirstLayer] = {
   0x0,
   0x0,0x0,
   0x0,
+  0x0,
   0x0
 };
 
@@ -414,7 +424,7 @@ void  AliGeomManager::InitAlignObjFromGeometry()
     fgAlignObjs[iLayer-kFirstLayer] = new AliAlignObj*[LayerSize(iLayer)];
     for (Int_t iModule = 0; iModule < LayerSize(iLayer); iModule++) {
       UShort_t volid = LayerToVolUID(iLayer,iModule);
-      fgAlignObjs[iLayer-kFirstLayer][iModule] = new AliAlignObjAngles("",volid,0,0,0,0,0,0,kTRUE);
+      fgAlignObjs[iLayer-kFirstLayer][iModule] = new AliAlignObjParams("",volid,0,0,0,0,0,0,kTRUE);
       const char *symname = SymName(volid);
       if (!GetFromGeometry(symname, *fgAlignObjs[iLayer-kFirstLayer][iModule]))
        AliErrorClass(Form("Failed to extract the alignment object for the volume (ID=%d and path=%s) !",volid,symname));
@@ -834,6 +844,22 @@ void AliGeomManager::InitSymNamesLUT()
     }
   }
 
+  /*********************      EMCAL layer   ***********************/
+  {
+    TString str = "EMCAL/FullSupermodule";
+    modnum=0;
+
+    for (Int_t iModule=1; iModule <= 12; iModule++) {
+      symname = str;
+      symname += iModule;
+      if(iModule >10) {
+       symname = "EMCAL/HalfSupermodule";
+       symname += iModule-10;
+      }
+      modnum = iModule-1;
+      fgSymName[kEMCAL-kFirstLayer][modnum] = symname.Data();
+    }
+  }
 
 }
 
@@ -968,6 +994,40 @@ Bool_t AliGeomManager::GetRotation(Int_t index, Double_t r[9])
   return kTRUE;
 }
 
+//_____________________________________________________________________________
+Bool_t AliGeomManager::GetDeltaForBranch(Int_t index, TGeoHMatrix &inclusiveD)
+{
+  // The method sets the matrix passed as argument as the global delta
+  // (for the volume referred by the unique index) including the displacements
+  // of all parent volumes in the branch.
+  //
+  const char* symname = SymName(index);
+  if(!symname) return kFALSE;
+
+  TGeoHMatrix go,invgo;
+  go = *GetOrigGlobalMatrix(index);
+  invgo = go.Inverse();
+  inclusiveD = *GetMatrix(symname);
+  inclusiveD.Multiply(&invgo);
+
+  return kTRUE;
+}
+
+//_____________________________________________________________________________
+Bool_t AliGeomManager::GetDeltaForBranch(AliAlignObj& aao, TGeoHMatrix &inclusiveD)
+{
+  // The method sets the matrix passed as argument as the global delta
+  // (for the volume referred by the alignment object) including the displacements
+  // of all parent volumes in the brach.
+  //
+  Int_t index = aao.GetVolUID();
+  if(!index){
+    AliErrorClass("Either the alignment object or its index are not valid");
+    return kFALSE;
+  }
+  return GetDeltaForBranch(index, inclusiveD);
+}
+
 //______________________________________________________________________
 Bool_t AliGeomManager::GetOrigGlobalMatrix(const char* symname, TGeoHMatrix &m) 
 {
@@ -1184,6 +1244,56 @@ TGeoPNEntry* AliGeomManager::GetPNEntry(ELayerID layerId, Int_t modId)
 }
 
 //_____________________________________________________________________________
+void AliGeomManager::CheckOverlapsOverPNs(Double_t threshold)
+{
+  // Check for overlaps/extrusions on physical nodes only;
+  // this overlap-checker is meant to be used to check overlaps/extrusions
+  // originated by the application of alignment objects.
+  //
+
+  TObjArray* ovexlist = new TObjArray(64);
+
+  AliInfoClass("********* Checking overlaps/extrusions over physical nodes only *********");
+  TObjArray* pnList = gGeoManager->GetListOfPhysicalNodes();
+  TGeoVolume* mvol = 0;
+  TGeoPhysicalNode* pn;
+  TObjArray* overlaps = new TObjArray(64);
+  overlaps->SetOwner();
+
+  TStopwatch timer2;
+  timer2.Start();
+  for(Int_t pni=0; pni<pnList->GetEntriesFast(); pni++){
+    pn = (TGeoPhysicalNode*) pnList->UncheckedAt(pni);
+    // checking the volume of the mother (go upper in the tree in case it is an assembly)
+    Int_t levup=1;
+    while(((TGeoVolume*)pn->GetVolume(pn->GetLevel()-levup))->IsAssembly()) levup++;
+      //Printf("Going to upper level");
+    mvol = pn->GetVolume(pn->GetLevel()-levup);
+    if(!mvol->IsSelected()){
+      AliInfoClass(Form("Checking overlaps for volume %s",mvol->GetName()));
+      mvol->CheckOverlaps(threshold);
+      ovexlist = gGeoManager->GetListOfOverlaps();
+      TIter next(ovexlist);
+      TGeoOverlap *ov;
+      while ((ov=(TGeoOverlap*)next())) overlaps->Add(ov->Clone());
+      mvol->SelectVolume();
+    }
+  }
+  mvol->SelectVolume(kTRUE); // clears the list of selected volumes
+
+  AliInfoClass(Form("Number of overlapping/extruding PNs: %d",overlaps->GetEntriesFast()));
+  timer2.Stop();
+  timer2.Print();
+
+  TIter nextN(overlaps);
+  TGeoOverlap *ovlp;
+  while ((ovlp=(TGeoOverlap*)nextN())) ovlp->PrintInfo();
+
+  overlaps->Delete();
+  delete overlaps;
+}
+
+//_____________________________________________________________________________
 Bool_t AliGeomManager::ApplyAlignObjsFromCDB(const char* AlignDetsList)
 {
   // Calls AddAlignObjsFromCDBSingleDet for the detectors appearing in
@@ -1271,7 +1381,7 @@ Bool_t AliGeomManager::LoadAlignObjsFromCDBSingleDet(const char* detName, TObjAr
 }
 
 //_____________________________________________________________________________
-Bool_t AliGeomManager::ApplyAlignObjsToGeom(TObjArray& alignObjArray)
+Bool_t AliGeomManager::ApplyAlignObjsToGeom(TObjArray& alignObjArray, Bool_t ovlpcheck)
 {
   // Read collection of alignment objects (AliAlignObj derived) saved
   // in the TClonesArray alObjArray and apply them to gGeoManager
@@ -1284,7 +1394,7 @@ Bool_t AliGeomManager::ApplyAlignObjsToGeom(TObjArray& alignObjArray)
   for(Int_t j=0; j<nvols; j++)
     {
       AliAlignObj* alobj = (AliAlignObj*) alignObjArray.UncheckedAt(j);
-      if (alobj->ApplyToGeometry() == kFALSE) flag = kFALSE;
+      if (alobj->ApplyToGeometry(ovlpcheck) == kFALSE) flag = kFALSE;
     }
 
   if (AliDebugLevelClass() >= 1) {