]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
New method of Aliimulation to apply detector misalignment (R.Grosso)
authorhristov <hristov@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 1 Dec 2005 14:58:31 +0000 (14:58 +0000)
committerhristov <hristov@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 1 Dec 2005 14:58:31 +0000 (14:58 +0000)
STEER/AliSimulation.cxx
STEER/AliSimulation.h

index 676103e31bed903965153c2a9411b35a3a4c977c..ce363eb9a3280c7f9ab5b04f8304b5de4c06686a 100644 (file)
 #include "AliVertexGenFile.h"
 
 #include "AliDAQConfig.h"
+#include "AliAlignObj.h"
+#include "AliAlignObjAngles.h"
+#include "AliAlignObjMatrix.h"
 
 ClassImp(AliSimulation)
 
@@ -257,6 +260,115 @@ void AliSimulation::SetEventsPerFile(const char* detector, const char* type,
   fEventsPerFile.Add(obj);
 }
 
+//_____________________________________________________________________________
+Bool_t AliSimulation::ApplyDisplacements(TGeoManager* geoManager, const char* fileName, const char* ClArrayName)
+{
+  // read collection of alignment objects (AliAlignObj derived) saved
+  // in the TClonesArray ClArrayName in the file fileName and apply
+  // them to the TGeo geometry passed as argument
+  //
+
+  TFile* inFile = TFile::Open(fileName,"READ");
+  if (!inFile || !inFile->IsOpen()) {
+    AliErrorClass(Form("Could not open file %s !",fileName));
+    return kFALSE;
+  }
+
+  TClonesArray* AlObjArray = ((TClonesArray*) inFile->Get(ClArrayName));
+  Int_t nvols = AlObjArray->GetEntriesFast();
+
+  AliAlignObj::ELayerID layerId; // unique identity for volume in the alobj
+  Int_t modId; // unique identity for volume in the alobj
+  Bool_t ispathvalid; // false if volume path for alobj is not valid for TGeo
+
+  TGeoHMatrix dm;
+
+  for(Int_t j=0; j<nvols; j++)
+    {
+      AliAlignObj* alobj = (AliAlignObj*) AlObjArray->UncheckedAt(j);
+      const char* volpath = alobj->GetVolPath();
+      TGeoPhysicalNode* node = (TGeoPhysicalNode*) geoManager->MakePhysicalNode(volpath);
+      alobj->GetMatrix(dm);
+      alobj->GetVolUID(layerId, modId);
+      ispathvalid = geoManager->cd(volpath);
+      if(!ispathvalid){
+       AliWarningClass(Form("Volume path %s not valid!",volpath));
+       return kFALSE;
+      }
+      TGeoHMatrix* hm = geoManager->GetCurrentMatrix();
+      hm->MultiplyLeft(&dm);
+      AliInfoClass(Form("Aligning volume %s of detector layer %d with local ID %d",volpath,layerId,modId));
+      node->Align(hm);
+
+    }
+  
+  inFile->Close();
+  return kTRUE;
+
+}
+
+//_____________________________________________________________________________
+Bool_t AliSimulation::ApplyDisplacements(TGeoManager* geoManager, AliCDBParam* param, AliCDBId& Id)
+{
+  // read collection of alignment objects (AliAlignObj derived) saved
+  // in the TClonesArray ClArrayName in the AliCDBEntry identified by
+  // param (to get the AliCDBStorage) and Id; apply the alignment objects
+  // to the TGeo geometry passed as argument
+  //
+
+  AliCDBStorage* storage = AliCDBManager::Instance()->GetStorage(param);
+  AliCDBEntry* entry = storage->Get(Id);
+  TClonesArray* AlObjArray = ((TClonesArray*) entry->GetObject());
+
+  Int_t nvols = AlObjArray->GetEntriesFast();
+  AliAlignObj* alobj;
+
+  AliAlignObj::ELayerID layerId; // unique identity for volume in the alobj
+  Int_t modId; // unique identity for volume in the alobj
+  Bool_t ispathvalid; // false if volume path for alobj is not valid for TGeo
+
+  TGeoHMatrix dm;
+
+  for(Int_t j=0; j<nvols; j++)
+    {
+      alobj = (AliAlignObj*) AlObjArray->UncheckedAt(j);
+      const char* volpath = alobj->GetVolPath();
+      TGeoPhysicalNode* node = (TGeoPhysicalNode*) geoManager->MakePhysicalNode(volpath);
+      alobj->GetMatrix(dm);
+      alobj->GetVolUID(layerId, modId);
+      ispathvalid = geoManager->cd(volpath);
+      if(!ispathvalid){
+       AliWarningClass(Form("Volume path %s not valid!",volpath));
+       return kFALSE;
+      }
+      TGeoHMatrix* hm = geoManager->GetCurrentMatrix();
+      hm->MultiplyLeft(&dm);
+      AliInfoClass(Form("Aligning volume %s of detector layer %d with local ID %d",volpath,layerId,modId));
+      node->Align(hm);
+
+    }
+  
+  return kTRUE;
+
+}
+
+//_____________________________________________________________________________
+Bool_t AliSimulation::ApplyDisplacements(TGeoManager* geoManager, const char* uri, const char* path, Int_t runnum, Int_t version, Int_t sversion)
+{
+  // read collection of alignment objects (AliAlignObj derived) saved
+  // in the TClonesArray ClArrayName in the AliCDBEntry identified by
+  // param (to get the AliCDBStorage) and Id; apply the alignment objects
+  // to the TGeo geometry passed as argument
+  //
+
+  AliCDBParam* param = AliCDBManager::Instance()->CreateParameter(uri);
+  AliCDBId id(path, runnum, runnum, version, sversion);
+  ApplyDisplacements(geoManager, param, id);
+
+  return kTRUE;
+
+}
+
 //_____________________________________________________________________________
 void AliSimulation::MergeWith(const char* fileName, Int_t nSignalPerBkgrd)
 {
index 9fadb2ab55028467c1e902bad6687a366657cd2f..1919ea8e3d624fe60a4d59346bd1eefd9734ad78 100644 (file)
 #include <TNamed.h>
 #include <TString.h>
 #include <TObjArray.h>
+#include <TGeoManager.h>
+#include <TGeoPhysicalNode.h>
+#include "AliCDBManager.h"
+#include "AliCDBStorage.h"
+#include "AliCDBEntry.h"
+#include "AliCDBId.h"
 
 class AliRunLoader;
 
@@ -51,6 +57,16 @@ public:
                                 Bool_t deleteIntermediateFiles = kFALSE)
                    {fWriteRawData = detectors; fRawDataFileName = fileName;
                   fDeleteIntermediateFiles = deleteIntermediateFiles;};
+  static Bool_t  ApplyDisplacements(TGeoManager* geoManager,
+                                   const char* fileName,
+                                   const char* ClArrayName);
+  static Bool_t  ApplyDisplacements(TGeoManager* geoManager,
+                                   AliCDBParam* param,
+                                   AliCDBId& Id);
+  static Bool_t  ApplyDisplacements(TGeoManager* geoManager,
+                                   const char* uri, const char* path,
+                                   Int_t runnum, Int_t version,
+                                   Int_t sversion);
 
   virtual Bool_t Run(Int_t nEvents = 0);