]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - EMCAL/AliEMCALSurvey.cxx
chi2, mean and rms checks for input samples for fitting
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALSurvey.cxx
index 7bba70a2d389e156d53cb9b261bb208d586f5617..18aee8b5204f4845c60b8356ff6f5b9a7598bd29 100644 (file)
 // and convert the data into AliAlignObjParams of alignable EMCAL volumes.
 // AliEMCALSurvey inherits TObject only to use AliLog "functions".
 //
-// This whole thing is just a dummy class with dummy variables until
-// the actual survey points are determined.  For now I assumed that
-// the x,y center and starting z value of each supermodule is the only
-// surveyed point
+// Dummy functions originally written before EMCAL installation and
+// survey are kept for backward compatibility, but now they are not
+// used.
+// Surveyed points on the face of each module are read in from file
+// and converted to position of the center and roll, pitch, yaw angles
+// of each surveyed SM.
 //
 // J.L. Klay - Cal Poly
-// 28-Feb-2008
+// 07-Apr-2010
 //
 
 #include <fstream>
@@ -36,6 +38,7 @@
 #include <TMath.h>
 
 #include "AliSurveyObj.h"
+#include "AliSurveyPoint.h"
 
 #include "AliAlignObjParams.h"
 #include "AliEMCALGeometry.h"
@@ -54,13 +57,15 @@ AliEMCALSurvey::AliEMCALSurvey()
 
 namespace {
 
-  //for now, measurements assumed to be taken at x,y center and
-  //nominal starting z value of each supermodule
+  //Coordinates for each SM described in survey reports
 
   struct AliEMCALSuperModuleCoords {
-    Double_t fX1; //x coordinate of the first supermodule point
-    Double_t fY1; //y coordinate of the first supermodule point
-    Double_t fZ1; //z coordinate of the first supermodule point
+    Double_t fX1; //x coordinate of the center of supermodule
+    Double_t fY1; //y coordinate of the center of supermodule
+    Double_t fZ1; //z coordinate of the center of supermodule
+    Double_t fPhi;  //roll angle (phi) of supermodule
+    Double_t fTheta; //pitch (theta) of supermodule
+    Double_t fPsi;   //yaw (psi) of supermodule
   };
 
 }
@@ -77,40 +82,52 @@ AliEMCALSurvey::AliEMCALSurvey(const TString &txtFileName)
     return;
   }
 
-  std::ifstream inputFile(txtFileName.Data());
-  if (!inputFile) {
-    AliError(("Cannot open the survey file " + txtFileName).Data());
-    return;
-  }
+  AliSurveyObj *s1 = new AliSurveyObj();
+  s1->FillFromLocalFile(txtFileName);
 
-  fNSuperModule = geom->GetNumberOfSuperModules();
+  TObjArray* points = s1->GetData();
 
-  Int_t dummyInt = 0;
-  Double_t *xReal = new Double_t[fNSuperModule];
-  Double_t *yReal = new Double_t[fNSuperModule];
-  Double_t *zReal = new Double_t[fNSuperModule];
-
-  for (Int_t i = 0; i < fNSuperModule; ++i) {
-    if (!inputFile) {
-      AliError("Error while reading input file.");
-      delete [] xReal;
-      delete [] yReal;
-      delete [] zReal;
-      return;
-    }
-    inputFile>>dummyInt>>xReal[i]>>yReal[i]>>zReal[i];
-  }
+  fNSuperModule = geom->GetNumberOfSuperModules();
 
-  InitSuperModuleData(xReal, yReal, zReal);
+  InitSuperModuleData(points);
+
+  //////////////////////////////////
+  //Old way with dummy survey file
+  //////////////////////////////////
+  //std::ifstream inputFile(txtFileName.Data());
+  //if (!inputFile) {
+  //  AliError(("Cannot open the survey file " + txtFileName).Data());
+  //  return;
+  //}
+  //
+  //Int_t dummyInt = 0;
+  //Double_t *xReal = new Double_t[fNSuperModule];
+  //Double_t *yReal = new Double_t[fNSuperModule];
+  //Double_t *zReal = new Double_t[fNSuperModule];
+  //
+  //for (Int_t i = 0; i < fNSuperModule; ++i) {
+  //  if (!inputFile) {
+  //    AliError("Error while reading input file.");
+  //    delete [] xReal;
+  //    delete [] yReal;
+  //    delete [] zReal;
+  //    return;
+  //  }
+  //  inputFile>>dummyInt>>xReal[i]>>yReal[i]>>zReal[i];
+  //}
+  //
+  //InitSuperModuleData(xReal, yReal, zReal);
+  //
+  //delete [] xReal;
+  //delete [] yReal;
+  //delete [] zReal;
 
-  delete [] xReal;
-  delete [] yReal;
-  delete [] zReal;
 }
 
 //____________________________________________________________________________
 AliEMCALSurvey::~AliEMCALSurvey()
 {
+  //destructor
   delete [] fSuperModuleData;
 }
 
