CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Classes | Functions
LASBarrelAlgorithm.h File Reference
#include <vector>
#include <cmath>
#include <string>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <TMinuit.h>
#include "Alignment/LaserAlignment/interface/LASBarrelAlignmentParameterSet.h"
#include "Alignment/LaserAlignment/interface/LASCoordinateSet.h"
#include "Alignment/LaserAlignment/interface/LASGlobalData.h"
#include "Alignment/LaserAlignment/interface/LASGlobalLoop.h"

Go to the source code of this file.

Classes

class  LASBarrelAlgorithm
 

Functions

void fcn (int &, double *, double &, double *, int)
 

Function Documentation

void fcn ( int &  npar,
double *  gin,
double &  f,
double *  par,
int  iflag 
)

minuit chisquare func

Definition at line 343 of file LASBarrelAlgorithm.cc.

References funct::cos(), LASCoordinateSet::GetPhi(), LASCoordinateSet::GetPhiError(), LASCoordinateSet::GetR(), LASGlobalData< T >::GetTEC2TECEntry(), LASGlobalData< T >::GetTIBTOBEntry(), LASCoordinateSet::GetZ(), pos, funct::pow(), funct::sin(), LASGlobalLoop::TEC2TECLoop(), and LASGlobalLoop::TIBTOBLoop().

Referenced by LASBarrelAlgorithm::CalculateParameters(), MuonResidualsFitter::dofit(), fftjetcms::fftjet_JetFunctor_parser(), fftjetcms::fftjet_PeakFunctor_parser(), PVFitter::runBXFitter(), and PVFitter::runFitter().

