CMS 3D CMS Logo

Public Member Functions | Private Types | Private Member Functions | Private Attributes

MillePedeAlignmentAlgorithm Class Reference

#include <MillePedeAlignmentAlgorithm.h>

Inheritance diagram for MillePedeAlignmentAlgorithm:
AlignmentAlgorithmBase

List of all members.

Public Member Functions

virtual void endRun (const EventInfo &eventInfo, const EndRunInfo &runInfo, const edm::EventSetup &setup)
 Run on run products, e.g. TkLAS.
virtual void initialize (const edm::EventSetup &setup, AlignableTracker *tracker, AlignableMuon *muon, AlignableExtras *extras, AlignmentParameterStore *store)
 Call at beginning of job.
 MillePedeAlignmentAlgorithm (const edm::ParameterSet &cfg)
 Constructor.
virtual void run (const edm::EventSetup &setup, const EventInfo &eventInfo)
 Run the algorithm on trajectories and tracks.
virtual void setParametersForRunRange (const RunRange &runrange)
virtual void terminate ()
 Call at end of job.
virtual ~MillePedeAlignmentAlgorithm ()
 Destructor.

Private Types

enum  EModeBit { myMilleBit = 1 << 0, myPedeRunBit = 1 << 1, myPedeSteerBit = 1 << 2, myPedeReadBit = 1 << 3 }
enum  MeasurementDirection { kLocalX = 0, kLocalY }

Private Member Functions

bool addHits (const std::vector< Alignable * > &alis, const std::vector< AlignmentUserVariables * > &mpVars) const
bool addHitStatistics (int fromLoop, const std::string &outFile, const std::vector< std::string > &inFiles) const
void addLasBeam (const EventInfo &eventInfo, const TkFittedLasBeam &lasBeam, const std::vector< TrajectoryStateOnSurface > &tsoses)
void addLaserData (const EventInfo &eventInfo, const TkFittedLasBeamCollection &tkLasBeams, const TsosVectorCollection &tkLasBeamTsoses)
int addMeasurementData (const EventInfo &eventInfo, const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr, unsigned int iHit, AlignmentParameters *&params)
void addMsMeas (const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr, unsigned int iMsMeas)
 adds data from reference trajectory from a specific multiple scattering measurement
void addPxbSurvey (const edm::ParameterSet &pxbSurveyCfg)
 add measurement data from PXB survey
std::pair< unsigned int,
unsigned int > 
addReferenceTrajectory (const EventInfo &eventInfo, const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr)
 fill mille for a trajectory, returning number of x/y hits ([0,0] if 'bad' trajectory)
void addRefTrackData2D (const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr, unsigned int iTrajHit, TMatrixDSym &aHitCovarianceM, TMatrixF &aHitResidualsM, TMatrixF &aLocalDerivativesM)
 adds data from reference trajectory from a specific Hit
void addRefTrackMsMeas1D (const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr, unsigned int iTrajHit, TMatrixDSym &aHitCovarianceM, TMatrixF &aHitResidualsM, TMatrixF &aLocalDerivativesM)
 adds multiple scattering data from reference trajectory from a specific Hit
bool areEmptyParams (const std::vector< Alignable * > &alignables) const
void buildUserVariables (const std::vector< Alignable * > &alignables) const
 add MillePedeVariables for each AlignmentParameters (exception if no parameters...)
int callMille (const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr, unsigned int iTrajHit, const std::vector< int > &globalLabels, const std::vector< float > &globalDerivativesX, const std::vector< float > &globalDerivativesY)
 calls callMille1D or callMille2D
int callMille1D (const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr, unsigned int iTrajHit, const std::vector< int > &globalLabels, const std::vector< float > &globalDerivativesX)
 calls Mille for 1D hits
int callMille2D (const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr, unsigned int iTrajHit, const std::vector< int > &globalLabels, const std::vector< float > &globalDerivativesx, const std::vector< float > &globalDerivativesy)
unsigned int decodeMode (const std::string &mode) const
void diagonalize (TMatrixDSym &aHitCovarianceM, TMatrixF &aLocalDerivativesM, TMatrixF &aHitResidualsM, TMatrixF &theGlobalDerivativesM) const
unsigned int doIO (int loop) const
bool globalDerivativesHierarchy (const EventInfo &eventInfo, const TrajectoryStateOnSurface &tsos, Alignable *ali, const AlignableDetOrUnitPtr &alidet, std::vector< float > &globalDerivativesX, std::vector< float > &globalDerivativesY, std::vector< int > &globalLabels, AlignmentParameters *&lowestParams) const
 recursively adding derivatives and labels, false if problems
bool is2D (const TransientTrackingRecHit::ConstRecHitPointer &recHit) const
 true if hit belongs to 2D detector (currently tracker specific)
bool isMode (unsigned int testMode) const
void makeGlobDerivMatrix (const std::vector< float > &globalDerivativesx, const std::vector< float > &globalDerivativesy, TMatrixF &aGlobalDerivativesM)
bool readFromPede (const edm::ParameterSet &mprespset, bool setUserVars, const RunRange &runrange)
 read pede input defined by 'psetName', flag to create/not create MillePedeVariables

Private Attributes

AlignableNavigatortheAlignableNavigator
std::vector< Alignable * > theAlignables
AlignmentParameterStoretheAlignmentParameterStore
 directory for all kind of files
edm::ParameterSet theConfig
std::string theDir
bool theDoSurveyPixelBarrel
std::vector< float > theFloatBufferX
std::vector< float > theFloatBufferY
std::vector< int > theIntBuffer
double theMaximalCor2D
MilletheMille
unsigned int theMinNumHits
unsigned int theMode
MillePedeMonitortheMonitor
const PedeLabelerBasethePedeLabels
PedeSteererthePedeSteer
TrajectoryFactoryBasetheTrajectoryFactory

Detailed Description

CMSSW interface to pede: produces pede's binary input and steering file(s)

Author:
: Gero Flucke date : October 2006
Revision:
1.32
Date:
2011/02/16 13:11:57

(last update by

Author:
mussgill

)

Definition at line 52 of file MillePedeAlignmentAlgorithm.h.


Member Enumeration Documentation

Enumerator:
myMilleBit 
myPedeRunBit 
myPedeSteerBit 
myPedeReadBit 

Definition at line 173 of file MillePedeAlignmentAlgorithm.h.

                {myMilleBit = 1 << 0, myPedeRunBit = 1 << 1, myPedeSteerBit = 1 << 2,
                 myPedeReadBit = 1 << 3};
Enumerator:
kLocalX 
kLocalY 

Definition at line 84 of file MillePedeAlignmentAlgorithm.h.

{kLocalX = 0, kLocalY};

Constructor & Destructor Documentation

MillePedeAlignmentAlgorithm::MillePedeAlignmentAlgorithm ( const edm::ParameterSet cfg)

Constructor.

Definition at line 78 of file MillePedeAlignmentAlgorithm.cc.

References edm::ParameterSet::getUntrackedParameter(), theConfig, and theDir.

                                                                                   :
  AlignmentAlgorithmBase(cfg), 
  theConfig(cfg), theMode(this->decodeMode(theConfig.getUntrackedParameter<std::string>("mode"))),
  theDir(theConfig.getUntrackedParameter<std::string>("fileDir")),
  theAlignmentParameterStore(0), theAlignables(), theAlignableNavigator(0),
  theMonitor(0), theMille(0), thePedeLabels(0), thePedeSteer(0),
  theTrajectoryFactory(0),
  theMinNumHits(cfg.getParameter<unsigned int>("minNumHits")),
  theMaximalCor2D(cfg.getParameter<double>("max2Dcorrelation"))
{
  if (!theDir.empty() && theDir.find_last_of('/') != theDir.size()-1) theDir += '/';// may need '/'
  edm::LogInfo("Alignment") << "@SUB=MillePedeAlignmentAlgorithm" << "Start in mode '"
                            << theConfig.getUntrackedParameter<std::string>("mode")
                            << "' with output directory '" << theDir << "'.";
}
MillePedeAlignmentAlgorithm::~MillePedeAlignmentAlgorithm ( ) [virtual]

Member Function Documentation

bool MillePedeAlignmentAlgorithm::addHits ( const std::vector< Alignable * > &  alis,
const std::vector< AlignmentUserVariables * > &  mpVars 
) const [private]

Definition at line 733 of file MillePedeAlignmentAlgorithm.cc.

References MillePedeVariables::hitsX(), MillePedeVariables::hitsY(), MillePedeVariables::increaseHitsX(), MillePedeVariables::increaseHitsY(), MillePedeVariables::size(), and AlignmentParameters::userVariables().

Referenced by addHitStatistics().

