CMS 3D CMS Logo

MillePedeAlignmentAlgorithm.cc
Go to the documentation of this file.
1 
12 
17 
19 
24 #include "Alignment/MillePedeAlignmentAlgorithm/src/Mille.h" // 'unpublished' interface located in src
29 
32 
36 
40 
41 // includes to make known that they inherit from Alignable:
45 
50 
56 
60 
62 
63 #include <fstream>
64 #include <sstream>
65 #include <algorithm>
66 #include <sys/stat.h>
67 
68 #include <TMath.h>
72 
73 // Includes for PXB survey
80 
82 
83 using namespace gbl;
84 
85 // Constructor ----------------------------------------------------------------
86 //____________________________________________________
89  topoToken_(iC.esConsumes<TrackerTopology, TrackerTopologyRcd, edm::Transition::BeginRun>()),
90  aliThrToken_(iC.esConsumes<AlignPCLThresholds, AlignPCLThresholdsRcd, edm::Transition::BeginRun>()),
91  theConfig(cfg),
92  theMode(this->decodeMode(theConfig.getUntrackedParameter<std::string>("mode"))),
93  theDir(theConfig.getUntrackedParameter<std::string>("fileDir")),
94  theAlignmentParameterStore(nullptr),
95  theAlignables(),
96  theMinNumHits(cfg.getParameter<unsigned int>("minNumHits")),
97  theMaximalCor2D(cfg.getParameter<double>("max2Dcorrelation")),
98  firstIOV_(cfg.getUntrackedParameter<AlignmentAlgorithmBase::RunNumber>("firstIOV")),
99  ignoreFirstIOVCheck_(cfg.getUntrackedParameter<bool>("ignoreFirstIOVCheck")),
100  enableAlignableUpdates_(cfg.getUntrackedParameter<bool>("enableAlignableUpdates")),
101  theLastWrittenIov(0),
102  theGblDoubleBinary(cfg.getParameter<bool>("doubleBinary")),
103  runAtPCL_(cfg.getParameter<bool>("runAtPCL")),
104  ignoreHitsWithoutGlobalDerivatives_(cfg.getParameter<bool>("ignoreHitsWithoutGlobalDerivatives")),
105  skipGlobalPositionRcdCheck_(cfg.getParameter<bool>("skipGlobalPositionRcdCheck")),
106  uniqueRunRanges_(align::makeUniqueRunRanges(cfg.getUntrackedParameter<edm::VParameterSet>("RunRangeSelection"),
107  cond::timeTypeSpecs[cond::runnumber].beginValue)),
108  enforceSingleIOVInput_(!(enableAlignableUpdates_ && areIOVsSpecified())),
109  lastProcessedRun_(cond::timeTypeSpecs[cond::runnumber].beginValue) {
110  if (!theDir.empty() && theDir.find_last_of('/') != theDir.size() - 1)
111  theDir += '/'; // may need '/'
112  edm::LogInfo("Alignment") << "@SUB=MillePedeAlignmentAlgorithm"
113  << "Start in mode '" << theConfig.getUntrackedParameter<std::string>("mode")
114  << "' with output directory '" << theDir << "'.";
115  if (this->isMode(myMilleBit)) {
116  theMille = std::make_unique<Mille>(
117  (theDir + theConfig.getParameter<std::string>("binaryFile")).c_str()); // add ', false);' for text output);
118  // use same file for GBL
119  theBinary = std::make_unique<MilleBinary>((theDir + theConfig.getParameter<std::string>("binaryFile")).c_str(),
121  }
122 }
123 
124 // Destructor ----------------------------------------------------------------
125 //____________________________________________________
127 
128 // Call at beginning of job ---------------------------------------------------
129 //____________________________________________________
133  AlignableExtras *extras,
134  AlignmentParameterStore *store) {
135  if (muon) {
136  edm::LogWarning("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::initialize"
137  << "Running with AlignabeMuon not yet tested.";
138  }
139 
143  const auto &iov_alignments = setup.get<TrackerAlignmentRcd>().validityInterval();
144  const auto &iov_surfaces = setup.get<TrackerSurfaceDeformationRcd>().validityInterval();
145  const auto &iov_errors = setup.get<TrackerAlignmentErrorExtendedRcd>().validityInterval();
146 
147  std::ostringstream message;
148  bool throwException{false};
149  if (iov_alignments.first().eventID().run() != MIN_VAL || iov_alignments.last().eventID().run() != MAX_VAL) {
150  message << "\nTrying to apply " << setup.get<TrackerAlignmentRcd>().key().name()
151  << " with multiple IOVs in tag without specifying 'RunRangeSelection'.\n"
152  << "Validity range is " << iov_alignments.first().eventID().run() << " - "
153  << iov_alignments.last().eventID().run() << "\n";
154  throwException = true;
155  }
156  if (iov_surfaces.first().eventID().run() != MIN_VAL || iov_surfaces.last().eventID().run() != MAX_VAL) {
157  message << "\nTrying to apply " << setup.get<TrackerSurfaceDeformationRcd>().key().name()
158  << " with multiple IOVs in tag without specifying 'RunRangeSelection'.\n"
159  << "Validity range is " << iov_surfaces.first().eventID().run() << " - "
160  << iov_surfaces.last().eventID().run() << "\n";
161  throwException = true;
162  }
163  if (iov_errors.first().eventID().run() != MIN_VAL || iov_errors.last().eventID().run() != MAX_VAL) {
164  message << "\nTrying to apply " << setup.get<TrackerAlignmentErrorExtendedRcd>().key().name()
165  << " with multiple IOVs in tag without specifying 'RunRangeSelection'.\n"
166  << "Validity range is " << iov_errors.first().eventID().run() << " - "
167  << iov_errors.last().eventID().run() << "\n";
168  throwException = true;
169  }
170  if (throwException) {
171  throw cms::Exception("DatabaseError") << "@SUB=MillePedeAlignmentAlgorithm::initialize" << message.str();
172  }
173  }
174 
175  //Retrieve tracker topology from geometry
176  const TrackerTopology *const tTopo = &setup.getData(topoToken_);
177 
178  //Retrieve the thresolds cuts from DB for the PCL
179  if (runAtPCL_) {
180  const auto &th = &setup.getData(aliThrToken_);
181  theThresholds = std::make_shared<AlignPCLThresholds>();
182  storeThresholds(th->getNrecords(), th->getThreshold_Map());
183  }
184 
185  theAlignableNavigator = std::make_unique<AlignableNavigator>(extras, tracker, muon);
188 
189  edm::ParameterSet pedeLabelerCfg(theConfig.getParameter<edm::ParameterSet>("pedeLabeler"));
190  edm::VParameterSet RunRangeSelectionVPSet(theConfig.getUntrackedParameter<edm::VParameterSet>("RunRangeSelection"));
191  pedeLabelerCfg.addUntrackedParameter<edm::VParameterSet>("RunRangeSelection", RunRangeSelectionVPSet);
192 
193  std::string labelerPlugin = "PedeLabeler";
194  if (!RunRangeSelectionVPSet.empty()) {
195  labelerPlugin = "RunRangeDependentPedeLabeler";
196  if (pedeLabelerCfg.exists("plugin")) {
197  std::string labelerPluginCfg = pedeLabelerCfg.getParameter<std::string>("plugin");
198  if ((labelerPluginCfg != "PedeLabeler" && labelerPluginCfg != "RunRangeDependentPedeLabeler") ||
199  !pedeLabelerCfg.getUntrackedParameter<edm::VParameterSet>("parameterInstances").empty()) {
200  throw cms::Exception("BadConfig") << "MillePedeAlignmentAlgorithm::initialize"
201  << "both RunRangeSelection and generic labeler specified in config file. "
202  << "Please get rid of either one of them.\n";
203  }
204  }
205  } else {
206  if (pedeLabelerCfg.exists("plugin")) {
207  labelerPlugin = pedeLabelerCfg.getParameter<std::string>("plugin");
208  }
209  }
210 
211  if (!pedeLabelerCfg.exists("plugin")) {
212  pedeLabelerCfg.addUntrackedParameter<std::string>("plugin", labelerPlugin);
213  }
214 
215  edm::LogInfo("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::initialize"
216  << "Using plugin '" << labelerPlugin << "' to generate labels.";
217 
218  thePedeLabels = std::shared_ptr<PedeLabelerBase>(PedeLabelerPluginFactory::get()->create(
219  labelerPlugin, PedeLabelerBase::TopLevelAlignables(tracker, muon, extras), pedeLabelerCfg));
220 
221  // 1) Create PedeSteerer: correct alignable positions for coordinate system selection
222  edm::ParameterSet pedeSteerCfg(theConfig.getParameter<edm::ParameterSet>("pedeSteerer"));
223  thePedeSteer = std::make_unique<PedeSteerer>(tracker,
224  muon,
225  extras,
227  thePedeLabels.get(),
228  pedeSteerCfg,
229  theDir,
230  !this->isMode(myPedeSteerBit));
231 
232  // 2) If requested, directly read in and apply result of previous pede run,
233  // assuming that correction from 1) was also applied to create the result:
234  const std::vector<edm::ParameterSet> mprespset(
235  theConfig.getParameter<std::vector<edm::ParameterSet> >("pedeReaderInputs"));
236  if (!mprespset.empty()) {
237  edm::LogInfo("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::initialize"
238  << "Apply " << mprespset.end() - mprespset.begin()
239  << " previous MillePede constants from 'pedeReaderInputs'.";
240  }
241 
242  // FIXME: add selection of run range via 'pedeReaderInputs'
243  // Note: Results for parameters of IntegratedCalibration's cannot be treated...
245  for (std::vector<edm::ParameterSet>::const_iterator iSet = mprespset.begin(), iE = mprespset.end(); iSet != iE;
246  ++iSet) {
247  // This read will ignore calibrations as long as they are not yet passed to Millepede
248  // during/before initialize(..) - currently addCalibrations(..) is called later in AlignmentProducer
249  if (!this->readFromPede((*iSet), false, runrange)) { // false: do not erase SelectionUserVariables
250  throw cms::Exception("BadConfig")
251  << "MillePedeAlignmentAlgorithm::initialize: Problems reading input constants of "
252  << "pedeReaderInputs entry " << iSet - mprespset.begin() << '.';
253  }
255  // Needed to shut up later warning from checkAliParams:
257  }
258 
259  // 3) Now create steerings with 'final' start position:
260  thePedeSteer->buildSubSteer(tracker, muon, extras);
261 
262  // After (!) 1-3 of PedeSteerer which uses the SelectionUserVariables attached to the parameters:
263  this->buildUserVariables(theAlignables); // for hit statistics and/or pede result
264 
265  if (this->isMode(myMilleBit)) {
266  if (!theConfig.getParameter<std::vector<std::string> >("mergeBinaryFiles").empty() ||
267  !theConfig.getParameter<std::vector<std::string> >("mergeTreeFiles").empty()) {
268  throw cms::Exception("BadConfig") << "'vstring mergeTreeFiles' and 'vstring mergeBinaryFiles' must be empty for "
269  << "modes running mille.";
270  }
271  const std::string moniFile(theConfig.getUntrackedParameter<std::string>("monitorFile"));
272  if (!moniFile.empty())
273  theMonitor = std::make_unique<MillePedeMonitor>(tTopo, (theDir + moniFile).c_str());
274 
275  // Get trajectory factory. In case nothing found, FrameWork will throw...
276  const edm::ParameterSet fctCfg(theConfig.getParameter<edm::ParameterSet>("TrajectoryFactory"));
277  const std::string fctName(fctCfg.getParameter<std::string>("TrajectoryFactoryName"));
278  theTrajectoryFactory = TrajectoryFactoryPlugin::get()->create(fctName, fctCfg);
279  }
280 
281  if (this->isMode(myPedeSteerBit)) {
282  // Get config for survey and set flag accordingly
283  const edm::ParameterSet pxbSurveyCfg(theConfig.getParameter<edm::ParameterSet>("surveyPixelBarrel"));
284  theDoSurveyPixelBarrel = pxbSurveyCfg.getParameter<bool>("doSurvey");
286  this->addPxbSurvey(pxbSurveyCfg);
287  }
288 }
289 
290 //____________________________________________________
292 
293 //____________________________________________________
294 bool MillePedeAlignmentAlgorithm::addCalibrations(const std::vector<IntegratedCalibrationBase *> &iCals) {
295  theCalibrations.insert(theCalibrations.end(), iCals.begin(), iCals.end());
296  thePedeLabels->addCalibrations(iCals);
297  return true;
298 }
299 
300 //____________________________________________________
302  const AlignPCLThresholds::threshold_map &thresholdMap) {
303  theThresholds->setAlignPCLThresholds(nRecords, thresholdMap);
304  return true;
305 }
306 
307 //_____________________________________________________________________________
309  if (isMode(myMilleBit)) {
310  return true;
311  } else {
312  return false;
313  }
314 }
315 
316 //_____________________________________________________________________________
318  if (isMode(myPedeReadBit)) {
319  if (runAtPCL_) {
320  MillePedeFileReader mpReader(
322  mpReader.read();
323  return mpReader.storeAlignments();
324  } else {
325  return true;
326  }
327  } else {
328  return false;
329  }
330 }
331 
332 //____________________________________________________
334  if (this->isMode(myPedeReadBit)) {
335  if (not theAlignmentParameterStore) {
336  return false;
337  }
338  // restore initial positions, rotations and deformations
341  } else {
343  }
344 
345  // Needed to shut up later warning from checkAliParams:
347  // To avoid that they keep values from previous IOV if no new one in pede result
349 
350  if (!this->readFromPede(theConfig.getParameter<edm::ParameterSet>("pedeReader"), true, runrange)) {
351  edm::LogError("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::setParametersForRunRange"
352  << "Problems reading pede result, but applying!";
353  }
355 
356  this->doIO(++theLastWrittenIov); // pre-increment!
357  }
358 
359  return true;
360 }
361 
362 // Call at end of job ---------------------------------------------------------
363 //____________________________________________________
366  theMille.reset(); // delete to close binary before running pede below (flush would be enough...)
367  theBinary.reset();
368 
369  std::vector<std::string> files;
370  if (this->isMode(myMilleBit) || !theConfig.getParameter<std::string>("binaryFile").empty()) {
371  files.push_back(theDir + theConfig.getParameter<std::string>("binaryFile"));
372  } else {
373  const std::vector<std::string> plainFiles(theConfig.getParameter<std::vector<std::string> >("mergeBinaryFiles"));
374  files = getExistingFormattedFiles(plainFiles, theDir);
375  // Do some logging:
376  std::string filesForLogOutput;
377  for (const auto &file : files)
378  filesForLogOutput += " " + file + ",";
379  if (filesForLogOutput.length() != 0)
380  filesForLogOutput.pop_back();
381  edm::LogInfo("Alignment") << "Based on the config parameter mergeBinaryFiles, using the following "
382  << "files as input (assigned weights are indicated by ' -- <weight>'):"
383  << filesForLogOutput;
384  }
385 
387  return;
388 
389  // cache all positions, rotations and deformations
392  if (lastProcessedRun_ < uniqueRunRanges_.back().first) {
393  throw cms::Exception("BadConfig") << "@SUB=MillePedeAlignmentAlgorithm::terminate\n"
394  << "Last IOV of 'RunRangeSelection' has not been processed. "
395  << "Please reconfigure your source to process the runs at least up to "
396  << uniqueRunRanges_.back().first << ".";
397  }
398  auto lastCachedRun = uniqueRunRanges_.front().first;
399  for (const auto &runRange : uniqueRunRanges_) {
400  const auto run = runRange.first;
401  if (std::find(cachedRuns_.begin(), cachedRuns_.end(), run) == cachedRuns_.end()) {
404  } else {
405  lastCachedRun = run;
406  }
407  }
409  }
410 
411  const std::string masterSteer(thePedeSteer->buildMasterSteer(files)); // do only if myPedeSteerBit?
412  if (this->isMode(myPedeRunBit)) {
413  thePedeSteer->runPede(masterSteer);
414  }
415 
416  // parameters from pede are not yet applied,
417  // so we can still write start positions (but with hit statistics in case of mille):
418  this->doIO(0);
419  theLastWrittenIov = 0;
420 }
421 
423  const std::vector<std::string> &plainFiles, const std::string &theDir) {
424  std::vector<std::string> files;
425  for (const auto &plainFile : plainFiles) {
426  const std::string &theInputFileName = plainFile;
427  int theNumber = 0;
428  while (true) {
429  // Create a formatted version of the filename, with growing numbers
430  // If the parameter doesn't contain a formatting directive, it just stays unchanged
431  char theNumberedInputFileName[200];
432  sprintf(theNumberedInputFileName, theInputFileName.c_str(), theNumber);
433  std::string theCompleteInputFileName = theDir + theNumberedInputFileName;
434  const auto endOfStrippedFileName = theCompleteInputFileName.rfind(" --");
435  const auto strippedInputFileName = theCompleteInputFileName.substr(0, endOfStrippedFileName);
436  // Check if the file exists
437  struct stat buffer;
438  if (stat(strippedInputFileName.c_str(), &buffer) == 0) {
439  // If the file exists, add it to the list
440  files.push_back(theCompleteInputFileName);
441  if (theNumberedInputFileName == theInputFileName) {
442  // If the filename didn't contain a formatting directive, no reason to look any further, break out of the loop
443  break;
444  } else {
445  // Otherwise look for the next number
446  theNumber++;
447  }
448  } else {
449  // The file doesn't exist, break out of the loop
450  break;
451  }
452  }
453  // warning if unformatted (-> theNumber stays at 0) does not exist
454  if (theNumber == 0 && (files.empty() || files.back() != plainFile)) {
455  edm::LogWarning("Alignment") << "The input file '" << plainFile << "' does not exist.";
456  }
457  }
458  return files;
459 }
460 
461 // Run the algorithm on trajectories and tracks -------------------------------
462 //____________________________________________________
464  if (!this->isMode(myMilleBit))
465  return; // no theMille created...
466  const auto &tracks = eventInfo.trajTrackPairs();
467 
468  if (theMonitor) { // monitor input tracks
469  for (const auto &iTrajTrack : tracks) {
470  theMonitor->fillTrack(iTrajTrack.second);
471  }
472  }
473 
474  const RefTrajColl trajectories(theTrajectoryFactory->trajectories(setup, tracks, eventInfo.beamSpot()));
475 
476  // Now loop over ReferenceTrajectoryCollection
477  unsigned int refTrajCount = 0; // counter for track monitoring
478  const auto tracksPerTraj = theTrajectoryFactory->tracksPerTrajectory();
479  for (auto iRefTraj = trajectories.cbegin(), iRefTrajE = trajectories.cend(); iRefTraj != iRefTrajE;
480  ++iRefTraj, ++refTrajCount) {
481  RefTrajColl::value_type refTrajPtr = *iRefTraj;
482  if (theMonitor)
483  theMonitor->fillRefTrajectory(refTrajPtr);
484 
485  const auto nHitXy = this->addReferenceTrajectory(setup, eventInfo, refTrajPtr);
486 
487  if (theMonitor && (nHitXy.first || nHitXy.second)) {
488  // if trajectory used (i.e. some hits), fill monitoring
489  const auto offset = tracksPerTraj * refTrajCount;
490  for (unsigned int iTrack = 0; iTrack < tracksPerTraj; ++iTrack) {
491  theMonitor->fillUsedTrack(tracks[offset + iTrack].second, nHitXy.first, nHitXy.second);
492  }
493  }
494 
495  } // end of reference trajectory and track loop
496 }
497 
498 //____________________________________________________
499 std::pair<unsigned int, unsigned int> MillePedeAlignmentAlgorithm::addReferenceTrajectory(
500  const edm::EventSetup &setup, const EventInfo &eventInfo, const RefTrajColl::value_type &refTrajPtr) {
501  std::pair<unsigned int, unsigned int> hitResultXy(0, 0);
502  if (refTrajPtr->isValid()) {
503  // GblTrajectory?
504  if (!refTrajPtr->gblInput().empty()) {
505  // by construction: number of GblPoints == number of recHits or == zero !!!
506  unsigned int iHit = 0;
507  unsigned int numPointsWithMeas = 0;
508  std::vector<GblPoint>::iterator itPoint;
509  auto theGblInput = refTrajPtr->gblInput();
510  for (unsigned int iTraj = 0; iTraj < refTrajPtr->gblInput().size(); ++iTraj) {
511  for (itPoint = refTrajPtr->gblInput()[iTraj].first.begin(); itPoint < refTrajPtr->gblInput()[iTraj].first.end();
512  ++itPoint) {
513  if (this->addGlobalData(setup, eventInfo, refTrajPtr, iHit++, *itPoint) < 0)
514  return hitResultXy;
515  if (itPoint->hasMeasurement() >= 1)
516  ++numPointsWithMeas;
517  }
518  }
519  hitResultXy.first = numPointsWithMeas;
520  // check #hits criterion
521  if (hitResultXy.first == 0 || hitResultXy.first < theMinNumHits)
522  return hitResultXy;
523  // construct GBL trajectory
524  if (refTrajPtr->gblInput().size() == 1) {
525  // from single track
526  GblTrajectory aGblTrajectory(refTrajPtr->gblInput()[0].first, refTrajPtr->nominalField() != 0);
527  // GBL fit trajectory
528  /*double Chi2;
529  int Ndf;
530  double lostWeight;
531  aGblTrajectory.fit(Chi2, Ndf, lostWeight);
532  std::cout << " GblFit: " << Chi2 << ", " << Ndf << ", " << lostWeight << std::endl; */
533  // write to MP binary file
534  if (aGblTrajectory.isValid() && aGblTrajectory.getNumPoints() >= theMinNumHits)
535  aGblTrajectory.milleOut(*theBinary);
536  }
537  if (refTrajPtr->gblInput().size() == 2) {
538  // from TwoBodyDecay
539  GblTrajectory aGblTrajectory(refTrajPtr->gblInput(),
540  refTrajPtr->gblExtDerivatives(),
541  refTrajPtr->gblExtMeasurements(),
542  refTrajPtr->gblExtPrecisions());
543  // write to MP binary file
544  if (aGblTrajectory.isValid() && aGblTrajectory.getNumPoints() >= theMinNumHits)
545  aGblTrajectory.milleOut(*theBinary);
546  }
547  } else {
548  // to add hits if all fine:
549  std::vector<AlignmentParameters *> parVec(refTrajPtr->recHits().size());
550  // collect hit statistics, assuming that there are no y-only hits
551  std::vector<bool> validHitVecY(refTrajPtr->recHits().size(), false);
552  // Use recHits from ReferenceTrajectory (since they have the right order!):
553  for (unsigned int iHit = 0; iHit < refTrajPtr->recHits().size(); ++iHit) {
554  const int flagXY = this->addMeasurementData(setup, eventInfo, refTrajPtr, iHit, parVec[iHit]);
555 
556  if (flagXY < 0) { // problem
557  hitResultXy.first = 0;
558  break;
559  } else { // hit is fine, increase x/y statistics
560  if (flagXY >= 1)
561  ++hitResultXy.first;
562  validHitVecY[iHit] = (flagXY >= 2);
563  }
564  } // end loop on hits
565 
566  // add virtual measurements
567  for (unsigned int iVirtualMeas = 0; iVirtualMeas < refTrajPtr->numberOfVirtualMeas(); ++iVirtualMeas) {
568  this->addVirtualMeas(refTrajPtr, iVirtualMeas);
569  }
570 
571  // kill or end 'track' for mille, depends on #hits criterion
572  if (hitResultXy.first == 0 || hitResultXy.first < theMinNumHits) {
573  theMille->kill();
574  hitResultXy.first = hitResultXy.second = 0; //reset
575  } else {
576  theMille->end();
577  // add x/y hit count to MillePedeVariables of parVec,
578  // returning number of y-hits of the reference trajectory
579  hitResultXy.second = this->addHitCount(parVec, validHitVecY);
580  //
581  }
582  }
583 
584  } // end if valid trajectory
585 
586  return hitResultXy;
587 }
588 
589 //____________________________________________________
590 unsigned int MillePedeAlignmentAlgorithm::addHitCount(const std::vector<AlignmentParameters *> &parVec,
591  const std::vector<bool> &validHitVecY) const {
592  // Loop on all hit information in the input arrays and count valid y-hits:
593  unsigned int nHitY = 0;
594  for (unsigned int iHit = 0; iHit < validHitVecY.size(); ++iHit) {
595  Alignable *ali = (parVec[iHit] ? parVec[iHit]->alignable() : nullptr);
596  // Loop upwards on hierarchy of alignables to add hits to all levels
597  // that are currently aligned. If only a non-selected alignable was hit,
598  // (i.e. flagXY == 0 in addReferenceTrajectory(..)), there is no loop at all...
599  while (ali) {
601  if (pars) { // otherwise hierarchy level not selected
602  // cast ensured by previous checks:
603  MillePedeVariables *mpVar = static_cast<MillePedeVariables *>(pars->userVariables());
604  // every hit has an x-measurement, cf. addReferenceTrajectory(..):
605  mpVar->increaseHitsX();
606  if (validHitVecY[iHit]) {
607  mpVar->increaseHitsY();
608  if (pars == parVec[iHit])
609  ++nHitY; // do not count hits twice
610  }
611  }
612  ali = ali->mother();
613  }
614  }
615 
616  return nHitY;
617 }
618 
620  if (run.run() < firstIOV_ && !ignoreFirstIOVCheck_) {
621  throw cms::Exception("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::beginRun\n"
622  << "Using data (run = " << run.run() << ") prior to the first defined IOV ("
623  << firstIOV_ << ").";
624  }
625 
626  lastProcessedRun_ = run.run();
627 
628  if (changed && enableAlignableUpdates_) {
629  const auto runNumber = run.run();
631  for (auto runRange = uniqueRunRanges_.crbegin(); runRange != uniqueRunRanges_.crend(); ++runRange) {
632  if (runNumber >= runRange->first) {
633  firstRun = runRange->first;
634  break;
635  }
636  }
637  if (std::find(cachedRuns_.begin(), cachedRuns_.end(), firstRun) != cachedRuns_.end()) {
638  const auto &geometryRcd = setup.get<IdealGeometryRecord>();
639  const auto &globalPosRcd = setup.get<GlobalPositionRcd>();
640  const auto &alignmentRcd = setup.get<TrackerAlignmentRcd>();
641  const auto &surfaceRcd = setup.get<TrackerSurfaceDeformationRcd>();
642  const auto &errorRcd = setup.get<TrackerAlignmentErrorExtendedRcd>();
643 
644  std::ostringstream message;
645  bool throwException{false};
646  message << "Trying to cache tracker alignment payloads for a run (" << runNumber << ") in an IOV (" << firstRun
647  << ") that was already cached.\n"
648  << "The following records in your input database tag have an IOV "
649  << "boundary that does not match your IOV definition:\n";
650  if (geometryRcd.validityInterval().first().eventID().run() > firstRun) {
651  message << " - IdealGeometryRecord '" << geometryRcd.key().name() << "' (since "
652  << geometryRcd.validityInterval().first().eventID().run() << ")\n";
653  throwException = true;
654  }
655  if (globalPosRcd.validityInterval().first().eventID().run() > firstRun) {
656  message << " - GlobalPositionRecord '" << globalPosRcd.key().name() << "' (since "
657  << globalPosRcd.validityInterval().first().eventID().run() << ")";
659  message << " --> ignored\n";
660  } else {
661  message << "\n";
662  throwException = true;
663  }
664  }
665  if (alignmentRcd.validityInterval().first().eventID().run() > firstRun) {
666  message << " - TrackerAlignmentRcd '" << alignmentRcd.key().name() << "' (since "
667  << alignmentRcd.validityInterval().first().eventID().run() << ")\n";
668  throwException = true;
669  }
670  if (surfaceRcd.validityInterval().first().eventID().run() > firstRun) {
671  message << " - TrackerSurfaceDeformationRcd '" << surfaceRcd.key().name() << "' (since "
672  << surfaceRcd.validityInterval().first().eventID().run() << ")\n";
673  throwException = true;
674  }
675  if (errorRcd.validityInterval().first().eventID().run() > firstRun) {
676  message << " - TrackerAlignmentErrorExtendedRcd '" << errorRcd.key().name() << "' (since "
677  << errorRcd.validityInterval().first().eventID().run() << ")\n";
678  throwException = true;
679  }
680 
681  if (throwException) {
682  throw cms::Exception("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::beginRun\n" << message.str();
683  }
684  } else {
685  cachedRuns_.push_back(firstRun);
687  }
688  }
689 }
690 
691 //____________________________________________________
693  const EndRunInfo &runInfo,
694  const edm::EventSetup &setup) {
695  if (runInfo.tkLasBeams() && runInfo.tkLasBeamTsoses()) {
696  // LAS beam treatment
697  this->addLaserData(eventInfo, *(runInfo.tkLasBeams()), *(runInfo.tkLasBeamTsoses()));
698  }
699  if (this->isMode(myMilleBit))
700  theMille->flushOutputFile();
701 }
702 
703 // Implementation of endRun that DOES get called. (Because we need it.)
705  if (this->isMode(myMilleBit))
706  theMille->flushOutputFile();
707 }
708 
709 //____________________________________________________
711  if (!runAtPCL_)
712  return;
713  if (this->isMode(myMilleBit))
714  theMille->resetOutputFile();
715 }
716 
717 //____________________________________________________
719  if (!runAtPCL_)
720  return;
721  if (this->isMode(myMilleBit))
722  theMille->flushOutputFile();
723 }
724 
725 //____________________________________________________
727  const EventInfo &eventInfo,
729  unsigned int iHit,
731  params = nullptr;
732  theFloatBufferX.clear();
733  theFloatBufferY.clear();
734  theIntBuffer.clear();
735 
736  const TrajectoryStateOnSurface &tsos = refTrajPtr->trajectoryStates()[iHit];
737  const ConstRecHitPointer &recHitPtr = refTrajPtr->recHits()[iHit];
738  // ignore invalid hits
739  if (!recHitPtr->isValid())
740  return 0;
741 
742  // First add the derivatives from IntegratedCalibration's,
743  // should even be OK if problems for "usual" derivatives from Alignables
744  this->globalDerivativesCalibration(recHitPtr,
745  tsos,
746  setup,
747  eventInfo, // input
750  theIntBuffer); // output
751 
752  // get AlignableDet/Unit for this hit
753  AlignableDetOrUnitPtr alidet(theAlignableNavigator->alignableFromDetId(recHitPtr->geographicalId()));
754 
755  if (!this->globalDerivativesHierarchy(eventInfo,
756  tsos,
757  alidet,
758  alidet,
759  theFloatBufferX, // 2x alidet, sic!
761  theIntBuffer,
762  params)) {
763  return -1; // problem
765  return 0; // empty for X: no alignable for hit, nor calibrations
766  } else {
767  // store measurement even if no alignable or calibrations
768  // -> measurement used for pede-internal track-fit
769  return this->callMille(refTrajPtr, iHit, theIntBuffer, theFloatBufferX, theFloatBufferY);
770  }
771 }
772 
773 //____________________________________________________
774 
776  const EventInfo &eventInfo,
778  unsigned int iHit,
779  GblPoint &gblPoint) {
780  AlignmentParameters *params = nullptr;
781  std::vector<double> theDoubleBufferX, theDoubleBufferY;
782  theDoubleBufferX.clear();
783  theDoubleBufferY.clear();
784  theIntBuffer.clear();
785  int iret = 0;
786 
787  const TrajectoryStateOnSurface &tsos = refTrajPtr->trajectoryStates()[iHit];
788  const ConstRecHitPointer &recHitPtr = refTrajPtr->recHits()[iHit];
789  // ignore invalid hits
790  if (!recHitPtr->isValid())
791  return 0;
792 
793  // get AlignableDet/Unit for this hit
794  AlignableDetOrUnitPtr alidet(theAlignableNavigator->alignableFromDetId(recHitPtr->geographicalId()));
795 
796  if (!this->globalDerivativesHierarchy(eventInfo,
797  tsos,
798  alidet,
799  alidet,
800  theDoubleBufferX, // 2x alidet, sic!
801  theDoubleBufferY,
802  theIntBuffer,
803  params)) {
804  return -1; // problem
805  }
806  //calibration parameters
807  int globalLabel;
808  std::vector<IntegratedCalibrationBase::ValuesIndexPair> derivs;
809  for (auto iCalib = theCalibrations.begin(); iCalib != theCalibrations.end(); ++iCalib) {
810  // get all derivatives of this calibration // const unsigned int num =
811  (*iCalib)->derivatives(derivs, *recHitPtr, tsos, setup, eventInfo);
812  for (auto iValuesInd = derivs.begin(); iValuesInd != derivs.end(); ++iValuesInd) {
813  // transfer label and x/y derivatives
814  globalLabel = thePedeLabels->calibrationLabel(*iCalib, iValuesInd->second);
815  if (globalLabel > 0 && globalLabel <= 2147483647) {
816  theIntBuffer.push_back(globalLabel);
817  theDoubleBufferX.push_back(iValuesInd->first.first);
818  theDoubleBufferY.push_back(iValuesInd->first.second);
819  } else {
820  edm::LogError("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::addGlobalData"
821  << "Invalid label " << globalLabel << " <= 0 or > 2147483647";
822  }
823  }
824  }
825  unsigned int numGlobals = theIntBuffer.size();
826  if (numGlobals > 0) {
827  Eigen::Matrix<double, 2, Eigen::Dynamic> globalDer{2, numGlobals};
828  for (unsigned int i = 0; i < numGlobals; ++i) {
829  globalDer(0, i) = theDoubleBufferX[i];
830  globalDer(1, i) = theDoubleBufferY[i];
831  }
832  gblPoint.addGlobals(theIntBuffer, globalDer);
833  iret = 1;
834  }
835  return iret;
836 }
837 
838 //____________________________________________________
840  const TrajectoryStateOnSurface &tsos,
841  Alignable *ali,
842  const AlignableDetOrUnitPtr &alidet,
843  std::vector<float> &globalDerivativesX,
844  std::vector<float> &globalDerivativesY,
845  std::vector<int> &globalLabels,
846  AlignmentParameters *&lowestParams) const {
847  // derivatives and labels are recursively attached
848  if (!ali)
849  return true; // no mother might be OK
850 
851  if (false && theMonitor && alidet != ali)
852  theMonitor->fillFrameToFrame(alidet, ali);
853 
855 
856  if (params) {
857  if (!lowestParams)
858  lowestParams = params; // set parameters of lowest level
859 
860  bool hasSplitParameters = thePedeLabels->hasSplitParameters(ali);
861  const unsigned int alignableLabel = thePedeLabels->alignableLabel(ali);
862 
863  if (0 == alignableLabel) { // FIXME: what about regardAllHits in Markus' code?
864  edm::LogWarning("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::globalDerivativesHierarchy"
865  << "Label not found, skip Alignable.";
866  return false;
867  }
868 
869  const std::vector<bool> &selPars = params->selector();
870  const AlgebraicMatrix derivs(params->derivatives(tsos, alidet));
871 
872  // cols: 2, i.e. x&y, rows: parameters, usually RigidBodyAlignmentParameters::N_PARAM
873  for (unsigned int iSel = 0; iSel < selPars.size(); ++iSel) {
874  if (selPars[iSel]) {
875  globalDerivativesX.push_back(derivs[iSel][kLocalX] / thePedeSteer->cmsToPedeFactor(iSel));
876  if (hasSplitParameters == true) {
877  globalLabels.push_back(thePedeLabels->parameterLabel(ali, iSel, eventInfo, tsos));
878  } else {
879  globalLabels.push_back(thePedeLabels->parameterLabel(alignableLabel, iSel));
880  }
881  globalDerivativesY.push_back(derivs[iSel][kLocalY] / thePedeSteer->cmsToPedeFactor(iSel));
882  }
883  }
884  // Exclude mothers if Alignable selected to be no part of a hierarchy:
885  if (thePedeSteer->isNoHiera(ali))
886  return true;
887  }
888  // Call recursively for mother, will stop if mother == 0:
889  return this->globalDerivativesHierarchy(
890  eventInfo, tsos, ali->mother(), alidet, globalDerivativesX, globalDerivativesY, globalLabels, lowestParams);
891 }
892 
893 //____________________________________________________
895  const TrajectoryStateOnSurface &tsos,
896  Alignable *ali,
897  const AlignableDetOrUnitPtr &alidet,
898  std::vector<double> &globalDerivativesX,
899  std::vector<double> &globalDerivativesY,
900  std::vector<int> &globalLabels,
901  AlignmentParameters *&lowestParams) const {
902  // derivatives and labels are recursively attached
903  if (!ali)
904  return true; // no mother might be OK
905 
906  if (false && theMonitor && alidet != ali)
907  theMonitor->fillFrameToFrame(alidet, ali);
908 
910 
911  if (params) {
912  if (!lowestParams)
913  lowestParams = params; // set parameters of lowest level
914 
915  bool hasSplitParameters = thePedeLabels->hasSplitParameters(ali);
916  const unsigned int alignableLabel = thePedeLabels->alignableLabel(ali);
917 
918  if (0 == alignableLabel) { // FIXME: what about regardAllHits in Markus' code?
919  edm::LogWarning("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::globalDerivativesHierarchy"
920  << "Label not found, skip Alignable.";
921  return false;
922  }
923 
924  const std::vector<bool> &selPars = params->selector();
925  const AlgebraicMatrix derivs(params->derivatives(tsos, alidet));
926  int globalLabel;
927 
928  // cols: 2, i.e. x&y, rows: parameters, usually RigidBodyAlignmentParameters::N_PARAM
929  for (unsigned int iSel = 0; iSel < selPars.size(); ++iSel) {
930  if (selPars[iSel]) {
931  if (hasSplitParameters == true) {
932  globalLabel = thePedeLabels->parameterLabel(ali, iSel, eventInfo, tsos);
933  } else {
934  globalLabel = thePedeLabels->parameterLabel(alignableLabel, iSel);
935  }
936  if (globalLabel > 0 && globalLabel <= 2147483647) {
937  globalLabels.push_back(globalLabel);
938  globalDerivativesX.push_back(derivs[iSel][kLocalX] / thePedeSteer->cmsToPedeFactor(iSel));
939  globalDerivativesY.push_back(derivs[iSel][kLocalY] / thePedeSteer->cmsToPedeFactor(iSel));
940  } else {
941  edm::LogError("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::globalDerivativesHierarchy"
942  << "Invalid label " << globalLabel << " <= 0 or > 2147483647";
943  }
944  }
945  }
946  // Exclude mothers if Alignable selected to be no part of a hierarchy:
947  if (thePedeSteer->isNoHiera(ali))
948  return true;
949  }
950  // Call recursively for mother, will stop if mother == 0:
951  return this->globalDerivativesHierarchy(
952  eventInfo, tsos, ali->mother(), alidet, globalDerivativesX, globalDerivativesY, globalLabels, lowestParams);
953 }
954 
955 //____________________________________________________
957  const TrajectoryStateOnSurface &tsos,
958  const edm::EventSetup &setup,
959  const EventInfo &eventInfo,
960  std::vector<float> &globalDerivativesX,
961  std::vector<float> &globalDerivativesY,
962  std::vector<int> &globalLabels) const {
963  std::vector<IntegratedCalibrationBase::ValuesIndexPair> derivs;
964  for (auto iCalib = theCalibrations.begin(); iCalib != theCalibrations.end(); ++iCalib) {
965  // get all derivatives of this calibration // const unsigned int num =
966  (*iCalib)->derivatives(derivs, *recHit, tsos, setup, eventInfo);
967  for (auto iValuesInd = derivs.begin(); iValuesInd != derivs.end(); ++iValuesInd) {
968  // transfer label and x/y derivatives
969  globalLabels.push_back(thePedeLabels->calibrationLabel(*iCalib, iValuesInd->second));
970  globalDerivativesX.push_back(iValuesInd->first.first);
971  globalDerivativesY.push_back(iValuesInd->first.second);
972  }
973  }
974 }
975 
976 // //____________________________________________________
977 // void MillePedeAlignmentAlgorithm
978 // ::callMille(const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr,
979 // unsigned int iTrajHit, MeasurementDirection xOrY,
980 // const std::vector<float> &globalDerivatives, const std::vector<int> &globalLabels)
981 // {
982 // const unsigned int xyIndex = iTrajHit*2 + xOrY;
983 // // FIXME: here for residuum and sigma we could use KALMAN-Filter results
984 // const float residuum =
985 // refTrajPtr->measurements()[xyIndex] - refTrajPtr->trajectoryPositions()[xyIndex];
986 // const float covariance = refTrajPtr->measurementErrors()[xyIndex][xyIndex];
987 // const float sigma = (covariance > 0. ? TMath::Sqrt(covariance) : 0.);
988 
989 // const AlgebraicMatrix &locDerivMatrix = refTrajPtr->derivatives();
990 
991 // std::vector<float> localDerivs(locDerivMatrix.num_col());
992 // for (unsigned int i = 0; i < localDerivs.size(); ++i) {
993 // localDerivs[i] = locDerivMatrix[xyIndex][i];
994 // }
995 
996 // // &(vector[0]) is valid - as long as vector is not empty
997 // // cf. http://www.parashift.com/c++-faq-lite/containers.html#faq-34.3
998 // theMille->mille(localDerivs.size(), &(localDerivs[0]),
999 // globalDerivatives.size(), &(globalDerivatives[0]), &(globalLabels[0]),
1000 // residuum, sigma);
1001 // if (theMonitor) {
1002 // theMonitor->fillDerivatives(refTrajPtr->recHits()[iTrajHit],localDerivs, globalDerivatives,
1003 // (xOrY == kLocalY));
1004 // theMonitor->fillResiduals(refTrajPtr->recHits()[iTrajHit],
1005 // refTrajPtr->trajectoryStates()[iTrajHit],
1006 // iTrajHit, residuum, sigma, (xOrY == kLocalY));
1007 // }
1008 // }
1009 
1010 //____________________________________________________
1012  // FIXME: Check whether this is a reliable and recommended way to find out...
1013 
1014  if (recHit->dimension() < 2) {
1015  return false; // some muon and TIB/TOB stuff really has RecHit1D
1016  } else if (recHit->detUnit()) { // detunit in strip is 1D, in pixel 2D
1017  return recHit->detUnit()->type().isTrackerPixel();
1018  } else { // stereo strips (FIXME: endcap trouble due to non-parallel strips (wedge sensors)?)
1019  if (dynamic_cast<const ProjectedSiStripRecHit2D *>(recHit->hit())) { // check persistent hit
1020  // projected: 1D measurement on 'glued' module
1021  return false;
1022  } else {
1023  return true;
1024  }
1025  }
1026 }
1027 
1028 //__________________________________________________________________________________________________
1030  bool setUserVars,
1031  const RunRange &runrange) {
1032  bool allEmpty = this->areEmptyParams(theAlignables);
1033 
1034  PedeReader reader(mprespset, *thePedeSteer, *thePedeLabels, runrange);
1035  align::Alignables alis;
1036  bool okRead = reader.read(alis, setUserVars); // also may set params of IntegratedCalibration's
1037  bool numMatch = true;
1038 
1039  std::stringstream out;
1040  out << "Read " << alis.size() << " alignables";
1041  if (alis.size() != theAlignables.size()) {
1042  out << " while " << theAlignables.size() << " in store";
1043  numMatch = false; // FIXME: Should we check one by one? Or transfer 'alis' to the store?
1044  }
1045  if (!okRead)
1046  out << ", but problems in reading";
1047  if (!allEmpty)
1048  out << ", possibly overwriting previous settings";
1049  out << ".";
1050 
1051  if (okRead && allEmpty) {
1052  if (numMatch) { // as many alignables with result as trying to align
1053  edm::LogInfo("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::readFromPede" << out.str();
1054  } else if (!alis.empty()) { // dead module do not get hits and no pede result
1055  edm::LogWarning("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::readFromPede" << out.str();
1056  } else { // serious problem: no result read - and not all modules can be dead...
1057  edm::LogError("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::readFromPede" << out.str();
1058  return false;
1059  }
1060  return true;
1061  }
1062  // the rest is not OK:
1063  edm::LogError("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::readFromPede" << out.str();
1064  return false;
1065 }
1066 
1067 //__________________________________________________________________________________________________
1069  for (const auto &iAli : alignables) {
1070  const AlignmentParameters *params = iAli->alignmentParameters();
1071  if (params) {
1072  const auto &parVec(params->parameters());
1073  const auto &parCov(params->covariance());
1074  for (int i = 0; i < parVec.num_row(); ++i) {
1075  if (parVec[i] != 0.)
1076  return false;
1077  for (int j = i; j < parCov.num_col(); ++j) {
1078  if (parCov[i][j] != 0.)
1079  return false;
1080  }
1081  }
1082  }
1083  }
1084 
1085  return true;
1086 }
1087 
1088 //__________________________________________________________________________________________________
1089 unsigned int MillePedeAlignmentAlgorithm::doIO(int loop) const {
1090  unsigned int result = 0;
1091 
1092  const std::string outFilePlain(theConfig.getParameter<std::string>("treeFile"));
1093  if (outFilePlain.empty()) {
1094  edm::LogInfo("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::doIO"
1095  << "treeFile parameter empty => skip writing for 'loop' " << loop;
1096  return result;
1097  }
1098 
1099  const std::string outFile(theDir + outFilePlain);
1100 
1101  AlignmentIORoot aliIO;
1102  int ioerr = 0;
1103  if (loop == 0) {
1104  aliIO.writeAlignableOriginalPositions(theAlignables, outFile.c_str(), loop, false, ioerr);
1105  if (ioerr) {
1106  edm::LogError("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::doIO"
1107  << "Problem " << ioerr << " in writeAlignableOriginalPositions";
1108  ++result;
1109  }
1110  } else if (loop == 1) {
1111  // only for first iov add hit counts, else 2x, 3x,... number of hits in IOV 2, 3,...
1112  const std::vector<std::string> inFiles(theConfig.getParameter<std::vector<std::string> >("mergeTreeFiles"));
1113  const std::vector<std::string> binFiles(theConfig.getParameter<std::vector<std::string> >("mergeBinaryFiles"));
1114  if (inFiles.size() != binFiles.size()) {
1115  edm::LogWarning("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::doIO"
1116  << "'vstring mergeTreeFiles' and 'vstring mergeBinaryFiles' "
1117  << "differ in size";
1118  }
1119  this->addHitStatistics(0, outFile, inFiles); // add hit info from tree 0 in 'infiles'
1120  }
1121  MillePedeVariablesIORoot millePedeIO;
1122  millePedeIO.writeMillePedeVariables(theAlignables, outFile.c_str(), loop, false, ioerr);
1123  if (ioerr) {
1124  edm::LogError("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::doIO"
1125  << "Problem " << ioerr << " writing MillePedeVariables";
1126  ++result;
1127  }
1128 
1129  aliIO.writeOrigRigidBodyAlignmentParameters(theAlignables, outFile.c_str(), loop, false, ioerr);
1130  if (ioerr) {
1131  edm::LogError("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::doIO"
1132  << "Problem " << ioerr << " in writeOrigRigidBodyAlignmentParameters, " << loop;
1133  ++result;
1134  }
1135  aliIO.writeAlignableAbsolutePositions(theAlignables, outFile.c_str(), loop, false, ioerr);
1136  if (ioerr) {
1137  edm::LogError("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::doIO"
1138  << "Problem " << ioerr << " in writeAlignableAbsolutePositions, " << loop;
1139  ++result;
1140  }
1141 
1142  return result;
1143 }
1144 
1145 //__________________________________________________________________________________________________
1147  for (const auto &iAli : alis) {
1148  AlignmentParameters *params = iAli->alignmentParameters();
1149  if (!params) {
1150  throw cms::Exception("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::buildUserVariables"
1151  << "No parameters for alignable";
1152  }
1153  MillePedeVariables *userVars = dynamic_cast<MillePedeVariables *>(params->userVariables());
1154  if (userVars) { // Just re-use existing, keeping label and numHits:
1155  for (unsigned int iPar = 0; iPar < userVars->size(); ++iPar) {
1156  // if (params->hierarchyLevel() > 0) {
1157  //std::cout << params->hierarchyLevel() << "\nBefore: " << userVars->parameter()[iPar];
1158  // }
1159  userVars->setAllDefault(iPar);
1160  //std::cout << "\nAfter: " << userVars->parameter()[iPar] << std::endl;
1161  }
1162  } else { // Nothing yet or erase wrong type:
1163  userVars = new MillePedeVariables(
1164  params->size(),
1165  thePedeLabels->alignableLabel(iAli),
1166  thePedeLabels->alignableTracker()->objectIdProvider().typeToName(iAli->alignableObjectId()));
1167  params->setUserVariables(userVars);
1168  }
1169  }
1170 }
1171 
1172 //__________________________________________________________________________________________________
1174  if (mode == "full") {
1176  } else if (mode == "mille") {
1177  return myMilleBit; // + myPedeSteerBit; // sic! Including production of steerig file. NO!
1178  } else if (mode == "pede") {
1180  } else if (mode == "pedeSteer") {
1181  return myPedeSteerBit;
1182  } else if (mode == "pedeRun") {
1183  return myPedeSteerBit + myPedeRunBit + myPedeReadBit; // sic! Including steering and reading of result.
1184  } else if (mode == "pedeRead") {
1185  return myPedeReadBit;
1186  }
1187 
1188  throw cms::Exception("BadConfig") << "Unknown mode '" << mode
1189  << "', use 'full', 'mille', 'pede', 'pedeRun', 'pedeSteer' or 'pedeRead'.";
1190 
1191  return 0;
1192 }
1193 
1194 //__________________________________________________________________________________________________
1196  const std::string &outFile,
1197  const std::vector<std::string> &inFiles) const {
1198  bool allOk = true;
1199  int ierr = 0;
1200  MillePedeVariablesIORoot millePedeIO;
1201  for (std::vector<std::string>::const_iterator iFile = inFiles.begin(); iFile != inFiles.end(); ++iFile) {
1202  const std::string inFile(theDir + *iFile);
1203  const std::vector<AlignmentUserVariables *> mpVars =
1204  millePedeIO.readMillePedeVariables(theAlignables, inFile.c_str(), fromIov, ierr);
1205  if (ierr || !this->addHits(theAlignables, mpVars)) {
1206  edm::LogError("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::addHitStatistics"
1207  << "Error " << ierr << " reading from " << inFile << ", tree " << fromIov
1208  << ", or problems in addHits";
1209  allOk = false;
1210  }
1211  for (std::vector<AlignmentUserVariables *>::const_iterator i = mpVars.begin(); i != mpVars.end(); ++i) {
1212  delete *i; // clean created objects
1213  }
1214  }
1215 
1216  return allOk;
1217 }
1218 
1219 //__________________________________________________________________________________________________
1221  const std::vector<AlignmentUserVariables *> &mpVars) const {
1222  bool allOk = (mpVars.size() == alis.size());
1223  std::vector<AlignmentUserVariables *>::const_iterator iUser = mpVars.begin();
1224  for (auto iAli = alis.cbegin(); iAli != alis.cend() && iUser != mpVars.end(); ++iAli, ++iUser) {
1225  MillePedeVariables *mpVarNew = dynamic_cast<MillePedeVariables *>(*iUser);
1226  AlignmentParameters *ps = (*iAli)->alignmentParameters();
1227  MillePedeVariables *mpVarOld = (ps ? dynamic_cast<MillePedeVariables *>(ps->userVariables()) : nullptr);
1228  if (!mpVarNew || !mpVarOld || mpVarOld->size() != mpVarNew->size()) {
1229  allOk = false;
1230  continue; // FIXME error etc.?
1231  }
1232 
1233  mpVarOld->increaseHitsX(mpVarNew->hitsX());
1234  mpVarOld->increaseHitsY(mpVarNew->hitsY());
1235  }
1236 
1237  return allOk;
1238 }
1239 
1240 //__________________________________________________________________________________________________
1241 template <typename GlobalDerivativeMatrix>
1242 void MillePedeAlignmentAlgorithm::makeGlobDerivMatrix(const std::vector<float> &globalDerivativesx,
1243  const std::vector<float> &globalDerivativesy,
1244  Eigen::MatrixBase<GlobalDerivativeMatrix> &aGlobalDerivativesM) {
1245  static_assert(GlobalDerivativeMatrix::RowsAtCompileTime == 2, "global derivative matrix must have two rows");
1246 
1247  for (size_t i = 0; i < globalDerivativesx.size(); ++i) {
1248  aGlobalDerivativesM(0, i) = globalDerivativesx[i];
1249  aGlobalDerivativesM(1, i) = globalDerivativesy[i];
1250  }
1251 }
1252 
1253 //__________________________________________________________________________________________________
1254 template <typename CovarianceMatrix,
1255  typename LocalDerivativeMatrix,
1256  typename ResidualMatrix,
1257  typename GlobalDerivativeMatrix>
1258 void MillePedeAlignmentAlgorithm::diagonalize(Eigen::MatrixBase<CovarianceMatrix> &aHitCovarianceM,
1259  Eigen::MatrixBase<LocalDerivativeMatrix> &aLocalDerivativesM,
1260  Eigen::MatrixBase<ResidualMatrix> &aHitResidualsM,
1261  Eigen::MatrixBase<GlobalDerivativeMatrix> &aGlobalDerivativesM) const {
1263  "'aLocalDerivativesM' and 'aHitResidualsM' must have the "
1264  "same underlying scalar type");
1266  "'aLocalDerivativesM' and 'aGlobalDerivativesM' must have the "
1267  "same underlying scalar type");
1268 
1269  Eigen::SelfAdjointEigenSolver<typename CovarianceMatrix::PlainObject> myDiag{aHitCovarianceM};
1270  // eigenvectors of real symmetric matrices are orthogonal, i.e. invert == transpose
1271  auto aTranfoToDiagonalSystemInv =
1272  myDiag.eigenvectors().transpose().template cast<typename LocalDerivativeMatrix::Scalar>();
1273 
1274  aHitCovarianceM = myDiag.eigenvalues().asDiagonal();
1275  aLocalDerivativesM = aTranfoToDiagonalSystemInv * aLocalDerivativesM;
1276  aHitResidualsM = aTranfoToDiagonalSystemInv * aHitResidualsM;
1277  if (aGlobalDerivativesM.size() > 0) {
1278  // diagonalize only if measurement depends on alignables or calibrations
1279  aGlobalDerivativesM = aTranfoToDiagonalSystemInv * aGlobalDerivativesM;
1280  }
1281 }
1282 
1283 //__________________________________________________________________________________________________
1284 template <typename CovarianceMatrix, typename ResidualMatrix, typename LocalDerivativeMatrix>
1287  unsigned int iVirtualMeas,
1288  Eigen::MatrixBase<CovarianceMatrix> &aHitCovarianceM,
1289  Eigen::MatrixBase<ResidualMatrix> &aHitResidualsM,
1290  Eigen::MatrixBase<LocalDerivativeMatrix> &aLocalDerivativesM) {
1291  // This Method is valid for 1D measurements only
1292 
1293  const unsigned int xIndex = iVirtualMeas + refTrajPtr->numberOfHitMeas();
1294 
1295  aHitCovarianceM(0, 0) = refTrajPtr->measurementErrors()[xIndex][xIndex];
1296  aHitResidualsM(0, 0) = refTrajPtr->measurements()[xIndex];
1297 
1298  const auto &locDerivMatrix = refTrajPtr->derivatives();
1299  for (int i = 0; i < locDerivMatrix.num_col(); ++i) {
1300  aLocalDerivativesM(0, i) = locDerivMatrix[xIndex][i];
1301  }
1302 }
1303 
1304 //__________________________________________________________________________________________________
1305 template <typename CovarianceMatrix, typename ResidualMatrix, typename LocalDerivativeMatrix>
1307  unsigned int iTrajHit,
1308  Eigen::MatrixBase<CovarianceMatrix> &aHitCovarianceM,
1309  Eigen::MatrixBase<ResidualMatrix> &aHitResidualsM,
1310  Eigen::MatrixBase<LocalDerivativeMatrix> &aLocalDerivativesM) {
1311  // This Method is valid for 2D measurements only
1312 
1313  const unsigned int xIndex = iTrajHit * 2;
1314  const unsigned int yIndex = iTrajHit * 2 + 1;
1315 
1316  aHitCovarianceM(0, 0) = refTrajPtr->measurementErrors()[xIndex][xIndex];
1317  aHitCovarianceM(0, 1) = refTrajPtr->measurementErrors()[xIndex][yIndex];
1318  aHitCovarianceM(1, 0) = refTrajPtr->measurementErrors()[yIndex][xIndex];
1319  aHitCovarianceM(1, 1) = refTrajPtr->measurementErrors()[yIndex][yIndex];
1320 
1321  aHitResidualsM(0, 0) = refTrajPtr->measurements()[xIndex] - refTrajPtr->trajectoryPositions()[xIndex];
1322  aHitResidualsM(1, 0) = refTrajPtr->measurements()[yIndex] - refTrajPtr->trajectoryPositions()[yIndex];
1323 
1324  const auto &locDerivMatrix = refTrajPtr->derivatives();
1325  for (int i = 0; i < locDerivMatrix.num_col(); ++i) {
1326  aLocalDerivativesM(0, i) = locDerivMatrix[xIndex][i];
1327  aLocalDerivativesM(1, i) = locDerivMatrix[yIndex][i];
1328  }
1329 }
1330 
1331 //__________________________________________________________________________________________________
1333  unsigned int iTrajHit,
1334  const std::vector<int> &globalLabels,
1335  const std::vector<float> &globalDerivativesX,
1336  const std::vector<float> &globalDerivativesY) {
1337  const ConstRecHitPointer aRecHit(refTrajPtr->recHits()[iTrajHit]);
1338 
1339  if ((aRecHit)->dimension() == 1) {
1340  return this->callMille1D(refTrajPtr, iTrajHit, globalLabels, globalDerivativesX);
1341  } else {
1342  return this->callMille2D(refTrajPtr, iTrajHit, globalLabels, globalDerivativesX, globalDerivativesY);
1343  }
1344 }
1345 
1346 //__________________________________________________________________________________________________
1348  unsigned int iTrajHit,
1349  const std::vector<int> &globalLabels,
1350  const std::vector<float> &globalDerivativesX) {
1351  const ConstRecHitPointer aRecHit(refTrajPtr->recHits()[iTrajHit]);
1352  const unsigned int xIndex = iTrajHit * 2; // the even ones are local x
1353 
1354  // local derivatives
1355  const AlgebraicMatrix &locDerivMatrix = refTrajPtr->derivatives();
1356  const int nLocal = locDerivMatrix.num_col();
1357  std::vector<float> localDerivatives(nLocal);
1358  for (unsigned int i = 0; i < localDerivatives.size(); ++i) {
1359  localDerivatives[i] = locDerivMatrix[xIndex][i];
1360  }
1361 
1362  // residuum and error
1363  float residX = refTrajPtr->measurements()[xIndex] - refTrajPtr->trajectoryPositions()[xIndex];
1364  float hitErrX = TMath::Sqrt(refTrajPtr->measurementErrors()[xIndex][xIndex]);
1365 
1366  // number of global derivatives
1367  const int nGlobal = globalDerivativesX.size();
1368 
1369  // &(localDerivatives[0]) etc. are valid - as long as vector is not empty
1370  // cf. http://www.parashift.com/c++-faq-lite/containers.html#faq-34.3
1371  theMille->mille(
1372  nLocal, &(localDerivatives[0]), nGlobal, &(globalDerivativesX[0]), &(globalLabels[0]), residX, hitErrX);
1373 
1374  if (theMonitor) {
1375  theMonitor->fillDerivatives(
1376  aRecHit, &(localDerivatives[0]), nLocal, &(globalDerivativesX[0]), nGlobal, &(globalLabels[0]));
1377  theMonitor->fillResiduals(aRecHit, refTrajPtr->trajectoryStates()[iTrajHit], iTrajHit, residX, hitErrX, false);
1378  }
1379 
1380  return 1;
1381 }
1382 
1383 //__________________________________________________________________________________________________
1385  unsigned int iTrajHit,
1386  const std::vector<int> &globalLabels,
1387  const std::vector<float> &globalDerivativesx,
1388  const std::vector<float> &globalDerivativesy) {
1389  const ConstRecHitPointer aRecHit(refTrajPtr->recHits()[iTrajHit]);
1390 
1391  if ((aRecHit)->dimension() != 2) {
1392  edm::LogError("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::callMille2D"
1393  << "You try to call method for 2D hits for a " << (aRecHit)->dimension()
1394  << "D Hit. Hit gets ignored!";
1395  return -1;
1396  }
1397 
1398  Eigen::Matrix<double, 2, 2> aHitCovarianceM;
1399  Eigen::Matrix<float, 2, 1> aHitResidualsM;
1400  Eigen::Matrix<float, 2, Eigen::Dynamic> aLocalDerivativesM{2, refTrajPtr->derivatives().num_col()};
1401  // below method fills above 3 matrices
1402  this->addRefTrackData2D(refTrajPtr, iTrajHit, aHitCovarianceM, aHitResidualsM, aLocalDerivativesM);
1403  Eigen::Matrix<float, 2, Eigen::Dynamic> aGlobalDerivativesM{2, globalDerivativesx.size()};
1404  this->makeGlobDerivMatrix(globalDerivativesx, globalDerivativesy, aGlobalDerivativesM);
1405 
1406  // calculates correlation between Hit measurements
1407  // FIXME: Should take correlation (and resulting transformation) from original hit,
1408  // not 2x2 matrix from ReferenceTrajectory: That can come from error propagation etc.!
1409  const double corr = aHitCovarianceM(0, 1) / sqrt(aHitCovarianceM(0, 0) * aHitCovarianceM(1, 1));
1410  if (theMonitor)
1411  theMonitor->fillCorrelations2D(corr, aRecHit);
1412  bool diag = false; // diagonalise only tracker TID, TEC
1413  switch (aRecHit->geographicalId().subdetId()) {
1414  case SiStripDetId::TID:
1415  case SiStripDetId::TEC:
1416  if (aRecHit->geographicalId().det() == DetId::Tracker && TMath::Abs(corr) > theMaximalCor2D) {
1417  this->diagonalize(aHitCovarianceM, aLocalDerivativesM, aHitResidualsM, aGlobalDerivativesM);
1418  diag = true;
1419  }
1420  break;
1421  default:;
1422  }
1423 
1424  float newResidX = aHitResidualsM(0, 0);
1425  float newResidY = aHitResidualsM(1, 0);
1426  float newHitErrX = TMath::Sqrt(aHitCovarianceM(0, 0));
1427  float newHitErrY = TMath::Sqrt(aHitCovarianceM(1, 1));
1428 
1429  // change from column major (Eigen default) to row major to have row entries
1430  // in continuous memory
1431  std::vector<float> newLocalDerivs(aLocalDerivativesM.size());
1432  Eigen::Map<Eigen::Matrix<float, 2, Eigen::Dynamic, Eigen::RowMajor> >(
1433  newLocalDerivs.data(), aLocalDerivativesM.rows(), aLocalDerivativesM.cols()) = aLocalDerivativesM;
1434  float *newLocalDerivsX = &(newLocalDerivs[0]);
1435  float *newLocalDerivsY = &(newLocalDerivs[aLocalDerivativesM.cols()]);
1436 
1437  // change from column major (Eigen default) to row major to have row entries
1438  // in continuous memory
1439  std::vector<float> newGlobDerivs(aGlobalDerivativesM.size());
1440  Eigen::Map<Eigen::Matrix<float, 2, Eigen::Dynamic, Eigen::RowMajor> >(
1441  newGlobDerivs.data(), aGlobalDerivativesM.rows(), aGlobalDerivativesM.cols()) = aGlobalDerivativesM;
1442  float *newGlobDerivsX = &(newGlobDerivs[0]);
1443  float *newGlobDerivsY = &(newGlobDerivs[aGlobalDerivativesM.cols()]);
1444 
1445  const int nLocal = aLocalDerivativesM.cols();
1446  const int nGlobal = aGlobalDerivativesM.cols();
1447 
1448  if (diag && (newHitErrX > newHitErrY)) { // also for 2D hits?
1449  // measurement with smaller error is x-measurement (for !is2D do not fill y-measurement):
1450  std::swap(newResidX, newResidY);
1451  std::swap(newHitErrX, newHitErrY);
1452  std::swap(newLocalDerivsX, newLocalDerivsY);
1453  std::swap(newGlobDerivsX, newGlobDerivsY);
1454  }
1455 
1456  // &(globalLabels[0]) is valid - as long as vector is not empty
1457  // cf. http://www.parashift.com/c++-faq-lite/containers.html#faq-34.3
1458  theMille->mille(nLocal, newLocalDerivsX, nGlobal, newGlobDerivsX, &(globalLabels[0]), newResidX, newHitErrX);
1459 
1460  if (theMonitor) {
1461  theMonitor->fillDerivatives(aRecHit, newLocalDerivsX, nLocal, newGlobDerivsX, nGlobal, &(globalLabels[0]));
1462  theMonitor->fillResiduals(
1463  aRecHit, refTrajPtr->trajectoryStates()[iTrajHit], iTrajHit, newResidX, newHitErrX, false);
1464  }
1465  const bool isReal2DHit = this->is2D(aRecHit); // strip is 1D (except matched hits)
1466  if (isReal2DHit) {
1467  theMille->mille(nLocal, newLocalDerivsY, nGlobal, newGlobDerivsY, &(globalLabels[0]), newResidY, newHitErrY);
1468  if (theMonitor) {
1469  theMonitor->fillDerivatives(aRecHit, newLocalDerivsY, nLocal, newGlobDerivsY, nGlobal, &(globalLabels[0]));
1470  theMonitor->fillResiduals(
1471  aRecHit, refTrajPtr->trajectoryStates()[iTrajHit], iTrajHit, newResidY, newHitErrY, true); // true: y
1472  }
1473  }
1474 
1475  return (isReal2DHit ? 2 : 1);
1476 }
1477 
1478 //__________________________________________________________________________________________________
1480  unsigned int iVirtualMeas) {
1481  Eigen::Matrix<double, 1, 1> aHitCovarianceM;
1482  Eigen::Matrix<float, 1, 1> aHitResidualsM;
1483  Eigen::Matrix<float, 1, Eigen::Dynamic> aLocalDerivativesM{1, refTrajPtr->derivatives().num_col()};
1484  // below method fills above 3 'matrices'
1485  this->addRefTrackVirtualMeas1D(refTrajPtr, iVirtualMeas, aHitCovarianceM, aHitResidualsM, aLocalDerivativesM);
1486 
1487  // no global parameters (use dummy 0)
1488  auto aGlobalDerivativesM = Eigen::Matrix<float, 1, 1>::Zero();
1489 
1490  float newResidX = aHitResidualsM(0, 0);
1491  float newHitErrX = TMath::Sqrt(aHitCovarianceM(0, 0));
1492  std::vector<float> newLocalDerivsX(aLocalDerivativesM.size());
1493  Eigen::Map<Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> >(
1494  newLocalDerivsX.data(), aLocalDerivativesM.rows(), aLocalDerivativesM.cols()) = aLocalDerivativesM;
1495 
1496  std::vector<float> newGlobDerivsX(aGlobalDerivativesM.size());
1497  Eigen::Map<Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> >(
1498  newGlobDerivsX.data(), aGlobalDerivativesM.rows(), aGlobalDerivativesM.cols()) = aGlobalDerivativesM;
1499 
1500  const int nLocal = aLocalDerivativesM.cols();
1501  const int nGlobal = 0;
1502 
1503  theMille->mille(nLocal, newLocalDerivsX.data(), nGlobal, newGlobDerivsX.data(), &nGlobal, newResidX, newHitErrX);
1504 }
1505 
1506 //____________________________________________________
1508  const TkFittedLasBeamCollection &lasBeams,
1509  const TsosVectorCollection &lasBeamTsoses) {
1510  TsosVectorCollection::const_iterator iTsoses = lasBeamTsoses.begin();
1511  for (TkFittedLasBeamCollection::const_iterator iBeam = lasBeams.begin(), iEnd = lasBeams.end(); iBeam != iEnd;
1512  ++iBeam, ++iTsoses) { // beam/tsoses parallel!
1513 
1514  edm::LogInfo("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::addLaserData"
1515  << "Beam " << iBeam->getBeamId() << " with " << iBeam->parameters().size()
1516  << " parameters and " << iBeam->getData().size() << " hits.\n There are "
1517  << iTsoses->size() << " TSOSes.";
1518 
1519  this->addLasBeam(eventInfo, *iBeam, *iTsoses);
1520  }
1521 }
1522 
1523 //____________________________________________________
1525  const TkFittedLasBeam &lasBeam,
1526  const std::vector<TrajectoryStateOnSurface> &tsoses) {
1527  AlignmentParameters *dummyPtr = nullptr; // for globalDerivativesHierarchy()
1528  std::vector<float> lasLocalDerivsX; // buffer for local derivatives
1529  const unsigned int beamLabel = thePedeLabels->lasBeamLabel(lasBeam.getBeamId()); // for global par
1530 
1531  for (unsigned int iHit = 0; iHit < tsoses.size(); ++iHit) {
1532  if (!tsoses[iHit].isValid())
1533  continue;
1534  // clear buffer
1535  theFloatBufferX.clear();
1536  theFloatBufferY.clear();
1537  theIntBuffer.clear();
1538  lasLocalDerivsX.clear();
1539  // get alignables and global parameters
1540  const SiStripLaserRecHit2D &hit = lasBeam.getData()[iHit];
1541  AlignableDetOrUnitPtr lasAli(theAlignableNavigator->alignableFromDetId(hit.getDetId()));
1543  eventInfo, tsoses[iHit], lasAli, lasAli, theFloatBufferX, theFloatBufferY, theIntBuffer, dummyPtr);
1544  // fill derivatives vector from derivatives matrix
1545  for (unsigned int nFitParams = 0; nFitParams < static_cast<unsigned int>(lasBeam.parameters().size());
1546  ++nFitParams) {
1547  const float derivative = lasBeam.derivatives()[iHit][nFitParams];
1548  if (nFitParams < lasBeam.firstFixedParameter()) { // first local beam parameters
1549  lasLocalDerivsX.push_back(derivative);
1550  } else { // now global ones
1551  const unsigned int numPar = nFitParams - lasBeam.firstFixedParameter();
1552  theIntBuffer.push_back(thePedeLabels->parameterLabel(beamLabel, numPar));
1553  theFloatBufferX.push_back(derivative);
1554  }
1555  } // end loop over parameters
1556 
1557  const float residual = hit.localPosition().x() - tsoses[iHit].localPosition().x();
1558  // error from file or assume 0.003
1559  const float error = 0.003; // hit.localPositionError().xx(); sqrt???
1560 
1561  theMille->mille(lasLocalDerivsX.size(),
1562  &(lasLocalDerivsX[0]),
1563  theFloatBufferX.size(),
1564  &(theFloatBufferX[0]),
1565  &(theIntBuffer[0]),
1566  residual,
1567  error);
1568  } // end of loop over hits
1569 
1570  theMille->end();
1571 }
1572 
1574  // do some printing, if requested
1575  const bool doOutputOnStdout(pxbSurveyCfg.getParameter<bool>("doOutputOnStdout"));
1576  if (doOutputOnStdout) {
1577  edm::LogInfo("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::addPxbSurvey"
1578  << "# Output from addPxbSurvey follows below because "
1579  << "doOutputOnStdout is set to True";
1580  }
1581 
1582  // instantiate a dicer object
1583  SurveyPxbDicer dicer(pxbSurveyCfg.getParameter<std::vector<edm::ParameterSet> >("toySurveyParameters"),
1584  pxbSurveyCfg.getParameter<unsigned int>("toySurveySeed"));
1585  std::ofstream outfile(pxbSurveyCfg.getUntrackedParameter<std::string>("toySurveyFile").c_str());
1586 
1587  // read data from file
1588  std::vector<SurveyPxbImageLocalFit> measurements;
1589  std::string filename(pxbSurveyCfg.getParameter<edm::FileInPath>("infile").fullPath());
1591 
1592  // loop over photographs (=measurements) and perform the fit
1593  for (std::vector<SurveyPxbImageLocalFit>::size_type i = 0; i != measurements.size(); i++) {
1594  if (doOutputOnStdout) {
1595  edm::LogInfo("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::addPxbSurvey"
1596  << "Module " << i << ": ";
1597  }
1598 
1599  // get the Alignables and their surfaces
1600  AlignableDetOrUnitPtr mod1(theAlignableNavigator->alignableFromDetId(measurements[i].getIdFirst()));
1601  AlignableDetOrUnitPtr mod2(theAlignableNavigator->alignableFromDetId(measurements[i].getIdSecond()));
1602  const AlignableSurface &surf1 = mod1->surface();
1603  const AlignableSurface &surf2 = mod2->surface();
1604 
1605  // the position of the fiducial points in local frame of a PXB module
1606  const LocalPoint fidpoint0(-0.91, +3.30);
1607  const LocalPoint fidpoint1(+0.91, +3.30);
1608  const LocalPoint fidpoint2(+0.91, -3.30);
1609  const LocalPoint fidpoint3(-0.91, -3.30);
1610 
1611  // We choose the local frame of the first module as reference,
1612  // so take the fidpoints of the second module and calculate their
1613  // positions in the reference frame
1614  const GlobalPoint surf2point0(surf2.toGlobal(fidpoint0));
1615  const GlobalPoint surf2point1(surf2.toGlobal(fidpoint1));
1616  const LocalPoint fidpoint0inSurf1frame(surf1.toLocal(surf2point0));
1617  const LocalPoint fidpoint1inSurf1frame(surf1.toLocal(surf2point1));
1618 
1619  // Create the vector for the fit
1621  fidpointvec.push_back(fidpoint0inSurf1frame);
1622  fidpointvec.push_back(fidpoint1inSurf1frame);
1623  fidpointvec.push_back(fidpoint2);
1624  fidpointvec.push_back(fidpoint3);
1625 
1626  // if toy survey is requested, dice the values now
1627  if (pxbSurveyCfg.getParameter<bool>("doToySurvey")) {
1628  dicer.doDice(fidpointvec, measurements[i].getIdPair(), outfile);
1629  }
1630 
1631  // do the fit
1632  measurements[i].doFit(fidpointvec, thePedeLabels->alignableLabel(mod1), thePedeLabels->alignableLabel(mod2));
1633  SurveyPxbImageLocalFit::localpars_t a; // local pars from fit
1634  a = measurements[i].getLocalParameters();
1635  const SurveyPxbImageLocalFit::value_t chi2 = measurements[i].getChi2();
1636 
1637  // do some reporting, if requested
1638  if (doOutputOnStdout) {
1639  edm::LogInfo("Alignment") << "@SUB=MillePedeAlignmentAlgorithm::addPxbSurvey"
1640  << "a: " << a[0] << ", " << a[1] << ", " << a[2] << ", " << a[3]
1641  << " S= " << sqrt(a[2] * a[2] + a[3] * a[3]) << " phi= " << atan(a[3] / a[2])
1642  << " chi2= " << chi2 << std::endl;
1643  }
1644  if (theMonitor) {
1645  theMonitor->fillPxbSurveyHistsChi2(chi2);
1646  theMonitor->fillPxbSurveyHistsLocalPars(a[0], a[1], sqrt(a[2] * a[2] + a[3] * a[3]), atan(a[3] / a[2]));
1647  }
1648 
1649  // pass the results from the local fit to mille
1651  theMille->mille((int)measurements[i].getLocalDerivsSize(),
1652  measurements[i].getLocalDerivsPtr(j),
1653  (int)measurements[i].getGlobalDerivsSize(),
1654  measurements[i].getGlobalDerivsPtr(j),
1655  measurements[i].getGlobalDerivsLabelPtr(j),
1656  measurements[i].getResiduum(j),
1657  measurements[i].getSigma(j));
1658  }
1659  theMille->end();
1660  }
1661  outfile.close();
1662 }
1663 
1665  const auto runRangeSelection = theConfig.getUntrackedParameter<edm::VParameterSet>("RunRangeSelection");
1666 
1667  if (runRangeSelection.empty())
1668  return false;
1669 
1670  const auto runRanges =
1672 
1673  return !(runRanges.empty());
1674 }
MillePedeAlignmentAlgorithm::topoToken_
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > topoToken_
Definition: MillePedeAlignmentAlgorithm.h:273
TkFittedLasBeam.h
MillePedeAlignmentAlgorithm::theDir
std::string theDir
Definition: MillePedeAlignmentAlgorithm.h:284
MillePedeVariables::increaseHitsY
void increaseHitsY(unsigned int add=1)
increase hits for y-measurement
Definition: MillePedeVariables.h:84
dataset.firstRun
firstRun
Definition: dataset.py:940
pat::helper::ParametrizationHelper::dimension
uint32_t dimension(pat::CandKinResolution::Parametrization parametrization)
Returns the number of free parameters in a parametrization (3 or 4)
Definition: ParametrizationHelper.h:12
AlignmentIORoot.h
cond::time::MIN_VAL
const Time_t MIN_VAL(0)
SiStripLaserRecHit2D
Definition: SiStripLaserRecHit2D.h:12
AlignmentIORoot::writeAlignableAbsolutePositions
void writeAlignableAbsolutePositions(const align::Alignables &alivec, const char *filename, int iter, bool validCheck, int &ierr) override
write Alignable current absolute positions
Definition: AlignmentIORoot.cc:145
MillePedeAlignmentAlgorithm::theLastWrittenIov
int theLastWrittenIov
Definition: MillePedeAlignmentAlgorithm.h:301
GlobalPositionRcd.h
MillePedeFileReader::storeAlignments
bool storeAlignments()
Definition: MillePedeFileReader.cc:30
AlignmentParametersFactory.h
electrons_cff.bool
bool
Definition: electrons_cff.py:366
mps_fire.i
i
Definition: mps_fire.py:428
TsosVectorCollection
std::vector< std::vector< TrajectoryStateOnSurface > > TsosVectorCollection
Definition: TsosVectorCollection.h:16
MillePedeAlignmentAlgorithm::MillePedeAlignmentAlgorithm
MillePedeAlignmentAlgorithm(const edm::ParameterSet &cfg, edm::ConsumesCollector &iC)
Constructor.
Definition: MillePedeAlignmentAlgorithm.cc:87
MillePedeAlignmentAlgorithm::thePedeSteer
std::unique_ptr< PedeSteerer > thePedeSteer
Definition: MillePedeAlignmentAlgorithm.h:291
MessageLogger.h
cond::TimeTypeSpecs::beginValue
Time_t beginValue
Definition: Time.h:41
align
Definition: AlignableIndexer.h:30
MillePedeAlignmentAlgorithm::theConfig
edm::ParameterSet theConfig
Definition: MillePedeAlignmentAlgorithm.h:282
PedeLabelerPluginFactory.h
MillePedeAlignmentAlgorithm::firstIOV_
const align::RunNumber firstIOV_
Definition: MillePedeAlignmentAlgorithm.h:298
MillePedeAlignmentAlgorithm::addRefTrackVirtualMeas1D
void addRefTrackVirtualMeas1D(const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr, unsigned int iVirtualMeas, Eigen::MatrixBase< CovarianceMatrix > &aHitCovarianceM, Eigen::MatrixBase< ResidualMatrix > &aHitResidualsM, Eigen::MatrixBase< LocalDerivativeMatrix > &aLocalDerivativesM)
adds data for a specific virtual measurement from reference trajectory
Definition: MillePedeAlignmentAlgorithm.cc:1285
MillePedeAlignmentAlgorithm::makeGlobDerivMatrix
void makeGlobDerivMatrix(const std::vector< float > &globalDerivativesx, const std::vector< float > &globalDerivativesy, Eigen::MatrixBase< GlobalDerivativeMatrix > &aGlobalDerivativesM)
Definition: MillePedeAlignmentAlgorithm.cc:1242
TkLasBeam::getBeamId
unsigned int getBeamId(void) const
return the full beam identifier
Definition: TkLasBeam.h:23
AlignmentParameterStore::alignables
const align::Alignables & alignables(void) const
get all alignables
Definition: AlignmentParameterStore.h:47
AlignmentParameterStore::resetParameters
void resetParameters(void)
reset parameters, correlations, user variables
Definition: AlignmentParameterStore.cc:271
ESHandle.h
AlgebraicObjects.h
muon
Definition: MuonCocktails.h:17
MillePedeAlignmentAlgorithm::globalDerivativesCalibration
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
Definition: MillePedeAlignmentAlgorithm.cc:956
MillePedeFileReader::read
void read()
Definition: MillePedeFileReader.cc:24
CalibrationSummaryClient_cfi.params
params
Definition: CalibrationSummaryClient_cfi.py:14
edm::Run
Definition: Run.h:45
MillePedeAlignmentAlgorithm::theMonitor
std::unique_ptr< MillePedeMonitor > theMonitor
Definition: MillePedeAlignmentAlgorithm.h:288
edm
HLT enums.
Definition: AlignableModifier.h:19
TrackerTopology
Definition: TrackerTopology.h:16
MillePedeAlignmentAlgorithm::theFloatBufferX
std::vector< float > theFloatBufferX
Definition: MillePedeAlignmentAlgorithm.h:302
SurveyPxbImage.h
Alignable
Definition: Alignable.h:27
MillePedeAlignmentAlgorithm::kLocalY
Definition: MillePedeAlignmentAlgorithm.h:121
MillePedeAlignmentAlgorithm::theMaximalCor2D
double theMaximalCor2D
Definition: MillePedeAlignmentAlgorithm.h:296
ALCARECOPromptCalibProdSiPixelAli0T_cff.mode
mode
Definition: ALCARECOPromptCalibProdSiPixelAli0T_cff.py:96
AlignableExtras.h
PedeReader
Definition: PedeReader.h:33
AlignmentParameterStore::restoreCachedTransformations
void restoreCachedTransformations(void)
restore the previously cached position, rotation and other parameters
Definition: AlignmentParameterStore.cc:316
GeomDetType.h
MillePedeAlignmentAlgorithm::theAlignables
align::Alignables theAlignables
Definition: MillePedeAlignmentAlgorithm.h:286
MillePedeAlignmentAlgorithm.h
MillePedeAlignmentAlgorithm::theTrajectoryFactory
std::unique_ptr< TrajectoryFactoryBase > theTrajectoryFactory
Definition: MillePedeAlignmentAlgorithm.h:292
MillePedeAlignmentAlgorithm::uniqueRunRanges_
const align::RunRanges uniqueRunRanges_
Definition: MillePedeAlignmentAlgorithm.h:314
AlignmentParameters::userVariables
AlignmentUserVariables * userVariables(void) const
Get pointer to user variables.
Definition: AlignmentParameters.cc:101
edm::VParameterSet
std::vector< ParameterSet > VParameterSet
Definition: ParameterSet.h:34
MillePedeAlignmentAlgorithm::theGblDoubleBinary
bool theGblDoubleBinary
Definition: MillePedeAlignmentAlgorithm.h:308
funct::derivative
Derivative< X, A >::type derivative(const A &_)
Definition: Derivative.h:18
edm::ValidityInterval::first
const IOVSyncValue & first() const
Definition: ValidityInterval.h:37
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:222
MillePedeAlignmentAlgorithm::cachedRuns_
std::vector< align::RunNumber > cachedRuns_
Definition: MillePedeAlignmentAlgorithm.h:316
SiStripDetId.h
MillePedeAlignmentAlgorithm::endRun
virtual void endRun(const EventInfo &, const EndRunInfo &, const edm::EventSetup &)
Run on run products, e.g. TkLAS.
Definition: MillePedeAlignmentAlgorithm.cc:692
TrackerAlignmentRcd
Definition: TrackerAlignmentRcd.h:6
FastTrackerRecHitMaskProducer_cfi.trajectories
trajectories
Definition: FastTrackerRecHitMaskProducer_cfi.py:7
AlignPCLThresholds
Definition: AlignPCLThresholds.h:11
AlignPCLThresholdsRcd
Definition: AlignPCLThresholdsRcd.h:23
edm::eventsetup::EventSetupRecordImplementation::key
EventSetupRecordKey key() const override
Definition: EventSetupRecordImplementation.h:45
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
ReferenceCountingPointer
Definition: ReferenceCounted.h:60
MillePedeAlignmentAlgorithm::decodeMode
unsigned int decodeMode(const std::string &mode) const
Definition: MillePedeAlignmentAlgorithm.cc:1173
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
MillePedeAlignmentAlgorithm::endLuminosityBlock
void endLuminosityBlock(const edm::EventSetup &) override
called at end of luminosity block
Definition: MillePedeAlignmentAlgorithm.cc:718
AlignableSurface::toLocal
align::RotationType toLocal(const align::RotationType &) const
Return in local frame a rotation given in global frame.
Definition: AlignableSurface.cc:35
beamerCreator.create
def create(alignables, pedeDump, additionalData, outputFile, config)
Definition: beamerCreator.py:44
MillePedeAlignmentAlgorithm::theMille
std::unique_ptr< Mille > theMille
Definition: MillePedeAlignmentAlgorithm.h:289
hltPixelTracks_cff.chi2
chi2
Definition: hltPixelTracks_cff.py:25
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
AlignmentIORoot::writeAlignableOriginalPositions
void writeAlignableOriginalPositions(const align::Alignables &alivec, const char *filename, int iter, bool validCheck, int &ierr) override
write Alignable original (before misalignment) absolute positions
Definition: AlignmentIORoot.cc:201
SurveyPxbImageReader
Class to hold one picture of the BPix survey.
Definition: SurveyPxbImageReader.h:15
relativeConstraints.error
error
Definition: relativeConstraints.py:53
AlignableDetOrUnitPtr
Definition: AlignableDetOrUnitPtr.h:30
MillePedeAlignmentAlgorithm::terminate
void terminate() override
Called at end of job.
Definition: MillePedeAlignmentAlgorithm.cc:365
MillePedeAlignmentAlgorithm::getExistingFormattedFiles
std::vector< std::string > getExistingFormattedFiles(const std::vector< std::string > &plainFiles, const std::string &theDir)
Definition: MillePedeAlignmentAlgorithm.cc:422
edm::ParameterSet::addUntrackedParameter
void addUntrackedParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:192
MillePedeAlignmentAlgorithm::lastProcessedRun_
align::RunNumber lastProcessedRun_
Definition: MillePedeAlignmentAlgorithm.h:317
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
PedeLabelerBase.h
MillePedeAlignmentAlgorithm::theThresholds
std::shared_ptr< AlignPCLThresholds > theThresholds
Definition: MillePedeAlignmentAlgorithm.h:294
TrackerSurfaceDeformationRcd.h
MillePedeAlignmentAlgorithm::theDoSurveyPixelBarrel
bool theDoSurveyPixelBarrel
Definition: MillePedeAlignmentAlgorithm.h:305
AlignmentAlgorithmBase
Definition: AlignmentAlgorithmBase.h:60
GlobalPositionRcd
Definition: GlobalPositionRcd.h:6
rpcPointValidation_cfi.recHit
recHit
Definition: rpcPointValidation_cfi.py:7
singleTopDQM_cfi.setup
setup
Definition: singleTopDQM_cfi.py:37
MillePedeAlignmentAlgorithm::myMilleBit
Definition: MillePedeAlignmentAlgorithm.h:276
Mille.h
AlignmentParameters
Definition: AlignmentParameters.h:35
MillePedeAlignmentAlgorithm::beginRun
void beginRun(const edm::Run &run, const edm::EventSetup &setup, bool changed) override
called at begin of run
Definition: MillePedeAlignmentAlgorithm.cc:619
SurveyPxbDicer::doDice
std::string doDice(const fidpoint_t &fidpointvec, const idPair_t &id, const bool rotate=false)
Definition: SurveyPxbDicer.cc:37
convertSQLiteXML.runNumber
runNumber
Definition: convertSQLiteXML.py:91
MillePedeVariables.h
TrackerAlignmentErrorExtendedRcd.h
edmScanValgrind.buffer
buffer
Definition: edmScanValgrind.py:171
MillePedeAlignmentAlgorithm::addGlobalData
int addGlobalData(const edm::EventSetup &setup, const EventInfo &eventInfo, const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr, unsigned int iHit, gbl::GblPoint &gblPoint)
Definition: MillePedeAlignmentAlgorithm.cc:775
hit::x
double x
Definition: SiStripHitEffFromCalibTree.cc:89
AlignmentParameters.h
CovarianceMatrix
math::Error< 5 >::type CovarianceMatrix
Definition: SeedToTrackProducer.h:48
MillePedeAlignmentAlgorithm::addLaserData
void addLaserData(const EventInfo &eventInfo, const TkFittedLasBeamCollection &tkLasBeams, const TsosVectorCollection &tkLasBeamTsoses)
Definition: MillePedeAlignmentAlgorithm.cc:1507
MillePedeAlignmentAlgorithm::isMode
bool isMode(unsigned int testMode) const
Definition: MillePedeAlignmentAlgorithm.h:278
MillePedeAlignmentAlgorithm::myPedeSteerBit
Definition: MillePedeAlignmentAlgorithm.h:276
MillePedeAlignmentAlgorithm::theAlignableNavigator
std::unique_ptr< AlignableNavigator > theAlignableNavigator
Definition: MillePedeAlignmentAlgorithm.h:287
edm::FileInPath
Definition: FileInPath.h:61
MillePedeVariables::hitsY
unsigned int hitsY() const
get number of hits for y-measurement
Definition: MillePedeVariables.h:82
MillePedeAlignmentAlgorithm::callMille
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
Definition: MillePedeAlignmentAlgorithm.cc:1332
TrajectoryStateOnSurface
Definition: TrajectoryStateOnSurface.h:16
MillePedeVariables::size
unsigned int size() const
number of parameters
Definition: MillePedeVariables.h:33
MillePedeAlignmentAlgorithm::setParametersForRunRange
bool setParametersForRunRange(const RunRange &runrange) override
Definition: MillePedeAlignmentAlgorithm.cc:333
MillePedeVariablesIORoot.h
TsosVectorCollection.h
trigger::size_type
uint16_t size_type
Definition: TriggerTypeDefs.h:18
cond::timeTypeSpecs
const TimeTypeSpecs timeTypeSpecs[]
Definition: Time.cc:16
TrackerSurfaceDeformationRcd
Definition: TrackerSurfaceDeformationRcd.h:6
ConstRecHitPointer
TransientTrackingRecHit::ConstRecHitPointer ConstRecHitPointer
Definition: MillePedeAlignmentAlgorithm.cc:70
Track.h
submitPVResolutionJobs.files
files
Definition: submitPVResolutionJobs.py:373
MillePedeAlignmentAlgorithm::myPedeRunBit
Definition: MillePedeAlignmentAlgorithm.h:276
SurveyPxbImageLocalFit::fidpoint_t
std::vector< coord_t > fidpoint_t
Definition: SurveyPxbImageLocalFit.h:17
Abs
T Abs(T a)
Definition: MathUtil.h:49
align::makeNonOverlappingRunRanges
RunRanges makeNonOverlappingRunRanges(const edm::VParameterSet &runRanges, const RunNumber &defaultRun)
Definition: Utilities.cc:202
std::swap
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
Definition: DataFrameContainer.h:209
MillePedeAlignmentAlgorithm::addHitStatistics
bool addHitStatistics(int fromLoop, const std::string &outFile, const std::vector< std::string > &inFiles) const
Definition: MillePedeAlignmentAlgorithm.cc:1195
AlignmentParameterStore::applyParameters
void applyParameters(void)
Obsolete: Use AlignableNavigator::alignableDetFromDetId and alignableFromAlignableDet.
Definition: AlignmentParameterStore.cc:255
DQM.reader
reader
Definition: DQM.py:105
alignCSCRings.corr
dictionary corr
Definition: alignCSCRings.py:124
MillePedeAlignmentAlgorithm::enableAlignableUpdates_
const bool enableAlignableUpdates_
Definition: MillePedeAlignmentAlgorithm.h:300
MillePedeAlignmentAlgorithm::globalDerivativesHierarchy
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
Definition: MillePedeAlignmentAlgorithm.cc:839
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
MillePedeAlignmentAlgorithm::supportsCalibrations
bool supportsCalibrations() override
Returns whether MP supports calibrations.
Definition: MillePedeAlignmentAlgorithm.cc:291
Run.h
AlignableTracker
Definition: AlignableTracker.h:17
MillePedeAlignmentAlgorithm::theCalibrations
std::vector< IntegratedCalibrationBase * > theCalibrations
Definition: MillePedeAlignmentAlgorithm.h:293
corrVsCorr.filename
filename
Definition: corrVsCorr.py:123
MillePedeAlignmentAlgorithm::theBinary
std::unique_ptr< gbl::MilleBinary > theBinary
Definition: MillePedeAlignmentAlgorithm.h:307
PedeLabelerBase::TopLevelAlignables
Definition: PedeLabelerBase.h:39
MillePedeAlignmentAlgorithm::diagonalize
void diagonalize(Eigen::MatrixBase< CovarianceMatrix > &aHitCovarianceM, Eigen::MatrixBase< LocalDerivativeMatrix > &aLocalDerivativesM, Eigen::MatrixBase< ResidualMatrix > &aHitResidualsM, Eigen::MatrixBase< GlobalDerivativeMatrix > &aGlobalDerivativesM) const
Definition: MillePedeAlignmentAlgorithm.cc:1258
edm::eventsetup::EventSetupRecordKey::name
const char * name() const
Definition: EventSetupRecordKey.h:46
MillePedeVariables::hitsX
unsigned int hitsX() const
get number of hits for x-measurement
Definition: MillePedeVariables.h:76
AlignableSurface::toGlobal
align::GlobalPoints toGlobal(const align::LocalPoints &) const
Return in global coord given a set of local points.
Definition: AlignableSurface.cc:15
Alignable::surface
const AlignableSurface & surface() const
Return the Surface (global position and orientation) of the object.
Definition: Alignable.h:132
MillePedeAlignmentAlgorithm::theIntBuffer
std::vector< int > theIntBuffer
Definition: MillePedeAlignmentAlgorithm.h:304
MillePedeAlignmentAlgorithm::theAlignmentParameterStore
AlignmentParameterStore * theAlignmentParameterStore
directory for all kind of files
Definition: MillePedeAlignmentAlgorithm.h:285
AlignableExtras
Definition: AlignableExtras.h:19
MillePedeAlignmentAlgorithm::aliThrToken_
const edm::ESGetToken< AlignPCLThresholds, AlignPCLThresholdsRcd > aliThrToken_
Definition: MillePedeAlignmentAlgorithm.h:274
AlignmentAlgorithmBase::EndRunInfo
define run information passed to algorithms (in endRun)
Definition: AlignmentAlgorithmBase.h:97
Point3DBase< float, LocalTag >
MillePedeAlignmentAlgorithm::runAtPCL_
const bool runAtPCL_
Definition: MillePedeAlignmentAlgorithm.h:310
AlignableNavigator.h
sistrip::SpyUtilities::isValid
const bool isValid(const Frame &aFrame, const FrameQuality &aQuality, const uint16_t aExpectedPos)
Definition: SiStripSpyUtilities.cc:124
MillePedeAlignmentAlgorithm::addLasBeam
void addLasBeam(const EventInfo &eventInfo, const TkFittedLasBeam &lasBeam, const std::vector< TrajectoryStateOnSurface > &tsoses)
Definition: MillePedeAlignmentAlgorithm.cc:1524
SiStripDetId::TEC
static constexpr auto TEC
Definition: SiStripDetId.h:40
AlignmentParameterStore.h
edm::EventID::run
RunNumber_t run() const
Definition: EventID.h:38
MillePedeAlignmentAlgorithm::thePedeLabels
std::shared_ptr< PedeLabelerBase > thePedeLabels
Definition: MillePedeAlignmentAlgorithm.h:290
L1TdeCSCTF_cfi.outFile
outFile
Definition: L1TdeCSCTF_cfi.py:5
RefTrajColl
TrajectoryFactoryBase::ReferenceTrajectoryCollection RefTrajColl
Definition: MillePedeAlignmentAlgorithm.cc:71
MillePedeAlignmentAlgorithm::run
void run(const edm::EventSetup &setup, const EventInfo &eventInfo) override
Run the algorithm on trajectories and tracks.
Definition: MillePedeAlignmentAlgorithm.cc:463
geometryDiff.file
file
Definition: geometryDiff.py:13
MillePedeAlignmentAlgorithm::theMinNumHits
unsigned int theMinNumHits
Definition: MillePedeAlignmentAlgorithm.h:295
PbPb_ZMuSkimMuonDPG_cff.tracker
tracker
Definition: PbPb_ZMuSkimMuonDPG_cff.py:60
cond
Definition: plugin.cc:23
edm::ParameterSet::exists
bool exists(std::string const &parameterName) const
checks if a parameter exists
Definition: ParameterSet.cc:681
MillePedeAlignmentAlgorithm::addHits
bool addHits(const align::Alignables &alis, const std::vector< AlignmentUserVariables * > &mpVars) const
Definition: MillePedeAlignmentAlgorithm.cc:1220
MillePedeAlignmentAlgorithm::callMille2D
int callMille2D(const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr, unsigned int iTrajHit, const std::vector< int > &globalLabels, const std::vector< float > &globalDerivativesx, const std::vector< float > &globalDerivativesy)
Definition: MillePedeAlignmentAlgorithm.cc:1384
SurveyPxbImageLocalFit.h
MillePedeVariables::setAllDefault
bool setAllDefault(unsigned int nParam)
set default values for all data concerning nParam (false if nParam out of range)
Definition: MillePedeVariables.cc:32
MillePedeAlignmentAlgorithm::enforceSingleIOVInput_
const bool enforceSingleIOVInput_
Definition: MillePedeAlignmentAlgorithm.h:315
edm::IOVSyncValue::eventID
const EventID & eventID() const
Definition: IOVSyncValue.h:40
MillePedeAlignmentAlgorithm::areEmptyParams
bool areEmptyParams(const align::Alignables &alignables) const
Definition: MillePedeAlignmentAlgorithm.cc:1068
TrajectoryFactoryBase::ReferenceTrajectoryCollection
std::vector< ReferenceTrajectoryPtr > ReferenceTrajectoryCollection
Definition: TrajectoryFactoryBase.h:26
edm::ParameterSet
Definition: ParameterSet.h:47
edm::Transition
Transition
Definition: Transition.h:12
SurveyPxbImageLocalFit::count_t
unsigned int count_t
Definition: SurveyPxbImageLocalFit.h:18
a
double a
Definition: hdecay.h:119
DetId::Tracker
Definition: DetId.h:25
AlignableDetOrUnitPtr.h
tracks
const uint32_t *__restrict__ const HitContainer *__restrict__ TkSoA *__restrict__ tracks
Definition: CAHitNtupletGeneratorKernelsImpl.h:176
MillePedeAlignmentAlgorithm::processesEvents
bool processesEvents() override
Returns whether MP should process events in the current configuration.
Definition: MillePedeAlignmentAlgorithm.cc:308
TrackingRecHit::ConstRecHitContainer
std::vector< ConstRecHitPointer > ConstRecHitContainer
Definition: TrackingRecHit.h:32
MillePedeVariables::increaseHitsX
void increaseHitsX(unsigned int add=1)
increase hits for x-measurement
Definition: MillePedeVariables.h:78
AlignableMuon.h
TrajectoryFactoryPlugin.h
AlignmentAlgorithmBase::RunNumber
align::RunNumber RunNumber
Definition: AlignmentAlgorithmBase.h:69
MillePedeAlignmentAlgorithm::addPxbSurvey
void addPxbSurvey(const edm::ParameterSet &pxbSurveyCfg)
add measurement data from PXB survey
Definition: MillePedeAlignmentAlgorithm.cc:1573
heppy_loop.loop
loop
Definition: heppy_loop.py:28
cond::runnumber
Definition: Time.h:19
MillePedeFileReader
Definition: MillePedeFileReader.h:57
MillePedeAlignmentAlgorithm::addReferenceTrajectory
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 'bad' trajectory)
Definition: MillePedeAlignmentAlgorithm.cc:499
TkFittedLasBeam::parameters
const std::vector< Scalar > & parameters() const
parallel to derivatives()
Definition: TkFittedLasBeam.h:29
MillePedeAlignmentAlgorithm::addRefTrackData2D
void addRefTrackData2D(const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr, unsigned int iTrajHit, Eigen::MatrixBase< CovarianceMatrix > &aHitCovarianceM, Eigen::MatrixBase< ResidualMatrix > &aHitResidualsM, Eigen::MatrixBase< LocalDerivativeMatrix > &aLocalDerivativesM)
adds data from reference trajectory from a specific Hit
Definition: MillePedeAlignmentAlgorithm.cc:1306
AlignableMuon
Constructor of the full muon geometry.
Definition: AlignableMuon.h:38
TrackingRecHit::ConstRecHitPointer
std::shared_ptr< TrackingRecHit const > ConstRecHitPointer
Definition: TrackingRecHit.h:25
createfilelist.int
int
Definition: createfilelist.py:10
cond::time::MAX_VAL
const Time_t MAX_VAL(std::numeric_limits< Time_t >::max())
cond::TimeTypeSpecs::endValue
Time_t endValue
Definition: Time.h:42
MillePedeAlignmentAlgorithm::beginLuminosityBlock
void beginLuminosityBlock(const edm::EventSetup &) override
called at begin of luminosity block (resets Mille binary in mille mode)
Definition: MillePedeAlignmentAlgorithm.cc:710
IdealGeometryRecord.h
TrackerAlignmentRcd.h
ProjectedSiStripRecHit2D.h
MillePedeAlignmentAlgorithm::addMeasurementData
int addMeasurementData(const edm::EventSetup &setup, const EventInfo &eventInfo, const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr, unsigned int iHit, AlignmentParameters *&params)
Definition: MillePedeAlignmentAlgorithm.cc:726
edm::EventSetup
Definition: EventSetup.h:58
AlignmentParameterStore::cacheTransformations
void cacheTransformations(void)
cache the current position, rotation and other parameters
Definition: AlignmentParameterStore.cc:303
TkFittedLasBeam
Definition: TkFittedLasBeam.h:18
reco::JetExtendedAssociation::value_type
Container::value_type value_type
Definition: JetExtendedAssociation.h:30
MillePedeAlignmentAlgorithm::initialize
void initialize(const edm::EventSetup &setup, AlignableTracker *tracker, AlignableMuon *muon, AlignableExtras *extras, AlignmentParameterStore *store) override
Called at beginning of job.
Definition: MillePedeAlignmentAlgorithm.cc:130
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
get
#define get
AlignPCLThresholds::threshold_map
std::map< std::string, AlignPCLThreshold > threshold_map
Definition: AlignPCLThresholds.h:13
MillePedeAlignmentAlgorithm::~MillePedeAlignmentAlgorithm
~MillePedeAlignmentAlgorithm() override
Destructor.
Definition: MillePedeAlignmentAlgorithm.cc:126
MillePedeVariablesIORoot::readMillePedeVariables
std::vector< AlignmentUserVariables * > readMillePedeVariables(const align::Alignables &alivec, const char *filename, int iter, int &ierr)
Definition: MillePedeVariablesIORoot.cc:59
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
MillePedeAlignmentAlgorithm::callMille1D
int callMille1D(const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr, unsigned int iTrajHit, const std::vector< int > &globalLabels, const std::vector< float > &globalDerivativesX)
calls Mille for 1D hits
Definition: MillePedeAlignmentAlgorithm.cc:1347
MillePedeVariablesIORoot
Definition: MillePedeVariablesIORoot.h:29
MillePedeAlignmentAlgorithm::theFloatBufferY
std::vector< float > theFloatBufferY
Definition: MillePedeAlignmentAlgorithm.h:303
MillePedeAlignmentAlgorithm::storeThresholds
virtual bool storeThresholds(const int &nRecords, const AlignPCLThresholds::threshold_map &thresholdMap)
Definition: MillePedeAlignmentAlgorithm.cc:301
looper.cfg
cfg
Definition: looper.py:296
AlignmentIORoot::writeOrigRigidBodyAlignmentParameters
void writeOrigRigidBodyAlignmentParameters(const align::Alignables &alivec, const char *filename, int iter, bool validCheck, int &ierr) override
write RigidBodyAlignmentParameters as applied on top of original positions
Definition: AlignmentIORoot.cc:65
SiStripDetId::TID
static constexpr auto TID
Definition: SiStripDetId.h:38
dumpTauVariables_cfi.eventInfo
eventInfo
add run, event number and lumi section
Definition: dumpTauVariables_cfi.py:12
SurveyPxbDicer.h
Trajectory.h
GeomDet.h
align::Alignables
std::vector< Alignable * > Alignables
Definition: Utilities.h:31
MillePedeAlignmentAlgorithm::myPedeReadBit
Definition: MillePedeAlignmentAlgorithm.h:276
MillePedeMonitor.h
std
Definition: JetResolutionObject.h:76
AlgebraicMatrix
CLHEP::HepMatrix AlgebraicMatrix
Definition: AlgebraicObjects.h:14
writedatasetfile.run
run
Definition: writedatasetfile.py:27
MillePedeAlignmentAlgorithm::skipGlobalPositionRcdCheck_
const bool skipGlobalPositionRcdCheck_
Definition: MillePedeAlignmentAlgorithm.h:312
MillePedeAlignmentAlgorithm::ignoreFirstIOVCheck_
const bool ignoreFirstIOVCheck_
Definition: MillePedeAlignmentAlgorithm.h:299
MillePedeAlignmentAlgorithm::ignoreHitsWithoutGlobalDerivatives_
const bool ignoreHitsWithoutGlobalDerivatives_
Definition: MillePedeAlignmentAlgorithm.h:311
SurveyPxbDicer
Definition: SurveyPxbDicer.h:21
MillePedeAlignmentAlgorithm::addCalibrations
bool addCalibrations(const std::vector< IntegratedCalibrationBase * > &iCals) override
Pass integrated calibrations to Millepede (they are not owned by Millepede!)
Definition: MillePedeAlignmentAlgorithm.cc:294
ConstRecHitContainer
TransientTrackingRecHit::ConstRecHitContainer ConstRecHitContainer
Definition: MillePedeAlignmentAlgorithm.cc:69
AlignmentParameterStore
Definition: AlignmentParameterStore.h:23
MillePedeAlignmentAlgorithm::kLocalX
Definition: MillePedeAlignmentAlgorithm.h:121
MillePedeAlignmentAlgorithm::is2D
bool is2D(const TransientTrackingRecHit::ConstRecHitPointer &recHit) const
true if hit belongs to 2D detector (currently tracker specific)
Definition: MillePedeAlignmentAlgorithm.cc:1011
MillePedeAlignmentAlgorithm::addHitCount
unsigned int addHitCount(const std::vector< AlignmentParameters * > &parVec, const std::vector< bool > &validHitVecY) const
Definition: MillePedeAlignmentAlgorithm.cc:590
AlignableSurface
Definition: AlignableSurface.h:20
TkFittedLasBeam::firstFixedParameter
unsigned int firstFixedParameter() const
Definition: TkFittedLasBeam.h:36
MillePedeVariablesIORoot::writeMillePedeVariables
void writeMillePedeVariables(const align::Alignables &alivec, const char *filename, int iter, bool validCheck, int &ierr)
Definition: MillePedeVariablesIORoot.cc:35
LocalPoint.h
relativeConstraints.value
value
Definition: relativeConstraints.py:53
relativeConstraints.empty
bool empty
Definition: relativeConstraints.py:46
SurveyPxbImageReader.h
Exception
Definition: hltDiff.cc:245
SurveyPxbImage::value_t
double value_t
Definition: SurveyPxbImage.h:16
TkFittedLasBeamCollection
std::vector< TkFittedLasBeam > TkFittedLasBeamCollection
Definition: TkFittedLasBeamCollectionFwd.h:3
MillePedeAlignmentAlgorithm::readFromPede
bool readFromPede(const edm::ParameterSet &mprespset, bool setUserVars, const RunRange &runrange)
read pede input defined by 'psetName', flag to create/not create MillePedeVariables
Definition: MillePedeAlignmentAlgorithm.cc:1029
MillePedeAlignmentAlgorithm::storeAlignments
bool storeAlignments() override
Returns whether MP produced results to be stored.
Definition: MillePedeAlignmentAlgorithm.cc:317
IntegratedCalibrationBase.h
EventSetup.h
align::makeUniqueRunRanges
RunRanges makeUniqueRunRanges(const edm::VParameterSet &runRanges, const RunNumber &defaultRun)
Definition: Utilities.cc:241
submitPVValidationJobs.runInfo
dictionary runInfo
Definition: submitPVValidationJobs.py:1013
TkLasBeam::getData
const std::vector< SiStripLaserRecHit2D > & getData(void) const
access the collection of hits
Definition: TkLasBeam.h:26
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
AlignmentAlgorithmBase::RunRange
align::RunRange RunRange
Definition: AlignmentAlgorithmBase.h:70
cond::persistency::throwException
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:12
MillePedeFileReader.h
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
PedeReader.h
AlignmentIORoot
Definition: AlignmentIORoot.h:15
mps_fire.result
result
Definition: mps_fire.py:311
AlignableTracker.h
timingPdfMaker.outfile
outfile
Definition: timingPdfMaker.py:350
TrackerTopologyRcd
Definition: TrackerTopologyRcd.h:10
MillePedeVariables
Definition: MillePedeVariables.h:21
MillePedeAlignmentAlgorithm::addVirtualMeas
void addVirtualMeas(const ReferenceTrajectoryBase::ReferenceTrajectoryPtr &refTrajPtr, unsigned int iVirtualMeas)
adds data for virtual measurements from reference trajectory
Definition: MillePedeAlignmentAlgorithm.cc:1479
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
edm_modernize_messagelogger.stat
stat
Definition: edm_modernize_messagelogger.py:27
DeDxTools::esConsumes
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
hltrates_dqm_sourceclient-live_cfg.offset
offset
Definition: hltrates_dqm_sourceclient-live_cfg.py:82
MillePedeAlignmentAlgorithm::doIO
unsigned int doIO(int loop) const
Definition: MillePedeAlignmentAlgorithm.cc:1089
edm::eventsetup::EventSetupRecord::validityInterval
ValidityInterval validityInterval() const
Definition: EventSetupRecord.h:94
MillePedeAlignmentAlgorithm::buildUserVariables
void buildUserVariables(const align::Alignables &alignables) const
add MillePedeVariables for each AlignmentParameters (exception if no parameters......
Definition: MillePedeAlignmentAlgorithm.cc:1146
AlignmentAlgorithmBase::EventInfo::trajTrackPairs
const ConstTrajTrackPairCollection & trajTrackPairs() const
Definition: AlignmentAlgorithmBase.h:85
crabWrapper.key
key
Definition: crabWrapper.py:19
Alignable::alignmentParameters
AlignmentParameters * alignmentParameters() const
Get the AlignmentParameters.
Definition: Alignable.h:58
TrackerAlignmentErrorExtendedRcd
Definition: TrackerAlignmentErrorExtendedRcd.h:6
GlobalPoint.h
edm::ConsumesCollector
Definition: ConsumesCollector.h:45
IdealGeometryRecord
Definition: IdealGeometryRecord.h:25
edm::FileInPath::fullPath
std::string fullPath() const
Definition: FileInPath.cc:161
hit
Definition: SiStripHitEffFromCalibTree.cc:88
TrajectoryFactoryBase.h
TkFittedLasBeam::derivatives
const AlgebraicMatrix & derivatives() const
matrix of local derivatives: columns are parameters, rows are hits
Definition: TkFittedLasBeam.h:33
SurveyPxbImageLocalFit::nMsrmts
static const count_t nMsrmts
Definition: SurveyPxbImageLocalFit.h:21
SurveyPxbImageLocalFit::localpars_t
std::vector< value_t > localpars_t
Definition: SurveyPxbImageLocalFit.h:16
AlignmentAlgorithmBase::EventInfo
define event information passed to algorithms
Definition: AlignmentAlgorithmBase.h:73
Alignable::mother
Alignable * mother() const
Return pointer to container alignable (if any)
Definition: Alignable.h:91
MillePedeAlignmentAlgorithm::areIOVsSpecified
bool areIOVsSpecified() const
Definition: MillePedeAlignmentAlgorithm.cc:1664
PedeSteerer.h