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