343  {
344 
345  double chisquare = 0.;
346 
347  // the loop object and its variables
348  LASGlobalLoop moduleLoop;
349  int det, beam, pos, disk;
350 
352  // ADJUST THIS ALSO IN LASGeometryUpdater
354 
355  // the z positions of the halfbarrel_end_faces / outer_TEC_disks (in mm);
356  // parameters are: det, side(0=+/1=-), z(lower/upper). TECs have no side (use side = 0)
357  std::vector<std::vector<std::vector<double> > > endFaceZPositions( 4, std::vector<std::vector<double> >( 2, std::vector<double>( 2, 0. ) ) );
358  endFaceZPositions.at( 0 ).at( 0 ).at( 0 ) = 1322.5; // TEC+, *, disk1 ///
359  endFaceZPositions.at( 0 ).at( 0 ).at( 1 ) = 2667.5; // TEC+, *, disk9 /// SIDE INFORMATION
360  endFaceZPositions.at( 1 ).at( 0 ).at( 0 ) = -2667; // TEC-, *, disk1 /// MEANINGLESS FOR TEC -> USE .at(0)!
361  endFaceZPositions.at( 1 ).at( 0 ).at( 1 ) = -1322.5; // TEC-, *, disk9 ///
362  endFaceZPositions.at( 2 ).at( 1 ).at( 0 ) = -700.; // TIB, -, small z
363  endFaceZPositions.at( 2 ).at( 1 ).at( 1 ) = -300.; // TIB, -, large z
364  endFaceZPositions.at( 2 ).at( 0 ).at( 0 ) = 300.; // TIB, +, small z
365  endFaceZPositions.at( 2 ).at( 0 ).at( 1 ) = 700.; // TIB, +, large z
366  endFaceZPositions.at( 3 ).at( 1 ).at( 0 ) = -1090.; // TOB, -, small z
367  endFaceZPositions.at( 3 ).at( 1 ).at( 1 ) = -300.; // TOB, -, large z
368  endFaceZPositions.at( 3 ).at( 0 ).at( 0 ) = 300.; // TOB, +, small z
369  endFaceZPositions.at( 3 ).at( 0 ).at( 1 ) = 1090.; // TOB, +, large z
370 
371  // the z positions of the virtual planes at which the beam parameters are measured
372  std::vector<double> disk9EndFaceZPositions( 2, 0. );
373  disk9EndFaceZPositions.at( 0 ) = -2667.5; // TEC- disk9
374  disk9EndFaceZPositions.at( 1 ) = 2667.5; // TEC+ disk9
375 
376  // reduced z positions of the beam spots ( z'_{k,j}, z"_{k,j} )
377  double detReducedZ[2] = { 0., 0. };
378  // reduced beam splitter positions ( zt'_{k,j}, zt"_{k,j} )
379  double beamReducedZ[2] = { 0., 0. };
380 
381  // calculate residual for TIBTOB
382  det = 2; beam = 0; pos = 0;
383  do {
384 
385  // define the side: 0 for TIB+/TOB+ and 1 for TIB-/TOB-
386  const int theSide = pos<3 ? 0 : 1;
387 
388  // this is the path the beam has to travel radially after being reflected
389  // by the AT mirrors (TIB:50mm, TOB:36mm) -> used for beam parameters
390  const double radialOffset = det==2 ? 50. : 36.;
391 
392  // reduced module's z position with respect to the subdetector endfaces
393  detReducedZ[0] = aMeasuredCoordinates->GetTIBTOBEntry( det, beam, pos ).GetZ() - endFaceZPositions.at( det ).at( theSide ).at( 0 );
394  detReducedZ[0] /= ( endFaceZPositions.at( det ).at( theSide ).at( 1 ) - endFaceZPositions.at( det ).at( theSide ).at( 0 ) );
395  detReducedZ[1] = endFaceZPositions.at( det ).at( theSide ).at( 1 ) - aMeasuredCoordinates->GetTIBTOBEntry( det, beam, pos ).GetZ();
396  detReducedZ[1] /= ( endFaceZPositions.at( det ).at( theSide ).at( 1 ) - endFaceZPositions.at( det ).at( theSide ).at( 0 ) );
397 
398  // reduced module's z position with respect to the tec disks +-9 (for the beam parameters)
399  beamReducedZ[0] = ( aMeasuredCoordinates->GetTIBTOBEntry( det, beam, pos ).GetZ() - radialOffset ) - disk9EndFaceZPositions.at( 0 );
400  beamReducedZ[0] /= ( disk9EndFaceZPositions.at( 1 ) - disk9EndFaceZPositions.at( 0 ) );
401  beamReducedZ[1] = disk9EndFaceZPositions.at( 1 ) - ( aMeasuredCoordinates->GetTIBTOBEntry( det, beam, pos ).GetZ() - radialOffset );
402  beamReducedZ[1] /= ( disk9EndFaceZPositions.at( 1 ) - disk9EndFaceZPositions.at( 0 ) );
403 
404 
405  // phi residual for this module as measured
406  const double measuredResidual = aMeasuredCoordinates->GetTIBTOBEntry( det, beam, pos ).GetPhi() - //&
407  aNominalCoordinates->GetTIBTOBEntry( det, beam, pos ).GetPhi();
408 
409  // shortcuts for speed
410  const double currentPhi = aNominalCoordinates->GetTIBTOBEntry( det, beam, pos ).GetPhi();
411  const double currentR = aNominalCoordinates->GetTIBTOBEntry( det, beam, pos ).GetR();
412 
413  // phi residual for this module calculated from the parameters and nominal coordinates:
414  // this is the sum over the contributions from all parameters
415  double calculatedResidual = 0.;
416 
417  // note that the contributions ym_{i,j,k} given in the tables in TkLasATModel TWiki
418  // are defined as R*phi, so here they are divided by the R_j factors (we minimize delta phi)
419 
420  // unfortunately, minuit keeps parameters in a 1-dim array,
421  // so we need to address the correct par[] for the 4 cases TIB+/TIB-/TOB+/TOB-
422  int indexBase = 0;
423  if( det == 2 ) { // TIB
424  if( theSide == 0 ) indexBase = 0; // TIB+
425  if( theSide == 1 ) indexBase = 6; // TIB-
426  }
427  if( det == 3 ) { // TOB
428  if( theSide == 0 ) indexBase = 12; // TOB+
429  if( theSide == 1 ) indexBase = 18; // TOB-
430  }
431 
432  // par[0] ("subRot1"): rotation around z of first end face
433  calculatedResidual += detReducedZ[1] * par[indexBase+0];
434 
435  // par[1] ("subRot2"): rotation around z of second end face
436  calculatedResidual += detReducedZ[0] * par[indexBase+1];
437 
438  // par[2] ("subTransX1"): translation along x of first end face
439  calculatedResidual += detReducedZ[1] * sin( currentPhi ) / currentR * par[indexBase+2];
440 
441  // par[3] ("subTransX2"): translation along x of second end face
442  calculatedResidual += detReducedZ[0] * sin( currentPhi ) / currentR * par[indexBase+3];
443 
444  // par[4] ("subTransY1"): translation along y of first end face
445  calculatedResidual += -1. * detReducedZ[1] * cos( currentPhi ) / currentR * par[indexBase+4];
446 
447  // par[5] ("subTransY2"): translation along y of second end face
448  calculatedResidual += -1. * detReducedZ[0] * cos( currentPhi ) / currentR * par[indexBase+5];
449 
450 
451  // now come the 8*2 beam parameters, calculate the respective parameter index base first (-> which beam)
452  indexBase = 36 + beam * 2;
453 
454  // (there's no TIB/TOB/+/- distinction here for the beams)
455 
456  // ("beamRot1"): rotation around z at zt1
457  calculatedResidual += beamReducedZ[1] * par[indexBase];
458 
459  // ("beamRot2"): rotation around z at zt2
460  calculatedResidual += beamReducedZ[0] * par[indexBase+1];
461 
462 
463  // now calculate the chisquare
464  chisquare += pow( measuredResidual - calculatedResidual, 2 ) / pow( aMeasuredCoordinates->GetTIBTOBEntry( det, beam, pos ).GetPhiError(), 2 );
465 
466  } while( moduleLoop.TIBTOBLoop( det, beam, pos ) );
467 
468 
469 
470 
471 
472  // calculate residual for TEC AT
473  det = 0; beam = 0; disk = 0;
474  do {
475 
476  // define the side: TECs sides already disentangled by the "det" index, so fix this to zero
477  const int theSide = 0;
478 
479  // reduced module's z position with respect to the subdetector endfaces
480  detReducedZ[0] = aMeasuredCoordinates->GetTEC2TECEntry( det, beam, disk ).GetZ() - endFaceZPositions.at( det ).at( theSide ).at( 0 );
481  detReducedZ[0] /= ( endFaceZPositions.at( det ).at( theSide ).at( 1 ) - endFaceZPositions.at( det ).at( theSide ).at( 0 ) );
482  detReducedZ[1] = endFaceZPositions.at( det ).at( theSide ).at( 1 ) - aMeasuredCoordinates->GetTEC2TECEntry( det, beam, disk ).GetZ();
483  detReducedZ[1] /= ( endFaceZPositions.at( det ).at( theSide ).at( 1 ) - endFaceZPositions.at( det ).at( theSide ).at( 0 ) );
484 
485  // reduced module's z position with respect to the tec disks +-9 (for the beam parameters)
486  beamReducedZ[0] = aMeasuredCoordinates->GetTEC2TECEntry( det, beam, disk ).GetZ() - disk9EndFaceZPositions.at( 0 );
487  beamReducedZ[0] /= ( disk9EndFaceZPositions.at( 1 ) - disk9EndFaceZPositions.at( 0 ) );
488  beamReducedZ[1] = disk9EndFaceZPositions.at( 1 ) - aMeasuredCoordinates->GetTEC2TECEntry( det, beam, disk ).GetZ();
489  beamReducedZ[1] /= ( disk9EndFaceZPositions.at( 1 ) - disk9EndFaceZPositions.at( 0 ) );
490 
491  // phi residual for this module as measured
492  const double measuredResidual = aMeasuredCoordinates->GetTEC2TECEntry( det, beam, disk ).GetPhi() - //&
493  aNominalCoordinates->GetTEC2TECEntry( det, beam, disk ).GetPhi();
494 
495  // shortcuts for speed
496  const double currentPhi = aNominalCoordinates->GetTEC2TECEntry( det, beam, disk ).GetPhi();
497  const double currentR = aNominalCoordinates->GetTEC2TECEntry( det, beam, disk ).GetR();
498 
499  // phi residual for this module calculated from the parameters and nominal coordinates:
500  // this is the sum over the contributions from all parameters
501  double calculatedResidual = 0.;
502 
503  // note that the contributions ym_{i,j,k} given in the tables in TkLasATModel TWiki
504  // are defined as R*phi, so here they are divided by the R_j factors (we minimize delta phi)
505 
506  // there's also a distinction between TEC+/- parameters in situ (det==0 ? <TEC+> : <TEC->)
507 
508  // par[0] ("subRot1"): rotation around z of first end face
509  calculatedResidual += detReducedZ[1] * (det==0 ? par[24] : par[30]);
510 
511  // par[1] ("subRot2"): rotation around z of second end face
512  calculatedResidual += detReducedZ[0] * (det==0 ? par[25] : par[31]);
513 
514  // par[2] ("subTransX1"): translation along x of first end face
515  calculatedResidual += detReducedZ[1] * sin( currentPhi ) * (det==0 ? par[26] : par[32]) / currentR;
516 
517  // par[3] ("subTransX2"): translation along x of second end face
518  calculatedResidual += detReducedZ[0] * sin( currentPhi ) * (det==0 ? par[27] : par[33]) / currentR;
519 
520  // par[4] ("subTransY1"): translation along y of first end face
521  calculatedResidual += -1. * detReducedZ[1] * cos( currentPhi ) * (det==0 ? par[28] : par[34]) / currentR;
522 
523  // par[5] ("subTransY2"): translation along y of second end face
524  calculatedResidual += -1. * detReducedZ[0] * cos( currentPhi ) * (det==0 ? par[29] : par[35]) / currentR;
525 
526  // now come the 8*2 beam parameters; calculate the respective parameter index base first (-> which beam)
527  const unsigned int indexBase = 36 + beam * 2;
528 
529  // there's no TEC+/- distinction here
530 
531  // par[6] ("beamRot1"): rotation around z at zt1
532  calculatedResidual += beamReducedZ[1] * par[indexBase];
533 
534  // par[7] ("beamRot2"): rotation around z at zt2
535  calculatedResidual += beamReducedZ[0] * par[indexBase+1];
536 
537 
538  // now calculate the chisquare
539  // TODO: check for phi != 0 !!!
540  chisquare += pow( measuredResidual - calculatedResidual, 2 ) / pow( aMeasuredCoordinates->GetTEC2TECEntry( det, beam, disk ).GetPhiError(), 2 );
541 
542  } while( moduleLoop.TEC2TECLoop( det, beam, disk ) );
543 
544 
545 
546  // return the chisquare by ref
547  f = chisquare;
548 
549 }
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
LASGlobalData< LASCoordinateSet > * aMeasuredCoordinates
double GetPhi(void) const
LASGlobalData< LASCoordinateSet > * aNominalCoordinates
bool TEC2TECLoop(int &, int &, int &) const
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
double f[11][100]
T & GetTIBTOBEntry(int subdetector, int beam, int tibTobPosition)
T & GetTEC2TECEntry(int subdetector, int beam, int tecDisk)
double GetZ(void) const
bool TIBTOBLoop(int &, int &, int &) const
double GetPhiError(void) const
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
double GetR(void) const
const double par[8 *NPar][4]