@@ -149,6 +166,7 @@ void AliEMCALSurvey::CreateAliAlignObjParams(TClonesArray &array)
                        false
                        );
     ++arrayInd;
+
   }
 
 }
@@ -184,9 +202,153 @@ AliEMCALSurvey::AliEMCALSuperModuleDelta AliEMCALSurvey::GetSuperModuleTransform
 }
 
 //____________________________________________________________________________
-void AliEMCALSurvey::InitSuperModuleData(const Double_t *xReal, const Double_t *yReal, const Double_t *zReal)
+void AliEMCALSurvey::InitSuperModuleData(const TObjArray *svypts)
 {
+  //This method uses the data points from the actual EMCAL survey to
+  //create the alignment matrices.  Only valid for measured(installed)
+  //SM, others will have null objects
+  
+  
+  AliEMCALGeometry *geom = AliEMCALGeometry::GetInstance();
+  //Center of supermodules
+  Float_t *pars = geom->GetSuperModulesPars();
+  Double_t rpos = (geom->GetEnvelop(0) + geom->GetEnvelop(1))/2.;
+  Double_t phi, phiRad, xpos, ypos, zpos;
+
+  AliEMCALSuperModuleCoords *idealSM = new AliEMCALSuperModuleCoords[fNSuperModule];
+  for (Int_t smodnum = 0; smodnum < geom->GetNumberOfSuperModules(); ++smodnum) {
+    AliEMCALSuperModuleCoords &smc = idealSM[smodnum];
+    phiRad = geom->GetPhiCenterOfSM(smodnum); //comes in radians
+    phi = phiRad*180./TMath::Pi(); //need degrees for AliAlignObjParams
+    xpos = rpos * TMath::Cos(phiRad);
+    ypos = rpos * TMath::Sin(phiRad);
+    zpos = pars[2];
+    if(geom->GetKey110DEG() && smodnum >= 10) {
+      xpos += (pars[1]/2. * TMath::Sin(phiRad));
+      ypos -= (pars[1]/2. * TMath::Cos(phiRad));
+    }
+    smc.fX1 = xpos;
+    smc.fY1 = ypos;
+    smc.fPhi = phi; //degrees
+    smc.fTheta = 0.; //degrees
+    smc.fPsi = 0.; //degrees
+    if(smodnum%2==0) {
+      smc.fZ1 = zpos;
+    } else {
+      smc.fZ1 = -zpos;
+    }
+
+    printf("PHI OF IDEAL SM = %.2f\n",smc.fPhi);
+
+  }
+
+  //Real coordinates of center and rotation angles need to be computed
+  //from survey points
+
+  char substr[100];
+  AliEMCALSuperModuleCoords *realSM = new AliEMCALSuperModuleCoords[fNSuperModule];
+  for (Int_t smodnum = 0; smodnum < geom->GetNumberOfSuperModules(); ++smodnum) {
+    AliEMCALSuperModuleCoords &smc = realSM[smodnum];
+    zpos = pars[2]; //center of SM in z from geometry
+
+    sprintf(substr,"4096%d",smodnum);
+    //retrieve components of four face points and determine average position of center
+    //in x,y,z
+
+    std::vector<Double_t> xval;
+    std::vector<Double_t> yval;
+    std::vector<Double_t> zval;
+    
+    for(Int_t i = 0; i < svypts->GetEntries(); i++) {
+      AliSurveyPoint* pt = (AliSurveyPoint*)svypts->At(i);
+      TString ptname = pt->GetPointName();
+      if(ptname.Contains(substr)) {
+       xval.push_back(pt->GetX()*100.); //convert m to cm
+       yval.push_back(pt->GetY()*100.); 
+       zval.push_back(pt->GetZ()*100.); 
+      }
+    }
+
+    //Take average of all relevant pairs of points
+    Double_t xReal = ((xval[1]+xval[7])/2.      //4X02 and 4X08
+                    + (xval[2]+xval[6])/2.      //4X03 and 4X07
+                    + (xval[3]+xval[5])/2.      //4X04 and 4X06
+                   + (xval[2]+xval[4])/2.)/4.; //4X03 and 4X05
+    Double_t yReal = ((yval[1]+yval[7])/2.      //4X02 and 4X08
+                    + (yval[2]+yval[6])/2.      //4X03 and 4X07
+                    + (yval[3]+yval[5])/2.      //4X04 and 4X06
+                   + (yval[2]+yval[4])/2.)/4.; //4X03 and 4X05
+    smc.fX1 = xReal;
+    smc.fY1 = yReal;
+
+    //Find average value of z for front face of SM
+    Double_t zReal = 0.;
+    Int_t nPoints = zval.size();
+    for(Int_t iz = 0; iz < nPoints; iz++) {
+      zReal += zval[iz];
+    }
+    if(nPoints > 0) zReal = zReal/nPoints;
+
+    if(smodnum%2==0) {
+      smc.fZ1 = zReal-zpos;  //z measured is along end,
+    } else {                 //convert to middle of SM
+      smc.fZ1 = zReal+zpos;
+    }
+
+    Double_t roll = ( TMath::ATan((yval[5]-yval[3])/(xval[5]-xval[3])) //4X04 and 4X06
+                     + TMath::ATan((yval[4]-yval[2])/(xval[4]-xval[2])) )/2.; //4X05 and 4X03
+    smc.fPhi = 90. + roll*TMath::RadToDeg();
+
+    //Note pitch calc only uses first 8 values, even though 10 are
+    //measured on the topmost modules
+    Double_t pitch = ( TMath::ATan((zval[0]-zval[1])/(yval[1]-yval[0])) //4X01 and 4X02
+                      + TMath::ATan((zval[2]-zval[3])/(yval[3]-yval[2])) //4X03 and 4X04
+                      + TMath::ATan((zval[4]-zval[5])/(yval[5]-yval[4])) //4X05 and 4X06
+                      + TMath::ATan((zval[6]-zval[7])/(yval[7]-yval[6])) )/4.; //4X07 and 4X08
+    smc.fTheta = 0. + pitch*TMath::RadToDeg();
+
+    Double_t yaw = ( TMath::ATan((zval[3]-zval[5])/(xval[5]-xval[3])) //4X04 and 4X06
+                    + TMath::ATan((zval[2]-zval[4])/(xval[4]-xval[2])) //4X03 and 4X05
+                    + TMath::ATan((zval[1]-zval[7])/(xval[7]-xval[1])) //4X02 and 4X08
+                    + TMath::ATan((zval[0]-zval[6])/(xval[6]-xval[0])) )/4.; //4X01 and 4X07
+    smc.fPsi = 0. + yaw*TMath::RadToDeg();
+
+  }//loop over supermodules
+  
+  fSuperModuleData = new AliEMCALSuperModuleDelta[fNSuperModule];
+  
+  for (Int_t i = 0; i < fNSuperModule; ++i) {
+    const AliEMCALSuperModuleCoords &real = realSM[i];
+    const AliEMCALSuperModuleCoords &ideal = idealSM[i];
+    AliEMCALSuperModuleDelta &t = fSuperModuleData[i];
+    t.fXShift = real.fX1 - ideal.fX1;
+    t.fYShift = real.fY1 - ideal.fY1;
+    t.fZShift = real.fZ1 - ideal.fZ1;
+    t.fPhi = real.fPhi - ideal.fPhi;
+    t.fTheta = real.fTheta - ideal.fTheta;
+    t.fPsi = real.fPsi - ideal.fPsi;
+
+    printf("===================== SM %d =======================\n",i);
+    printf("real x (%.2f) - ideal x (%.2f) = shift in x (%.2f)\n",real.fX1,ideal.fX1,t.fXShift);
+    printf("real y (%.2f) - ideal y (%.2f) = shift in y (%.2f)\n",real.fY1,ideal.fY1,t.fYShift);
+    printf("real z (%.2f) - ideal z (%.2f) = shift in z (%.2f)\n",real.fZ1,ideal.fZ1,t.fZShift);
+    printf("real theta (%.2f) - ideal theta (%.2f) = shift in theta %.2f\n",real.fTheta,ideal.fTheta,t.fTheta);
+    printf("real psi (%.2f) - ideal psi (%.2f) = shift in psi %.2f\n",real.fPsi,ideal.fPsi,t.fPsi);
+    printf("real phi (%.2f) - ideal phi (%.2f) = shift in phi %.2f\n",real.fPhi,ideal.fPhi,t.fPhi);
+    printf("===================================================\n");    
+  }
 
+  delete [] realSM;
+  delete [] idealSM;
+}
+
+
+//____________________________________________________________________________
+void AliEMCALSurvey::InitSuperModuleData(const Double_t *xReal, const Double_t *yReal, const Double_t *zReal)
+{
+  ///////////////////////////////////////
+  //Old dummy file way of doing it
+  //////////////////////////////////////
   AliEMCALGeometry *geom = AliEMCALGeometry::GetInstance();
   //Center of supermodules
   Float_t *pars = geom->GetSuperModulesPars();
@@ -244,8 +406,17 @@ void AliEMCALSurvey::InitSuperModuleData(const Double_t *xReal, const Double_t *
     t.fYShift = real.fY1 - ideal.fY1;
     t.fZShift = real.fZ1 - ideal.fZ1;
 
+    printf("===================== SM %d =======================\n",i);
+    printf("real x (%.2f) - ideal x (%.2f) = shift in x (%.2f)\n",real.fX1,ideal.fX1,t.fXShift);
+    printf("real y (%.2f) - ideal y (%.2f) = shift in y (%.2f)\n",real.fY1,ideal.fY1,t.fYShift);
+    printf("real z (%.2f) - ideal z (%.2f) = shift in z (%.2f)\n",real.fZ1,ideal.fZ1,t.fZShift);
+    printf("theta %.2f\n",t.fTheta);
+    printf("psi %.2f\n",t.fPsi);
+    printf("phi %.2f\n",t.fPhi);
+    printf("===================================================\n");    
   }
 
   delete [] realSM;
   delete [] idealSM;
 }
+