{
  bool allOk = (mpVars.size() == alis.size());
  std::vector<AlignmentUserVariables*>::const_iterator iUser = mpVars.begin();
  for (std::vector<Alignable*>::const_iterator iAli = alis.begin(); 
       iAli != alis.end() && iUser != mpVars.end(); ++iAli, ++iUser) {
    MillePedeVariables *mpVarNew = dynamic_cast<MillePedeVariables*>(*iUser);
    AlignmentParameters *ps = (*iAli)->alignmentParameters();
    MillePedeVariables *mpVarOld = (ps ? dynamic_cast<MillePedeVariables*>(ps->userVariables()) : 0);
    if (!mpVarNew || !mpVarOld || mpVarOld->size() != mpVarNew->size()) {
      allOk = false;
      continue; // FIXME error etc.?
    }

    mpVarOld->increaseHitsX(mpVarNew->hitsX());
    mpVarOld->increaseHitsY(mpVarNew->hitsY());
  }
  
  return allOk;
}
bool MillePedeAlignmentAlgorithm::addHitStatistics ( int  fromLoop,
const std::string &  outFile,
const std::vector< std::string > &  inFiles 
) const [private]

Definition at line 691 of file MillePedeAlignmentAlgorithm.cc.

References addHits(), i, MillePedeVariablesIORoot::readMillePedeVariables(), theAlignables, and theDir.

Referenced by doIO().

