Added possibility to runthe TGeo overlap checker restricting it to misaligned volumes...
authorrgrosso <rgrosso@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 23 Nov 2007 15:00:45 +0000 (15:00 +0000)
committerrgrosso <rgrosso@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 23 Nov 2007 15:00:45 +0000 (15:00 +0000)
STEER/AliAlignObj.cxx
STEER/AliAlignObj.h
STEER/AliGeomManager.cxx
STEER/AliGeomManager.h

index d2b5c9b..cee2c2b 100644 (file)
@@ -643,7 +643,7 @@ Bool_t AliAlignObj::GetLocalMatrix(TGeoHMatrix& m) const
 }
 
 //_____________________________________________________________________________
-Bool_t AliAlignObj::ApplyToGeometry()
+Bool_t AliAlignObj::ApplyToGeometry(Bool_t ovlpcheck)
 {
   // Apply the current alignment object to the TGeo geometry
   // This method returns FALSE if the symname of the object was not
@@ -692,7 +692,16 @@ Bool_t AliAlignObj::ApplyToGeometry()
   Int_t modId; // unique identity for volume inside layer in the alobj
   GetVolUID(layerId, modId);
   AliDebug(2,Form("Aligning volume %s of detector layer %d with local ID %d",symname,layerId,modId));
-  node->Align(ginv);
+  node->Align(ginv,0,ovlpcheck);
+  if(ovlpcheck){
+    Int_t novex=((TObjArray*)gGeoManager->GetListOfOverlaps())->GetEntriesFast();
+    if(novex){
+      TString error(Form("The alignment of volume %s introduced %d new overlap",GetSymName(),novex));
+      if(novex>1) error+="s";
+      AliError(error.Data());
+      return kFALSE;
+    }
+  }
 
   return kTRUE;
 }
index 91d142c..be0413a 100644 (file)
@@ -97,7 +97,7 @@ class AliAlignObj : public TObject {
   static const char* SymName(UShort_t voluid) {return AliGeomManager::SymName(voluid);}
   static const char* SymName(AliGeomManager::ELayerID layerId, Int_t modId) {return AliGeomManager::SymName(layerId, modId);}
 
-  Bool_t ApplyToGeometry();
+  Bool_t ApplyToGeometry(Bool_t ovlpcheck=kFALSE);
   static Bool_t   GetFromGeometry(const char *symname, AliAlignObj &alobj) {return AliGeomManager::GetFromGeometry(symname, alobj);}
 
   static AliAlignObj* GetAlignObj(UShort_t voluid) {return AliGeomManager::GetAlignObj(voluid);}
index 8db4eda..4cf16a3 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"
@@ -1240,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;
+  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
@@ -1327,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
@@ -1340,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) {
index 7763682..6eb1d28 100644 (file)
@@ -77,8 +77,9 @@ public:
 
   static void        LoadGeometry(const char *geomFileName = NULL);
   static void        SetGeometry(TGeoManager *geom);
+  static void        CheckOverlapsOverPNs(Double_t threshold);  
 
-  static Bool_t         ApplyAlignObjsToGeom(TObjArray& alObjArray);
+  static Bool_t         ApplyAlignObjsToGeom(TObjArray& alObjArray, Bool_t ovlpcheck=kFALSE);
 
   static Bool_t         ApplyAlignObjsToGeom(const char* fileName,
                                      const char* clArrayName);
@@ -89,7 +90,6 @@ public:
                                      Int_t sversion);
   static Bool_t         ApplyAlignObjsToGeom(const char* detName, Int_t runnum, Int_t version,
                                      Int_t sversion);
-
   static Bool_t         ApplyAlignObjsFromCDB(const char* AlDetsList);
   static Bool_t         LoadAlignObjsFromCDBSingleDet(const char* detName, TObjArray& alignObjArray);