CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MillePedeAlignmentAlgorithm.cc
Go to the documentation of this file.
1 
12 //#include "MillePedeAlignmentAlgorithm.h"
13 
17 
19 // in header, too
20 // end in header, too
21 
25 #include "Mille.h" // 'unpublished' interface located in src
26 #include "PedeSteerer.h" // dito
27 #include "PedeReader.h" // dito
30 
33 
37 
41 
42 // includes to make known that they inherit from Alignable:
46 
52 
57 
59 
60 #include <fstream>
61 #include <sstream>
62 #include <algorithm>
63 #include <sys/stat.h>
64 
65 #include <TMath.h>
66 #include <TMatrixDSymEigen.h>
70 
71 // Includes for PXB survey
72 #include <iostream>
79 
81 
82 
83 
84 
85 // Constructor ----------------------------------------------------------------
86 //____________________________________________________
89  theConfig(cfg), theMode(this->decodeMode(theConfig.getUntrackedParameter<std::string>("mode"))),
90  theDir(theConfig.getUntrackedParameter<std::string>("fileDir")),
91  theAlignmentParameterStore(0), theAlignables(), theAlignableNavigator(0),
92  theMonitor(0), theMille(0), thePedeLabels(0), thePedeSteer(0),
93  theTrajectoryFactory(0),
94  theMinNumHits(cfg.getParameter<unsigned int>("minNumHits")),
95  theMaximalCor2D(cfg.getParameter<double>("max2Dcorrelation")),
96  theLastWrittenIov(0),
97  theBinary(0),theGblDoubleBinary(cfg.getParameter<bool>("doubleBinary"))
98 {
99  if (!theDir.empty() && theDir.find_last_of('/') != theDir.size()-1) theDir += '/';// may need '/'
100  edm::LogInfo("Alignment") << "@SUB=MillePedeAlignmentAlgorithm" << "Start in mode '"
102  << "' with output directory '" << theDir << "'.";
103  if (this->isMode(myMilleBit)) {
104  theMille = new Mille((theDir + theConfig.getParameter<std::string>("binaryFile")).c_str());// add ', false);' for text output);
105  // use same file for GBL
107  }
108 }
109 
110 // Destructor ----------------------------------------------------------------
111 //____________________________________________________
113 {
114  delete theAlignableNavigator;
116  delete theMille;
117  theMille = 0;
118  delete theMonitor;
119  theMonitor = 0;
120  delete thePedeSteer;
121  thePedeSteer = 0;
122  delete thePedeLabels;
123  thePedeLabels = 0;
124  delete theTrajectoryFactory;
126 }
127 
128 // Call at beginning of job ---------------------------------------------------
129 //____________________________________________________
133 {
134  if (muon) {
135  edm::LogWarning("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::initialize"
136  << "Running with AlignabeMuon not yet tested.";
137  }
138 
139  //Retrieve tracker topology from geometry
140  edm::ESHandle<TrackerTopology> tTopoHandle;
141  setup.get<IdealGeometryRecord>().get(tTopoHandle);
142  const TrackerTopology* const tTopo = tTopoHandle.product();
143 
144  theAlignableNavigator = new AlignableNavigator(extras, tracker, muon);
147 
148  edm::ParameterSet pedeLabelerCfg(theConfig.getParameter<edm::ParameterSet>("pedeLabeler"));
149  edm::VParameterSet RunRangeSelectionVPSet(theConfig.getUntrackedParameter<edm::VParameterSet>("RunRangeSelection"));
150  pedeLabelerCfg.addUntrackedParameter<edm::VParameterSet>("RunRangeSelection",
151  RunRangeSelectionVPSet);
152 
153  std::string labelerPlugin = "PedeLabeler";
154  if (RunRangeSelectionVPSet.size()>0) {
155  labelerPlugin = "RunRangeDependentPedeLabeler";
156  if (pedeLabelerCfg.exists("plugin")) {
157  std::string labelerPluginCfg = pedeLabelerCfg.getParameter<std::string>("plugin");
158  if ((labelerPluginCfg!="PedeLabeler" && labelerPluginCfg!="RunRangeDependentPedeLabeler") ||
159  pedeLabelerCfg.getUntrackedParameter<edm::VParameterSet>("parameterInstances").size()>0) {
160  throw cms::Exception("BadConfig")
161  << "MillePedeAlignmentAlgorithm::initialize"
162  << "both RunRangeSelection and generic labeler specified in config file. "
163  << "Please get rid of either one of them.\n";
164  }
165  }
166  } else {
167  if (pedeLabelerCfg.exists("plugin")) {
168  labelerPlugin = pedeLabelerCfg.getParameter<std::string>("plugin");
169  }
170  }
171 
172  if (!pedeLabelerCfg.exists("plugin")) {
173  pedeLabelerCfg.addUntrackedParameter<std::string>("plugin", labelerPlugin);
174  }
175 
176  edm::LogInfo("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::initialize"
177  << "Using plugin '" << labelerPlugin << "' to generate labels.";
178 
179  thePedeLabels = PedeLabelerPluginFactory::get()->create(labelerPlugin,
180  PedeLabelerBase::TopLevelAlignables(tracker, muon, extras),
181  pedeLabelerCfg);
182 
183  // 1) Create PedeSteerer: correct alignable positions for coordinate system selection
184  edm::ParameterSet pedeSteerCfg(theConfig.getParameter<edm::ParameterSet>("pedeSteerer"));
185  thePedeSteer = new PedeSteerer(tracker, muon, extras,
187  pedeSteerCfg, theDir, !this->isMode(myPedeSteerBit));
188 
189  // 2) If requested, directly read in and apply result of previous pede run,
190  // assuming that correction from 1) was also applied to create the result:
191  const std::vector<edm::ParameterSet> mprespset
192  (theConfig.getParameter<std::vector<edm::ParameterSet> >("pedeReaderInputs"));
193  if (!mprespset.empty()) {
194  edm::LogInfo("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::initialize"
195  << "Apply " << mprespset.end() - mprespset.begin()
196  << " previous MillePede constants from 'pedeReaderInputs'.";
197  }
198 
199  // FIXME: add selection of run range via 'pedeReaderInputs'
200  // Note: Results for parameters of IntegratedCalibration's cannot be treated...
201  RunRange runrange(cond::timeTypeSpecs[cond::runnumber].beginValue,
203  for (std::vector<edm::ParameterSet>::const_iterator iSet = mprespset.begin(), iE = mprespset.end();
204  iSet != iE; ++iSet) {
205  // This read will ignore calibrations as long as they are not yet passed to Millepede
206  // during/before initialize(..) - currently addCalibrations(..) is called later in AlignmentProducer
207  if (!this->readFromPede((*iSet), false, runrange)) { // false: do not erase SelectionUserVariables
208  throw cms::Exception("BadConfig")
209  << "MillePedeAlignmentAlgorithm::initialize: Problems reading input constants of "
210  << "pedeReaderInputs entry " << iSet - mprespset.begin() << '.';
211  }
213  // Needed to shut up later warning from checkAliParams:
215  }
216 
217  // 3) Now create steerings with 'final' start position:
218  thePedeSteer->buildSubSteer(tracker, muon, extras);
219 
220  // After (!) 1-3 of PedeSteerer which uses the SelectionUserVariables attached to the parameters:
221  this->buildUserVariables(theAlignables); // for hit statistics and/or pede result
222 
223  if (this->isMode(myMilleBit)) {
224  if (!theConfig.getParameter<std::vector<std::string> >("mergeBinaryFiles").empty() ||
225  !theConfig.getParameter<std::vector<std::string> >("mergeTreeFiles").empty()) {
226  throw cms::Exception("BadConfig")
227  << "'vstring mergeTreeFiles' and 'vstring mergeBinaryFiles' must be empty for "
228  << "modes running mille.";
229  }
230  const std::string moniFile(theConfig.getUntrackedParameter<std::string>("monitorFile"));
231  if (moniFile.size()) theMonitor = new MillePedeMonitor(tTopo, (theDir + moniFile).c_str());
232 
233  // Get trajectory factory. In case nothing found, FrameWork will throw...
234  const edm::ParameterSet fctCfg(theConfig.getParameter<edm::ParameterSet>("TrajectoryFactory"));
235  const std::string fctName(fctCfg.getParameter<std::string>("TrajectoryFactoryName"));
236  theTrajectoryFactory = TrajectoryFactoryPlugin::get()->create(fctName, fctCfg);
237  }
238 
239  if (this->isMode(myPedeSteerBit)) {
240  // Get config for survey and set flag accordingly
241  const edm::ParameterSet pxbSurveyCfg(theConfig.getParameter<edm::ParameterSet>("surveyPixelBarrel"));
242  theDoSurveyPixelBarrel = pxbSurveyCfg.getParameter<bool>("doSurvey");
243  if (theDoSurveyPixelBarrel) this->addPxbSurvey(pxbSurveyCfg);
244  }
245 }
246 
247 //____________________________________________________
249  return true;
250 }
251 
252 //____________________________________________________
253 bool MillePedeAlignmentAlgorithm::addCalibrations(const std::vector<IntegratedCalibrationBase*> &iCals)
254 {
255  theCalibrations.insert(theCalibrations.end(), iCals.begin(), iCals.end());
257  return true;
258 }
259 
260 //_____________________________________________________________________________
262 {
263  if (isMode(myMilleBit)) {
264  return true;
265  } else {
266  return false;
267  }
268 }
269 
270 //____________________________________________________
272 {
273  if (this->isMode(myPedeReadBit)) {
274  // restore initial positions, rotations and deformations
276 
277  // Needed to shut up later warning from checkAliParams:
279  // To avoid that they keep values from previous IOV if no new one in pede result
281 
282  if (!this->readFromPede(theConfig.getParameter<edm::ParameterSet>("pedeReader"), true, runrange)) {
283  edm::LogError("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::setParametersForRunRange"
284  << "Problems reading pede result, but applying!";
285  }
287 
288  this->doIO(++theLastWrittenIov); // pre-increment!
289  }
290 
291  return true;
292 }
293 
294 // Call at end of job ---------------------------------------------------------
295 //____________________________________________________
297 {
298  terminate();
299 }
301 {
302  delete theMille;// delete to close binary before running pede below (flush would be enough...)
303  theMille = 0;
304 
305  std::vector<std::string> files;
306  if (this->isMode(myMilleBit) || !theConfig.getParameter<std::string>("binaryFile").empty()) {
307  files.push_back(theDir + theConfig.getParameter<std::string>("binaryFile"));
308  } else {
309  const std::vector<std::string> plainFiles(theConfig.getParameter<std::vector<std::string> >("mergeBinaryFiles"));
310  files = getExistingFormattedFiles(plainFiles, theDir);
311  // Do some logging:
312  std::string filesForLogOutput;
313  for (std::vector<std::string>::const_iterator i = files.begin(), iEnd = files.end(); i != iEnd; ++i) {
314  filesForLogOutput += " " + *i;
315  }
316  edm::LogInfo("Alignment") << "Based on the config parameter mergeBinaryFiles, using the following files as input:" << filesForLogOutput;
317  }
318 
319  // cache all positions, rotations and deformations
321 
322  const std::string masterSteer(thePedeSteer->buildMasterSteer(files));// do only if myPedeSteerBit?
323  if (this->isMode(myPedeRunBit)) {
324  thePedeSteer->runPede(masterSteer);
325  }
326 
327  // parameters from pede are not yet applied,
328  // so we can still write start positions (but with hit statistics in case of mille):
329  this->doIO(0);
330  theLastWrittenIov = 0;
331 }
332 
333 std::vector<std::string> MillePedeAlignmentAlgorithm::getExistingFormattedFiles(const std::vector<std::string> plainFiles, std::string theDir) {
334  std::vector<std::string> files;
335  for (std::vector<std::string>::const_iterator i = plainFiles.begin(), iEnd = plainFiles.end(); i != iEnd; ++i) {
336  std::string theInputFileName = *i;
337  int theNumber = 0;
338  while (true) {
339  // Create a formatted version of the filename, with growing numbers
340  // If the parameter doesn't contain a formatting directive, it just stays unchanged
341  char theNumberedInputFileName[200];
342  sprintf(theNumberedInputFileName, theInputFileName.c_str(), theNumber);
343  std::string theCompleteInputFileName = theDir + theNumberedInputFileName;
344  // Check if the file exists
345  struct stat buffer;
346  if (stat (theCompleteInputFileName.c_str(), &buffer) == 0) {
347  // If the file exists, add it to the list
348  files.push_back(theCompleteInputFileName);
349  if (theNumberedInputFileName == theInputFileName) {
350  // If the filename didn't contain a formatting directive, no reason to look any further, break out of the loop
351  break;
352  } else {
353  // Otherwise look for the next number
354  theNumber++;
355  }
356  } else {
357  // The file doesn't exist, break out of the loop
358  break;
359  }
360  }
361  }
362  return files;
363 }
364 
365 // Run the algorithm on trajectories and tracks -------------------------------
366 //____________________________________________________
368 {
369  if (!this->isMode(myMilleBit)) return; // no theMille created...
371 
372  if (theMonitor) { // monitor input tracks
373  for (ConstTrajTrackPairCollection::const_iterator iTrajTrack = tracks.begin();
374  iTrajTrack != tracks.end(); ++iTrajTrack) {
375  theMonitor->fillTrack((*iTrajTrack).second);
376  }
377  }
378 
379  const RefTrajColl trajectories(theTrajectoryFactory->trajectories(setup, tracks, eventInfo.beamSpot()));
380 
381  // Now loop over ReferenceTrajectoryCollection
382  unsigned int refTrajCount = 0; // counter for track monitoring if 1 track per trajectory
383  for (RefTrajColl::const_iterator iRefTraj = trajectories.begin(), iRefTrajE = trajectories.end();
384  iRefTraj != iRefTrajE; ++iRefTraj, ++refTrajCount) {
385 
386  RefTrajColl::value_type refTrajPtr = *iRefTraj;
387  if (theMonitor) theMonitor->fillRefTrajectory(refTrajPtr);
388 
389  const std::pair<unsigned int, unsigned int> nHitXy
390  = this->addReferenceTrajectory(setup, eventInfo, refTrajPtr);
391 
392  if (theMonitor && (nHitXy.first || nHitXy.second)) {
393  // if track used (i.e. some hits), fill monitoring
394  // track NULL ptr if trajectories and tracks do not match
395  const reco::Track *trackPtr =
396  (trajectories.size() == tracks.size() ? tracks[refTrajCount].second : 0);
397  theMonitor->fillUsedTrack(trackPtr, nHitXy.first, nHitXy.second);
398  }
399 
400  } // end of reference trajectory and track loop
401 }
402 
403 //____________________________________________________
404 std::pair<unsigned int, unsigned int>
406  const EventInfo &eventInfo,
407  const RefTrajColl::value_type &refTrajPtr)
408 {
409  std::pair<unsigned int, unsigned int> hitResultXy(0,0);
410  if (refTrajPtr->isValid()) {
411 
412 
413  // GblTrajectory?
414  if (refTrajPtr->gblInput().size() > 0) {
415  // by construction: number of GblPoints == number of recHits or == zero !!!
416  unsigned int iHit = 0;
417  unsigned int numPointsWithMeas = 0;
418  std::vector<GblPoint>::iterator itPoint;
419  std::vector<std::pair<std::vector<GblPoint>, TMatrixD> > theGblInput = refTrajPtr->gblInput();
420  for (unsigned int iTraj = 0; iTraj < refTrajPtr->gblInput().size(); ++iTraj) {
421  for (itPoint = refTrajPtr->gblInput()[iTraj].first.begin(); itPoint < refTrajPtr->gblInput()[iTraj].first.end(); ++itPoint) {
422  if (this->addGlobalData(setup, eventInfo, refTrajPtr, iHit++, *itPoint) < 0) return hitResultXy;
423  if (itPoint->hasMeasurement() >= 1) ++numPointsWithMeas;
424  }
425  }
426  hitResultXy.first = numPointsWithMeas;
427  // check #hits criterion
428  if (hitResultXy.first == 0 || hitResultXy.first < theMinNumHits) return hitResultXy;
429  // construct GBL trajectory
430  if (refTrajPtr->gblInput().size() == 1) {
431  // from single track
432  GblTrajectory aGblTrajectory( refTrajPtr->gblInput()[0].first, refTrajPtr->nominalField() != 0 );
433  // GBL fit trajectory
434  /*double Chi2;
435  int Ndf;
436  double lostWeight;
437  aGblTrajectory.fit(Chi2, Ndf, lostWeight);
438  std::cout << " GblFit: " << Chi2 << ", " << Ndf << ", " << lostWeight << std::endl; */
439  // write to MP binary file
440  if (aGblTrajectory.isValid() && aGblTrajectory.getNumPoints() >= theMinNumHits) aGblTrajectory.milleOut(*theBinary);
441  }
442  if (refTrajPtr->gblInput().size() == 2) {
443  // from TwoBodyDecay
444  GblTrajectory aGblTrajectory( refTrajPtr->gblInput(), refTrajPtr->gblExtDerivatives(), refTrajPtr->gblExtMeasurements(), refTrajPtr->gblExtPrecisions() );
445  // write to MP binary file
446  if (aGblTrajectory.isValid() && aGblTrajectory.getNumPoints() >= theMinNumHits) aGblTrajectory.milleOut(*theBinary);
447  }
448  } else {
449  // to add hits if all fine:
450  std::vector<AlignmentParameters*> parVec(refTrajPtr->recHits().size());
451  // collect hit statistics, assuming that there are no y-only hits
452  std::vector<bool> validHitVecY(refTrajPtr->recHits().size(), false);
453  // Use recHits from ReferenceTrajectory (since they have the right order!):
454  for (unsigned int iHit = 0; iHit < refTrajPtr->recHits().size(); ++iHit) {
455  const int flagXY = this->addMeasurementData(setup, eventInfo, refTrajPtr, iHit, parVec[iHit]);
456 
457  if (flagXY < 0) { // problem
458  hitResultXy.first = 0;
459  break;
460  } else { // hit is fine, increase x/y statistics
461  if (flagXY >= 1) ++hitResultXy.first;
462  validHitVecY[iHit] = (flagXY >= 2);
463  }
464  } // end loop on hits
465 
466  // add virtual measurements
467  for (unsigned int iVirtualMeas = 0; iVirtualMeas < refTrajPtr->numberOfVirtualMeas(); ++iVirtualMeas) {
468  this->addVirtualMeas(refTrajPtr, iVirtualMeas);
469  }
470 
471  // kill or end 'track' for mille, depends on #hits criterion
472  if (hitResultXy.first == 0 || hitResultXy.first < theMinNumHits) {
473  theMille->kill();
474  hitResultXy.first = hitResultXy.second = 0; //reset
475  } else {
476  theMille->end();
477  // add x/y hit count to MillePedeVariables of parVec,
478  // returning number of y-hits of the reference trajectory
479  hitResultXy.second = this->addHitCount(parVec, validHitVecY);
480  //
481  }
482  }
483 
484  } // end if valid trajectory
485 
486  return hitResultXy;
487 }
488 
489 //____________________________________________________
490 unsigned int
491 MillePedeAlignmentAlgorithm::addHitCount(const std::vector<AlignmentParameters*> &parVec,
492  const std::vector<bool> &validHitVecY) const
493 {
494  // Loop on all hit information in the input arrays and count valid y-hits:
495  unsigned int nHitY = 0;
496  for (unsigned int iHit = 0; iHit < validHitVecY.size(); ++iHit) {
497  Alignable *ali = (parVec[iHit] ? parVec[iHit]->alignable() : 0);
498  // Loop upwards on hierarchy of alignables to add hits to all levels
499  // that are currently aligned. If only a non-selected alignable was hit,
500  // (i.e. flagXY == 0 in addReferenceTrajectory(..)), there is no loop at all...
501  while (ali) {
503  if (pars) { // otherwise hierarchy level not selected
504  // cast ensured by previous checks:
505  MillePedeVariables *mpVar = static_cast<MillePedeVariables*>(pars->userVariables());
506  // every hit has an x-measurement, cf. addReferenceTrajectory(..):
507  mpVar->increaseHitsX();
508  if (validHitVecY[iHit]) {
509  mpVar->increaseHitsY();
510  if (pars == parVec[iHit]) ++nHitY; // do not count hits twice
511  }
512  }
513  ali = ali->mother();
514  }
515  }
516 
517  return nHitY;
518 }
519 
520 //____________________________________________________
522  const edm::EventSetup &setup)
523 {
524  if(runInfo.tkLasBeams() && runInfo.tkLasBeamTsoses()){
525  // LAS beam treatment
526  this->addLaserData(eventInfo, *(runInfo.tkLasBeams()), *(runInfo.tkLasBeamTsoses()));
527  }
529 }
530 
531 // Implementation of endRun that DOES get called. (Because we need it.)
534 }
535 
536 
537 //____________________________________________________
539  const EventInfo &eventInfo,
541  unsigned int iHit,
542  AlignmentParameters *&params)
543 {
544  params = 0;
545  theFloatBufferX.clear();
546  theFloatBufferY.clear();
547  theIntBuffer.clear();
548 
549  const TrajectoryStateOnSurface &tsos = refTrajPtr->trajectoryStates()[iHit];
550  const ConstRecHitPointer &recHitPtr = refTrajPtr->recHits()[iHit];
551  // ignore invalid hits
552  if (!recHitPtr->isValid()) return 0;
553 
554  // First add the derivatives from IntegratedCalibration's,
555  // should even be OK if problems for "usual" derivatives from Alignables
556  this->globalDerivativesCalibration(recHitPtr, tsos, setup, eventInfo, // input
558 
559  // get AlignableDet/Unit for this hit
560  AlignableDetOrUnitPtr alidet(theAlignableNavigator->alignableFromDetId(recHitPtr->geographicalId()));
561 
562  if (!this->globalDerivativesHierarchy(eventInfo,
563  tsos, alidet, alidet, theFloatBufferX, // 2x alidet, sic!
564  theFloatBufferY, theIntBuffer, params)) {
565  return -1; // problem
566  } else if (theFloatBufferX.empty()) {
567  return 0; // empty for X: no alignable for hit, nor calibrations
568  } else { // now even if no alignable, but calibrations!
569  return this->callMille(refTrajPtr, iHit, theIntBuffer, theFloatBufferX, theFloatBufferY);
570  }
571 }
572 
573 //____________________________________________________
574 
577  unsigned int iHit, GblPoint &gblPoint)
578 {
579  AlignmentParameters* params = 0;
580  std::vector<double> theDoubleBufferX, theDoubleBufferY;
581  theDoubleBufferX.clear();
582  theDoubleBufferY.clear();
583  theIntBuffer.clear();
584  int iret = 0;
585 
586  const TrajectoryStateOnSurface &tsos = refTrajPtr->trajectoryStates()[iHit];
587  const ConstRecHitPointer &recHitPtr = refTrajPtr->recHits()[iHit];
588  // ignore invalid hits
589  if (!recHitPtr->isValid()) return 0;
590 
591  // get AlignableDet/Unit for this hit
592  AlignableDetOrUnitPtr alidet(theAlignableNavigator->alignableFromDetId(recHitPtr->geographicalId()));
593 
594  if (!this->globalDerivativesHierarchy(eventInfo,
595  tsos, alidet, alidet, theDoubleBufferX, // 2x alidet, sic!
596  theDoubleBufferY, theIntBuffer, params)) {
597  return -1; // problem
598  }
599  //calibration parameters
600  int globalLabel;
601  std::vector<IntegratedCalibrationBase::ValuesIndexPair> derivs;
602  for (auto iCalib = theCalibrations.begin(); iCalib != theCalibrations.end(); ++iCalib) {
603  // get all derivatives of this calibration // const unsigned int num =
604  (*iCalib)->derivatives(derivs, *recHitPtr, tsos, setup, eventInfo);
605  for (auto iValuesInd = derivs.begin(); iValuesInd != derivs.end(); ++iValuesInd) {
606  // transfer label and x/y derivatives
607  globalLabel = thePedeLabels->calibrationLabel(*iCalib, iValuesInd->second);
608  if (globalLabel > 0 && globalLabel <= 2147483647) {
609  theIntBuffer.push_back(globalLabel);
610  theDoubleBufferX.push_back(iValuesInd->first.first);
611  theDoubleBufferY.push_back(iValuesInd->first.second);
612  } else {
613  std::cerr << "MillePedeAlignmentAlgorithm::addGlobalData: Invalid label " << globalLabel << " <= 0 or > 2147483647" << std::endl;
614  }
615  }
616  }
617  unsigned int numGlobals = theIntBuffer.size();
618  if (numGlobals > 0)
619  {
620  TMatrixD globalDer(2,numGlobals);
621  for (unsigned int i = 0; i < numGlobals; ++i) {
622  globalDer(0,i) = theDoubleBufferX[i];
623  globalDer(1,i) = theDoubleBufferY[i];
624  }
625  gblPoint.addGlobals( theIntBuffer, globalDer );
626  iret = 1;
627  }
628  return iret;
629 }
630 
631 //____________________________________________________
634  const TrajectoryStateOnSurface &tsos,
635  Alignable *ali, const AlignableDetOrUnitPtr &alidet,
636  std::vector<float> &globalDerivativesX,
637  std::vector<float> &globalDerivativesY,
638  std::vector<int> &globalLabels,
639  AlignmentParameters *&lowestParams) const
640 {
641  // derivatives and labels are recursively attached
642  if (!ali) return true; // no mother might be OK
643 
644  if (false && theMonitor && alidet != ali) theMonitor->fillFrameToFrame(alidet, ali);
645 
646  AlignmentParameters *params = ali->alignmentParameters();
647 
648  if (params) {
649  if (!lowestParams) lowestParams = params; // set parameters of lowest level
650 
651  bool hasSplitParameters = thePedeLabels->hasSplitParameters(ali);
652  const unsigned int alignableLabel = thePedeLabels->alignableLabel(ali);
653 
654  if (0 == alignableLabel) { // FIXME: what about regardAllHits in Markus' code?
655  edm::LogWarning("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::globalDerivativesHierarchy"
656  << "Label not found, skip Alignable.";
657  return false;
658  }
659 
660  const std::vector<bool> &selPars = params->selector();
661  const AlgebraicMatrix derivs(params->derivatives(tsos, alidet));
662 
663  // cols: 2, i.e. x&y, rows: parameters, usually RigidBodyAlignmentParameters::N_PARAM
664  for (unsigned int iSel = 0; iSel < selPars.size(); ++iSel) {
665  if (selPars[iSel]) {
666  globalDerivativesX.push_back(derivs[iSel][kLocalX]
667  /thePedeSteer->cmsToPedeFactor(iSel));
668  if (hasSplitParameters==true) {
669  globalLabels.push_back(thePedeLabels->parameterLabel(ali, iSel, eventInfo, tsos));
670  } else {
671  globalLabels.push_back(thePedeLabels->parameterLabel(alignableLabel, iSel));
672  }
673  globalDerivativesY.push_back(derivs[iSel][kLocalY]
674  /thePedeSteer->cmsToPedeFactor(iSel));
675  }
676  }
677  // Exclude mothers if Alignable selected to be no part of a hierarchy:
678  if (thePedeSteer->isNoHiera(ali)) return true;
679  }
680  // Call recursively for mother, will stop if mother == 0:
681  return this->globalDerivativesHierarchy(eventInfo,
682  tsos, ali->mother(), alidet,
683  globalDerivativesX, globalDerivativesY,
684  globalLabels, lowestParams);
685 }
686 
687 //____________________________________________________
690  const TrajectoryStateOnSurface &tsos,
691  Alignable *ali, const AlignableDetOrUnitPtr &alidet,
692  std::vector<double> &globalDerivativesX,
693  std::vector<double> &globalDerivativesY,
694  std::vector<int> &globalLabels,
695  AlignmentParameters *&lowestParams) const
696 {
697  // derivatives and labels are recursively attached
698  if (!ali) return true; // no mother might be OK
699 
700  if (false && theMonitor && alidet != ali) theMonitor->fillFrameToFrame(alidet, ali);
701 
702  AlignmentParameters *params = ali->alignmentParameters();
703 
704  if (params) {
705  if (!lowestParams) lowestParams = params; // set parameters of lowest level
706 
707  bool hasSplitParameters = thePedeLabels->hasSplitParameters(ali);
708  const unsigned int alignableLabel = thePedeLabels->alignableLabel(ali);
709 
710  if (0 == alignableLabel) { // FIXME: what about regardAllHits in Markus' code?
711  edm::LogWarning("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::globalDerivativesHierarchy"
712  << "Label not found, skip Alignable.";
713  return false;
714  }
715 
716  const std::vector<bool> &selPars = params->selector();
717  const AlgebraicMatrix derivs(params->derivatives(tsos, alidet));
718  int globalLabel;
719 
720  // cols: 2, i.e. x&y, rows: parameters, usually RigidBodyAlignmentParameters::N_PARAM
721  for (unsigned int iSel = 0; iSel < selPars.size(); ++iSel) {
722  if (selPars[iSel]) {
723  if (hasSplitParameters==true) {
724  globalLabel = thePedeLabels->parameterLabel(ali, iSel, eventInfo, tsos);
725  } else {
726  globalLabel = thePedeLabels->parameterLabel(alignableLabel, iSel);
727  }
728  if (globalLabel > 0 && globalLabel <= 2147483647) {
729  globalLabels.push_back(globalLabel);
730  globalDerivativesX.push_back(derivs[iSel][kLocalX] / thePedeSteer->cmsToPedeFactor(iSel));
731  globalDerivativesY.push_back(derivs[iSel][kLocalY] / thePedeSteer->cmsToPedeFactor(iSel));
732  } else {
733  std::cerr << "MillePedeAlignmentAlgorithm::globalDerivativesHierarchy: Invalid label " << globalLabel << " <= 0 or > 2147483647" << std::endl;
734  }
735  }
736  }
737  // Exclude mothers if Alignable selected to be no part of a hierarchy:
738  if (thePedeSteer->isNoHiera(ali)) return true;
739  }
740  // Call recursively for mother, will stop if mother == 0:
741  return this->globalDerivativesHierarchy(eventInfo,
742  tsos, ali->mother(), alidet,
743  globalDerivativesX, globalDerivativesY,
744  globalLabels, lowestParams);
745 }
746 
747 //____________________________________________________
750  const TrajectoryStateOnSurface &tsos,
751  const edm::EventSetup &setup, const EventInfo &eventInfo,
752  std::vector<float> &globalDerivativesX,
753  std::vector<float> &globalDerivativesY,
754  std::vector<int> &globalLabels) const
755 {
756  std::vector<IntegratedCalibrationBase::ValuesIndexPair> derivs;
757  for (auto iCalib = theCalibrations.begin(); iCalib != theCalibrations.end(); ++iCalib) {
758  // get all derivatives of this calibration // const unsigned int num =
759  (*iCalib)->derivatives(derivs, *recHit, tsos, setup, eventInfo);
760  for (auto iValuesInd = derivs.begin(); iValuesInd != derivs.end(); ++iValuesInd) {
761  // transfer label and x/y derivatives
762  globalLabels.push_back(thePedeLabels->calibrationLabel(*iCalib, iValuesInd->second));
763  globalDerivativesX.push_back(iValuesInd->first.first);
764  globalDerivativesY.push_back(iValuesInd->first.second);
765  }
766  }
767 }
768 
769 // //____________________________________________________
770 // void MillePedeAlignmentAlgorithm
771 // ::callMille(const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr,
772 // unsigned int iTrajHit, MeasurementDirection xOrY,
773 // const std::vector<float> &globalDerivatives, const std::vector<int> &globalLabels)
774 // {
775 // const unsigned int xyIndex = iTrajHit*2 + xOrY;
776 // // FIXME: here for residuum and sigma we could use KALMAN-Filter results
777 // const float residuum =
778 // refTrajPtr->measurements()[xyIndex] - refTrajPtr->trajectoryPositions()[xyIndex];
779 // const float covariance = refTrajPtr->measurementErrors()[xyIndex][xyIndex];
780 // const float sigma = (covariance > 0. ? TMath::Sqrt(covariance) : 0.);
781 
782 // const AlgebraicMatrix &locDerivMatrix = refTrajPtr->derivatives();
783 
784 // std::vector<float> localDerivs(locDerivMatrix.num_col());
785 // for (unsigned int i = 0; i < localDerivs.size(); ++i) {
786 // localDerivs[i] = locDerivMatrix[xyIndex][i];
787 // }
788 
789 // // &(vector[0]) is valid - as long as vector is not empty
790 // // cf. http://www.parashift.com/c++-faq-lite/containers.html#faq-34.3
791 // theMille->mille(localDerivs.size(), &(localDerivs[0]),
792 // globalDerivatives.size(), &(globalDerivatives[0]), &(globalLabels[0]),
793 // residuum, sigma);
794 // if (theMonitor) {
795 // theMonitor->fillDerivatives(refTrajPtr->recHits()[iTrajHit],localDerivs, globalDerivatives,
796 // (xOrY == kLocalY));
797 // theMonitor->fillResiduals(refTrajPtr->recHits()[iTrajHit],
798 // refTrajPtr->trajectoryStates()[iTrajHit],
799 // iTrajHit, residuum, sigma, (xOrY == kLocalY));
800 // }
801 // }
802 
803 //____________________________________________________
805 {
806  // FIXME: Check whether this is a reliable and recommended way to find out...
807 
808  if (recHit->dimension() < 2) {
809  return false; // some muon and TIB/TOB stuff really has RecHit1D
810  } else if (recHit->detUnit()) { // detunit in strip is 1D, in pixel 2D
811  return recHit->detUnit()->type().isTrackerPixel();
812  } else { // stereo strips (FIXME: endcap trouble due to non-parallel strips (wedge sensors)?)
813  if (dynamic_cast<const ProjectedSiStripRecHit2D*>(recHit->hit())) { // check persistent hit
814  // projected: 1D measurement on 'glued' module
815  return false;
816  } else {
817  return true;
818  }
819  }
820 }
821 
822 //__________________________________________________________________________________________________
823 bool MillePedeAlignmentAlgorithm::readFromPede(const edm::ParameterSet &mprespset, bool setUserVars,
824  const RunRange &runrange)
825 {
826  bool allEmpty = this->areEmptyParams(theAlignables);
827 
828  PedeReader reader(mprespset, *thePedeSteer, *thePedeLabels, runrange);
829  std::vector<Alignable*> alis;
830  bool okRead = reader.read(alis, setUserVars); // also may set params of IntegratedCalibration's
831  bool numMatch = true;
832 
833  std::stringstream out;
834  out << "Read " << alis.size() << " alignables";
835  if (alis.size() != theAlignables.size()) {
836  out << " while " << theAlignables.size() << " in store";
837  numMatch = false; // FIXME: Should we check one by one? Or transfer 'alis' to the store?
838  }
839  if (!okRead) out << ", but problems in reading";
840  if (!allEmpty) out << ", possibly overwriting previous settings";
841  out << ".";
842 
843  if (okRead && allEmpty) {
844  if (numMatch) { // as many alignables with result as trying to align
845  edm::LogInfo("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::readFromPede" << out.str();
846  } else if (alis.size()) { // dead module do not get hits and no pede result
847  edm::LogWarning("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::readFromPede" << out.str();
848  } else { // serious problem: no result read - and not all modules can be dead...
849  edm::LogError("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::readFromPede" << out.str();
850  return false;
851  }
852  return true;
853  }
854  // the rest is not OK:
855  edm::LogError("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::readFromPede" << out.str();
856  return false;
857 }
858 
859 //__________________________________________________________________________________________________
860 bool MillePedeAlignmentAlgorithm::areEmptyParams(const std::vector<Alignable*> &alignables) const
861 {
862 
863  for (std::vector<Alignable*>::const_iterator iAli = alignables.begin();
864  iAli != alignables.end(); ++iAli) {
865  const AlignmentParameters *params = (*iAli)->alignmentParameters();
866  if (params) {
867  const AlgebraicVector &parVec(params->parameters());
868  const AlgebraicMatrix &parCov(params->covariance());
869  for (int i = 0; i < parVec.num_row(); ++i) {
870  if (parVec[i] != 0.) return false;
871  for (int j = i; j < parCov.num_col(); ++j) {
872  if (parCov[i][j] != 0.) return false;
873  }
874  }
875  }
876  }
877 
878  return true;
879 }
880 
881 //__________________________________________________________________________________________________
883 {
884  unsigned int result = 0;
885 
886  const std::string outFilePlain(theConfig.getParameter<std::string>("treeFile"));
887  if (outFilePlain.empty()) {
888  edm::LogInfo("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::doIO"
889  << "treeFile parameter empty => skip writing for 'loop' " << loop;
890  return result;
891  }
892 
893  const std::string outFile(theDir + outFilePlain);
894 
895  AlignmentIORoot aliIO;
896  int ioerr = 0;
897  if (loop == 0) {
898  aliIO.writeAlignableOriginalPositions(theAlignables, outFile.c_str(), loop, false, ioerr);
899  if (ioerr) {
900  edm::LogError("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::doIO"
901  << "Problem " << ioerr << " in writeAlignableOriginalPositions";
902  ++result;
903  }
904  } else if (loop == 1) {
905  // only for first iov add hit counts, else 2x, 3x,... number of hits in IOV 2, 3,...
906  const std::vector<std::string> inFiles
907  (theConfig.getParameter<std::vector<std::string> >("mergeTreeFiles"));
908  const std::vector<std::string> binFiles
909  (theConfig.getParameter<std::vector<std::string> >("mergeBinaryFiles"));
910  if (inFiles.size() != binFiles.size()) {
911  edm::LogWarning("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::doIO"
912  << "'vstring mergeTreeFiles' and 'vstring mergeBinaryFiles' "
913  << "differ in size";
914  }
915  this->addHitStatistics(0, outFile, inFiles); // add hit info from tree 0 in 'infiles'
916  }
917  MillePedeVariablesIORoot millePedeIO;
918  millePedeIO.writeMillePedeVariables(theAlignables, outFile.c_str(), loop, false, ioerr);
919  if (ioerr) {
920  edm::LogError("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::doIO"
921  << "Problem " << ioerr << " writing MillePedeVariables";
922  ++result;
923  }
924 
925  aliIO.writeOrigRigidBodyAlignmentParameters(theAlignables, outFile.c_str(), loop, false, ioerr);
926  if (ioerr) {
927  edm::LogError("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::doIO" << "Problem " << ioerr
928  << " in writeOrigRigidBodyAlignmentParameters, " << loop;
929  ++result;
930  }
931  aliIO.writeAlignableAbsolutePositions(theAlignables, outFile.c_str(), loop, false, ioerr);
932  if (ioerr) {
933  edm::LogError("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::doIO" << "Problem " << ioerr
934  << " in writeAlignableAbsolutePositions, " << loop;
935  ++result;
936  }
937 
938  return result;
939 }
940 
941 //__________________________________________________________________________________________________
942 void MillePedeAlignmentAlgorithm::buildUserVariables(const std::vector<Alignable*> &alis) const
943 {
944  for (std::vector<Alignable*>::const_iterator iAli = alis.begin(); iAli != alis.end(); ++iAli) {
945  AlignmentParameters *params = (*iAli)->alignmentParameters();
946  if (!params) {
947  throw cms::Exception("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::buildUserVariables"
948  << "No parameters for alignable";
949  }
950  MillePedeVariables *userVars = dynamic_cast<MillePedeVariables*>(params->userVariables());
951  if (userVars) { // Just re-use existing, keeping label and numHits:
952  for (unsigned int iPar = 0; iPar < userVars->size(); ++iPar) {
953  // if (params->hierarchyLevel() > 0) {
954  //std::cout << params->hierarchyLevel() << "\nBefore: " << userVars->parameter()[iPar];
955  // }
956  userVars->setAllDefault(iPar);
957  //std::cout << "\nAfter: " << userVars->parameter()[iPar] << std::endl;
958  }
959  } else { // Nothing yet or erase wrong type:
960  userVars = new MillePedeVariables(params->size(), thePedeLabels->alignableLabel(*iAli));
961  params->setUserVariables(userVars);
962  }
963  }
964 }
965 
966 //__________________________________________________________________________________________________
968 {
969  if (mode == "full") {
971  } else if (mode == "mille") {
972  return myMilleBit; // + myPedeSteerBit; // sic! Including production of steerig file. NO!
973  } else if (mode == "pede") {
975  } else if (mode == "pedeSteer") {
976  return myPedeSteerBit;
977  } else if (mode == "pedeRun") {
978  return myPedeSteerBit + myPedeRunBit + myPedeReadBit; // sic! Including steering and reading of result.
979  } else if (mode == "pedeRead") {
980  return myPedeReadBit;
981  }
982 
983  throw cms::Exception("BadConfig")
984  << "Unknown mode '" << mode
985  << "', use 'full', 'mille', 'pede', 'pedeRun', 'pedeSteer' or 'pedeRead'.";
986 
987  return 0;
988 }
989 
990 //__________________________________________________________________________________________________
992  const std::vector<std::string> &inFiles) const
993 {
994  bool allOk = true;
995  int ierr = 0;
996  MillePedeVariablesIORoot millePedeIO;
997  for (std::vector<std::string>::const_iterator iFile = inFiles.begin();
998  iFile != inFiles.end(); ++iFile) {
999  const std::string inFile(theDir + *iFile);
1000  const std::vector<AlignmentUserVariables*> mpVars =
1001  millePedeIO.readMillePedeVariables(theAlignables, inFile.c_str(), fromIov, ierr);
1002  if (ierr || !this->addHits(theAlignables, mpVars)) {
1003  edm::LogError("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::addHitStatistics"
1004  << "Error " << ierr << " reading from " << inFile
1005  << ", tree " << fromIov << ", or problems in addHits";
1006  allOk = false;
1007  }
1008  for (std::vector<AlignmentUserVariables*>::const_iterator i = mpVars.begin();
1009  i != mpVars.end(); ++i) {
1010  delete *i; // clean created objects
1011  }
1012  }
1013 
1014  return allOk;
1015 }
1016 
1017 //__________________________________________________________________________________________________
1018 bool MillePedeAlignmentAlgorithm::addHits(const std::vector<Alignable*> &alis,
1019  const std::vector<AlignmentUserVariables*> &mpVars) const
1020 {
1021  bool allOk = (mpVars.size() == alis.size());
1022  std::vector<AlignmentUserVariables*>::const_iterator iUser = mpVars.begin();
1023  for (std::vector<Alignable*>::const_iterator iAli = alis.begin();
1024  iAli != alis.end() && iUser != mpVars.end(); ++iAli, ++iUser) {
1025  MillePedeVariables *mpVarNew = dynamic_cast<MillePedeVariables*>(*iUser);
1026  AlignmentParameters *ps = (*iAli)->alignmentParameters();
1027  MillePedeVariables *mpVarOld = (ps ? dynamic_cast<MillePedeVariables*>(ps->userVariables()) : 0);
1028  if (!mpVarNew || !mpVarOld || mpVarOld->size() != mpVarNew->size()) {
1029  allOk = false;
1030  continue; // FIXME error etc.?
1031  }
1032 
1033  mpVarOld->increaseHitsX(mpVarNew->hitsX());
1034  mpVarOld->increaseHitsY(mpVarNew->hitsY());
1035  }
1036 
1037  return allOk;
1038 }
1039 
1040 //__________________________________________________________________________________________________
1041 void MillePedeAlignmentAlgorithm::makeGlobDerivMatrix(const std::vector<float> &globalDerivativesx,
1042  const std::vector<float> &globalDerivativesy,
1043  TMatrixF &aGlobalDerivativesM)
1044 {
1045 
1046  for (unsigned int i = 0; i < globalDerivativesx.size(); ++i) {
1047  aGlobalDerivativesM(0,i) = globalDerivativesx[i];
1048  aGlobalDerivativesM(1,i) = globalDerivativesy[i];
1049  }
1050 }
1051 
1052 //__________________________________________________________________________________________________
1054 (TMatrixDSym &aHitCovarianceM, TMatrixF &aLocalDerivativesM, TMatrixF &aHitResidualsM,
1055  TMatrixF &aGlobalDerivativesM) const
1056 {
1057  TMatrixDSymEigen myDiag(aHitCovarianceM);
1058  TMatrixD aTranfoToDiagonalSystem = myDiag.GetEigenVectors();
1059  TMatrixD aTranfoToDiagonalSystemInv = myDiag.GetEigenVectors( );
1060  TMatrixF aTranfoToDiagonalSystemInvF = myDiag.GetEigenVectors( );
1061  TMatrixD aMatrix = aTranfoToDiagonalSystemInv.Invert() * aHitCovarianceM * aTranfoToDiagonalSystem;
1062  // Tranformation of matrix M is done by A^T*M*A, not A^{-1}*M*A.
1063  // But here A^T == A^{-1}, so we would only save CPU by Transpose()...
1064  // FIXME this - I guess simply use T(), not Transpose()...
1065  // TMatrixD aMatrix = aTranfoToDiagonalSystemInv.Transpose() * aHitCovarianceM
1066  // * aTranfoToDiagonalSystem;
1067  aHitCovarianceM = TMatrixDSym(2, aMatrix.GetMatrixArray());
1068  aTranfoToDiagonalSystemInvF.Invert();
1069  //edm::LogInfo("Alignment") << "NEW HIT loca in matrix"<<aLocalDerivativesM(0,0);
1070  aLocalDerivativesM = aTranfoToDiagonalSystemInvF * aLocalDerivativesM;
1071 
1072  //edm::LogInfo("Alignment") << "NEW HIT loca in matrix after diag:"<<aLocalDerivativesM(0,0);
1073  aHitResidualsM = aTranfoToDiagonalSystemInvF * aHitResidualsM;
1074  aGlobalDerivativesM = aTranfoToDiagonalSystemInvF * aGlobalDerivativesM;
1075 }
1076 
1077 //__________________________________________________________________________________________________
1080  unsigned int iVirtualMeas, TMatrixDSym &aHitCovarianceM,
1081  TMatrixF &aHitResidualsM, TMatrixF &aLocalDerivativesM)
1082 {
1083  // This Method is valid for 1D measurements only
1084 
1085  const unsigned int xIndex = iVirtualMeas + refTrajPtr->numberOfHitMeas();
1086  // Covariance into a TMatrixDSym
1087 
1088  //aHitCovarianceM = new TMatrixDSym(1);
1089  aHitCovarianceM(0,0)=refTrajPtr->measurementErrors()[xIndex][xIndex];
1090 
1091  //theHitResidualsM= new TMatrixF(1,1);
1092  aHitResidualsM(0,0)= refTrajPtr->measurements()[xIndex];
1093 
1094  // Local Derivatives into a TMatrixDSym (to use matrix operations)
1095  const AlgebraicMatrix &locDerivMatrix = refTrajPtr->derivatives();
1096  // theLocalDerivativeNumber = locDerivMatrix.num_col();
1097 
1098  //theLocalDerivativesM = new TMatrixF(1,locDerivMatrix.num_col());
1099  for (int i = 0; i < locDerivMatrix.num_col(); ++i) {
1100  aLocalDerivativesM(0,i) = locDerivMatrix[xIndex][i];
1101  }
1102 }
1103 
1104 //__________________________________________________________________________________________________
1107  unsigned int iTrajHit, TMatrixDSym &aHitCovarianceM,
1108  TMatrixF &aHitResidualsM, TMatrixF &aLocalDerivativesM)
1109 {
1110  // This Method is valid for 2D measurements only
1111 
1112  const unsigned int xIndex = iTrajHit*2;
1113  const unsigned int yIndex = iTrajHit*2+1;
1114  // Covariance into a TMatrixDSym
1115 
1116  //aHitCovarianceM = new TMatrixDSym(2);
1117  aHitCovarianceM(0,0)=refTrajPtr->measurementErrors()[xIndex][xIndex];
1118  aHitCovarianceM(0,1)=refTrajPtr->measurementErrors()[xIndex][yIndex];
1119  aHitCovarianceM(1,0)=refTrajPtr->measurementErrors()[yIndex][xIndex];
1120  aHitCovarianceM(1,1)=refTrajPtr->measurementErrors()[yIndex][yIndex];
1121 
1122  //theHitResidualsM= new TMatrixF(2,1);
1123  aHitResidualsM(0,0)= refTrajPtr->measurements()[xIndex] - refTrajPtr->trajectoryPositions()[xIndex];
1124  aHitResidualsM(1,0)= refTrajPtr->measurements()[yIndex] - refTrajPtr->trajectoryPositions()[yIndex];
1125 
1126  // Local Derivatives into a TMatrixDSym (to use matrix operations)
1127  const AlgebraicMatrix &locDerivMatrix = refTrajPtr->derivatives();
1128  // theLocalDerivativeNumber = locDerivMatrix.num_col();
1129 
1130  //theLocalDerivativesM = new TMatrixF(2,locDerivMatrix.num_col());
1131  for (int i = 0; i < locDerivMatrix.num_col(); ++i) {
1132  aLocalDerivativesM(0,i) = locDerivMatrix[xIndex][i];
1133  aLocalDerivativesM(1,i) = locDerivMatrix[yIndex][i];
1134  }
1135 }
1136 
1137 //__________________________________________________________________________________________________
1140  unsigned int iTrajHit, const std::vector<int> &globalLabels,
1141  const std::vector<float> &globalDerivativesX,
1142  const std::vector<float> &globalDerivativesY)
1143 {
1144  const ConstRecHitPointer aRecHit(refTrajPtr->recHits()[iTrajHit]);
1145 
1146  if((aRecHit)->dimension() == 1) {
1147  return this->callMille1D(refTrajPtr, iTrajHit, globalLabels, globalDerivativesX);
1148  } else {
1149  return this->callMille2D(refTrajPtr, iTrajHit, globalLabels,
1150  globalDerivativesX, globalDerivativesY);
1151  }
1152 }
1153 
1154 
1155 //__________________________________________________________________________________________________
1158  unsigned int iTrajHit, const std::vector<int> &globalLabels,
1159  const std::vector<float> &globalDerivativesX)
1160 {
1161  const ConstRecHitPointer aRecHit(refTrajPtr->recHits()[iTrajHit]);
1162  const unsigned int xIndex = iTrajHit*2; // the even ones are local x
1163 
1164  // local derivatives
1165  const AlgebraicMatrix &locDerivMatrix = refTrajPtr->derivatives();
1166  const int nLocal = locDerivMatrix.num_col();
1167  std::vector<float> localDerivatives(nLocal);
1168  for (unsigned int i = 0; i < localDerivatives.size(); ++i) {
1169  localDerivatives[i] = locDerivMatrix[xIndex][i];
1170  }
1171 
1172  // residuum and error
1173  float residX = refTrajPtr->measurements()[xIndex] - refTrajPtr->trajectoryPositions()[xIndex];
1174  float hitErrX = TMath::Sqrt(refTrajPtr->measurementErrors()[xIndex][xIndex]);
1175 
1176  // number of global derivatives
1177  const int nGlobal = globalDerivativesX.size();
1178 
1179  // &(localDerivatives[0]) etc. are valid - as long as vector is not empty
1180  // cf. http://www.parashift.com/c++-faq-lite/containers.html#faq-34.3
1181  theMille->mille(nLocal, &(localDerivatives[0]), nGlobal, &(globalDerivativesX[0]),
1182  &(globalLabels[0]), residX, hitErrX);
1183 
1184  if (theMonitor) {
1185  theMonitor->fillDerivatives(aRecHit, &(localDerivatives[0]), nLocal,
1186  &(globalDerivativesX[0]), nGlobal, &(globalLabels[0]));
1187  theMonitor->fillResiduals(aRecHit, refTrajPtr->trajectoryStates()[iTrajHit],
1188  iTrajHit, residX, hitErrX, false);
1189  }
1190 
1191  return 1;
1192 }
1193 
1194 //__________________________________________________________________________________________________
1197  unsigned int iTrajHit, const std::vector<int> &globalLabels,
1198  const std::vector<float> &globalDerivativesx,
1199  const std::vector<float> &globalDerivativesy)
1200 {
1201  const ConstRecHitPointer aRecHit(refTrajPtr->recHits()[iTrajHit]);
1202 
1203  if((aRecHit)->dimension() != 2) {
1204  edm::LogError("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::callMille2D"
1205  << "You try to call method for 2D hits for a "
1206  << (aRecHit)->dimension()
1207  << "D Hit. Hit gets ignored!";
1208  return -1;
1209  }
1210 
1211  TMatrixDSym aHitCovarianceM(2);
1212  TMatrixF aHitResidualsM(2,1);
1213  TMatrixF aLocalDerivativesM(2, refTrajPtr->derivatives().num_col());
1214  // below method fills above 3 matrices
1215  this->addRefTrackData2D(refTrajPtr, iTrajHit, aHitCovarianceM,aHitResidualsM,aLocalDerivativesM);
1216  TMatrixF aGlobalDerivativesM(2,globalDerivativesx.size());
1217  this->makeGlobDerivMatrix(globalDerivativesx, globalDerivativesy, aGlobalDerivativesM);
1218 
1219  // calculates correlation between Hit measurements
1220  // FIXME: Should take correlation (and resulting transformation) from original hit,
1221  // not 2x2 matrix from ReferenceTrajectory: That can come from error propagation etc.!
1222  const double corr = aHitCovarianceM(0,1) / sqrt(aHitCovarianceM(0,0) * aHitCovarianceM(1,1));
1223  if (theMonitor) theMonitor->fillCorrelations2D(corr, aRecHit);
1224  bool diag = false; // diagonalise only tracker TID, TEC
1225  switch(aRecHit->geographicalId().subdetId()) {
1226  case SiStripDetId::TID:
1227  case SiStripDetId::TEC:
1228  if (aRecHit->geographicalId().det() == DetId::Tracker && TMath::Abs(corr) > theMaximalCor2D) {
1229  this->diagonalize(aHitCovarianceM, aLocalDerivativesM, aHitResidualsM, aGlobalDerivativesM);
1230  diag = true;
1231  }
1232  break;
1233  default:;
1234  }
1235 
1236  float newResidX = aHitResidualsM(0,0);
1237  float newResidY = aHitResidualsM(1,0);
1238  float newHitErrX = TMath::Sqrt(aHitCovarianceM(0,0));
1239  float newHitErrY = TMath::Sqrt(aHitCovarianceM(1,1));
1240  float *newLocalDerivsX = aLocalDerivativesM[0].GetPtr();
1241  float *newLocalDerivsY = aLocalDerivativesM[1].GetPtr();
1242  float *newGlobDerivsX = aGlobalDerivativesM[0].GetPtr();
1243  float *newGlobDerivsY = aGlobalDerivativesM[1].GetPtr();
1244  const int nLocal = aLocalDerivativesM.GetNcols();
1245  const int nGlobal = aGlobalDerivativesM.GetNcols();
1246 
1247  if (diag && (newHitErrX > newHitErrY)) { // also for 2D hits?
1248  // measurement with smaller error is x-measurement (for !is2D do not fill y-measurement):
1249  std::swap(newResidX, newResidY);
1250  std::swap(newHitErrX, newHitErrY);
1251  std::swap(newLocalDerivsX, newLocalDerivsY);
1252  std::swap(newGlobDerivsX, newGlobDerivsY);
1253  }
1254 
1255  // &(globalLabels[0]) is valid - as long as vector is not empty
1256  // cf. http://www.parashift.com/c++-faq-lite/containers.html#faq-34.3
1257  theMille->mille(nLocal, newLocalDerivsX, nGlobal, newGlobDerivsX,
1258  &(globalLabels[0]), newResidX, newHitErrX);
1259 
1260  if (theMonitor) {
1261  theMonitor->fillDerivatives(aRecHit, newLocalDerivsX, nLocal, newGlobDerivsX, nGlobal,
1262  &(globalLabels[0]));
1263  theMonitor->fillResiduals(aRecHit, refTrajPtr->trajectoryStates()[iTrajHit],
1264  iTrajHit, newResidX, newHitErrX, false);
1265  }
1266  const bool isReal2DHit = this->is2D(aRecHit); // strip is 1D (except matched hits)
1267  if (isReal2DHit) {
1268  theMille->mille(nLocal, newLocalDerivsY, nGlobal, newGlobDerivsY,
1269  &(globalLabels[0]), newResidY, newHitErrY);
1270  if (theMonitor) {
1271  theMonitor->fillDerivatives(aRecHit, newLocalDerivsY, nLocal, newGlobDerivsY, nGlobal,
1272  &(globalLabels[0]));
1273  theMonitor->fillResiduals(aRecHit, refTrajPtr->trajectoryStates()[iTrajHit],
1274  iTrajHit, newResidY, newHitErrY, true);// true: y
1275  }
1276  }
1277 
1278  return (isReal2DHit ? 2 : 1);
1279 }
1280 
1281 //__________________________________________________________________________________________________
1283 ::addVirtualMeas(const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr, unsigned int iVirtualMeas)
1284 {
1285  TMatrixDSym aHitCovarianceM(1);
1286  TMatrixF aHitResidualsM(1,1);
1287  TMatrixF aLocalDerivativesM(1, refTrajPtr->derivatives().num_col());
1288  // below method fills above 3 'matrices'
1289  this->addRefTrackVirtualMeas1D(refTrajPtr, iVirtualMeas, aHitCovarianceM, aHitResidualsM, aLocalDerivativesM);
1290 
1291  // no global parameters (use dummy 0)
1292  TMatrixF aGlobalDerivativesM(1,1);
1293  aGlobalDerivativesM(0,0) = 0;
1294 
1295  float newResidX = aHitResidualsM(0,0);
1296  float newHitErrX = TMath::Sqrt(aHitCovarianceM(0,0));
1297  float *newLocalDerivsX = aLocalDerivativesM[0].GetPtr();
1298  float *newGlobDerivsX = aGlobalDerivativesM[0].GetPtr();
1299  const int nLocal = aLocalDerivativesM.GetNcols();
1300  const int nGlobal = 0;
1301 
1302  theMille->mille(nLocal, newLocalDerivsX, nGlobal, newGlobDerivsX,
1303  &nGlobal, newResidX, newHitErrX);
1304 }
1305 
1306 //____________________________________________________
1308  const TkFittedLasBeamCollection &lasBeams,
1309  const TsosVectorCollection &lasBeamTsoses)
1310 {
1311  TsosVectorCollection::const_iterator iTsoses = lasBeamTsoses.begin();
1312  for(TkFittedLasBeamCollection::const_iterator iBeam = lasBeams.begin(), iEnd = lasBeams.end();
1313  iBeam != iEnd; ++iBeam, ++iTsoses){ // beam/tsoses parallel!
1314 
1315  edm::LogInfo("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::addLaserData"
1316  << "Beam " << iBeam->getBeamId() << " with "
1317  << iBeam->parameters().size() << " parameters and "
1318  << iBeam->getData().size() << " hits.\n There are "
1319  << iTsoses->size() << " TSOSes.";
1320 
1321  this->addLasBeam(eventInfo, *iBeam, *iTsoses);
1322  }
1323 }
1324 
1325 //____________________________________________________
1327  const TkFittedLasBeam &lasBeam,
1328  const std::vector<TrajectoryStateOnSurface> &tsoses)
1329 {
1330  AlignmentParameters *dummyPtr = 0; // for globalDerivativesHierarchy()
1331  std::vector<float> lasLocalDerivsX; // buffer for local derivatives
1332  const unsigned int beamLabel = thePedeLabels->lasBeamLabel(lasBeam.getBeamId());// for global par
1333 
1334  for (unsigned int iHit = 0; iHit < tsoses.size(); ++iHit) {
1335  if (!tsoses[iHit].isValid()) continue;
1336  // clear buffer
1337  theFloatBufferX.clear();
1338  theFloatBufferY.clear();
1339  theIntBuffer.clear();
1340  lasLocalDerivsX.clear();
1341  // get alignables and global parameters
1342  const SiStripLaserRecHit2D &hit = lasBeam.getData()[iHit];
1344  this->globalDerivativesHierarchy(eventInfo,
1345  tsoses[iHit], lasAli, lasAli,
1347  // fill derivatives vector from derivatives matrix
1348  for (unsigned int nFitParams = 0;
1349  nFitParams < static_cast<unsigned int>(lasBeam.parameters().size());
1350  ++nFitParams) {
1351  const float derivative = lasBeam.derivatives()[iHit][nFitParams];
1352  if (nFitParams < lasBeam.firstFixedParameter()) { // first local beam parameters
1353  lasLocalDerivsX.push_back(derivative);
1354  } else { // now global ones
1355  const unsigned int numPar = nFitParams - lasBeam.firstFixedParameter();
1356  theIntBuffer.push_back(thePedeLabels->parameterLabel(beamLabel, numPar));
1357  theFloatBufferX.push_back(derivative);
1358  }
1359  } // end loop over parameters
1360 
1361  const float residual = hit.localPosition().x() - tsoses[iHit].localPosition().x();
1362  // error from file or assume 0.003
1363  const float error = 0.003; // hit.localPositionError().xx(); sqrt???
1364 
1365  theMille->mille(lasLocalDerivsX.size(), &(lasLocalDerivsX[0]), theFloatBufferX.size(),
1366  &(theFloatBufferX[0]), &(theIntBuffer[0]), residual, error);
1367  } // end of loop over hits
1368 
1369  theMille->end();
1370 }
1371 
1373 {
1374  // do some printing, if requested
1375  const bool doOutputOnStdout(pxbSurveyCfg.getParameter<bool>("doOutputOnStdout"));
1376  if (doOutputOnStdout) std::cout << "# Output from addPxbSurvey follows below because doOutputOnStdout is set to True" << std::endl;
1377 
1378  // instantiate a dicer object
1379  SurveyPxbDicer dicer(pxbSurveyCfg.getParameter<std::vector<edm::ParameterSet> >("toySurveyParameters"), pxbSurveyCfg.getParameter<unsigned int>("toySurveySeed"));
1380  std::ofstream outfile(pxbSurveyCfg.getUntrackedParameter<std::string>("toySurveyFile").c_str());
1381 
1382  // read data from file
1383  std::vector<SurveyPxbImageLocalFit> measurements;
1384  std::string filename(pxbSurveyCfg.getParameter<edm::FileInPath>("infile").fullPath());
1386 
1387  // loop over photographs (=measurements) and perform the fit
1388  for(std::vector<SurveyPxbImageLocalFit>::size_type i=0; i!=measurements.size(); i++)
1389  {
1390  if (doOutputOnStdout) std::cout << "Module " << i << ": ";
1391 
1392  // get the Alignables and their surfaces
1393  AlignableDetOrUnitPtr mod1(theAlignableNavigator->alignableFromDetId(measurements[i].getIdFirst()));
1394  AlignableDetOrUnitPtr mod2(theAlignableNavigator->alignableFromDetId(measurements[i].getIdSecond()));
1395  const AlignableSurface& surf1 = mod1->surface();
1396  const AlignableSurface& surf2 = mod2->surface();
1397 
1398  // the position of the fiducial points in local frame of a PXB module
1399  const LocalPoint fidpoint0(-0.91,+3.30);
1400  const LocalPoint fidpoint1(+0.91,+3.30);
1401  const LocalPoint fidpoint2(+0.91,-3.30);
1402  const LocalPoint fidpoint3(-0.91,-3.30);
1403 
1404  // We choose the local frame of the first module as reference,
1405  // so take the fidpoints of the second module and calculate their
1406  // positions in the reference frame
1407  const GlobalPoint surf2point0(surf2.toGlobal(fidpoint0));
1408  const GlobalPoint surf2point1(surf2.toGlobal(fidpoint1));
1409  const LocalPoint fidpoint0inSurf1frame(surf1.toLocal(surf2point0));
1410  const LocalPoint fidpoint1inSurf1frame(surf1.toLocal(surf2point1));
1411 
1412  // Create the vector for the fit
1414  fidpointvec.push_back(fidpoint0inSurf1frame);
1415  fidpointvec.push_back(fidpoint1inSurf1frame);
1416  fidpointvec.push_back(fidpoint2);
1417  fidpointvec.push_back(fidpoint3);
1418 
1419  // if toy survey is requested, dice the values now
1420  if (pxbSurveyCfg.getParameter<bool>("doToySurvey"))
1421  {
1422  dicer.doDice(fidpointvec,measurements[i].getIdPair(), outfile);
1423  }
1424 
1425  // do the fit
1426  measurements[i].doFit(fidpointvec, thePedeLabels->alignableLabel(mod1), thePedeLabels->alignableLabel(mod2));
1427  SurveyPxbImageLocalFit::localpars_t a; // local pars from fit
1428  a = measurements[i].getLocalParameters();
1429  const SurveyPxbImageLocalFit::value_t chi2 = measurements[i].getChi2();
1430 
1431  // do some reporting, if requested
1432  if (doOutputOnStdout)
1433  {
1434  std::cout << "a: " << a[0] << ", " << a[1] << ", " << a[2] << ", " << a[3]
1435  << " S= " << sqrt(a[2]*a[2]+a[3]*a[3])
1436  << " phi= " << atan(a[3]/a[2])
1437  << " chi2= " << chi2 << std::endl;
1438  }
1439  if (theMonitor)
1440  {
1442  theMonitor->fillPxbSurveyHistsLocalPars(a[0],a[1],sqrt(a[2]*a[2]+a[3]*a[3]),atan(a[3]/a[2]));
1443  }
1444 
1445  // pass the results from the local fit to mille
1447  {
1448  theMille->mille((int)measurements[i].getLocalDerivsSize(),
1449  measurements[i].getLocalDerivsPtr(j),
1450  (int)measurements[i].getGlobalDerivsSize(),
1451  measurements[i].getGlobalDerivsPtr(j),
1452  measurements[i].getGlobalDerivsLabelPtr(j),
1453  measurements[i].getResiduum(j),
1454  measurements[i].getSigma(j));
1455  }
1456  theMille->end();
1457  }
1458  outfile.close();
1459 }
1460 
virtual bool processesEvents() override
Returns whether MP should process events in the current configuration.
unsigned int hitsX() const
get number of hits for x-measurement
const TimeTypeSpecs timeTypeSpecs[]
Definition: Time.cc:22
T getParameter(std::string const &) const
unsigned int firstFixedParameter() const
GBL trajectory.
Definition: GblTrajectory.h:26
void globalDerivativesCalibration(const TransientTrackingRecHit::ConstRecHitPointer &recHit, const TrajectoryStateOnSurface &tsos, const edm::EventSetup &setup, const EventInfo &eventInfo, std::vector< float > &globalDerivativesX, std::vector< float > &globalDerivativesY, std::vector< int > &globalLabels) const
adding derivatives from integrated calibrations
T getUntrackedParameter(std::string const &, T const &) const
std::vector< AlignmentUserVariables * > readMillePedeVariables(const std::vector< Alignable * > &alivec, const char *filename, int iter, int &ierr)
int i
Definition: DBlmapReader.cc:9
unsigned int size() const
number of parameters
void resetParameters(void)
reset parameters, correlations, user variables
virtual bool supportsCalibrations() override
Returns whether MP supports calibrations.
tuple cfg
Definition: looper.py:259
void increaseHitsX(unsigned int add=1)
increase hits for x-measurement
bool read(std::vector< Alignable * > &alignables, bool setUserVars)
Definition: PedeReader.cc:52
Derivative< X, A >::type derivative(const A &_)
Definition: Derivative.h:18
virtual void endRun(const EventInfo &, const EndRunInfo &, const edm::EventSetup &)
Run on run products, e.g. TkLAS.
std::vector< coord_t > fidpoint_t
void increaseHitsY(unsigned int add=1)
increase hits for y-measurement
std::vector< Alignable * > theAlignables
TrajectoryFactoryBase::ReferenceTrajectoryCollection RefTrajColl
std::vector< ParameterSet > VParameterSet
Definition: ParameterSet.h:33
virtual unsigned int alignableLabel(Alignable *alignable) const =0
void writeAlignableOriginalPositions(const align::Alignables &alivec, const char *filename, int iter, bool validCheck, int &ierr)
write Alignable original (before misalignment) absolute positions
void fillPxbSurveyHistsLocalPars(const float &a0, const float &a1, const float &S, const float &phi)
bool exists(std::string const &parameterName) const
checks if a parameter exists
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
void restoreCachedTransformations(void)
restore the previously cached position, rotation and other parameters
void applyParameters(void)
Obsolete: Use AlignableNavigator::alignableDetFromDetId and alignableFromAlignableDet.
unsigned int addHitCount(const std::vector< AlignmentParameters * > &parVec, const std::vector< bool > &validHitVecY) const
int loop
CMSSW
virtual LocalPoint localPosition() const
const AlgebraicMatrix & derivatives() const
matrix of local derivatives: columns are parameters, rows are hits
const std::vector< bool > & selector(void) const
Get alignment parameter selector vector.
int callMille2D(const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr, unsigned int iTrajHit, const std::vector< int > &globalLabels, const std::vector< float > &globalDerivativesx, const std::vector< float > &globalDerivativesy)
std::pair< RunNumber, RunNumber > RunRange
virtual unsigned int lasBeamLabel(unsigned int lasBeamId) const =0
virtual void initialize(const edm::EventSetup &setup, AlignableTracker *tracker, AlignableMuon *muon, AlignableExtras *extras, AlignmentParameterStore *store)
Called at beginning of job.
uint16_t size_type
void addLasBeam(const EventInfo &eventInfo, const TkFittedLasBeam &lasBeam, const std::vector< TrajectoryStateOnSurface > &tsoses)
AlignmentParameters * alignmentParameters() const
Get the AlignmentParameters.
Definition: Alignable.h:57
const ConstTrajTrackPairCollection & trajTrackPairs() const
void fillPxbSurveyHistsChi2(const float &chi2)
define event information passed to algorithms
virtual unsigned int parameterLabel(unsigned int aliLabel, unsigned int parNum) const =0
returns the label for a given alignable parameter number combination
unsigned int doIO(int loop) const
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
TransientTrackingRecHit::ConstRecHitPointer ConstRecHitPointer
const AlgebraicVector & parameters(void) const
Get alignment parameters.
std::string doDice(const fidpoint_t &fidpointvec, const idPair_t &id, const bool rotate=false)
AlignmentUserVariables * userVariables(void) const
Get pointer to user variables.
int callMille1D(const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr, unsigned int iTrajHit, const std::vector< int > &globalLabels, const std::vector< float > &globalDerivativesX)
calls Mille for 1D hits
void addLaserData(const EventInfo &eventInfo, const TkFittedLasBeamCollection &tkLasBeams, const TsosVectorCollection &tkLasBeamTsoses)
int addMeasurementData(const edm::EventSetup &setup, const EventInfo &eventInfo, const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr, unsigned int iHit, AlignmentParameters *&params)
bool isMode(unsigned int testMode) const
align::RotationType toLocal(const align::RotationType &) const
Return in local frame a rotation given in global frame.
virtual AlgebraicMatrix derivatives(const TrajectoryStateOnSurface &tsos, const AlignableDetOrUnitPtr &alidet) const =0
Get derivatives of selected parameters.
CLHEP::HepMatrix AlgebraicMatrix
const std::vector< Scalar > & parameters() const
parallel to derivatives()
void fillUsedTrack(const reco::Track *track, unsigned int nHitX, unsigned int nHitY)
std::shared_ptr< TrackingRecHit const > ConstRecHitPointer
virtual bool setParametersForRunRange(const RunRange &runrange)
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
T sqrt(T t)
Definition: SSEVec.h:48
int runPede(const std::string &masterSteer) const
run pede, masterSteer should be as returned from buildMasterSteer(...)
Definition: PedeSteerer.cc:794
unsigned int getBeamId(void) const
return the full beam identifier
Definition: TkLasBeam.h:25
void end()
Definition: Mille.cc:137
tuple result
Definition: query.py:137
AlignmentParameterStore * theAlignmentParameterStore
directory for all kind of files
unsigned int hitsY() const
get number of hits for y-measurement
T Abs(T a)
Definition: MathUtil.h:49
bool is2D(const TransientTrackingRecHit::ConstRecHitPointer &recHit) const
true if hit belongs to 2D detector (currently tracker specific)
int addGlobalData(const edm::EventSetup &setup, const EventInfo &eventInfo, const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr, unsigned int iHit, GblPoint &gblPoint)
void diagonalize(TMatrixDSym &aHitCovarianceM, TMatrixF &aLocalDerivativesM, TMatrixF &aHitResidualsM, TMatrixF &theGlobalDerivativesM) const
int j
Definition: DBlmapReader.cc:9
const TkFittedLasBeamCollection * tkLasBeams() const
std::string buildMasterSteer(const std::vector< std::string > &binaryFiles)
construct (and return name of) master steering file from config, binaryFiles etc. ...
Definition: PedeSteerer.cc:754
void addGlobals(const std::vector< int > &aLabels, const TMatrixD &aDerivatives)
Add global derivatives to a point.
Definition: GblPoint.cc:298
Container::value_type value_type
std::vector< std::string > getExistingFormattedFiles(const std::vector< std::string > plainFiles, std::string theDir)
void mille(int NLC, const float *derLc, int NGL, const float *derGl, const int *label, float rMeas, float sigma)
Definition: Mille.cc:43
const AlignableSurface & surface() const
Return the Surface (global position and orientation) of the object.
Definition: Alignable.h:126
JetCorrectorParameters corr
Definition: classes.h:5
bool addHits(const std::vector< Alignable * > &alis, const std::vector< AlignmentUserVariables * > &mpVars) const
std::vector< ConstRecHitPointer > ConstRecHitContainer
void writeMillePedeVariables(const std::vector< Alignable * > &alivec, const char *filename, int iter, bool validCheck, int &ierr)
bool addHitStatistics(int fromLoop, const std::string &outFile, const std::vector< std::string > &inFiles) const
tuple out
Definition: dbtoconf.py:99
void flushOutputFile()
Definition: Mille.cc:130
bool areEmptyParams(const std::vector< Alignable * > &alignables) const
void addVirtualMeas(const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr, unsigned int iVirtualMeas)
adds data for virtual measurements from reference trajectory
bool readFromPede(const edm::ParameterSet &mprespset, bool setUserVars, const RunRange &runrange)
read pede input defined by &#39;psetName&#39;, flag to create/not create MillePedeVariables ...
CLHEP::HepVector AlgebraicVector
std::pair< unsigned int, unsigned int > addReferenceTrajectory(const edm::EventSetup &setup, const EventInfo &eventInfo, const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr)
fill mille for a trajectory, returning number of x/y hits ([0,0] if &#39;bad&#39; trajectory) ...
std::vector< ReferenceTrajectoryPtr > ReferenceTrajectoryCollection
const SiStripDetId & getDetId(void) const
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 milleOut(MilleBinary &aMille)
Write valid trajectory to Millepede-II binary file.
void setUserVariables(AlignmentUserVariables *auv)
Set pointer to user variables.
std::vector< IntegratedCalibrationBase * > theCalibrations
int size(void) const
Get number of parameters.
void buildSubSteer(AlignableTracker *aliTracker, AlignableMuon *aliMuon, AlignableExtras *aliExtras)
construct steering files about hierarchy, fixing etc. an keep track of their names ...
Definition: PedeSteerer.cc:673
void makeGlobDerivMatrix(const std::vector< float > &globalDerivativesx, const std::vector< float > &globalDerivativesy, TMatrixF &aGlobalDerivativesM)
tuple tracks
Definition: testEve_cfg.py:39
void addUntrackedParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:207
Class to hold one picture of the BPix survey.
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:86
std::vector< value_t > localpars_t
void fillTrack(const reco::Track *track)
virtual bool addCalibrations(const std::vector< IntegratedCalibrationBase * > &iCals)
Pass integrated calibrations to Millepede (they are not owned by Millepede!)
virtual void run(const edm::EventSetup &setup, const EventInfo &eventInfo)
Run the algorithm on trajectories and tracks.
virtual unsigned int calibrationLabel(const IntegratedCalibrationBase *calib, unsigned int paramNum) const
label for parameter &#39;paramNum&#39; (counted from 0) of an integrated calibration
void buildUserVariables(const std::vector< Alignable * > &alignables) const
add MillePedeVariables for each AlignmentParameters (exception if no parameters...)
MillePedeAlignmentAlgorithm(const edm::ParameterSet &cfg)
Constructor.
TrajectoryFactoryBase * theTrajectoryFactory
virtual ~MillePedeAlignmentAlgorithm()
Destructor.
virtual void addCalibrations(const std::vector< IntegratedCalibrationBase * > &iCals)
tell labeler to treat also integrated calibrations
std::vector< TkFittedLasBeam > TkFittedLasBeamCollection
double a
Definition: hdecay.h:121
const reco::BeamSpot & beamSpot() const
align::GlobalPoints toGlobal(const align::LocalPoints &) const
Return in global coord given a set of local points.
void cacheTransformations(void)
cache the current position, rotation and other parameters
virtual const ReferenceTrajectoryCollection trajectories(const edm::EventSetup &setup, const ConstTrajTrackPairCollection &tracks, const reco::BeamSpot &beamSpot) const =0
tuple filename
Definition: lut2db_cfg.py:20
void fillRefTrajectory(const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr)
Definition: Mille.h:26
TransientTrackingRecHit::ConstRecHitContainer ConstRecHitContainer
Millepede-II (binary) record.
Definition: MilleBinary.h:46
void kill()
Definition: Mille.cc:121
tuple cout
Definition: gather_cfg.py:121
void addRefTrackVirtualMeas1D(const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr, unsigned int iVirtualMeas, TMatrixDSym &aHitCovarianceM, TMatrixF &aHitResidualsM, TMatrixF &aLocalDerivativesM)
adds data for a specific virtual measurement from reference trajectory
static const count_t nMsrmts
void writeAlignableAbsolutePositions(const align::Alignables &alivec, const char *filename, int iter, bool validCheck, int &ierr)
write Alignable current absolute positions
void addPxbSurvey(const edm::ParameterSet &pxbSurveyCfg)
add measurement data from PXB survey
unsigned int decodeMode(const std::string &mode) const
std::string fullPath() const
Definition: FileInPath.cc:165
const std::vector< SiStripLaserRecHit2D > & getData(void) const
access the collection of hits
Definition: TkLasBeam.h:28
void writeOrigRigidBodyAlignmentParameters(const align::Alignables &alivec, const char *filename, int iter, bool validCheck, int &ierr)
write RigidBodyAlignmentParameters as applied on top of original positions
std::vector< std::vector< TrajectoryStateOnSurface > > TsosVectorCollection
define run information passed to algorithms (in endRun)
const TsosVectorCollection * tkLasBeamTsoses() const
might be null!
const AlgebraicSymMatrix & covariance(void) const
Get parameter covariance matrix.
Constructor of the full muon geometry.
Definition: AlignableMuon.h:36
uint32_t dimension(pat::CandKinResolution::Parametrization parametrization)
Returns the number of free parameters in a parametrization (3 or 4)
AlignableDetOrUnitPtr alignableFromDetId(const DetId &detid)
Returns AlignableDetOrUnitPtr corresponding to given DetId.
Alignable * mother() const
Return pointer to container alignable (if any)
Definition: Alignable.h:85
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
tuple size
Write out results.
T get(const Candidate &c)
Definition: component.h:55
const align::Alignables & alignables(void) const
get all alignables
std::vector< ConstTrajTrackPair > ConstTrajTrackPairCollection
bool setAllDefault(unsigned int nParam)
set default values for all data concerning nParam (false if nParam out of range)
Point on trajectory.
Definition: GblPoint.h:46
virtual void terminate()
Called at end of job.