CMS 3D CMS Logo

HIPAlignmentAlgorithm.cc
Go to the documentation of this file.
1 #include <fstream>
2 #include <unordered_map>
3 
4 #include "TFile.h"
5 #include "TTree.h"
6 #include "TList.h"
7 #include "TRandom.h"
8 #include "TMath.h"
9 
18 
21 
37 
39 
40 // Constructor ----------------------------------------------------------------
43  topoToken_(iC.esConsumes<TrackerTopology, IdealGeometryRecord, edm::Transition::EndRun>()),
44  topoToken2_(iC.esConsumes<TrackerTopology, TrackerTopologyRcd, edm::Transition::EndRun>()),
45  verbose(cfg.getParameter<bool>("verbosity")),
46  theMonitorConfig(cfg),
47  doTrackHitMonitoring(theMonitorConfig.fillTrackMonitoring || theMonitorConfig.fillTrackHitMonitoring),
48  defaultAlignableSpecs((Alignable*)nullptr),
49  surveyResiduals_(cfg.getUntrackedParameter<std::vector<std::string>>("surveyResiduals")),
50  theTrackHitMonitorIORootFile(nullptr),
51  theTrackMonitorTree(nullptr),
52  theHitMonitorTree(nullptr),
53  theAlignablesMonitorIORootFile(nullptr),
54  theAlignablesMonitorTree(nullptr),
55  theSurveyIORootFile(nullptr),
56  theSurveyTree(nullptr) {
57  // parse parameters
58  outpath = cfg.getParameter<std::string>("outpath");
59  outfile2 = cfg.getParameter<std::string>("outfile2");
60  struefile = cfg.getParameter<std::string>("trueFile");
61  smisalignedfile = cfg.getParameter<std::string>("misalignedFile");
62  salignedfile = cfg.getParameter<std::string>("alignedFile");
63  siterationfile = cfg.getParameter<std::string>("iterationFile");
64  suvarfilecore = cfg.getParameter<std::string>("uvarFile");
66  sparameterfile = cfg.getParameter<std::string>("parameterFile");
67  ssurveyfile = cfg.getParameter<std::string>("surveyFile");
68 
69  outfile2 = outpath + outfile2; //Alignablewise tree
77 
78  // parameters for APE
79  theApplyAPE = cfg.getParameter<bool>("applyAPE");
80  theAPEParameterSet = cfg.getParameter<std::vector<edm::ParameterSet>>("apeParam");
81 
82  themultiIOV = cfg.getParameter<bool>("multiIOV");
83  theIOVrangeSet = cfg.getParameter<std::vector<unsigned>>("IOVrange");
84 
85  defaultAlignableSpecs.minNHits = cfg.getParameter<int>("minimumNumberOfHits");
86  defaultAlignableSpecs.minRelParError = cfg.getParameter<double>("minRelParameterError");
87  defaultAlignableSpecs.maxRelParError = cfg.getParameter<double>("maxRelParameterError");
88  defaultAlignableSpecs.maxHitPull = cfg.getParameter<double>("maxAllowedHitPull");
89  theApplyCutsPerComponent = cfg.getParameter<bool>("applyCutsPerComponent");
90  theCutsPerComponent = cfg.getParameter<std::vector<edm::ParameterSet>>("cutsPerComponent");
91 
92  // for collector mode (parallel processing)
93  isCollector = cfg.getParameter<bool>("collectorActive");
94  theCollectorNJobs = cfg.getParameter<int>("collectorNJobs");
95  theCollectorPath = cfg.getParameter<std::string>("collectorPath");
96 
97  if (isCollector)
98  edm::LogInfo("Alignment") << "@SUB=HIPAlignmentAlgorithm::HIPAlignmentAlgorithm"
99  << "Collector mode";
100 
101  trackPs = cfg.getParameter<bool>("UsePreSelection");
102  theDataGroup = cfg.getParameter<int>("DataGroup");
103  trackWt = cfg.getParameter<bool>("UseReweighting");
104  Scale = cfg.getParameter<double>("Weight");
105  uniEta = trackWt && cfg.getParameter<bool>("UniformEta");
106  uniEtaFormula = cfg.getParameter<std::string>("UniformEtaFormula");
107  if (uniEtaFormula.empty()) {
108  edm::LogWarning("Alignment") << "@SUB=HIPAlignmentAlgorithm::HIPAlignmentAlgorithm"
109  << "Uniform eta formula is empty! Resetting to 1.";
110  uniEtaFormula = "1";
111  }
112  theEtaFormula = std::make_unique<TFormula>(uniEtaFormula.c_str());
113  rewgtPerAli = trackWt && cfg.getParameter<bool>("ReweightPerAlignable");
114  IsCollision = cfg.getParameter<bool>("isCollision");
115  SetScanDet = cfg.getParameter<std::vector<double>>("setScanDet");
116  col_cut = cfg.getParameter<double>("CLAngleCut");
117  cos_cut = cfg.getParameter<double>("CSAngleCut");
118 
119  edm::LogInfo("Alignment") << "@SUB=HIPAlignmentAlgorithm::HIPAlignmentAlgorithm"
120  << "Constructed";
121 }
122 
123 // Call at beginning of job ---------------------------------------------------
127  AlignableExtras* extras,
128  AlignmentParameterStore* store) {
129  edm::LogInfo("Alignment") << "@SUB=HIPAlignmentAlgorithm::initialize"
130  << "Initializing...";
131 
132  alignableObjectId_ = std::make_unique<AlignableObjectId>(AlignableObjectId::commonObjectIdProvider(tracker, muon));
133 
134  for (const auto& level : surveyResiduals_)
135  theLevels.push_back(alignableObjectId_->stringToId(level));
136 
137  const edm::ValidityInterval& validity = setup.get<TrackerAlignmentRcd>().validityInterval();
138  const edm::IOVSyncValue first1 = validity.first();
139  unsigned int firstrun = first1.eventID().run();
140  if (themultiIOV) {
141  if (theIOVrangeSet.size() != 1) {
142  bool findMatchIOV = false;
143  for (unsigned int iovl = 0; iovl < theIOVrangeSet.size(); iovl++) {
144  if (firstrun == theIOVrangeSet.at(iovl)) {
146  iovapp.append(".root");
147  iovapp.insert(0, "_");
148  salignedfile.replace(salignedfile.end() - 5, salignedfile.end(), iovapp);
149  siterationfile.replace(siterationfile.end() - 5, siterationfile.end(), iovapp);
150  //sparameterfile.replace(sparameterfile.end()-5, sparameterfile.end(),iovapp);
151  if (isCollector) {
152  outfile2.replace(outfile2.end() - 5, outfile2.end(), iovapp);
153  ssurveyfile.replace(ssurveyfile.end() - 5, ssurveyfile.end(), iovapp);
154  suvarfile.replace(suvarfile.end() - 5, suvarfile.end(), iovapp);
155  }
156 
157  edm::LogInfo("Alignment") << "@SUB=HIPAlignmentAlgorithm::initialize"
158  << "Found the IOV file matching IOV first run " << firstrun;
159  findMatchIOV = true;
160  break;
161  }
162  }
163  if (!findMatchIOV)
164  edm::LogError("Alignment") << "@SUB=HIPAlignmentAlgorithm::initialize"
165  << "Didn't find the IOV file matching IOV first run " << firstrun
166  << " from the validity interval";
167  } else {
168  std::string iovapp = std::to_string(theIOVrangeSet.at(0));
169  iovapp.append(".root");
170  iovapp.insert(0, "_");
171  salignedfile.replace(salignedfile.end() - 5, salignedfile.end(), iovapp);
172  siterationfile.replace(siterationfile.end() - 5, siterationfile.end(), iovapp);
173  }
174  }
175 
176  // accessor Det->AlignableDet
177  theAlignableDetAccessor = std::make_unique<AlignableNavigator>(extras, tracker, muon);
178  if (extras != nullptr)
179  edm::LogInfo("Alignment") << "@SUB=HIPAlignmentAlgorithm::initialize"
180  << "AlignableNavigator initialized with AlignableExtras";
181 
182  // set alignmentParameterStore
184 
185  // get alignables
187 
188  // Config flags that specify different detectors
189  {
191 
192  // APE parameters, clear if necessary
193  theAPEParameters.clear();
194  if (theApplyAPE) {
195  for (std::vector<edm::ParameterSet>::const_iterator setiter = theAPEParameterSet.begin();
196  setiter != theAPEParameterSet.end();
197  ++setiter) {
198  align::Alignables alignables;
199 
200  selector.clear();
201  edm::ParameterSet selectorPSet = setiter->getParameter<edm::ParameterSet>("Selector");
202  std::vector<std::string> alignParams = selectorPSet.getParameter<std::vector<std::string>>("alignParams");
203  if (alignParams.size() == 1 && alignParams[0] == std::string("selected"))
204  alignables = theAlignables;
205  else {
206  selector.addSelections(selectorPSet);
207  alignables = selector.selectedAlignables();
208  }
209 
210  std::vector<double> apeSPar = setiter->getParameter<std::vector<double>>("apeSPar");
211  std::vector<double> apeRPar = setiter->getParameter<std::vector<double>>("apeRPar");
212  std::string function = setiter->getParameter<std::string>("function");
213 
214  if (apeSPar.size() != 3 || apeRPar.size() != 3)
215  throw cms::Exception("BadConfig") << "apeSPar and apeRPar must have 3 values each" << std::endl;
216 
217  for (std::vector<double>::const_iterator i = apeRPar.begin(); i != apeRPar.end(); ++i)
218  apeSPar.push_back(*i);
219 
220  if (function == std::string("linear"))
221  apeSPar.push_back(0); // c.f. note in calcAPE
222  else if (function == std::string("exponential"))
223  apeSPar.push_back(1); // c.f. note in calcAPE
224  else if (function == std::string("step"))
225  apeSPar.push_back(2); // c.f. note in calcAPE
226  else
227  throw cms::Exception("BadConfig")
228  << "APE function must be \"linear\", \"exponential\", or \"step\"." << std::endl;
229 
230  theAPEParameters.push_back(std::make_pair(alignables, apeSPar));
231  }
232  }
233 
234  // Relative error per component instead of overall relative error
235  theAlignableSpecifics.clear();
237  for (std::vector<edm::ParameterSet>::const_iterator setiter = theCutsPerComponent.begin();
238  setiter != theCutsPerComponent.end();
239  ++setiter) {
240  align::Alignables alignables;
241 
242  selector.clear();
243  edm::ParameterSet selectorPSet = setiter->getParameter<edm::ParameterSet>("Selector");
244  std::vector<std::string> alignParams = selectorPSet.getParameter<std::vector<std::string>>("alignParams");
245  if (alignParams.size() == 1 && alignParams[0] == std::string("selected"))
246  alignables = theAlignables;
247  else {
248  selector.addSelections(selectorPSet);
249  alignables = selector.selectedAlignables();
250  }
251 
252  double minRelParError = setiter->getParameter<double>("minRelParError");
253  double maxRelParError = setiter->getParameter<double>("maxRelParError");
254  int minNHits = setiter->getParameter<int>("minNHits");
255  double maxHitPull = setiter->getParameter<double>("maxHitPull");
256  bool applyPixelProbCut = setiter->getParameter<bool>("applyPixelProbCut");
257  bool usePixelProbXYOrProbQ = setiter->getParameter<bool>("usePixelProbXYOrProbQ");
258  double minPixelProbXY = setiter->getParameter<double>("minPixelProbXY");
259  double maxPixelProbXY = setiter->getParameter<double>("maxPixelProbXY");
260  double minPixelProbQ = setiter->getParameter<double>("minPixelProbQ");
261  double maxPixelProbQ = setiter->getParameter<double>("maxPixelProbQ");
262  for (auto& ali : alignables) {
263  HIPAlignableSpecificParameters alispecs(ali);
264  alispecs.minRelParError = minRelParError;
265  alispecs.maxRelParError = maxRelParError;
266  alispecs.minNHits = minNHits;
267  alispecs.maxHitPull = maxHitPull;
268 
269  alispecs.applyPixelProbCut = applyPixelProbCut;
270  alispecs.usePixelProbXYOrProbQ = usePixelProbXYOrProbQ;
271  alispecs.minPixelProbXY = minPixelProbXY;
272  alispecs.maxPixelProbXY = maxPixelProbXY;
273  alispecs.minPixelProbQ = minPixelProbQ;
274  alispecs.maxPixelProbQ = maxPixelProbQ;
275 
276  theAlignableSpecifics.push_back(alispecs);
277  edm::LogInfo("Alignment") << "@SUB=HIPAlignmentAlgorithm::initialize"
278  << "Alignment specifics acquired for detector " << alispecs.id() << " / "
279  << alispecs.objId() << ":\n"
280  << " - minRelParError = " << alispecs.minRelParError << "\n"
281  << " - maxRelParError = " << alispecs.maxRelParError << "\n"
282  << " - minNHits = " << alispecs.minNHits << "\n"
283  << " - maxHitPull = " << alispecs.maxHitPull << "\n"
284  << " - applyPixelProbCut = " << alispecs.applyPixelProbCut << "\n"
285  << " - usePixelProbXYOrProbQ = " << alispecs.usePixelProbXYOrProbQ << "\n"
286  << " - minPixelProbXY = " << alispecs.minPixelProbXY << "\n"
287  << " - maxPixelProbXY = " << alispecs.maxPixelProbXY << "\n"
288  << " - minPixelProbQ = " << alispecs.minPixelProbQ << "\n"
289  << " - maxPixelProbQ = " << alispecs.maxPixelProbQ;
290  }
291  }
292  }
293  }
294 }
295 
296 // Call at new loop -------------------------------------------------------------
298  edm::LogInfo("Alignment") << "@SUB=HIPAlignmentAlgorithm::startNewLoop"
299  << "Begin";
300 
301  // iterate over all alignables and attach user variables
302  for (const auto& it : theAlignables) {
303  AlignmentParameters* ap = it->alignmentParameters();
304  int npar = ap->numSelected();
305  HIPUserVariables* userpar = new HIPUserVariables(npar);
306  ap->setUserVariables(userpar);
307  }
308 
309  // try to read in alignment parameters from a previous iteration
310  AlignablePositions theAlignablePositionsFromFile =
312  int numAlignablesFromFile = theAlignablePositionsFromFile.size();
313  if (numAlignablesFromFile == 0) { // file not there: first iteration
314  // set iteration number to 1 when needed
315  if (isCollector)
316  theIteration = 0;
317  else
318  theIteration = 1;
319  edm::LogWarning("Alignment") << "@SUB=HIPAlignmentAlgorithm::startNewLoop"
320  << "IO alignables file not found for iteration " << theIteration;
321  } else { // there have been previous iterations
322  edm::LogInfo("Alignment") << "@SUB=HIPAlignmentAlgorithm::startNewLoop"
323  << "Alignables Read " << numAlignablesFromFile;
324 
325  // get iteration number from file
327  // Where is the target for this?
329 
330  // increase iteration
331  if (ioerr == 0) {
332  theIteration++;
333  edm::LogWarning("Alignment") << "@SUB=HIPAlignmentAlgorithm::startNewLoop"
334  << "Iteration increased by one and is now " << theIteration;
335  }
336 
337  // now apply psotions of file from prev iteration
338  edm::LogInfo("Alignment") << "@SUB=HIPAlignmentAlgorithm::startNewLoop"
339  << "Apply positions from file ...";
341  }
342 
343  edm::LogWarning("Alignment") << "@SUB=HIPAlignmentAlgorithm::startNewLoop"
344  << "Current Iteration number: " << theIteration;
345 
346  // book root trees
347  bookRoot();
348 
349  // set alignment position error
351 
352  // run collector job if we are in parallel mode
353  if (isCollector)
354  collector();
355 
356  edm::LogInfo("Alignment") << "@SUB=HIPAlignmentAlgorithm::startNewLoop"
357  << "End";
358 }
359 
360 // Call at end of job ---------------------------------------------------------
362  edm::LogWarning("Alignment") << "[HIPAlignmentAlgorithm] Terminating";
363 
364  // calculating survey residuals
365  if (!theLevels.empty()) {
366  edm::LogWarning("Alignment") << "[HIPAlignmentAlgorithm] Using survey constraint";
367 
368  unsigned int nAlignable = theAlignables.size();
369  const TrackerTopology* const tTopo = &iSetup.getData(topoToken_);
370  for (unsigned int i = 0; i < nAlignable; ++i) {
371  const Alignable* ali = theAlignables[i];
373  HIPUserVariables* uservar = dynamic_cast<HIPUserVariables*>(ap->userVariables());
374  int nhit = uservar->nhit;
375 
376  // get position
377  std::pair<int, int> tl = theAlignmentParameterStore->typeAndLayer(ali, tTopo);
378  int tmp_Type = tl.first;
379  int tmp_Layer = tl.second;
380  GlobalPoint pos = ali->surface().position();
381  float tmpz = pos.z();
382  if (nhit < 1500 ||
383  (tmp_Type == 5 && tmp_Layer == 4 && fabs(tmpz) > 90)) { // FIXME: Needs revision for hardcoded consts
384  for (unsigned int l = 0; l < theLevels.size(); ++l) {
385  SurveyResidual res(*ali, theLevels[l], true);
386 
387  if (res.valid()) {
388  AlgebraicSymMatrix invCov = res.inverseCovariance();
389 
390  // variable for tree
391  AlgebraicVector sensResid = res.sensorResidual();
392  m3_Id = ali->id();
393  m3_ObjId = theLevels[l];
394  m3_par[0] = sensResid[0];
395  m3_par[1] = sensResid[1];
396  m3_par[2] = sensResid[2];
397  m3_par[3] = sensResid[3];
398  m3_par[4] = sensResid[4];
399  m3_par[5] = sensResid[5];
400 
401  uservar->jtvj += invCov;
402  uservar->jtve += invCov * sensResid;
403 
404  if (theSurveyTree != nullptr)
405  theSurveyTree->Fill();
406  }
407  }
408  }
409  }
410  }
411 
412  // write user variables
414  // don't store userVariable in main, to save time
415  if (!isCollector)
417 
418  // now calculate alignment corrections...
419  int ialigned = 0;
420  // iterate over alignment parameters
421  for (const auto& ali : theAlignables) {
422  AlignmentParameters* par = ali->alignmentParameters();
423 
424  if (SetScanDet.at(0) != 0) {
425  edm::LogWarning("Alignment") << "********Starting Scan*********";
426  edm::LogWarning("Alignment") << "det ID=" << SetScanDet.at(0) << ", starting position=" << SetScanDet.at(1)
427  << ", step=" << SetScanDet.at(2) << ", currentDet = " << ali->id();
428  }
429 
430  if ((SetScanDet.at(0) != 0) && (SetScanDet.at(0) != 1) && (ali->id() != SetScanDet.at(0)))
431  continue;
432 
433  bool test = calcParameters(ali, SetScanDet.at(0), SetScanDet.at(1), SetScanDet.at(2));
434  if (test) {
435  if (dynamic_cast<AlignableDetUnit*>(ali) != nullptr) {
436  std::vector<std::pair<int, SurfaceDeformation*>> pairs;
437  ali->surfaceDeformationIdPairs(pairs);
438  edm::LogInfo("Alignment") << "@SUB=HIPAlignmentAlgorithm::terminate"
439  << "The alignable contains " << pairs.size() << " surface deformations";
440  } else
441  edm::LogInfo("Alignment") << "@SUB=HIPAlignmentAlgorithm::terminate"
442  << "The alignable cannot contain surface deformations";
443 
445  // set these parameters 'valid'
446  ali->alignmentParameters()->setValid(true);
447  // increase counter
448  ialigned++;
449  } else
450  par->setValid(false);
451  }
452  //end looping over alignables
453 
454  edm::LogWarning("Alignment") << "[HIPAlignmentAlgorithm::terminate] Aligned units: " << ialigned;
455 
456  // fill alignable wise root tree
457  fillAlignablesMonitor(iSetup);
458 
459  edm::LogWarning("Alignment") << "[HIPAlignmentAlgorithm] Writing aligned parameters to file: " << theAlignables.size()
460  << ", for Iteration " << theIteration;
461 
462  // write user variables
463  if (isCollector)
465 
466  // write new absolute positions to disk
468 
469  // write alignment parameters to disk
470  //theIO.writeAlignmentParameters(theAlignables,
471  // sparameterfile.c_str(),theIteration,false,ioerr);
472 
473  // write iteration number to file
475 
476  // write out trees and close root file
477  // Survey tree
478  if (theSurveyIORootFile != nullptr) {
479  theSurveyIORootFile->cd();
480  if (theSurveyTree != nullptr)
481  theSurveyTree->Write();
482  delete theSurveyTree;
483  theSurveyTree = nullptr;
484  theSurveyIORootFile->Close();
485  }
486  // Alignable-wise tree is only filled once at iteration 1
487  if (theAlignablesMonitorIORootFile != nullptr) {
489  if (theAlignablesMonitorTree != nullptr)
490  theAlignablesMonitorTree->Write();
492  theAlignablesMonitorTree = nullptr;
494  }
495  // Eventwise and hitwise monitoring trees
496  if (theTrackHitMonitorIORootFile != nullptr) {
498  if (theTrackMonitorTree != nullptr) {
499  theTrackMonitorTree->Write();
500  delete theTrackMonitorTree;
501  theTrackMonitorTree = nullptr;
502  }
503  if (theHitMonitorTree != nullptr) {
504  theHitMonitorTree->Write();
505  delete theHitMonitorTree;
506  theHitMonitorTree = nullptr;
507  }
509  }
510 }
511 
513  const Alignable* ali,
514  const HIPAlignableSpecificParameters* alispecifics,
515  const TrajectoryStateOnSurface& tsos,
517  double hitwt) {
518  static const unsigned int hitDim = 1;
519  if (hitwt == 0.)
520  return false;
521 
522  // get trajectory impact point
523  LocalPoint alvec = tsos.localPosition();
524  AlgebraicVector pos(hitDim);
525  pos[0] = alvec.x();
526 
527  // get impact point covariance
528  AlgebraicSymMatrix ipcovmat(hitDim);
529  ipcovmat[0][0] = tsos.localError().positionError().xx();
530 
531  // get hit local position and covariance
532  AlgebraicVector coor(hitDim);
533  coor[0] = hit->localPosition().x();
534 
535  AlgebraicSymMatrix covmat(hitDim);
536  covmat[0][0] = hit->localPositionError().xx();
537 
538  // add hit and impact point covariance matrices
539  covmat = covmat + ipcovmat;
540 
541  // calculate the x pull of this hit
542  double xpull = 0.;
543  if (covmat[0][0] != 0.)
544  xpull = (pos[0] - coor[0]) / sqrt(fabs(covmat[0][0]));
545 
546  // get Alignment Parameters
548  HIPUserVariables* uservar = dynamic_cast<HIPUserVariables*>(params->userVariables());
549  uservar->datatype = theDataGroup;
550  // get derivatives
551  AlgebraicMatrix derivs2D = params->selectedDerivatives(tsos, alidet);
552  // calculate user parameters
553  int npar = derivs2D.num_row();
554  AlgebraicMatrix derivs(npar, hitDim, 0); // This is jT
555 
556  for (int ipar = 0; ipar < npar; ipar++) {
557  for (unsigned int idim = 0; idim < hitDim; idim++) {
558  derivs[ipar][idim] = derivs2D[ipar][idim];
559  }
560  }
561 
562  // invert covariance matrix
563  int ierr;
564  covmat.invert(ierr);
565  if (ierr != 0) {
566  edm::LogError("Alignment") << "@SUB=HIPAlignmentAlgorithm::processHit1D"
567  << "Cov. matrix inversion failed!";
568  return false;
569  }
570 
571  double maxHitPullThreshold =
573  bool useThisHit = (maxHitPullThreshold < 0.);
574  useThisHit |= (fabs(xpull) < maxHitPullThreshold);
575  if (!useThisHit) {
576  edm::LogInfo("Alignment") << "@SUB=HIPAlignmentAlgorithm::processHit2D"
577  << "Hit pull (x) " << xpull << " fails the cut " << maxHitPullThreshold;
578  return false;
579  }
580 
581  AlgebraicMatrix covtmp(covmat);
582  AlgebraicMatrix jtvjtmp(derivs * covtmp * derivs.T());
583  AlgebraicSymMatrix thisjtvj(npar);
584  AlgebraicVector thisjtve(npar);
585  thisjtvj.assign(jtvjtmp);
586  thisjtve = derivs * covmat * (pos - coor);
587 
588  AlgebraicVector hitresidual(hitDim);
589  hitresidual[0] = (pos[0] - coor[0]);
590 
591  AlgebraicMatrix hitresidualT;
592  hitresidualT = hitresidual.T();
593 
594  uservar->jtvj += hitwt * thisjtvj;
595  uservar->jtve += hitwt * thisjtve;
596  uservar->nhit++;
597 
598  //for alignable chi squared
599  float thischi2;
600  thischi2 = hitwt * (hitresidualT * covmat * hitresidual)[0];
601 
602  if (verbose && (thischi2 / static_cast<float>(uservar->nhit)) > 10.)
603  edm::LogWarning("Alignment") << "[HIPAlignmentAlgorithm::processHit1D] Added to Chi2 the number " << thischi2
604  << " having " << uservar->nhit << " ndof"
605  << ", X-resid " << hitresidual[0] << ", Cov^-1 matr (covmat):"
606  << " [0][0] = " << covmat[0][0];
607 
608  uservar->alichi2 += thischi2;
609  uservar->alindof += hitDim;
610 
611  return true;
612 }
613 
615  const Alignable* ali,
616  const HIPAlignableSpecificParameters* alispecifics,
617  const TrajectoryStateOnSurface& tsos,
619  double hitwt) {
620  static const unsigned int hitDim = 2;
621  if (hitwt == 0.)
622  return false;
623 
624  // get trajectory impact point
625  LocalPoint alvec = tsos.localPosition();
626  AlgebraicVector pos(hitDim);
627  pos[0] = alvec.x();
628  pos[1] = alvec.y();
629 
630  // get impact point covariance
631  AlgebraicSymMatrix ipcovmat(hitDim);
632  ipcovmat[0][0] = tsos.localError().positionError().xx();
633  ipcovmat[1][1] = tsos.localError().positionError().yy();
634  ipcovmat[0][1] = tsos.localError().positionError().xy();
635 
636  // get hit local position and covariance
637  AlgebraicVector coor(hitDim);
638  coor[0] = hit->localPosition().x();
639  coor[1] = hit->localPosition().y();
640 
641  AlgebraicSymMatrix covmat(hitDim);
642  covmat[0][0] = hit->localPositionError().xx();
643  covmat[1][1] = hit->localPositionError().yy();
644  covmat[0][1] = hit->localPositionError().xy();
645 
646  // add hit and impact point covariance matrices
647  covmat = covmat + ipcovmat;
648 
649  // calculate the x pull and y pull of this hit
650  double xpull = 0.;
651  double ypull = 0.;
652  if (covmat[0][0] != 0.)
653  xpull = (pos[0] - coor[0]) / sqrt(fabs(covmat[0][0]));
654  if (covmat[1][1] != 0.)
655  ypull = (pos[1] - coor[1]) / sqrt(fabs(covmat[1][1]));
656 
657  // get Alignment Parameters
659  HIPUserVariables* uservar = dynamic_cast<HIPUserVariables*>(params->userVariables());
660  uservar->datatype = theDataGroup;
661  // get derivatives
662  AlgebraicMatrix derivs2D = params->selectedDerivatives(tsos, alidet);
663  // calculate user parameters
664  int npar = derivs2D.num_row();
665  AlgebraicMatrix derivs(npar, hitDim, 0); // This is jT
666 
667  for (int ipar = 0; ipar < npar; ipar++) {
668  for (unsigned int idim = 0; idim < hitDim; idim++) {
669  derivs[ipar][idim] = derivs2D[ipar][idim];
670  }
671  }
672 
673  // invert covariance matrix
674  int ierr;
675  covmat.invert(ierr);
676  if (ierr != 0) {
677  edm::LogError("Alignment") << "@SUB=HIPAlignmentAlgorithm::processHit2D"
678  << "Cov. matrix inversion failed!";
679  return false;
680  }
681 
682  double maxHitPullThreshold =
684  bool useThisHit = (maxHitPullThreshold < 0.);
685  useThisHit |= (fabs(xpull) < maxHitPullThreshold && fabs(ypull) < maxHitPullThreshold);
686  if (!useThisHit) {
687  edm::LogInfo("Alignment") << "@SUB=HIPAlignmentAlgorithm::processHit2D"
688  << "Hit pull (x,y) " << xpull << " , " << ypull << " fails the cut "
689  << maxHitPullThreshold;
690  return false;
691  }
692 
693  AlgebraicMatrix covtmp(covmat);
694  AlgebraicMatrix jtvjtmp(derivs * covtmp * derivs.T());
695  AlgebraicSymMatrix thisjtvj(npar);
696  AlgebraicVector thisjtve(npar);
697  thisjtvj.assign(jtvjtmp);
698  thisjtve = derivs * covmat * (pos - coor);
699 
700  AlgebraicVector hitresidual(hitDim);
701  hitresidual[0] = (pos[0] - coor[0]);
702  hitresidual[1] = (pos[1] - coor[1]);
703 
704  AlgebraicMatrix hitresidualT;
705  hitresidualT = hitresidual.T();
706 
707  uservar->jtvj += hitwt * thisjtvj;
708  uservar->jtve += hitwt * thisjtve;
709  uservar->nhit++;
710 
711  //for alignable chi squared
712  float thischi2;
713  thischi2 = hitwt * (hitresidualT * covmat * hitresidual)[0];
714 
715  if (verbose && (thischi2 / static_cast<float>(uservar->nhit)) > 10.)
716  edm::LogWarning("Alignment") << "[HIPAlignmentAlgorithm::processHit2D] Added to Chi2 the number " << thischi2
717  << " having " << uservar->nhit << " ndof"
718  << ", X-resid " << hitresidual[0] << ", Y-resid " << hitresidual[1]
719  << ", Cov^-1 matr (covmat):"
720  << " [0][0] = " << covmat[0][0] << " [0][1] = " << covmat[0][1]
721  << " [1][0] = " << covmat[1][0] << " [1][1] = " << covmat[1][1];
722 
723  uservar->alichi2 += thischi2;
724  uservar->alindof += hitDim;
725 
726  return true;
727 }
728 
729 // Run the algorithm on trajectories and tracks -------------------------------
731  if (isCollector)
732  return;
733 
734  TrajectoryStateCombiner tsoscomb;
735 
737 
738  // loop over tracks
739  const ConstTrajTrackPairCollection& tracks = eventInfo.trajTrackPairs();
740  for (ConstTrajTrackPairCollection::const_iterator it = tracks.begin(); it != tracks.end(); ++it) {
741  const Trajectory* traj = (*it).first;
742  const reco::Track* track = (*it).second;
743 
744  float pt = track->pt();
745  float eta = track->eta();
746  float phi = track->phi();
747  float p = track->p();
748  float chi2n = track->normalizedChi2();
749  int nhit = track->numberOfValidHits();
750  float d0 = track->d0();
751  float dz = track->dz();
752 
753  int nhpxb = track->hitPattern().numberOfValidPixelBarrelHits();
754  int nhpxf = track->hitPattern().numberOfValidPixelEndcapHits();
755  int nhtib = track->hitPattern().numberOfValidStripTIBHits();
756  int nhtob = track->hitPattern().numberOfValidStripTOBHits();
757  int nhtid = track->hitPattern().numberOfValidStripTIDHits();
758  int nhtec = track->hitPattern().numberOfValidStripTECHits();
759 
760  if (verbose)
761  edm::LogInfo("Alignment") << "New track pt,eta,phi,chi2n,hits: " << pt << "," << eta << "," << phi << "," << chi2n
762  << "," << nhit;
763 
764  double ihitwt = 1;
765  double trkwt = 1;
766  if (trackWt) {
767  trkwt = Scale;
768  // Reweight by the specified eta distribution
769  if (uniEta)
770  trkwt *= theEtaFormula->Eval(fabs(eta));
771  }
772  if (trackPs) {
773  double r = gRandom->Rndm();
774  if (trkwt < r)
775  continue;
776  } else if (trackWt)
777  ihitwt = trkwt;
778 
779  // fill track parameters in root tree
780  {
781  theMonitorConfig.trackmonitorvars.m_Nhits.push_back(nhit);
787  theMonitorConfig.trackmonitorvars.m_nhPXB.push_back(nhpxb);
788  theMonitorConfig.trackmonitorvars.m_nhPXF.push_back(nhpxf);
789  theMonitorConfig.trackmonitorvars.m_nhTIB.push_back(nhtib);
790  theMonitorConfig.trackmonitorvars.m_nhTOB.push_back(nhtob);
791  theMonitorConfig.trackmonitorvars.m_nhTID.push_back(nhtid);
792  theMonitorConfig.trackmonitorvars.m_nhTEC.push_back(nhtec);
795  theMonitorConfig.trackmonitorvars.m_wt.push_back(ihitwt);
796  }
797 
798  std::vector<const TransientTrackingRecHit*> hitvec;
799  std::vector<TrajectoryStateOnSurface> tsosvec;
800 
801  // loop over measurements
802  std::vector<TrajectoryMeasurement> measurements = traj->measurements();
803  for (std::vector<TrajectoryMeasurement>::iterator im = measurements.begin(); im != measurements.end(); ++im) {
804  TrajectoryMeasurement meas = *im;
805 
806  // const TransientTrackingRecHit* ttrhit = &(*meas.recHit());
807  // const TrackingRecHit *hit = ttrhit->hit();
808  const TransientTrackingRecHit* hit = &(*meas.recHit());
809 
810  if (hit->isValid() && theAlignableDetAccessor->detAndSubdetInMap(hit->geographicalId())) {
811  // this is the updated state (including the current hit)
812  // TrajectoryStateOnSurface tsos=meas.updatedState();
813  // combine fwd and bwd predicted state to get state
814  // which excludes current hit
815 
817  if (eventInfo.clusterValueMap()) {
818  // check from the PrescalingMap if the hit was taken.
819  // If not skip to the next TM
820  // bool hitTaken=false;
821  AlignmentClusterFlag myflag;
822 
823  int subDet = hit->geographicalId().subdetId();
824  //take the actual RecHit out of the Transient one
825  const TrackingRecHit* rechit = hit->hit();
826  if (subDet > 2) { // AM: if possible use enum instead of hard-coded value
827  const std::type_info& type = typeid(*rechit);
828 
829  if (type == typeid(SiStripRecHit1D)) {
830  const SiStripRecHit1D* stripHit1D = dynamic_cast<const SiStripRecHit1D*>(rechit);
831  if (stripHit1D) {
832  SiStripRecHit1D::ClusterRef stripclust(stripHit1D->cluster());
833  // myflag=PrescMap[stripclust];
834  myflag = (*eventInfo.clusterValueMap())[stripclust];
835  } else
836  edm::LogError("HIPAlignmentAlgorithm")
837  << "ERROR in <HIPAlignmentAlgorithm::run>: Dynamic cast of Strip RecHit failed! "
838  << "TypeId of the RecHit: " << className(*hit);
839  } //end if type = SiStripRecHit1D
840  else if (type == typeid(SiStripRecHit2D)) {
841  const SiStripRecHit2D* stripHit2D = dynamic_cast<const SiStripRecHit2D*>(rechit);
842  if (stripHit2D) {
843  SiStripRecHit2D::ClusterRef stripclust(stripHit2D->cluster());
844  // myflag=PrescMap[stripclust];
845  myflag = (*eventInfo.clusterValueMap())[stripclust];
846  } else
847  edm::LogError("HIPAlignmentAlgorithm")
848  << "ERROR in <HIPAlignmentAlgorithm::run>: Dynamic cast of Strip RecHit failed! "
849  << "TypeId of the TTRH: " << className(*hit);
850  } //end if type == SiStripRecHit2D
851  } //end if hit from strips
852  else {
853  const SiPixelRecHit* pixelhit = dynamic_cast<const SiPixelRecHit*>(rechit);
854  if (pixelhit) {
855  SiPixelClusterRefNew pixelclust(pixelhit->cluster());
856  // myflag=PrescMap[pixelclust];
857  myflag = (*eventInfo.clusterValueMap())[pixelclust];
858  } else
859  edm::LogError("HIPAlignmentAlgorithm")
860  << "ERROR in <HIPAlignmentAlgorithm::run>: Dynamic cast of Pixel RecHit failed! "
861  << "TypeId of the TTRH: " << className(*hit);
862  } //end 'else' it is a pixel hit
863  if (!myflag.isTaken())
864  continue;
865  } //end if Prescaled Hits
867 
869 
870  if (tsos.isValid()) {
871  hitvec.push_back(hit);
872  tsosvec.push_back(tsos);
873  }
874 
875  } //hit valid
876  }
877 
878  // transform RecHit vector to AlignableDet vector
879  std::vector<AlignableDetOrUnitPtr> alidetvec = theAlignableDetAccessor->alignablesFromHits(hitvec);
880 
881  // get concatenated alignment parameters for list of alignables
883 
884  std::vector<TrajectoryStateOnSurface>::const_iterator itsos = tsosvec.begin();
885  std::vector<const TransientTrackingRecHit*>::const_iterator ihit = hitvec.begin();
886 
887  // loop over vectors(hit,tsos)
888  while (itsos != tsosvec.end()) {
889  // get AlignableDet for this hit
890  const GeomDet* det = (*ihit)->det();
891  // int subDet= (*ihit)->geographicalId().subdetId();
892  uint32_t nhitDim = (*ihit)->dimension();
893 
894  AlignableDetOrUnitPtr alidet = theAlignableDetAccessor->alignableFromGeomDet(det);
895 
896  // get relevant Alignable
897  Alignable* ali = aap.alignableFromAlignableDet(alidet);
898 
899  if (ali != nullptr) {
900  const HIPAlignableSpecificParameters* alispecifics = findAlignableSpecs(ali);
901  const TrajectoryStateOnSurface& tsos = *itsos;
902 
903  // LocalVector v = tsos.localDirection();
904  // double proj_z = v.dot(LocalVector(0,0,1));
905 
906  //In fact, sin_theta=Abs(mom_z)
907  double mom_x = tsos.localDirection().x();
908  double mom_y = tsos.localDirection().y();
909  double mom_z = tsos.localDirection().z();
910  double sin_theta = TMath::Abs(mom_z) / sqrt(pow(mom_x, 2) + pow(mom_y, 2) + pow(mom_z, 2));
911  double angle = TMath::ASin(sin_theta);
912  double alihitwt = ihitwt;
913 
914  //Make cut on hit impact angle, reduce collision hits perpendicular to modules
915  if (IsCollision) {
916  if (angle > col_cut)
917  alihitwt = 0;
918  } else {
919  if (angle < cos_cut)
920  alihitwt = 0;
921  }
922 
923  // Fill hit monitor variables
927 
928  // Check pixel XY and Q probabilities
929  if ((*ihit)->hit() != nullptr) {
930  const SiPixelRecHit* pixhit = dynamic_cast<const SiPixelRecHit*>((*ihit)->hit());
931  if (pixhit != nullptr) {
934  // Prob X, Y are deprecated
938  if (alispecifics->applyPixelProbCut) {
939  bool probXYgood = (theMonitorConfig.hitmonitorvars.m_probXY >= alispecifics->minPixelProbXY &&
941  bool probQgood = (theMonitorConfig.hitmonitorvars.m_probQ >= alispecifics->minPixelProbQ &&
943  bool probXYQgood;
944  if (alispecifics->usePixelProbXYOrProbQ)
945  probXYQgood = (probXYgood || probQgood);
946  else
947  probXYQgood = (probXYgood && probQgood);
948  if (!probXYQgood)
949  alihitwt = 0;
950  }
951  }
952  }
953  }
954 
956  bool hitProcessed = false;
957  switch (nhitDim) {
958  case 1:
959  hitProcessed = processHit1D(alidet, ali, alispecifics, tsos, *ihit, alihitwt);
960  break;
961  case 2:
962  hitProcessed = processHit2D(alidet, ali, alispecifics, tsos, *ihit, alihitwt);
963  break;
964  default:
965  edm::LogError("HIPAlignmentAlgorithm")
966  << "ERROR in <HIPAlignmentAlgorithm::run>: Number of hit dimensions = " << nhitDim
967  << " is not supported!" << std::endl;
968  break;
969  }
972  }
973 
974  itsos++;
975  ihit++;
976  }
977  } // end of track loop
978 
979  // fill eventwise root tree (with prescale defined in pset)
982 }
983 
984 // ----------------------------------------------------------------------------
986  int result;
987 
988  std::ifstream inIterFile(filename.c_str(), std::ios::in);
989  if (!inIterFile) {
990  edm::LogError("Alignment") << "[HIPAlignmentAlgorithm::readIterationFile] ERROR! "
991  << "Unable to open Iteration file";
992  result = -1;
993  } else {
994  inIterFile >> result;
995  edm::LogWarning("Alignment") << "[HIPAlignmentAlgorithm::readIterationFile] "
996  << "Read last iteration number from file: " << result;
997  }
998  inIterFile.close();
999 
1000  return result;
1001 }
1002 
1003 // ----------------------------------------------------------------------------
1005  std::ofstream outIterFile((filename.c_str()), std::ios::out);
1006  if (!outIterFile)
1007  edm::LogError("Alignment") << "[HIPAlignmentAlgorithm::writeIterationFile] ERROR: Unable to write Iteration file";
1008  else {
1009  outIterFile << iter;
1010  edm::LogWarning("Alignment") << "[HIPAlignmentAlgorithm::writeIterationFile] writing iteration number to file: "
1011  << iter;
1012  }
1013  outIterFile.close();
1014 }
1015 
1016 // ----------------------------------------------------------------------------
1017 // set alignment position error
1019  // Check if user wants to override APE
1020  if (!theApplyAPE) {
1021  edm::LogInfo("Alignment") << "[HIPAlignmentAlgorithm::setAlignmentPositionError] No APE applied";
1022  return; // NO APE APPLIED
1023  }
1024 
1025  edm::LogInfo("Alignment") << "[HIPAlignmentAlgorithm::setAlignmentPositionError] Apply APE!";
1026 
1027  double apeSPar[3], apeRPar[3];
1028  for (const auto& alipars : theAPEParameters) {
1029  const auto& alignables = alipars.first;
1030  const auto& pars = alipars.second;
1031 
1032  apeSPar[0] = pars[0];
1033  apeSPar[1] = pars[1];
1034  apeSPar[2] = pars[2];
1035  apeRPar[0] = pars[3];
1036  apeRPar[1] = pars[4];
1037  apeRPar[2] = pars[5];
1038 
1039  int function = pars[6];
1040 
1041  // Printout for debug
1042  printf("APE: %u alignables\n", (unsigned int)alignables.size());
1043  for (int i = 0; i < 21; ++i) {
1044  double apelinstest = calcAPE(apeSPar, i, 0);
1045  double apeexpstest = calcAPE(apeSPar, i, 1);
1046  double apestepstest = calcAPE(apeSPar, i, 2);
1047  double apelinrtest = calcAPE(apeRPar, i, 0);
1048  double apeexprtest = calcAPE(apeRPar, i, 1);
1049  double apesteprtest = calcAPE(apeRPar, i, 2);
1050  printf("APE: iter slin sexp sstep rlin rexp rstep: %5d %12.5f %12.5f %12.5f %12.5f %12.5f %12.5f \n",
1051  i,
1052  apelinstest,
1053  apeexpstest,
1054  apestepstest,
1055  apelinrtest,
1056  apeexprtest,
1057  apesteprtest);
1058  }
1059 
1060  // set APE
1061  double apeshift = calcAPE(apeSPar, theIteration, function);
1062  double aperot = calcAPE(apeRPar, theIteration, function);
1063  theAlignmentParameterStore->setAlignmentPositionError(alignables, apeshift, aperot);
1064  }
1065 }
1066 
1067 // ----------------------------------------------------------------------------
1068 // calculate APE
1069 double HIPAlignmentAlgorithm::calcAPE(double* par, int iter, int function) {
1070  double diter = (double)iter;
1071  if (function == 0)
1072  return std::max(par[1], par[0] + ((par[1] - par[0]) / par[2]) * diter);
1073  else if (function == 1)
1074  return std::max(0., par[0] * (exp(-pow(diter, par[1]) / par[2])));
1075  else if (function == 2) {
1076  int ipar2 = (int)par[2];
1077  int step = iter / ipar2;
1078  double dstep = (double)step;
1079  return std::max(0., par[0] - par[1] * dstep);
1080  } else
1081  assert(false); // should have been caught in the constructor
1082 }
1083 
1084 // ----------------------------------------------------------------------------
1085 // book root trees
1087  // create ROOT files
1089  theTrackHitMonitorIORootFile = TFile::Open(theMonitorConfig.outfile.c_str(), "update");
1091  // book event-wise ROOT Tree
1093  TString tname = Form("T1_%i", theIteration);
1094  theTrackMonitorTree = new TTree(tname, "Eventwise tree");
1095  //theTrackMonitorTree->Branch("Run", &m_Run, "Run/I");
1096  //theTrackMonitorTree->Branch("Event", &m_Event, "Event/I");
1097  theTrackMonitorTree->Branch("DataType", &m_datatype);
1100  }
1101  // book hit-wise ROOT Tree
1103  TString tname_hit = Form("T1_hit_%i", theIteration);
1104  theHitMonitorTree = new TTree(tname_hit, "Hitwise tree");
1105  theHitMonitorTree->Branch("DataType", &m_datatype);
1108  }
1109  }
1110 
1111  // book alignable-wise ROOT Tree
1112  if (isCollector) {
1113  TString tname = Form("T2_%i", theIteration);
1114  theAlignablesMonitorIORootFile = TFile::Open(outfile2.c_str(), "update");
1116  theAlignablesMonitorTree = new TTree(tname, "Alignablewise tree");
1117  theAlignablesMonitorTree->Branch("Id", &m2_Id, "Id/i");
1118  theAlignablesMonitorTree->Branch("ObjId", &m2_ObjId, "ObjId/I");
1119  theAlignablesMonitorTree->Branch("Nhit", &m2_Nhit);
1120  theAlignablesMonitorTree->Branch("DataType", &m2_datatype);
1121  theAlignablesMonitorTree->Branch("Type", &m2_Type);
1122  theAlignablesMonitorTree->Branch("Layer", &m2_Layer);
1123  theAlignablesMonitorTree->Branch("Xpos", &m2_Xpos);
1124  theAlignablesMonitorTree->Branch("Ypos", &m2_Ypos);
1125  theAlignablesMonitorTree->Branch("Zpos", &m2_Zpos);
1126  theAlignablesMonitorTree->Branch("DeformationsType", &m2_dtype, "DeformationsType/I");
1127  theAlignablesMonitorTree->Branch("NumDeformations", &m2_nsurfdef);
1128  theAlignablesMonitorTree->Branch("Deformations", &m2_surfDef);
1129  }
1130 
1131  // book survey-wise ROOT Tree only if survey is enabled
1132  if (!theLevels.empty()) {
1133  TString tname = Form("T3_%i", theIteration);
1134  theSurveyIORootFile = TFile::Open(ssurveyfile.c_str(), "update");
1135  theSurveyIORootFile->cd();
1136  theSurveyTree = new TTree(tname, "Survey Tree");
1137  theSurveyTree->Branch("Id", &m3_Id, "Id/i");
1138  theSurveyTree->Branch("ObjId", &m3_ObjId, "ObjId/I");
1139  theSurveyTree->Branch("Par", &m3_par, "Par[6]/F");
1140  edm::LogInfo("Alignment") << "[HIPAlignmentAlgorithm::bookRoot] Survey trees booked.";
1141  }
1142  edm::LogInfo("Alignment") << "[HIPAlignmentAlgorithm::bookRoot] Root trees booked.";
1143 }
1144 
1145 // ----------------------------------------------------------------------------
1146 // fill alignable-wise root tree
1148  if (theAlignablesMonitorIORootFile == (TFile*)nullptr)
1149  return;
1150  using std::setw;
1152 
1153  int naligned = 0;
1154 
1155  //Retrieve tracker topology from geometry
1156  const TrackerTopology* const tTopo = &iSetup.getData(topoToken2_);
1157 
1158  for (const auto& ali : theAlignables) {
1159  AlignmentParameters* dap = ali->alignmentParameters();
1160 
1161  // consider only those parameters classified as 'valid'
1162  if (dap->isValid()) {
1163  // get number of hits from user variable
1164  HIPUserVariables* uservar = dynamic_cast<HIPUserVariables*>(dap->userVariables());
1165  m2_Nhit = uservar->nhit;
1166  m2_datatype = uservar->datatype;
1167 
1168  // get type/layer
1169  std::pair<int, int> tl = theAlignmentParameterStore->typeAndLayer(ali, tTopo);
1170  m2_Type = tl.first;
1171  m2_Layer = tl.second;
1172 
1173  // get identifier (as for IO)
1174  m2_Id = ali->id();
1175  m2_ObjId = ali->alignableObjectId();
1176 
1177  // get position
1178  GlobalPoint pos = ali->surface().position();
1179  m2_Xpos = pos.x();
1180  m2_Ypos = pos.y();
1181  m2_Zpos = pos.z();
1182 
1183  m2_surfDef.clear();
1184  {
1185  std::vector<std::pair<int, SurfaceDeformation*>> dali_id_pairs;
1186  SurfaceDeformation* dali_obj = nullptr;
1188  std::vector<double> dali;
1189  if (1 == ali->surfaceDeformationIdPairs(dali_id_pairs)) {
1190  dali_obj = dali_id_pairs[0].second;
1191  dali = dali_obj->parameters();
1193  }
1194  for (auto& dit : dali)
1195  m2_surfDef.push_back((float)dit);
1196  m2_dtype = dtype;
1197  m2_nsurfdef = m2_surfDef.size();
1198  }
1199 
1200  if (verbose) {
1201  AlgebraicVector pars = dap->parameters();
1202  edm::LogVerbatim("Alignment") << "------------------------------------------------------------------------\n"
1203  << " ALIGNABLE: " << setw(6) << naligned << '\n'
1204  << "hits: " << setw(4) << m2_Nhit << " type: " << setw(4) << m2_Type
1205  << " layer: " << setw(4) << m2_Layer << " id: " << setw(4) << m2_Id
1206  << " objId: " << setw(4) << m2_ObjId << '\n'
1207  << std::fixed << std::setprecision(5) << "x,y,z: " << setw(12) << m2_Xpos
1208  << setw(12) << m2_Ypos << setw(12) << m2_Zpos
1209  << "\nDeformations type, nDeformations: " << setw(12) << m2_dtype << setw(12)
1210  << m2_nsurfdef << '\n'
1211  << "params: " << setw(12) << pars[0] << setw(12) << pars[1] << setw(12) << pars[2]
1212  << setw(12) << pars[3] << setw(12) << pars[4] << setw(12) << pars[5];
1213  }
1214 
1215  naligned++;
1216  if (theAlignablesMonitorTree != nullptr)
1217  theAlignablesMonitorTree->Fill();
1218  }
1219  }
1220 }
1221 
1222 // ----------------------------------------------------------------------------
1223 bool HIPAlignmentAlgorithm::calcParameters(Alignable* ali, int setDet, double start, double step) {
1224  edm::LogInfo("Alignment") << "@SUB=HIPAlignmentAlgorithm::calcParameters"
1225  << "Begin: Processing detector " << ali->id();
1226 
1227  // Alignment parameters
1229  const HIPAlignableSpecificParameters* alispecifics = findAlignableSpecs(ali);
1230  // access user variables
1231  HIPUserVariables* uservar = dynamic_cast<HIPUserVariables*>(par->userVariables());
1232  int nhit = uservar->nhit;
1233  // The following variable is needed for the extended 1D/2D hit fix using
1234  // matrix shrinkage and expansion
1235  // int hitdim = uservar->hitdim;
1236 
1237  // Test nhits
1238  int minHitThreshold = (!theApplyCutsPerComponent ? defaultAlignableSpecs.minNHits : alispecifics->minNHits);
1239  if (!isCollector)
1240  minHitThreshold = 1;
1241  if (setDet == 0 && nhit < minHitThreshold) {
1242  edm::LogInfo("Alignment") << "@SUB=HIPAlignmentAlgorithm::calcParameters"
1243  << "Skipping detector " << ali->id() << " because number of hits = " << nhit
1244  << " <= " << minHitThreshold;
1245  par->setValid(false);
1246  return false;
1247  }
1248 
1249  AlgebraicSymMatrix jtvj = uservar->jtvj;
1250  AlgebraicVector jtve = uservar->jtve;
1251 
1252  // these are the alignment corrections+covariance (for selected params)
1253  int npar = jtve.num_row();
1254  AlgebraicVector params(npar);
1255  AlgebraicVector paramerr(npar);
1256  AlgebraicSymMatrix cov(npar);
1257 
1258  // errors of parameters
1259  if (isCollector) {
1260  if (setDet == 0) {
1261  int ierr;
1262  AlgebraicSymMatrix jtvjinv = jtvj.inverse(ierr);
1263  if (ierr != 0) {
1264  edm::LogError("Alignment") << "@SUB=HIPAlignmentAlgorithm::calcParameters"
1265  << "Matrix inversion failed!";
1266  return false;
1267  }
1268  params = -(jtvjinv * jtve);
1269  cov = jtvjinv;
1270 
1271  double minRelErrThreshold =
1273  double maxRelErrThreshold =
1275  for (int i = 0; i < npar; i++) {
1276  double relerr = 0;
1277  if (fabs(cov[i][i]) > 0.)
1278  paramerr[i] = sqrt(fabs(cov[i][i]));
1279  else
1280  paramerr[i] = params[i];
1281  if (params[i] != 0.)
1282  relerr = fabs(paramerr[i] / params[i]);
1283  if ((maxRelErrThreshold >= 0. && relerr > maxRelErrThreshold) || relerr < minRelErrThreshold) {
1284  edm::LogWarning("Alignment") << "@SUB=HIPAlignmentAlgorithm::calcParameters"
1285  << "RelError = " << relerr << " > " << maxRelErrThreshold << " or < "
1286  << minRelErrThreshold << ". Setting param = paramerr = 0 for component " << i;
1287  params[i] = 0;
1288  paramerr[i] = 0;
1289  }
1290  }
1291  } else {
1292  if (params.num_row() != 1) {
1293  edm::LogError("Alignment") << "@SUB=HIPAlignmentAlgorithm::calcParameters"
1294  << "For scanning, please only turn on one parameter! check common_cff_py.txt";
1295  return false;
1296  }
1297  if (theIteration == 1)
1298  params[0] = start;
1299  else
1300  params[0] = step;
1301  edm::LogWarning("Alignment") << "@SUB=HIPAlignmentAlgorithm::calcParameters"
1302  << "Parameters = " << params;
1303  }
1304  }
1305 
1306  uservar->alipar = params;
1307  uservar->alierr = paramerr;
1308 
1309  AlignmentParameters* parnew = par->cloneFromSelected(params, cov);
1310  ali->setAlignmentParameters(parnew);
1311  parnew->setValid(true);
1312 
1313  edm::LogInfo("Alignment") << "@SUB=HIPAlignmentAlgorithm::calcParameters"
1314  << "End: Processing detector " << ali->id();
1315 
1316  return true;
1317 }
1318 
1319 //-----------------------------------------------------------------------------
1321  edm::LogInfo("Alignment") << "@SUB=HIPAlignmentAlgorithm::collector"
1322  << "Called for iteration " << theIteration;
1323 
1324  std::vector<std::string> monitorFileList;
1325  HIPUserVariablesIORoot HIPIO;
1326 
1327  typedef int pawt_t;
1328  std::unordered_map<Alignable*, std::unordered_map<int, pawt_t>> ali_datatypecountpair_map;
1329  if (rewgtPerAli) {
1330  edm::LogInfo("Alignment") << "@SUB=HIPAlignmentAlgorithm::collector"
1331  << "Per-alignable reweighting is turned on. Iterating over the parallel jobs to sum "
1332  "number of hits per alignable for each data type.";
1333  // Counting step for per-alignable reweighting
1334  for (int ijob = 1; ijob <= theCollectorNJobs; ijob++) {
1335  edm::LogInfo("Alignment") << "@SUB=HIPAlignmentAlgorithm::collector"
1336  << "Pre-reading uservar for job " << ijob;
1337 
1338  std::string str = std::to_string(ijob);
1339  std::string uvfile = theCollectorPath + "/job" + str + "/" + suvarfilecore;
1340 
1341  std::vector<AlignmentUserVariables*> uvarvec =
1342  HIPIO.readHIPUserVariables(theAlignables, uvfile.c_str(), theIteration, ioerr);
1343  if (uvarvec.size() != theAlignables.size())
1344  edm::LogWarning("Alignment") << "@SUB=HIPAlignmentAlgorithm::collector"
1345  << "Number of alignables = " << theAlignables.size()
1346  << " is not the same as number of user variables = " << uvarvec.size()
1347  << ". A mismatch might occur!";
1348  if (ioerr != 0) {
1349  edm::LogError("Alignment") << "@SUB=HIPAlignmentAlgorithm::collector"
1350  << "Could not read user variable files for job " << ijob << " in iteration "
1351  << theIteration;
1352  continue;
1353  }
1354  std::vector<AlignmentUserVariables*>::const_iterator iuvar =
1355  uvarvec.begin(); // This vector should have 1-to-1 correspondence with the alignables vector
1356  for (const auto& ali : theAlignables) {
1357  // No need for the user variables already attached to the alignables
1358  // Just count from what you read.
1359  HIPUserVariables* uvar = dynamic_cast<HIPUserVariables*>(*iuvar);
1360  if (uvar != nullptr) {
1361  int alijobdtype = uvar->datatype;
1362  pawt_t alijobnhits = uvar->nhit;
1363  if (ali_datatypecountpair_map.find(ali) == ali_datatypecountpair_map.end()) { // This is a new alignable
1364  std::unordered_map<int, pawt_t> newmap;
1365  ali_datatypecountpair_map[ali] = newmap;
1366  ali_datatypecountpair_map[ali][alijobdtype] = alijobnhits;
1367  } else { // Alignable already exists in the map
1368  std::unordered_map<int, pawt_t>& theMap = ali_datatypecountpair_map[ali];
1369  if (theMap.find(alijobdtype) == theMap.end())
1370  theMap[alijobdtype] = alijobnhits;
1371  else
1372  theMap[alijobdtype] += alijobnhits;
1373  }
1374  delete uvar; // Delete new user variables as they are added
1375  }
1376  iuvar++;
1377  } // End loop over alignables
1378  } // End loop over subjobs
1379  }
1380 
1381  for (int ijob = 1; ijob <= theCollectorNJobs; ijob++) {
1382  edm::LogInfo("Alignment") << "@SUB=HIPAlignmentAlgorithm::collector"
1383  << "Reading uservar for job " << ijob;
1384 
1385  std::string str = std::to_string(ijob);
1386  std::string uvfile = theCollectorPath + "/job" + str + "/" + suvarfilecore;
1387 
1388  std::vector<AlignmentUserVariables*> uvarvec =
1389  HIPIO.readHIPUserVariables(theAlignables, uvfile.c_str(), theIteration, ioerr);
1390  if (uvarvec.size() != theAlignables.size())
1391  edm::LogWarning("Alignment") << "@SUB=HIPAlignmentAlgorithm::collector"
1392  << "Number of alignables = " << theAlignables.size()
1393  << " is not the same as number of user variables = " << uvarvec.size()
1394  << ". A mismatch might occur!";
1395 
1396  if (ioerr != 0) {
1397  edm::LogError("Alignment") << "@SUB=HIPAlignmentAlgorithm::collector"
1398  << "Could not read user variable files for job " << ijob << " in iteration "
1399  << theIteration;
1400  continue;
1401  }
1402 
1403  // add
1404  std::vector<AlignmentUserVariables*> uvarvecadd;
1405  std::vector<AlignmentUserVariables*>::const_iterator iuvarnew = uvarvec.begin();
1406  for (const auto& ali : theAlignables) {
1407  AlignmentParameters* ap = ali->alignmentParameters();
1408 
1409  HIPUserVariables* uvarold = dynamic_cast<HIPUserVariables*>(ap->userVariables());
1410  HIPUserVariables* uvarnew = dynamic_cast<HIPUserVariables*>(*iuvarnew);
1411 
1412  HIPUserVariables* uvar = uvarold->clone();
1413  uvar->datatype =
1414  theDataGroup; // Set the data type of alignable to that specified for the collector job (-2 by default)
1415 
1416  if (uvarnew != nullptr) {
1417  double peraliwgt = 1;
1418  if (rewgtPerAli) {
1419  int alijobdtype = uvarnew->datatype;
1420  if (ali_datatypecountpair_map.find(ali) != ali_datatypecountpair_map.end() &&
1421  ali_datatypecountpair_map[ali].find(alijobdtype) != ali_datatypecountpair_map[ali].end()) {
1422  peraliwgt = ali_datatypecountpair_map[ali][alijobdtype];
1423  unsigned int nNonZeroTypes = 0;
1424  pawt_t sumwgts = 0;
1425  for (auto it = ali_datatypecountpair_map[ali].cbegin(); it != ali_datatypecountpair_map[ali].cend(); ++it) {
1426  sumwgts += it->second;
1427  if (it->second != pawt_t(0))
1428  nNonZeroTypes++;
1429  }
1430  edm::LogInfo("Alignment") << "@SUB=HIPAlignmentAlgorithm::collector"
1431  << "Reweighting detector " << ali->id() << " / " << ali->alignableObjectId()
1432  << " for data type " << alijobdtype << " by " << sumwgts << "/" << peraliwgt
1433  << "/" << nNonZeroTypes;
1434  peraliwgt = ((nNonZeroTypes == 0 || peraliwgt == double(0))
1435  ? double(1)
1436  : double((double(sumwgts)) / peraliwgt / (double(nNonZeroTypes))));
1437  } else if (ali_datatypecountpair_map.find(ali) != ali_datatypecountpair_map.end())
1438  edm::LogError("Alignment") << "@SUB=HIPAlignmentAlgorithm::collector"
1439  << "Could not find data type " << alijobdtype << " for detector " << ali->id()
1440  << " / " << ali->alignableObjectId();
1441  else
1442  edm::LogError("Alignment") << "@SUB=HIPAlignmentAlgorithm::collector"
1443  << "Could not find detector " << ali->id() << " / " << ali->alignableObjectId()
1444  << " in the map ali_datatypecountpair_map";
1445  }
1446 
1447  uvar->nhit = (uvarold->nhit) + (uvarnew->nhit);
1448  uvar->jtvj = (uvarold->jtvj) + peraliwgt * (uvarnew->jtvj);
1449  uvar->jtve = (uvarold->jtve) + peraliwgt * (uvarnew->jtve);
1450  uvar->alichi2 = (uvarold->alichi2) + peraliwgt * (uvarnew->alichi2);
1451  uvar->alindof = (uvarold->alindof) + (uvarnew->alindof);
1452 
1453  delete uvarnew; // Delete new user variables as they are added
1454  }
1455 
1456  uvarvecadd.push_back(uvar);
1457  iuvarnew++;
1458  }
1459 
1461 
1462  // fill Eventwise Tree
1463  if (doTrackHitMonitoring) {
1464  uvfile = theCollectorPath + "/job" + str + "/" + theMonitorConfig.outfilecore;
1465  monitorFileList.push_back(uvfile);
1466  }
1467  } // end loop on jobs
1468 
1469  // Collect monitor (eventwise and hitwise) trees
1471  collectMonitorTrees(monitorFileList);
1472 }
1473 
1474 //------------------------------------------------------------------------------------
1475 void HIPAlignmentAlgorithm::collectMonitorTrees(const std::vector<std::string>& filenames) {
1476  if (!doTrackHitMonitoring)
1477  return;
1478  if (!isCollector)
1479  throw cms::Exception("LogicError") << "[HIPAlignmentAlgorithm::collectMonitorTrees] Called in non-collector mode."
1480  << std::endl;
1481 
1482  TString theTrackMonitorTreeName = Form("T1_%i", theIteration);
1483  TString theHitMonitorTreeName = Form("T1_hit_%i", theIteration);
1484 
1485  std::vector<TFile*> finputlist;
1486  TList* eventtrees = new TList;
1487  TList* hittrees = new TList;
1488  for (std::string const& filename : filenames) {
1489  TFile* finput = TFile::Open(filename.c_str(), "read");
1490  if (finput != nullptr) {
1491  TTree* tmptree;
1493  tmptree = nullptr;
1494  tmptree = (TTree*)finput->Get(theTrackMonitorTreeName);
1495  if (tmptree != nullptr)
1496  eventtrees->Add(tmptree);
1497  }
1499  tmptree = nullptr;
1500  tmptree = (TTree*)finput->Get(theHitMonitorTreeName);
1501  if (tmptree != nullptr)
1502  hittrees->Add((TTree*)finput->Get(theHitMonitorTreeName));
1503  }
1504  finputlist.push_back(finput);
1505  }
1506  }
1507 
1508  if (theTrackHitMonitorIORootFile != nullptr) { // This should never happen
1509  edm::LogError("Alignment") << "@SUB=HIPAlignmentAlgorithm::collectMonitorTrees"
1510  << "Monitor file is already open while it is not supposed to be!";
1511  delete theTrackMonitorTree;
1512  theTrackMonitorTree = nullptr;
1513  delete theHitMonitorTree;
1514  theHitMonitorTree = nullptr;
1516  }
1517  theTrackHitMonitorIORootFile = TFile::Open(theMonitorConfig.outfile.c_str(), "update");
1519  if (eventtrees->GetSize() > 0)
1520  theTrackMonitorTree = TTree::MergeTrees(eventtrees);
1521  if (hittrees->GetSize() > 0)
1522  theHitMonitorTree = TTree::MergeTrees(hittrees);
1523  // Leave it to HIPAlignmentAlgorithm::terminate to write the trees and close theTrackHitMonitorIORootFile
1524 
1525  delete hittrees;
1526  delete eventtrees;
1527  for (TFile*& finput : finputlist)
1528  finput->Close();
1529 
1530  // Rename the trees to standard names
1531  if (theTrackMonitorTree != nullptr)
1532  theTrackMonitorTree->SetName(theTrackMonitorTreeName);
1533  if (theHitMonitorTree != nullptr)
1534  theHitMonitorTree->SetName(theHitMonitorTreeName);
1535 }
1536 
1537 //-----------------------------------------------------------------------------------
1539  if (ali != nullptr) {
1540  for (std::vector<HIPAlignableSpecificParameters>::iterator it = theAlignableSpecifics.begin();
1541  it != theAlignableSpecifics.end();
1542  it++) {
1543  if (it->matchAlignable(ali))
1544  return &(*it);
1545  }
1546  edm::LogInfo("Alignment") << "[HIPAlignmentAlgorithm::findAlignableSpecs] Alignment object with id " << ali->id()
1547  << " / " << ali->alignableObjectId() << " could not be found. Returning default.";
1548  }
1549  return &defaultAlignableSpecs;
1550 }
Definition: start.py:1
Log< level::Info, true > LogVerbatim
std::vector< float > m_P
std::vector< int > m_nhTIB
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
const IOVSyncValue & first() const
AlignmentParameters * alignmentParameters() const
Get the AlignmentParameters.
Definition: Alignable.h:58
std::vector< HIPAlignableSpecificParameters > theAlignableSpecifics
HIPAlignableSpecificParameters defaultAlignableSpecs
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
const LocalTrajectoryError & localError() const
const AlignableSurface & surface() const
Return the Surface (global position and orientation) of the object.
Definition: Alignable.h:132
AlignmentParameterStore * theAlignmentParameterStore
std::vector< float > m_Eta
std::vector< float > m_d0
static AlignableObjectId commonObjectIdProvider(const AlignableObjectId &, const AlignableObjectId &)
T z() const
Definition: PV3DBase.h:61
bool verbose
void setAlignmentPositionError(const align::Alignables &alivec, double valshift, double valrot)
Set Alignment position error.
HIPAlignableSpecificParameters * findAlignableSpecs(const Alignable *ali)
void run(const edm::EventSetup &setup, const EventInfo &eventInfo) override
Run the algorithm.
TrajectoryStateOnSurface const & forwardPredictedState() const
Access to forward predicted state (from fitter or builder)
void initialize(const edm::EventSetup &setup, AlignableTracker *tracker, AlignableMuon *muon, AlignableExtras *extras, AlignmentParameterStore *store) override
Call at beginning of job.
align::StructureType m2_ObjId
bool hasFilledProb() const
AlgebraicVector alipar
const AlgebraicVector & parameters(void) const
Get alignment parameters.
void writeIterationFile(std::string filename, int iter)
const align::Alignables & alignables(void) const
get all alignables
void applyParameters(void)
Obsolete: Use AlignableNavigator::alignableDetFromDetId and alignableFromAlignableDet.
std::pair< int, int > typeAndLayer(const Alignable *ali, const TrackerTopology *tTopo) const
Obtain type and layer from Alignable.
AlgebraicVector jtve
Log< level::Error, false > LogError
LocalError positionError() const
void attachUserVariables(const align::Alignables &alivec, const std::vector< AlignmentUserVariables *> &uvarvec, int &ierr)
Attach User Variables to given alignables.
assert(be >=bs)
void applyAlignableAbsolutePositions(const align::Alignables &alis, const AlignablePositions &newpos, int &ierr)
apply absolute positions to alignables
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > topoToken2_
std::vector< int > m_Nhits
int numSelected(void) const
Get number of selected parameters.
ClusterRef cluster() const
Definition: Electron.h:6
static std::string to_string(const XMLCh *ch)
std::unique_ptr< AlignableNavigator > theAlignableDetAccessor
define event information passed to algorithms
std::vector< unsigned > theIOVrangeSet
void writeHIPUserVariables(const Alignables &alivec, const char *filename, int iter, bool validCheck, int &ierr)
bool calcParameters(Alignable *ali, int setDet, double start, double step)
DataContainer const & measurements() const
Definition: Trajectory.h:178
HIPUserVariables * clone(void) const override
const bool fillTrackHitMonitoring
AlgebraicSymMatrix jtvj
std::vector< float > m_Pt
void bookBranches() override
float yy() const
Definition: LocalError.h:24
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
std::vector< int > m_nhPXB
std::vector< float > m_wt
std::vector< AlignmentUserVariables * > readHIPUserVariables(const Alignables &alivec, const char *filename, int iter, int &ierr)
void setAlignmentParameters(AlignmentParameters *dap)
Set the AlignmentParameters.
Definition: Alignable.cc:123
CLHEP::HepMatrix AlgebraicMatrix
std::vector< edm::ParameterSet > theCutsPerComponent
void setValid(bool v)
Set validity flag.
CompositeAlignmentParameters selectParameters(const std::vector< AlignableDet *> &alignabledets) const
std::vector< int > m_nhTID
AlgebraicVector alierr
T sqrt(T t)
Definition: SSEVec.h:19
std::vector< float > m_Phi
LocalVector localDirection() const
HIPHitMonitorVariables hitmonitorvars
AlignmentUserVariables * userVariables(void) const
Get pointer to user variables.
virtual StructureType alignableObjectId() const =0
Return the alignable type identifier.
TrajectoryStateOnSurface const & backwardPredictedState() const
Access to backward predicted state (from smoother)
std::vector< int > m_nhTEC
AlignablePositions readAlignableAbsolutePositions(const align::Alignables &alivec, const char *filename, int iter, int &ierr) override
read Alignable current absolute positions
Transition
Definition: Transition.h:12
float probabilityXY() const
Definition: SiPixelRecHit.h:86
virtual std::vector< double > parameters() const =0
parameters - interpretation left to the concrete implementation
int readIterationFile(std::string filename)
std::vector< double > SetScanDet
bool isValid(void) const
Get validity flag.
const bool fillTrackMonitoring
unsigned int m_rawQualityWord
void collectMonitorTrees(const std::vector< std::string > &filenames)
double calcAPE(double *par, int iter, int function)
Log< level::Info, false > LogInfo
RunNumber_t run() const
Definition: EventID.h:38
float xy() const
Definition: LocalError.h:23
CLHEP::HepVector AlgebraicVector
align::ID id() const
Return the ID of Alignable, i.e. DetId of &#39;first&#39; component GeomDet(Unit).
Definition: Alignable.h:180
static constexpr float d0
void setTree(TTree *tree_)
std::vector< int > m_nhTOB
const PositionType & position() const
void setUserVariables(AlignmentUserVariables *auv)
Set pointer to user variables.
HIPTrackMonitorVariables trackmonitorvars
const std::string outfilecore
SiPixelRecHitQuality::QualWordType rawQualityWord() const
Definition: SiPixelRecHit.h:78
std::unique_ptr< AlignableObjectId > alignableObjectId_
virtual int type() const =0
specific type, i.e. SurfaceDeformationFactory::Type
void writeAlignableAbsolutePositions(const align::Alignables &alivec, const char *filename, int iter, bool validCheck, int &ierr) override
write Alignable current absolute positions
void bookBranches() override
HIPAlignmentAlgorithm(const edm::ParameterSet &cfg, edm::ConsumesCollector &iC)
Constructor.
std::vector< edm::ParameterSet > theAPEParameterSet
align::StructureType m3_ObjId
std::unique_ptr< TFormula > theEtaFormula
std::vector< Alignable * > Alignables
Definition: Utilities.h:31
const EventID & eventID() const
Definition: IOVSyncValue.h:40
const edm::ESGetToken< TrackerTopology, IdealGeometryRecord > topoToken_
align::Alignables theAlignables
virtual void terminate()
Called at end of job (must be implemented in derived class)
HLT enums.
std::vector< float > m2_surfDef
HIPMonitorConfig theMonitorConfig
void fillAlignablesMonitor(const edm::EventSetup &setup)
CLHEP::HepSymMatrix AlgebraicSymMatrix
std::string tname(const std::string &tableName, const std::string &schemaVersion)
void startNewLoop(void) override
Called at start of new loop.
const std::vector< std::string > surveyResiduals_
std::vector< int > m_nhPXF
std::vector< AlignableAbsData > AlignablePositions
Definition: AlignableData.h:47
step
Definition: StallMonitor.cc:83
bool processHit2D(const AlignableDetOrUnitPtr &alidet, const Alignable *ali, const HIPAlignableSpecificParameters *alispecifics, const TrajectoryStateOnSurface &tsos, const TrackingRecHit *hit, double hitwt)
std::vector< float > m_dz
eventInfo
add run, event number and lumi section
bool processHit1D(const AlignableDetOrUnitPtr &alidet, const Alignable *ali, const HIPAlignableSpecificParameters *alispecifics, const TrajectoryStateOnSurface &tsos, const TrackingRecHit *hit, double hitwt)
Log< level::Warning, false > LogWarning
std::vector< std::pair< align::Alignables, std::vector< double > > > theAPEParameters
Alignable * alignableFromAlignableDet(const AlignableDetOrUnitPtr &adet) const
Get relevant Alignable from AlignableDet.
virtual AlignmentParameters * cloneFromSelected(const AlgebraicVector &par, const AlgebraicSymMatrix &cov) const =0
float probabilityQ() const
Definition: SiPixelRecHit.h:87
#define str(s)
Constructor of the full muon geometry.
Definition: AlignableMuon.h:38
ClusterRef cluster() const
std::vector< align::StructureType > theLevels
std::vector< float > m_Chi2n
TSOS combine(const TSOS &pTsos1, const TSOS &pTsos2) const
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
float xx() const
Definition: LocalError.h:22
std::string className(const T &t)
Definition: ClassName.h:31
ConstRecHitPointer const & recHit() const
Our base class.
Definition: SiPixelRecHit.h:23
T angle(T x1, T y1, T z1, T x2, T y2, T z2)
Definition: angle.h:11
SurfaceDeformationFactory::Type m2_dtype
std::vector< ConstTrajTrackPair > ConstTrajTrackPairCollection