{
  bool allOk = true;
  int ierr = 0;
  MillePedeVariablesIORoot millePedeIO;
  if (inFiles.empty()) {
    const std::vector<AlignmentUserVariables*> mpVars =
      millePedeIO.readMillePedeVariables(theAlignables, outFile.c_str(), fromLoop, ierr);
    if (ierr || !this->addHits(theAlignables, mpVars)) {
      edm::LogError("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::addHitStatistics"
                                 << "Error " << ierr << " reading from " << outFile 
                                 << ", tree " << fromLoop << ", or problems in addHits";
      allOk = false;
    }
    for (std::vector<AlignmentUserVariables*>::const_iterator i = mpVars.begin();
         i != mpVars.end(); ++i){
      delete *i; // clean created objects
    }
  } else {
    for (std::vector<std::string>::const_iterator iFile = inFiles.begin();
         iFile != inFiles.end(); ++iFile) {
      const std::string inFile(theDir + *iFile); 
      const std::vector<AlignmentUserVariables*> mpVars =
        millePedeIO.readMillePedeVariables(theAlignables, inFile.c_str(), fromLoop, ierr);
      if (ierr || !this->addHits(theAlignables, mpVars)) {
        edm::LogError("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::addHitStatistics"
                                   << "Error " << ierr << " reading from " << inFile 
                                   << ", tree " << fromLoop << ", or problems in addHits";
        allOk = false;
      }
      for (std::vector<AlignmentUserVariables*>::const_iterator i = mpVars.begin();
           i != mpVars.end(); ++i) {
        delete *i; // clean created objects
      }
    }
  }

  return allOk;
}
void MillePedeAlignmentAlgorithm::addLasBeam ( const EventInfo eventInfo,
const TkFittedLasBeam lasBeam,
const std::vector< TrajectoryStateOnSurface > &  tsoses 
) [private]

Definition at line 1041 of file MillePedeAlignmentAlgorithm.cc.

References AlignableNavigator::alignableFromDetId(), funct::derivative(), TkFittedLasBeam::derivatives(), Mille::end(), error, TkFittedLasBeam::firstFixedParameter(), TkLasBeam::getBeamId(), TkLasBeam::getData(), SiStripLaserRecHit2D::getDetId(), globalDerivativesHierarchy(), PedeLabelerBase::lasBeamLabel(), SiStripLaserRecHit2D::localPosition(), Mille::mille(), PedeLabelerBase::parameterLabel(), TkFittedLasBeam::parameters(), theAlignableNavigator, theFloatBufferX, theFloatBufferY, theIntBuffer, theMille, thePedeLabels, and PV3DBase< T, PVType, FrameType >::x().

Referenced by addLaserData().

{
  AlignmentParameters *dummyPtr = 0; // for globalDerivativesHierarchy()
  std::vector<float> lasLocalDerivsX; // buffer for local derivatives
  const unsigned int beamLabel = thePedeLabels->lasBeamLabel(lasBeam.getBeamId());// for global par
  
  for (unsigned int iHit = 0; iHit < tsoses.size(); ++iHit) {
    if (!tsoses[iHit].isValid()) continue;
    // clear buffer
    theFloatBufferX.clear();
    theFloatBufferY.clear();
    theIntBuffer.clear();
    lasLocalDerivsX.clear();
    // get alignables and global parameters
    const SiStripLaserRecHit2D &hit = lasBeam.getData()[iHit];
    AlignableDetOrUnitPtr lasAli(theAlignableNavigator->alignableFromDetId(hit.getDetId()));
    this->globalDerivativesHierarchy(eventInfo,
                                     tsoses[iHit], lasAli, lasAli, 
                                     theFloatBufferX, theFloatBufferY, theIntBuffer, dummyPtr);
    // fill derivatives vector from derivatives matrix
    for (unsigned int nFitParams = 0; 
         nFitParams < static_cast<unsigned int>(lasBeam.parameters().size()); 
         ++nFitParams) {
      const float derivative = lasBeam.derivatives()[iHit][nFitParams];
      if (nFitParams < lasBeam.firstFixedParameter()) { // first local beam parameters
        lasLocalDerivsX.push_back(derivative);
      } else {                                          // now global ones
        const unsigned int numPar = nFitParams - lasBeam.firstFixedParameter();
        theIntBuffer.push_back(thePedeLabels->parameterLabel(beamLabel, numPar));
        theFloatBufferX.push_back(derivative);
      }
    } // end loop over parameters

    const float residual = hit.localPosition().x() - tsoses[iHit].localPosition().x();
    // error from file or assume 0.003
    const float error = 0.003; // hit.localPositionError().xx(); sqrt???
    
    theMille->mille(lasLocalDerivsX.size(), &(lasLocalDerivsX[0]), theFloatBufferX.size(),
                    &(theFloatBufferX[0]), &(theIntBuffer[0]), residual, error);
  } // end of loop over hits
  
  theMille->end();
}
void MillePedeAlignmentAlgorithm::addLaserData ( const EventInfo eventInfo,
const TkFittedLasBeamCollection tkLasBeams,
const TsosVectorCollection tkLasBeamTsoses 
) [private]

Definition at line 1022 of file MillePedeAlignmentAlgorithm.cc.

References addLasBeam().

Referenced by endRun().

{
  TsosVectorCollection::const_iterator iTsoses = lasBeamTsoses.begin();
  for(TkFittedLasBeamCollection::const_iterator iBeam = lasBeams.begin(), iEnd = lasBeams.end();
      iBeam != iEnd; ++iBeam, ++iTsoses){ // beam/tsoses parallel!

    edm::LogInfo("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::addLaserData"
                              << "Beam " << iBeam->getBeamId() << " with " 
                              << iBeam->parameters().size() << " parameters and " 
                              << iBeam->getData().size() << " hits.\n There are " 
                              << iTsoses->size() << " TSOSes.";

    this->addLasBeam(eventInfo, *iBeam, *iTsoses);
  }
}
int MillePedeAlignmentAlgorithm::addMeasurementData ( const EventInfo eventInfo,
const ReferenceTrajectoryBase::ReferenceTrajectoryPtr refTrajPtr,
unsigned int  iHit,
AlignmentParameters *&  params 
) [private]

If hit is usable: callMille for x and (probably) y direction. If globalDerivatives fine: returns 2 if 2D-hit, 1 if 1D-hit, 0 if no Alignable for hit. Returns -1 if any problem (for params cf. globalDerivativesHierarchy)

Definition at line 380 of file MillePedeAlignmentAlgorithm.cc.

References AlignableNavigator::alignableFromDetId(), callMille(), globalDerivativesHierarchy(), theAlignableNavigator, theFloatBufferX, theFloatBufferY, and theIntBuffer.

Referenced by addReferenceTrajectory().

{
  params = 0;
  theFloatBufferX.clear();
  theFloatBufferY.clear();
  theIntBuffer.clear();
 
  const TrajectoryStateOnSurface &tsos = refTrajPtr->trajectoryStates()[iHit];
  const ConstRecHitPointer &recHitPtr = refTrajPtr->recHits()[iHit];
  // ignore invalid hits
  if (!recHitPtr->isValid()) return 0;

  // get AlignableDet/Unit for this hit
  AlignableDetOrUnitPtr alidet(theAlignableNavigator->alignableFromDetId(recHitPtr->geographicalId()));
  
  if (!this->globalDerivativesHierarchy(eventInfo,
                                        tsos, alidet, alidet, theFloatBufferX, // 2x alidet, sic!
                                        theFloatBufferY, theIntBuffer, params)) {
    return -1; // problem
  } else if (theFloatBufferX.empty()) {
    return 0; // empty for X: no alignable for hit
  } else { 
    return this->callMille(refTrajPtr, iHit, theIntBuffer, theFloatBufferX, theFloatBufferY);
  }
}
void MillePedeAlignmentAlgorithm::addMsMeas ( const ReferenceTrajectoryBase::ReferenceTrajectoryPtr refTrajPtr,
unsigned int  iMsMeas 
) [private]

adds data from reference trajectory from a specific multiple scattering measurement

Definition at line 998 of file MillePedeAlignmentAlgorithm.cc.

Referenced by addReferenceTrajectory().

{
  TMatrixDSym aHitCovarianceM(1);
  TMatrixF aHitResidualsM(1,1);
  TMatrixF aLocalDerivativesM(1, refTrajPtr->derivatives().num_col());
  // below method fills above 3 'matrices'
  this->addRefTrackMsMeas1D(refTrajPtr, iMsMeas, aHitCovarianceM, aHitResidualsM, aLocalDerivativesM);
  
  // no global parameters (use dummy 0)
  TMatrixF aGlobalDerivativesM(1,1);
  aGlobalDerivativesM(0,0) = 0;
      
  float newResidX = aHitResidualsM(0,0);  
  float newHitErrX = TMath::Sqrt(aHitCovarianceM(0,0));
  float *newLocalDerivsX = aLocalDerivativesM[0].GetPtr();
  float *newGlobDerivsX  = aGlobalDerivativesM[0].GetPtr();
  const int nLocal  = aLocalDerivativesM.GetNcols();
  const int nGlobal = 0;
  
  theMille->mille(nLocal, newLocalDerivsX, nGlobal, newGlobDerivsX,
                  &nGlobal, newResidX, newHitErrX);  
}
void MillePedeAlignmentAlgorithm::addPxbSurvey ( const edm::ParameterSet pxbSurveyCfg) [private]

add measurement data from PXB survey

Definition at line 1087 of file MillePedeAlignmentAlgorithm.cc.

References a, AlignableNavigator::alignableFromDetId(), PedeLabelerBase::alignableLabel(), gather_cfg::cout, SurveyPxbDicer::doDice(), Mille::end(), lut2db_cfg::filename, MillePedeMonitor::fillPxbSurveyHistsChi2(), MillePedeMonitor::fillPxbSurveyHistsLocalPars(), edm::FileInPath::fullPath(), edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), i, j, Mille::mille(), SurveyPxbImageLocalFit::nMsrmts, EdgesToViz::outfile, mathSSE::sqrt(), theAlignableNavigator, theMille, theMonitor, thePedeLabels, AlignableSurface::toGlobal(), and AlignableSurface::toLocal().

Referenced by initialize().

{
        // do some printing, if requested
        const bool doOutputOnStdout(pxbSurveyCfg.getParameter<bool>("doOutputOnStdout"));
        if (doOutputOnStdout) std::cout << "# Output from addPxbSurvey follows below because doOutputOnStdout is set to True" << std::endl;

        // instantiate a dicer object
        SurveyPxbDicer dicer(pxbSurveyCfg.getParameter<std::vector<edm::ParameterSet> >("toySurveyParameters"), pxbSurveyCfg.getParameter<unsigned int>("toySurveySeed"));
        std::ofstream outfile(pxbSurveyCfg.getUntrackedParameter<std::string>("toySurveyFile").c_str());

        // read data from file
        std::vector<SurveyPxbImageLocalFit> measurements;
        std::string filename(pxbSurveyCfg.getParameter<edm::FileInPath>("infile").fullPath());
        SurveyPxbImageReader<SurveyPxbImageLocalFit> reader(filename, measurements, 800);

        // loop over photographs (=measurements) and perform the fit
        for(std::vector<SurveyPxbImageLocalFit>::size_type i=0; i!=measurements.size(); i++)
        {
                if (doOutputOnStdout) std::cout << "Module " << i << ": ";

                // get the Alignables and their surfaces
                AlignableDetOrUnitPtr mod1(theAlignableNavigator->alignableFromDetId(measurements[i].getIdFirst()));
                AlignableDetOrUnitPtr mod2(theAlignableNavigator->alignableFromDetId(measurements[i].getIdSecond()));
                const AlignableSurface& surf1 = mod1->surface();
                const AlignableSurface& surf2 = mod2->surface();
                
                // the position of the fiducial points in local frame of a PXB module
                const LocalPoint fidpoint0(-0.91,+3.30);
                const LocalPoint fidpoint1(+0.91,+3.30);
                const LocalPoint fidpoint2(+0.91,-3.30);
                const LocalPoint fidpoint3(-0.91,-3.30);
                
                // We choose the local frame of the first module as reference,
                // so take the fidpoints of the second module and calculate their
                // positions in the reference frame
                const GlobalPoint surf2point0(surf2.toGlobal(fidpoint0));
                const GlobalPoint surf2point1(surf2.toGlobal(fidpoint1));
                const LocalPoint fidpoint0inSurf1frame(surf1.toLocal(surf2point0));
                const LocalPoint fidpoint1inSurf1frame(surf1.toLocal(surf2point1));
                
                // Create the vector for the fit
                SurveyPxbImageLocalFit::fidpoint_t fidpointvec;
                fidpointvec.push_back(fidpoint0inSurf1frame);
                fidpointvec.push_back(fidpoint1inSurf1frame);
                fidpointvec.push_back(fidpoint2);
                fidpointvec.push_back(fidpoint3);

                // if toy survey is requested, dice the values now
                if (pxbSurveyCfg.getParameter<bool>("doToySurvey"))
                {
                        dicer.doDice(fidpointvec,measurements[i].getIdPair(), outfile);
                }
                
                // do the fit
                measurements[i].doFit(fidpointvec, thePedeLabels->alignableLabel(mod1), thePedeLabels->alignableLabel(mod2));
            SurveyPxbImageLocalFit::localpars_t a; // local pars from fit
                a = measurements[i].getLocalParameters();
                const SurveyPxbImageLocalFit::value_t chi2 = measurements[i].getChi2();

                // do some reporting, if requested
                if (doOutputOnStdout)
                {
                  std::cout << "a: " << a[0] << ", " << a[1]  << ", " << a[2] << ", " << a[3]
                        << " S= " << sqrt(a[2]*a[2]+a[3]*a[3])
                        << " phi= " << atan(a[3]/a[2])
                        << " chi2= " << chi2 << std::endl;
                }
                if (theMonitor) 
                {
                        theMonitor->fillPxbSurveyHistsChi2(chi2);
                        theMonitor->fillPxbSurveyHistsLocalPars(a[0],a[1],sqrt(a[2]*a[2]+a[3]*a[3]),atan(a[3]/a[2]));
                }

                // pass the results from the local fit to mille
                for(SurveyPxbImageLocalFit::count_t j=0; j!=SurveyPxbImageLocalFit::nMsrmts; j++)
                {
                        theMille->mille((int)measurements[i].getLocalDerivsSize(),
                                measurements[i].getLocalDerivsPtr(j),
                                (int)measurements[i].getGlobalDerivsSize(),
                                measurements[i].getGlobalDerivsPtr(j),
                                measurements[i].getGlobalDerivsLabelPtr(j),
                                measurements[i].getResiduum(j),
                                measurements[i].getSigma(j));
                }
                theMille->end();
        }
        outfile.close();
}
std::pair< unsigned int, unsigned int > MillePedeAlignmentAlgorithm::addReferenceTrajectory ( const EventInfo eventInfo,
const ReferenceTrajectoryBase::ReferenceTrajectoryPtr refTrajPtr 
) [private]

fill mille for a trajectory, returning number of x/y hits ([0,0] if 'bad' trajectory)

Definition at line 319 of file MillePedeAlignmentAlgorithm.cc.

References addMeasurementData(), addMsMeas(), Mille::end(), MillePedeVariables::increaseHitsX(), MillePedeVariables::increaseHitsY(), Mille::kill(), theMille, and theMinNumHits.

Referenced by run().

{
  std::pair<unsigned int, unsigned int> hitResultXy(0,0);
  if (refTrajPtr->isValid()) {
    
    // to add hits if all fine:
    std::vector<AlignmentParameters*> parVec(refTrajPtr->recHits().size());
    // collect hit statistics, assuming that there are no y-only hits
    std::vector<bool> validHitVecY(refTrajPtr->recHits().size(), false);
    // Use recHits from ReferenceTrajectory (since they have the right order!):
    for (unsigned int iHit = 0; iHit < refTrajPtr->recHits().size(); ++iHit) {
      const int flagXY = this->addMeasurementData(eventInfo, refTrajPtr, iHit, parVec[iHit]);

      if (flagXY < 0) { // problem
        hitResultXy.first = 0;
        break;
      } else { // hit is fine, increase x/y statistics
        if (flagXY >= 1) ++hitResultXy.first;
        validHitVecY[iHit] = (flagXY >= 2);
      } 
    } // end loop on hits

// CHK add 'Multiple Scattering Measurements' for break points, broken lines
    for (unsigned int iMsMeas = 0; iMsMeas < refTrajPtr->numberOfMsMeas(); ++iMsMeas) {
      this->addMsMeas(refTrajPtr, iMsMeas);
    }
             
    // kill or end 'track' for mille, depends on #hits criterion
    if (hitResultXy.first == 0 || hitResultXy.first < theMinNumHits) {
      theMille->kill();
      hitResultXy.first = hitResultXy.second = 0; //reset
    } else {
      theMille->end();
      // take care about hit statistics as well
      for (unsigned int iHit = 0; iHit < validHitVecY.size(); ++iHit) {
        if (!parVec[iHit]) continue; // in case a non-selected alignable was hit (flagXY == 0)
        MillePedeVariables *mpVar = static_cast<MillePedeVariables*>(parVec[iHit]->userVariables());
        mpVar->increaseHitsX(); // every hit has an x-measurement, cf. above...
        if (validHitVecY[iHit]) {
          mpVar->increaseHitsY();
          ++hitResultXy.second;
        }
      }  
    }
  } // end if valid trajectory

  return hitResultXy;
}
void MillePedeAlignmentAlgorithm::addRefTrackData2D ( const ReferenceTrajectoryBase::ReferenceTrajectoryPtr refTrajPtr,
unsigned int  iTrajHit,
TMatrixDSym &  aHitCovarianceM,
TMatrixF &  aHitResidualsM,
TMatrixF &  aLocalDerivativesM 
) [private]

adds data from reference trajectory from a specific Hit

Definition at line 821 of file MillePedeAlignmentAlgorithm.cc.

References i.

{
  // This Method is valid for 2D measurements only
  
  const unsigned int xIndex = iTrajHit*2;
  const unsigned int yIndex = iTrajHit*2+1;
  // Covariance into a TMatrixDSym

  //aHitCovarianceM = new TMatrixDSym(2);
  aHitCovarianceM(0,0)=refTrajPtr->measurementErrors()[xIndex][xIndex];
  aHitCovarianceM(0,1)=refTrajPtr->measurementErrors()[xIndex][yIndex];
  aHitCovarianceM(1,0)=refTrajPtr->measurementErrors()[yIndex][xIndex];
  aHitCovarianceM(1,1)=refTrajPtr->measurementErrors()[yIndex][yIndex];
  
  //theHitResidualsM= new TMatrixF(2,1);
  aHitResidualsM(0,0)= refTrajPtr->measurements()[xIndex] - refTrajPtr->trajectoryPositions()[xIndex];
  aHitResidualsM(1,0)= refTrajPtr->measurements()[yIndex] - refTrajPtr->trajectoryPositions()[yIndex];
  
  // Local Derivatives into a TMatrixDSym (to use matrix operations)
  const AlgebraicMatrix &locDerivMatrix = refTrajPtr->derivatives();
  //  theLocalDerivativeNumber = locDerivMatrix.num_col();
  
  //theLocalDerivativesM = new TMatrixF(2,locDerivMatrix.num_col());
  for (int i = 0; i < locDerivMatrix.num_col(); ++i) {
    aLocalDerivativesM(0,i) = locDerivMatrix[xIndex][i];
    aLocalDerivativesM(1,i) = locDerivMatrix[yIndex][i];
  }
}
void MillePedeAlignmentAlgorithm::addRefTrackMsMeas1D ( const ReferenceTrajectoryBase::ReferenceTrajectoryPtr refTrajPtr,
unsigned int  iTrajHit,
TMatrixDSym &  aHitCovarianceM,
TMatrixF &  aHitResidualsM,
TMatrixF &  aLocalDerivativesM 
) [private]

adds multiple scattering data from reference trajectory from a specific Hit

Definition at line 794 of file MillePedeAlignmentAlgorithm.cc.

References i.

{

  // This Method is valid for 1D measurements only
  const unsigned int xIndex = iMsMeas + refTrajPtr->numberOfHitMeas();
  // Covariance into a TMatrixDSym
  
  //aHitCovarianceM = new TMatrixDSym(1);
  aHitCovarianceM(0,0)=refTrajPtr->measurementErrors()[xIndex][xIndex];
  
  //theHitResidualsM= new TMatrixF(1,1);
  aHitResidualsM(0,0)= refTrajPtr->measurements()[xIndex];
  
  // Local Derivatives into a TMatrixDSym (to use matrix operations)
  const AlgebraicMatrix &locDerivMatrix = refTrajPtr->derivatives();
  //  theLocalDerivativeNumber = locDerivMatrix.num_col();
  
  //theLocalDerivativesM = new TMatrixF(1,locDerivMatrix.num_col());
  for (int i = 0; i < locDerivMatrix.num_col(); ++i) {
    aLocalDerivativesM(0,i) = locDerivMatrix[xIndex][i];
  }
}
bool MillePedeAlignmentAlgorithm::areEmptyParams ( const std::vector< Alignable * > &  alignables) const [private]

Definition at line 556 of file MillePedeAlignmentAlgorithm.cc.

References AlignmentParameters::covariance(), i, j, and AlignmentParameters::parameters().

Referenced by readFromPede().

{
  
  for (std::vector<Alignable*>::const_iterator iAli = alignables.begin();
       iAli != alignables.end(); ++iAli) {
    const AlignmentParameters *params = (*iAli)->alignmentParameters();
    if (params) {
      const AlgebraicVector &parVec(params->parameters());
      const AlgebraicMatrix &parCov(params->covariance());
      for (int i = 0; i < parVec.num_row(); ++i) {
        if (parVec[i] != 0.) return false;
        for (int j = i; j < parCov.num_col(); ++j) {
          if (parCov[i][j] != 0.) return false;
        }
      }
    }
  }
  
  return true;
}
void MillePedeAlignmentAlgorithm::buildUserVariables ( const std::vector< Alignable * > &  alignables) const [private]

add MillePedeVariables for each AlignmentParameters (exception if no parameters...)

Definition at line 653 of file MillePedeAlignmentAlgorithm.cc.

References PedeLabelerBase::alignableLabel(), Exception, AlignmentParameters::setUserVariables(), AlignmentParameters::size(), and thePedeLabels.

Referenced by initialize().

{
  for (std::vector<Alignable*>::const_iterator iAli = alis.begin(); iAli != alis.end(); ++iAli) {
    AlignmentParameters *params = (*iAli)->alignmentParameters();
    if (!params) {
      throw cms::Exception("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::buildUserVariables"
                                        << "No parameters for alignable";
    }
    MillePedeVariables *userVars = new MillePedeVariables(params->size(), thePedeLabels->alignableLabel(*iAli));
    params->setUserVariables(userVars);
  }
}
int MillePedeAlignmentAlgorithm::callMille ( const ReferenceTrajectoryBase::ReferenceTrajectoryPtr refTrajPtr,
unsigned int  iTrajHit,
const std::vector< int > &  globalLabels,
const std::vector< float > &  globalDerivativesX,
const std::vector< float > &  globalDerivativesY 
) [private]

calls callMille1D or callMille2D

Definition at line 854 of file MillePedeAlignmentAlgorithm.cc.

Referenced by addMeasurementData().

{    
  const ConstRecHitPointer aRecHit(refTrajPtr->recHits()[iTrajHit]);

  if((aRecHit)->dimension() == 1) {
    return this->callMille1D(refTrajPtr, iTrajHit, globalLabels, globalDerivativesX);
  } else {
    return this->callMille2D(refTrajPtr, iTrajHit, globalLabels,
                             globalDerivativesX, globalDerivativesY);
  }
}
int MillePedeAlignmentAlgorithm::callMille1D ( const ReferenceTrajectoryBase::ReferenceTrajectoryPtr refTrajPtr,
unsigned int  iTrajHit,
const std::vector< int > &  globalLabels,
const std::vector< float > &  globalDerivativesX 
) [private]

calls Mille for 1D hits

Definition at line 872 of file MillePedeAlignmentAlgorithm.cc.

References i.

{
  const ConstRecHitPointer aRecHit(refTrajPtr->recHits()[iTrajHit]);
  const unsigned int xIndex = iTrajHit*2; // the even ones are local x

  // local derivatives
  const AlgebraicMatrix &locDerivMatrix = refTrajPtr->derivatives();
  const int nLocal  = locDerivMatrix.num_col();
  std::vector<float> localDerivatives(nLocal);
  for (unsigned int i = 0; i < localDerivatives.size(); ++i) {
    localDerivatives[i] = locDerivMatrix[xIndex][i];
  }

  // residuum and error
  float residX = refTrajPtr->measurements()[xIndex] - refTrajPtr->trajectoryPositions()[xIndex];
  float hitErrX = TMath::Sqrt(refTrajPtr->measurementErrors()[xIndex][xIndex]);

  // number of global derivatives
  const int nGlobal = globalDerivativesX.size();

  // &(localDerivatives[0]) etc. are valid - as long as vector is not empty
  // cf. https://www.parashift.com/c++-faq-lite/containers.html#faq-34.3
  theMille->mille(nLocal, &(localDerivatives[0]), nGlobal, &(globalDerivativesX[0]),
                  &(globalLabels[0]), residX, hitErrX);

  if (theMonitor) {
    theMonitor->fillDerivatives(aRecHit, &(localDerivatives[0]), nLocal,
                                &(globalDerivativesX[0]), nGlobal, &(globalLabels[0]));
    theMonitor->fillResiduals(aRecHit, refTrajPtr->trajectoryStates()[iTrajHit],
                              iTrajHit, residX, hitErrX, false);
  }

  return 1;
}
int MillePedeAlignmentAlgorithm::callMille2D ( const ReferenceTrajectoryBase::ReferenceTrajectoryPtr refTrajPtr,
unsigned int  iTrajHit,
const std::vector< int > &  globalLabels,
const std::vector< float > &  globalDerivativesx,
const std::vector< float > &  globalDerivativesy 
) [private]

calls Mille for x and possibly y component of hit, y is skipped for non-real 2D (e.g. SiStripRecHit2D), for TID/TEC first diagonalises if correlation is larger than configurable

Definition at line 911 of file MillePedeAlignmentAlgorithm.cc.

References corr, pat::helper::ParametrizationHelper::dimension(), mathSSE::sqrt(), std::swap(), SiStripDetId::TEC, SiStripDetId::TID, and DetId::Tracker.

{
  const ConstRecHitPointer aRecHit(refTrajPtr->recHits()[iTrajHit]);
  
  if((aRecHit)->dimension() != 2) {
    edm::LogError("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::callMille2D"
                               << "You try to call method for 2D hits for a " 
                               << (aRecHit)->dimension()
                               <<  "D Hit. Hit gets ignored!";
    return -1;
  }

  TMatrixDSym aHitCovarianceM(2);
  TMatrixF aHitResidualsM(2,1);
  TMatrixF aLocalDerivativesM(2, refTrajPtr->derivatives().num_col());
  // below method fills above 3 matrices
  this->addRefTrackData2D(refTrajPtr, iTrajHit, aHitCovarianceM,aHitResidualsM,aLocalDerivativesM);
  TMatrixF aGlobalDerivativesM(2,globalDerivativesx.size());
  this->makeGlobDerivMatrix(globalDerivativesx, globalDerivativesy, aGlobalDerivativesM);
 
  // calculates correlation between Hit measurements
  // FIXME: Should take correlation (and resulting transformation) from original hit, 
  //        not 2x2 matrix from ReferenceTrajectory: That can come from error propagation etc.!
  const double corr = aHitCovarianceM(0,1) / sqrt(aHitCovarianceM(0,0) * aHitCovarianceM(1,1));
  if (theMonitor) theMonitor->fillCorrelations2D(corr, aRecHit);
  bool diag = false; // diagonalise only tracker TID, TEC
  switch(aRecHit->geographicalId().subdetId()) {
  case SiStripDetId::TID:
  case SiStripDetId::TEC:
    if (aRecHit->geographicalId().det() == DetId::Tracker && TMath::Abs(corr) > theMaximalCor2D) {
      this->diagonalize(aHitCovarianceM, aLocalDerivativesM, aHitResidualsM, aGlobalDerivativesM);
      diag = true;
    }
    break;
  default:;
  }

  float newResidX = aHitResidualsM(0,0);
  float newResidY = aHitResidualsM(1,0);
  float newHitErrX = TMath::Sqrt(aHitCovarianceM(0,0));
  float newHitErrY = TMath::Sqrt(aHitCovarianceM(1,1));
  float *newLocalDerivsX = aLocalDerivativesM[0].GetPtr();
  float *newLocalDerivsY = aLocalDerivativesM[1].GetPtr();
  float *newGlobDerivsX  = aGlobalDerivativesM[0].GetPtr();
  float *newGlobDerivsY  = aGlobalDerivativesM[1].GetPtr();
  const int nLocal  = aLocalDerivativesM.GetNcols();
  const int nGlobal = aGlobalDerivativesM.GetNcols();

  if (diag && (newHitErrX > newHitErrY)) { // also for 2D hits?
    // measurement with smaller error is x-measurement (for !is2D do not fill y-measurement):
    std::swap(newResidX, newResidY);
    std::swap(newHitErrX, newHitErrY);
    std::swap(newLocalDerivsX, newLocalDerivsY);
    std::swap(newGlobDerivsX, newGlobDerivsY);
  }

  // &(globalLabels[0]) is valid - as long as vector is not empty 
  // cf. https://www.parashift.com/c++-faq-lite/containers.html#faq-34.3
  theMille->mille(nLocal, newLocalDerivsX, nGlobal, newGlobDerivsX,
                  &(globalLabels[0]), newResidX, newHitErrX);

  if (theMonitor) {
    theMonitor->fillDerivatives(aRecHit, newLocalDerivsX, nLocal, newGlobDerivsX, nGlobal,
                                &(globalLabels[0]));
    theMonitor->fillResiduals(aRecHit, refTrajPtr->trajectoryStates()[iTrajHit],
                              iTrajHit, newResidX, newHitErrX, false);
  }
  const bool isReal2DHit = this->is2D(aRecHit); // strip is 1D (except matched hits)
  if (isReal2DHit) {
    theMille->mille(nLocal, newLocalDerivsY, nGlobal, newGlobDerivsY,
                    &(globalLabels[0]), newResidY, newHitErrY);
    if (theMonitor) {
      theMonitor->fillDerivatives(aRecHit, newLocalDerivsY, nLocal, newGlobDerivsY, nGlobal,
                                  &(globalLabels[0]));
      theMonitor->fillResiduals(aRecHit, refTrajPtr->trajectoryStates()[iTrajHit],
                                iTrajHit, newResidY, newHitErrY, true);// true: y
    }
  }

  return (isReal2DHit ? 2 : 1);
}
unsigned int MillePedeAlignmentAlgorithm::decodeMode ( const std::string &  mode) const [private]

Definition at line 667 of file MillePedeAlignmentAlgorithm.cc.

References Exception, myMilleBit, myPedeReadBit, myPedeRunBit, and myPedeSteerBit.

{
  if (mode == "full") {
    return myMilleBit + myPedeSteerBit + myPedeRunBit + myPedeReadBit;
  } else if (mode == "mille") {
    return myMilleBit; // + myPedeSteerBit; // sic! Including production of steerig file. NO!
  } else if (mode == "pede") {
    return myPedeSteerBit + myPedeRunBit + myPedeReadBit;
  } else if (mode == "pedeSteer") {
    return myPedeSteerBit;
  } else if (mode == "pedeRun") {
    return myPedeSteerBit + myPedeRunBit + myPedeReadBit; // sic! Including steering and reading of result.
  } else if (mode == "pedeRead") {
    return myPedeReadBit;
  }

  throw cms::Exception("BadConfig") 
    << "Unknown mode '" << mode  
    << "', use 'full', 'mille', 'pede', 'pedeRun', 'pedeSteer' or 'pedeRead'.";

  return 0;
}
void MillePedeAlignmentAlgorithm::diagonalize ( TMatrixDSym &  aHitCovarianceM,
TMatrixF &  aLocalDerivativesM,
TMatrixF &  aHitResidualsM,
TMatrixF &  theGlobalDerivativesM 
) const [private]

Definition at line 769 of file MillePedeAlignmentAlgorithm.cc.

{
  TMatrixDSymEigen myDiag(aHitCovarianceM);
  TMatrixD aTranfoToDiagonalSystem = myDiag.GetEigenVectors();
  TMatrixD aTranfoToDiagonalSystemInv = myDiag.GetEigenVectors( );
  TMatrixF aTranfoToDiagonalSystemInvF = myDiag.GetEigenVectors( );
  TMatrixD aMatrix = aTranfoToDiagonalSystemInv.Invert() * aHitCovarianceM * aTranfoToDiagonalSystem;
  // Tranformation of matrix M is done by A^T*M*A, not A^{-1}*M*A.
  // But here A^T == A^{-1}, so we would only save CPU by Transpose()...
  // FIXME this - I guess simply use T(), not Transpose()...
  // TMatrixD aMatrix = aTranfoToDiagonalSystemInv.Transpose() * aHitCovarianceM
  //    * aTranfoToDiagonalSystem;
  aHitCovarianceM = TMatrixDSym(2, aMatrix.GetMatrixArray());
  aTranfoToDiagonalSystemInvF.Invert();
  //edm::LogInfo("Alignment") << "NEW HIT loca in matrix"<<aLocalDerivativesM(0,0);
  aLocalDerivativesM = aTranfoToDiagonalSystemInvF * aLocalDerivativesM;
  
  //edm::LogInfo("Alignment") << "NEW HIT loca in matrix after diag:"<<aLocalDerivativesM(0,0);
  aHitResidualsM      = aTranfoToDiagonalSystemInvF * aHitResidualsM;
  aGlobalDerivativesM = aTranfoToDiagonalSystemInvF * aGlobalDerivativesM;
}
unsigned int MillePedeAlignmentAlgorithm::doIO ( int  loop) const [private]

Definition at line 578 of file MillePedeAlignmentAlgorithm.cc.

References addHitStatistics(), edm::ParameterSet::getParameter(), python::cmstools::loop(), query::result, theAlignables, theConfig, theDir, AlignmentIORoot::writeAlignableAbsolutePositions(), AlignmentIORoot::writeAlignableOriginalPositions(), AlignmentIORoot::writeAlignableRelativePositions(), MillePedeVariablesIORoot::writeMillePedeVariables(), and AlignmentIORoot::writeOrigRigidBodyAlignmentParameters().

Referenced by initialize(), and terminate().

{
  unsigned int result = 0;

  const std::string outFilePlain(theConfig.getParameter<std::string>("treeFile"));
  if (outFilePlain.empty()) {
    edm::LogInfo("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::doIO"
                              << "treeFile parameter empty => skip writing for 'loop' " << loop;
    return result;
  }

  const std::string outFile(theDir + outFilePlain);

  AlignmentIORoot aliIO;
  int ioerr = 0;
  if (loop == 0) {
    aliIO.writeAlignableOriginalPositions(theAlignables, outFile.c_str(), loop, false, ioerr);
    if (ioerr) {
      edm::LogError("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::doIO"
                                 << "Problem " << ioerr << " in writeAlignableOriginalPositions";
      ++result;
    }
  } else {
    if (loop > 1) {
      const std::vector<std::string> inFiles
        (theConfig.getParameter<std::vector<std::string> >("mergeTreeFiles"));
      const std::vector<std::string> binFiles
        (theConfig.getParameter<std::vector<std::string> >("mergeBinaryFiles"));
      if (inFiles.size() != binFiles.size()) {
        edm::LogWarning("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::doIO"
                                     << "'vstring mergeTreeFiles' and 'vstring mergeBinaryFiles' "
                                     << "differ in size";
      }
      this->addHitStatistics(loop - 1, outFile, inFiles);
    }
    MillePedeVariablesIORoot millePedeIO;
    millePedeIO.writeMillePedeVariables(theAlignables, outFile.c_str(), loop, false, ioerr);
    if (ioerr) {
      edm::LogError("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::doIO"
                                 << "Problem " << ioerr << " writing MillePedeVariables";
      ++result;
    }
// // problem with following writeOrigRigidBodyAlignmentParameters
//     aliIO.writeAlignmentParameters(theAlignables, outFile.c_str(), loop, false, ioerr);
//     if (ioerr) {
//       edm::LogError("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::doIO"
//                                  << "Problem " << ioerr << " in writeAlignmentParameters, " << loop;
//       ++result;
//     }
  }
  
  //  aliIO.writeAlignmentParameters(theAlignables, ("tmp"+outFile).c_str(), loop, false, ioerr);
  aliIO.writeOrigRigidBodyAlignmentParameters(theAlignables, outFile.c_str(), loop, false, ioerr);
  if (ioerr) {
    edm::LogError("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::doIO" << "Problem " << ioerr
                               << " in writeOrigRigidBodyAlignmentParameters, " << loop;
    ++result;
  }
  aliIO.writeAlignableAbsolutePositions(theAlignables, outFile.c_str(), loop, false, ioerr);
  if (ioerr) {
    edm::LogError("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::doIO" << "Problem " << ioerr
                               << " in writeAlignableAbsolutePositions, " << loop;
    ++result;
  }
  aliIO.writeAlignableRelativePositions(theAlignables, outFile.c_str(), loop, false, ioerr);
  if (ioerr) {
    edm::LogError("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::doIO" << "Problem " << ioerr
                               << " in writeAlignableRelativePositions, " << loop;
    ++result;
  }

  return result;
}
void MillePedeAlignmentAlgorithm::endRun ( const EventInfo eventInfo,
const EndRunInfo runInfo,
const edm::EventSetup setup 
) [virtual]

Run on run products, e.g. TkLAS.

Definition at line 370 of file MillePedeAlignmentAlgorithm.cc.

References addLaserData(), AlignmentAlgorithmBase::EndRunInfo::tkLasBeams_, and AlignmentAlgorithmBase::EndRunInfo::tkLasBeamTsoses_.

{
  if(runInfo.tkLasBeams_ && runInfo.tkLasBeamTsoses_){
    // LAS beam treatment
    this->addLaserData(eventInfo, *(runInfo.tkLasBeams_), *(runInfo.tkLasBeamTsoses_));
  }
}
bool MillePedeAlignmentAlgorithm::globalDerivativesHierarchy ( const EventInfo eventInfo,
const TrajectoryStateOnSurface tsos,
Alignable ali,
const AlignableDetOrUnitPtr alidet,
std::vector< float > &  globalDerivativesX,
std::vector< float > &  globalDerivativesY,
std::vector< int > &  globalLabels,
AlignmentParameters *&  lowestParams 
) const [private]

recursively adding derivatives and labels, false if problems

Definition at line 411 of file MillePedeAlignmentAlgorithm.cc.

References Alignable::alignmentParameters(), AlignmentParameters::derivatives(), Alignable::mother(), and AlignmentParameters::selector().

Referenced by addLasBeam(), and addMeasurementData().

{
  // derivatives and labels are recursively attached
  if (!ali) return true; // no mother might be OK

  if (false && theMonitor && alidet != ali) theMonitor->fillFrameToFrame(alidet, ali);

  AlignmentParameters *params = ali->alignmentParameters();

  if (params) {
    if (!lowestParams) lowestParams = params; // set parameters of lowest level

    bool hasSplitParameters = thePedeLabels->hasSplitParameters(ali);
    const unsigned int alignableLabel = thePedeLabels->alignableLabel(ali);
    
    if (0 == alignableLabel) { // FIXME: what about regardAllHits in Markus' code?
      edm::LogWarning("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::globalDerivativesHierarchy"
                                   << "Label not found, skip Alignable.";
      return false;
    }
    
    const std::vector<bool> &selPars = params->selector();
    const AlgebraicMatrix derivs(params->derivatives(tsos, alidet));

    // cols: 2, i.e. x&y, rows: parameters, usually RigidBodyAlignmentParameters::N_PARAM
    for (unsigned int iSel = 0; iSel < selPars.size(); ++iSel) {
      if (selPars[iSel]) {
        globalDerivativesX.push_back(derivs[iSel][kLocalX]
                                     /thePedeSteer->cmsToPedeFactor(iSel));
        if (hasSplitParameters==true) {
          globalLabels.push_back(thePedeLabels->parameterLabel(ali, iSel, eventInfo, tsos));
        } else {
          globalLabels.push_back(thePedeLabels->parameterLabel(alignableLabel, iSel));
        }
        globalDerivativesY.push_back(derivs[iSel][kLocalY]
                                     /thePedeSteer->cmsToPedeFactor(iSel));
      }
    }
    // Exclude mothers if Alignable selected to be no part of a hierarchy:
    if (thePedeSteer->isNoHiera(ali)) return true;
  }
  // Call recursively for mother, will stop if mother == 0:
  return this->globalDerivativesHierarchy(eventInfo,
                                          tsos, ali->mother(), alidet,
                                          globalDerivativesX, globalDerivativesY,
                                          globalLabels, lowestParams);
}
void MillePedeAlignmentAlgorithm::initialize ( const edm::EventSetup setup,
AlignableTracker tracker,
AlignableMuon muon,
AlignableExtras extras,
AlignmentParameterStore store 
) [virtual]

Call at beginning of job.

Implements AlignmentAlgorithmBase.

Definition at line 114 of file MillePedeAlignmentAlgorithm.cc.

References addPxbSurvey(), edm::ParameterSet::addUntrackedParameter(), AlignmentParameterStore::alignables(), AlignmentParameterStore::applyParameters(), PedeSteerer::buildSubSteer(), buildUserVariables(), doIO(), relativeConstraints::empty, Exception, edm::ParameterSet::exists(), reco::get(), edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), isMode(), myMilleBit, myPedeSteerBit, readFromPede(), AlignmentParameterStore::resetParameters(), cond::runnumber, findQualityFiles::size, theAlignableNavigator, theAlignables, theAlignmentParameterStore, theConfig, theDir, theDoSurveyPixelBarrel, theMille, theMonitor, thePedeLabels, thePedeSteer, theTrajectoryFactory, and cond::timeTypeSpecs.

{
  if (muon) {
    edm::LogWarning("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::initialize"
                                 << "Running with AlignabeMuon not yet tested.";
  }

  theAlignableNavigator = new AlignableNavigator(extras, tracker, muon);
  theAlignmentParameterStore = store;
  theAlignables = theAlignmentParameterStore->alignables();

  edm::ParameterSet pedeLabelerCfg(theConfig.getParameter<edm::ParameterSet>("pedeLabeler"));
  edm::VParameterSet RunRangeSelectionVPSet(theConfig.getUntrackedParameter<edm::VParameterSet>("RunRangeSelection"));
  pedeLabelerCfg.addUntrackedParameter<edm::VParameterSet>("RunRangeSelection",
                                                           RunRangeSelectionVPSet);

  std::string labelerPlugin = "PedeLabeler";
  if (RunRangeSelectionVPSet.size()>0) {
    labelerPlugin = "RunRangeDependentPedeLabeler";
    if (pedeLabelerCfg.exists("plugin")) {
      std::string labelerPluginCfg = pedeLabelerCfg.getParameter<std::string>("plugin");
      if ((labelerPluginCfg!="PedeLabeler" && labelerPluginCfg!="RunRangeDependentPedeLabeler") ||
          pedeLabelerCfg.getUntrackedParameter<edm::VParameterSet>("parameterInstances").size()>0) {
        throw cms::Exception("BadConfig")
          << "MillePedeAlignmentAlgorithm::initialize"
          << "both RunRangeSelection and generic labeler specified in config file. "
          << "Please get rid of either one of them.\n";
      }
    }
  } else {
    if (pedeLabelerCfg.exists("plugin")) {
      labelerPlugin = pedeLabelerCfg.getParameter<std::string>("plugin");
    }
  }
  
  if (!pedeLabelerCfg.exists("plugin")) {
    pedeLabelerCfg.addUntrackedParameter<std::string>("plugin", labelerPlugin);
  }

  edm::LogInfo("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::initialize"
                            << "Using plugin '" << labelerPlugin << "' to generate labels.";
  
  thePedeLabels = PedeLabelerPluginFactory::get()->create(labelerPlugin,
                                                          PedeLabelerBase::TopLevelAlignables(tracker, muon, extras),
                                                          pedeLabelerCfg);
  
  // 1) Create PedeSteerer: correct alignable positions for coordinate system selection
  edm::ParameterSet pedeSteerCfg(theConfig.getParameter<edm::ParameterSet>("pedeSteerer"));
  thePedeSteer = new PedeSteerer(tracker, muon, extras,
                                 theAlignmentParameterStore, thePedeLabels,
                                 pedeSteerCfg, theDir, !this->isMode(myPedeSteerBit));
  
  // 2) If requested, directly read in and apply result of previous pede run,
  //    assuming that correction from 1) was also applied to create the result:
  const std::vector<edm::ParameterSet> mprespset
    (theConfig.getParameter<std::vector<edm::ParameterSet> >("pedeReaderInputs"));
  if (!mprespset.empty()) {
    edm::LogInfo("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::initialize"
                              << "Apply " << mprespset.end() - mprespset.begin()
                              << " previous MillePede constants from 'pedeReaderInputs'.";
  }

  RunRange runrange(cond::timeTypeSpecs[cond::runnumber].beginValue,
                    cond::timeTypeSpecs[cond::runnumber].endValue);
  for (std::vector<edm::ParameterSet>::const_iterator iSet = mprespset.begin(), iE = mprespset.end();
       iSet != iE; ++iSet) {
    if (!this->readFromPede((*iSet), false, runrange)) { // false: do not erase SelectionUserVariables
      throw cms::Exception("BadConfig")
        << "MillePedeAlignmentAlgorithm::initialize: Problems reading input constants of "
        << "pedeReaderInputs entry " << iSet - mprespset.begin() << '.';
    }
    theAlignmentParameterStore->applyParameters();
    // Needed to shut up later warning from checkAliParams:
    theAlignmentParameterStore->resetParameters();
  }
  
  // 3) Now create steerings with 'final' start position:
  thePedeSteer->buildSubSteer(tracker, muon, extras);

  // After (!) 1-3 of PedeSteerer which uses the SelectionUserVariables attached to the parameters:
  this->buildUserVariables(theAlignables); // for hit statistics and/or pede result

  if (this->isMode(myMilleBit)) {
    if (!theConfig.getParameter<std::vector<std::string> >("mergeBinaryFiles").empty() ||
        !theConfig.getParameter<std::vector<std::string> >("mergeTreeFiles").empty()) {
      throw cms::Exception("BadConfig")
        << "'vstring mergeTreeFiles' and 'vstring mergeBinaryFiles' must be empty for "
        << "modes running mille.";
    }
    theMille = new Mille((theDir + theConfig.getParameter<std::string>("binaryFile")).c_str());// add ', false);' for text output);
    const std::string moniFile(theConfig.getUntrackedParameter<std::string>("monitorFile"));
    if (moniFile.size()) theMonitor = new MillePedeMonitor((theDir + moniFile).c_str());

    // Get trajectory factory. In case nothing found, FrameWork will throw...
    const edm::ParameterSet fctCfg(theConfig.getParameter<edm::ParameterSet>("TrajectoryFactory"));
    const std::string fctName(fctCfg.getParameter<std::string>("TrajectoryFactoryName"));
    theTrajectoryFactory = TrajectoryFactoryPlugin::get()->create(fctName, fctCfg);
  }

  // FIXME: for PlotMillePede hit statistics stuff we also might want doIO(0)... ?
  if (this->isMode(myPedeSteerBit) // for pedeRun and pedeRead we might want to merge
      || !theConfig.getParameter<std::vector<std::string> >("mergeTreeFiles").empty()) {
    this->doIO(0);

  // Get config for survey and set flag accordingly
  const edm::ParameterSet pxbSurveyCfg(theConfig.getParameter<edm::ParameterSet>("surveyPixelBarrel"));
  theDoSurveyPixelBarrel = pxbSurveyCfg.getParameter<bool>("doSurvey");
  if (theDoSurveyPixelBarrel) addPxbSurvey(pxbSurveyCfg);
  }
}
bool MillePedeAlignmentAlgorithm::is2D ( const TransientTrackingRecHit::ConstRecHitPointer recHit) const [private]

true if hit belongs to 2D detector (currently tracker specific)

Definition at line 500 of file MillePedeAlignmentAlgorithm.cc.

{
  // FIXME: Check whether this is a reliable and recommended way to find out...

  if (recHit->dimension() < 2) {
    return false; // some muon and TIB/TOB stuff really has RecHit1D
  } else if (recHit->detUnit()) { // detunit in strip is 1D, in pixel 2D 
    return recHit->detUnit()->type().isTrackerPixel();
  } else { // stereo strips  (FIXME: endcap trouble due to non-parallel strips (wedge sensors)?)
    if (dynamic_cast<const ProjectedSiStripRecHit2D*>(recHit->hit())) { // check persistent hit
      // projected: 1D measurement on 'glued' module
      return false;
    } else {
      return true;
    }
  }
}
bool MillePedeAlignmentAlgorithm::isMode ( unsigned int  testMode) const [inline, private]

Definition at line 176 of file MillePedeAlignmentAlgorithm.h.

References theMode.

Referenced by initialize(), run(), setParametersForRunRange(), and terminate().

{return (theMode & testMode);}
void MillePedeAlignmentAlgorithm::makeGlobDerivMatrix ( const std::vector< float > &  globalDerivativesx,
const std::vector< float > &  globalDerivativesy,
TMatrixF &  aGlobalDerivativesM 
) [private]

Definition at line 756 of file MillePedeAlignmentAlgorithm.cc.

References i.

{

  for (unsigned int i = 0; i < globalDerivativesx.size(); ++i) {
    aGlobalDerivativesM(0,i) = globalDerivativesx[i];
    aGlobalDerivativesM(1,i) = globalDerivativesy[i]; 
  }
}
bool MillePedeAlignmentAlgorithm::readFromPede ( const edm::ParameterSet mprespset,
bool  setUserVars,
const RunRange runrange 
) [private]

read pede input defined by 'psetName', flag to create/not create MillePedeVariables

Definition at line 519 of file MillePedeAlignmentAlgorithm.cc.

References areEmptyParams(), dbtoconf::out, PedeReader::read(), theAlignables, thePedeLabels, and thePedeSteer.

Referenced by initialize(), setParametersForRunRange(), and terminate().

{
  bool allEmpty = this->areEmptyParams(theAlignables);

  PedeReader reader(mprespset, *thePedeSteer, *thePedeLabels, runrange);
  std::vector<Alignable*> alis;
  bool okRead = reader.read(alis, setUserVars);
  bool numMatch = true;
  
  std::stringstream out("Read ");
  out << alis.size() << " alignables";
  if (alis.size() != theAlignables.size()) {
    out << " while " << theAlignables.size() << " in store";
    numMatch = false; // FIXME: Should we check one by one? Or transfer 'alis' to the store?
  }
  if (!okRead) out << ", but problems in reading"; 
  if (!allEmpty) out << ", possibly overwriting previous settings";
  out << ".";

  if (okRead && allEmpty) {
    if (numMatch) { // as many alignables with result as trying to align
      edm::LogInfo("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::readFromPede" << out.str();
    } else if (alis.size()) { // dead module do not get hits and no pede result
      edm::LogWarning("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::readFromPede" << out.str();
    } else { // serious problem: no result read - and not all modules can be dead...
      edm::LogError("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::readFromPede" << out.str();
      return false;
    }
    return true;
  }
  // the rest is not OK:
  edm::LogError("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::readFromPede" << out.str();
  return false;
}
void MillePedeAlignmentAlgorithm::run ( const edm::EventSetup setup,
const EventInfo eventInfo 
) [virtual]

Run the algorithm on trajectories and tracks.

Implements AlignmentAlgorithmBase.

Definition at line 280 of file MillePedeAlignmentAlgorithm.cc.

References addReferenceTrajectory(), AlignmentAlgorithmBase::EventInfo::beamSpot_, MillePedeMonitor::fillRefTrajectory(), MillePedeMonitor::fillTrack(), MillePedeMonitor::fillUsedTrack(), isMode(), myMilleBit, theMonitor, theTrajectoryFactory, testEve_cfg::tracks, TrajectoryFactoryBase::trajectories(), and AlignmentAlgorithmBase::EventInfo::trajTrackPairs_.

{
  if (!this->isMode(myMilleBit)) return; // no theMille created...
  const ConstTrajTrackPairCollection &tracks = eventInfo.trajTrackPairs_;

  if (theMonitor) { // monitor input tracks
    for (ConstTrajTrackPairCollection::const_iterator iTrajTrack = tracks.begin();
         iTrajTrack != tracks.end(); ++iTrajTrack) {
      theMonitor->fillTrack((*iTrajTrack).second);
    }
  }

  const RefTrajColl trajectories(theTrajectoryFactory->trajectories(setup, tracks, eventInfo.beamSpot_));

  // Now loop over ReferenceTrajectoryCollection
  unsigned int refTrajCount = 0; // counter for track monitoring if 1 track per trajectory
  for (RefTrajColl::const_iterator iRefTraj = trajectories.begin(), iRefTrajE = trajectories.end();
       iRefTraj != iRefTrajE; ++iRefTraj, ++refTrajCount) {

    RefTrajColl::value_type refTrajPtr = *iRefTraj; 
    if (theMonitor) theMonitor->fillRefTrajectory(refTrajPtr);

    const std::pair<unsigned int, unsigned int> nHitXy = this->addReferenceTrajectory(eventInfo, refTrajPtr);

    if (theMonitor && (nHitXy.first || nHitXy.second)) {
      // if track used (i.e. some hits), fill monitoring
      // track NULL ptr if trajectories and tracks do not match
      const reco::Track *trackPtr = 
        (trajectories.size() == tracks.size() ? tracks[refTrajCount].second : 0);
      theMonitor->fillUsedTrack(trackPtr, nHitXy.first, nHitXy.second);
    }

  } // end of reference trajectory and track loop
}
void MillePedeAlignmentAlgorithm::setParametersForRunRange ( const RunRange runrange) [virtual]

called in order to pass parameters to alignables for a specific run range in case the algorithm supports run range dependent alignment.

Reimplemented from AlignmentAlgorithmBase.

Definition at line 227 of file MillePedeAlignmentAlgorithm.cc.

References AlignmentParameterStore::applyParameters(), edm::ParameterSet::getParameter(), isMode(), myPedeReadBit, readFromPede(), theAlignmentParameterStore, and theConfig.

{
  if (this->isMode(myPedeReadBit)) {
    if (!this->readFromPede(theConfig.getParameter<edm::ParameterSet>("pedeReader"), true, runrange)) {
      edm::LogError("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::terminate"
                                 << "Problems reading pede result, but applying!";
    }
    theAlignmentParameterStore->applyParameters();
  }
}
void MillePedeAlignmentAlgorithm::terminate ( void  ) [virtual]

Call at end of job.

Implements AlignmentAlgorithmBase.

Definition at line 240 of file MillePedeAlignmentAlgorithm.cc.

References AlignmentParameterStore::applyParameters(), PedeSteerer::buildMasterSteer(), doIO(), electronDbsDiscovery::files, edm::ParameterSet::getParameter(), i, isMode(), myMilleBit, myPedeReadBit, myPedeRunBit, readFromPede(), cond::runnumber, PedeSteerer::runPede(), theAlignmentParameterStore, theConfig, theDir, theMille, thePedeSteer, and cond::timeTypeSpecs.

{
  delete theMille;// delete to close binary before running pede below (flush would be enough...)
  theMille = 0;

  std::vector<std::string> files;
  if (this->isMode(myMilleBit) || !theConfig.getParameter<std::string>("binaryFile").empty()) {
    files.push_back(theDir + theConfig.getParameter<std::string>("binaryFile"));
  } else {
    const std::vector<std::string> plainFiles
      (theConfig.getParameter<std::vector<std::string> >("mergeBinaryFiles"));
    for (std::vector<std::string>::const_iterator i = plainFiles.begin(), iEnd = plainFiles.end();
         i != iEnd; ++i) {
      files.push_back(theDir + *i);
    }
  }
  const std::string masterSteer(thePedeSteer->buildMasterSteer(files));// do only if myPedeSteerBit?
  if (this->isMode(myPedeRunBit)) {
    thePedeSteer->runPede(masterSteer);
  }
  
  if (this->isMode(myPedeReadBit)) {
    RunRange runrange(cond::timeTypeSpecs[cond::runnumber].beginValue,
                      cond::timeTypeSpecs[cond::runnumber].endValue);
    if (!this->readFromPede(theConfig.getParameter<edm::ParameterSet>("pedeReader"), true, runrange)) {
      edm::LogError("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::terminate"
                                 << "Problems reading pede result, but applying!";
    }
    theAlignmentParameterStore->applyParameters();
  }

  if (this->isMode(myMilleBit)) { // if mille was run, we store trees with suffix _1...
    this->doIO(1);
  } else if (this->isMode(myPedeReadBit)) {// if pede runs otherwise, we use _2 (=> probably merge)
    this->doIO(2);
  }
}

Member Data Documentation

Definition at line 186 of file MillePedeAlignmentAlgorithm.h.

Referenced by addHitStatistics(), doIO(), initialize(), and readFromPede().

directory for all kind of files

Definition at line 185 of file MillePedeAlignmentAlgorithm.h.

Referenced by initialize(), setParametersForRunRange(), and terminate().

std::string MillePedeAlignmentAlgorithm::theDir [private]

Definition at line 199 of file MillePedeAlignmentAlgorithm.h.

Referenced by initialize().

std::vector<float> MillePedeAlignmentAlgorithm::theFloatBufferX [private]

maximal correlation allowed for 2D hit in TID/TEC. If larger, the 2D measurement gets diagonalized!!!

Definition at line 196 of file MillePedeAlignmentAlgorithm.h.

Referenced by addLasBeam(), and addMeasurementData().

std::vector<float> MillePedeAlignmentAlgorithm::theFloatBufferY [private]

Definition at line 197 of file MillePedeAlignmentAlgorithm.h.

Referenced by addLasBeam(), and addMeasurementData().

std::vector<int> MillePedeAlignmentAlgorithm::theIntBuffer [private]

Definition at line 198 of file MillePedeAlignmentAlgorithm.h.

Referenced by addLasBeam(), and addMeasurementData().

Definition at line 194 of file MillePedeAlignmentAlgorithm.h.

Definition at line 193 of file MillePedeAlignmentAlgorithm.h.

Referenced by addReferenceTrajectory().

unsigned int MillePedeAlignmentAlgorithm::theMode [private]

Definition at line 183 of file MillePedeAlignmentAlgorithm.h.

Referenced by isMode().

Definition at line 192 of file MillePedeAlignmentAlgorithm.h.

Referenced by initialize(), run(), and ~MillePedeAlignmentAlgorithm().