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