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