From 6526a72c570f2e38335cd4670cda3795da01e774 Mon Sep 17 00:00:00 2001 From: masera Date: Mon, 11 May 2009 09:02:19 +0000 Subject: [PATCH] Interface to AliMillePede2 for ITS alignment + related classes (R. Shaoyan) --- ITS/AliITSAlignMille2.cxx | 2266 +++++++++++++++++++------- ITS/AliITSAlignMille2.h | 246 +-- ITS/AliITSAlignMille2ConstrArray.cxx | 101 ++ ITS/AliITSAlignMille2ConstrArray.h | 51 + ITS/AliITSAlignMille2Constraint.cxx | 65 + ITS/AliITSAlignMille2Constraint.h | 69 + ITS/AliITSAlignMille2Module.cxx | 1851 +++++++++++++-------- ITS/AliITSAlignMille2Module.h | 74 +- ITS/CMake_libITSrec.txt | 2 + ITS/ITSrecLinkDef.h | 4 +- ITS/libITSrec.pkg | 2 + 11 files changed, 3354 insertions(+), 1377 deletions(-) create mode 100644 ITS/AliITSAlignMille2ConstrArray.cxx create mode 100644 ITS/AliITSAlignMille2ConstrArray.h create mode 100644 ITS/AliITSAlignMille2Constraint.cxx create mode 100644 ITS/AliITSAlignMille2Constraint.h diff --git a/ITS/AliITSAlignMille2.cxx b/ITS/AliITSAlignMille2.cxx index 93f3b8a1cd4..6a2b7d64b33 100644 --- a/ITS/AliITSAlignMille2.cxx +++ b/ITS/AliITSAlignMille2.cxx @@ -16,15 +16,15 @@ /* $Id$ */ //----------------------------------------------------------------------------- -/// \class AliITSAlignMille -/// Alignment class fro the ALICE ITS detector -/// -/// ITS specific alignment class which interface to AliMillepede. -/// For each track ProcessTrack calculates the local and global derivatives -/// at each hit and fill the corresponding local equations. Provide methods for -/// fixing or constraining detection elements for best results. -/// -/// \author M. Lunardon (thanks to J. Castillo) +// +// Interface to AliMillePede2 alignment class for the ALICE ITS detector +// +// ITS specific alignment class which interface to AliMillepede. +// For each track ProcessTrack calculates the local and global derivatives +// at each hit and fill the corresponding local equations. Provide methods for +// fixing or constraining detection elements for best results. +// +// author M. Lunardon (thanks to J. Castillo), ruben.shahoyan@cern.ch //----------------------------------------------------------------------------- #include @@ -35,6 +35,7 @@ #include #include #include +#include #include "AliITSAlignMille2.h" #include "AliITSgeomTGeo.h" @@ -46,14 +47,17 @@ #include "TSystem.h" // come si fa? #include "AliTrackFitterRieman.h" -/// \cond CLASSIMP + ClassImp(AliITSAlignMille2) -/// \endcond + + +//======================================================================================================== AliITSAlignMille2* AliITSAlignMille2::fgInstance = 0; Int_t AliITSAlignMille2::fgInstanceID = 0; -AliITSAlignMille2::AliITSAlignMille2(const Char_t *configFilename, Bool_t initmille) +//________________________________________________________________________________________________________ +AliITSAlignMille2::AliITSAlignMille2(const Char_t *configFilename ) : TObject(), fMillepede(0), fStartFac(16.), @@ -63,44 +67,47 @@ AliITSAlignMille2::AliITSAlignMille2(const Char_t *configFilename, Bool_t initmi fNLocal(4), fNStdDev(3), fIsMilleInit(kFALSE), - fSensorsIn(kFALSE), - fParSigTranslations(0.0100), - fParSigRotations(0.1), -// + fAllowPseudoParents(kFALSE), + // fCurrentModule(0), fTrack(0), + fTrackBuff(0), fCluster(), fGlobalDerivatives(0), -// + // fMinNPtsPerTrack(3), fInitTrackParamsMeth(1), fTotBadLocEqPoints(0), fRieman(0), // + fConstraints(0), + // fUseGlobalDelta(kFALSE), fRequirePoints(kFALSE), fTempExcludedModule(-1), // fGeometryFileName("geometry.root"), fPreAlignmentFileName(""), + fConstrRefFileName(""), fGeoManager(0), fIsConfigured(kFALSE), fPreAlignQF(0), // + fCorrectSDD(0), + fInitialRecSDD(0), fPrealignment(0), + fConstrRef(0), fMilleModule(2), fSuperModule(2), fNModules(0), fNSuperModules(0), fUsePreAlignment(kFALSE), - fUseSortedTracks(kTRUE), fBOn(kFALSE), fBField(0.0), - fBug(0) + fBug(0), + fMilleVersion(2) { /// main constructor that takes input from configuration file - // - fMillepede = new AliMillePede2(); for (int i=3;i--;) fSigmaFactor[i] = 1.0; // // new RS @@ -117,244 +124,566 @@ AliITSAlignMille2::AliITSAlignMille2(const Char_t *configFilename, Bool_t initmi // Int_t lc=LoadConfig(configFilename); if (lc) { - AliInfo(Form("Error %d loading configuration from %s",lc,configFilename)); - } - else { - fIsConfigured=kTRUE; - if (initmille) { - AliInfo(Form("Initializing Millepede with %d gpar, %d lpar and %d stddev ...",fNGlobal, fNLocal, fNStdDev)); - Init(fNGlobal, fNLocal, fNStdDev); - ResetLocalEquation(); - AliInfo("Parameters initialized to zero"); - } - else { - AliInfo("Millepede has not been initialized ... "); - } + AliError(Form("Error %d loading configuration from %s",lc,configFilename)); + exit(1); } // + fMillepede = new AliMillePede2(); fgInstance = this; fgInstanceID++; // } -AliITSAlignMille2::~AliITSAlignMille2() { +//________________________________________________________________________________________________________ +AliITSAlignMille2::~AliITSAlignMille2() +{ /// Destructor - if (fMillepede) delete fMillepede; - if (fGlobalDerivatives) delete[] fGlobalDerivatives; - if (fRieman) delete fRieman; - if (fPrealignment) delete fPrealignment; + if (fMillepede) delete fMillepede; fMillepede = 0; + if (fGlobalDerivatives) delete[] fGlobalDerivatives; fGlobalDerivatives = 0; + if (fRieman) delete fRieman; fRieman = 0; + if (fPrealignment) delete fPrealignment; fPrealignment = 0; + if (fConstrRef) delete fConstrRef; fConstrRef = 0; + if (fCorrectSDD) delete fCorrectSDD; fCorrectSDD = 0; + if (fInitialRecSDD) delete fInitialRecSDD; fInitialRecSDD = 0; + fTrackBuff.Delete(); + fConstraints.Delete(); fMilleModule.Delete(); fSuperModule.Delete(); if (--fgInstanceID==0) fgInstance = 0; } /////////////////////////////////////////////////////////////////////// +TObjArray* AliITSAlignMille2::GetConfigRecord(FILE* stream, TString& recTitle, TString& recOpt, Bool_t rew) +{ + TString record; + static TObjArray* recElems = 0; + if (recElems) {delete recElems; recElems = 0;} + // + TString keyws = recTitle; + if (!keyws.IsNull()) { + keyws.ToUpper(); + // keyws += " "; + } + while (record.Gets(stream)) { + int cmt=record.Index("#"); + if (cmt>=0) record.Remove(cmt); // skip comment + record.ReplaceAll("\t"," "); + record.ReplaceAll("\r"," "); + record.Remove(TString::kBoth,' '); + if (record.IsNull()) continue; // nothing to decode + if (!keyws.IsNull() && !record.BeginsWith(keyws.Data())) continue; // specific record was requested + // + recElems = record.Tokenize(" "); + recTitle = recElems->At(0)->GetName(); + recTitle.ToUpper(); + recOpt = recElems->GetLast()>0 ? recElems->At(1)->GetName() : ""; + break; + } + if (rew || !recElems) rewind(stream); + return recElems; +} -Int_t AliITSAlignMille2::LoadConfig(const Char_t *cfile) { - /// return 0 if success +//________________________________________________________________________________________________________ +Int_t AliITSAlignMille2::LoadConfig(const Char_t *cfile) +{ /// return 0 if success /// 1 if error in module index or voluid - + // FILE *pfc=fopen(cfile,"r"); if (!pfc) return -1; - - Char_t st[200],st2[200]; - Char_t tmp[100]; - Int_t idx,itx,ity,itz,ith,ips,iph; - Float_t f1,f2,f3; - UShort_t voluid; - Int_t nmod=0; - // - while (fgets(st,200,pfc)) { - // - for (int i=0; iAccessPathName(st2)) { AliInfo("*** WARNING! *** geometry file not found! "); return -1;} - fGeometryFileName=st2; - InitGeometry(); - } + // + TString record,recTitle,recOpt,recExt; + Int_t nrecElems,irec; + TObjArray *recArr=0; + // + fNModules = 0; + Bool_t stopped = kFALSE; + // + while(1) { // - if (strstr(st,"PREALIGNMENT_FILE")) { - sscanf(st,"%s %s",tmp,st2); - if (gSystem->AccessPathName(st2)) { AliInfo("*** WARNING! *** prealignment file not found! "); return -1;} - fPreAlignmentFileName=st2; - itx=ApplyToGeometry(); - if (itx) { AliInfo(Form("*** WARNING! *** error %d reading prealignment file! ",itx)); return -6;} - } + // ============= 1: we read some obligatory records in predefined order ================ + // + recTitle = "GEOMETRY_FILE"; + if ( !GetConfigRecord(pfc,recTitle,recOpt,1) || + (fGeometryFileName=recOpt).IsNull() || + gSystem->AccessPathName(recOpt.Data()) || + InitGeometry() ) + { AliError("Failed to find/load Geometry"); stopped = kTRUE; break;} // - if (strstr(st,"SUPERMODULE_FILE")) { - sscanf(st,"%s %s",tmp,st2); - if (gSystem->AccessPathName(st2)) { AliInfo("*** WARNING! *** supermodule file not found! "); return -1;} - if (LoadSuperModuleFile(st2)) return -1; - } + recTitle = "SUPERMODULE_FILE"; + if ( !GetConfigRecord(pfc,recTitle,recOpt,1) || + recOpt.IsNull() || + gSystem->AccessPathName(recOpt.Data()) || + LoadSuperModuleFile(recOpt.Data())) + { AliError("Failed to find/load SuperModules"); stopped = kTRUE; break;} // - if (strstr(st,"SET_B_FIELD")) { - sscanf(st,"%s %f",tmp,&f1); - if (f1>0) { - fBField = f1; - fBOn = kTRUE; - fNLocal = 5; // helices - fRieman = new AliTrackFitterRieman(); - } - else { - fBField = 0.0; - fBOn = kFALSE; - fNLocal = 4; - } + recTitle = "CONSTRAINTS_REFERENCE_FILE"; // LOCAL_CONSTRAINTS are defined wrt these deltas + if ( GetConfigRecord(pfc,recTitle,recOpt,1) ) { + if (recOpt.IsNull() || recOpt=="IDEAL") SetConstraintWrtRef( "IDEAL" ); + else if (gSystem->AccessPathName(recOpt.Data()) || SetConstraintWrtRef(recOpt.Data()) ) + { AliError("Failed to load reference deltas for local constraints"); stopped = kTRUE; break;} } + // + recTitle = "PREALIGNMENT_FILE"; + if ( GetConfigRecord(pfc,recTitle,recOpt,1) ) + if ( (fPreAlignmentFileName=recOpt).IsNull() || + gSystem->AccessPathName(recOpt.Data()) || + ApplyToGeometry()) + { AliError(Form("Failed to load Prealignment file %s",recOpt.Data())); stopped = kTRUE; break;} // - if (strstr(st,"SET_MINPNT_TRA")) { - sscanf(st,"%s %d",tmp,&idx); - fMinNPtsPerTrack=idx; + recTitle = "PRECALIBSDD_FILE"; + if ( GetConfigRecord(pfc,recTitle,recOpt,1) ) { + if ( recOpt.IsNull() || gSystem->AccessPathName(recOpt.Data()) ) {stopped = kTRUE; break;} + AliInfo(Form("Using %s for SDD precalibration",recOpt.Data())); + TFile* precfi = TFile::Open(recOpt.Data()); + if (!precfi->IsOpen()) {stopped = kTRUE; break;} + fCorrectSDD = (AliITSresponseSDD*)precfi->Get("AliITSresponseSDD"); + precfi->Close(); + delete precfi; + if (!fCorrectSDD) {AliError("Precalibration SDD object is not found"); stopped = kTRUE; break;} } // - if (strstr(st,"SET_PARSIG_TRA")) { - sscanf(st,"%s %f",tmp,&f1); - fParSigTranslations=f1; + recTitle = "INITCALBSDD_FILE"; + if ( GetConfigRecord(pfc,recTitle,recOpt,1) ) { + if ( recOpt.IsNull() || gSystem->AccessPathName(recOpt.Data()) ) {stopped = kTRUE; break;} + AliInfo(Form("Using %s as SDD calibration used in TrackPoints",recOpt.Data())); + TFile* precf = TFile::Open(recOpt.Data()); + if (!precf->IsOpen()) {stopped = kTRUE; break;} + fInitialRecSDD = (AliITSresponseSDD*)precf->Get("AliITSresponseSDD"); + precf->Close(); + delete precf; + if (!fInitialRecSDD) {AliError("Initial Calibration SDD object is not found"); stopped = kTRUE; break;} } // - if (strstr(st,"SET_PARSIG_ROT")) { - sscanf(st,"%s %f",tmp,&f1); - fParSigRotations=f1; - } + recTitle = "SET_GLOBAL_DELTAS"; + if ( GetConfigRecord(pfc,recTitle,recOpt,1) ) SetUseGlobalDelta(kTRUE); // - if (strstr(st,"SET_NSTDDEV")) { - sscanf(st,"%s %d",tmp,&idx); - fNStdDev=idx; - } + // =========== 2: see if there are local gaussian constraints defined ===================== + // Note that they should be loaded before the modules declaration // - if (strstr(st,"SET_RESCUT_INIT")) { - sscanf(st,"%s %f",tmp,&f1); - fResCutInitial=f1; - } + recTitle = "CONSTRAINT_LOCAL"; + while( (recArr=GetConfigRecord(pfc,recTitle,recOpt,0)) ) { + nrecElems = recArr->GetLast()+1; + if (recOpt.IsFloat()) {stopped = kTRUE; break;} // wrong name + if (GetConstraint(recOpt.Data())) { + AliError(Form("Existing constraint %s repeated",recOpt.Data())); + stopped = kTRUE; break; + } + recExt = recArr->At(2)->GetName(); + if (!recExt.IsFloat()) {stopped = kTRUE; break;} + double val = recExt.Atof(); + recExt = recArr->At(3)->GetName(); + if (!recExt.IsFloat()) {stopped = kTRUE; break;} + double err = recExt.Atof(); + int nwgh = nrecElems - 4; + double *wgh = new double[nwgh]; + for (nwgh=0,irec=4;irecAt(irec)->GetName(); + if (!recExt.IsFloat()) {stopped = kTRUE; break;} + wgh[nwgh++] = recExt.Atof(); + } + if (stopped) {delete[] wgh; break;} + // + ConstrainLocal(recOpt.Data(),wgh,nwgh,val,err); + delete[] wgh; + // + } // end while for loop over local constraints + if (stopped) break; // - if (strstr(st,"SET_RESCUT_OTHER")) { - sscanf(st,"%s %f",tmp,&f1); - fResCut=f1; - } + // =========== 3: now read modules to align =================================== // - if (strstr(st,"SET_LOCALSIGMAFACTOR")) { - f1=f2=f3=0; - sscanf(st,"%s %f %f %f",tmp,&f1,&f2,&f3); - if (f1>0) fSigmaFactor[0] = f1; - if (f2>0) fSigmaFactor[1] = f2; else fSigmaFactor[1]=fSigmaFactor[0]; - if (f3>0) fSigmaFactor[2] = f3; else fSigmaFactor[2]=fSigmaFactor[1]; - } + rewind(pfc); + while( (recArr=GetConfigRecord(pfc,recTitle="",recOpt,0)) ) { + if (!(recTitle=="MODULE_VOLUID" || recTitle=="MODULE_INDEX")) continue; + // Expected format: MODULE id tolX tolY tolZ tolPsi tolTh tolPhi [[sigX sigY sigZ] extra params] + // where tol* is the tolerance (sigma) for given DOF. 0 means fixed + // sig* is the scaling parameters for the errors of the clusters of this module + // extra params are defined for specific modules, e.g. t0 and vdrift corrections of SDD + // + nrecElems = recArr->GetLast()+1; + if (nrecElems<2 || !recOpt.IsDigit()) {stopped = kTRUE; break;} + int idx = recOpt.Atoi(); + UShort_t voluid = (idx<=kMaxITSSensID) ? GetModuleVolumeID(idx) : idx; + AliITSAlignMille2Module* mod = 0; + // + if (voluid>=kMinITSSupeModuleID) { // custom supermodule + for (int j=0; jGetVolumeID()) { + mod = new AliITSAlignMille2Module(*GetSuperModule(j)); + // the matrix might be updated in case some prealignment was applied, check + TGeoHMatrix* mup = AliGeomManager::GetMatrix(mod->GetName()); + if (mup) *(mod->GetMatrix()) = *mup; + fMilleModule.AddAtAndExpand(mod,fNModules); + break; + } + } + } + else if (idx<=kMaxITSSensVID) { + mod = new AliITSAlignMille2Module(voluid); + fMilleModule.AddAtAndExpand(mod,fNModules); + } + if (!mod) {stopped = kTRUE; break;} // bad volid + // + // geometry variation settings + for (int i=0;i= nrecElems) break; + recExt = recArr->At(irec)->GetName(); + if (!recExt.IsFloat()) {stopped = kTRUE; break;} + mod->SetFreeDOF(i, recExt.Atof() ); + } + if (stopped) break; + // + // scaling factors for cluster errors + // first set default ones + for (int i=0;i<3;i++) mod->SetSigmaFactor(i, fSigmaFactor[i]); + for (int i=0;i<3;i++) { + irec = i+8; + if (irec >= nrecElems) break; + recExt = recArr->At(irec)->GetName(); + if (!recExt.IsFloat()) {stopped = kTRUE; break;} + mod->SetSigmaFactor(i, recExt.Atof() ); + } + if (stopped) break; + // + mod->SetGeomParamsGlobal(fUseGlobalDelta); + // now comes special detectors treatment + if (mod->IsSDD()) { + double vl = 0; + if (nrecElems>11) { + recExt = recArr->At(11)->GetName(); + if (recExt.IsFloat()) vl = recExt.Atof(); + else {stopped = kTRUE; break;} + irec = 11; + } + mod->SetFreeDOF(AliITSAlignMille2Module::kDOFT0,vl); + // + vl = 0; + if (nrecElems>12) { + recExt = recArr->At(12)->GetName(); + if (recExt.IsFloat()) vl = recExt.Atof(); + else {stopped = kTRUE; break;} + irec = 12; + } + mod->SetFreeDOF(AliITSAlignMille2Module::kDOFDV,vl); + } + // + mod->SetUniqueID(fNModules); + mod->EvaluateDOF(); + fNModules++; + // + // now check if there are local constraints on this module + for (++irec;irecAt(irec)->GetName(); + if (recExt.IsFloat()) {stopped=kTRUE;break;} + AliITSAlignMille2ConstrArray* cstr = (AliITSAlignMille2ConstrArray*)GetConstraint(recExt.Data()); + if (!cstr) { + AliInfo(Form("No Local constraint %s was declared",recExt.Data())); + stopped=kTRUE; + break; + } + cstr->AddModule(mod); + } + if (stopped) break; + } // end while for loop over modules + if (stopped) break; // - if (strstr(st,"SET_STARTFAC")) { - sscanf(st,"%s %f",tmp,&f1); - fStartFac=f1; - } + if (fNModules==0) {AliError("Failed to find any MODULE"); stopped = kTRUE; break;} + BuildHierarchy(); // preprocess loaded modules // - // >> RS - if (strstr(st,"REQUIRE_POINT")) { - // syntax: REQUIRE_POINT where ndet updw nreqpts - // where = LAYER or DETECTOR - // ndet = detector number: 1-6 for LAYER and 1-3 for DETECTOR (SPD=1, SDD=2, SSD=3) - // updw = 1 for Y>0, -1 for Y<0, 0 if not specified - // nreqpts = minimum number of points of that type - sscanf(st,"%s %s %d %d %d",tmp,st2,&itx,&ity,&itz); - itx--; - if (strstr(st2,"LAYER")) { - if (itx<0 || itx>5) return -7; - if (ity>0) fNReqLayUp[itx]=itz; - else if (ity<0) fNReqLayDown[itx]=itz; - else fNReqLay[itx]=itz; - fRequirePoints=kTRUE; + // =========== 4: the rest may come in arbitrary order ======================================= + rewind(pfc); + while ( (recArr=GetConfigRecord(pfc,recTitle="",recOpt,0))!=0 ) { + // + nrecElems = recArr->GetLast()+1; + // + // some simple flags ----------------------------------------------------------------------- + // + if (recTitle == "SET_PSEUDO_PARENTS") SetAllowPseudoParents(kTRUE); + // + // some optional parameters ---------------------------------------------------------------- + else if (recTitle == "SET_TRACK_FIT_METHOD") { + if (recOpt.IsNull() || !recOpt.IsDigit() ) {stopped = kTRUE; break;} + SetInitTrackParamsMeth(recOpt.Atoi()); } - else if (strstr(st2,"DETECTOR")) { // DETECTOR - if (itx<0 || itx>2) return -7; - if (ity>0) fNReqDetUp[itx]=itz; - else if (ity<0) fNReqDetDown[itx]=itz; - else fNReqDet[itx]=itz; - fRequirePoints=kTRUE; + // + else if (recTitle == "SET_MINPNT_TRA") { + if (recOpt.IsNull() || !recOpt.IsDigit() ) {stopped = kTRUE; break;} + fMinNPtsPerTrack = recOpt.Atoi(); } - } - // << RS - - // - if (strstr(st,"MODULE_INDEX") || strstr(st,"MODULE_VOLUID")) { - f1=f2=f3=0; - sscanf(st,"%s %d %d %d %d %d %d %d %f %f %f",tmp,&idx,&itx,&ity,&itz,&iph,&ith,&ips,&f1,&f2,&f3); // - if (idx<=kMaxITSSensID) voluid=GetModuleVolumeID(idx); - else voluid = UShort_t(idx); + else if (recTitle == "SET_NSTDDEV") { + if (recOpt.IsNull() || !recOpt.IsFloat() ) {stopped = kTRUE; break;} + fNStdDev = (Int_t)recOpt.Atof(); + } // - if (voluid>=kMinITSSupeModuleID) { // custom supermodule - int ism=-1; - for (int j=0; jGetVolumeID()) ism=j; - if (ism<0) return -1; // bad volid - fMilleModule.AddAtAndExpand(new AliITSAlignMille2Module(*GetSuperModule(ism)),nmod); - // >> RS -// if (f1>0) { -// for (int kk=0; kkGetNSensitiveVolumes(); kk++) { -// idx=AliITSAlignMille2Module::GetIndexFromVolumeID(GetMilleModule(nmod)->GetSensitiveVolumeVolumeID()[kk]); -// if (idx>=0) fSensVolSigmaXfactor[idx]=f1; -// } -// } -// if (f2>0) { -// for (int kk=0; kkGetNSensitiveVolumes(); kk++) { -// idx=AliITSAlignMille2Module::GetIndexFromVolumeID(GetMilleModule(nmod)->GetSensitiveVolumeVolumeID()[kk]); -// if (idx>=0) fSensVolSigmaZfactor[idx]=f2; -// } -// } - // << RS + else if (recTitle == "SET_RESCUT_INIT") { + if (recOpt.IsNull() || !recOpt.IsFloat() ) {stopped = kTRUE; break;} + fResCutInitial = recOpt.Atof(); } - else if (idx<=kMaxITSSensVID) { - fMilleModule.AddAtAndExpand(new AliITSAlignMille2Module(voluid),nmod); - AliITSAlignMille2Module* md = (AliITSAlignMille2Module*) fMilleModule[nmod]; - fSensorsIn = kTRUE; - md->SetSensorsProvided(); + // + else if (recTitle == "SET_RESCUT_OTHER") { + if (recOpt.IsNull() || !recOpt.IsFloat() ) {stopped = kTRUE; break;} + fResCut = recOpt.Atof(); } - else return -1; // bad volid // - AliITSAlignMille2Module* mod = GetMilleModule(nmod); - mod->SetFreeDOF(kDOFTX,itx!=0); - mod->SetFreeDOF(kDOFTY,ity!=0); - mod->SetFreeDOF(kDOFTZ,itz!=0); - mod->SetFreeDOF(kDOFPH,iph!=0); - mod->SetFreeDOF(kDOFTH,ith!=0); - mod->SetFreeDOF(kDOFPS,ips!=0); + else if (recTitle == "SET_LOCALSIGMAFACTOR") { //------------------------- + for (irec=0;irec<3;irec++) if (nrecElems>irec+1) { + fSigmaFactor[irec] = ((TObjString*)recArr->At(irec+1))->GetString().Atof(); + if (fSigmaFactor[irec]<=0.) stopped = kTRUE; + } + if (stopped) break; + } // - mod->SetUniqueID(nmod); - if (f1>0) mod->SetSigmaXFactor(f1); - if (f2>0) mod->SetSigmaYFactor(f2); else mod->SetSigmaYFactor(mod->GetSigmaXFactor()); - if (f3>0) mod->SetSigmaZFactor(f3); else mod->SetSigmaZFactor(mod->GetSigmaYFactor()); - nmod++; - } + else if (recTitle == "SET_STARTFAC") { //------------------------- + if (recOpt.IsNull() || !recOpt.IsFloat() ) {stopped = kTRUE; break;} + fStartFac = recOpt.Atof(); + } + // + else if (recTitle == "SET_B_FIELD") { //------------------------- + if (recOpt.IsNull() || !recOpt.IsFloat() ) {stopped = kTRUE; break;} + fBField = recOpt.Atof(); + if (fBField>0) { + fBOn = kTRUE; + fNLocal = 5; // helices + fRieman = new AliTrackFitterRieman(); + } + else { + fBField = 0.0; + fBOn = kFALSE; + fNLocal = 4; + } + } + // + else if (recTitle == "SET_SPARSE_MATRIX") { // matrix solver type + // + AliMillePede2::SetGlobalMatSparse(kTRUE); + if (recOpt.IsNull()) continue; + // solver type and settings + if (recOpt == "MINRES") AliMillePede2::SetIterSolverType( AliMinResSolve::kSolMinRes ); + else if (recOpt == "FGMRES") AliMillePede2::SetIterSolverType( AliMinResSolve::kSolFGMRes ); + else {stopped = kTRUE; break;} + // + if (nrecElems>=3) { // preconditioner type + recExt = recArr->At(2)->GetName(); + if (!recExt.IsDigit()) {stopped = kTRUE; break;} + AliMillePede2::SetMinResPrecondType( recExt.Atoi() ); + } + // + if (nrecElems>=4) { // tolerance + recExt = recArr->At(3)->GetName(); + if (!recExt.IsFloat()) {stopped = kTRUE; break;} + AliMillePede2::SetMinResTol( recExt.Atof() ); + } + // + if (nrecElems>=5) { // maxIter + recExt = recArr->At(4)->GetName(); + if (!recExt.IsDigit()) {stopped = kTRUE; break;} + AliMillePede2::SetMinResMaxIter( recExt.Atoi() ); + } + } + // + else if (recTitle == "REQUIRE_POINT") { //------------------------- + // syntax: REQUIRE_POINT where ndet updw nreqpts + // where = LAYER or DETECTOR + // ndet = detector number: 1-6 for LAYER and 1-3 for DETECTOR (SPD=1, SDD=2, SSD=3) + // updw = 1 for Y>0, -1 for Y<0, 0 if not specified + // nreqpts = minimum number of points of that type + if (nrecElems>=5) { + recOpt.ToUpper(); + int lr = ((TObjString*)recArr->At(2))->GetString().Atoi() - 1; + int hb = ((TObjString*)recArr->At(3))->GetString().Atoi(); + int np = ((TObjString*)recArr->At(4))->GetString().Atoi(); + fRequirePoints = kTRUE; + if (recOpt == "LAYER") { + if (lr<0 || lr>5) {stopped = kTRUE; break;} + if (hb>0) fNReqLayUp[lr] = np; + else if (hb<0) fNReqLayDown[lr] = np; + else fNReqLay[lr] = np; + } + else if (recOpt == "DETECTOR") { + if (lr<0 || lr>2) {stopped = kTRUE; break;} + if (hb>0) fNReqDetUp[lr] = np; + else if (hb<0) fNReqDetDown[lr] = np; + else fNReqDet[lr] = np; + } + else {stopped = kTRUE; break;} + } + else {stopped = kTRUE; break;} + } + // + // global constraints on the subunits/orphans + else if (recTitle == "CONSTRAINT_ORPHANS") { //------------------------ + // expect CONSTRAINT_ORPHANS MEAN/MEDIAN Value parID0 ... parID1 ... + if (nrecElems<4) {stopped = kTRUE; break;} + recExt = recArr->At(2)->GetName(); + if (!recExt.IsFloat()) {stopped = kTRUE; break;} + double val = recExt.Atof(); + UInt_t pattern = 0; + for (irec=3;irecAt(irec)->GetName(); + if (!recExt.IsDigit()) {stopped = kTRUE; break;} + pattern |= 0x1 << recExt.Atoi(); + } + if (stopped) break; + if (recOpt == "MEAN") ConstrainOrphansMean(val,pattern); + else if (recOpt == "MEDIAN") ConstrainOrphansMedian(val,pattern); + else {stopped = kTRUE; break;} + } + // + else if (recTitle == "CONSTRAINT_SUBUNITS") { //------------------------ + // expect ONSTRAINT_SUBUNITS MEAN/MEDIAN Value parID0 ... parID1 ... VolID1 ... VolIDn - VolIDm + if (nrecElems<5) {stopped = kTRUE; break;} + recExt = recArr->At(2)->GetName(); + if (!recExt.IsFloat()) {stopped = kTRUE; break;} + double val = recExt.Atof(); + UInt_t pattern = 0; + for (irec=3;irecAt(irec)->GetName(); + if (!recExt.IsDigit()) {stopped = kTRUE; break;} + int parid = recExt.Atoi(); + if (paridAt(irec)->GetName(); + if (recExt == "-") {rangeStart = curID; continue;} // range is requested + else if (!recExt.IsDigit()) {stopped = kTRUE; break;} + else curID = recExt.Atoi(); + // + if (curID<=kMaxITSSensID) curID = GetModuleVolumeID(curID); + // this was a range start or single + int start; + if (rangeStart>=0) {start = rangeStart+1; rangeStart=-1;} // continue the range + else start = curID; // create constraint either for single module (or 1st in the range) + for (int id=start;id<=curID;id++) { + int id0 = IsVIDDefined(id); + if (id0<0) {AliDebug(3,Form("Undefined module %d requested in the SubUnits constraint, skipping",id)); continue;} + if (meanC) ConstrainModuleSubUnitsMean(id0,val,pattern); + else ConstrainModuleSubUnitsMedian(id0,val,pattern); + } + } + if (rangeStart>=0) stopped = kTRUE; // unfinished range + if (stopped) break; + } + // + // association of modules with local constraints + else if (recTitle == "APPLY_CONSTRAINT") { //------------------------ + // expect APPLY_CONSTRAINT NAME [NAME1...] [VolID1 ... VolIDn - VolIDm] + if (nrecElems<3) {stopped = kTRUE; break;} + int nmID0=-1,nmID1=-1; + for (irec=1;irecAt(irec)->GetName(); + if (recExt.IsFloat()) break; + // check if such a constraint was declared + if (!GetConstraint(recExt.Data())) { + AliInfo(Form("No Local constraint %s was declared",recExt.Data())); + stopped=kTRUE; + break; + } + if (nmID0<0) nmID0 = irec; + nmID1 = irec; + } + if (stopped) break; + // + if (irec>=nrecElems) {stopped = kTRUE; break;} // no modules provided + // + // now read the list of modules to constrain + int curID = -1; + int rangeStart = -1; + for (;irecAt(irec)->GetName(); + if (recExt == "-") {rangeStart = curID; continue;} // range is requested + else if (!recExt.IsDigit()) {stopped = kTRUE; break;} + else curID = recExt.Atoi(); + // + if (curID<=kMaxITSSensID) curID = GetModuleVolumeID(curID); + // + // this was a range start or single + int start; + if (rangeStart>=0) {start = rangeStart+1; rangeStart=-1;} // continue the range + else start = curID; // create constraint either for single module (or 1st in the range) + for (int id=start;id<=curID;id++) { + AliITSAlignMille2Module *md = GetMilleModuleByVID(id); + if (!md) {AliDebug(3,Form("Undefined module %d requested in the Local constraint, skipping",id)); continue;} + for (int nmid=nmID0;nmid<=nmID1;nmid++) + ((AliITSAlignMille2ConstrArray*)GetConstraint(recArr->At(nmid)->GetName()))->AddModule(md); + } + } + if (rangeStart>=0) stopped = kTRUE; // unfinished range + if (stopped) break; + } + // + else continue; // already processed record + // + } // end of while loop 4 over the various params // - } // end while - // - fNModules = nmod; - fNGlobal = fNModules*kNParCh; + break; + } // end of while(1) loop // fclose(pfc); + if (stopped) { + AliError(Form("Failed on record %s %s ...\n",recTitle.Data(),recOpt.Data())); + return -1; + } + // + fIsConfigured = kTRUE; + return 0; +} + +//________________________________________________________________________________________________________ +void AliITSAlignMille2::BuildHierarchy() +{ + // build the hieararhy of the modules to align // + if (!GetUseGlobalDelta() && PseudoParentsAllowed()) { + AliInfo("PseudoParents mode is allowed only when the deltas are global\n" + "Since Deltas are local, switching to NoPseudoParents"); + SetAllowPseudoParents(kFALSE); + } // set parent/child relationship for modules to align - printf("Setting parent/child relationships\n"); + AliInfo("Setting parent/child relationships\n"); // - for (int ipar=0;ipar parent reference + for (int ipar=0;iparGetIndex()<=kMaxITSSensID) continue; // sensor cannot be a parent + if (parent->IsSensor()) continue; // sensor cannot be a parent // - for (int icld=0;icldBelongsTo(parent)) continue; + // child cannot have more sensors than the parent + if (child->GetNSensitiveVolumes() > parent->GetNSensitiveVolumes()) continue; // AliITSAlignMille2Module* parOld = child->GetParent(); + // is this parent candidate closer than the old parent ? if (parOld && parOld->GetNSensitiveVolumes()GetNSensitiveVolumes()) continue; // parOld is closer child->SetParent(parent); } // } // + // add parent -> children reference + for (int icld=0;icldGetParent(); + if (parent) parent->AddChild(child); + } + // // reorder the modules in such a way that parents come first - for (int icld=0;icldGetParent()) && (parent->GetUniqueID()GetUniqueID()) ) { + while ( (parent=child->GetParent()) && (parent->GetUniqueID()>child->GetUniqueID()) ) { // swap fMilleModule[icld] = parent; fMilleModule[parent->GetUniqueID()] = child; @@ -363,36 +692,61 @@ Int_t AliITSAlignMille2::LoadConfig(const Char_t *cfile) { child = parent; } // - } + } // - // go over the child->parent chain and mark modules with explicitly provided sensors - for (int icld=nmod;icld--;) { + // Go over the child->parent chain and mark modules with explicitly provided sensors. + // If the sensors of the unit are explicitly declared, all undeclared sensors are + // suppresed in this unit. + for (int icld=fNModules;icld--;) { AliITSAlignMille2Module* child = GetMilleModule(icld); AliITSAlignMille2Module* parent = child->GetParent(); if (!parent) continue; - parent->SetSensorsProvided( child->AreSensorsProvided() ); - if (!parent->AreSensorsProvided()) continue; - // suppress unused sensors - for (int isn=0;isnGetNSensitiveVolumes();isn++) { - int snVID = parent->GetSensVolVolumeID(isn); - // check if this sensor is explicitly requested - for (int imd=nmod;imd--;) if (GetMilleModule(imd)->GetVolumeID() == snVID) {snVID = -1; break;} - // - if (snVID==-1) continue; // found this sensor, do nothing - // - // otherwise, remove this sensor from the module list - AliInfo(Form("Removing sensor %d from %s",snVID,parent->GetName())); - parent->DelSensitiveVolume(isn--); + // + // check if this parent was already processed + if (!parent->AreSensorsProvided()) { + parent->DelSensitiveVolumes(); + parent->SetSensorsProvided(kTRUE); + } + // reattach sensors to parent + for (int isc=child->GetNSensitiveVolumes();isc--;) { + UShort_t senVID = child->GetSensVolVolumeID(isc); + if (!parent->IsIn(senVID)) parent->AddSensitiveVolume(senVID); } } // - fGlobalDerivatives = new Double_t[fNGlobal]; - memset(fGlobalDerivatives,0,fNGlobal*sizeof(Double_t)); - // - return 0; } - +// pepo +//________________________________________________________________________________________________________ +void AliITSAlignMille2::SetCurrentModule(Int_t id) +{ + /// set the current supermodule + // new meaning + if (fMilleVersion>=2) { + fCurrentModule = GetMilleModule(id); + return; + } + // old meaning + if (fMilleVersion<=1) { + Int_t index=id; + /// set as current the SuperModule that contains the 'index' sens.vol. + if (index<0 || index>2197) { + AliInfo("index does not correspond to a sensitive volume!"); + return; + } + UShort_t voluid=AliITSAlignMille2Module::GetVolumeIDFromIndex(index); + Int_t k=IsContained(voluid); + if (k>=0){ + fCluster.SetVolumeID(voluid); + fCluster.SetXYZ(0,0,0); + InitModuleParams(); + } + else + AliInfo(Form("module %d not defined\n",index)); + } +} +// endpepo +//________________________________________________________________________________________________________ void AliITSAlignMille2::SetRequiredPoint(Char_t* where, Int_t ndet, Int_t updw, Int_t nreqpts) { // set minimum number of points in specific detector or layer @@ -417,8 +771,9 @@ void AliITSAlignMille2::SetRequiredPoint(Char_t* where, Int_t ndet, Int_t updw, } } - -Int_t AliITSAlignMille2::GetModuleIndex(const Char_t *symname) { +//________________________________________________________________________________________________________ +Int_t AliITSAlignMille2::GetModuleIndex(const Char_t *symname) +{ /// index from symname if (!symname) return -1; for (Int_t i=0;i<=kMaxITSSensID; i++) { @@ -427,7 +782,9 @@ Int_t AliITSAlignMille2::GetModuleIndex(const Char_t *symname) { return -1; } -Int_t AliITSAlignMille2::GetModuleIndex(UShort_t voluid) { +//________________________________________________________________________________________________________ +Int_t AliITSAlignMille2::GetModuleIndex(UShort_t voluid) +{ /// index from volume ID AliGeomManager::ELayerID lay = AliGeomManager::VolUIDToLayer(voluid); if (lay<1|| lay>6) return -1; @@ -438,7 +795,9 @@ Int_t AliITSAlignMille2::GetModuleIndex(UShort_t voluid) { return idx; } -UShort_t AliITSAlignMille2::GetModuleVolumeID(const Char_t *symname) { +//________________________________________________________________________________________________________ +UShort_t AliITSAlignMille2::GetModuleVolumeID(const Char_t *symname) +{ /// volume ID from symname /// works for sensitive volumes only if (!symname) return 0; @@ -454,7 +813,9 @@ UShort_t AliITSAlignMille2::GetModuleVolumeID(const Char_t *symname) { return 0; } -UShort_t AliITSAlignMille2::GetModuleVolumeID(Int_t index) { +//________________________________________________________________________________________________________ +UShort_t AliITSAlignMille2::GetModuleVolumeID(Int_t index) +{ /// volume ID from index if (index<0) return 0; if (index<2198) @@ -467,64 +828,218 @@ UShort_t AliITSAlignMille2::GetModuleVolumeID(Int_t index) { return 0; } -void AliITSAlignMille2::InitGeometry() { +//________________________________________________________________________________________________________ +Int_t AliITSAlignMille2::InitGeometry() +{ /// initialize geometry + AliInfo("Loading initial geometry"); AliGeomManager::LoadGeometry(fGeometryFileName.Data()); fGeoManager = AliGeomManager::GetGeometry(); if (!fGeoManager) { AliInfo("Couldn't initialize geometry"); - return; + return -1; + } + return 0; +} + +//________________________________________________________________________________________________________ +Int_t AliITSAlignMille2::SetConstraintWrtRef(const char* reffname) +{ + // Load the global deltas from this file. The local gaussian constraints on some modules + // will be defined with respect to the deltas from this reference file, converted to local + // delta format. Note: conversion to local format requires reloading the geometry! + // + AliInfo(Form("Loading reference deltas for local constraints from %s",reffname)); + if (!fGeoManager) return -1; + fConstrRefFileName = reffname; + if (fConstrRefFileName == "IDEAL") { // the reference is the ideal geometry, just create dummy reference array + fConstrRef = new TClonesArray("AliAlignObjParams",1); + return 0; + } + TFile *pref = TFile::Open(fConstrRefFileName.Data()); + if (!pref->IsOpen()) return -2; + fConstrRef = (TClonesArray*)pref->Get("ITSAlignObjs"); + pref->Close(); + delete pref; + if (!fConstrRef) { + AliError(Form("Did not find reference prealignment deltas in %s",reffname)); + return -1; + } + // + // we need ideal geometry to convert global deltas to local ones + if (fUsePreAlignment) { + AliError("The call of SetConstraintWrtRef must be done before application of the prealignment"); + return -1; + } + // + AliInfo("Converting global reference deltas to local ones"); + Int_t nprea = fConstrRef->GetEntriesFast(); + for (int ix=0; ixAt(ix); + if (!preo->ApplyToGeometry()) return -1; } + // + // now convert the global reference deltas to local ones + for (int i=fConstrRef->GetEntriesFast();i--;) { + AliAlignObjParams *preo = (AliAlignObjParams*)fConstrRef->At(i); + TGeoHMatrix * mupd = AliGeomManager::GetMatrix(preo->GetSymName()); + if (!mupd) { // this is not alignable entry, need to look in the supermodules + for (int im=fNSuperModules;im--;) { + AliITSAlignMille2Module* mod = GetSuperModule(im); + if ( strcmp(mod->GetName(), preo->GetSymName()) ) continue; + mupd = mod->GetMatrix(); + break; + } + if (!mupd) { + AliError(Form("Failed to find the volume for reference %s",preo->GetSymName())); + return -1; + } + } + TGeoHMatrix preMat; + preo->GetMatrix(preMat); // Delta_Glob + TGeoHMatrix tmpMat = *mupd; // Delta_Glob * Delta_Glob_Par * M + preMat.MultiplyLeft( &tmpMat.Inverse() ); // M^-1 * Delta_Glob_Par^-1 = (Delta_Glob_Par * M)^-1 + tmpMat.MultiplyLeft( &preMat ); // (Delta_Glob_Par * M)^-1 * Delta_Glob * Delta_Glob_Par * M = Delta_loc + preo->SetMatrix(tmpMat); // local corrections + } + // + // we need to reload the geometry spoiled by this reference deltas... + delete fGeoManager; + AliInfo("Reloading initial geometry"); + AliGeomManager::LoadGeometry(fGeometryFileName.Data()); + fGeoManager = AliGeomManager::GetGeometry(); + return 0; } -void AliITSAlignMille2::Init(Int_t nGlobal, /* number of global paramers */ - Int_t nLocal, /* number of local parameters */ - Int_t nStdDev /* std dev cut */ ) +//________________________________________________________________________________________________________ +void AliITSAlignMille2::Init() { - /// Initialization of AliMillepede. Fix parameters, define constraints ... - fMillepede->InitMille(nGlobal,nLocal,nStdDev,fResCut,fResCutInitial); + // + if (fIsMilleInit) { + AliInfo("Millepede has been already initialized!"); + return; + } + // range constraints in such a way that the childs are constrained before their parents + // orphan constraints come last + for (int ic=0;icGetModuleID()GetModuleID()) { + // swap + fConstraints[ic] = cst1; + fConstraints[ic1] = cst0; + } + } + } + // + if (!GetUseGlobalDelta()) { + AliInfo("ATTENTION: The parameters are defined in the local frame, no check for degeneracy will be done"); + for (int imd=fNModules;imd--;) { + AliITSAlignMille2Module* mod = GetMilleModule(imd); + int npar = mod->GetNParTot(); + // the parameter may have max 1 free instance, otherwise the equations are underdefined + for (int ipar=0;iparIsFreeDOF(ipar)) continue; + mod->SetParOffset(ipar,fNGlobal++); + } + } + } + else { + // init millepede, decide which parameters are to be fitted explicitly + for (int imd=fNModules;imd--;) { + AliITSAlignMille2Module* mod = GetMilleModule(imd); + int npar = mod->GetNParTot(); + // the parameter may have max 1 free instance, otherwise the equations are underdefined + for (int ipar=0;iparIsFreeDOF(ipar)) continue; // fixed + // + int nFreeInstances = 0; + // + AliITSAlignMille2Module* parent = mod; + Bool_t cstMeanMed=kFALSE,cstGauss=kFALSE; + // + Bool_t AddToFit = kFALSE; + // the parameter may be ommitted from explicit fit (if PseudoParentsAllowed is true) if + // 1) it is not explicitly constrained or its does not participate in Gaussian constraint + // 2) the same applies to all of its parents + // 3) it has at least 1 unconstrained direct child + while(parent) { + if (!parent->IsFreeDOF(ipar)) {parent = parent->GetParent(); continue;} + nFreeInstances++; + if (IsParModConstrained(parent,ipar, cstMeanMed, cstGauss)) nFreeInstances--; + if (cstGauss) AddToFit = kTRUE; + parent = parent->GetParent(); + } + if (nFreeInstances>1) { + AliError(Form("Parameter#%d of module %s\nhas %d free instances in the " + "unconstrained parents\nSystem is undefined",ipar,mod->GetName(),nFreeInstances)); + exit(1); + } + // + // i) Are PseudoParents allowed? + if (!PseudoParentsAllowed()) AddToFit = kTRUE; + // ii) check if this module has no child with such a free parameter. Since the order of this check + // goes from child to parent, by this moment such a parameter must have been already added + else if (!IsParModFamilyVaried(mod,ipar)) AddToFit = kTRUE; // no varied children at all + else if (!IsParFamilyFree(mod,ipar,1)) AddToFit = kTRUE; // no unconstrained direct children + // otherwise the value of this parameter can be extracted from simple contraint and the values of + // the relevant parameters of its children the fit is done. Hence it is not included + if (!AddToFit) continue; + // + // shall add this parameter to explicit fit + // printf("Adding %s %d -> %d\n",mod->GetName(), ipar, fNGlobal); + mod->SetParOffset(ipar,fNGlobal++); + } + } + } + // + AliInfo(Form("Initializing Millepede with %d gpar, %d lpar and %d stddev ...",fNGlobal, fNLocal, fNStdDev)); + fGlobalDerivatives = new Double_t[fNGlobal]; + memset(fGlobalDerivatives,0,fNGlobal*sizeof(Double_t)); + // + fMillepede->InitMille(fNGlobal,fNLocal,fNStdDev,fResCut,fResCutInitial); fIsMilleInit = kTRUE; - + // + ResetLocalEquation(); + AliInfo("Parameters initialized to zero"); + // /// Fix non free parameters for (Int_t i=0; iIsFreeDOF(j)) FixParameter(i*kNParCh+j,0.0); - else { - // pepopepo: da verificare il settaggio delle sigma, ma forse va bene... - Double_t parsig=0; - if (j<3) parsig = fParSigTranslations; // translations (0.0100 cm) - else parsig = fParSigRotations; // rotations (1/10 deg) - FixParameter(i*kNParCh+j,parsig); - } - } + AliITSAlignMille2Module* mod = GetMilleModule(i); + for (Int_t j=0; jGetNParTot(); j++) { + if (mod->GetParOffset(j)<0) continue; // not varied + FixParameter(mod->GetParOffset(j),mod->GetParConstraint(j)); + fMillepede->SetParamGrID(i, mod->GetParOffset(j)); + } } // // Set iterations - if (fStartFac>1) fMillepede->SetIterations(fStartFac); + if (fStartFac>1) fMillepede->SetIterations(fStartFac); + // } - -void AliITSAlignMille2::AddConstraint(Double_t *par, Double_t value) { +//________________________________________________________________________________________________________ +void AliITSAlignMille2::AddConstraint(Double_t *par, Double_t value, Double_t sigma) +{ /// Constrain equation defined by par to value - if (!fIsMilleInit) { - AliInfo("Millepede has not been initialized!"); - return; - } - fMillepede->SetGlobalConstraint(par, value); + if (!fIsMilleInit) Init(); + fMillepede->SetGlobalConstraint(par, value, sigma); AliInfo("Adding constraint"); } -void AliITSAlignMille2::InitGlobalParameters(Double_t *par) { +//________________________________________________________________________________________________________ +void AliITSAlignMille2::InitGlobalParameters(Double_t *par) +{ /// Initialize global parameters with par array - if (!fIsMilleInit) { - AliInfo("Millepede has not been initialized!"); - return; - } + if (!fIsMilleInit) Init(); fMillepede->SetGlobalParameters(par); AliInfo("Init Global Parameters"); } - -void AliITSAlignMille2::FixParameter(Int_t iPar, Double_t value) { + +//________________________________________________________________________________________________________ +void AliITSAlignMille2::FixParameter(Int_t iPar, Double_t value) +{ /// Parameter iPar is encourage to vary in [-value;value]. /// If value == 0, parameter is fixed if (!fIsMilleInit) { @@ -535,19 +1050,21 @@ void AliITSAlignMille2::FixParameter(Int_t iPar, Double_t value) { if (value==0) AliInfo(Form("Parameter %i Fixed", iPar)); } +//________________________________________________________________________________________________________ void AliITSAlignMille2::ResetLocalEquation() { /// Reset the derivative vectors for(int i=fNLocal;i--;) fLocalDerivatives[i] = 0.0; - for(int i=fNGlobal;i--;) fGlobalDerivatives[i] = 0.0; + memset(fGlobalDerivatives, 0, fNGlobal*sizeof(double) ); } +//________________________________________________________________________________________________________ Int_t AliITSAlignMille2::ApplyToGeometry() { // apply starting realignment to ideal geometry - // + AliInfo(Form("Using %s for prealignment",fPreAlignmentFileName.Data())); if (!fGeoManager) return -1; - TFile *pref = new TFile(fPreAlignmentFileName.Data()); + TFile *pref = TFile::Open(fPreAlignmentFileName.Data()); if (!pref->IsOpen()) return -2; fPrealignment = (TClonesArray*)pref->Get("ITSAlignObjs"); if (!fPrealignment) return -3; @@ -563,6 +1080,7 @@ Int_t AliITSAlignMille2::ApplyToGeometry() } //TString nms = preo->GetSymName(); //if (!nms.Contains("Ladder")) continue; //RRR + //printf("Applying#%4d %s\n",ix,preo->GetSymName()); if (!preo->ApplyToGeometry()) return -4; } // @@ -573,17 +1091,21 @@ Int_t AliITSAlignMille2::ApplyToGeometry() return 0; } +//________________________________________________________________________________________________________ Int_t AliITSAlignMille2::GetPreAlignmentQualityFactor(Int_t index) const { if (!fUsePreAlignment || index<0 || index>=fPreAlignQF.GetSize()) return -1; return fPreAlignQF[index]-1; } -AliTrackPointArray *AliITSAlignMille2::PrepareTrack(const AliTrackPointArray *atp) { +//________________________________________________________________________________________________________ +AliTrackPointArray *AliITSAlignMille2::PrepareTrack(const AliTrackPointArray *atp) +{ /// create a new AliTrackPointArray keeping only defined modules /// move points according to a given prealignment, if any /// sort alitrackpoints w.r.t. global Y direction, if selected - + const double kTiny = 1E-12; + // AliTrackPointArray *atps=NULL; Int_t idx[20]; Int_t npts=atp->GetNPoints(); @@ -593,10 +1115,10 @@ AliTrackPointArray *AliITSAlignMille2::PrepareTrack(const AliTrackPointArray *at Int_t intidx[20]; for (int j=0; jGetVolumeID()[j]); + intidx[j] = IsVIDContained(atp->GetVolumeID()[j]); if (intidx[j]>=0) ngoodpts++; } - AliDebug(3,Form("Number of points in defined modules: %d",ngoodpts)); + AliDebug(3,Form("Number of points in defined modules: %d out of %d",ngoodpts,npts)); // reject track if not enough points are left if (ngoodptsGetY(),idx); // sort descending... - + TMath::Sort(npts,atp->GetY(),idx); // sort descending... + // Int_t npto=0; for (int i=0; iGetSensitiveVolumeOrigGlobalMatrix(p.GetVolumeID()); + AliITSAlignMille2Module *mod = GetMilleModule(intidx[idx[i]]); + TGeoHMatrix *svOrigMatrix = mod->GetSensitiveVolumeOrigGlobalMatrix(p.GetVolumeID()); // get back real local coordinates: use OriginalGlobalMatrix because AliTrackPoints were written // with idel geometry Double_t pg[3],pl[3]; @@ -689,6 +1215,43 @@ AliTrackPointArray *AliITSAlignMille2::PrepareTrack(const AliTrackPointArray *at svOrigMatrix->MasterToLocal(pg,pl); AliDebug(3,Form("Local coordinates of measured point : X=%f Y=%f Z=%f \n",pl[0],pl[1],pl[2])); + // + // this is a temporary code to extract the drift speed used for given point + if (p.GetDriftTime()>0) { // RRR + // calculate the drift speed + int sid = AliITSAlignMille2Module::GetIndexFromVolumeID(p.GetVolumeID());// - kSDDoffsID; + fDriftTime0[npto] = fInitialRecSDD ? fInitialRecSDD->GetTimeZero(sid) : 0.; + /* + AliGeomManager::ELayerID lay = AliGeomManager::VolUIDToLayer(p.GetVolumeID()); + if (lay==3) fDriftTime0[npto] = pg[2]<0 ? 169.5 : 140.1; + else if (lay==4) fDriftTime0[npto] = pg[2]<0 ? 158.3 : 139.0; + else { + AliError(Form("Strange layer %d for moduleID %d",lay,p.GetVolumeID())); + exit(1); + } + */ + double tdif = p.GetDriftTime() - fDriftTime0[npto]; + if (tdif<=0) tdif = 1; + double vdrift = (3.5085-TMath::Abs(pl[0]))/tdif; + if (vdrift<0) vdrift = 0; + // + // TEMPORARY CORRECTION (if provided) -------------->>> + if (fCorrectSDD) { + float t0Upd = fCorrectSDD->GetTimeZero(sid); + vdrift += fCorrectSDD->GetDeltaVDrift(sid); + tdif = p.GetDriftTime() - t0Upd; + // correct Xlocal + pl[0] = TMath::Sign(3.5085 - vdrift*tdif,pl[0]); + fDriftTime0[npto] = t0Upd; + } + // TEMPORARY CORRECTION (if provided) --------------<<< + fDriftSpeed[npto] = TMath::Sign(vdrift,pl[0]); + // + /* + printf("%d %+6.2f %+6.2f %+6.2f %+5.2f %+5.2f %+5.2f %+6.1f %+6.1f %+f %+f\n", + p.GetVolumeID(),pg[0],pg[1],pg[2],pl[0],pl[1],pl[2],p.GetDriftTime(), fDriftTime0[npto], fDriftSpeed[npto],tdif); + */ + } // update covariance matrix TGeoHMatrix hcov; @@ -704,11 +1267,26 @@ AliTrackPointArray *AliITSAlignMille2::PrepareTrack(const AliTrackPointArray *at hcovel[8]=double(p.GetCov()[5]); hcov.SetRotation(hcovel); // now rotate in local system + // printf("\nErrMatGlob: before\n"); hcov.Print(""); //RRR hcov.Multiply(svOrigMatrix); hcov.MultiplyLeft(&svOrigMatrix->Inverse()); // now hcov is LOCAL COVARIANCE MATRIX - - // >> RS + // apply sigma scaling + // printf("\nErrMatLoc: before\n"); hcov.Print(""); //RRR + Double_t *hcovscl = hcov.GetRotationMatrix(); + // for (int ir=3;ir--;) for (int ic=3;ic--;) hcovscl[ir*3+ic] *= mod->GetSigmaFactor(ir)*mod->GetSigmaFactor(ic); //RRR + // RS TEMPORARY: nullify non-diagonal elements and sigY + hcovscl[5] = 0; + for (int ir=3;ir--;) for (int ic=3;ic--;) { + if (ir==ic) { + if (TMath::Abs(hcovscl[ir*3+ic])GetSigmaFactor(ir)*mod->GetSigmaFactor(ic); //RRR + } + else hcovscl[ir*3+ic] = 0; + } + // + // printf("\nErrMatLoc: after\n"); hcov.Print(""); //RRR + // if (fBug==1) { // correzione bug LAYER 5 SSD temporanea.. int ssdidx=AliITSAlignMille2Module::GetIndexFromVolumeID(p.GetVolumeID()); @@ -718,40 +1296,42 @@ AliTrackPointArray *AliITSAlignMille2::PrepareTrack(const AliTrackPointArray *at if (ladder==19) p.SetVolumeID(AliITSAlignMille2Module::GetVolumeIDFromIndex(ssdidx-1)); } } - - // << RS - /// get (evenctually prealigned) matrix of sens. vol. - TGeoHMatrix *svMatrix = GetMilleModule(intidx[idx[i]])->GetSensitiveVolumeMatrix(p.GetVolumeID()); + TGeoHMatrix *svMatrix = mod->GetSensitiveVolumeMatrix(p.GetVolumeID()); // modify global coordinates according with pre-aligment svMatrix->LocalToMaster(pl,pg); // now rotate in local system hcov.Multiply(&svMatrix->Inverse()); hcov.MultiplyLeft(svMatrix); // hcov is back in GLOBAL RF + // cure once more + for (int ir=3;ir--;) for (int ic=3;ic--;) if (TMath::Abs(hcovscl[ir*3+ic])AddPoint(npto,&p); - AliDebug(2,Form("Adding point[%d] = ( %f , %f , %f ) volid = %d",npto,atps->GetX()[npto],atps->GetY()[npto],atps->GetZ()[npto],atps->GetVolumeID()[npto] )); - + AliDebug(2,Form("Adding point[%d] = ( %f , %f , %f ) volid = %d",npto,atps->GetX()[npto], + atps->GetY()[npto],atps->GetZ()[npto],atps->GetVolumeID()[npto] )); + // printf("Adding %d %d %f\n",npto, p.GetVolumeID(), p.GetY()); npto++; } return atps; } - - -AliTrackPointArray *AliITSAlignMille2::SortTrack(const AliTrackPointArray *atp) { +//________________________________________________________________________________________________________ +AliTrackPointArray *AliITSAlignMille2::SortTrack(const AliTrackPointArray *atp) +{ /// sort alitrackpoints w.r.t. global Y direction AliTrackPointArray *atps=NULL; Int_t idx[20]; @@ -769,8 +1349,19 @@ AliTrackPointArray *AliITSAlignMille2::SortTrack(const AliTrackPointArray *atp) return atps; } +//________________________________________________________________________________________________________ +Int_t AliITSAlignMille2::GetCurrentLayer() const +{ + if (!fGeoManager) { + AliInfo("ITS geometry not initialized!"); + return -1; + } + return (Int_t)AliGeomManager::VolUIDToLayer(fCluster.GetVolumeID()); +} -Int_t AliITSAlignMille2::InitModuleParams() { +//________________________________________________________________________________________________________ +Int_t AliITSAlignMille2::InitModuleParams() +{ /// initialize geometry parameters for a given detector /// for current cluster (fCluster) /// fGlobalInitParam[] is set as: @@ -779,6 +1370,7 @@ Int_t AliITSAlignMille2::InitModuleParams() { /// *** At the moment: using Raffalele's angles definition *** /// /// return 0 if success + /// If module is found but has no parameters to vary, return 1 if (!fGeoManager) { AliInfo("ITS geometry not initialized!"); @@ -793,13 +1385,17 @@ Int_t AliITSAlignMille2::InitModuleParams() { // IT IS VERY IMPORTANT: start from the end of the list, where the childs are located !!! Int_t k=fNModules-1; fCurrentModule = 0; - while (k>=0 && ! (fCurrentModule=GetMilleModule(k))->IsIn(voluid)) { - // VERY IMPORTANT: if the sensors were explicitly provided, don't look in the supermodules - if (fSensorsIn && fCurrentModule->GetVolumeID() > kMaxITSSensVID) {k=-1; break;} - k--; - } + // VERY IMPORTANT: if the sensors were explicitly provided, don't look in the supermodules + while (k>=0 && ! (fCurrentModule=GetMilleModule(k))->IsIn(voluid)) k--; if (k<0) return -3; - // fCurrentModule = GetMilleModule(k); + // + /* + // Check if the module has free params. If not, go over the parents + AliITSAlignMille2Module* mdtmp = fCurrentModule; + while (mdtmp && mdtmp->GetNParFree()==0) mdtmp = mdtmp->GetParent(); + if (!mdtmp) return 1; // nothing to vary here + fCurrentModule = mdtmp; + */ // fModuleInitParam[0] = 0.0; fModuleInitParam[1] = 0.0; @@ -807,7 +1403,8 @@ Int_t AliITSAlignMille2::InitModuleParams() { fModuleInitParam[3] = 0.0; // psi (X) fModuleInitParam[4] = 0.0; // theta (Y) fModuleInitParam[5] = 0.0; // phi (Z) - + fModuleInitParam[6] = 0.0; + fModuleInitParam[7] = 0.0; /// get (evenctually prealigned) matrix of sens. vol. TGeoHMatrix *svMatrix = fCurrentModule->GetSensitiveVolumeMatrix(voluid); @@ -833,7 +1430,7 @@ Int_t AliITSAlignMille2::InitModuleParams() { // now rotate in local system hcov.Multiply(svMatrix); hcov.MultiplyLeft(&svMatrix->Inverse()); - + // // set local sigmas fSigmaLoc[0] = TMath::Sqrt(TMath::Abs(hcov.GetRotationMatrix()[0])); fSigmaLoc[1] = TMath::Sqrt(TMath::Abs(hcov.GetRotationMatrix()[4])); // RS @@ -842,15 +1439,18 @@ Int_t AliITSAlignMille2::InitModuleParams() { // set minimum value for SigmaLoc to 10 micron if (fSigmaLoc[0]<0.0010) fSigmaLoc[0]=0.0010; if (fSigmaLoc[2]<0.0010) fSigmaLoc[2]=0.0010; - + // + /* RRR the rescaling is moved to PrepareTrack // multiply local sigmas by global and module specific factor for (int i=3;i--;) fSigmaLoc[i] *= fSigmaFactor[i]*fCurrentModule->GetSigmaFactor(i); // + */ AliDebug(2,Form("Setting StDev from CovMat : fSigmaLocX=%g fSigmaLocY=%g fSigmaLocZ=%g \n",fSigmaLoc[0] ,fSigmaLoc[1] ,fSigmaLoc[2] )); return 0; } +//________________________________________________________________________________________________________ void AliITSAlignMille2::Print(Option_t*) const { /// @@ -887,13 +1487,11 @@ void AliITSAlignMille2::Print(Option_t*) const } // printf("\n Millepede configuration parameters:\n"); - printf(" init parsig for translations : %.4f\n",fParSigTranslations); - printf(" init parsig for rotations : %.4f\n",fParSigRotations); printf(" init value for chi2 cut : %.4f\n",fStartFac); printf(" first iteration cut value : %.4f\n",fResCutInitial); printf(" other iterations cut value : %.4f\n",fResCut); printf(" number of stddev for chi2 cut : %d\n",fNStdDev); - printf(" mult. fact. for local sigmas : %.4f %.4f %.4f\n",fSigmaFactor[0],fSigmaFactor[1],fSigmaFactor[2]); + printf(" def.scaling for local sigmas : %.4f %.4f %.4f\n",fSigmaFactor[0],fSigmaFactor[1],fSigmaFactor[2]); printf("List of defined modules:\n"); printf(" intidx\tindex\tvoluid\tname\n"); @@ -903,19 +1501,66 @@ void AliITSAlignMille2::Print(Option_t*) const } } +//________________________________________________________________________________________________________ AliITSAlignMille2Module *AliITSAlignMille2::GetMilleModuleByVID(UShort_t voluid) const { - // return pointer to a define supermodule + // return pointer to a defined supermodule // return NULL if error - Int_t i=IsDefined(voluid); + Int_t i=IsVIDDefined(voluid); if (i<0) return NULL; return GetMilleModule(i); } -Bool_t AliITSAlignMille2::InitRiemanFit() +//________________________________________________________________________________________________________ +AliITSAlignMille2Module *AliITSAlignMille2::GetMilleModuleBySymName(const Char_t* symname) const { - // Initialize Riemann Fitter for current track - // return kFALSE if error + // return pointer to a defined supermodule + // return NULL if error + UShort_t vid = AliITSAlignMille2Module::GetVolumeIDFromSymname(symname); + if (vid>0) return GetMilleModuleByVID(vid); + else { // this is not alignable module, need to look within defined supermodules + int i = IsSymDefined(symname); + if (i>=0) return GetMilleModule(i); + } + return 0; +} + +//________________________________________________________________________________________________________ +AliITSAlignMille2Module *AliITSAlignMille2::GetMilleModuleIfContained(const Char_t* symname) const +{ + // return pointer to a defined/contained supermodule + // return NULL otherwise + int i = IsSymContained(symname); + return i<0 ? 0 : GetMilleModule(i); +} + +//________________________________________________________________________________________________________ +AliAlignObjParams* AliITSAlignMille2::GetPrealignedObject(const Char_t* symname) const +{ + if (!fPrealignment) return 0; + for (int ipre=fPrealignment->GetEntriesFast();ipre--;) { // was the corresponding object prealigned? + AliAlignObjParams* preob = (AliAlignObjParams*)fPrealignment->At(ipre); + if (!strcmp(preob->GetSymName(),symname)) return preob; + } + return 0; +} + +//________________________________________________________________________________________________________ +AliAlignObjParams* AliITSAlignMille2::GetConstrRefObject(const Char_t* symname) const +{ + if (!fConstrRef) return 0; + for (int ipre=fConstrRef->GetEntriesFast();ipre--;) { // was the corresponding object prealigned? + AliAlignObjParams* preob = (AliAlignObjParams*)fConstrRef->At(ipre); + if (!strcmp(preob->GetSymName(),symname)) return preob; + } + return 0; +} + +//________________________________________________________________________________________________________ +Bool_t AliITSAlignMille2::InitRiemanFit() +{ + // Initialize Riemann Fitter for current track + // return kFALSE if error if (!fBOn) return kFALSE; @@ -944,6 +1589,7 @@ Bool_t AliITSAlignMille2::InitRiemanFit() return kTRUE; } +//________________________________________________________________________________________________________ Bool_t fullErr2D = kTRUE; void trackFit2D(Int_t &, Double_t *, double &chi2, double *par, int) @@ -995,6 +1641,7 @@ void trackFit2D(Int_t &, Double_t *, double &chi2, double *par, int) // } +//________________________________________________________________________________________________________ void AliITSAlignMille2::InitTrackParams(int meth) { /// initialize local parameters with different methods @@ -1027,7 +1674,6 @@ void AliITSAlignMille2::InitTrackParams(int meth) // fLocalInitParam[1] = (sZ*sYY-sY*sZY)/det; fLocalInitParam[3] = (sZY*npts-sY*sZ)/det; - //AliDebug(2,Form("X = p0gx + ugx*Y : p0gx = %f +- %f ugx = %f +- %f\n",fLocalInitParam[0],f1->GetParError(0),fLocalInitParam[2],f1->GetParError(1))); AliDebug(2,Form("X = p0gx + ugx*Y : p0gx = %f ugx = %f\n",fLocalInitParam[0],fLocalInitParam[2])); // if (meth==1) return; @@ -1055,7 +1701,7 @@ void AliITSAlignMille2::InitTrackParams(int meth) // arglist[0] = 1000; // number of function calls arglist[1] = 0.001; // tolerance - fullErr2D = kTRUE; + fullErr2D = kFALSE;//kTRUE; minuit->ExecuteCommand("MIGRAD",arglist,2); // for (int i=0;i<4;i++) fLocalInitParam[i] = minuit->GetParameter(i); @@ -1063,38 +1709,51 @@ void AliITSAlignMille2::InitTrackParams(int meth) // } +//________________________________________________________________________________________________________ +Int_t AliITSAlignMille2::IsSymDefined(const Char_t* symname) const +{ + // checks if supermodule with this symname is defined and return the internal index + // return -1 if not. + for (int k=fNModules;k--;) if (!strcmp(symname,GetMilleModule(k)->GetName())) return k; + return -1; +} + +//________________________________________________________________________________________________________ +Int_t AliITSAlignMille2::IsSymContained(const Char_t* symname) const +{ + // checks if module with this symname is defined and return the internal index + // return -1 if not. + UShort_t vid = AliITSAlignMille2Module::GetVolumeIDFromSymname(symname); + if (vid>0) return IsVIDContained(vid); + // only sensors have real vid, but maybe we have a supermodule with fake vid? + // IMPORTANT: always start from the end to start from the sensors + return IsSymDefined(symname); +} -Int_t AliITSAlignMille2::IsDefined(UShort_t voluid) const +//________________________________________________________________________________________________________ +Int_t AliITSAlignMille2::IsVIDDefined(UShort_t voluid) const { // checks if supermodule 'voluid' is defined and return the internal index - // return -1 if error - Int_t k = fNModules-1; - while ( k>=0 && !(voluid==GetMilleModule(k)->GetVolumeID()) ) k--; - if (k<0) return -1; - return k; + // return -1 if not. + for (int k=fNModules;k--;) if (voluid==GetMilleModule(k)->GetVolumeID()) return k; + return -1; } -Int_t AliITSAlignMille2::IsContained(UShort_t voluid) const +//________________________________________________________________________________________________________ +Int_t AliITSAlignMille2::IsVIDContained(UShort_t voluid) const { - // checks if the sensitive module 'voluid' is contained inside a supermodule and return the internal index of the last identified supermodule + // checks if the sensitive module 'voluid' is contained inside a supermodule + // and return the internal index of the last identified supermodule // return -1 if error + // IMPORTANT: always start from the end to start from the sensors if (AliITSAlignMille2Module::GetIndexFromVolumeID(voluid)<0) return -1; - Int_t k=fNModules-1; - while (k>=0 && !(GetMilleModule(k)->IsIn(voluid)) ) k--; - if (k<0) return -1; - return k; + for (int k=fNModules;k--;) if (GetMilleModule(k)->IsIn(voluid)) return k; + return -1; } -Bool_t AliITSAlignMille2::CheckVolumeID(UShort_t voluid) const +//________________________________________________________________________________________________________ +Int_t AliITSAlignMille2::CheckCurrentTrack() { - /// check if a sensitive volume is contained inside one of the defined supermodules - Int_t k=fNModules-1; - while (k>=0 && !(GetMilleModule(k)->IsIn(voluid)) ) k--; - if (k>=0) return kTRUE; - return kFALSE; -} - -Int_t AliITSAlignMille2::CheckCurrentTrack() { /// checks if AliTrackPoints belongs to defined modules /// return number of good poins /// return 0 if not enough points @@ -1102,28 +1761,22 @@ Int_t AliITSAlignMille2::CheckCurrentTrack() { Int_t npts = fTrack->GetNPoints(); Int_t ngoodpts=0; // debug points - for (int j=0; jGetVolumeID()[j]; - if (CheckVolumeID(voluid)) { - ngoodpts++; - } - } - + for (int j=0; jGetVolumeID()[j])>=0) ngoodpts++; + // if (ngoodptsGetNPoints(); AliDebug(2,Form("*** Input track with %d points ***",npts)); @@ -1134,6 +1787,9 @@ Int_t AliITSAlignMille2::ProcessTrack(const AliTrackPointArray *track) { if (!fTrack) return -1; npts = fTrack->GetNPoints(); + if (npts>kMaxPoints) { + AliError(Form("Compiled with kMaxPoints=%d, current track has %d points",kMaxPoints,npts)); + } AliDebug(2,Form("*** Processing prepared track with %d points ***",npts)); if (!fBOn) { // straight lines @@ -1149,17 +1805,18 @@ Int_t AliITSAlignMille2::ProcessTrack(const AliTrackPointArray *track) { // local parms (fLocalInitParam[]) are the Riemann Fitter params if (!InitRiemanFit()) { AliInfo("Riemann fit failed! skipping this track..."); - delete fTrack; fTrack=NULL; return -5; } } Int_t nloceq=0; - static Mille2Data md[100]; - + Int_t ngloeq=0; + static Mille2Data md[kMaxPoints]; + // for (Int_t ipt=0; iptGetPoint(fCluster,ipt); + fCluster.SetUniqueID(ipt); AliDebug(2,Form("\n--- processing point %d --- \n",ipt)); // set geometry parameters for the the current module @@ -1168,15 +1825,15 @@ Int_t AliITSAlignMille2::ProcessTrack(const AliTrackPointArray *track) { track->GetVolumeID()[ipt], fCurrentModule->GetIndex(), fCurrentModule->GetUniqueID(), AliGeomManager::SymName(track->GetVolumeID()[ipt]) )); AliDebug(2,Form(" Preprocessed Point = ( %f , %f , %f ) \n",fCluster.GetX(),fCluster.GetY(),fCluster.GetZ())); - - if (!AddLocalEquation(md[nloceq])) nloceq++; - else fTotBadLocEqPoints++; + int res = AddLocalEquation(md[nloceq]); + if (res<0) {fTotBadLocEqPoints++; nloceq = 0; break;} + else if (res==0) nloceq++; + else {nloceq++; ngloeq++;} } // end loop over points // - delete fTrack; fTrack=NULL; - // not enough good points! - if (nloceqGetSensitiveVolumeModifiedMatrix(fCluster.GetVolumeID(),gpar, - !fUseGlobalDelta); - if (!fTempHMat) return -1; + TGeoHMatrix *tempHMat = fCurrentModule->GetSensitiveVolumeModifiedMatrix(fCluster.GetVolumeID(),gpar, + !fUseGlobalDelta); + if (!tempHMat) return -1; Double_t v0g[3]; // vector with straight line direction in global coord. Double_t p0g[3]; // point of the straight line (glo) @@ -1266,8 +1925,8 @@ Int_t AliITSAlignMille2::CalcIntersectionPoint(Double_t *lpar, Double_t *gpar) { // same in local coord. Double_t p0l[3],v0l[3]; - fTempHMat->MasterToLocalVect(v0g,v0l); - fTempHMat->MasterToLocal(p0g,p0l); + tempHMat->MasterToLocalVect(v0g,v0l); + tempHMat->MasterToLocal(p0g,p0l); if (TMath::Abs(v0l[1])<1e-15) { AliInfo("Track Y direction in local frame is zero! Cannot proceed..."); @@ -1280,13 +1939,15 @@ Int_t AliITSAlignMille2::CalcIntersectionPoint(Double_t *lpar, Double_t *gpar) { fPintLoc[2] = p0l[2] - (v0l[2]/v0l[1])*p0l[1]; // global intersection point - fTempHMat->LocalToMaster(fPintLoc,fPintGlo); + tempHMat->LocalToMaster(fPintLoc,fPintGlo); AliDebug(3,Form("Intesect. point: L( %f , %f , %f ) G( %f , %f , %f )\n",fPintLoc[0],fPintLoc[1],fPintLoc[2],fPintGlo[0],fPintGlo[1],fPintGlo[2])); return 0; } -Int_t AliITSAlignMille2::CalcDerivatives(Int_t paridx, Bool_t islpar) { +//________________________________________________________________________________________________________ +Int_t AliITSAlignMille2::CalcDerivatives(Int_t paridx, Bool_t islpar) +{ /// calculate numerically (ROOT's style) the derivatives for /// local X intersection and local Z intersection /// parlist: local (islpar=kTRUE) pgx0, pgz0, ugx0, ugz0 OR riemann's params @@ -1294,19 +1955,21 @@ Int_t AliITSAlignMille2::CalcDerivatives(Int_t paridx, Bool_t islpar) { /// return 0 if success // copy initial parameters - Double_t lpar[ITSMILLE2_NLOCAL]; - Double_t gpar[ITSMILLE2_NPARCH]; - for (Int_t i=0; iGetNParFree()==0) continue; + nmodTested++; + for (Int_t i=0; iGetParOffset(i)<0) continue; // this parameter is not explicitly fitted + if (!dfDone[i]) { + if (CalcDerivatives(i,kFALSE)) return -1; + else { + dfDone[i] = kTRUE; + if (zeroX) zeroX = fDerivativeGlo[i][0]==0; + if (zeroZ) zeroZ = fDerivativeGlo[i][2]==0; + } + } + // + m.dergloX[ifill] = fDerivativeGlo[i][0]; + m.dergloZ[ifill] = fDerivativeGlo[i][2]; + m.parMilleID[ifill++] = fCurrentModule->GetParOffset(i); + } + // + // specific for special sensors + if ( fCurrentModule->IsSDD() && + (fCurrentModule->GetParOffset(AliITSAlignMille2Module::kDOFT0)>=0 || + fCurrentModule->GetParOffset(AliITSAlignMille2Module::kDOFDV)>=0) ) { + // + // assume for sensor local xloc = xloc0 + V0*dT0+dV*(T-T0) + // where V0 and T are the nominal drift velocity, time and time0 + // and the dT0 and dV are the corrections: + // dX/dT0 = dX/dxloc * dxloc/dT0 = dX/dxloc * V0 + // dX/dV = dX/dxloc * dxloc/dV = dX/dxloc * (T-T0) + // IMPORTANT: the geom derivatives are over the SENSOR LOCAL parameters + // + if (!dfDone[AliITSAlignMille2Module::kDOFT0] || !dfDone[AliITSAlignMille2Module::kDOFDV]) { + // + double dXdxlocsens=0., dZdxlocsens=0.; + // + // if the current module is the sensor itself and we work with local params, then + // we can directly take dX/dxloc_sens dZ/dxloc_sens + if (!fUseGlobalDelta && fCurrentModule->GetVolumeID()==fCluster.GetVolumeID()) { + if (dfDone[AliITSAlignMille2Module::kDOFTX]) { + CalcDerivatives(AliITSAlignMille2Module::kDOFTX,kFALSE); + dfDone[AliITSAlignMille2Module::kDOFTX] = kTRUE; + } + dXdxlocsens = fDerivativeGlo[AliITSAlignMille2Module::kDOFTX][0]; + dZdxlocsens = fDerivativeGlo[AliITSAlignMille2Module::kDOFTX][2]; + } + // + else { // need to perform some transformations + // fetch the jacobian of the transformation from the sensors local frame to the frame + // where the parameters are defined: + // Global: dX/dxloc_sens = dX/dxgl*dxgl/dxloc_sens + ...dX/dphigl*dphigl/dxloc_sens + if (fUseGlobalDelta) fCurrentModule->CalcDerivGloLoc(fCluster.GetVolumeID(), + AliITSAlignMille2Module::kDOFTX, jacobian); + // Local: dX/dxloc_sens = dX/dxcurr*dxcurr/dxloc_sens +..+dX/dphicurr * dphicurr/dxloc_sens + else fCurrentModule->CalcDerivCurLoc(fCluster.GetVolumeID(), + AliITSAlignMille2Module::kDOFTX, jacobian); + // + for (int j=0;jGetParOffset(AliITSAlignMille2Module::kDOFT0)>=0) { + m.dergloX[ifill] = fDerivativeGlo[AliITSAlignMille2Module::kDOFT0][0]; + m.dergloZ[ifill] = fDerivativeGlo[AliITSAlignMille2Module::kDOFT0][2]; + m.parMilleID[ifill++] = fCurrentModule->GetParOffset(AliITSAlignMille2Module::kDOFT0); + } + // + if (fCurrentModule->GetParOffset(AliITSAlignMille2Module::kDOFDV)>=0) { + m.dergloX[ifill] = fDerivativeGlo[AliITSAlignMille2Module::kDOFDV][0]; + m.dergloZ[ifill] = fDerivativeGlo[AliITSAlignMille2Module::kDOFDV][2]; + m.parMilleID[ifill++] = fCurrentModule->GetParOffset(AliITSAlignMille2Module::kDOFDV); } } - // for (Int_t i=0; iGetUniqueID(); - nLev++; // + m.moduleID[m.nModFilled++] = fCurrentModule->GetUniqueID(); } while( (fCurrentModule=fCurrentModule->GetParent()) ); // + if (nmodTested>0 && zeroX) {AliInfo("Aborting: zero global X derivatives!");return -1;} + if (nmodTested>0 && zeroZ) {AliInfo("Aborting: zero global Z derivatives!");return -1;} + // // ok, can copy to m AliDebug(2,Form("Adding local equation X with fMeas=%.6f and fSigma=%.6f",(fMeasLoc[0]-fPintLoc0[0]), fSigmaLoc[0])); m.measX = fMeasLoc[0]-fPintLoc0[0]; @@ -1456,13 +2210,15 @@ Int_t AliITSAlignMille2::AddLocalEquation(Mille2Data &m) { m.measZ = fMeasLoc[2]-fPintLoc0[2]; m.sigmaZ = fSigmaLoc[2]; // - m.levFilled = nLev; + m.nGlobFilled = ifill; fCurrentModule = endModule; // - return 0; + return Int_t(!zeroX && !zeroZ); } -void AliITSAlignMille2::SetLocalEquations(const Mille2Data *marr, Int_t neq) { +//________________________________________________________________________________________________________ +void AliITSAlignMille2::SetLocalEquations(const Mille2Data *marr, Int_t neq) +{ /// Set local equations with data stored in m /// return 0 if success // @@ -1473,49 +2229,53 @@ void AliITSAlignMille2::SetLocalEquations(const Mille2Data *marr, Int_t neq) { // set equation for Xloc coordinate AliDebug(2,Form("setting local equation X with fMeas=%.6f and fSigma=%.6f",m.measX, m.sigmaX)); for (int i=fNLocal; i--;) SetLocalDerivative( i, m.derlocX[i] ); - for (int il=m.levFilled;il--;) { - GetMilleModule(m.moduleIDX[il])->IncNProcessedPoints(); - int hlev = m.moduleIDX[il]*ITSMILLE2_NPARCH; // id of the supermodule - int llev = il*ITSMILLE2_NPARCH; - for (int i=ITSMILLE2_NPARCH; i--;) SetGlobalDerivative( hlev+i, m.dergloX[llev+i] ); - } - // + for (int i=m.nGlobFilled;i--;) SetGlobalDerivative( m.parMilleID[i] , m.dergloX[i] ); fMillepede->SetLocalEquation(fGlobalDerivatives, fLocalDerivatives, m.measX, m.sigmaX); // // set equation for Zloc coordinate AliDebug(2,Form("setting local equation Z with fMeas=%.6f and fSigma=%.6f",m.measZ, m.sigmaZ)); for (int i=fNLocal; i--;) SetLocalDerivative( i, m.derlocZ[i] ); - for (int il=m.levFilled;il--;) { - int hlev = m.moduleIDX[il]*ITSMILLE2_NPARCH; // id of the supermodule - int llev = il*ITSMILLE2_NPARCH; - for (int i=ITSMILLE2_NPARCH; i--;) SetGlobalDerivative(hlev+i, m.dergloZ[llev+i] ); - } + for (int i=m.nGlobFilled;i--;) SetGlobalDerivative( m.parMilleID[i] , m.dergloZ[i] ); fMillepede->SetLocalEquation(fGlobalDerivatives, fLocalDerivatives, m.measZ, m.sigmaZ); + // + for (int i=m.nModFilled;i--;) GetMilleModule(m.moduleID[i])->IncNProcessedPoints(); + // } } -Int_t AliITSAlignMille2::GlobalFit(Double_t *parameters,Double_t *errors,Double_t *pulls) { +//________________________________________________________________________________________________________ +Int_t AliITSAlignMille2::GlobalFit() +{ /// Call global fit; Global parameters are stored in parameters - if (!fIsMilleInit) { - AliInfo("Millepede has not been initialized!"); - return 0; - } - int res = fMillepede->GlobalFit(parameters,errors,pulls); + if (!fIsMilleInit) Init(); + // + ApplyPreConstraints(); + int res = fMillepede->GlobalFit(); AliInfo(Form("%s fitting global parameters!",res ? "Done":"Failed")); - return res; -} + if (res) { + // fetch the parameters + for (int imd=fNModules;imd--;) { + AliITSAlignMille2Module* mod = GetMilleModule(imd); + int nprocp = 0; + for (int ip=mod->GetNParTot();ip--;) { + int idp = mod->GetParOffset(ip); + if (idp<0) continue; // was not in the explicit fit + mod->SetParVal(ip,fMillepede->GetFinalParam(idp)); + mod->SetParErr(ip,fMillepede->GetFinalError(idp)); + int np = fMillepede->GetProcessedPoints(idp); + if (TMath::Abs(np)>TMath::Abs(nprocp)) nprocp = np; + } + if (!mod->GetNProcessedPoints()) mod->SetNProcessedPoints(nprocp); + } -Double_t AliITSAlignMille2::GetParError(Int_t iPar) { - /// Get error of parameter iPar - if (!fIsMilleInit) { - AliInfo("Millepede has not been initialized!"); - return 0; } - Double_t lErr = fMillepede->GetParError(iPar); - return lErr; + ApplyPostConstraints(); + return res; } -void AliITSAlignMille2::PrintGlobalParameters() { +//________________________________________________________________________________________________________ +void AliITSAlignMille2::PrintGlobalParameters() +{ /// Print global parameters if (!fIsMilleInit) { AliInfo("Millepede has not been initialized!"); @@ -1524,7 +2284,7 @@ void AliITSAlignMille2::PrintGlobalParameters() { fMillepede->PrintGlobalParameters(); } -// //_________________________________________________________________________ +//________________________________________________________________________________________________________ Int_t AliITSAlignMille2::LoadSuperModuleFile(const Char_t *sfile) { // load definitions of supermodules from a root file @@ -1556,6 +2316,7 @@ Int_t AliITSAlignMille2::LoadSuperModuleFile(const Char_t *sfile) a->GetMatrix(m); // sscanf(st,"%s",symname); + // // decode module list char *stp=strstr(st,"ModuleList:"); if (!stp) return -3; @@ -1604,236 +2365,561 @@ Int_t AliITSAlignMille2::LoadSuperModuleFile(const Char_t *sfile) } } Int_t smindex=int(2198+volid-14336); // virtual index + // fSuperModule.AddAtAndExpand(new AliITSAlignMille2Module(smindex,volid,symname,&m,n,volidsv),fNSuperModules); // fNSuperModules++; } - + // smf->Close(); // return 0; } -//_________________________________________________________________________ -void AliITSAlignMille2::ConstrainModuleSubUnits(Int_t idm, Double_t val, UInt_t pattern) +//________________________________________________________________________________________________________ +void AliITSAlignMille2::ConstrainModuleSubUnitsMean(Int_t idm, Double_t val, UInt_t pattern) { // require that sum of modifications for the childs of this module is = val, i.e. // the internal corrections moves the module as a whole by fixed value (0 by default). // pattern is the bit pattern for the parameters to constrain // - static TObjArray childs; - childs.Clear(); - // - // build list of childs for this module - int nChilds = 0; - AliITSAlignMille2Module* parent = GetMilleModule(idm); - if (!parent) return; - // - for (int i=fNModules;i--;) { - AliITSAlignMille2Module* child = GetMilleModule(i); - if (child->GetParent() == parent) childs.AddAtAndExpand(child,nChilds++); - } - if (nChilds<1) return; - // - int npc = 0; - for (int ip=0;ip>ip)&0x1) /*|| !parent->IsFreeDOF(ip)*/) continue; - ResetLocalEquation(); - for (int ich=nChilds;ich--;) fGlobalDerivatives[childs[ich]->GetUniqueID()*kNParCh+ip] = 1.0; - AddConstraint(fGlobalDerivatives,val); - npc++; + if (fIsMilleInit) { + AliInfo("Millepede has been already initialized: no constrain may be added!"); + return; } - // - AliInfo(Form("Constrained %d params for %d submodules of module #%d: %s",npc,nChilds,idm,parent->GetName())); - // + if (!GetMilleModule(idm)->GetNChildren()) return; + TString nm = "cstrSUMean"; + nm += GetNConstraints(); + AliITSAlignMille2Constraint *cstr = new AliITSAlignMille2Constraint(nm.Data(),AliITSAlignMille2Constraint::kTypeMean, + idm,val,pattern); + cstr->SetConstraintID(GetNConstraints()); + fConstraints.Add(cstr); } -//_________________________________________________________________________ -void AliITSAlignMille2::PostConstrainModuleSubUnitsMedian(Int_t idm, Double_t val, UInt_t pattern) +//________________________________________________________________________________________________________ +void AliITSAlignMille2::ConstrainModuleSubUnitsMedian(Int_t idm, Double_t val, UInt_t pattern) { // require that median of the modifications for the childs of this module is = val, i.e. // the internal corrections moves the module as a whole by fixed value (0 by default) // module the outliers. // pattern is the bit pattern for the parameters to constrain // The difference between the mean and the median will be transfered to the parent + if (fIsMilleInit) { + AliInfo("Millepede has been already initialized: no constrain may be added!"); + return; + } + if (!GetMilleModule(idm)->GetNChildren()) return; + TString nm = "cstrSUMed"; + nm += GetNConstraints(); + AliITSAlignMille2Constraint *cstr = new AliITSAlignMille2Constraint(nm.Data(),AliITSAlignMille2Constraint::kTypeMedian, + idm,val,pattern); + cstr->SetConstraintID(GetNConstraints()); + fConstraints.Add(cstr); +} + +//________________________________________________________________________________________________________ +void AliITSAlignMille2::ConstrainOrphansMean(Double_t val, UInt_t pattern) +{ + // require that median of the modifications for the supermodules which have no parents is = val, i.e. + // the corrections moves the whole setup by fixed value (0 by default) modulo the outliers. + // pattern is the bit pattern for the parameters to constrain // - static TObjArray childs; - childs.Clear(); - // - // build list of childs for this module - int nChilds = 0; - AliITSAlignMille2Module* parent = GetMilleModule(idm); - if (!parent) return; + if (fIsMilleInit) { + AliInfo("Millepede has been already initialized: no constrain may be added!"); + return; + } + TString nm = "cstrOMean"; + nm += GetNConstraints(); + AliITSAlignMille2Constraint *cstr = new AliITSAlignMille2Constraint(nm.Data(),AliITSAlignMille2Constraint::kTypeMean, + -1,val,pattern); + cstr->SetConstraintID(GetNConstraints()); + fConstraints.Add(cstr); +} + +//________________________________________________________________________________________________________ +void AliITSAlignMille2::ConstrainOrphansMedian(Double_t val, UInt_t pattern) +{ + // require that median of the modifications for the supermodules which have no parents is = val, i.e. + // the corrections moves the whole setup by fixed value (0 by default) modulo the outliers. + // pattern is the bit pattern for the parameters to constrain // - for (int i=fNModules;i--;) { - AliITSAlignMille2Module* child = GetMilleModule(i); - if (child->GetParent() == parent) childs.AddAtAndExpand(child,nChilds++); + if (fIsMilleInit) { + AliInfo("Millepede has been already initialized: no constrain may be added!"); + return; } - if (nChilds<1) return; + TString nm = "cstrOMed"; + nm += GetNConstraints(); + AliITSAlignMille2Constraint *cstr = new AliITSAlignMille2Constraint(nm.Data(),AliITSAlignMille2Constraint::kTypeMedian, + -1,val,pattern); + cstr->SetConstraintID(GetNConstraints()); + fConstraints.Add(cstr); +} + +//________________________________________________________________________________________________________ +void AliITSAlignMille2::ConstrainLocal(const Char_t* name,Double_t *parcf,Int_t npar,Double_t val,Double_t err) +{ + if (fIsMilleInit) { + AliInfo("Millepede has been already initialized: no constrain may be added!"); + return; + } + AliITSAlignMille2ConstrArray *cstr = new AliITSAlignMille2ConstrArray(name,parcf,npar,val,err); + cstr->SetConstraintID(GetNConstraints()); + fConstraints.Add(cstr); +} + +//________________________________________________________________________________________________________ +void AliITSAlignMille2::ApplyGaussianConstraint(AliITSAlignMille2ConstrArray* cstr) +{ + // apply the constraint on the local corrections of a list of modules + int nmod = cstr->GetNModules(); + double jacobian[AliITSAlignMille2Module::kMaxParGeom][AliITSAlignMille2Module::kMaxParGeom]; // - int npc = 0; - double *deltas = fMillepede->GetDeltaPars(); - double *tmpArr = new double[nChilds]; + for (int imd=nmod;imd--;) { + int modID = cstr->GetModuleID(imd); + AliITSAlignMille2Module* mod = GetMilleModule(modID); + ResetLocalEquation(); + int nadded = 0; + double value = cstr->GetValue(); + double sigma = cstr->GetError(); + // + // in case the reference (survey) deltas were imposed for Gaussian constraints + // already accumulated corrections: they must be subtracted from the constraint value. + if (IsConstraintWrtRef()) { + // + Double_t precal[AliITSAlignMille2Module::kMaxParTot]; + Double_t refcal[AliITSAlignMille2Module::kMaxParTot]; + for (int ip=AliITSAlignMille2Module::kMaxParTot;ip--;) {precal[ip]=0; refcal[ip] = 0.;} + // + // check if there was a reference delta provided for this module + AliAlignObjParams* parref = GetConstrRefObject(mod->GetName()); + if (parref) parref->GetPars(refcal, refcal+3); // found reference delta + // + // extract already applied local corrections for this module + if (fPrealignment) { + // + AliAlignObjParams *preo = GetPrealignedObject(mod->GetName()); + if (preo) { + TGeoHMatrix preMat,tmpMat = *mod->GetMatrix(); // Delta_Glob * Delta_Glob_Par * M + preo->GetMatrix(preMat); // Delta_Glob + preMat.MultiplyLeft( &tmpMat.Inverse() ); // M^-1 * Delta_Glob_Par^-1 = (Delta_Glob_Par * M)^-1 + tmpMat.MultiplyLeft( &preMat ); // (Delta_Glob_Par * M)^-1 * Delta_Glob * Delta_Glob_Par * M = Delta_loc + AliAlignObjParams algob; + algob.SetMatrix(tmpMat); + algob.GetPars(precal,precal+3); // local corrections for geometry + } + } + // + // subtract the contribution to constraint from precalibration + for (int ipar=cstr->GetNCoeffs();ipar--;) value += (refcal[ipar]-precal[ipar])*cstr->GetCoeff(ipar); + // + } + // + if (fUseGlobalDelta) mod->CalcDerivLocGlo(&jacobian[0][0]); + // + for (int ipar=cstr->GetNCoeffs();ipar--;) { + double coef = cstr->GetCoeff(ipar); + if (coef==0) continue; + // + if (!fUseGlobalDelta || ipar>= AliITSAlignMille2Module::kMaxParGeom) { // + // we are working with local params or if the given param is not related to geometry, + // apply the constraint directly + int parPos = mod->GetParOffset(ipar); + if (parPos<0) continue; // not in the fit + fGlobalDerivatives[parPos] += coef; + nadded++; + } + else { // we are working with global params, while the constraint is on local ones -> jacobian + for (int jpar=AliITSAlignMille2Module::kMaxParGeom;jpar--;) { + int parPos = mod->GetParOffset(jpar); + if (parPos<0) continue; + fGlobalDerivatives[parPos] += coef*jacobian[ipar][jpar]; + nadded++; + } + } + } + if (nadded) AddConstraint(fGlobalDerivatives, value, sigma); + } // - for (int ip=0;ip>ip)&0x1) /*|| !parent->IsFreeDOF(ip)*/) continue; - // compute the median of the deltas - for (int ich=nChilds;ich--;) tmpArr[ich] = deltas[childs[ich]->GetUniqueID()*kNParCh+ip]; - for (int ic0=0;ic0tmpArr[ic1]) {double tv=tmpArr[ic0]; tmpArr[ic0]=tmpArr[ic1]; tmpArr[ic1]=tv;} +} + +//________________________________________________________________________________________________________ +void AliITSAlignMille2::ApplyPreConstraints() +{ + int nconstr = GetNConstraints(); + for (int i=0;iGetType() == AliITSAlignMille2ConstrArray::kTypeGaussian) { + ApplyGaussianConstraint( (AliITSAlignMille2ConstrArray*)cstr); + continue; + } // - for (int ich=nChilds;ich--;) deltas[childs[ich]->GetUniqueID()*kNParCh+ip] -= median - val; - deltas[parent->GetUniqueID()*kNParCh+ip] += median - val; - npc++; + if (cstr->GetType() == AliITSAlignMille2Constraint::kTypeMedian) continue; // post type constraint + // + if (!fUseGlobalDelta) continue; // mean/med constraints must be applied to global deltas + // apply constraint on the mean's before the fit + int imd = cstr->GetModuleID(); + if (imd>=0) { + AliITSAlignMille2Module* mod = GetMilleModule(imd); + UInt_t pattern = 0; + for (int ipar=mod->GetNParTot();ipar--;) { + if (!cstr->IncludesParam(ipar)) continue; + if (mod->GetParOffset(ipar)<0) continue; // parameter is not in the explicit fit -> post constraint + pattern |= 0x1<SetApplied(ipar); + } + ConstrainModuleSubUnits(imd,cstr->GetValue(),pattern); + // + } + else if (!PseudoParentsAllowed()) { + ConstrainOrphans(cstr->GetValue(),(UInt_t)cstr->GetPattern()); + cstr->SetApplied(-1); + } } - delete[] tmpArr; +} + +//________________________________________________________________________________________________________ +void AliITSAlignMille2::ApplyPostConstraints() +{ + int nconstr = GetNConstraints(); + Bool_t convGlo = kFALSE; + // check if there is something to do + int ntodo = 0; + for (int i=0;iGetType() == AliITSAlignMille2ConstrArray::kTypeGaussian) continue; + if (cstr->GetRemainingPattern() == 0) continue; + ntodo++; + } + if (!ntodo) return; // - AliInfo(Form("Applied median constraint to %d params for %d submodules of module #%d: %s",npc,nChilds,idm,parent->GetName())); + if (!fUseGlobalDelta) { // need to convert to global params + ConvertParamsToGlobal(); + convGlo = kTRUE; + } // + for (int i=0;iGetType() == AliITSAlignMille2ConstrArray::kTypeGaussian) continue; + // + int imd = cstr->GetModuleID(); + // + if (imd>=0) { + AliITSAlignMille2Module* mod = GetMilleModule(imd); + UInt_t pattern = 0; + for (int ipar=mod->GetNParTot();ipar--;) { + if (cstr->IsApplied(ipar)) continue; + if (!cstr->IncludesParam(ipar)) continue; + if (!mod->IsFreeDOF(ipar)) continue; // parameter is fixed, will not apply constraint + pattern |= 0x1<SetApplied(ipar); + } + if (pattern) PostConstrainModuleSubUnits(cstr->GetType(),cstr->GetModuleID(),cstr->GetValue(),pattern); + // + } + else if (PseudoParentsAllowed()) { + UInt_t pattern = (UInt_t)cstr->GetRemainingPattern(); + PostConstrainOrphans(cstr->GetType(),cstr->GetValue(),pattern); + cstr->SetApplied(-1); + } + } + // if there was a conversion, rewind it + if (convGlo) ConvertParamsToLocal(); + // } -//_________________________________________________________________________ -void AliITSAlignMille2::ConstrainOrphans(Double_t val, UInt_t pattern) +//________________________________________________________________________________________________________ +void AliITSAlignMille2::ConstrainModuleSubUnits(Int_t idm, Double_t val, UInt_t pattern) { - // require that median of the modifications for the supermodules which have no parents is = val, i.e. - // the corrections moves the whole setup by fixed value (0 by default) modulo the outliers. + // require that sum of modifications for the childs of this module is = val, i.e. + // the internal corrections moves the module as a whole by fixed value (0 by default). // pattern is the bit pattern for the parameters to constrain // - static TObjArray modSet; - modSet.Clear(); // - // build list of childs for this module - int nModules = 0; - int *nFree = new int[kNParCh]; - for (int i=0;iGetParent()) continue; // skip this - for (int ip=0;ip>ip)&0x1) && module->IsFreeDOF(ip)) nFree[ip]++; - modSet.AddAtAndExpand(module,nModules++); + for (int ip=0;ip>ip)&0x1) /*|| !parent->IsFreeDOF(ip)*/) continue; + ResetLocalEquation(); + int nadd = 0; + for (int ich=mod->GetNChildren();ich--;) { + int idpar = ((AliITSAlignMille2Module*)mod->GetChild(ich))->GetParOffset(ip); + if (idpar<0) continue; + fGlobalDerivatives[idpar] = 1.0; + nadd++; + } + // + if (nadd>0) { + AddConstraint(fGlobalDerivatives,val); + AliInfo(Form("Constrained param %d for %d submodules of module #%d: %s",ip,nadd,idm,mod->GetName())); + } } - if (nModules<1) return; // - int npc = 0; +} + +//________________________________________________________________________________________________________ +void AliITSAlignMille2::ConstrainOrphans(Double_t val, UInt_t pattern) +{ + // require that median of the modifications for the supermodules which have no parents is = val, i.e. + // the corrections moves the whole setup by fixed value (0 by default) modulo the outliers. + // pattern is the bit pattern for the parameters to constrain + // for (int ip=0;ip>ip)&0x1) ) continue; ResetLocalEquation(); - for (int ich=nModules;ich--;) { - AliITSAlignMille2Module* module = (AliITSAlignMille2Module*) modSet[ich]; - if ( !((pattern>>ip)&0x1) || !module->IsFreeDOF(ip)) continue; - fGlobalDerivatives[module->GetUniqueID()*kNParCh+ip] = 1.0; + int nadd = 0; + for (int imd=fNModules;imd--;) { + AliITSAlignMille2Module* mod = GetMilleModule(imd); + if (mod->GetParent()) continue; // this is not an orphan + int idpar = mod->GetParOffset(ip); + if (idpar<0) continue; + fGlobalDerivatives[idpar] = 1.0; + nadd++; + } + if (nadd>0) { + AddConstraint(fGlobalDerivatives,val); + AliInfo(Form("Constrained param %d for %d orphan modules",ip,nadd)); } - AddConstraint(fGlobalDerivatives,val); - npc++; } // - delete[] nFree; - AliInfo(Form("Constrained %d params for %d orphan modules",npc,nModules)); // } -//_________________________________________________________________________ -void AliITSAlignMille2::PostConstrainOrphansMedian(Double_t val, UInt_t pattern) + +//________________________________________________________________________________________________________ +void AliITSAlignMille2::PostConstrainModuleSubUnits(Int_t type,Int_t idm, Double_t val, UInt_t pattern) { - // require that sum of modifications for the supermodules which have no parents is = val, i.e. - // the corrections moves the whole setup by fixed value (0 by default). + // require that median or mean of the modifications for the childs of this module is = val, i.e. + // the internal corrections moves the module as a whole by fixed value (0 by default) + // module the outliers. // pattern is the bit pattern for the parameters to constrain + // The difference between the mean and the median will be transfered to the parent // - static TObjArray modSet; - modSet.Clear(); - // - // build list of childs for this module - int nModules = 0; - int *nFree = new int[kNParCh]; - for (int i=0;iGetParent()) continue; // skip this - for (int ip=0;ip>ip)&0x1) && module->IsFreeDOF(ip)) nFree[ip]++; - modSet.AddAtAndExpand(module,nModules++); - } - if (nModules<1) return; + AliITSAlignMille2Module* parent = GetMilleModule(idm); + int nc = parent->GetNChildren(); // - int npc = 0; - double *deltas = fMillepede->GetDeltaPars(); - double *tmpArr = new double[nModules]; + double *tmpArr = new double[nc]; // for (int ip=0;ipGetUniqueID()*kNParCh+ip]; - for (int ic0=0;ic0tmpArr[ic1]) {double tv=tmpArr[ic0]; tmpArr[ic0]=tmpArr[ic1]; tmpArr[ic1]=tv;}; + int npc = 0; + if ( !((pattern>>ip)&0x1) || !parent->IsFreeDOF(ip)) continue; + // compute the mean and median of the deltas + int nfree = 0; + for (int ich=nc;ich--;) { + AliITSAlignMille2Module* child = parent->GetChild(ich); + // if (!child->IsFreeDOF(ip)) continue; + tmpArr[nfree++] = child->GetParVal(ip); + } + double median=0,mean=0; + for (int ic0=0;ic0tmpArr[ic1]) {double tv=tmpArr[ic0]; tmpArr[ic0]=tmpArr[ic1]; tmpArr[ic1]=tv;} + } // - int kmed = nModules/2; - double median = (tmpArr[kmed]+tmpArr[nModules-kmed-1])/2.; - // - for (int ich=nModules;ich--;) { - AliITSAlignMille2Module* module = (AliITSAlignMille2Module*) modSet[ich]; - if ( !((pattern>>ip)&0x1) || !module->IsFreeDOF(ip)) continue; - deltas[module->GetUniqueID()*kNParCh+ip] -= median - val; + int kmed = nfree/2; + median = (tmpArr[kmed]+tmpArr[nfree-kmed-1])/2.; + if (nfree>0) mean /= nfree; + // + double shift = val - (type==AliITSAlignMille2Constraint::kTypeMean ? mean : median); + // + for (int ich=nc;ich--;) { + AliITSAlignMille2Module* child = parent->GetChild(ich); + // if (!child->IsFreeDOF(ip)) continue; + child->SetParVal(ip, child->GetParVal(ip) + shift); + npc++; } - npc++; + // + parent->SetParVal(ip, parent->GetParVal(ip) - shift); + AliInfo(Form("%s constraint: added %f shift to param[%d] of %d children of module %d: %s", + type==AliITSAlignMille2Constraint::kTypeMean ? "MEAN" : "MEDIAN",shift, + ip,npc,idm,parent->GetName())); } + delete[] tmpArr; // - delete[] nFree; - delete[] tmpArr; - AliInfo(Form("Applied median constraint to %d params for %d orphan modules",npc,nModules)); // } -//_________________________________________________________________________ -void AliITSAlignMille2::ConstrainLinComb(const Int_t *vidLst, const Float_t *wghLst, Int_t nmd, Double_t val, UInt_t pattern) +//________________________________________________________________________________________________________ +void AliITSAlignMille2::PostConstrainOrphans(Int_t type,Double_t val, UInt_t pattern) { - // require that the linear combinations of the nmd modules (refered by their volume ID) from the - // modList with the coefficients wghLst adds up to val. - // pattern is the bit pattern for the parameters to constrain. + // require that median or mean of modifications for the supermodules which have no parents is = val, i.e. + // the corrections moves the whole setup by fixed value (0 by default). + // pattern is the bit pattern for the parameters to constrain // - static TObjArray modSet; - modSet.Clear(); + int nc = fNModules; // - // build list of childs for this module - int nModules = 0; - int *nFree = new int[kNParCh]; - for (int i=0;iGetParent()) norph ++; + if (!norph) return; + double *tmpArr = new double[norph]; // - for (int imd=nmd;imd--;) { - UShort_t vid = (UShort_t)vidLst[imd]; - for (int i=fNModules;i--;) { - AliITSAlignMille2Module* module = GetMilleModule(i); - if (module->GetVolumeID() == vid) { - modSet.AddAtAndExpand(module,nModules++); - for (int ip=0;ip>ip)&0x1) && module->IsFreeDOF(ip)) nFree[ip]++; - break; - } + for (int ip=0;ip>ip)&0x1)) continue; + // compute the mean and median of the deltas + int nfree = 0; + for (int ich=nc;ich--;) { + AliITSAlignMille2Module* child = GetMilleModule(ich); + // if (child->GetParent() || !child->IsFreeDOF(ip)) continue; + if (child->GetParent()) continue; + tmpArr[nfree++] = child->GetParVal(ip); + } + double median=0,mean=0; + for (int ic0=0;ic0tmpArr[ic1]) {double tv=tmpArr[ic0]; tmpArr[ic0]=tmpArr[ic1]; tmpArr[ic1]=tv;} + } + // + int kmed = nfree/2; + median = (tmpArr[kmed]+tmpArr[nfree-kmed-1])/2.; + if (nfree>0) mean /= nfree; + // + double shift = val - (type==AliITSAlignMille2Constraint::kTypeMean ? mean : median); + // + for (int ich=nc;ich--;) { + AliITSAlignMille2Module* child = GetMilleModule(ich); + // if (child->GetParent() || !child->IsFreeDOF(ip)) continue; + if (child->GetParent()) continue; + child->SetParVal(ip, child->GetParVal(ip) + shift); + npc++; } + // + AliInfo(Form("%s constraint: added %f shift to param[%d] of %d orphan modules", + type==AliITSAlignMille2Constraint::kTypeMean ? "MEAN" : "MEDIAN",shift, + ip,npc)); } + delete[] tmpArr; // - if (nModules != nmd) { - AliInfo(Form("Error: constraint for %d modules requested but %d are found",nmd,nModules)); - delete[] nFree; - return; +} + +//________________________________________________________________________________________________________ +Bool_t AliITSAlignMille2::IsParModConstrained(AliITSAlignMille2Module* mod,Int_t par, Bool_t &meanmed, Bool_t &gaussian) const +{ + // check if par of the module participates in some constraint, and set the flag for their types + meanmed = gaussian = kFALSE; + // + if ( mod->IsParConstrained(par) ) gaussian = kTRUE; // direct constraint on this param + // + for (int icstr=GetNConstraints();icstr--;) { + AliITSAlignMille2Constraint* cstr = GetConstraint(icstr); + // + if (!cstr->IncludesModPar(mod,par)) continue; + if (cstr->GetType()==AliITSAlignMille2ConstrArray::kTypeGaussian) gaussian = kTRUE; + else meanmed = kTRUE; + // + if (meanmed && gaussian) break; // no sense to check further } - int npc = 0; - for (int ip=0;ip>ip)&0x1) || !module->IsFreeDOF(ip)) continue; - fGlobalDerivatives[module->GetUniqueID()*kNParCh+ip] = wghLst[ich]; - } - AddConstraint(fGlobalDerivatives,val); - npc++; + // + return meanmed||gaussian; +} + +//________________________________________________________________________________________________________ +Bool_t AliITSAlignMille2::IsParModFamilyVaried(AliITSAlignMille2Module* mod,Int_t par,Int_t depth) const +{ + // check if parameter par is varied for this module or its children up to the level depth + if (depth<0) return kFALSE; + if (mod->GetParOffset(par)>=0) return kTRUE; + for (int icld=mod->GetNChildren();icld--;) { + AliITSAlignMille2Module* child = mod->GetChild(icld); + if (IsParModFamilyVaried(child, par, depth-1)) return kTRUE; } + return kFALSE; // - delete[] nFree; - AliInfo(Form("Constrained %d params for linerar combination of %d modules",npc,nModules)); +} + +/* +//________________________________________________________________________________________________________ +Bool_t AliITSAlignMille2::IsParFamilyFree(AliITSAlignMille2Module* mod,Int_t par,Int_t depth) const +{ + // check if parameter par is varied and is not subjected to gaussian constraint for the children up to the level depth + if (depth<0) return kTRUE; + for (int icld=mod->GetNChildren();icld--;) { + AliITSAlignMille2Module* child = mod->GetChild(icld); + //if (child->GetParOffset(par)<0) continue; // fixed + Bool_t cstMM=kFALSE,cstGS=kFALSE; + // does this child have gaussian constraint ? + if (!IsParModConstrained(child,par,cstMM,cstGS) || !cstGS ) return kTRUE; + // check its children + if (!IsParFamilyFree(child,par,depth-1)) return kTRUE; + } + return kFALSE; + // +} +*/ + +//________________________________________________________________________________________________________ +Bool_t AliITSAlignMille2::IsParFamilyFree(AliITSAlignMille2Module* mod,Int_t par,Int_t depth) const +{ + // check if parameter par is varied and is not subjected to gaussian constraint for the children up to the level depth + if (depth<0) return kFALSE; + for (int icld=mod->GetNChildren();icld--;) { + AliITSAlignMille2Module* child = mod->GetChild(icld); + //if (child->GetParOffset(par)<0) continue; // fixed + Bool_t cstMM=kFALSE,cstGS=kFALSE; + // does this child have gaussian constraint ? + if (!IsParModConstrained(child,par,cstMM,cstGS) || !cstGS ) return kTRUE; + // check its children + if (IsParFamilyFree(child,par,depth-1)) return kTRUE; + } + return kFALSE; // } + +//________________________________________________________________________________________________________ +Double_t AliITSAlignMille2::GetTDriftSDD() const +{ + double t = fCluster.GetDriftTime(); + return t - fDriftTime0[ fCluster.GetUniqueID() ]; +} + +//________________________________________________________________________________________________________ +Double_t AliITSAlignMille2::GetVDriftSDD() const +{ + return fDriftSpeed[ fCluster.GetUniqueID() ]; +} + +//________________________________________________________________________________________________________ +Bool_t AliITSAlignMille2::FixedOrphans() const +{ + // are there fixed modules with no parent (normally in such a case + // the constraints on the orphans should not be applied + if (!IsConfigured()) { + AliInfo("Still not configured"); + return kFALSE; + } + for (int i=0;iGetParent()==0 && md->GetNParFree()==0) return kTRUE; + } + return kFALSE; +} + +//________________________________________________________________________________________________________ +void AliITSAlignMille2::ConvertParamsToGlobal() +{ + double pars[AliITSAlignMille2Module::kMaxParGeom]; + for (int imd=fNModules;imd--;) { + AliITSAlignMille2Module* mod = GetMilleModule(imd); + if (mod->GeomParamsGlobal()) continue; + mod->GetGeomParamsGlo(pars); + mod->SetParVals(pars,AliITSAlignMille2Module::kMaxParGeom); + mod->SetGeomParamsGlobal(kTRUE); + } +} + +//________________________________________________________________________________________________________ +void AliITSAlignMille2::ConvertParamsToLocal() +{ + double pars[AliITSAlignMille2Module::kMaxParGeom]; + for (int imd=fNModules;imd--;) { + AliITSAlignMille2Module* mod = GetMilleModule(imd); + if (!mod->GeomParamsGlobal()) continue; + mod->GetGeomParamsLoc(pars); + mod->SetParVals(pars,AliITSAlignMille2Module::kMaxParGeom); + mod->SetGeomParamsGlobal(kFALSE); + } +} + + diff --git a/ITS/AliITSAlignMille2.h b/ITS/AliITSAlignMille2.h index 91f17c48aa7..8c8f8337d9d 100644 --- a/ITS/AliITSAlignMille2.h +++ b/ITS/AliITSAlignMille2.h @@ -1,99 +1,126 @@ #ifndef ALIITSALIGNMILLE2_H #define ALIITSALIGNMILLE2_H + /* Copyright(c) 2007-2009 , ALICE Experiment at CERN, All rights reserved. * * See cxx source for full Copyright notice */ /* $Id$ */ - -/// \ingroup rec -/// \class AliITSAlignMille2 -/// \brief Class for alignment of ITS +//----------------------------------------------------------------------------- // -// Authors: Marcello Lunardon +// Interface to AliMillePede2 alignment class for the ALICE ITS detector +// +// ITS specific alignment class which interface to AliMillepede. +// For each track ProcessTrack calculates the local and global derivatives +// at each hit and fill the corresponding local equations. Provide methods for +// fixing or constraining detection elements for best results. +// +// author M. Lunardon (thanks to J. Castillo), ruben.shahoyan@cern.ch +//----------------------------------------------------------------------------- +#include +#include #include #include +#include +#include "AliITSresponseSDD.h" #include "AliTrackPointArray.h" #include "AliITSAlignMille2Module.h" +#include "AliITSAlignMille2Constraint.h" +#include "AliITSAlignMille2ConstrArray.h" class AliMillePede2; class AliAlignObjParams; class TGeoManager; -class TGeoHMatrix; //class AliITSAlignMille2Module; class AliTrackFitterRieman; class TVirtualFitter; // number of used objects -#define ITSMILLE2_NPARCH 6 -#define ITSMILLE2_NLOCAL 5 -struct Mille2Data { - /// structure to store data for 2 LocalEquations (X and Z) - // - Int_t moduleIDX[10]; // max 10 hierarchy levels!!! - Int_t levFilled; - // - Double_t measX; - Double_t measZ; - Double_t sigmaX; - Double_t sigmaZ; - // - Double_t derlocX[ITSMILLE2_NLOCAL]; - Double_t derlocZ[ITSMILLE2_NLOCAL]; - // - Double_t dergloX[ITSMILLE2_NPARCH*10]; - Double_t dergloZ[ITSMILLE2_NPARCH*10]; -}; class AliITSAlignMille2: public TObject { public: - enum {kNLocal=ITSMILLE2_NLOCAL,kNParCh=ITSMILLE2_NPARCH, - kMaxITSSensID=2197,kMaxITSSensVID=14300,kMinITSSupeModuleID=14336}; - enum {kDOFTX,kDOFTY,kDOFTZ,kDOFPH,kDOFTH,kDOFPS}; + enum {kNLocal=5,kMaxPoints=100, + kNParChGeom = AliITSAlignMille2Module::kMaxParGeom, + kNParCh = AliITSAlignMille2Module::kMaxParTot, + kMaxITSSensID=2197,kMaxITSSensVID=14300,kMinITSSupeModuleID=14336,kSDDoffsID=240}; // + protected: + struct Mille2Data { // structure to store data for 2 LocalEquations (X and Z) + enum {kMaxLev = 7}; + Double_t measX, measZ, sigmaX, sigmaZ; + Double_t derlocX[kNLocal], derlocZ[kNLocal]; + Int_t nModFilled, nGlobFilled, moduleID[kMaxLev]; + Int_t parMilleID[AliITSAlignMille2Module::kMaxParTot*kMaxLev]; + Double_t dergloX[AliITSAlignMille2Module::kMaxParTot*kMaxLev]; + Double_t dergloZ[AliITSAlignMille2Module::kMaxParTot*kMaxLev]; + }; + // public: // - AliITSAlignMille2(const Char_t *configFilename="AliITSAlignMille.conf", Bool_t initmille=kTRUE); + AliITSAlignMille2(const Char_t *configFilename="AliITSAlignMille.conf"); virtual ~AliITSAlignMille2(); // - AliMillePede2* GetMillePede() const {return fMillepede;} - - // geometry methods + AliMillePede2* GetMillePede() const {return fMillepede;} + // + // configuration methods + // + Int_t IsVIDDefined(UShort_t voluid) const; + Int_t IsVIDContained(UShort_t voluid) const; + Int_t IsSymDefined(const Char_t* name) const; + Int_t IsSymContained(const Char_t* name) const; + // Int_t GetModuleIndex(const Char_t *symname); Int_t GetModuleIndex(UShort_t voluid); UShort_t GetModuleVolumeID(const Char_t *symname); UShort_t GetModuleVolumeID(Int_t index); - void SetParSigTranslations(double v) {fParSigTranslations = v;} - void SetParSigRotations(double v) {fParSigRotations = v;} + AliITSAlignMille2Module* GetMilleModuleByVID(UShort_t voluid) const; // get pointer to the defined supermodule + AliITSAlignMille2Module* GetMilleModuleBySymName(const Char_t* symname) const; // get pointer to the defined supermodule + AliITSAlignMille2Module* GetMilleModuleIfContained(const Char_t* symname) const; + AliITSAlignMille2Module* GetMilleModule(Int_t id) const {return (AliITSAlignMille2Module*)fMilleModule[id];} + AliITSAlignMille2Module* GetCurrentModule() const {return fCurrentModule;} + AliITSAlignMille2Module* GetSuperModule(Int_t id) const {return (AliITSAlignMille2Module*)fSuperModule[id];} + // + AliAlignObjParams* GetPrealignedObject(const Char_t* symname) const; + AliAlignObjParams* GetConstrRefObject(const Char_t* symname) const; + // + void ConvertParamsToGlobal(); + void ConvertParamsToLocal(); // - // configuration methods - void SetGeometryFileName(const Char_t* filename="geometry.root") { fGeometryFileName = filename; } const Char_t* GetGeometryFileName() {return fGeometryFileName.Data();} const Char_t* GetPreAlignmentFileName() {return fPreAlignmentFileName.Data();} TClonesArray* GetPreAlignmentDeltas() const {return fPrealignment;} - void SetCurrentModule(Int_t id) {fCurrentModule = GetMilleModule(id);} + AliITSresponseSDD* GetSDDPrecalibration() const {return fCorrectSDD;} + AliITSresponseSDD* GetSDDInit() const {return fInitialRecSDD;} void PrintCurrentModuleInfo() const {if (fCurrentModule) fCurrentModule->Print();} void Print(Option_t*) const; Bool_t IsConfigured() const {return fIsConfigured;} - void SetRequiredPoint(Char_t* where, Int_t ndet, Int_t updw, Int_t nreqpts); - void SetUseGlobalDelta(Bool_t v=kTRUE) {fUseGlobalDelta = v;} Bool_t GetUseGlobalDelta() const {return fUseGlobalDelta;} + Bool_t IsConstraintWrtRef() const {return fConstrRef!=0;} + Bool_t FixedOrphans() const; + // + // geometry stuffs + Int_t GetNModules() const {return fNModules;} + Int_t GetCurrentModuleIndex() const {return fCurrentModule ? fCurrentModule->GetIndex():-1;} + TGeoHMatrix *GetCurrentModuleHMatrix() const {return fCurrentModule ? fCurrentModule->GetMatrix():0;} + Double_t *GetCurrentModuleTranslation() const {return fCurrentModule ? fCurrentModule->GetMatrix()->GetTranslation():0;} + Int_t GetCurrentModuleInternalIndex() const {return fCurrentModule ? Int_t(fCurrentModule->GetUniqueID()):-1;} + Int_t GetTotBadLocEqPoints() const {return fTotBadLocEqPoints;} + Int_t GetNConstraints() const {return fConstraints.GetLast()+1;} + Int_t InitModuleParams(); // // fitting methods AliTrackFitterRieman *GetRiemanFitter() const {return fRieman;} AliTrackPointArray *PrepareTrack(const AliTrackPointArray *track); - Int_t ProcessTrack(const AliTrackPointArray *track); + AliTrackPointArray *GetCurrentTrack() {return fTrack;} + AliTrackPoint *GetCurrentCluster() {return &fCluster;} + void SetCurrentTrack(AliTrackPointArray *atp) {fTrack=atp;} + void SetCurrentCluster(AliTrackPoint &atp) {fCluster=atp;} void InitTrackParams(int meth=1); - void SetMinNPtsPerTrack(Int_t pts=3) {fMinNPtsPerTrack=pts;} - void SetInitTrackParamsMeth(Int_t meth=1) {fInitTrackParamsMeth=meth;} - Bool_t InitRiemanFit(); - Int_t InitModuleParams(); + Int_t ProcessTrack(const AliTrackPointArray *track); Int_t CheckCurrentTrack(); - Bool_t CheckVolumeID(UShort_t voluid) const; - Int_t IsDefined(UShort_t voluid) const; - Int_t IsContained(UShort_t voluid) const; + // Int_t CalcIntersectionPoint(Double_t *lpar, Double_t *gpar); Int_t CalcDerivatives(Int_t paridx, Bool_t islpar); Double_t* GetLocalIntersectionPoint() const {return (Double_t*)fPintLoc;} @@ -101,76 +128,101 @@ class AliITSAlignMille2: public TObject AliTrackPointArray *SortTrack(const AliTrackPointArray *atp); void SetTemporaryExcludedModule(Int_t index) {fTempExcludedModule=index;} Int_t GetTemporaryExcludedModule() const {return fTempExcludedModule;} + Double_t GetMeasGlo(Int_t dim) const {return fMeasGlo[dim];} + Double_t GetMeasLoc(Int_t dim) const {return fMeasLoc[dim];} + Int_t GetCurrentLayer() const; // // Hierarchical contraints - void ConstrainModuleSubUnits(Int_t idm, Double_t val=0, UInt_t pattern=0xfffffff); - void ConstrainOrphans(Double_t val=0,UInt_t pattern=0xfffffff); - void ConstrainLinComb(const Int_t *modLst,const Float_t *wghLst, Int_t nmd, Double_t val=0, UInt_t pattern=0xfffffff); + Bool_t PseudoParentsAllowed() const {return fAllowPseudoParents;} + void ConstrainModuleSubUnitsMean(Int_t idm, Double_t val=0, UInt_t pattern=0xff); + void ConstrainModuleSubUnitsMedian(Int_t idm, Double_t val=0, UInt_t pattern=0xff); + void ConstrainOrphansMean(Double_t val=0, UInt_t pattern=0xff); + void ConstrainOrphansMedian(Double_t val=0, UInt_t pattern=0xff); + void ConstrainLocal(const Char_t* name,Double_t *parcf,Int_t npar,Double_t val,Double_t err); // - void PostConstrainModuleSubUnitsMedian(Int_t idm, Double_t val=0, UInt_t pattern=0xfffffff); - void PostConstrainOrphansMedian(Double_t val=0, UInt_t pattern=0xfffffff); + void ApplyGaussianConstraint(AliITSAlignMille2ConstrArray* cstr); + void ApplyPreConstraints(); + void ApplyPostConstraints(); // - // Double_t* GetModuleConstrDerivs(Int_t matRow,Int_t matCol, TGeoHMatrix &matLoc); + Bool_t IsParModConstrained(AliITSAlignMille2Module* mod,Int_t par, Bool_t &meanmed, Bool_t &gaussian) const; + Bool_t IsParModFamilyVaried(AliITSAlignMille2Module* mod,Int_t par,Int_t depth=999) const; + Bool_t IsParFamilyFree(AliITSAlignMille2Module* mod,Int_t par,Int_t depth=999) const; // // millepede methods + Int_t GlobalFit(); void FixParameter(Int_t param, Double_t value); - void AddConstraint(Double_t *factor, Double_t value ); - void InitGlobalParameters(Double_t *par); - void SetLocalDerivative(Int_t index, Double_t value) {fLocalDerivatives[index] = value;} - void SetGlobalDerivative(Int_t index, Double_t value) {fGlobalDerivatives[index] = value;} - // - Int_t GlobalFit(Double_t *parameters=0,Double_t *errors=0,Double_t *pulls=0); void PrintGlobalParameters(); - Double_t GetParError(Int_t iPar); Int_t AddLocalEquation(Mille2Data &m); void SetLocalEquations(const Mille2Data *marr, Int_t neq); // - // fitting stuffs - AliTrackPointArray *GetCurrentTrack() {return fTrack;} - AliTrackPoint *GetCurrentCluster() {return &fCluster;} - void SetCurrentTrack(AliTrackPointArray *atp) {fTrack=atp;} - void SetCurrentCluster(AliTrackPoint &atp) {fCluster=atp;} - - // geometry stuffs - Int_t GetNModules() const {return fNModules;} - Int_t GetCurrentModuleIndex() const {return fCurrentModule ? fCurrentModule->GetIndex():-1;} - TGeoHMatrix *GetCurrentModuleHMatrix() const {return fCurrentModule ? fCurrentModule->GetMatrix():0;} - Double_t *GetCurrentModuleTranslation() const {return fCurrentModule ? fCurrentModule->GetMatrix()->GetTranslation():0;} - Int_t GetCurrentModuleInternalIndex() const {return fCurrentModule ? static_cast(fCurrentModule->GetUniqueID()):-1;} - Int_t GetTotBadLocEqPoints() const {return fTotBadLocEqPoints;} + // module specific // - AliITSAlignMille2Module* GetMilleModuleByVID(UShort_t voluid) const; // get pointer to the defined supermodule - AliITSAlignMille2Module* GetMilleModule(Int_t id) const {return (AliITSAlignMille2Module*)fMilleModule[id];} - AliITSAlignMille2Module* GetCurrentModule() const {return fCurrentModule;} - AliITSAlignMille2Module* GetSuperModule(Int_t id) const {return (AliITSAlignMille2Module*)fSuperModule[id];} + Double_t GetTDriftSDD() const; + Double_t GetVDriftSDD() const; + // + AliITSAlignMille2Constraint* GetConstraint(Int_t i) const {return (AliITSAlignMille2Constraint*)fConstraints.At(i);} + AliITSAlignMille2Constraint* GetConstraint(const char* name) const {return (AliITSAlignMille2Constraint*)fConstraints.FindObject(name);} // // debug stuffs + void FetchCluster(const AliTrackPointArray *trc,int ip) {trc->GetPoint(fCluster,ip);} + void SetLocalInitParams(Double_t *par) {for (int i=kNLocal;i--;) fLocalInitParam[i]=par[i];} Double_t *GetMeasLoc() const {return (Double_t*)fMeasLoc;} Double_t *GetSigmaLoc() const {return (Double_t*)fSigmaLoc;} Double_t GetBField() const {return fBField;} Double_t *GetLocalInitParam() const {return (Double_t*)fLocalInitParam;} Double_t *GetLocalInitParEr() const {return (Double_t*)fLocalInitParEr;} - Double_t GetLocalDX() const {return fDerivativeLoc[0];} - Double_t GetLocalDY() const {return fDerivativeLoc[1];} - Double_t GetLocalDZ() const {return fDerivativeLoc[2];} - Double_t GetLocalDif(int i) const {return fDerivativeLoc[i];} - Double_t GetParSigTranslations() const {return fParSigTranslations;} - Double_t GetParSigRotations() const {return fParSigRotations;} + Double_t GetLocalDif(int par, int coor) const {return fDerivativeLoc[par][coor];} + Double_t GetGlobalDif(int par, int coor) const {return fDerivativeGlo[par][coor];} Int_t GetPreAlignmentQualityFactor(Int_t index) const;// if not prealign. return -1 void SetBug(Int_t bug) {fBug=bug;} // 1:SSD inversion sens.18-19 - static AliITSAlignMille2* GetInstance() {return fgInstance;} + static AliITSAlignMille2* GetInstance() {return fgInstance;} + + // pepo + // flag for AliITSAlignMille compatibility + Int_t GetMilleVersion() const {return fMilleVersion;} + void SetMilleVersion(Int_t m1) {fMilleVersion=m1;} + // modified existing methods + void SetCurrentModule(Int_t id); + // old methods recovered + Int_t IsDefined(UShort_t voluid) const {return IsVIDDefined(voluid);} + Int_t IsContained(UShort_t voluid) const {return IsVIDContained(voluid);} + // moved from private to public + void SetRequiredPoint(Char_t* where, Int_t ndet, Int_t updw, Int_t nreqpts); + Bool_t InitRiemanFit(); + void SetMinNPtsPerTrack(Int_t pts=3) {fMinNPtsPerTrack=pts;} // private: // // configuration methods + void Init(); Int_t LoadConfig(const Char_t *cfile="AliITSAlignMille.conf"); + TObjArray* GetConfigRecord(FILE* stream, TString& recTitle, TString& recOpt, Bool_t rew); + // + void BuildHierarchy(); Int_t LoadSuperModuleFile(const Char_t *cfile="ITSMilleSuperModules.root"); void ResetLocalEquation(); - void InitGeometry(); + Int_t InitGeometry(); Int_t ApplyToGeometry(); // + void ConstrainModuleSubUnits(Int_t idm, Double_t val=0, UInt_t pattern=0xff); + void ConstrainOrphans(Double_t val=0,UInt_t pattern=0xff); + void PostConstrainModuleSubUnits(Int_t type,Int_t idm, Double_t val, UInt_t pattern); + void PostConstrainOrphans(Int_t type,Double_t val, UInt_t pattern); + // + void SetGeometryFileName(const Char_t* filename="geometry.root") { fGeometryFileName = filename; } + + void SetInitTrackParamsMeth(Int_t meth=1) {fInitTrackParamsMeth=meth;} + // + void AddConstraint(Double_t *factor, Double_t value, Double_t sigma=0); + void InitGlobalParameters(Double_t *par); + void SetLocalDerivative(Int_t index, Double_t value) {fLocalDerivatives[index] = value;} + void SetGlobalDerivative(Int_t index, Double_t value) {fGlobalDerivatives[index] = value;} + // // millepede methods - void Init(Int_t nGlobal, Int_t nLocal, Int_t nStdDev); + // + void SetUseGlobalDelta(Bool_t v=kTRUE) {fUseGlobalDelta = v;} + void SetAllowPseudoParents(Bool_t v=kTRUE) {fAllowPseudoParents = v;} + Int_t SetConstraintWrtRef(const char* reffname); // AliITSAlignMille2(const AliITSAlignMille2& rhs); AliITSAlignMille2& operator=(const AliITSAlignMille2& rhs); @@ -186,13 +238,12 @@ class AliITSAlignMille2: public TObject Int_t fNLocal; // Number of local parameters Int_t fNStdDev; // Number of standard deviations for chi2 cut Bool_t fIsMilleInit; // Flag for initialization - Bool_t fSensorsIn; // Are sensors explicitly provieded by the conf file? - Double_t fParSigTranslations; // init sigma for transl. params [cm] - Double_t fParSigRotations; // init sigma for rot. params [deg] + Bool_t fAllowPseudoParents; // For simple constraints don't involve parents into the fit // // fitting stuffs AliITSAlignMille2Module *fCurrentModule; // Current SuperModule index AliTrackPointArray *fTrack; // pointer to current track + TObjArray fTrackBuff; // buffer for tracks of min length AliTrackPoint fCluster; // current cluster Double_t *fGlobalDerivatives; // Array of global derivatives Double_t fLocalDerivatives[kNLocal]; // Array of local deriv. @@ -207,12 +258,14 @@ class AliITSAlignMille2: public TObject Double_t fSigmaLoc[3]; // stdev current point Double_t fSigmaFactor[3]; // multiplicative factor for cluster sigmaX,Y,Z // - Double_t fDerivativeLoc[3]; // localXYZ deriv. + Double_t fDerivativeLoc[kNLocal][3]; // XYZ deriv. over local params + Double_t fDerivativeGlo[kNParCh][3]; // XYZ deriv. over global params Int_t fMinNPtsPerTrack; // min number of points per track to accept it Int_t fInitTrackParamsMeth; // method for track fit Int_t fTotBadLocEqPoints; // total number of reject points because of bad EqLoc AliTrackFitterRieman *fRieman; // riemann fitter for helices // + TObjArray fConstraints; // list of constraints // >> new members Bool_t fUseGlobalDelta; // intetpret deltas as global Bool_t fRequirePoints; // required points in specific layers @@ -228,25 +281,34 @@ class AliITSAlignMille2: public TObject // geometry stuffs TString fGeometryFileName; // Geometry file name TString fPreAlignmentFileName; // file with prealigned objects + TString fConstrRefFileName; // file with prealigned objects wrt which constraints are defined TGeoManager *fGeoManager; Bool_t fIsConfigured; TArrayS fPreAlignQF; // + AliITSresponseSDD* fCorrectSDD; // array of SDD t0/vdrift calib params + AliITSresponseSDD* fInitialRecSDD; // array of SDD t0/vdrift calib params used to create the track points TClonesArray* fPrealignment; // array of prealignment global deltas + TClonesArray* fConstrRef; // array of refererence deltas with respect to which the constraint are defined (survey?) TObjArray fMilleModule; /// array of super modules to be aligned TObjArray fSuperModule; /// array of super modules defined in supermodule file Int_t fNModules; // number of defined modules from config file Int_t fNSuperModules; /// number of custom supermodules in SM file Bool_t fUsePreAlignment; // start from prealigned setup - Bool_t fUseSortedTracks; // default is kTRUE Bool_t fBOn; // magentic field ON Double_t fBField; // value of magnetic field Int_t fBug; /// tag for temporary bug correction + // pepo + Int_t fMilleVersion; /// tag for backward compatibility + // endpepo + // + Double_t fDriftSpeed[50]; //temporary array for drift times of SDD alitrackpoints + Double_t fDriftTime0[50]; //temporary array for drift time 0's used for SDD alitrackpoints // static AliITSAlignMille2* fgInstance; // global pointer on itself static Int_t fgInstanceID; // global counter of the instances + // ClassDef(AliITSAlignMille2, 0) - }; #endif diff --git a/ITS/AliITSAlignMille2ConstrArray.cxx b/ITS/AliITSAlignMille2ConstrArray.cxx new file mode 100644 index 00000000000..b4ca683da1c --- /dev/null +++ b/ITS/AliITSAlignMille2ConstrArray.cxx @@ -0,0 +1,101 @@ +#include "AliITSAlignMille2ConstrArray.h" +#include "AliITSAlignMille2Module.h" + +//======================================================================================================== +ClassImp(AliITSAlignMille2ConstrArray) + +//________________________________________________________________________________________________________ +AliITSAlignMille2ConstrArray::AliITSAlignMille2ConstrArray() : +AliITSAlignMille2Constraint(), +fModuleIDs(0), +fModulePatt(0), +fCoeffs(0), +fError(0) +{} + +//________________________________________________________________________________________________________ +AliITSAlignMille2ConstrArray::AliITSAlignMille2ConstrArray(const Char_t* name,Double_t *parcf,Int_t npar,Double_t val,Double_t err) : + AliITSAlignMille2Constraint(name,kTypeGaussian,-100,val,0), + fModuleIDs(0), + fModulePatt(0), + fCoeffs(npar), + fError(err) +{ + for (int i=0;iGetUniqueID() == (UInt_t)fModuleIDs[im]) return; } + fModuleIDs.Set(nmd+1); + fModulePatt.Set(nmd+1); + fModuleIDs[nmd] = mod->GetUniqueID(); + double jacobian[AliITSAlignMille2Module::kMaxParGeom][AliITSAlignMille2Module::kMaxParGeom]; + if (mod->GeomParamsGlobal()) mod->CalcDerivLocGlo(&jacobian[0][0]); + // + Short_t patt = GetPattern(); + if (mod->GeomParamsGlobal()) { + // the constraint is defined in the module's local frame. If the alignment of geom params is + // done in the global frame, we need to set the real parameter involved + patt &= 0xffff<< AliITSAlignMille2Module::kMaxParGeom; // reset the geometry parameters + for (int i=0;iGetUniqueID(), par); +} + + +//________________________________________________________________________________________________________ +void AliITSAlignMille2ConstrArray::Print(Option_t* ) const +{ + printf("#%3d Constraint %s of type %d | Value=%+e Error=%+e\n",GetConstraintID(),GetName(),GetType(),GetValue(),GetError()); + printf("Weights on params: "); for (int i=0;i=0) or all modules w/o +parents (ID=-1): the mean or median of the GLOBAL corrections of each parameter requested +in the pattern must be = 0. When added explicitly to the fit it requires addition of +Lagrange multipliers which may require more powerfull matrix preconditioners. For this +reason we usually ommit the constrain from explicit fit and apply it afterwards to obtained +parameters (with median constraint this is the only method possible) + +Author: ruben.shahoyan@cern.ch +------------------------------------------------------------------------------------------*/ +#include "AliITSAlignMille2Constraint.h" +#include "AliITSAlignMille2Module.h" + + + +ClassImp(AliITSAlignMille2Constraint) + +//________________________________________________________________________________________________________ +AliITSAlignMille2Constraint::AliITSAlignMille2Constraint() : +TNamed(), +fType(kTypeMean), +fVal(0), +fModuleID(0), +fApplied(0) +{} + +//________________________________________________________________________________________________________ +AliITSAlignMille2Constraint::AliITSAlignMille2Constraint(const Char_t* name,Int_t t,Int_t mdID,Double_t val,UInt_t pattern) : +TNamed(name,""), +fType(t), +fVal(val), +fModuleID(mdID), +fApplied(0) +{ + SetPattern(pattern); +} + +//________________________________________________________________________________________________________ +AliITSAlignMille2Constraint::AliITSAlignMille2Constraint(const AliITSAlignMille2Constraint& src) : +TNamed(src), +fType(src.fType), +fVal(src.fVal), +fModuleID(src.fModuleID), +fApplied(src.fApplied) +{/* DUMMY */} + +//________________________________________________________________________________________________________ +Bool_t AliITSAlignMille2Constraint::IncludesModPar(AliITSAlignMille2Module* mod, Int_t par) const +{ + // is this module/parameter mentioned in the list? + if (!IncludesParam(par)) return kFALSE; + if (fModuleID==-1 && !mod->GetParent()) return kTRUE; + return IncludesModule( mod->GetUniqueID() ); +} + + +//________________________________________________________________________________________________________ +void AliITSAlignMille2Constraint::Print(Option_t* ) const +{ + printf("#%3d Constraint %s of type %d on module %d to value %+e\n",GetConstraintID(),GetName(),GetType(),GetModuleID(),GetValue()); + printf("Paremeters: "); + for (int i=0;i<=8;i++) if (TestBit(0x1< +#include +#include + +class AliITSAlignMille2Module; + +/*----------------------------------------------------------------------------------------- +Simple constraint on the subunits of the module ID (if ID>=0) or all modules w/o +parents (ID=-1): the mean or median of the GLOBAL corrections of each parameter requested +in the pattern must be = 0. When added explicitly to the fit it requires addition of +Lagrange multipliers which may require more powerfull matrix preconditioners. For this +reason we usually ommit the constrain from explicit fit and apply it afterwards to obtained +parameters (with median constraint this is the only method possible) + +Author: ruben.shahoyan@cern.ch +------------------------------------------------------------------------------------------*/ +class AliITSAlignMille2Constraint : public TNamed +{ + public: + enum {kTypeMean,kTypeMedian}; + enum {kDisabledBit=31}; + // + AliITSAlignMille2Constraint(); + AliITSAlignMille2Constraint(const Char_t* name,Int_t t,Int_t mdID,Double_t val=0,UInt_t pattern=0x0ffff); + virtual ~AliITSAlignMille2Constraint() {} + // + UInt_t GetConstraintID() const {return GetUniqueID();} + Int_t GetType() const {return fType;} + Int_t GetModuleID() const {return fModuleID;} + Double_t GetValue() const {return fVal;} + UInt_t GetPattern() const {return (UInt_t)TestBits(0x0ffff);} + UInt_t GetAppliedPattern() const {return fApplied;} + UInt_t GetRemainingPattern() const {return (~fApplied)&GetPattern();} + Bool_t IsApplied(Int_t par) const {return fApplied & (0x1<>kDisabledBit)&0x1;} + // + virtual Bool_t IncludesModule(Int_t id) const {return fModuleID==id;} + virtual Bool_t IncludesModPar(Int_t id,Int_t par) const {return IncludesModule(id) && IncludesParam(par);} + virtual Bool_t IncludesModPar(AliITSAlignMille2Module* mod, Int_t par) const; + // + protected: + AliITSAlignMille2Constraint(const AliITSAlignMille2Constraint& src); + AliITSAlignMille2Constraint& operator=(const AliITSAlignMille2Constraint& ) {return *this;} + // + protected: + Int_t fType; // constriant type: mean, median ... + Double_t fVal; // constraint value + Int_t fModuleID; // Id of the module involved, -1 for orphans + UInt_t fApplied; // was it already applied? + // + ClassDef(AliITSAlignMille2Constraint,0) +}; + + +#endif diff --git a/ITS/AliITSAlignMille2Module.cxx b/ITS/AliITSAlignMille2Module.cxx index 81ce6b52f0b..287c439caea 100644 --- a/ITS/AliITSAlignMille2Module.cxx +++ b/ITS/AliITSAlignMille2Module.cxx @@ -1,687 +1,1164 @@ -/************************************************************************** - * Copyright(c) 2007-2009, ALICE Experiment at CERN, All rights reserved. * - * * - * Author: The ALICE Off-line Project. * - * Contributors are mentioned in the code where appropriate. * - * * - * Permission to use, copy, modify and distribute this software and its * - * documentation strictly for non-commercial purposes is hereby granted * - * without fee, provided that the above copyright notice appears in all * - * copies and that both the copyright notice and this permission notice * - * appear in the supporting documentation. The authors make no claims * - * about the suitability of this software for any purpose. It is * - * provided "as is" without express or implied warranty. * - **************************************************************************/ - -/* $Id$ */ -//----------------------------------------------------------------------------- -/// class AliITSAlignMille2Module -/// Alignment class for the ALICE ITS detector -/// -/// This class is used by AliITSAlignMille to build custom supermodules -/// made of ITS sensitive modules. These supermodules are then aligned -/// -/// Custom supermodules must have VolumeID > 14335 -/// -/// \author M. Lunardon -//----------------------------------------------------------------------------- - -#include -#include - -#include "AliITSAlignMille2Module.h" -#include "AliITSgeomTGeo.h" -#include "AliGeomManager.h" -#include "AliAlignObjParams.h" -#include "AliLog.h" -#include "AliITSAlignMille2.h" - -/// \cond CLASSIMP -ClassImp(AliITSAlignMille2Module) -/// \endcond - -#define CORHW_ - -AliAlignObjParams AliITSAlignMille2Module::fgTempAlignObj; - -//------------------------------------------------------------- -AliITSAlignMille2Module::AliITSAlignMille2Module() : - TNamed(), - fNSensVol(0), - fIndex(-1), - fVolumeID(0), - fNProcPoints(0), - fSensVolIndex(0), - fSensVolVolumeID(0), - fMatrix(NULL), - fSensVolMatrix(NULL), - fSensVolModifMatrix(NULL), - fParent(NULL) -{ - /// void constructor - fMatrix = new TGeoHMatrix; - fSensVolMatrix = new TGeoHMatrix; - fSensVolModifMatrix = new TGeoHMatrix; - fSensVolIndex.Set(1); - fSensVolVolumeID.Set(1); - fSigmaFactor[0]=fSigmaFactor[1]=fSigmaFactor[2]=1.0; -} - -//------------------------------------------------------------- -AliITSAlignMille2Module::AliITSAlignMille2Module(Int_t index,UShort_t volid,char* symname,TGeoHMatrix *m,Int_t nsv,UShort_t *volidsv) : - TNamed(), - fNSensVol(0), - fIndex(-1), - fVolumeID(0), - fNProcPoints(0), - fSensVolIndex(0), - fSensVolVolumeID(0), - fMatrix(NULL), - fSensVolMatrix(NULL), - fSensVolModifMatrix(NULL), - fParent(NULL) -{ - /// void constructor - fMatrix = new TGeoHMatrix; - fSensVolMatrix = new TGeoHMatrix; - fSensVolModifMatrix = new TGeoHMatrix; - fSigmaFactor[0]=fSigmaFactor[1]=fSigmaFactor[2]=1.0; - if (Set(index,volid,symname,m,nsv,volidsv)) { - AliInfo("Error in AliITSAlignMille2Module::Set() - initializing void supermodule..."); - } -} - -//------------------------------------------------------------- -AliITSAlignMille2Module::AliITSAlignMille2Module(UShort_t volid) : - TNamed(), - fNSensVol(0), - fIndex(-1), - fVolumeID(0), - fNProcPoints(0), - fSensVolIndex(0), - fSensVolVolumeID(0), - fMatrix(NULL), - fSensVolMatrix(NULL), - fSensVolModifMatrix(NULL), - fParent(NULL) -{ - /// simple constructor building a supermodule from a single sensitive volume - fMatrix = new TGeoHMatrix; - fSensVolMatrix = new TGeoHMatrix; - fSensVolModifMatrix = new TGeoHMatrix; - // temporary align object, just use the rotation... - fSensVolIndex.Set(1); - fSensVolVolumeID.Set(1); - fSigmaFactor[0]=fSigmaFactor[1]=fSigmaFactor[2]=1.0; - // - fIndex = GetIndexFromVolumeID(volid); - if (fIndex>=0 && gGeoManager) { // good sensitive module and geometry loaded - SetName(AliGeomManager::SymName(volid)); - fVolumeID = volid; - AddSensitiveVolume(volid); - if (SensVolMatrix(volid, fMatrix)) - AliInfo("Matrix not defined"); - } - else { - AliInfo("Wrong VolumeID or Geometry not loaded - initializing void supermodule..."); - } -} - - -//_____________________________________________________________________________ -AliITSAlignMille2Module::AliITSAlignMille2Module(const AliITSAlignMille2Module &m) : - TNamed(m), - fNSensVol(m.fNSensVol), - fIndex(m.fIndex), - fVolumeID(m.fVolumeID), - fNProcPoints(0), - fSensVolIndex(m.fSensVolIndex), - fSensVolVolumeID(m.fSensVolVolumeID), - fMatrix(new TGeoHMatrix(*m.GetMatrix())), - fSensVolMatrix(new TGeoHMatrix), - fSensVolModifMatrix(new TGeoHMatrix), - fParent(m.fParent) -{ - // Copy constructor - fSensVolIndex = m.fSensVolIndex; - fSensVolVolumeID = m.fSensVolVolumeID; - for (int i=3;i--;) fSigmaFactor[i] = m.fSigmaFactor[i]; -} - -//_____________________________________________________________________________ -AliITSAlignMille2Module& AliITSAlignMille2Module::operator=(const AliITSAlignMille2Module &m) -{ - // operator = - // - if(this==&m) return *this; - ((TNamed *)this)->operator=(m); - // - fNSensVol=m.fNSensVol; - fIndex=m.fIndex; - fVolumeID=m.fVolumeID; - for (int i=3;i--;) fSigmaFactor[i] = m.fSigmaFactor[i]; - if (fMatrix) delete fMatrix; - fMatrix=new TGeoHMatrix(*m.GetMatrix()); - fSensVolIndex = m.fSensVolIndex; - fSensVolVolumeID = m.fSensVolVolumeID; - fParent = m.fParent; - return *this; -} - - -//------------------------------------------------------------- -AliITSAlignMille2Module::~AliITSAlignMille2Module() { - /// Destructor - delete fMatrix; - delete fSensVolMatrix; - delete fSensVolModifMatrix; -} - -//------------------------------------------------------------- -Int_t AliITSAlignMille2Module::Set(Int_t index, UShort_t volid, char* symname, TGeoHMatrix *m, Int_t nsv, UShort_t *volidsv) -{ - // initialize a custom supermodule - // index, volid, symname and matrix must be given - // if (volidsv) add nsv sensitive volumes to the supermodules - // return 0 if success - - if (index<2198) { - AliInfo("Index must be >= 2198"); - return -1; - } - if (volid<14336) { - AliInfo("VolumeID must be >= 14336"); - return -2; - } - - if (!symname) return -3; - for (Int_t i=0; i<2198; i++) { - if (!strcmp(symname,AliITSgeomTGeo::GetSymName(i))) { - AliInfo("Symname already used by a Sensitive Volume"); - return -3; - } - } - - if (!m) return -4; - - // can initialize needed stuffs - fIndex = index; - fVolumeID = volid; - SetName(symname); - // - (*fMatrix) = (*m); - // - fSensVolIndex.Set(nsv); - fSensVolVolumeID.Set(nsv); - // add sensitive volumes - for (Int_t i=0; i6) return -1; - Int_t idx=Int_t(voluid)-2048*lay; - if (idx>=AliGeomManager::LayerSize(lay)) return -1; - for (Int_t ilay=1; ilay=parent->GetNSensitiveVolumes()) return kFALSE; - return parent->IsIn( fSensVolVolumeID[0] ); -} - -//------------------------------------------------------------- -TGeoHMatrix *AliITSAlignMille2Module::GetSensitiveVolumeModifiedMatrix(UShort_t voluid, Double_t *delta,Bool_t local) -{ - // modify the original TGeoHMatrix of the sensitive module 'voluid' according - // with a delta transform. applied to the supermodule matrix - // return NULL if error - - if (!IsIn(voluid)) return NULL; - if (!gGeoManager) return NULL; - - // prepare the TGeoHMatrix - Double_t tr[3],ang[3]; - tr[0]=delta[0]; // in centimeter - tr[1]=delta[1]; - tr[2]=delta[2]; - ang[0]=delta[3]; // psi (X) in deg - ang[1]=delta[4]; // theta (Y) - ang[2]=delta[5]; // phi (Z) - // - fgTempAlignObj.SetRotation(ang[0],ang[1],ang[2]); - fgTempAlignObj.SetTranslation(tr[0],tr[1],tr[2]); - AliDebug(3,Form("Delta angles: psi=%f theta=%f phi=%f",ang[0],ang[1],ang[2])); - TGeoHMatrix hm; - fgTempAlignObj.GetMatrix(hm); - //printf("\n0: delta matrix\n");hm.Print(); - - // 1) start setting fSensVolModif = fSensVol - if (SensVolMatrix(voluid, fSensVolModifMatrix)) return NULL; - // - if (local) { - // 2) set fSensVolModif = SensVolRel - fSensVolModifMatrix->MultiplyLeft( &fMatrix->Inverse() ); - // 3) multiply left by delta - fSensVolModifMatrix->MultiplyLeft( &hm ); - // 4) multiply left by fMatrix - fSensVolModifMatrix->MultiplyLeft( fMatrix ); - } - else fSensVolModifMatrix->MultiplyLeft( &hm ); - // - return fSensVolModifMatrix; -} - -//------------------------------------------------------------- -AliAlignObjParams *AliITSAlignMille2Module::GetSensitiveVolumeMisalignment(UShort_t voluid, Double_t *deltalocal) -{ - // calculate misalignment of sens.vol. 'voluid' according with a displacement 'deltalocal' - // of the mother volume. The misalignment is returned as AliAlignObjParams object - - if (!IsIn(voluid)) return NULL; - if (!gGeoManager) return NULL; - - // prepare the TGeoHMatrix - Double_t tr[3],ang[3]; - tr[0]=deltalocal[0]; // in centimeter - tr[1]=deltalocal[1]; - tr[2]=deltalocal[2]; - ang[0]=deltalocal[3]; // psi (X) in deg - ang[1]=deltalocal[4]; // theta (Y) - ang[2]=deltalocal[5]; // phi (Z) - // - fgTempAlignObj.SetRotation(ang[0],ang[1],ang[2]); - fgTempAlignObj.SetTranslation(tr[0],tr[1],tr[2]); - AliDebug(3,Form("Delta angles: psi=%f theta=%f phi=%f",ang[0],ang[1],ang[2])); - // - return GetSensitiveVolumeMisalignment(voluid,&fgTempAlignObj); -} - -//------------------------------------------------------------- -AliAlignObjParams *AliITSAlignMille2Module::GetSensitiveVolumeMisalignment(UShort_t voluid, AliAlignObjParams *a) -{ - // return the misalignment of the sens. vol. 'voluid' corresponding with - // a misalignment 'a' in the mother volume - // return NULL if error - - // Gsv = Gg * Gg-1 * Gsv -> Lsv,g = Gg-1 * Gsv - // G'sv = Gg * Dg * Lsv,g === Gsv * Dsv - // Gg * Dg * Gg-1 * Gsv = Gsv * Gsv-1 * Gg * Dg * Gg-1 * Gsv - // - // => Dsv = (Gsv-1 * Gg * Dg * Gg-1 * Gsv) - // - - if (!IsIn(voluid)) return NULL; - if (!gGeoManager) return NULL; - - //a->Print(""); - - // prepare the Delta matrix Dg - TGeoHMatrix dg; - a->GetMatrix(dg); - //dg.Print(); - - // 1) start setting fSensVolModif = Gsv - if (SensVolMatrix(voluid, fSensVolModifMatrix)) return NULL; - //printf("\n1: modif=orig del sensvol\n");fSensVolModifMatrix->Print(); - - // 2) set fSensVolModif = Gg-1 * Gsv - fSensVolModifMatrix->MultiplyLeft( &fMatrix->Inverse() ); - //printf("\n2: modif=relative del sensvol\n");fSensVolModifMatrix->Print(); - - // 3) set fSensVolModif = Dg * Gg-1 * Gsv - fSensVolModifMatrix->MultiplyLeft( &dg ); - //printf("\n3: modif= delta*relative\n");fSensVolModifMatrix->Print(); - - // 4) set fSensVolModif = Gg * Dg * Gg-1 * Gsv - fSensVolModifMatrix->MultiplyLeft( fMatrix ); - //printf("\n4: modif=quasi,manca il Gsv-1...\n");fSensVolModifMatrix->Print(); - - // 5) set fSensVolModif = Gsv-1 * Gg * Dg * Gg-1 * Gsv - if (SensVolMatrix(voluid, &dg)) return NULL; - fSensVolModifMatrix->MultiplyLeft( &dg.Inverse() ); - //printf("\n5: modif=finale\n");fSensVolModifMatrix->Print(); - // - // >> RS - // 6) mo' fSensVolModif dovrebbe essere la Dsv(loc) t.c. G'sv = Gsv*Dsv(loc) - // per trasformarla in Dsv(loc rispetto al Gsv0, non modificato) dovrebbe essere: - // Dsv(loc) -> Dpre * Dsv(loc) * Dpre-1 - //TGeoHMatrix dpre; // dpre = Gsv0-1*Gsv - //if (SensVolOrigGlobalMatrix(voluid, &dg)) return NULL; - //if (SensVolMatrix(voluid, &dpre)) return NULL; - //dpre.MultiplyLeft( &dg.Inverse() ); - //fSensVolModifMatrix->Multiply( &dpre.Inverse() ); - //fSensVolModifMatrix->MultiplyLeft( &dpre ); - // direi che NON FUNZIONA!!!! - - // << RS - - // reset align object (may not be needed...) - fgTempAlignObj.SetVolUID(0); - fgTempAlignObj.SetSymName(""); - fgTempAlignObj.SetTranslation(0,0,0); - fgTempAlignObj.SetRotation(0,0,0); - // - // >> RS -#ifdef CORHW_ - // correction for SPD y-shift - if (voluid>=2048 && voluid<4256) { - TGeoHMatrix deltay; - double dy[3]={0.,0.0081,0.}; - deltay.SetTranslation(dy); - fSensVolModifMatrix->MultiplyLeft( &deltay ); - fSensVolModifMatrix->Multiply( &deltay.Inverse() ); - } -#endif - // << RS - if (!fgTempAlignObj.SetMatrix(*fSensVolModifMatrix)) return NULL; - fgTempAlignObj.SetVolUID(voluid); - fgTempAlignObj.SetSymName(AliGeomManager::SymName(voluid)); - // - return &fgTempAlignObj; -} - -// >> RS -//------------------------------------------------------------- -AliAlignObjParams *AliITSAlignMille2Module::GetSensitiveVolumeTotalMisalignment(UShort_t voluid, Double_t *deltalocal) -{ - // calculate misalignment of sens.vol. 'voluid' according with a displacement 'deltalocal' - // of the mother volume. The misalignment is returned as AliAlignObjParams object including - // the (evenctual) prealignment => no merging needed - - if (!IsIn(voluid)) return NULL; - if (!gGeoManager) return NULL; - - // prepare the TGeoHMatrix - Double_t tr[3],ang[3]; - tr[0]=deltalocal[0]; // in centimeter - tr[1]=deltalocal[1]; - tr[2]=deltalocal[2]; - ang[0]=deltalocal[3]; // psi (X) in deg - ang[1]=deltalocal[4]; // theta (Y) - ang[2]=deltalocal[5]; // phi (Z) - - // reset align object (may not be needed...) - fgTempAlignObj.SetVolUID(0); - fgTempAlignObj.SetSymName(""); - fgTempAlignObj.SetRotation(ang[0],ang[1],ang[2]); - fgTempAlignObj.SetTranslation(tr[0],tr[1],tr[2]); - AliDebug(3,Form("Delta angles: psi=%f theta=%f phi=%f",ang[0],ang[1],ang[2])); - - // Gsv = Gg * Gg-1 * Gsv -> Lsv,g = Gg-1 * Gsv - // G'sv = Gg * Dg * Lsv,g === DGsv * Gsv - // - // => Dsv = (G0sv-1 * Gg * Dg * Gg-1 * GMsv) // - // - - // prepare the Delta matrix Dg - TGeoHMatrix dg; - fgTempAlignObj.GetMatrix(dg); - //dg.Print(); - - // 1) start setting fSensVolModif = Gsv - if (SensVolMatrix(voluid, fSensVolModifMatrix)) return NULL; - //printf("\n1: modif=orig del sensvol\n");fSensVolModifMatrix->Print(); - - // 2) set fSensVolModif = Gg-1 * Gsv - fSensVolModifMatrix->MultiplyLeft( &fMatrix->Inverse() ); - //printf("\n2: modif=relative del sensvol\n");fSensVolModifMatrix->Print(); - - // 3) set fSensVolModif = Dg * Gg-1 * Gsv - fSensVolModifMatrix->MultiplyLeft( &dg ); - //printf("\n3: modif= delta*relative\n");fSensVolModifMatrix->Print(); - - // 4) set fSensVolModif = Gg * Dg * Gg-1 * Gsv - fSensVolModifMatrix->MultiplyLeft( fMatrix ); - //printf("\n4: modif=quasi,manca il Gsv-1...\n");fSensVolModifMatrix->Print(); - - // 5) set fSensVolModif = G0sv-1 * Gg * Dg * Gg-1 * Gsv - // qui usa l'orig anziche' la prealigned... - if (SensVolOrigGlobalMatrix(voluid, &dg)) return NULL; - fSensVolModifMatrix->MultiplyLeft( &dg.Inverse() ); - //printf("\n5: modif=finale\n");fSensVolModifMatrix->Print(); - - // reset align object (may not be needed...) - fgTempAlignObj.SetVolUID(0); - fgTempAlignObj.SetSymName(""); - fgTempAlignObj.SetTranslation(0,0,0); - fgTempAlignObj.SetRotation(0,0,0); - -#ifdef CORHW_ - // correction for SPD y-shift - if (voluid>=2048 && voluid<4256) { - TGeoHMatrix deltay; - double dy[3]={0.,0.0081,0.}; - deltay.SetTranslation(dy); - fSensVolModifMatrix->MultiplyLeft( &deltay ); - fSensVolModifMatrix->Multiply( &deltay.Inverse() ); - } -#endif - if (!fgTempAlignObj.SetMatrix(*fSensVolModifMatrix)) return NULL; - fgTempAlignObj.SetVolUID(voluid); - fgTempAlignObj.SetSymName(AliGeomManager::SymName(voluid)); - - - //fgTempAlignObj.Print(""); - - return &fgTempAlignObj; -} -//------------------------------------------------------------- - -//------------------------------------------------------------- -AliAlignObjParams *AliITSAlignMille2Module::GetSensitiveVolumeGlobalMisalignment(UShort_t voluid, Double_t *deltalocal) -{ - // calculate misalignment of sens.vol. 'voluid' according with a displacement 'deltalocal' - // of the mother volume. The misalignment is returned as AliAlignObjParams object - - if (!IsIn(voluid)) return NULL; - if (!gGeoManager) return NULL; - - // prepare the TGeoHMatrix - Double_t tr[3],ang[3]; - tr[0]=deltalocal[0]; // in centimeter - tr[1]=deltalocal[1]; - tr[2]=deltalocal[2]; - ang[0]=deltalocal[3]; // psi (X) in deg - ang[1]=deltalocal[4]; // theta (Y) - ang[2]=deltalocal[5]; // phi (Z) - - // reset align object (may not be needed...) - fgTempAlignObj.SetTranslation(0,0,0); - fgTempAlignObj.SetRotation(0,0,0); - - fgTempAlignObj.SetRotation(ang[0],ang[1],ang[2]); - fgTempAlignObj.SetTranslation(tr[0],tr[1],tr[2]); - AliDebug(3,Form("Delta angles: psi=%f theta=%f phi=%f",ang[0],ang[1],ang[2])); - - // Gsv = Gg * Gg-1 * Gsv -> Lsv,g = Gg-1 * Gsv - // G'sv = Gg * Dg * Lsv,g === DGsv * Gsv - // - // => DGsv = (Gg * Dg * Gg-1) - // - - // prepare the Delta matrix Dg - TGeoHMatrix dg; - fgTempAlignObj.GetMatrix(dg); - //dg.Print(); - - dg.MultiplyLeft( fMatrix ); - dg.Multiply( &fMatrix->Inverse() ); - - // reset align object (may not be needed...) - fgTempAlignObj.SetTranslation(0,0,0); - fgTempAlignObj.SetRotation(0,0,0); - - fgTempAlignObj.SetVolUID(voluid); - fgTempAlignObj.SetSymName(AliGeomManager::SymName(voluid)); - - if (!fgTempAlignObj.SetMatrix(dg)) return NULL; - - //fgTempAlignObj.Print(""); - - return &fgTempAlignObj; -} -// << RS - -//------------------------------------------------------------- -TGeoHMatrix *AliITSAlignMille2Module::GetSensitiveVolumeMatrix(UShort_t voluid) -{ - // return TGeoHMatrix of the sens.vol. 'voluid' in the current geometry - if (SensVolMatrix(voluid,fSensVolMatrix)) return NULL; - return fSensVolMatrix; -} - -//------------------------------------------------------------- -TGeoHMatrix *AliITSAlignMille2Module::GetSensitiveVolumeOrigGlobalMatrix(UShort_t voluid) -{ - // return original ideal position (from AliGeomManager::GetOrigGlobalMatrix()) - if (SensVolOrigGlobalMatrix(voluid,fSensVolMatrix)) return NULL; - return fSensVolMatrix; -} -//------------------------------------------------------------- -Int_t AliITSAlignMille2Module::SensVolMatrix(UShort_t volid, TGeoHMatrix *m) -{ - // set matrix for sensitive modules (SPD corrected) - // return 0 if success - Double_t rot[9]; - Int_t idx=GetIndexFromVolumeID(volid); - if (idx<0) return -1; - if (!AliITSgeomTGeo::GetRotation(idx,rot)) return -2; - m->SetRotation(rot); - Double_t oLoc[3]={0,0,0}; - Double_t oGlo[3]={0,0,0}; - if (!AliITSgeomTGeo::LocalToGlobal(idx,oLoc,oGlo)) return -3; - m->SetTranslation(oGlo); - return 0; -} - -//------------------------------------------------------------- -Int_t AliITSAlignMille2Module::SensVolOrigGlobalMatrix(UShort_t volid, TGeoHMatrix *m) -{ - // set original global matrix for sensitive modules (SPD corrected) - // return 0 if success - Int_t idx=GetIndexFromVolumeID(volid); - if (idx<0) return -1; - TGeoHMatrix mo; - if (!AliGeomManager::GetOrigGlobalMatrix(AliGeomManager::SymName(volid),mo)) (*m)=mo; - -#ifdef CORHW_ - // SPD y-shift by 81 mu - if (volid<5000) { - Double_t oLoc[3]={0.0,0.0081,0.0}; - Double_t oGlo[3]={0,0,0}; - m->LocalToMaster(oLoc,oGlo); - m->SetTranslation(oGlo); - } -#endif - return 0; -} - -//------------------------------------------------------------- -UShort_t AliITSAlignMille2Module::GetVolumeIDFromSymname(const Char_t *symname) { - /// volume ID from symname - if (!symname) return 0; - - for (UShort_t voluid=2000; voluid<13300; voluid++) { - Int_t modId; - AliGeomManager::ELayerID layerId = AliGeomManager::VolUIDToLayer(voluid,modId); - if (layerId>0 && layerId<7 && modId>=0 && modId2197) return 0; - return GetVolumeIDFromSymname(AliITSgeomTGeo::GetSymName(index)); -} - -//------------------------------------------------------------- -void AliITSAlignMille2Module::Print(Option_t*) const -{ - /// - printf("*** ITS SuperModule for AliITSAlignMille ***\n"); - printf("symname : %s\n",GetName()); - printf("parent : %s\n",fParent ? fParent->GetName() : "N/A"); - printf("volumeID : %4d | index : %4d\n",fVolumeID,fIndex); - printf("Factors : X=%.2f Y=%.2f Z=%.2f | DOF: Tx:%d Ty:%d Tz:%d Phi:%d Theta:%d Psi:%d\n", - fSigmaFactor[0],fSigmaFactor[1],fSigmaFactor[2], - IsFreeDOF(AliITSAlignMille2::kDOFTX),IsFreeDOF(AliITSAlignMille2::kDOFTY), - IsFreeDOF(AliITSAlignMille2::kDOFTZ),IsFreeDOF(AliITSAlignMille2::kDOFPH), - IsFreeDOF(AliITSAlignMille2::kDOFTH),IsFreeDOF(AliITSAlignMille2::kDOFPS)); - fMatrix->Print(); - printf("%4d Sensitive volumes | %6d Processed Points\n",fNSensVol,fNProcPoints); - for (Int_t i=0; iGetAlignableEntry(GetName())!=0; -} - -//------------------------------------------------------------- -void AliITSAlignMille2Module::GetLocalMatrix(TGeoHMatrix &mat) const -{ - // return the local matrix for transformation to its parent - mat = *fMatrix; - if (fParent) mat.MultiplyLeft( &fParent->GetMatrix()->Inverse() ); -} +/************************************************************************** + * Copyright(c) 2007-2009, ALICE Experiment at CERN, All rights reserved. * + * * + * Author: The ALICE Off-line Project. * + * Contributors are mentioned in the code where appropriate. * + * * + * Permission to use, copy, modify and distribute this software and its * + * documentation strictly for non-commercial purposes is hereby granted * + * without fee, provided that the above copyright notice appears in all * + * copies and that both the copyright notice and this permission notice * + * appear in the supporting documentation. The authors make no claims * + * about the suitability of this software for any purpose. It is * + * provided "as is" without express or implied warranty. * + **************************************************************************/ + +/* $Id$ */ +//----------------------------------------------------------------------------- +/// \class AliITSAlignMille2Module +/// Alignment class for the ALICE ITS detector +/// +/// This class is used by AliITSAlignMille to build custom supermodules +/// made of ITS sensitive modules. These supermodules are then aligned +/// +/// Custom supermodules must have VolumeID > 14335 +/// +/// \author M. Lunardon +//----------------------------------------------------------------------------- + +#include +#include + +#include "AliITSAlignMille2Module.h" +#include "AliITSgeomTGeo.h" +#include "AliGeomManager.h" +#include "AliAlignObjParams.h" +#include "AliLog.h" +#include "AliITSAlignMille2.h" + +/// \cond CLASSIMP +ClassImp(AliITSAlignMille2Module) +/// \endcond + +#define CORHW_ + +AliAlignObjParams AliITSAlignMille2Module::fgTempAlignObj; +const Float_t AliITSAlignMille2Module::fgkDummyConstraint = 1.E3; + +//------------------------------------------------------------- +AliITSAlignMille2Module::AliITSAlignMille2Module() : + TNamed(), + fNSensVol(0), + fIndex(-1), + fDetType(-1), + fVolumeID(0), + fNParTot(0), + fNParFree(0), + fParOffs(0), + fNProcPoints(0), + fParVals(0), + fParErrs(0), + fParCstr(0), + fSensVolIndex(0), + fSensVolVolumeID(0), + fMatrix(NULL), + fSensVolMatrix(NULL), + fSensVolModifMatrix(NULL), + fParent(NULL), + fChildren(0) +{ + /// void constructor + fMatrix = new TGeoHMatrix; + fSensVolMatrix = new TGeoHMatrix; + fSensVolModifMatrix = new TGeoHMatrix; + fSensVolIndex.Set(1); + fSensVolVolumeID.Set(1); + fSigmaFactor[0]=fSigmaFactor[1]=fSigmaFactor[2]=1.0; +} + +//------------------------------------------------------------- +AliITSAlignMille2Module::AliITSAlignMille2Module(Int_t index,UShort_t volid,char* symname,TGeoHMatrix *m,Int_t nsv,UShort_t *volidsv) : + TNamed(), + fNSensVol(0), + fIndex(-1), + fDetType(-1), + fVolumeID(0), + fNParTot(0), + fNParFree(0), + fParOffs(kMaxParGeom), + fNProcPoints(0), + fParVals(0), + fParErrs(0), + fParCstr(0), + fSensVolIndex(0), + fSensVolVolumeID(0), + fMatrix(NULL), + fSensVolMatrix(NULL), + fSensVolModifMatrix(NULL), + fParent(NULL), + fChildren(0) +{ + /// void constructor + fMatrix = new TGeoHMatrix; + fSensVolMatrix = new TGeoHMatrix; + fSensVolModifMatrix = new TGeoHMatrix; + fSigmaFactor[0]=fSigmaFactor[1]=fSigmaFactor[2]=1.0; + for (int i=kMaxParGeom;i--;) fParOffs[i] = -1; + if (Set(index,volid,symname,m,nsv,volidsv)) { + AliInfo("Error in AliITSAlignMille2Module::Set() - initializing void supermodule..."); + } + AssignDetType(); +} + +//------------------------------------------------------------- +AliITSAlignMille2Module::AliITSAlignMille2Module(UShort_t volid) : + TNamed(), + fNSensVol(0), + fIndex(-1), + fDetType(-1), + fVolumeID(0), + fNParTot(0), + fNParFree(0), + fParOffs(kMaxParGeom), + fNProcPoints(0), + fParVals(0), + fParErrs(0), + fParCstr(0), + fSensVolIndex(0), + fSensVolVolumeID(0), + fMatrix(NULL), + fSensVolMatrix(NULL), + fSensVolModifMatrix(NULL), + fParent(NULL), + fChildren(0) +{ + /// simple constructor building a supermodule from a single sensitive volume + fMatrix = new TGeoHMatrix; + fSensVolMatrix = new TGeoHMatrix; + fSensVolModifMatrix = new TGeoHMatrix; + // temporary align object, just use the rotation... + fSensVolIndex.Set(1); + fSensVolVolumeID.Set(1); + fSigmaFactor[0]=fSigmaFactor[1]=fSigmaFactor[2]=1.0; + for (int i=kMaxParGeom;i--;) fParOffs[i] = -1; + // + fIndex = GetIndexFromVolumeID(volid); + if (fIndex>=0 && gGeoManager) { // good sensitive module and geometry loaded + SetName(AliGeomManager::SymName(volid)); + fVolumeID = volid; + AddSensitiveVolume(volid); + SetSensorsProvided(kTRUE); + if (SensVolMatrix(volid, fMatrix)) + AliInfo("Matrix not defined"); + } + else { + AliInfo("Wrong VolumeID or Geometry not loaded - initializing void supermodule..."); + } + AssignDetType(); +} + + +//_____________________________________________________________________________ +AliITSAlignMille2Module::AliITSAlignMille2Module(const AliITSAlignMille2Module &m) : + TNamed(m), + fNSensVol(m.fNSensVol), + fIndex(m.fIndex), + fDetType(m.fDetType), + fVolumeID(m.fVolumeID), + fNParTot(m.fNParTot), + fNParFree(m.fNParFree), + fParOffs(m.fNParTot), + fNProcPoints(0), + fParVals(0), + fParErrs(0), + fParCstr(0), + fSensVolIndex(m.fSensVolIndex), + fSensVolVolumeID(m.fSensVolVolumeID), + fMatrix(new TGeoHMatrix(*m.GetMatrix())), + fSensVolMatrix(new TGeoHMatrix), + fSensVolModifMatrix(new TGeoHMatrix), + fParent(m.fParent), + fChildren(0) +{ + // Copy constructor + fSensVolIndex = m.fSensVolIndex; + fSensVolVolumeID = m.fSensVolVolumeID; + for (int i=m.fNParTot;i--;) fParOffs[i] = m.fParOffs[i]; + for (int i=3;i--;) fSigmaFactor[i] = m.fSigmaFactor[i]; + if (fNParTot) { + fParVals = new Float_t[fNParTot]; + fParErrs = new Float_t[fNParTot]; + fParCstr = new Float_t[fNParTot]; + for (int i=fNParTot;i--;) { + fParVals[i] = m.fParVals[i]; + fParErrs[i] = m.fParErrs[i]; + fParCstr[i] = m.fParCstr[i]; + } + } +} + +//_____________________________________________________________________________ +AliITSAlignMille2Module& AliITSAlignMille2Module::operator=(const AliITSAlignMille2Module &m) +{ + // operator = + // + if(this==&m) return *this; + ((TNamed *)this)->operator=(m); + // + fNSensVol=m.fNSensVol; + fIndex=m.fIndex; + fDetType = m.fDetType; + fVolumeID=m.fVolumeID; + fNParTot = m.fNParTot; + fNParFree = m.fNParFree; + delete[] fParVals; fParVals = 0; + delete[] fParErrs; fParErrs = 0; + delete[] fParCstr; fParCstr = 0; + // + if (fNParTot) { + fParVals = new Float_t[fNParTot]; + fParErrs = new Float_t[fNParTot]; + for (int i=m.GetNParTot();i--;) { + fParVals[i] = m.fParVals[i]; + fParErrs[i] = m.fParErrs[i]; + fParCstr[i] = m.fParCstr[i]; + } + } + // + fParOffs.Set(fNParTot); + for (int i=0;i= 2198"); + return -1; + } + if (volid<14336) { + AliInfo("VolumeID must be >= 14336"); + return -2; + } + + if (!symname) return -3; + for (Int_t i=0; i<2198; i++) { + if (!strcmp(symname,AliITSgeomTGeo::GetSymName(i))) { + AliInfo("Symname already used by a Sensitive Volume"); + return -3; + } + } + + if (!m) return -4; + + // can initialize needed stuffs + fIndex = index; + fVolumeID = volid; + SetName(symname); + // + (*fMatrix) = (*m); + // + fSensVolIndex.Set(nsv); + fSensVolVolumeID.Set(nsv); + // add sensitive volumes + for (Int_t i=0; i0) fParCstr[dof] = fgkDummyConstraint+1.; // the parameter is free and unconstrained + else if (cstr<0) fParCstr[dof] = -cstr; // the parameter is free but constrained + else fParCstr[dof] = 0; // fixed parameter +} + +//------------------------------------------------------------- +Bool_t AliITSAlignMille2Module::IsSensor(UShort_t voluid) +{ + // Does this volid correspond to sensor ? + AliGeomManager::ELayerID layId = AliGeomManager::VolUIDToLayerSafe(voluid); + if (layId>0 && layId<7) { + Int_t mId = Int_t(voluid & 0x7ff); + if( mId>=0 && mId6) return -1; + Int_t idx=Int_t(voluid)-2048*lay; + if (idx>=AliGeomManager::LayerSize(lay)) return -1; + for (Int_t ilay=1; ilay=parent->GetNSensitiveVolumes()) return kFALSE; + return parent->IsIn( fSensVolVolumeID[0] ); +} + +//------------------------------------------------------------- +TGeoHMatrix *AliITSAlignMille2Module::GetSensitiveVolumeModifiedMatrix(UShort_t voluid, Double_t *delta,Bool_t local) +{ + // modify the original TGeoHMatrix of the sensitive module 'voluid' according + // with a delta transform. applied to the supermodule matrix + // return NULL if error + + if (!IsIn(voluid)) return NULL; + if (!gGeoManager) return NULL; + + // prepare the TGeoHMatrix + Double_t tr[3],ang[3]; + tr[0]=delta[0]; // in centimeter + tr[1]=delta[1]; + tr[2]=delta[2]; + ang[0]=delta[3]; // psi (X) in deg + ang[1]=delta[4]; // theta (Y) + ang[2]=delta[5]; // phi (Z) + // + fgTempAlignObj.SetRotation(ang[0],ang[1],ang[2]); + fgTempAlignObj.SetTranslation(tr[0],tr[1],tr[2]); + AliDebug(3,Form("Delta angles: psi=%f theta=%f phi=%f",ang[0],ang[1],ang[2])); + TGeoHMatrix hm; + fgTempAlignObj.GetMatrix(hm); + //printf("\n0: delta matrix\n");hm.Print(); + + // 1) start setting fSensVolModif = fSensVol + if (SensVolMatrix(voluid, fSensVolModifMatrix)) return NULL; + // + if (local) { + // 2) set fSensVolModif = SensVolRel + fSensVolModifMatrix->MultiplyLeft( &fMatrix->Inverse() ); + // 3) multiply left by delta + fSensVolModifMatrix->MultiplyLeft( &hm ); + // 4) multiply left by fMatrix + fSensVolModifMatrix->MultiplyLeft( fMatrix ); + } + else fSensVolModifMatrix->MultiplyLeft( &hm ); + // + return fSensVolModifMatrix; +} + +//------------------------------------------------------------- +AliAlignObjParams *AliITSAlignMille2Module::GetSensitiveVolumeMisalignment(UShort_t voluid, Double_t *deltalocal) +{ + // calculate misalignment of sens.vol. 'voluid' according with a displacement 'deltalocal' + // of the mother volume. The misalignment is returned as AliAlignObjParams object + + if (!IsIn(voluid)) return NULL; + if (!gGeoManager) return NULL; + + // prepare the TGeoHMatrix + Double_t tr[3],ang[3]; + tr[0]=deltalocal[0]; // in centimeter + tr[1]=deltalocal[1]; + tr[2]=deltalocal[2]; + ang[0]=deltalocal[3]; // psi (X) in deg + ang[1]=deltalocal[4]; // theta (Y) + ang[2]=deltalocal[5]; // phi (Z) + // + fgTempAlignObj.SetRotation(ang[0],ang[1],ang[2]); + fgTempAlignObj.SetTranslation(tr[0],tr[1],tr[2]); + AliDebug(3,Form("Delta angles: psi=%f theta=%f phi=%f",ang[0],ang[1],ang[2])); + // + return GetSensitiveVolumeMisalignment(voluid,&fgTempAlignObj); +} + +//------------------------------------------------------------- +AliAlignObjParams *AliITSAlignMille2Module::GetSensitiveVolumeMisalignment(UShort_t voluid, AliAlignObjParams *a) +{ + // return the misalignment of the sens. vol. 'voluid' corresponding with + // a misalignment 'a' in the mother volume + // return NULL if error + + // Gsv = Gg * Gg-1 * Gsv -> Lsv,g = Gg-1 * Gsv + // G'sv = Gg * Dg * Lsv,g === Gsv * Dsv + // Gg * Dg * Gg-1 * Gsv = Gsv * Gsv-1 * Gg * Dg * Gg-1 * Gsv + // + // => Dsv = (Gsv-1 * Gg * Dg * Gg-1 * Gsv) + // + + if (!IsIn(voluid)) return NULL; + if (!gGeoManager) return NULL; + + //a->Print(""); + + // prepare the Delta matrix Dg + TGeoHMatrix dg; + a->GetMatrix(dg); + //dg.Print(); + + // 1) start setting fSensVolModif = Gsv + if (SensVolMatrix(voluid, fSensVolModifMatrix)) return NULL; + //printf("\n1: modif=orig del sensvol\n");fSensVolModifMatrix->Print(); + + // 2) set fSensVolModif = Gg-1 * Gsv + fSensVolModifMatrix->MultiplyLeft( &fMatrix->Inverse() ); + //printf("\n2: modif=relative del sensvol\n");fSensVolModifMatrix->Print(); + + // 3) set fSensVolModif = Dg * Gg-1 * Gsv + fSensVolModifMatrix->MultiplyLeft( &dg ); + //printf("\n3: modif= delta*relative\n");fSensVolModifMatrix->Print(); + + // 4) set fSensVolModif = Gg * Dg * Gg-1 * Gsv + fSensVolModifMatrix->MultiplyLeft( fMatrix ); + //printf("\n4: modif=quasi,manca il Gsv-1...\n");fSensVolModifMatrix->Print(); + + // 5) set fSensVolModif = Gsv-1 * Gg * Dg * Gg-1 * Gsv + if (SensVolMatrix(voluid, &dg)) return NULL; + fSensVolModifMatrix->MultiplyLeft( &dg.Inverse() ); + //printf("\n5: modif=finale\n");fSensVolModifMatrix->Print(); + // + // >> RS + // 6) mo' fSensVolModif dovrebbe essere la Dsv(loc) t.c. G'sv = Gsv*Dsv(loc) + // per trasformarla in Dsv(loc rispetto al Gsv0, non modificato) dovrebbe essere: + // Dsv(loc) -> Dpre * Dsv(loc) * Dpre-1 + //TGeoHMatrix dpre; // dpre = Gsv0-1*Gsv + //if (SensVolOrigGlobalMatrix(voluid, &dg)) return NULL; + //if (SensVolMatrix(voluid, &dpre)) return NULL; + //dpre.MultiplyLeft( &dg.Inverse() ); + //fSensVolModifMatrix->Multiply( &dpre.Inverse() ); + //fSensVolModifMatrix->MultiplyLeft( &dpre ); + // direi che NON FUNZIONA!!!! + + // << RS + + // reset align object (may not be needed...) + fgTempAlignObj.SetVolUID(0); + fgTempAlignObj.SetSymName(""); + fgTempAlignObj.SetTranslation(0,0,0); + fgTempAlignObj.SetRotation(0,0,0); + // + // >> RS +#ifdef CORHW_ + // correction for SPD y-shift + if (voluid>=2048 && voluid<4256) { + TGeoHMatrix deltay; + double dy[3]={0.,0.0081,0.}; + deltay.SetTranslation(dy); + fSensVolModifMatrix->MultiplyLeft( &deltay ); + fSensVolModifMatrix->Multiply( &deltay.Inverse() ); + } +#endif + // << RS + if (!fgTempAlignObj.SetMatrix(*fSensVolModifMatrix)) return NULL; + fgTempAlignObj.SetVolUID(voluid); + fgTempAlignObj.SetSymName(AliGeomManager::SymName(voluid)); + // + return &fgTempAlignObj; +} + +// >> RS +//------------------------------------------------------------- +AliAlignObjParams *AliITSAlignMille2Module::GetSensitiveVolumeTotalMisalignment(UShort_t voluid, Double_t *deltalocal) +{ + // calculate misalignment of sens.vol. 'voluid' according with a displacement 'deltalocal' + // of the mother volume. The misalignment is returned as AliAlignObjParams object including + // the (evenctual) prealignment => no merging needed + + if (!IsIn(voluid)) return NULL; + if (!gGeoManager) return NULL; + + // prepare the TGeoHMatrix + Double_t tr[3],ang[3]; + tr[0]=deltalocal[0]; // in centimeter + tr[1]=deltalocal[1]; + tr[2]=deltalocal[2]; + ang[0]=deltalocal[3]; // psi (X) in deg + ang[1]=deltalocal[4]; // theta (Y) + ang[2]=deltalocal[5]; // phi (Z) + + // reset align object (may not be needed...) + fgTempAlignObj.SetVolUID(0); + fgTempAlignObj.SetSymName(""); + fgTempAlignObj.SetRotation(ang[0],ang[1],ang[2]); + fgTempAlignObj.SetTranslation(tr[0],tr[1],tr[2]); + AliDebug(3,Form("Delta angles: psi=%f theta=%f phi=%f",ang[0],ang[1],ang[2])); + + // Gsv = Gg * Gg-1 * Gsv -> Lsv,g = Gg-1 * Gsv + // G'sv = Gg * Dg * Lsv,g === DGsv * Gsv + // + // => Dsv = (G0sv-1 * Gg * Dg * Gg-1 * GMsv) // + // + + // prepare the Delta matrix Dg + TGeoHMatrix dg; + fgTempAlignObj.GetMatrix(dg); + //dg.Print(); + + // 1) start setting fSensVolModif = Gsv + if (SensVolMatrix(voluid, fSensVolModifMatrix)) return NULL; + //printf("\n1: modif=orig del sensvol\n");fSensVolModifMatrix->Print(); + + // 2) set fSensVolModif = Gg-1 * Gsv + fSensVolModifMatrix->MultiplyLeft( &fMatrix->Inverse() ); + //printf("\n2: modif=relative del sensvol\n");fSensVolModifMatrix->Print(); + + // 3) set fSensVolModif = Dg * Gg-1 * Gsv + fSensVolModifMatrix->MultiplyLeft( &dg ); + //printf("\n3: modif= delta*relative\n");fSensVolModifMatrix->Print(); + + // 4) set fSensVolModif = Gg * Dg * Gg-1 * Gsv + fSensVolModifMatrix->MultiplyLeft( fMatrix ); + //printf("\n4: modif=quasi,manca il Gsv-1...\n");fSensVolModifMatrix->Print(); + + // 5) set fSensVolModif = G0sv-1 * Gg * Dg * Gg-1 * Gsv + // qui usa l'orig anziche' la prealigned... + if (SensVolOrigGlobalMatrix(voluid, &dg)) return NULL; + fSensVolModifMatrix->MultiplyLeft( &dg.Inverse() ); + //printf("\n5: modif=finale\n");fSensVolModifMatrix->Print(); + + // reset align object (may not be needed...) + fgTempAlignObj.SetVolUID(0); + fgTempAlignObj.SetSymName(""); + fgTempAlignObj.SetTranslation(0,0,0); + fgTempAlignObj.SetRotation(0,0,0); + +#ifdef CORHW_ + // correction for SPD y-shift + if (voluid>=2048 && voluid<4256) { + TGeoHMatrix deltay; + double dy[3]={0.,0.0081,0.}; + deltay.SetTranslation(dy); + fSensVolModifMatrix->MultiplyLeft( &deltay ); + fSensVolModifMatrix->Multiply( &deltay.Inverse() ); + } +#endif + if (!fgTempAlignObj.SetMatrix(*fSensVolModifMatrix)) return NULL; + fgTempAlignObj.SetVolUID(voluid); + fgTempAlignObj.SetSymName(AliGeomManager::SymName(voluid)); + + + //fgTempAlignObj.Print(""); + + return &fgTempAlignObj; +} +//------------------------------------------------------------- + +//------------------------------------------------------------- +AliAlignObjParams *AliITSAlignMille2Module::GetSensitiveVolumeGlobalMisalignment(UShort_t voluid, Double_t *deltalocal) +{ + // calculate misalignment of sens.vol. 'voluid' according with a displacement 'deltalocal' + // of the mother volume. The misalignment is returned as AliAlignObjParams object + + if (!IsIn(voluid)) return NULL; + if (!gGeoManager) return NULL; + + // prepare the TGeoHMatrix + Double_t tr[3],ang[3]; + tr[0]=deltalocal[0]; // in centimeter + tr[1]=deltalocal[1]; + tr[2]=deltalocal[2]; + ang[0]=deltalocal[3]; // psi (X) in deg + ang[1]=deltalocal[4]; // theta (Y) + ang[2]=deltalocal[5]; // phi (Z) + + // reset align object (may not be needed...) + fgTempAlignObj.SetTranslation(0,0,0); + fgTempAlignObj.SetRotation(0,0,0); + + fgTempAlignObj.SetRotation(ang[0],ang[1],ang[2]); + fgTempAlignObj.SetTranslation(tr[0],tr[1],tr[2]); + AliDebug(3,Form("Delta angles: psi=%f theta=%f phi=%f",ang[0],ang[1],ang[2])); + + // Gsv = Gg * Gg-1 * Gsv -> Lsv,g = Gg-1 * Gsv + // G'sv = Gg * Dg * Lsv,g === DGsv * Gsv + // + // => DGsv = (Gg * Dg * Gg-1) + // + + // prepare the Delta matrix Dg + TGeoHMatrix dg; + fgTempAlignObj.GetMatrix(dg); + //dg.Print(); + + dg.MultiplyLeft( fMatrix ); + dg.Multiply( &fMatrix->Inverse() ); + + // reset align object (may not be needed...) + fgTempAlignObj.SetTranslation(0,0,0); + fgTempAlignObj.SetRotation(0,0,0); + + fgTempAlignObj.SetVolUID(voluid); + fgTempAlignObj.SetSymName(AliGeomManager::SymName(voluid)); + + if (!fgTempAlignObj.SetMatrix(dg)) return NULL; + + //fgTempAlignObj.Print(""); + + return &fgTempAlignObj; +} +// << RS + +//------------------------------------------------------------- +TGeoHMatrix *AliITSAlignMille2Module::GetSensitiveVolumeMatrix(UShort_t voluid) +{ + // return TGeoHMatrix of the sens.vol. 'voluid' in the current geometry + if (SensVolMatrix(voluid,fSensVolMatrix)) return NULL; + return fSensVolMatrix; +} + +//------------------------------------------------------------- +TGeoHMatrix *AliITSAlignMille2Module::GetSensitiveVolumeOrigGlobalMatrix(UShort_t voluid) +{ + // return original ideal position (from AliGeomManager::GetOrigGlobalMatrix()) + if (SensVolOrigGlobalMatrix(voluid,fSensVolMatrix)) return NULL; + return fSensVolMatrix; +} +//------------------------------------------------------------- +Int_t AliITSAlignMille2Module::SensVolMatrix(UShort_t volid, TGeoHMatrix *m) +{ + // set matrix for sensitive modules (SPD corrected) + // return 0 if success + Double_t rot[9]; + Int_t idx=GetIndexFromVolumeID(volid); + if (idx<0) return -1; + if (!AliITSgeomTGeo::GetRotation(idx,rot)) return -2; + m->SetRotation(rot); + Double_t oLoc[3]={0,0,0}; + Double_t oGlo[3]={0,0,0}; + if (!AliITSgeomTGeo::LocalToGlobal(idx,oLoc,oGlo)) return -3; + m->SetTranslation(oGlo); + return 0; +} + +//------------------------------------------------------------- +Int_t AliITSAlignMille2Module::SensVolOrigGlobalMatrix(UShort_t volid, TGeoHMatrix *m) +{ + // set original global matrix for sensitive modules (SPD corrected) + // return 0 if success + Int_t idx=GetIndexFromVolumeID(volid); + if (idx<0) return -1; + TGeoHMatrix mo; + if (!AliGeomManager::GetOrigGlobalMatrix(AliGeomManager::SymName(volid),mo)) return -1; + (*m)=mo; + // +#ifdef CORHW_ + // SPD y-shift by 81 mu + if (volid<5000) { + Double_t oLoc[3]={0.0,0.0081,0.0}; + Double_t oGlo[3]={0,0,0}; + m->LocalToMaster(oLoc,oGlo); + m->SetTranslation(oGlo); + } +#endif + return 0; +} + +//------------------------------------------------------------- +UShort_t AliITSAlignMille2Module::GetVolumeIDFromSymname(const Char_t *symname) { + /// volume ID from symname + if (!symname) return 0; + + for (UShort_t voluid=2000; voluid<13300; voluid++) { + Int_t modId; + AliGeomManager::ELayerID layerId = AliGeomManager::VolUIDToLayer(voluid,modId); + if (layerId>0 && layerId<7 && modId>=0 && modId2197) return 0; + return GetVolumeIDFromSymname(AliITSgeomTGeo::GetSymName(index)); +} + +//------------------------------------------------------------- +void AliITSAlignMille2Module::Print(Option_t*) const +{ + // + const char* typeName[] = {"SPD","SDD","SSD"}; + printf("*** ITS SuperModule for AliITSAlignMille ***\n"); + printf("symname : %s (type: %s)\n",GetName(),fDetType<0 ? "N/A":typeName[fDetType]); + printf("parent : %s | %d children\n",fParent ? fParent->GetName() : "N/A",GetNChildren()); + printf("volumeID : %4d | index : %4d | Geom.Params are %s\n",fVolumeID,fIndex, + GeomParamsGlobal() ? "Global":"Local"); + printf("Factors : X=%.2f Y=%.2f Z=%.2f\n" + "DOF: %cTx:%5d| %cTy:%5d| %cTz:%5d| %cPsi:%5d| %cTheta:%5d| %cPhi:%5d|", + fSigmaFactor[0],fSigmaFactor[1],fSigmaFactor[2], + IsFreeDOF(kDOFTX) ? '+':'-',fParOffs[kDOFTX],IsFreeDOF(kDOFTY) ? '+':'-',fParOffs[kDOFTY], + IsFreeDOF(kDOFTZ) ? '+':'-',fParOffs[kDOFTZ],IsFreeDOF(kDOFPS) ? '+':'-',fParOffs[kDOFPS], + IsFreeDOF(kDOFTH) ? '+':'-',fParOffs[kDOFTH],IsFreeDOF(kDOFPH) ? '+':'-',fParOffs[kDOFPH]); + if (IsSDD()) printf("%cT0:%5d| %cDV:%5d|",IsFreeDOF(kDOFT0)?'+':'-',fParOffs[kDOFT0], + IsFreeDOF(kDOFDV)?'+':'-',fParOffs[kDOFDV]); + printf("\n"); + fMatrix->Print(); + printf("%4d Sensitive volumes | %6d Processed Points\n",fNSensVol,fNProcPoints); + for (Int_t i=0; iGetAlignableEntry(GetName())!=0; +} + +//------------------------------------------------------------- +void AliITSAlignMille2Module::GetLocalMatrix(TGeoHMatrix &mat) const +{ + // return the local matrix for transformation to its parent + mat = *fMatrix; + if (fParent) mat.MultiplyLeft( &fParent->GetMatrix()->Inverse() ); +} + +//------------------------------------------------------------- +void AliITSAlignMille2Module::AssignDetType() +{ + TString tp = GetName(); + if (tp.Contains("SPD",TString::kIgnoreCase)) fDetType = kSPD; + else if (tp.Contains("SDD",TString::kIgnoreCase)) fDetType = kSDD; + else if (tp.Contains("SSD",TString::kIgnoreCase)) fDetType = kSSD; + else fDetType = -1; + fNParTot = IsSDD() ? 8:6; + fNParFree = 0; + fParVals = new Float_t[fNParTot]; + fParErrs = new Float_t[fNParTot]; + fParCstr = new Float_t[fNParTot]; + if (fParOffs.GetSize()MultiplyLeft( &fMatrix->Inverse() ); + fgTempAlignObj.SetMatrix(*fSensVolMatrix); + fgTempAlignObj.GetPars(t,r); +} + +//------------------------------------------------------------- +void AliITSAlignMille2Module::GetSensVolGlobalParams(UShort_t volid,Double_t* loct,Double_t* locr,Double_t *t, Double_t *r) +{ + // return global parameters of the sensor volid modified by the localDelta params + for (int i=3;i--;) t[i] = r[i] = 0.; + if (SensVolMatrix(volid,fSensVolMatrix)) return; + fgTempAlignObj.SetTranslation(loct[0],loct[1],loct[2]); + fgTempAlignObj.SetRotation(locr[0],locr[1],locr[2]); + // + fgTempAlignObj.GetMatrix(*fSensVolModifMatrix); // obtain local delta + fSensVolModifMatrix->MultiplyLeft( fSensVolMatrix ); // obtain global delta + fgTempAlignObj.SetMatrix(*fSensVolModifMatrix); + fgTempAlignObj.GetPars(t,r); // obtain global params +} + +//------------------------------------------------------------- +void AliITSAlignMille2Module::GetSensVolLocalParams(UShort_t volid,Double_t* loct,Double_t* locr,Double_t *t, Double_t *r) +{ + // return parameters of the sensor volid (modified by the localDelta params) in the current volume + for (int i=3;i--;) t[i] = r[i] = 0.; + if (SensVolMatrix(volid,fSensVolMatrix)) return; + fgTempAlignObj.SetTranslation(loct[0],loct[1],loct[2]); + fgTempAlignObj.SetRotation(locr[0],locr[1],locr[2]); + // + fgTempAlignObj.GetMatrix(*fSensVolModifMatrix); // obtain local delta + fSensVolModifMatrix->MultiplyLeft( fSensVolMatrix ); // obtain global delta + fSensVolModifMatrix->MultiplyLeft( &fMatrix->Inverse() ); // obtain delta in current volume + fgTempAlignObj.SetMatrix(*fSensVolModifMatrix); + fgTempAlignObj.GetPars(t,r); // obtain params +} + +//------------------------------------------------------------- +void AliITSAlignMille2Module::SetParVals(Double_t *vl,Int_t npar) +{ + for (int i=TMath::Min(npar,(Int_t)fNParTot);i--;) fParVals[i] = vl[i]; +} + +//------------------------------------------------------------- +void AliITSAlignMille2Module::GetGeomParamsGlo(Double_t *pars) +{ + // recompute parameters from local to global frame + // + // is there anything to do? + if (GeomParamsGlobal()) {for (int i=kMaxParGeom;i--;) pars[i] = fParVals[i]; return;} + // + // IMPORTANT: It is assumed that the parents params are defined in a same way (local or global) + // as for the current module. Since in the mp2 the modules are stored from parents to children, + // it is safe to call this method in loop staring from the lowest level child, i.e. from the end + // of the modules array. + // + // DeltaGlobal = (ModifParents)*DeltaLocal*(ModifParents)^-1 + // + *fSensVolMatrix = *fMatrix; // current global matrix + AliITSAlignMille2Module* parent = GetParent(); + while (parent) { + if (parent->GeomParamsGlobal()) { + AliError("Cannot convert params to Global when the parents are already Global\n"); + for (int i=kMaxParGeom;i--;) pars[i] = 0; + return; + } + fSensVolMatrix->MultiplyLeft( &parent->GetMatrix()->Inverse() ); // Local Matrix + Float_t *parpar = parent->GetParVals(); + fgTempAlignObj.SetTranslation(parpar[0],parpar[1],parpar[2]); + fgTempAlignObj.SetRotation(parpar[3],parpar[4],parpar[5]); + fgTempAlignObj.GetMatrix(*fSensVolModifMatrix); + fSensVolMatrix->MultiplyLeft(fSensVolModifMatrix); + fSensVolMatrix->MultiplyLeft(parent->GetMatrix()); // global matrix after parents modifications + parent = parent->GetParent(); + } + // + fgTempAlignObj.SetTranslation(fParVals[0],fParVals[1],fParVals[2]); + fgTempAlignObj.SetRotation(fParVals[3],fParVals[4],fParVals[5]); + fgTempAlignObj.GetMatrix(*fSensVolModifMatrix); // local delta matrix + fSensVolModifMatrix->Multiply( &fSensVolMatrix->Inverse() ); + fSensVolModifMatrix->MultiplyLeft( fSensVolMatrix ); + fgTempAlignObj.SetMatrix( *fSensVolModifMatrix ); // global delta matrix + fgTempAlignObj.GetPars(pars,pars+3); + // +} + +//------------------------------------------------------------- +void AliITSAlignMille2Module::GetGeomParamsLoc(Double_t *pars) +{ + // recompute parameters from global to local frame + // + // is there anything to do? + if (!GeomParamsGlobal()) {for (int i=kMaxParGeom;i--;) pars[i] = fParVals[i]; return;} + // + // IMPORTANT: It is assumed that the parents params are defined in a same way (local or global) + // as for the current module. Since in the mp2 the modules are stored from parents to children, + // it is safe to call this method in loop staring from the lowest level child, i.e. from the end + // of the modules array. + // + // DeltaLocal = (DeltaParents*GlobalMat)^-1*DeltaGlobal*(DeltaParents*GlobalMat) + // + AliITSAlignMille2Module* parent = GetParent(); + fgTempAlignObj.SetTranslation(0.,0.,0.); + fgTempAlignObj.SetRotation(0.,0.,0.); + fgTempAlignObj.GetMatrix(*fSensVolMatrix); // get no-shift matrix + // + while (parent) { // accumulate the product of parents global modifications + if (!parent->GeomParamsGlobal()) { + AliError("Cannot convert params to Local when the parents are already Local\n"); + for (int i=kMaxParGeom;i--;) pars[i] = 0; + return; + } + Float_t *parpar = parent->GetParVals(); + fgTempAlignObj.SetTranslation(parpar[0],parpar[1],parpar[2]); + fgTempAlignObj.SetRotation(parpar[3],parpar[4],parpar[5]); + fgTempAlignObj.GetMatrix(*fSensVolModifMatrix); + fSensVolMatrix->Multiply(fSensVolModifMatrix); + parent = parent->GetParent(); + } + // global matrix after parents modifications + fSensVolMatrix->Multiply(fMatrix); + // + fgTempAlignObj.SetTranslation(fParVals[0],fParVals[1],fParVals[2]); + fgTempAlignObj.SetRotation(fParVals[3],fParVals[4],fParVals[5]); + fgTempAlignObj.GetMatrix(*fSensVolModifMatrix); // global delta matrix + fSensVolModifMatrix->MultiplyLeft( &fSensVolMatrix->Inverse() ); + fSensVolModifMatrix->Multiply( fSensVolMatrix ); + fgTempAlignObj.SetMatrix( *fSensVolModifMatrix ); // local delta matrix + fgTempAlignObj.GetPars(pars,pars+3); + // +} + +//------------------------------------------------------------- +void AliITSAlignMille2Module::CalcDerivGloLoc(Int_t idx,Double_t *deriv) +{ + // calculate derivative of global params vs local param idx: deriv[j] = dParGlo[j]/dParLoc[idx] + Double_t lpar[kMaxParGeom]; + for (int i=kMaxParGeom;i--;) lpar[i] = 0.; + // using f(x+h),f(x-h),f(x+h/2),f(x-h2)... + Double_t par1[kMaxParGeom]; // f(x-h) + Double_t par2[kMaxParGeom]; // f(x-h/2) + Double_t par3[kMaxParGeom]; // f(x+h/2) + Double_t par4[kMaxParGeom]; // f(x+h) + // + const Double_t dpar = 1e-3; + // + // first values + lpar[idx] -= dpar; + GetGlobalParams(lpar,lpar+3, par1,par1+3); + // + // second values + lpar[idx] += dpar/2; + GetGlobalParams(lpar,lpar+3, par2,par2+3); + // + // third values + lpar[idx] += dpar; + GetGlobalParams(lpar,lpar+3, par3,par3+3); + // + // fourth values + lpar[idx] += dpar/2; + GetGlobalParams(lpar,lpar+3, par4,par4+3); + // + Double_t h2 = 1./(2.*dpar); + for (int i=kMaxParGeom;i--;) { + Double_t d0 = par4[i]-par1[i]; + Double_t d2 = 2.*(par3[i]-par2[i]); + deriv[i] = h2*(4*d2 - d0)/3.; + if (TMath::Abs(deriv[i]) < 1.0e-9) deriv[i] = 0.0; + } + // +} + +//------------------------------------------------------------- +void AliITSAlignMille2Module::CalcDerivLocGlo(Double_t *deriv) +{ + // calculate derivative of local params vs global params: deriv[i][j] = dParLoc[i]/dParGlo[j] + Double_t gpar[kMaxParGeom]; + for (int i=kMaxParGeom;i--;) gpar[i] = 0.; + // using f(x+h),f(x-h),f(x+h/2),f(x-h2)... + Double_t par1[kMaxParGeom]; // f(x-h) + Double_t par2[kMaxParGeom]; // f(x-h/2) + Double_t par3[kMaxParGeom]; // f(x+h/2) + Double_t par4[kMaxParGeom]; // f(x+h) + // + const Double_t dpar = 1e-3; + // + for (int ig=kMaxParGeom;ig--;) { + // first values + gpar[ig] -= dpar; + GetLocalParams(gpar,gpar+3, par1,par1+3); + // + // second values + gpar[ig] += dpar/2; + GetLocalParams(gpar,gpar+3, par2,par2+3); + // + // third values + gpar[ig] += dpar; + GetLocalParams(gpar,gpar+3, par3,par3+3); + // + // fourth values + gpar[ig] += dpar/2; + GetLocalParams(gpar,gpar+3, par4,par4+3); + // + Double_t h2 = 1./(2.*dpar); + for (int i=kMaxParGeom;i--;) { + Double_t d0 = par4[i]-par1[i]; + Double_t d2 = 2.*(par3[i]-par2[i]); + int idig = i*kMaxParGeom + ig; + deriv[idig] = h2*(4*d2 - d0)/3.; + if (TMath::Abs(deriv[idig]) < 1.0e-9) deriv[idig] = 0.0; + } + } + // +} + +//________________________________________________________________________________________________________ +void AliITSAlignMille2Module::CalcDerivGloLoc(Int_t sensVol,Int_t paridx,Double_t* derivative) +{ + /// calculate numerically the derivatives of global params vs local param paridx for sensor sensVol: dPglob/dPloc_paridx + // + Double_t lpar[kMaxParGeom]; + for (int i=kMaxParGeom;i--;) lpar[i] = 0.; + // using f(x+h),f(x-h),f(x+h/2),f(x-h2)... + Double_t par1[kMaxParGeom]; // f(x-h) + Double_t par2[kMaxParGeom]; // f(x-h/2) + Double_t par3[kMaxParGeom]; // f(x+h/2) + Double_t par4[kMaxParGeom]; // f(x+h) + // + const Double_t dpar = 1e-3; + // + // first values + lpar[paridx] -= dpar; + GetSensVolGlobalParams(sensVol,lpar,lpar+3, par1,par1+3); + // + // second values + lpar[paridx] += dpar/2; + GetSensVolGlobalParams(sensVol,lpar,lpar+3, par2,par2+3); + // + // third values + lpar[paridx] += dpar; + GetSensVolGlobalParams(sensVol,lpar,lpar+3, par3,par3+3); + // + // fourth values + lpar[paridx] += dpar/2; + GetSensVolGlobalParams(sensVol,lpar,lpar+3, par4,par4+3); + // + Double_t h2 = 1./(2.*dpar); + for (int i=kMaxParGeom;i--;) { + Double_t d0 = par4[i]-par1[i]; + Double_t d2 = 2.*(par3[i]-par2[i]); + derivative[i] = h2*(4*d2 - d0)/3.; + if (TMath::Abs(derivative[i]) < 1.0e-9) derivative[i] = 0.0; + } + // +} + +//________________________________________________________________________________________________________ +void AliITSAlignMille2Module::CalcDerivCurLoc(Int_t sensVol,Int_t paridx,Double_t* derivative) +{ + /// calculate numerically the derivatives of sensor params in the current volume vs sensor local param paridx + // + Double_t lpar[kMaxParGeom]; + for (int i=kMaxParGeom;i--;) lpar[i] = 0.; + // using f(x+h),f(x-h),f(x+h/2),f(x-h2)... + Double_t par1[kMaxParGeom]; // f(x-h) + Double_t par2[kMaxParGeom]; // f(x-h/2) + Double_t par3[kMaxParGeom]; // f(x+h/2) + Double_t par4[kMaxParGeom]; // f(x+h) + // + const Double_t dpar = 1e-3; + // + // first values + lpar[paridx] -= dpar; + GetSensVolLocalParams(sensVol,lpar,lpar+3, par1,par1+3); + // + // second values + lpar[paridx] += dpar/2; + GetSensVolLocalParams(sensVol,lpar,lpar+3, par2,par2+3); + // + // third values + lpar[paridx] += dpar; + GetSensVolLocalParams(sensVol,lpar,lpar+3, par3,par3+3); + // + // fourth values + lpar[paridx] += dpar/2; + GetSensVolLocalParams(sensVol,lpar,lpar+3, par4,par4+3); + // + Double_t h2 = 1./(2.*dpar); + for (int i=kMaxParGeom;i--;) { + Double_t d0 = par4[i]-par1[i]; + Double_t d2 = 2.*(par3[i]-par2[i]); + derivative[i] = h2*(4*d2 - d0)/3.; + if (TMath::Abs(derivative[i]) < 1.0e-9) derivative[i] = 0.0; + } + // +} + + +//------------------------------------------------------------- +void AliITSAlignMille2Module::GetGlobalParams(Double_t *t, Double_t *r) +{ + // global parameters of the module + fgTempAlignObj.SetMatrix( *fMatrix ); + fgTempAlignObj.GetPars(t,r); +} + +//------------------------------------------------------------- +void AliITSAlignMille2Module::GetGlobalParams(const Double_t* loct, const Double_t* locr, Double_t *t, Double_t *r) +{ + // global parameters of the module after the modification by local loct,locr + fgTempAlignObj.SetTranslation(loct[0],loct[1],loct[2]); + fgTempAlignObj.SetRotation(locr[0],locr[1],locr[2]); + fgTempAlignObj.GetMatrix(*fSensVolModifMatrix); + *fSensVolMatrix = *fMatrix; + fSensVolMatrix->Multiply(fSensVolModifMatrix); + fgTempAlignObj.SetMatrix(*fSensVolMatrix); + fgTempAlignObj.GetPars(t,r); +} + +//------------------------------------------------------------- +void AliITSAlignMille2Module::GetLocalParams(const Double_t* glot, const Double_t* glor, Double_t *t, Double_t *r) +{ + // obtain local delta parameters from global delta params + fgTempAlignObj.SetTranslation(glot[0],glot[1],glot[2]); + fgTempAlignObj.SetRotation(glor[0],glor[1],glor[2]); + fgTempAlignObj.GetMatrix(*fSensVolMatrix); + fSensVolMatrix->Multiply( fMatrix ); + fSensVolMatrix->MultiplyLeft( &fMatrix->Inverse() ); + fgTempAlignObj.SetMatrix(*fSensVolMatrix); + fgTempAlignObj.GetPars(t,r); +} + diff --git a/ITS/AliITSAlignMille2Module.h b/ITS/AliITSAlignMille2Module.h index 7758fe8d08b..39adb77c443 100644 --- a/ITS/AliITSAlignMille2Module.h +++ b/ITS/AliITSAlignMille2Module.h @@ -18,6 +18,7 @@ #include #include #include +#include class AliITSAlignMille2; class AliAlignObjParams; @@ -26,6 +27,10 @@ class TGeoHMatrix; class AliITSAlignMille2Module : public TNamed { public: + enum {kSPD,kSDD,kSSD}; + enum {kMaxParGeom=6,kMaxParTot=8,kSensDefBit=0,kGlobalGeomBit=1}; + enum {kDOFTX,kDOFTY,kDOFTZ,kDOFPS,kDOFTH,kDOFPH,kDOFT0,kDOFDV}; + // AliITSAlignMille2Module(); AliITSAlignMille2Module(UShort_t volid); AliITSAlignMille2Module(Int_t index, UShort_t volid, char* symname, TGeoHMatrix *m, Int_t nsv=0, UShort_t *volidsv=NULL); @@ -48,15 +53,39 @@ public: Float_t GetSigmaYFactor() const {return fSigmaFactor[1];} Float_t GetSigmaZFactor() const {return fSigmaFactor[2];} Int_t GetNProcessedPoints() const {return fNProcPoints;} - Bool_t IsFreeDOF(Int_t dof) const {return TestBit(1<0;} + Bool_t AreSensorsProvided() const {return TestBit(1<<(kSensDefBit+1));} + Bool_t GeomParamsGlobal() const {return TestBit(1<<(kGlobalGeomBit+1));} Bool_t IsIn(UShort_t volid) const; Bool_t IsAlignable() const; Bool_t BelongsTo(AliITSAlignMille2Module* parent) const; AliITSAlignMille2Module* GetParent() const {return fParent;} + AliITSAlignMille2Module* GetChild(Int_t i) const {return (AliITSAlignMille2Module*)fChildren[i];} + Int_t GetNChildren() const {return fChildren.GetLast()+1;} + // void Print(Option_t* opt="") const; // + void EvaluateDOF(); + UShort_t GetNParTot() const {return fNParTot;} + UShort_t GetNParFree() const {return fNParFree;} + Float_t *GetParVals() const {return fParVals;} + Double_t GetParVal(int par) const {return fParVals[par];} + Double_t GetParErr(int par) const {return fParErrs[par];} + Double_t GetParConstraint(int par) const {return fParCstr[par];} + Int_t GetParOffset(Int_t par) const {return fParOffs[par];} + Int_t GetDetType() const {return fDetType;} + Bool_t IsParConstrained(Int_t par) const {return fParCstr[par]>0 && fParCstr[par]0. ? s:0.0;} void SetSigmaFactor(Int_t i,Float_t v) {fSigmaFactor[i]=v;} void SetSigmaXFactor(Float_t v) {fSigmaFactor[0]=v;} void SetSigmaYFactor(Float_t v) {fSigmaFactor[1]=v;} @@ -64,12 +93,18 @@ public: void IncNProcessedPoints(Int_t step=1) {fNProcPoints += step;} void SetNProcessedPoints(Int_t v) {fNProcPoints = v;} void SetParent(AliITSAlignMille2Module* par) {fParent = par;} - void SetFreeDOF(Int_t dof,Bool_t free=kTRUE) {SetBit(1<