From 392efe7353b6d279169c734b3314ed04ddf576e5 Mon Sep 17 00:00:00 2001 From: shahoian Date: Sun, 4 Nov 2012 19:44:10 +0000 Subject: [PATCH] Added macros to create misalignment and to apply it. Added shortcuts for extraction of alignable volumes symnames --- ITS/UPGRADE/AliITSUGeomTGeo.cxx | 28 ++++++ ITS/UPGRADE/AliITSUGeomTGeo.h | 5 + ITS/UPGRADE/AliITSUv11.cxx | 13 +-- ITS/UPGRADE/ApplyAlignment.C | 44 ++++++++ ITS/UPGRADE/MakeITSUResMisAlignment.C | 138 ++++++++++++++++++++++++++ 5 files changed, 220 insertions(+), 8 deletions(-) create mode 100644 ITS/UPGRADE/ApplyAlignment.C create mode 100644 ITS/UPGRADE/MakeITSUResMisAlignment.C diff --git a/ITS/UPGRADE/AliITSUGeomTGeo.cxx b/ITS/UPGRADE/AliITSUGeomTGeo.cxx index ae5524a0838..9eddadbca14 100644 --- a/ITS/UPGRADE/AliITSUGeomTGeo.cxx +++ b/ITS/UPGRADE/AliITSUGeomTGeo.cxx @@ -285,6 +285,34 @@ const char* AliITSUGeomTGeo::GetSymName(Int_t index) const return pne->GetName(); } +//______________________________________________________________________ +const char* AliITSUGeomTGeo::ComposeSymNameITS() +{ + // sym name of the layer + return "ITS"; +} + +//______________________________________________________________________ +const char* AliITSUGeomTGeo::ComposeSymNameLayer(Int_t lr) +{ + // sym name of the layer + return Form("%s/%s%d",ComposeSymNameITS(),GetITSLayerPattern(),lr); +} + +//______________________________________________________________________ +const char* AliITSUGeomTGeo::ComposeSymNameLadder(Int_t lr, Int_t ladder) +{ + // sym name of the ladder at given layer + return Form("%s/%s%d",ComposeSymNameLayer(lr),GetITSLadderPattern(),ladder); +} + +//______________________________________________________________________ +const char* AliITSUGeomTGeo::ComposeSymNameModule(Int_t lr, Int_t lad, int det) +{ + // sym name of the module + return Form("%s/%s%d",ComposeSymNameLadder(lr,lad),GetITSModulePattern(),det); +} + //______________________________________________________________________ TGeoHMatrix* AliITSUGeomTGeo::GetMatrix(Int_t index) const { diff --git a/ITS/UPGRADE/AliITSUGeomTGeo.h b/ITS/UPGRADE/AliITSUGeomTGeo.h index 09a1cbc0651..1bac124eee9 100644 --- a/ITS/UPGRADE/AliITSUGeomTGeo.h +++ b/ITS/UPGRADE/AliITSUGeomTGeo.h @@ -117,6 +117,11 @@ class AliITSUGeomTGeo : public TObject { static void SetITSsegmentationFileName(const char* nm) {fgITSsegmFileName = nm;} static UInt_t ComposeDetTypeID(UInt_t segmId); // + static const char *ComposeSymNameITS(); + static const char *ComposeSymNameLayer(Int_t lr); + static const char *ComposeSymNameLadder(Int_t lr, Int_t lad); + static const char *ComposeSymNameModule(Int_t lr, Int_t lad, int det); + // // hack to avoid using AliGeomManager Int_t LayerToVolUID(Int_t lay,int detInLay) const {return GetModuleIndex(lay,detInLay);} static Int_t ModuleVolUID(Int_t mod) {return mod;} diff --git a/ITS/UPGRADE/AliITSUv11.cxx b/ITS/UPGRADE/AliITSUv11.cxx index 3d97fb9c8eb..558b99e3eb1 100644 --- a/ITS/UPGRADE/AliITSUv11.cxx +++ b/ITS/UPGRADE/AliITSUv11.cxx @@ -226,11 +226,11 @@ void AliITSUv11::AddAlignableVolumes() const{ AliInfo("Add ITS alignable volumes"); if (!gGeoManager) { AliFatal("TGeoManager doesn't exist !"); return; } - TString pth,snm; + TString pth; // pth = Form("ALIC_1/%s_2",AliITSUGeomTGeo::GetITSVolPattern()); // RS: to be checked with MS - if( !gGeoManager->SetAlignableEntry("ITS",pth.Data()) ) + if( !gGeoManager->SetAlignableEntry(AliITSUGeomTGeo::ComposeSymNameITS(),pth.Data()) ) AliFatal(Form("Unable to set alignable entry ! %s :: %s","ITS",pth.Data())); // int modNum = 0; @@ -238,28 +238,25 @@ void AliITSUv11::AddAlignableVolumes() const{ for (int lr=0; lrSetAlignableEntry(snm.Data(),pth.Data()); + gGeoManager->SetAlignableEntry(AliITSUGeomTGeo::ComposeSymNameLayer(lr),pth.Data()); // for (int ld=0; ldSetAlignableEntry(snmL.Data(),pthL.Data()); + gGeoManager->SetAlignableEntry(AliITSUGeomTGeo::ComposeSymNameLadder(lr,ld),pthL.Data()); // for (int md=0; mdSetAlignableEntry(snmM.Data(),pthM.Data(),modUID); + gGeoManager->SetAlignableEntry(AliITSUGeomTGeo::ComposeSymNameModule(lr,ld,md),pthM.Data(),modUID); // double yshift = -(fUpGeom[lr]->GetSensorThick()-fUpGeom[lr]->GetLadderThick())/2; // SetT2Lmatrix(modUID,yshift, kTRUE,kTRUE); // RS: do we need here special matrix, ask MS diff --git a/ITS/UPGRADE/ApplyAlignment.C b/ITS/UPGRADE/ApplyAlignment.C new file mode 100644 index 00000000000..94e6b4ae9dd --- /dev/null +++ b/ITS/UPGRADE/ApplyAlignment.C @@ -0,0 +1,44 @@ +void ApplyAlignment(const char* fileMA) +{ + // apply ITSU alignment from the file + // + if (!gGeoManager) { + if (!gSystem->AccessPathName("geometry.root")) { + printf("Loading geometry.root from current directory\n"); + AliGeomManager::LoadGeometry("geometry.root"); //load geom from default CDB storage + } + else { + printf("No geometry in memory and not geometry.root in current directory\n"); + return; + } + } + else { + if (gGeoManager->IsLocked()) { + printf("There is geometry in memory but it is locked"); + return; + } + } + // + TFile* fl = TFile::Open(fileMA); + if (!fl) { + printf("Failed to open misalignments file %s\n",fileMA); + } + TClonesArray* arr = (TClonesArray*)fl->Get("ITSUAlignObjs"); + if (!arr) { + AliCDBEntry* cdbe = (AliCDBEntry*) fl->Get("AliCDBEntry"); + if (!cdbe) { + printf("File %s does not contain recognizable misalignment\n",fileMA); + return; + } + arr = (TClonesArray*)cdbe->GetObject(); + } + // + if (!arr->IsA()==TClonesArray::Class()) { + printf("The object in %s is not TClonesArray\n",fileMA); + return; + } + printf("Applying misalignment from %s geometry in memory\n",fileMA); + AliGeomManager::ApplyAlignObjsToGeom(*arr); + gGeoManager->LockGeometry(); + // +} diff --git a/ITS/UPGRADE/MakeITSUResMisAlignment.C b/ITS/UPGRADE/MakeITSUResMisAlignment.C new file mode 100644 index 00000000000..f91b7b05d3f --- /dev/null +++ b/ITS/UPGRADE/MakeITSUResMisAlignment.C @@ -0,0 +1,138 @@ +// macro to create +Double_t sgXMod=30e-4,sgYMod=30e-4,sgZMod=30e-4,sgThtMod=0.1,sgPsiMod=0.1,sgPhiMod=0.1; +Double_t sgXLad=30e-4,sgYLad=30e-4,sgZLad=30e-4,sgThtLad=0.1,sgPsiLad=0.1,sgPhiLad=0.1; +Double_t sgXLay=30e-4,sgYLay=30e-4,sgZLay=30e-4,sgThtLay=0.1,sgPsiLay=0.1,sgPhiLay=0.1; +Double_t sgXITS=100e-4,sgYITS=100e-4,sgZITS=2000e-4,sgThtITS=0.1,sgPsiITS=0.1,sgPhiITS=0.1; +// +TClonesArray* deltas=0; +// +void MakeITSUResMisAlignment() +{ + gSystem->Load("libITSUpgradeBase"); + // + // at the moment we don't want to write to official CDB + gSystem->Setenv("TOCDB","kTRUE"); + gSystem->Setenv("STORAGE","local://"); + // + // Activate CDB storage and load geometry from CDB + AliCDBManager* cdb = AliCDBManager::Instance(); + if(!cdb->IsDefaultStorageSet()) cdb->SetDefaultStorage("local://"); + cdb->SetRun(0); + AliCDBStorage* storage; + // + if (!gGeoManager) { + if (!gSystem->AccessPathName("geometry.root")) { + printf("Loading geometry.root from current directory\n"); + AliGeomManager::LoadGeometry("geometry.root"); //load geom from default CDB storage + } + } + // + if (TString(gSystem->Getenv("TOCDB")) == TString("kTRUE")) { + TString Storage = gSystem->Getenv("STORAGE"); + if (!Storage.BeginsWith("local://") && !Storage.BeginsWith("alien://")) { + Error(macroname,"STORAGE variable set to %s is not valid. Exiting\n",Storage.Data()); + return; + } + storage = cdb->GetStorage(Storage.Data()); + if (!storage) { + Error(macroname,"Unable to open storage %s\n",Storage.Data()); + return; + } + // + if (!gGeoManager) { + AliCDBPath path("GRP","Geometry","Data"); + AliCDBEntry *entry = storage->Get(path.GetPath(),cdb->GetRun()); + if(!entry) Fatal(macroname,"Could not get the specified CDB entry!"); + entry->SetOwner(0); + TGeoManager* geom = (TGeoManager*) entry->GetObject(); + AliGeomManager::SetGeometry(geom); + } + } + // + const UShort_t dummyVID = 0xffff; + AliITSUGeomTGeo* gm0 = new AliITSUGeomTGeo(kTRUE); + // + deltas = new TClonesArray("AliAlignObjParams"); + double dx,dy,dz,dtht,dpsi,dphi; + // + TString sname; + int idel = 0; + // + dx = sgXITS*gRandom->Gaus(); + dy = sgYITS*gRandom->Gaus(); + dz = sgZITS*gRandom->Gaus(); + dtht = sgThtITS*gRandom->Gaus(); + dpsi = sgPsiITS*gRandom->Gaus(); + dphi = sgPhiITS*gRandom->Gaus(); + sname = gm0->ComposeSymNameITS(); + new( (*deltas)[idel++] ) AliAlignObjParams(sname.Data(),dummyVID, + dx,dy,dz,dtht,dpsi,dphi,kTRUE); + // + for (int ilr=0;ilrGetNLayers();ilr++) { + // + dx = sgXLay*gRandom->Gaus(); + dy = sgYLay*gRandom->Gaus(); + dz = sgZLay*gRandom->Gaus(); + dtht = sgThtLay*gRandom->Gaus(); + dpsi = sgPsiLay*gRandom->Gaus(); + dphi = sgPhiLay*gRandom->Gaus(); + sname = gm0->ComposeSymNameLayer(ilr); + new( (*deltas)[idel++] ) AliAlignObjParams(sname.Data(),dummyVID, + dx,dy,dz,dtht,dpsi,dphi,kTRUE); + // + for (int ild=0;ildGetNLadders(ilr);ild++) { + // + dx = sgXLad*gRandom->Gaus(); + dy = sgYLad*gRandom->Gaus(); + dz = sgZLad*gRandom->Gaus(); + dtht = sgThtLad*gRandom->Gaus(); + dpsi = sgPsiLad*gRandom->Gaus(); + dphi = sgPhiLad*gRandom->Gaus(); + sname = gm0->ComposeSymNameLadder(ilr,ild); + new( (*deltas)[idel++] ) AliAlignObjParams(sname.Data(),dummyVID, + dx,dy,dz,dtht,dpsi,dphi,kTRUE); + // + for (int isn=0;isnGetNDetectors(ilr);isn++) { + dx = sgXMod*gRandom->Gaus(); + dy = sgYMod*gRandom->Gaus(); + dz = sgZMod*gRandom->Gaus(); + dtht = sgThtMod*gRandom->Gaus(); + dpsi = sgPsiMod*gRandom->Gaus(); + dphi = sgPhiMod*gRandom->Gaus(); + int mid = gm0->GetModuleIndex(ilr,ild,isn); + sname = gm0->GetSymName(mid); + new( (*deltas)[idel++] ) AliAlignObjParams(sname.Data(),gm0->ModuleVolUID(mid), + dx,dy,dz,dtht,dpsi,dphi,kTRUE); + } + } + } + // + if( TString(gSystem->Getenv("TOCDB")) != TString("kTRUE") ){ + // save on file + const char* filename = "ITSUresidualMisalignment.root"; + TFile f(filename,"RECREATE"); + if(!f){ + Error(macroname,"cannot open file for output\n"); + return; + } + Info(macroname,"Saving alignment objects to the file %s", filename); + f.cd(); + f.WriteObject(deltas,"ITSUAlignObjs","kSingleKey"); + f.Close(); + } + else{ + // save in CDB storage + AliCDBMetaData* md = new AliCDBMetaData(); + md->SetResponsible("R.S."); + md->SetComment("Residual misalignment for ITSU"); + md->SetAliRootVersion(gSystem->Getenv("ARVERSION")); + AliCDBId id("ITS/Align/Data",0,AliCDBRunRange::Infinity()); + storage->Put(deltas,id,md); + } + + // apply to geometry + printf("Applying created misalignment to geometry in memory\n"); + AliGeomManager::ApplyAlignObjsToGeom(*deltas); + gGeoManager->LockGeometry(); + // +} -- 2.43.0