CMS 3D CMS Logo

LASBarrelAlgorithm.cc

Go to the documentation of this file.
00001 
00002 
00003 #include "Alignment/LaserAlignment/src/LASBarrelAlgorithm.h"
00004 
00005 
00006 // this is ugly but we need it for Minuit
00007 // until a better solution is at hand
00008 LASGlobalData<LASCoordinateSet>* aMeasuredCoordinates;
00009 LASGlobalData<LASCoordinateSet>* aNominalCoordinates;
00010 
00011 
00012 
00013 
00014 
00018 LASBarrelAlgorithm::LASBarrelAlgorithm() {
00019 
00020   minuit = new TMinuit( 52 );
00021   
00022 }
00023 
00024 
00025 
00026 
00027 
00033 LASBarrelAlignmentParameterSet LASBarrelAlgorithm::CalculateParameters( LASGlobalData<LASCoordinateSet>& measuredCoordinates,
00034                                                                         LASGlobalData<LASCoordinateSet>& nominalCoordinates   ) {
00035   
00036   std::cout << " [LASBarrelAlgorithm::CalculateParameters] -- Starting." << std::endl;
00037 
00038 
00040   // for testing..
00041   ReadMisalignmentFromFile( "misalign-var.txt", measuredCoordinates, nominalCoordinates );
00043     
00044 
00045   // statics for minuit
00046   aMeasuredCoordinates = &measuredCoordinates;
00047   aNominalCoordinates  = &nominalCoordinates;
00048 
00049   // minimizer and variables for it
00050   minuit->SetFCN( fcn );
00051   double arglist[10];
00052   int _ierflg = 0;
00053 
00054   // toggle minuit blabla
00055   arglist[0] = -1;
00056   minuit->mnexcm( "SET PRI", arglist, 1, _ierflg );
00057 
00058   // set par errors
00059   arglist[0] = 1;
00060   minuit->mnexcm( "SET ERR", arglist ,1, _ierflg );
00061 
00062 
00063   //
00064   // define 52 parameters
00065   //
00066 
00067   // start values: to be evacuated to cfg
00068   static float _vstart[52] = {
00069     0.00, 0.00, 0.0, 0.0, 0.0, 0.0, // subdet for TIB+
00070     0.00, 0.00, 0.0, 0.0, 0.0, 0.0, // subdet for TIB-
00071     0.00, 0.00, 0.0, 0.0, 0.0, 0.0, // subdet for TOB+
00072     0.00, 0.00, 0.0, 0.0, 0.0, 0.0, // subdet for TOB-
00073     0.00, 0.00, 0.0, 0.0, 0.0, 0.0, // subdet for TEC+
00074     0.00, 0.00, 0.0, 0.0, 0.0, 0.0, // subdet for TEC-
00075     0.00, 0.00,  0.00, 0.00,  0.00, 0.00,  0.00, 0.00, // beams 0-3
00076     0.00, 0.00,  0.00, 0.00,  0.00, 0.00,  0.00, 0.00  // beams 4-7
00077   };
00078 
00079 
00081   // ReadStartParametersFromFile( "startParameters.txt", _vstart ); // debug
00083 
00084 
00085   // step sizes: to be tuned, to be evacuated to cfg
00086   static float _vstep[52] = { 
00087     0.0001, 0.0001, 0.1, 0.1, 0.1, 0.1, // subdet for TIB+
00088     0.0001, 0.0001, 0.1, 0.1, 0.1, 0.1, // subdet for TIB-
00089     0.0001, 0.0001, 0.1, 0.1, 0.1, 0.1, // subdet for TOB+
00090     0.0001, 0.0001, 0.1, 0.1, 0.1, 0.1, // subdet for TOB-
00091     0.0001, 0.0001, 0.1, 0.1, 0.1, 0.1, // subdet for TEC+
00092     0.0001, 0.0001, 0.1, 0.1, 0.1, 0.1, // subdet for TEC-
00093     0.0001, 0.0001,  0.0001, 0.0001,  0.0001, 0.0001,  0.0001, 0.0001, // beams 0-3
00094     0.0001, 0.0001,  0.0001, 0.0001,  0.1000, 0.0001,  0.0001, 0.0001  // beams 4-7
00095   };
00096 
00097 
00098   // subdetector parameters for TIB+:
00099 
00100   // rotation around z of first end face 
00101   minuit->mnparm(  0, "subRot1TIB+",      _vstart[0],  _vstep[0],  0, 0, _ierflg );
00102   // rotation around z of second end face
00103   minuit->mnparm(  1, "subRot2TIB+",      _vstart[1],  _vstep[1],  0, 0, _ierflg );
00104   // translation along x of first end face
00105   minuit->mnparm(  2, "subTransX1TIB+",   _vstart[2],  _vstep[2],  0, 0, _ierflg );
00106   // translation along x of second end face
00107   minuit->mnparm(  3, "subTransX2TIB+",   _vstart[3],  _vstep[3],  0, 0, _ierflg );
00108   // translation along y of first end face
00109   minuit->mnparm(  4, "subTransY1TIB+",   _vstart[4],  _vstep[4],  0, 0, _ierflg );
00110   // translation along y of second  end face
00111   minuit->mnparm(  5, "subTransY2TIB+",   _vstart[5],  _vstep[5],  0, 0, _ierflg );
00112 
00113   // subdetector parameters for TIB-:
00114 
00115   // rotation around z of first end face 
00116   minuit->mnparm(  6, "subRot1TIB-",      _vstart[6],  _vstep[6],  0, 0, _ierflg );
00117   // rotation around z of second end face
00118   minuit->mnparm(  7, "subRot2TIB-",      _vstart[7],  _vstep[7],  0, 0, _ierflg );
00119   // translation along x of first end face
00120   minuit->mnparm(  8, "subTransX1TIB-",   _vstart[8],  _vstep[8],  0, 0, _ierflg );
00121   // translation along x of second end face
00122   minuit->mnparm(  9, "subTransX2TIB-",   _vstart[9],  _vstep[9],  0, 0, _ierflg );
00123   // translation along y of first end face
00124   minuit->mnparm( 10, "subTransY1TIB-",   _vstart[10], _vstep[10], 0, 0, _ierflg );
00125   // translation along y of second  end face
00126   minuit->mnparm( 11, "subTransY2TIB-",   _vstart[11], _vstep[11], 0, 0, _ierflg );
00127 
00128   // subdetector parameters for TOB+:
00129 
00130   // rotation around z of first end face 
00131   minuit->mnparm( 12, "subRot1TOB+",      _vstart[12], _vstep[12], 0, 0, _ierflg );
00132   // rotation around z of second end face
00133   minuit->mnparm( 13, "subRot2TOB+",      _vstart[13], _vstep[13], 0, 0, _ierflg );
00134   // translation along x of first end face
00135   minuit->mnparm( 14, "subTransX1TOB+",   _vstart[14], _vstep[14], 0, 0, _ierflg );
00136   // translation along x of second end face
00137   minuit->mnparm( 15, "subTransX2TOB+",   _vstart[15], _vstep[15], 0, 0, _ierflg );
00138   // translation along y of first end face
00139   minuit->mnparm( 16, "subTransY1TOB+",   _vstart[16], _vstep[16], 0, 0, _ierflg );
00140   // translation along y of second  end face
00141   minuit->mnparm( 17, "subTransY2TOB+",   _vstart[17], _vstep[17], 0, 0, _ierflg );
00142 
00143   // subdetector parameters for TOB-:
00144 
00145   // rotation around z of first end face 
00146   minuit->mnparm( 18, "subRot1TOB-",      _vstart[18], _vstep[18], 0, 0, _ierflg );
00147   // rotation around z of second end face
00148   minuit->mnparm( 19, "subRot2TOB-",      _vstart[19], _vstep[19], 0, 0, _ierflg );
00149   // translation along x of first end face
00150   minuit->mnparm( 20, "subTransX1TOB-",   _vstart[20], _vstep[20], 0, 0, _ierflg );
00151   // translation along x of second end face
00152   minuit->mnparm( 21, "subTransX2TOB-",   _vstart[21], _vstep[21], 0, 0, _ierflg );
00153   // translation along y of first end face
00154   minuit->mnparm( 22, "subTransY1TOB-",   _vstart[22], _vstep[22], 0, 0, _ierflg );
00155   // translation along y of second  end face
00156   minuit->mnparm( 23, "subTransY2TOB-",   _vstart[23], _vstep[23], 0, 0, _ierflg );
00157 
00158   // subdetector parameters for TEC+:
00159 
00160   // rotation around z of first end face 
00161   minuit->mnparm( 24, "subRot1TEC+",      _vstart[24], _vstep[24], 0, 0, _ierflg );
00162   // rotation around z of second end face
00163   minuit->mnparm( 25, "subRot2TEC+",      _vstart[25], _vstep[25], 0, 0, _ierflg );
00164   // translation along x of first end face
00165   minuit->mnparm( 26, "subTransX1TEC+",   _vstart[26], _vstep[26], 0, 0, _ierflg );
00166   // translation along x of second end face
00167   minuit->mnparm( 27, "subTransX2TEC+",   _vstart[27], _vstep[27], 0, 0, _ierflg );
00168   // translation along y of first end face
00169   minuit->mnparm( 28, "subTransY1TEC+",   _vstart[28], _vstep[28], 0, 0, _ierflg );
00170   // translation along y of second  end face
00171   minuit->mnparm( 29, "subTransY2TEC+",   _vstart[29], _vstep[29], 0, 0, _ierflg );
00172 
00173   // subdetector parameters for TEC-:
00174 
00175   // rotation around z of first end face 
00176   minuit->mnparm( 30, "subRot1TEC-",      _vstart[30], _vstep[30], 0, 0, _ierflg );
00177   // rotation around z of second end face
00178   minuit->mnparm( 31, "subRot2TEC-",      _vstart[31], _vstep[31], 0, 0, _ierflg );
00179   // translation along x of first end face
00180   minuit->mnparm( 32, "subTransX1TEC-",   _vstart[32], _vstep[32], 0, 0, _ierflg );
00181   // translation along x of second end face
00182   minuit->mnparm( 33, "subTransX2TEC-",   _vstart[33], _vstep[33], 0, 0, _ierflg );
00183   // translation along y of first end face
00184   minuit->mnparm( 34, "subTransY1TEC-",   _vstart[34], _vstep[34], 0, 0, _ierflg );
00185   // translation along y of second  end face
00186   minuit->mnparm( 35, "subTransY2TEC-",   _vstart[35], _vstep[35], 0, 0, _ierflg );
00187 
00188 
00189   // beam parameters (+-z pairs, duplicated for beams 0-7):
00190 
00191   // rotation around z at zt1
00192   minuit->mnparm( 36, "beamRot1Beam0",    _vstart[36],  _vstep[36], 0, 0, _ierflg );
00193   // rotation around z at zt2
00194   minuit->mnparm( 37, "beamRot2Beam0",    _vstart[37],  _vstep[37], 0, 0, _ierflg );
00195   
00196   // rotation around z at zt1
00197   minuit->mnparm( 38, "beamRot1Beam1",    _vstart[38],  _vstep[38], 0, 0, _ierflg );
00198   // rotation around z at zt2
00199   minuit->mnparm( 39, "beamRot2Beam1",    _vstart[39],  _vstep[39], 0, 0, _ierflg );
00200 
00201   // rotation around z at zt1
00202   minuit->mnparm( 40, "beamRot1Beam2",    _vstart[40],  _vstep[40], 0, 0, _ierflg );
00203   // rotation around z at zt2
00204   minuit->mnparm( 41, "beamRot2Beam2",    _vstart[41],  _vstep[41], 0, 0, _ierflg );
00205 
00206   // rotation around z at zt1
00207   minuit->mnparm( 42, "beamRot1Beam3",    _vstart[42],  _vstep[42], 0, 0, _ierflg );
00208   // rotation around z at zt2
00209   minuit->mnparm( 43, "beamRot2Beam3",    _vstart[43],  _vstep[43], 0, 0, _ierflg );
00210 
00211   // rotation around z at zt1
00212   minuit->mnparm( 44, "beamRot1Beam4",    _vstart[44],  _vstep[44], 0, 0, _ierflg );
00213   // rotation around z at zt2
00214   minuit->mnparm( 45, "beamRot2Beam4",    _vstart[45],  _vstep[45], 0, 0, _ierflg );
00215   
00216   // rotation around z at zt1
00217   minuit->mnparm( 46, "beamRot1Beam5",    _vstart[46],  _vstep[46], 0, 0, _ierflg );
00218   // rotation around z at zt2
00219   minuit->mnparm( 47, "beamRot2Beam5",    _vstart[47],  _vstep[47], 0, 0, _ierflg );
00220 
00221   // rotation around z at zt1
00222   minuit->mnparm( 48, "beamRot1Beam6",    _vstart[48],  _vstep[48], 0, 0, _ierflg );
00223   // rotation around z at zt2
00224   minuit->mnparm( 49, "beamRot2Beam6",    _vstart[49],  _vstep[49], 0, 0, _ierflg );
00225 
00226   // rotation around z at zt1
00227   minuit->mnparm( 50, "beamRot1Beam7",    _vstart[50],  _vstep[50], 0, 0, _ierflg );
00228   // rotation around z at zt2
00229   minuit->mnparm( 51, "beamRot2Beam7",    _vstart[51],  _vstep[51], 0, 0, _ierflg );
00230 
00231 
00232   // we fix the respective outer disks 9 of each endcap
00233   // as a reference system (pars 25,27,29 & 30,32,34)
00234   // note: minuit numbering is fortran style...
00235   arglist[0] = 26; arglist[1] = 28; arglist[2] = 30;
00236   minuit->mnexcm( "FIX", arglist ,3, _ierflg ); // TEC+
00237   arglist[0] = 31; arglist[1] = 33; arglist[2] = 35;
00238   minuit->mnexcm( "FIX", arglist ,3, _ierflg ); // TEC-
00239 
00240 
00242   // DEBUG: FIX BEAM PARAMETERS /////////////////////////////////////////////////////////////////////
00243 //   double parlist[16];
00244 //   for( int par = 37; par <= 52; ++par ) parlist[par-37] = par;
00245 //   minuit->mnexcm( "FIX", parlist ,16, _ierflg );
00247 
00248 
00249   // now ready for minimization step
00250   arglist[0] = 5000;
00251   arglist[1] = 0.01;
00252   minuit->mnexcm( "MIGRAD", arglist , 2, _ierflg );
00253 
00254   Dump();
00255 
00256   // now fill the result vector.
00257   // turned out that the parameter numbering is stupid, change this later..
00258   LASBarrelAlignmentParameterSet theResult;
00259   double par = 0., parError = 0.;
00260 
00261   // TEC+ rot
00262   minuit->GetParameter( 24, par, parError ); theResult.GetParameter( 0, 0, 0 ).first = par; theResult.GetParameter( 0, 0, 0 ).second = parError;
00263   minuit->GetParameter( 25, par, parError ); theResult.GetParameter( 0, 1, 0 ).first = par; theResult.GetParameter( 0, 1, 0 ).second = parError;
00264   // TEC+ x
00265   minuit->GetParameter( 26, par, parError ); theResult.GetParameter( 0, 0, 1 ).first = par; theResult.GetParameter( 0, 0, 1 ).second = parError;
00266   minuit->GetParameter( 27, par, parError ); theResult.GetParameter( 0, 1, 1 ).first = par; theResult.GetParameter( 0, 1, 1 ).second = parError;
00267   // TEC+ x
00268   minuit->GetParameter( 28, par, parError ); theResult.GetParameter( 0, 0, 2 ).first = par; theResult.GetParameter( 0, 0, 2 ).second = parError;
00269   minuit->GetParameter( 29, par, parError ); theResult.GetParameter( 0, 1, 2 ).first = par; theResult.GetParameter( 0, 1, 2 ).second = parError;
00270 
00271   // TEC- rot
00272   minuit->GetParameter( 30, par, parError ); theResult.GetParameter( 1, 0, 0 ).first = par; theResult.GetParameter( 1, 0, 0 ).second = parError;
00273   minuit->GetParameter( 31, par, parError ); theResult.GetParameter( 1, 1, 0 ).first = par; theResult.GetParameter( 1, 1, 0 ).second = parError;
00274   // TEC- x
00275   minuit->GetParameter( 32, par, parError ); theResult.GetParameter( 1, 0, 1 ).first = par; theResult.GetParameter( 1, 0, 1 ).second = parError;
00276   minuit->GetParameter( 33, par, parError ); theResult.GetParameter( 1, 1, 1 ).first = par; theResult.GetParameter( 1, 1, 1 ).second = parError;
00277   // TEC- x
00278   minuit->GetParameter( 34, par, parError ); theResult.GetParameter( 1, 0, 2 ).first = par; theResult.GetParameter( 1, 0, 2 ).second = parError;
00279   minuit->GetParameter( 35, par, parError ); theResult.GetParameter( 1, 1, 2 ).first = par; theResult.GetParameter( 1, 1, 2 ).second = parError;
00280 
00281   // TIB+ rot
00282   minuit->GetParameter(  0, par, parError ); theResult.GetParameter( 2, 0, 0 ).first = par; theResult.GetParameter( 2, 0, 0 ).second = parError;
00283   minuit->GetParameter(  1, par, parError ); theResult.GetParameter( 2, 1, 0 ).first = par; theResult.GetParameter( 2, 1, 0 ).second = parError;
00284   // TIB+ x
00285   minuit->GetParameter(  2, par, parError ); theResult.GetParameter( 2, 0, 1 ).first = par; theResult.GetParameter( 2, 0, 1 ).second = parError;
00286   minuit->GetParameter(  3, par, parError ); theResult.GetParameter( 2, 1, 1 ).first = par; theResult.GetParameter( 2, 1, 1 ).second = parError;
00287   // TIB+ x
00288   minuit->GetParameter(  4, par, parError ); theResult.GetParameter( 2, 0, 2 ).first = par; theResult.GetParameter( 2, 0, 2 ).second = parError;
00289   minuit->GetParameter(  5, par, parError ); theResult.GetParameter( 2, 1, 2 ).first = par; theResult.GetParameter( 2, 1, 2 ).second = parError;
00290 
00291   // TIB- rot
00292   minuit->GetParameter(  6, par, parError ); theResult.GetParameter( 3, 0, 0 ).first = par; theResult.GetParameter( 3, 0, 0 ).second = parError;
00293   minuit->GetParameter(  7, par, parError ); theResult.GetParameter( 3, 1, 0 ).first = par; theResult.GetParameter( 3, 1, 0 ).second = parError;
00294   // TIB- x
00295   minuit->GetParameter(  8, par, parError ); theResult.GetParameter( 3, 0, 1 ).first = par; theResult.GetParameter( 3, 0, 1 ).second = parError;
00296   minuit->GetParameter(  9, par, parError ); theResult.GetParameter( 3, 1, 1 ).first = par; theResult.GetParameter( 3, 1, 1 ).second = parError;
00297   // TIB- x
00298   minuit->GetParameter( 10, par, parError ); theResult.GetParameter( 3, 0, 2 ).first = par; theResult.GetParameter( 3, 0, 2 ).second = parError;
00299   minuit->GetParameter( 11, par, parError ); theResult.GetParameter( 3, 1, 2 ).first = par; theResult.GetParameter( 3, 1, 2 ).second = parError;
00300 
00301   // TOB+ rot
00302   minuit->GetParameter( 12, par, parError ); theResult.GetParameter( 4, 0, 0 ).first = par; theResult.GetParameter( 4, 0, 0 ).second = parError;
00303   minuit->GetParameter( 13, par, parError ); theResult.GetParameter( 4, 1, 0 ).first = par; theResult.GetParameter( 4, 1, 0 ).second = parError;
00304   // TOB+ x
00305   minuit->GetParameter( 14, par, parError ); theResult.GetParameter( 4, 0, 1 ).first = par; theResult.GetParameter( 4, 0, 1 ).second = parError;
00306   minuit->GetParameter( 15, par, parError ); theResult.GetParameter( 4, 1, 1 ).first = par; theResult.GetParameter( 4, 1, 1 ).second = parError;
00307   // TOB+ x
00308   minuit->GetParameter( 16, par, parError ); theResult.GetParameter( 4, 0, 2 ).first = par; theResult.GetParameter( 4, 0, 2 ).second = parError;
00309   minuit->GetParameter( 17, par, parError ); theResult.GetParameter( 4, 1, 2 ).first = par; theResult.GetParameter( 4, 1, 2 ).second = parError;
00310 
00311   // TOB- rot
00312   minuit->GetParameter( 18, par, parError ); theResult.GetParameter( 5, 0, 0 ).first = par; theResult.GetParameter( 5, 0, 0 ).second = parError;
00313   minuit->GetParameter( 19, par, parError ); theResult.GetParameter( 5, 1, 0 ).first = par; theResult.GetParameter( 5, 1, 0 ).second = parError;
00314   // TOB- x
00315   minuit->GetParameter( 20, par, parError ); theResult.GetParameter( 5, 0, 1 ).first = par; theResult.GetParameter( 5, 0, 1 ).second = parError;
00316   minuit->GetParameter( 21, par, parError ); theResult.GetParameter( 5, 1, 1 ).first = par; theResult.GetParameter( 5, 1, 1 ).second = parError;
00317   // TOB- x
00318   minuit->GetParameter( 22, par, parError ); theResult.GetParameter( 5, 0, 2 ).first = par; theResult.GetParameter( 5, 0, 2 ).second = parError;
00319   minuit->GetParameter( 23, par, parError ); theResult.GetParameter( 5, 1, 2 ).first = par; theResult.GetParameter( 5, 1, 2 ).second = parError;
00320 
00321   std::cout << " [LASBarrelAlgorithm::CalculateParameters] -- Done." << std::endl;
00322 
00323   return theResult;
00324 
00325 }
00326 
00327 
00328 
00329 
00330 
00334 void fcn( int &npar, double *gin, double &f, double *par, int iflag )  {
00335 
00336   double chisquare = 0.;
00337 
00338   // the loop object and its variables
00339   LASGlobalLoop moduleLoop;
00340   int det, beam, pos, disk;
00341 
00343   // ADJUST THIS ALSO IN LASGeometryUpdater
00345 
00346   // the z positions of the halfbarrel_end_faces / outer_TEC_disks (in mm);
00347   // parameters are: det, side(0=+/1=-), z(lower/upper). TECs have no side (use side = 0)
00348   std::vector<std::vector<std::vector<double> > > endFaceZPositions( 4, std::vector<std::vector<double> >( 2, std::vector<double>( 2, 0. ) ) );
00349   endFaceZPositions.at( 0 ).at( 0 ).at( 0 ) = 1250.;  // TEC+, *, disk1 ///
00350   endFaceZPositions.at( 0 ).at( 0 ).at( 1 ) = 2595.;  // TEC+, *, disk9 /// SIDE INFORMATION
00351   endFaceZPositions.at( 1 ).at( 0 ).at( 0 ) = -2595.; // TEC-, *, disk1 /// MEANINGLESS FOR TEC -> USE .at(0)!
00352   endFaceZPositions.at( 1 ).at( 0 ).at( 1 ) = -1250.; // TEC-, *, disk9 ///
00353   endFaceZPositions.at( 2 ).at( 1 ).at( 0 ) = -700.;  // TIB,  -, small z
00354   endFaceZPositions.at( 2 ).at( 1 ).at( 1 ) = -300.;  // TIB,  -, large z
00355   endFaceZPositions.at( 2 ).at( 0 ).at( 0 ) = 300.;   // TIB,  +, small z
00356   endFaceZPositions.at( 2 ).at( 0 ).at( 1 ) = 700.;   // TIB,  +, large z
00357   endFaceZPositions.at( 3 ).at( 1 ).at( 0 ) = -1090.; // TOB,  -, small z
00358   endFaceZPositions.at( 3 ).at( 1 ).at( 1 ) = -300.;  // TOB,  -, large z
00359   endFaceZPositions.at( 3 ).at( 0 ).at( 0 ) = 300.;   // TOB,  +, small z
00360   endFaceZPositions.at( 3 ).at( 0 ).at( 1 ) = 1090.;  // TOB,  +, large z
00361 
00362   // the z positions of the TEC outer disks (9) in mm
00363   // (in priciple one could also use the above vector set here, but it's more compact)
00364   std::vector<double> disk9EndFaceZPositions( 2, 0. );
00365   disk9EndFaceZPositions.at( 0 ) = -2595.; // TEC- disk9
00366   disk9EndFaceZPositions.at( 1 ) =  2595.; // TEC+ disk9
00367 
00368   // reduced z positions of the beam spots ( z'_{k,j}, z"_{k,j} )
00369   double detReducedZ[2] = { 0., 0. };
00370   // reduced beam splitter positions ( zt'_{k,j}, zt"_{k,j} )
00371   double beamReducedZ[2] = { 0., 0. };
00372 
00373   // calculate residual for TIBTOB
00374   det = 2; beam = 0; pos = 0;
00375   do {
00376 
00377     // define the side: 0 for TIB+/TOB+ and 1 for TIB-/TOB-
00378     const int theSide = pos<3 ? 0 : 1;
00379     
00380     // reduced module's z position with respect to the subdetector endfaces
00381     detReducedZ[0] = aMeasuredCoordinates->GetTIBTOBEntry( det, beam, pos ).GetZ() - endFaceZPositions.at( det ).at( theSide ).at( 0 );
00382     detReducedZ[0] /= ( endFaceZPositions.at( det ).at( theSide ).at( 1 ) - endFaceZPositions.at( det ).at( theSide ).at( 0 ) );
00383     detReducedZ[1] = endFaceZPositions.at( det ).at( theSide ).at( 1 ) - aMeasuredCoordinates->GetTIBTOBEntry( det, beam, pos ).GetZ();
00384     detReducedZ[1] /= ( endFaceZPositions.at( det ).at( theSide ).at( 1 ) - endFaceZPositions.at( det ).at( theSide ).at( 0 ) );
00385 
00386     // reduced module's z position with respect to the tec disks +-9 (for the beam parameters)
00387     beamReducedZ[0] = aMeasuredCoordinates->GetTIBTOBEntry( det, beam, pos ).GetZ() - disk9EndFaceZPositions.at( 0 );
00388     beamReducedZ[0] /= ( disk9EndFaceZPositions.at( 1 ) - disk9EndFaceZPositions.at( 0 ) );
00389     beamReducedZ[1] = disk9EndFaceZPositions.at( 1 ) - aMeasuredCoordinates->GetTIBTOBEntry( det, beam, pos ).GetZ();
00390     beamReducedZ[1] /= ( disk9EndFaceZPositions.at( 1 ) - disk9EndFaceZPositions.at( 0 ) );
00391 
00392     // phi residual for this module as measured
00393     const double measuredResidual = aMeasuredCoordinates->GetTIBTOBEntry( det, beam, pos ).GetPhi() - //&
00394       aNominalCoordinates->GetTIBTOBEntry( det, beam, pos ).GetPhi();
00395 
00396     // shortcuts for speed
00397     const double currentPhi = aNominalCoordinates->GetTIBTOBEntry( det, beam, pos ).GetPhi();
00398     const double currentR   = aNominalCoordinates->GetTIBTOBEntry( det, beam, pos ).GetR();
00399 
00400     // phi residual for this module calculated from the parameters and nominal coordinates:
00401     // this is the sum over the contributions from all parameters
00402     double calculatedResidual = 0.;
00403 
00404     // note that the contributions ym_{i,j,k} given in the tables in TkLasATModel TWiki
00405     // are defined as R*phi, so here they are divided by the R_j factors (we minimize delta phi)
00406 
00407     // unfortunately, minuit keeps parameters in a 1-dim array,
00408     // so we need to address the correct par[] for the 4 cases TIB+/TIB-/TOB+/TOB-
00409     int indexBase = 0;
00410     if( det == 2 ) { // TIB
00411       if( theSide == 0 ) indexBase = 0; // TIB+
00412       if( theSide == 1 ) indexBase = 6; // TIB-
00413     }
00414     if( det == 3 ) { // TOB
00415       if( theSide == 0 ) indexBase = 12; // TOB+
00416       if( theSide == 1 ) indexBase = 18; // TOB-
00417     }
00418 
00419     // par[0] ("subRot1"): rotation around z of first end face
00420     calculatedResidual += detReducedZ[1] * par[indexBase+0];
00421     
00422     // par[1] ("subRot2"): rotation around z of second end face
00423     calculatedResidual += detReducedZ[0] * par[indexBase+1];
00424     
00425     // par[2] ("subTransX1"): translation along x of first end face
00426     calculatedResidual += detReducedZ[1] * sin( currentPhi ) / currentR * par[indexBase+2];
00427 
00428     // par[3] ("subTransX2"): translation along x of second end face
00429     calculatedResidual += detReducedZ[0] * sin( currentPhi ) / currentR * par[indexBase+3];
00430 
00431     // par[4] ("subTransY1"): translation along y of first end face
00432     calculatedResidual += -1. * detReducedZ[1] * cos( currentPhi ) / currentR * par[indexBase+4];
00433 
00434     // par[5] ("subTransY2"): translation along y of second end face
00435     calculatedResidual += -1. * detReducedZ[0] * cos( currentPhi ) / currentR * par[indexBase+5];
00436 
00437 
00438     // now come the 8*2 beam parameters, calculate the respective parameter index base first (-> which beam)
00439     indexBase = 36 + beam * 2;
00440 
00441     // (there's no TIB/TOB/+/- distinction here for the beams)
00442 
00443     // ("beamRot1"): rotation around z at zt1
00444     calculatedResidual += beamReducedZ[1] * par[indexBase];
00445 
00446     // ("beamRot2"): rotation around z at zt2
00447     calculatedResidual +=  beamReducedZ[0] * par[indexBase+1];
00448  
00449 
00450     // now calculate the chisquare
00451     chisquare += pow( measuredResidual - calculatedResidual, 2 ) / pow( aMeasuredCoordinates->GetTIBTOBEntry( det, beam, pos ).GetPhiError(), 2 );
00452 
00453   } while( moduleLoop.TIBTOBLoop( det, beam, pos ) );
00454 
00455  
00456 
00457 
00458 
00459   // calculate residual for TEC AT
00460   det = 0; beam = 0; disk = 0;
00461   do {
00462     
00463     // define the side: TECs sides already disentangled by the "det" index, so fix this to zero
00464     const int theSide = 0;
00465     
00466     // reduced module's z position with respect to the subdetector endfaces
00467     detReducedZ[0] = aMeasuredCoordinates->GetTEC2TECEntry( det, beam, disk ).GetZ() - endFaceZPositions.at( det ).at( theSide ).at( 0 );
00468     detReducedZ[0] /= ( endFaceZPositions.at( det ).at( theSide ).at( 1 ) - endFaceZPositions.at( det ).at( theSide ).at( 0 ) );
00469     detReducedZ[1] = endFaceZPositions.at( det ).at( theSide ).at( 1 ) - aMeasuredCoordinates->GetTEC2TECEntry( det, beam, disk ).GetZ();
00470     detReducedZ[1] /= ( endFaceZPositions.at( det ).at( theSide ).at( 1 ) - endFaceZPositions.at( det ).at( theSide ).at( 0 ) );
00471 
00472     // reduced module's z position with respect to the tec disks +-9 (for the beam parameters)
00473     beamReducedZ[0] = aMeasuredCoordinates->GetTEC2TECEntry( det, beam, disk ).GetZ() - disk9EndFaceZPositions.at( 0 );
00474     beamReducedZ[0] /= ( disk9EndFaceZPositions.at( 1 ) - disk9EndFaceZPositions.at( 0 ) );
00475     beamReducedZ[1] = disk9EndFaceZPositions.at( 1 ) - aMeasuredCoordinates->GetTEC2TECEntry( det, beam, disk ).GetZ();
00476     beamReducedZ[1] /= ( disk9EndFaceZPositions.at( 1 ) - disk9EndFaceZPositions.at( 0 ) );
00477 
00478     // phi residual for this module as measured
00479     const double measuredResidual = aMeasuredCoordinates->GetTEC2TECEntry( det, beam, disk ).GetPhi() - //&
00480       aNominalCoordinates->GetTEC2TECEntry( det, beam, disk ).GetPhi();
00481 
00482     // shortcuts for speed
00483     const double currentPhi = aNominalCoordinates->GetTEC2TECEntry( det, beam, disk ).GetPhi();
00484     const double currentR   = aNominalCoordinates->GetTEC2TECEntry( det, beam, disk ).GetR();
00485 
00486     // phi residual for this module calculated from the parameters and nominal coordinates:
00487     // this is the sum over the contributions from all parameters
00488     double calculatedResidual = 0.;
00489 
00490     // note that the contributions ym_{i,j,k} given in the tables in TkLasATModel TWiki
00491     // are defined as R*phi, so here they are divided by the R_j factors (we minimize delta phi)
00492 
00493     // there's also a distinction between TEC+/- parameters in situ (det==0 ? <TEC+> : <TEC->)
00494 
00495     // par[0] ("subRot1"): rotation around z of first end face
00496     calculatedResidual += detReducedZ[1] * (det==0 ? par[24] : par[30]);
00497     
00498     // par[1] ("subRot2"): rotation around z of second end face
00499     calculatedResidual += detReducedZ[0] * (det==0 ? par[25] : par[31]);
00500     
00501     // par[2] ("subTransX1"): translation along x of first end face
00502     calculatedResidual += detReducedZ[1] * sin( currentPhi ) * (det==0 ? par[26] : par[32]) / currentR;
00503 
00504     // par[3] ("subTransX2"): translation along x of second end face
00505     calculatedResidual += detReducedZ[0] * sin( currentPhi ) * (det==0 ? par[27] : par[33]) / currentR;
00506 
00507     // par[4] ("subTransY1"): translation along y of first end face
00508     calculatedResidual += -1. * detReducedZ[1] * cos( currentPhi ) * (det==0 ? par[28] : par[34]) / currentR;
00509 
00510     // par[5] ("subTransY2"): translation along y of second end face
00511     calculatedResidual += -1. * detReducedZ[0] * cos( currentPhi ) * (det==0 ? par[29] : par[35]) / currentR;
00512 
00513     // now come the 8*2 beam parameters; calculate the respective parameter index base first (-> which beam)
00514     const unsigned int indexBase = 36 + beam * 2;
00515 
00516     // there's no TEC+/- distinction here
00517 
00518     // par[6] ("beamRot1"): rotation around z at zt1
00519     calculatedResidual += beamReducedZ[1] * par[indexBase];
00520 
00521     // par[7] ("beamRot2"): rotation around z at zt2
00522     calculatedResidual +=  beamReducedZ[0] * par[indexBase+1];
00523  
00524 
00525     // now calculate the chisquare 
00526     // TODO: check for phi != 0 !!!
00527     chisquare += pow( measuredResidual - calculatedResidual, 2 ) / pow( aMeasuredCoordinates->GetTEC2TECEntry( det, beam, disk ).GetPhiError(), 2 );
00528 
00529   } while( moduleLoop.TEC2TECLoop( det, beam, disk ) );
00530 
00531 
00532 
00533   // return the chisquare by ref
00534   f = chisquare;
00535   
00536 }
00537 
00538 
00539 
00540 
00545 void LASBarrelAlgorithm::Dump( void ) {
00546   
00547   if( !minuit ) {
00548     std::cerr << " [LASBarrelAlgorithm::Dump] ** WARNING: minimizer object uninitialized." << std::endl;
00549     return;
00550   }
00551 
00552   std::cout << std::endl << " [LASBarrelAlgorithm::Dump] -- Parameter dump: " << std::endl;
00553 
00554   const int subdetParMap[6] = { 24, 30, 0, 6, 12, 18 }; // map to one-dim array
00555   const std::string subdetNames[6] = { " TEC+  ", " TEC-  ", " TIB+  ", " TIB-  ", " TOB+  ", " TOB-  " };
00556   double value, error;
00557 
00558   std::cout << " Detector parameters: " << std::endl;
00559   std::cout << " -------------------" << std::endl;
00560   std::cout << " Values:     PHI1         X1          Y1         PHI2         X2          Y2   " << std::endl;
00561   for( int subdet = 0; subdet < 6; ++subdet ) {
00562     std::cout <<subdetNames[subdet];
00563     for( int par = subdetParMap[subdet]; par <= subdetParMap[subdet] + 4; par += 2 ) {
00564       minuit->GetParameter( par, value, error );
00565       std::cout << std::setw( 12 ) << std::setprecision( 6 ) << std::fixed << value;
00566     }
00567     for( int par = subdetParMap[subdet] + 1; par <= subdetParMap[subdet] + 5; par += 2 ) {
00568       minuit->GetParameter( par, value, error );
00569       std::cout << std::setw( 12 ) << std::setprecision( 6 ) << std::fixed << value;
00570     }
00571     std::cout << std::endl;
00572   }
00573 
00574   std::cout << " Errors:     PHI1         X1          Y1         PHI2         X2          Y2   " << std::endl;
00575   for( int subdet = 0; subdet < 6; ++subdet ) {
00576     std::cout <<subdetNames[subdet];
00577     for( int par = subdetParMap[subdet]; par <= subdetParMap[subdet] + 4; par += 2 ) {
00578       minuit->GetParameter( par, value, error );
00579       std::cout << std::setw( 12 ) << std::setprecision( 6 ) << std::fixed << error;
00580     }
00581     for( int par = subdetParMap[subdet] + 1; par <= subdetParMap[subdet] + 5; par += 2 ) {
00582       minuit->GetParameter( par, value, error );
00583       std::cout << std::setw( 12 ) << std::setprecision( 6 ) << std::fixed << error;
00584     }
00585     std::cout << std::endl;
00586   }
00587 
00588   std::cout << std::endl;
00589   std::cout << " Beam parameters: " << std::endl;
00590   std::cout << " ---------------" << std::endl;
00591   std::cout << " Values:  PHI1        PHI2" << std::endl;
00592   for( int beam = 0; beam < 8; ++beam ) {
00593     std::cout << " " << beam << "  ";
00594     for( int z = 0; z < 2; ++z ) {
00595       minuit->GetParameter( 36 + beam + z, value, error );
00596       std::cout << std::setw( 12 ) << std::setprecision( 6 ) << std::fixed << value;
00597     }
00598     std::cout << std::endl;
00599   }  
00600 
00601   std::cout << " Errors:  PHI1        PHI2" << std::endl;
00602   for( int beam = 0; beam < 8; ++beam ) {
00603     std::cout << " " << beam << "  ";
00604     for( int z = 0; z < 2; ++z ) {
00605       minuit->GetParameter( 36 + beam + z, value, error );
00606       std::cout << std::setw( 12 ) << std::setprecision( 6 ) << std::fixed << error;
00607     }
00608     std::cout << std::endl;
00609   }
00610 
00611 
00612 
00613   // det parameters once again without leading column (for easy read-in), into a file
00614   ofstream file( "/afs/cern.ch/user/o/olzem/public/parameters_det.txt" );
00615   for( int subdet = 0; subdet < 6; ++subdet ) {
00616     for( int par = subdetParMap[subdet]; par <= subdetParMap[subdet] + 4; par += 2 ) {
00617       minuit->GetParameter( par, value, error );
00618       file << std::setw( 12 ) << std::setprecision( 6 ) << std::fixed << value;
00619     }
00620     for( int par = subdetParMap[subdet] + 1; par <= subdetParMap[subdet] + 5; par += 2 ) {
00621       minuit->GetParameter( par, value, error );
00622       file << std::setw( 12 ) << std::setprecision( 6 ) << std::fixed << value;
00623     }
00624     file << std::endl;
00625   }
00626   file.close();
00627 
00628   // same for beam parameters
00629   file.open( "/afs/cern.ch/user/o/olzem/public/parameters_beam.txt" );
00630   for( int beam = 0; beam < 8; ++beam ) {
00631     for( int z = 0; z < 2; ++z ) {
00632       minuit->GetParameter( 36 + beam + z, value, error );
00633       file << std::setw( 12 ) << std::setprecision( 6 ) << std::fixed << value;
00634     }
00635     file << std::endl;
00636   }  
00637   file.close();
00638 
00639 
00640   std:: cout << " [LASBarrelAlgorithm::Dump] -- End parameter dump." << std::endl;
00641   std::cout << std::endl;
00642 
00643 }
00644 
00645 
00646 
00647 
00648 
00658 void LASBarrelAlgorithm::ReadMisalignmentFromFile( const char* filename, 
00659                                                    LASGlobalData<LASCoordinateSet>& measuredCoordinates,
00660                                                    LASGlobalData<LASCoordinateSet>& nominalCoordinates  ) {
00661 
00662   ifstream file( filename );
00663   if( file.bad() ) {
00664     std::cerr << " [LASBarrelAlgorithm::ReadMisalignmentFromFile] ** ERROR: cannot open file \"" << filename << "\"." << std::endl;
00665     return;
00666   }
00667 
00668   std::cerr << " @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" << std::endl;
00669   std::cerr << " @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" << std::endl;
00670   std::cerr << " [LASBarrelAlgorithm::ReadMisalignmentFromFile] ** WARNING: you are reading a fake measurement from a file!" << std::endl;
00671   std::cerr << " @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" << std::endl;
00672   std::cerr << " @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" << std::endl;
00673 
00674 
00675   // the measured coordinates will finally be overwritten;
00676   // first, set them to the nominal values
00677   measuredCoordinates = nominalCoordinates;
00678 
00679   // and put large errors on all values;
00680   {
00681     LASGlobalLoop moduleLoop;
00682     int det, ring, beam, disk, pos;
00683     
00684     det = 0; ring = 0; beam = 0; disk = 0;
00685     do {
00686       measuredCoordinates.GetTECEntry( det, ring, beam, disk ).SetPhiError( 1000. );
00687     } while( moduleLoop.TECLoop( det, ring, beam, disk ) );
00688     
00689     det = 2; beam = 0; pos = 0;
00690     do {
00691       measuredCoordinates.GetTIBTOBEntry( det, beam, pos ).SetPhiError( 1000. );
00692     } while( moduleLoop.TIBTOBLoop( det, beam, pos  ) );
00693     
00694     det = 0; beam = 0; disk = 0;
00695     do {
00696       measuredCoordinates.GetTEC2TECEntry( det, beam, disk ).SetPhiError( 1000. );
00697     } while( moduleLoop.TEC2TECLoop( det, beam, disk ) );
00698   }
00699 
00700 
00701   // buffers for read-in
00702   int det, beam, z, ring;
00703   double phi, phiError;
00704 
00705   while( !file.eof() ) {
00706 
00707     file >> det;
00708     if( file.eof() ) break; // do not read the last line twice, do not fill trash if file empty
00709 
00710     file >> beam; file >> z; file >> ring;
00711     file >> phi; file >> phiError;
00712 
00713     if( det > 1 ) { // TIB/TOB
00714       measuredCoordinates.GetTIBTOBEntry( det, beam, z ).SetPhi( phi );
00715       measuredCoordinates.GetTIBTOBEntry( det, beam, z ).SetPhiError( phiError );
00716     } else { // TEC or TEC(at)
00717       if( ring > -1 ) { // TEC
00718         measuredCoordinates.GetTECEntry( det, ring, beam, z ).SetPhi( phi );
00719         measuredCoordinates.GetTECEntry( det, ring, beam, z ).SetPhiError( phiError );
00720       }
00721       else { // TEC(at)
00722         measuredCoordinates.GetTEC2TECEntry( det, beam, z ).SetPhi( phi );
00723         measuredCoordinates.GetTEC2TECEntry( det, beam, z ).SetPhiError( phiError );
00724       }
00725     }
00726 
00727   }
00728   
00729   file.close();
00730 
00731 }
00732 
00733 
00734 
00735 
00736 
00745 void LASBarrelAlgorithm::ReadStartParametersFromFile( const char* filename, float values[52] ) {
00746   
00747   ifstream file( filename );
00748   if( file.bad() ) {
00749     std::cerr << " [LASBarrelAlgorithm::ReadStartParametersFromFile] ** ERROR: cannot open file \"" << filename << "\"." << std::endl;
00750     return;
00751   }
00752 
00753   std::cerr << " @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" << std::endl;
00754   std::cerr << " @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" << std::endl;
00755   std::cerr << " [LASBarrelAlgorithm::ReadStartParametersFrom File] ** WARNING: you are reading parameter start values from a file!" << std::endl;
00756   std::cerr << " @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" << std::endl;
00757   std::cerr << " @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" << std::endl;
00758 
00759   // map to the minuit par array
00760   const int subdetParMap[6] = { 24, 30, 0, 6, 12, 18 };
00761   
00762   for( int det = 0; det < 6; ++det ) {
00763     file >> values[subdetParMap[det]];   // phi1
00764     file >> values[subdetParMap[det]+2]; // x1
00765     file >> values[subdetParMap[det]+4]; // y1
00766     file >> values[subdetParMap[det]+1]; // phi2
00767     file >> values[subdetParMap[det]+3]; // x2
00768     file >> values[subdetParMap[det]+5]; // y2
00769   }
00770   
00771 }

Generated on Tue Jun 9 17:24:08 2009 for CMSSW by  doxygen 1.5.4