CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
HIPAlignmentAlgorithm Class Reference

#include <HIPAlignmentAlgorithm.h>

Inheritance diagram for HIPAlignmentAlgorithm:
AlignmentAlgorithmBase

Public Member Functions

 HIPAlignmentAlgorithm (const edm::ParameterSet &cfg)
 Constructor. More...
 
void initialize (const edm::EventSetup &setup, AlignableTracker *tracker, AlignableMuon *muon, AlignableExtras *extras, AlignmentParameterStore *store) override
 Call at beginning of job. More...
 
void run (const edm::EventSetup &setup, const EventInfo &eventInfo) override
 Run the algorithm. More...
 
void startNewLoop (void) override
 Called at start of new loop. More...
 
void terminate (const edm::EventSetup &setup) override
 Call at end of job. More...
 
 ~HIPAlignmentAlgorithm () override
 Destructor. More...
 
- Public Member Functions inherited from AlignmentAlgorithmBase
virtual bool addCalibrations (const Calibrations &)
 
bool addCalibrations (const CalibrationsOwner &cals)
 
 AlignmentAlgorithmBase (const edm::ParameterSet &)
 Constructor. More...
 
virtual void beginLuminosityBlock (const edm::EventSetup &setup)
 called at begin of luminosity block (no lumi block info passed yet) More...
 
virtual void beginRun (const edm::Run &, const edm::EventSetup &, bool changed)
 called at begin of run More...
 
virtual void endLuminosityBlock (const edm::EventSetup &setup)
 called at end of luminosity block (no lumi block info passed yet) More...
 
virtual void endRun (const EndRunInfo &runInfo, const edm::EventSetup &setup)
 called at end of run - order of arguments like in EDProducer etc. More...
 
virtual bool processesEvents ()
 Returns whether algorithm proccesses events in current configuration. More...
 
virtual bool setParametersForRunRange (const RunRange &rr)
 
virtual bool storeAlignments ()
 Returns whether algorithm produced results to be stored. More...
 
virtual bool supportsCalibrations ()
 
virtual void terminate ()
 Called at end of job (must be implemented in derived class) More...
 
virtual ~AlignmentAlgorithmBase ()
 Destructor. More...
 

Private Member Functions

void bookRoot (void)
 
double calcAPE (double *par, int iter, int function)
 
bool calcParameters (Alignable *ali, int setDet, double start, double step)
 
void collectMonitorTrees (const std::vector< std::string > &filenames)
 
void collector (void)
 
void fillAlignablesMonitor (const edm::EventSetup &setup)
 
HIPAlignableSpecificParametersfindAlignableSpecs (const Alignable *ali)
 
bool processHit1D (const AlignableDetOrUnitPtr &alidet, const Alignable *ali, const HIPAlignableSpecificParameters *alispecifics, const TrajectoryStateOnSurface &tsos, const TrackingRecHit *hit, double hitwt)
 
bool processHit2D (const AlignableDetOrUnitPtr &alidet, const Alignable *ali, const HIPAlignableSpecificParameters *alispecifics, const TrajectoryStateOnSurface &tsos, const TrackingRecHit *hit, double hitwt)
 
int readIterationFile (std::string filename)
 
void setAlignmentPositionError (void)
 
void writeIterationFile (std::string filename, int iter)
 

Private Attributes

std::unique_ptr< AlignableObjectIdalignableObjectId_
 
double col_cut
 
double cos_cut
 
HIPAlignableSpecificParameters defaultAlignableSpecs
 
const bool doTrackHitMonitoring
 
int ioerr
 
bool isCollector
 
bool IsCollision
 
int m2_datatype
 
SurfaceDeformationFactory::Type m2_dtype
 
align::ID m2_Id
 
int m2_Layer
 
int m2_Nhit
 
unsigned int m2_nsurfdef
 
align::StructureType m2_ObjId
 
std::vector< float > m2_surfDef
 
int m2_Type
 
float m2_Xpos
 
float m2_Ypos
 
float m2_Zpos
 
align::ID m3_Id
 
align::StructureType m3_ObjId
 
float m3_par [6]
 
int m_datatype
 
std::string outfile2
 
std::string outpath
 
bool rewgtPerAli
 
std::string salignedfile
 
double Scale
 
std::vector< double > SetScanDet
 
std::string siterationfile
 
std::string smisalignedfile
 
std::string sparameterfile
 
std::string ssurveyfile
 
std::string struefile
 
const std::vector< std::string > surveyResiduals_
 
std::string suvarfile
 
std::string suvarfilecore
 
std::unique_ptr< AlignableNavigatortheAlignableDetAccessor
 
align::Alignables theAlignables
 
TFile * theAlignablesMonitorIORootFile
 
TTree * theAlignablesMonitorTree
 
std::vector< HIPAlignableSpecificParameterstheAlignableSpecifics
 
AlignmentParameterStoretheAlignmentParameterStore
 
std::vector< std::pair< align::Alignables, std::vector< double > > > theAPEParameters
 
std::vector< edm::ParameterSettheAPEParameterSet
 
bool theApplyAPE
 
bool theApplyCutsPerComponent
 
int theCollectorNJobs
 
std::string theCollectorPath
 
std::vector< edm::ParameterSettheCutsPerComponent
 
int theDataGroup
 
std::unique_ptr< TFormula > theEtaFormula
 
TTree * theHitMonitorTree
 
AlignmentIORoot theIO
 
std::vector< unsigned > theIOVrangeSet
 
int theIteration
 
std::vector< align::StructureTypetheLevels
 
HIPMonitorConfig theMonitorConfig
 
bool themultiIOV
 
TFile * theSurveyIORootFile
 
TTree * theSurveyTree
 
TFile * theTrackHitMonitorIORootFile
 
TTree * theTrackMonitorTree
 
bool trackPs
 
bool trackWt
 
bool uniEta
 
std::string uniEtaFormula
 
const bool verbose
 

Additional Inherited Members

- Public Types inherited from AlignmentAlgorithmBase
typedef std::pair< const Trajectory *, const reco::Track * > ConstTrajTrackPair
 
typedef std::vector< ConstTrajTrackPairConstTrajTrackPairCollection
 
using RunNumber = align::RunNumber
 
using RunRange = align::RunRange
 

Detailed Description

Definition at line 31 of file HIPAlignmentAlgorithm.h.

Constructor & Destructor Documentation

HIPAlignmentAlgorithm::HIPAlignmentAlgorithm ( const edm::ParameterSet cfg)

Constructor.

Definition at line 45 of file HIPAlignmentAlgorithm.cc.

References col_cut, cos_cut, defaultAlignableSpecs, edm::ParameterSet::getParameter(), isCollector, IsCollision, HIPAlignableSpecificParameters::maxHitPull, HIPAlignableSpecificParameters::maxRelParError, HIPAlignableSpecificParameters::minNHits, HIPAlignableSpecificParameters::minRelParError, outfile2, outpath, rewgtPerAli, salignedfile, Scale, SetScanDet, siterationfile, smisalignedfile, sparameterfile, ssurveyfile, AlCaHLTBitMon_QueryRunRegistry::string, struefile, suvarfile, suvarfilecore, theAPEParameterSet, theApplyAPE, theApplyCutsPerComponent, theCollectorNJobs, theCollectorPath, theCutsPerComponent, theDataGroup, theEtaFormula, theIOVrangeSet, themultiIOV, trackPs, trackWt, uniEta, and uniEtaFormula.

47  verbose(cfg.getParameter<bool>("verbosity")),
48  theMonitorConfig(cfg),
51  surveyResiduals_(cfg.getUntrackedParameter<std::vector<std::string>>("surveyResiduals")),
53  theTrackMonitorTree(nullptr),
54  theHitMonitorTree(nullptr),
56  theAlignablesMonitorTree(nullptr),
57  theSurveyIORootFile(nullptr),
58  theSurveyTree(nullptr) {
59  // parse parameters
60  outpath = cfg.getParameter<std::string>("outpath");
61  outfile2 = cfg.getParameter<std::string>("outfile2");
62  struefile = cfg.getParameter<std::string>("trueFile");
63  smisalignedfile = cfg.getParameter<std::string>("misalignedFile");
64  salignedfile = cfg.getParameter<std::string>("alignedFile");
65  siterationfile = cfg.getParameter<std::string>("iterationFile");
66  suvarfilecore = cfg.getParameter<std::string>("uvarFile");
68  sparameterfile = cfg.getParameter<std::string>("parameterFile");
69  ssurveyfile = cfg.getParameter<std::string>("surveyFile");
70 
71  outfile2 = outpath + outfile2; //Alignablewise tree
72  struefile = outpath + struefile;
73  smisalignedfile = outpath + smisalignedfile;
74  salignedfile = outpath + salignedfile;
75  siterationfile = outpath + siterationfile;
76  suvarfile = outpath + suvarfile;
78  ssurveyfile = outpath + ssurveyfile;
79 
80  // parameters for APE
81  theApplyAPE = cfg.getParameter<bool>("applyAPE");
82  theAPEParameterSet = cfg.getParameter<std::vector<edm::ParameterSet>>("apeParam");
83 
84  themultiIOV = cfg.getParameter<bool>("multiIOV");
85  theIOVrangeSet = cfg.getParameter<std::vector<unsigned>>("IOVrange");
86 
87  defaultAlignableSpecs.minNHits = cfg.getParameter<int>("minimumNumberOfHits");
88  ;
89  defaultAlignableSpecs.minRelParError = cfg.getParameter<double>("minRelParameterError");
90  defaultAlignableSpecs.maxRelParError = cfg.getParameter<double>("maxRelParameterError");
91  defaultAlignableSpecs.maxHitPull = cfg.getParameter<double>("maxAllowedHitPull");
92  theApplyCutsPerComponent = cfg.getParameter<bool>("applyCutsPerComponent");
93  theCutsPerComponent = cfg.getParameter<std::vector<edm::ParameterSet>>("cutsPerComponent");
94 
95  // for collector mode (parallel processing)
96  isCollector = cfg.getParameter<bool>("collectorActive");
97  theCollectorNJobs = cfg.getParameter<int>("collectorNJobs");
98  theCollectorPath = cfg.getParameter<std::string>("collectorPath");
99 
100  if (isCollector)
101  edm::LogInfo("Alignment") << "@SUB=HIPAlignmentAlgorithm::HIPAlignmentAlgorithm"
102  << "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"
112  << "Uniform eta formula is empty! Resetting to 1.";
113  uniEtaFormula = "1";
114  }
115  theEtaFormula = std::make_unique<TFormula>(uniEtaFormula.c_str());
116  rewgtPerAli = trackWt && cfg.getParameter<bool>("ReweightPerAlignable");
117  IsCollision = cfg.getParameter<bool>("isCollision");
118  SetScanDet = cfg.getParameter<std::vector<double>>("setScanDet");
119  col_cut = cfg.getParameter<double>("CLAngleCut");
120  cos_cut = cfg.getParameter<double>("CSAngleCut");
121 
122  edm::LogInfo("Alignment") << "@SUB=HIPAlignmentAlgorithm::HIPAlignmentAlgorithm"
123  << "Constructed";
124 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
HIPAlignableSpecificParameters defaultAlignableSpecs
std::vector< unsigned > theIOVrangeSet
const bool fillTrackHitMonitoring
std::vector< edm::ParameterSet > theCutsPerComponent
AlignmentAlgorithmBase(const edm::ParameterSet &)
Constructor.
std::vector< double > SetScanDet
const bool fillTrackMonitoring
std::vector< edm::ParameterSet > theAPEParameterSet
std::unique_ptr< TFormula > theEtaFormula
HIPMonitorConfig theMonitorConfig
const std::vector< std::string > surveyResiduals_
HIPAlignmentAlgorithm::~HIPAlignmentAlgorithm ( )
inlineoverride

Member Function Documentation

void HIPAlignmentAlgorithm::bookRoot ( void  )
private

Definition at line 1093 of file HIPAlignmentAlgorithm.cc.

References HIPTrackMonitorVariables::bookBranches(), HIPHitMonitorVariables::bookBranches(), doTrackHitMonitoring, HIPMonitorConfig::fillTrackHitMonitoring, HIPMonitorConfig::fillTrackMonitoring, HIPMonitorConfig::hitmonitorvars, isCollector, m2_datatype, m2_dtype, m2_Id, m2_Layer, m2_Nhit, m2_nsurfdef, m2_ObjId, m2_surfDef, m2_Type, m2_Xpos, m2_Ypos, m2_Zpos, m3_Id, m3_ObjId, m3_par, m_datatype, HIPMonitorConfig::outfile, outfile2, HIPMonitorVariables::setTree(), ssurveyfile, theAlignablesMonitorIORootFile, theAlignablesMonitorTree, theHitMonitorTree, theIteration, theLevels, theMonitorConfig, theSurveyIORootFile, theSurveyTree, theTrackHitMonitorIORootFile, theTrackMonitorTree, cond::persistency::GLOBAL_TAG::tname, and HIPMonitorConfig::trackmonitorvars.

Referenced by startNewLoop(), and ~HIPAlignmentAlgorithm().

1093  {
1094  // create ROOT files
1096  theTrackHitMonitorIORootFile = TFile::Open(theMonitorConfig.outfile.c_str(), "update");
1098  // book event-wise ROOT Tree
1100  TString tname = Form("T1_%i", theIteration);
1101  theTrackMonitorTree = new TTree(tname, "Eventwise tree");
1102  //theTrackMonitorTree->Branch("Run", &m_Run, "Run/I");
1103  //theTrackMonitorTree->Branch("Event", &m_Event, "Event/I");
1104  theTrackMonitorTree->Branch("DataType", &m_datatype);
1107  }
1108  // book hit-wise ROOT Tree
1110  TString tname_hit = Form("T1_hit_%i", theIteration);
1111  theHitMonitorTree = new TTree(tname_hit, "Hitwise tree");
1112  theHitMonitorTree->Branch("DataType", &m_datatype);
1115  }
1116  }
1117 
1118  // book alignable-wise ROOT Tree
1119  if (isCollector) {
1120  TString tname = Form("T2_%i", theIteration);
1121  theAlignablesMonitorIORootFile = TFile::Open(outfile2.c_str(), "update");
1123  theAlignablesMonitorTree = new TTree(tname, "Alignablewise tree");
1124  theAlignablesMonitorTree->Branch("Id", &m2_Id, "Id/i");
1125  theAlignablesMonitorTree->Branch("ObjId", &m2_ObjId, "ObjId/I");
1126  theAlignablesMonitorTree->Branch("Nhit", &m2_Nhit);
1127  theAlignablesMonitorTree->Branch("DataType", &m2_datatype);
1128  theAlignablesMonitorTree->Branch("Type", &m2_Type);
1129  theAlignablesMonitorTree->Branch("Layer", &m2_Layer);
1130  theAlignablesMonitorTree->Branch("Xpos", &m2_Xpos);
1131  theAlignablesMonitorTree->Branch("Ypos", &m2_Ypos);
1132  theAlignablesMonitorTree->Branch("Zpos", &m2_Zpos);
1133  theAlignablesMonitorTree->Branch("DeformationsType", &m2_dtype, "DeformationsType/I");
1134  theAlignablesMonitorTree->Branch("NumDeformations", &m2_nsurfdef);
1135  theAlignablesMonitorTree->Branch("Deformations", &m2_surfDef);
1136  }
1137 
1138  // book survey-wise ROOT Tree only if survey is enabled
1139  if (!theLevels.empty()) {
1140  TString tname = Form("T3_%i", theIteration);
1141  theSurveyIORootFile = TFile::Open(ssurveyfile.c_str(), "update");
1142  theSurveyIORootFile->cd();
1143  theSurveyTree = new TTree(tname, "Survey Tree");
1144  theSurveyTree->Branch("Id", &m3_Id, "Id/i");
1145  theSurveyTree->Branch("ObjId", &m3_ObjId, "ObjId/I");
1146  theSurveyTree->Branch("Par", &m3_par, "Par[6]/F");
1147  edm::LogInfo("Alignment") << "[HIPAlignmentAlgorithm::bookRoot] Survey trees booked.";
1148  }
1149  edm::LogInfo("Alignment") << "[HIPAlignmentAlgorithm::bookRoot] Root trees booked.";
1150 }
static char const * tname
Definition: GTSchema.h:13
align::StructureType m2_ObjId
const bool fillTrackHitMonitoring
void bookBranches() override
HIPHitMonitorVariables hitmonitorvars
const bool fillTrackMonitoring
void setTree(TTree *tree_)
HIPTrackMonitorVariables trackmonitorvars
void bookBranches() override
align::StructureType m3_ObjId
std::vector< float > m2_surfDef
HIPMonitorConfig theMonitorConfig
std::vector< align::StructureType > theLevels
SurfaceDeformationFactory::Type m2_dtype
double HIPAlignmentAlgorithm::calcAPE ( double *  par,
int  iter,
int  function 
)
private

Definition at line 1076 of file HIPAlignmentAlgorithm.cc.

References JetChargeProducer_cfi::exp, createfilelist::int, SiStripPI::max, and funct::pow().

Referenced by setAlignmentPositionError(), and ~HIPAlignmentAlgorithm().

1076  {
1077  double diter = (double)iter;
1078  if (function == 0)
1079  return std::max(par[1], par[0] + ((par[1] - par[0]) / par[2]) * diter);
1080  else if (function == 1)
1081  return std::max(0., par[0] * (exp(-pow(diter, par[1]) / par[2])));
1082  else if (function == 2) {
1083  int ipar2 = (int)par[2];
1084  int step = iter / ipar2;
1085  double dstep = (double)step;
1086  return std::max(0., par[0] - par[1] * dstep);
1087  } else
1088  assert(false); // should have been caught in the constructor
1089 }
step
Definition: StallMonitor.cc:94
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:30
bool HIPAlignmentAlgorithm::calcParameters ( Alignable ali,
int  setDet,
double  start,
double  step 
)
private

Definition at line 1234 of file HIPAlignmentAlgorithm.cc.

References HIPUserVariables::alierr, Alignable::alignmentParameters(), HIPUserVariables::alipar, AlignmentParameters::cloneFromSelected(), defaultAlignableSpecs, findAlignableSpecs(), mps_fire::i, Alignable::id(), isCollector, HIPUserVariables::jtve, HIPUserVariables::jtvj, HIPAlignableSpecificParameters::maxRelParError, HIPAlignableSpecificParameters::minNHits, HIPAlignableSpecificParameters::minRelParError, HIPUserVariables::nhit, CalibrationSummaryClient_cfi::params, Alignable::setAlignmentParameters(), AlignmentParameters::setValid(), mathSSE::sqrt(), command_line::start, theApplyCutsPerComponent, theIteration, and AlignmentParameters::userVariables().

Referenced by terminate(), and ~HIPAlignmentAlgorithm().

1234  {
1235  edm::LogInfo("Alignment") << "@SUB=HIPAlignmentAlgorithm::calcParameters"
1236  << "Begin: Processing detector " << ali->id();
1237 
1238  // Alignment parameters
1240  const HIPAlignableSpecificParameters* alispecifics = findAlignableSpecs(ali);
1241  // access user variables
1242  HIPUserVariables* uservar = dynamic_cast<HIPUserVariables*>(par->userVariables());
1243  int nhit = uservar->nhit;
1244  // The following variable is needed for the extended 1D/2D hit fix using
1245  // matrix shrinkage and expansion
1246  // int hitdim = uservar->hitdim;
1247 
1248  // Test nhits
1249  int minHitThreshold = (!theApplyCutsPerComponent ? defaultAlignableSpecs.minNHits : alispecifics->minNHits);
1250  if (!isCollector)
1251  minHitThreshold = 1;
1252  if (setDet == 0 && nhit < minHitThreshold) {
1253  edm::LogInfo("Alignment") << "@SUB=HIPAlignmentAlgorithm::calcParameters"
1254  << "Skipping detector " << ali->id() << " because number of hits = " << nhit
1255  << " <= " << minHitThreshold;
1256  par->setValid(false);
1257  return false;
1258  }
1259 
1260  AlgebraicSymMatrix jtvj = uservar->jtvj;
1261  AlgebraicVector jtve = uservar->jtve;
1262 
1263  // these are the alignment corrections+covariance (for selected params)
1264  int npar = jtve.num_row();
1265  AlgebraicVector params(npar);
1266  AlgebraicVector paramerr(npar);
1267  AlgebraicSymMatrix cov(npar);
1268 
1269  // errors of parameters
1270  if (isCollector) {
1271  if (setDet == 0) {
1272  int ierr;
1273  AlgebraicSymMatrix jtvjinv = jtvj.inverse(ierr);
1274  if (ierr != 0) {
1275  edm::LogError("Alignment") << "@SUB=HIPAlignmentAlgorithm::calcParameters"
1276  << "Matrix inversion failed!";
1277  return false;
1278  }
1279  params = -(jtvjinv * jtve);
1280  cov = jtvjinv;
1281 
1282  double minRelErrThreshold =
1284  double maxRelErrThreshold =
1286  for (int i = 0; i < npar; i++) {
1287  double relerr = 0;
1288  if (fabs(cov[i][i]) > 0.)
1289  paramerr[i] = sqrt(fabs(cov[i][i]));
1290  else
1291  paramerr[i] = params[i];
1292  if (params[i] != 0.)
1293  relerr = fabs(paramerr[i] / params[i]);
1294  if ((maxRelErrThreshold >= 0. && relerr > maxRelErrThreshold) || relerr < minRelErrThreshold) {
1295  edm::LogWarning("Alignment") << "@SUB=HIPAlignmentAlgorithm::calcParameters"
1296  << "RelError = " << relerr << " > " << maxRelErrThreshold << " or < "
1297  << minRelErrThreshold << ". Setting param = paramerr = 0 for component " << i;
1298  params[i] = 0;
1299  paramerr[i] = 0;
1300  }
1301  }
1302  } else {
1303  if (params.num_row() != 1) {
1304  edm::LogError("Alignment") << "@SUB=HIPAlignmentAlgorithm::calcParameters"
1305  << "For scanning, please only turn on one parameter! check common_cff_py.txt";
1306  return false;
1307  }
1308  if (theIteration == 1)
1309  params[0] = start;
1310  else
1311  params[0] = step;
1312  edm::LogWarning("Alignment") << "@SUB=HIPAlignmentAlgorithm::calcParameters"
1313  << "Parameters = " << params;
1314  }
1315  }
1316 
1317  uservar->alipar = params;
1318  uservar->alierr = paramerr;
1319 
1320  AlignmentParameters* parnew = par->cloneFromSelected(params, cov);
1321  ali->setAlignmentParameters(parnew);
1322  parnew->setValid(true);
1323 
1324  edm::LogInfo("Alignment") << "@SUB=HIPAlignmentAlgorithm::calcParameters"
1325  << "End: Processing detector " << ali->id();
1326 
1327  return true;
1328 }
align::ID id() const
Return the ID of Alignable, i.e. DetId of &#39;first&#39; component GeomDet(Unit).
Definition: Alignable.h:180
HIPAlignableSpecificParameters defaultAlignableSpecs
virtual AlignmentParameters * cloneFromSelected(const AlgebraicVector &par, const AlgebraicSymMatrix &cov) const =0
HIPAlignableSpecificParameters * findAlignableSpecs(const Alignable *ali)
AlgebraicVector alipar
AlgebraicVector jtve
AlignmentParameters * alignmentParameters() const
Get the AlignmentParameters.
Definition: Alignable.h:58
AlgebraicSymMatrix jtvj
AlignmentUserVariables * userVariables(void) const
Get pointer to user variables.
void setAlignmentParameters(AlignmentParameters *dap)
Set the AlignmentParameters.
Definition: Alignable.cc:123
void setValid(bool v)
Set validity flag.
AlgebraicVector alierr
T sqrt(T t)
Definition: SSEVec.h:19
CLHEP::HepVector AlgebraicVector
CLHEP::HepSymMatrix AlgebraicSymMatrix
step
Definition: StallMonitor.cc:94
void HIPAlignmentAlgorithm::collectMonitorTrees ( const std::vector< std::string > &  filenames)
private

Definition at line 1486 of file HIPAlignmentAlgorithm.cc.

References doTrackHitMonitoring, Exception, corrVsCorr::filename, HIPMonitorConfig::fillTrackHitMonitoring, HIPMonitorConfig::fillTrackMonitoring, isCollector, HIPMonitorConfig::outfile, AlCaHLTBitMon_QueryRunRegistry::string, theHitMonitorTree, theIteration, theMonitorConfig, theTrackHitMonitorIORootFile, and theTrackMonitorTree.

Referenced by collector(), and ~HIPAlignmentAlgorithm().

1486  {
1487  if (!doTrackHitMonitoring)
1488  return;
1489  if (!isCollector)
1490  throw cms::Exception("LogicError") << "[HIPAlignmentAlgorithm::collectMonitorTrees] Called in non-collector mode."
1491  << std::endl;
1492 
1493  TString theTrackMonitorTreeName = Form("T1_%i", theIteration);
1494  TString theHitMonitorTreeName = Form("T1_hit_%i", theIteration);
1495 
1496  std::vector<TFile*> finputlist;
1497  TList* eventtrees = new TList;
1498  TList* hittrees = new TList;
1499  for (std::string const& filename : filenames) {
1500  TFile* finput = TFile::Open(filename.c_str(), "read");
1501  if (finput != nullptr) {
1502  TTree* tmptree;
1504  tmptree = nullptr;
1505  tmptree = (TTree*)finput->Get(theTrackMonitorTreeName);
1506  if (tmptree != nullptr)
1507  eventtrees->Add(tmptree);
1508  }
1510  tmptree = nullptr;
1511  tmptree = (TTree*)finput->Get(theHitMonitorTreeName);
1512  if (tmptree != nullptr)
1513  hittrees->Add((TTree*)finput->Get(theHitMonitorTreeName));
1514  }
1515  finputlist.push_back(finput);
1516  }
1517  }
1518 
1519  if (theTrackHitMonitorIORootFile != nullptr) { // This should never happen
1520  edm::LogError("Alignment") << "@SUB=HIPAlignmentAlgorithm::collectMonitorTrees"
1521  << "Monitor file is already open while it is not supposed to be!";
1522  delete theTrackMonitorTree;
1523  theTrackMonitorTree = nullptr;
1524  delete theHitMonitorTree;
1525  theHitMonitorTree = nullptr;
1527  }
1528  theTrackHitMonitorIORootFile = TFile::Open(theMonitorConfig.outfile.c_str(), "update");
1530  if (eventtrees->GetSize() > 0)
1531  theTrackMonitorTree = TTree::MergeTrees(eventtrees);
1532  if (hittrees->GetSize() > 0)
1533  theHitMonitorTree = TTree::MergeTrees(hittrees);
1534  // Leave it to HIPAlignmentAlgorithm::terminate to write the trees and close theTrackHitMonitorIORootFile
1535 
1536  delete hittrees;
1537  delete eventtrees;
1538  for (TFile*& finput : finputlist)
1539  finput->Close();
1540 
1541  // Rename the trees to standard names
1542  if (theTrackMonitorTree != nullptr)
1543  theTrackMonitorTree->SetName(theTrackMonitorTreeName);
1544  if (theHitMonitorTree != nullptr)
1545  theHitMonitorTree->SetName(theHitMonitorTreeName);
1546 }
const bool fillTrackHitMonitoring
const bool fillTrackMonitoring
HIPMonitorConfig theMonitorConfig
void HIPAlignmentAlgorithm::collector ( void  )
private

Definition at line 1331 of file HIPAlignmentAlgorithm.cc.

References HIPUserVariables::alichi2, HIPUserVariables::alindof, AlignmentParameterStore::attachUserVariables(), HIPUserVariables::clone(), collectMonitorTrees(), HIPUserVariables::datatype, doTrackHitMonitoring, ioerr, HIPUserVariables::jtve, HIPUserVariables::jtvj, HIPUserVariables::nhit, HIPMonitorConfig::outfilecore, HIPUserVariablesIORoot::readHIPUserVariables(), rewgtPerAli, str, AlCaHLTBitMon_QueryRunRegistry::string, suvarfilecore, theAlignables, theAlignmentParameterStore, theCollectorNJobs, theCollectorPath, theDataGroup, theIteration, theMonitorConfig, and AlignmentParameters::userVariables().

Referenced by startNewLoop(), and ~HIPAlignmentAlgorithm().

1331  {
1332  edm::LogInfo("Alignment") << "@SUB=HIPAlignmentAlgorithm::collector"
1333  << "Called for iteration " << theIteration;
1334 
1335  std::vector<std::string> monitorFileList;
1336  HIPUserVariablesIORoot HIPIO;
1337 
1338  typedef int pawt_t;
1339  std::unordered_map<Alignable*, std::unordered_map<int, pawt_t>> ali_datatypecountpair_map;
1340  if (rewgtPerAli) {
1341  edm::LogInfo("Alignment") << "@SUB=HIPAlignmentAlgorithm::collector"
1342  << "Per-alignable reweighting is turned on. Iterating over the parallel jobs to sum "
1343  "number of hits per alignable for each data type.";
1344  // Counting step for per-alignable reweighting
1345  for (int ijob = 1; ijob <= theCollectorNJobs; ijob++) {
1346  edm::LogInfo("Alignment") << "@SUB=HIPAlignmentAlgorithm::collector"
1347  << "Pre-reading uservar for job " << ijob;
1348 
1349  std::string str = std::to_string(ijob);
1350  std::string uvfile = theCollectorPath + "/job" + str + "/" + suvarfilecore;
1351 
1352  std::vector<AlignmentUserVariables*> uvarvec =
1353  HIPIO.readHIPUserVariables(theAlignables, uvfile.c_str(), theIteration, ioerr);
1354  if (uvarvec.size() != theAlignables.size())
1355  edm::LogWarning("Alignment") << "@SUB=HIPAlignmentAlgorithm::collector"
1356  << "Number of alignables = " << theAlignables.size()
1357  << " is not the same as number of user variables = " << uvarvec.size()
1358  << ". A mismatch might occur!";
1359  if (ioerr != 0) {
1360  edm::LogError("Alignment") << "@SUB=HIPAlignmentAlgorithm::collector"
1361  << "Could not read user variable files for job " << ijob << " in iteration "
1362  << theIteration;
1363  continue;
1364  }
1365  std::vector<AlignmentUserVariables*>::const_iterator iuvar =
1366  uvarvec.begin(); // This vector should have 1-to-1 correspondence with the alignables vector
1367  for (const auto& ali : theAlignables) {
1368  // No need for the user variables already attached to the alignables
1369  // Just count from what you read.
1370  HIPUserVariables* uvar = dynamic_cast<HIPUserVariables*>(*iuvar);
1371  if (uvar != nullptr) {
1372  int alijobdtype = uvar->datatype;
1373  pawt_t alijobnhits = uvar->nhit;
1374  if (ali_datatypecountpair_map.find(ali) == ali_datatypecountpair_map.end()) { // This is a new alignable
1375  std::unordered_map<int, pawt_t> newmap;
1376  ali_datatypecountpair_map[ali] = newmap;
1377  ali_datatypecountpair_map[ali][alijobdtype] = alijobnhits;
1378  } else { // Alignable already exists in the map
1379  std::unordered_map<int, pawt_t>& theMap = ali_datatypecountpair_map[ali];
1380  if (theMap.find(alijobdtype) == theMap.end())
1381  theMap[alijobdtype] = alijobnhits;
1382  else
1383  theMap[alijobdtype] += alijobnhits;
1384  }
1385  delete uvar; // Delete new user variables as they are added
1386  }
1387  iuvar++;
1388  } // End loop over alignables
1389  } // End loop over subjobs
1390  }
1391 
1392  for (int ijob = 1; ijob <= theCollectorNJobs; ijob++) {
1393  edm::LogInfo("Alignment") << "@SUB=HIPAlignmentAlgorithm::collector"
1394  << "Reading uservar for job " << ijob;
1395 
1396  std::string str = std::to_string(ijob);
1397  std::string uvfile = theCollectorPath + "/job" + str + "/" + suvarfilecore;
1398 
1399  std::vector<AlignmentUserVariables*> uvarvec =
1400  HIPIO.readHIPUserVariables(theAlignables, uvfile.c_str(), theIteration, ioerr);
1401  if (uvarvec.size() != theAlignables.size())
1402  edm::LogWarning("Alignment") << "@SUB=HIPAlignmentAlgorithm::collector"
1403  << "Number of alignables = " << theAlignables.size()
1404  << " is not the same as number of user variables = " << uvarvec.size()
1405  << ". A mismatch might occur!";
1406 
1407  if (ioerr != 0) {
1408  edm::LogError("Alignment") << "@SUB=HIPAlignmentAlgorithm::collector"
1409  << "Could not read user variable files for job " << ijob << " in iteration "
1410  << theIteration;
1411  continue;
1412  }
1413 
1414  // add
1415  std::vector<AlignmentUserVariables*> uvarvecadd;
1416  std::vector<AlignmentUserVariables*>::const_iterator iuvarnew = uvarvec.begin();
1417  for (const auto& ali : theAlignables) {
1418  AlignmentParameters* ap = ali->alignmentParameters();
1419 
1420  HIPUserVariables* uvarold = dynamic_cast<HIPUserVariables*>(ap->userVariables());
1421  HIPUserVariables* uvarnew = dynamic_cast<HIPUserVariables*>(*iuvarnew);
1422 
1423  HIPUserVariables* uvar = uvarold->clone();
1424  uvar->datatype =
1425  theDataGroup; // Set the data type of alignable to that specified for the collector job (-2 by default)
1426 
1427  if (uvarnew != nullptr) {
1428  double peraliwgt = 1;
1429  if (rewgtPerAli) {
1430  int alijobdtype = uvarnew->datatype;
1431  if (ali_datatypecountpair_map.find(ali) != ali_datatypecountpair_map.end() &&
1432  ali_datatypecountpair_map[ali].find(alijobdtype) != ali_datatypecountpair_map[ali].end()) {
1433  peraliwgt = ali_datatypecountpair_map[ali][alijobdtype];
1434  unsigned int nNonZeroTypes = 0;
1435  pawt_t sumwgts = 0;
1436  for (auto it = ali_datatypecountpair_map[ali].cbegin(); it != ali_datatypecountpair_map[ali].cend(); ++it) {
1437  sumwgts += it->second;
1438  if (it->second != pawt_t(0))
1439  nNonZeroTypes++;
1440  }
1441  edm::LogInfo("Alignment") << "@SUB=HIPAlignmentAlgorithm::collector"
1442  << "Reweighting detector " << ali->id() << " / " << ali->alignableObjectId()
1443  << " for data type " << alijobdtype << " by " << sumwgts << "/" << peraliwgt
1444  << "/" << nNonZeroTypes;
1445  peraliwgt = ((nNonZeroTypes == 0 || peraliwgt == double(0))
1446  ? double(1)
1447  : double((double(sumwgts)) / peraliwgt / (double(nNonZeroTypes))));
1448  } else if (ali_datatypecountpair_map.find(ali) != ali_datatypecountpair_map.end())
1449  edm::LogError("Alignment") << "@SUB=HIPAlignmentAlgorithm::collector"
1450  << "Could not find data type " << alijobdtype << " for detector " << ali->id()
1451  << " / " << ali->alignableObjectId();
1452  else
1453  edm::LogError("Alignment") << "@SUB=HIPAlignmentAlgorithm::collector"
1454  << "Could not find detector " << ali->id() << " / " << ali->alignableObjectId()
1455  << " in the map ali_datatypecountpair_map";
1456  }
1457 
1458  uvar->nhit = (uvarold->nhit) + (uvarnew->nhit);
1459  uvar->jtvj = (uvarold->jtvj) + peraliwgt * (uvarnew->jtvj);
1460  uvar->jtve = (uvarold->jtve) + peraliwgt * (uvarnew->jtve);
1461  uvar->alichi2 = (uvarold->alichi2) + peraliwgt * (uvarnew->alichi2);
1462  uvar->alindof = (uvarold->alindof) + (uvarnew->alindof);
1463 
1464  delete uvarnew; // Delete new user variables as they are added
1465  }
1466 
1467  uvarvecadd.push_back(uvar);
1468  iuvarnew++;
1469  }
1470 
1471  theAlignmentParameterStore->attachUserVariables(theAlignables, uvarvecadd, ioerr);
1472 
1473  // fill Eventwise Tree
1474  if (doTrackHitMonitoring) {
1475  uvfile = theCollectorPath + "/job" + str + "/" + theMonitorConfig.outfilecore;
1476  monitorFileList.push_back(uvfile);
1477  }
1478  } // end loop on jobs
1479 
1480  // Collect monitor (eventwise and hitwise) trees
1482  collectMonitorTrees(monitorFileList);
1483 }
void attachUserVariables(const align::Alignables &alivec, const std::vector< AlignmentUserVariables * > &uvarvec, int &ierr)
Attach User Variables to given alignables.
AlignmentParameterStore * theAlignmentParameterStore
HIPUserVariables * clone(void) const override
AlgebraicVector jtve
AlgebraicSymMatrix jtvj
AlignmentUserVariables * userVariables(void) const
Get pointer to user variables.
std::vector< AlignmentUserVariables * > readHIPUserVariables(const Alignables &alivec, const char *filename, int iter, int &ierr)
void collectMonitorTrees(const std::vector< std::string > &filenames)
const std::string outfilecore
align::Alignables theAlignables
HIPMonitorConfig theMonitorConfig
#define str(s)
void HIPAlignmentAlgorithm::fillAlignablesMonitor ( const edm::EventSetup setup)
private

Definition at line 1154 of file HIPAlignmentAlgorithm.cc.

References HIPUserVariables::datatype, runTauDisplay::dtype, alignBH_cfg::fixed, edm::EventSetup::get(), AlignmentParameters::isValid(), SurfaceDeformationFactory::kNoDeformations, m2_datatype, m2_dtype, m2_Id, m2_Layer, m2_Nhit, m2_nsurfdef, m2_ObjId, m2_surfDef, m2_Type, m2_Xpos, m2_Ypos, m2_Zpos, HIPUserVariables::nhit, SurfaceDeformation::parameters(), AlignmentParameters::parameters(), edm::ESHandle< T >::product(), theAlignables, theAlignablesMonitorIORootFile, theAlignablesMonitorTree, theAlignmentParameterStore, SurfaceDeformation::type(), AlignmentParameterStore::typeAndLayer(), AlignmentParameters::userVariables(), PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().

Referenced by terminate(), and ~HIPAlignmentAlgorithm().

1154  {
1155  if (theAlignablesMonitorIORootFile == (TFile*)nullptr)
1156  return;
1157  using std::setw;
1159 
1160  int naligned = 0;
1161 
1162  //Retrieve tracker topology from geometry
1163  edm::ESHandle<TrackerTopology> tTopoHandle;
1164  // iSetup.get<IdealGeometryRecord>().get(tTopoHandle);
1165  iSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
1166 
1167  const TrackerTopology* const tTopo = tTopoHandle.product();
1168 
1169  for (const auto& ali : theAlignables) {
1170  AlignmentParameters* dap = ali->alignmentParameters();
1171 
1172  // consider only those parameters classified as 'valid'
1173  if (dap->isValid()) {
1174  // get number of hits from user variable
1175  HIPUserVariables* uservar = dynamic_cast<HIPUserVariables*>(dap->userVariables());
1176  m2_Nhit = uservar->nhit;
1177  m2_datatype = uservar->datatype;
1178 
1179  // get type/layer
1180  std::pair<int, int> tl = theAlignmentParameterStore->typeAndLayer(ali, tTopo);
1181  m2_Type = tl.first;
1182  m2_Layer = tl.second;
1183 
1184  // get identifier (as for IO)
1185  m2_Id = ali->id();
1186  m2_ObjId = ali->alignableObjectId();
1187 
1188  // get position
1189  GlobalPoint pos = ali->surface().position();
1190  m2_Xpos = pos.x();
1191  m2_Ypos = pos.y();
1192  m2_Zpos = pos.z();
1193 
1194  m2_surfDef.clear();
1195  {
1196  std::vector<std::pair<int, SurfaceDeformation*>> dali_id_pairs;
1197  SurfaceDeformation* dali_obj = nullptr;
1199  std::vector<double> dali;
1200  if (1 == ali->surfaceDeformationIdPairs(dali_id_pairs)) {
1201  dali_obj = dali_id_pairs[0].second;
1202  dali = dali_obj->parameters();
1203  dtype = (SurfaceDeformationFactory::Type)dali_obj->type();
1204  }
1205  for (auto& dit : dali)
1206  m2_surfDef.push_back((float)dit);
1207  m2_dtype = dtype;
1208  m2_nsurfdef = m2_surfDef.size();
1209  }
1210 
1211  if (verbose) {
1212  AlgebraicVector pars = dap->parameters();
1213  edm::LogVerbatim("Alignment") << "------------------------------------------------------------------------\n"
1214  << " ALIGNABLE: " << setw(6) << naligned << '\n'
1215  << "hits: " << setw(4) << m2_Nhit << " type: " << setw(4) << m2_Type
1216  << " layer: " << setw(4) << m2_Layer << " id: " << setw(4) << m2_Id
1217  << " objId: " << setw(4) << m2_ObjId << '\n'
1218  << std::fixed << std::setprecision(5) << "x,y,z: " << setw(12) << m2_Xpos
1219  << setw(12) << m2_Ypos << setw(12) << m2_Zpos
1220  << "\nDeformations type, nDeformations: " << setw(12) << m2_dtype << setw(12)
1221  << m2_nsurfdef << '\n'
1222  << "params: " << setw(12) << pars[0] << setw(12) << pars[1] << setw(12) << pars[2]
1223  << setw(12) << pars[3] << setw(12) << pars[4] << setw(12) << pars[5];
1224  }
1225 
1226  naligned++;
1227  if (theAlignablesMonitorTree != nullptr)
1228  theAlignablesMonitorTree->Fill();
1229  }
1230  }
1231 }
AlignmentParameterStore * theAlignmentParameterStore
std::pair< int, int > typeAndLayer(const Alignable *ali, const TrackerTopology *tTopo) const
Obtain type and layer from Alignable.
virtual std::vector< double > parameters() const =0
parameters - interpretation left to the concrete implementation
align::StructureType m2_ObjId
T y() const
Definition: PV3DBase.h:60
virtual int type() const =0
specific type, i.e. SurfaceDeformationFactory::Type
const AlgebraicVector & parameters(void) const
Get alignment parameters.
AlignmentUserVariables * userVariables(void) const
Get pointer to user variables.
T z() const
Definition: PV3DBase.h:61
CLHEP::HepVector AlgebraicVector
align::Alignables theAlignables
std::vector< float > m2_surfDef
bool isValid(void) const
Get validity flag.
T x() const
Definition: PV3DBase.h:59
T const * product() const
Definition: ESHandle.h:86
SurfaceDeformationFactory::Type m2_dtype
HIPAlignableSpecificParameters * HIPAlignmentAlgorithm::findAlignableSpecs ( const Alignable ali)
private

Definition at line 1549 of file HIPAlignmentAlgorithm.cc.

References Alignable::alignableObjectId(), defaultAlignableSpecs, Alignable::id(), and theAlignableSpecifics.

Referenced by calcParameters(), run(), and ~HIPAlignmentAlgorithm().

1549  {
1550  if (ali != nullptr) {
1551  for (std::vector<HIPAlignableSpecificParameters>::iterator it = theAlignableSpecifics.begin();
1552  it != theAlignableSpecifics.end();
1553  it++) {
1554  if (it->matchAlignable(ali))
1555  return &(*it);
1556  }
1557  edm::LogInfo("Alignment") << "[HIPAlignmentAlgorithm::findAlignableSpecs] Alignment object with id " << ali->id()
1558  << " / " << ali->alignableObjectId() << " could not be found. Returning default.";
1559  }
1560  return &defaultAlignableSpecs;
1561 }
align::ID id() const
Return the ID of Alignable, i.e. DetId of &#39;first&#39; component GeomDet(Unit).
Definition: Alignable.h:180
std::vector< HIPAlignableSpecificParameters > theAlignableSpecifics
HIPAlignableSpecificParameters defaultAlignableSpecs
virtual StructureType alignableObjectId() const =0
Return the alignable type identifier.
void HIPAlignmentAlgorithm::initialize ( const edm::EventSetup setup,
AlignableTracker tracker,
AlignableMuon muon,
AlignableExtras extras,
AlignmentParameterStore store 
)
overridevirtual

Call at beginning of job.

Implements AlignmentAlgorithmBase.

Definition at line 127 of file HIPAlignmentAlgorithm.cc.

References AlignmentParameterSelector::addSelections(), alignableObjectId_, AlignmentParameterStore::alignables(), ALCARECOPromptCalibProdSiPixelAli0T_cff::alignParams, HIPAlignableSpecificParameters::applyPixelProbCut, AlignmentParameterSelector::clear(), AlignableObjectId::commonObjectIdProvider(), edm::IOVSyncValue::eventID(), Exception, edm::ValidityInterval::first(), writedatasetfile::firstrun, edm::EventSetup::get(), edm::ParameterSet::getParameter(), mps_fire::i, HIPAlignableSpecificParameters::id(), isCollector, personalPlayback::level, HIPAlignableSpecificParameters::maxHitPull, HIPAlignableSpecificParameters::maxPixelProbQ, HIPAlignableSpecificParameters::maxPixelProbXY, HIPAlignableSpecificParameters::maxRelParError, FastTrackerRecHitCombiner_cfi::minNHits, HIPAlignableSpecificParameters::minNHits, HIPAlignableSpecificParameters::minPixelProbQ, HIPAlignableSpecificParameters::minPixelProbXY, HIPAlignableSpecificParameters::minRelParError, HLT_2018_cff::muon, HIPAlignableSpecificParameters::objId(), outfile2, edm::EventID::run(), salignedfile, AlignmentParameterSelector::selectedAlignables(), siterationfile, ssurveyfile, AlCaHLTBitMon_QueryRunRegistry::string, surveyResiduals_, suvarfile, theAlignableDetAccessor, theAlignables, theAlignableSpecifics, theAlignmentParameterStore, theAPEParameters, theAPEParameterSet, theApplyAPE, theApplyCutsPerComponent, theCutsPerComponent, theIOVrangeSet, theLevels, themultiIOV, PbPb_ZMuSkimMuonDPG_cff::tracker, and HIPAlignableSpecificParameters::usePixelProbXYOrProbQ.

Referenced by ~HIPAlignmentAlgorithm().

131  {
132  edm::LogInfo("Alignment") << "@SUB=HIPAlignmentAlgorithm::initialize"
133  << "Initializing...";
134 
135  alignableObjectId_ = std::make_unique<AlignableObjectId>(AlignableObjectId::commonObjectIdProvider(tracker, muon));
136 
137  for (const auto& level : surveyResiduals_)
138  theLevels.push_back(alignableObjectId_->stringToId(level));
139 
140  edm::ESHandle<Alignments> globalPositionRcd;
141 
142  const edm::ValidityInterval& validity = setup.get<TrackerAlignmentRcd>().validityInterval();
143  const edm::IOVSyncValue first1 = validity.first();
144  unsigned int firstrun = first1.eventID().run();
145  if (themultiIOV) {
146  if (theIOVrangeSet.size() != 1) {
147  bool findMatchIOV = false;
148  for (unsigned int iovl = 0; iovl < theIOVrangeSet.size(); iovl++) {
149  if (firstrun == theIOVrangeSet.at(iovl)) {
150  std::string iovapp = std::to_string(firstrun);
151  iovapp.append(".root");
152  iovapp.insert(0, "_");
153  salignedfile.replace(salignedfile.end() - 5, salignedfile.end(), iovapp);
154  siterationfile.replace(siterationfile.end() - 5, siterationfile.end(), iovapp);
155  //sparameterfile.replace(sparameterfile.end()-5, sparameterfile.end(),iovapp);
156  if (isCollector) {
157  outfile2.replace(outfile2.end() - 5, outfile2.end(), iovapp);
158  ssurveyfile.replace(ssurveyfile.end() - 5, ssurveyfile.end(), iovapp);
159  suvarfile.replace(suvarfile.end() - 5, suvarfile.end(), iovapp);
160  }
161 
162  edm::LogInfo("Alignment") << "@SUB=HIPAlignmentAlgorithm::initialize"
163  << "Found the IOV file matching IOV first run " << firstrun;
164  findMatchIOV = true;
165  break;
166  }
167  }
168  if (!findMatchIOV)
169  edm::LogError("Alignment") << "@SUB=HIPAlignmentAlgorithm::initialize"
170  << "Didn't find the IOV file matching IOV first run " << firstrun
171  << " from the validity interval";
172  } else {
173  std::string iovapp = std::to_string(theIOVrangeSet.at(0));
174  iovapp.append(".root");
175  iovapp.insert(0, "_");
176  salignedfile.replace(salignedfile.end() - 5, salignedfile.end(), iovapp);
177  siterationfile.replace(siterationfile.end() - 5, siterationfile.end(), iovapp);
178  }
179  }
180 
181  // accessor Det->AlignableDet
182  theAlignableDetAccessor = std::make_unique<AlignableNavigator>(extras, tracker, muon);
183  if (extras != nullptr)
184  edm::LogInfo("Alignment") << "@SUB=HIPAlignmentAlgorithm::initialize"
185  << "AlignableNavigator initialized with AlignableExtras";
186 
187  // set alignmentParameterStore
189 
190  // get alignables
192 
193  // Config flags that specify different detectors
194  {
195  AlignmentParameterSelector selector(tracker, muon, extras);
196 
197  // APE parameters, clear if necessary
198  theAPEParameters.clear();
199  if (theApplyAPE) {
200  for (std::vector<edm::ParameterSet>::const_iterator setiter = theAPEParameterSet.begin();
201  setiter != theAPEParameterSet.end();
202  ++setiter) {
203  align::Alignables alignables;
204 
205  selector.clear();
206  edm::ParameterSet selectorPSet = setiter->getParameter<edm::ParameterSet>("Selector");
207  std::vector<std::string> alignParams = selectorPSet.getParameter<std::vector<std::string>>("alignParams");
208  if (alignParams.size() == 1 && alignParams[0] == std::string("selected"))
209  alignables = theAlignables;
210  else {
211  selector.addSelections(selectorPSet);
212  alignables = selector.selectedAlignables();
213  }
214 
215  std::vector<double> apeSPar = setiter->getParameter<std::vector<double>>("apeSPar");
216  std::vector<double> apeRPar = setiter->getParameter<std::vector<double>>("apeRPar");
217  std::string function = setiter->getParameter<std::string>("function");
218 
219  if (apeSPar.size() != 3 || apeRPar.size() != 3)
220  throw cms::Exception("BadConfig") << "apeSPar and apeRPar must have 3 values each" << std::endl;
221 
222  for (std::vector<double>::const_iterator i = apeRPar.begin(); i != apeRPar.end(); ++i)
223  apeSPar.push_back(*i);
224 
225  if (function == std::string("linear"))
226  apeSPar.push_back(0); // c.f. note in calcAPE
227  else if (function == std::string("exponential"))
228  apeSPar.push_back(1); // c.f. note in calcAPE
229  else if (function == std::string("step"))
230  apeSPar.push_back(2); // c.f. note in calcAPE
231  else
232  throw cms::Exception("BadConfig")
233  << "APE function must be \"linear\", \"exponential\", or \"step\"." << std::endl;
234 
235  theAPEParameters.push_back(std::make_pair(alignables, apeSPar));
236  }
237  }
238 
239  // Relative error per component instead of overall relative error
240  theAlignableSpecifics.clear();
242  for (std::vector<edm::ParameterSet>::const_iterator setiter = theCutsPerComponent.begin();
243  setiter != theCutsPerComponent.end();
244  ++setiter) {
245  align::Alignables alignables;
246 
247  selector.clear();
248  edm::ParameterSet selectorPSet = setiter->getParameter<edm::ParameterSet>("Selector");
249  std::vector<std::string> alignParams = selectorPSet.getParameter<std::vector<std::string>>("alignParams");
250  if (alignParams.size() == 1 && alignParams[0] == std::string("selected"))
251  alignables = theAlignables;
252  else {
253  selector.addSelections(selectorPSet);
254  alignables = selector.selectedAlignables();
255  }
256 
257  double minRelParError = setiter->getParameter<double>("minRelParError");
258  double maxRelParError = setiter->getParameter<double>("maxRelParError");
259  int minNHits = setiter->getParameter<int>("minNHits");
260  double maxHitPull = setiter->getParameter<double>("maxHitPull");
261  bool applyPixelProbCut = setiter->getParameter<bool>("applyPixelProbCut");
262  bool usePixelProbXYOrProbQ = setiter->getParameter<bool>("usePixelProbXYOrProbQ");
263  double minPixelProbXY = setiter->getParameter<double>("minPixelProbXY");
264  double maxPixelProbXY = setiter->getParameter<double>("maxPixelProbXY");
265  double minPixelProbQ = setiter->getParameter<double>("minPixelProbQ");
266  double maxPixelProbQ = setiter->getParameter<double>("maxPixelProbQ");
267  for (auto& ali : alignables) {
268  HIPAlignableSpecificParameters alispecs(ali);
269  alispecs.minRelParError = minRelParError;
270  alispecs.maxRelParError = maxRelParError;
271  alispecs.minNHits = minNHits;
272  alispecs.maxHitPull = maxHitPull;
273 
274  alispecs.applyPixelProbCut = applyPixelProbCut;
275  alispecs.usePixelProbXYOrProbQ = usePixelProbXYOrProbQ;
276  alispecs.minPixelProbXY = minPixelProbXY;
277  alispecs.maxPixelProbXY = maxPixelProbXY;
278  alispecs.minPixelProbQ = minPixelProbQ;
279  alispecs.maxPixelProbQ = maxPixelProbQ;
280 
281  theAlignableSpecifics.push_back(alispecs);
282  edm::LogInfo("Alignment") << "@SUB=HIPAlignmentAlgorithm::initialize"
283  << "Alignment specifics acquired for detector " << alispecs.id() << " / "
284  << alispecs.objId() << ":\n"
285  << " - minRelParError = " << alispecs.minRelParError << "\n"
286  << " - maxRelParError = " << alispecs.maxRelParError << "\n"
287  << " - minNHits = " << alispecs.minNHits << "\n"
288  << " - maxHitPull = " << alispecs.maxHitPull << "\n"
289  << " - applyPixelProbCut = " << alispecs.applyPixelProbCut << "\n"
290  << " - usePixelProbXYOrProbQ = " << alispecs.usePixelProbXYOrProbQ << "\n"
291  << " - minPixelProbXY = " << alispecs.minPixelProbXY << "\n"
292  << " - maxPixelProbXY = " << alispecs.maxPixelProbXY << "\n"
293  << " - minPixelProbQ = " << alispecs.minPixelProbQ << "\n"
294  << " - maxPixelProbQ = " << alispecs.maxPixelProbQ;
295  }
296  }
297  }
298  }
299 }
RunNumber_t run() const
Definition: EventID.h:38
T getParameter(std::string const &) const
std::vector< HIPAlignableSpecificParameters > theAlignableSpecifics
AlignmentParameterStore * theAlignmentParameterStore
const EventID & eventID() const
Definition: IOVSyncValue.h:40
static AlignableObjectId commonObjectIdProvider(const AlignableObjectId &, const AlignableObjectId &)
std::unique_ptr< AlignableNavigator > theAlignableDetAccessor
std::vector< unsigned > theIOVrangeSet
std::vector< edm::ParameterSet > theCutsPerComponent
std::unique_ptr< AlignableObjectId > alignableObjectId_
std::vector< edm::ParameterSet > theAPEParameterSet
std::vector< Alignable * > Alignables
Definition: Utilities.h:31
align::Alignables theAlignables
T get() const
Definition: EventSetup.h:73
const std::vector< std::string > surveyResiduals_
const IOVSyncValue & first() const
std::vector< std::pair< align::Alignables, std::vector< double > > > theAPEParameters
std::vector< align::StructureType > theLevels
const align::Alignables & alignables(void) const
get all alignables
bool HIPAlignmentAlgorithm::processHit1D ( const AlignableDetOrUnitPtr alidet,
const Alignable ali,
const HIPAlignableSpecificParameters alispecifics,
const TrajectoryStateOnSurface tsos,
const TrackingRecHit hit,
double  hitwt 
)
private

Definition at line 519 of file HIPAlignmentAlgorithm.cc.

References HIPUserVariables::alichi2, Alignable::alignmentParameters(), HIPUserVariables::alindof, HIPUserVariables::datatype, defaultAlignableSpecs, HIPUserVariables::jtve, HIPUserVariables::jtvj, TrajectoryStateOnSurface::localError(), TrajectoryStateOnSurface::localPosition(), TrackingRecHit::localPosition(), TrackingRecHit::localPositionError(), HIPAlignableSpecificParameters::maxHitPull, HIPUserVariables::nhit, CalibrationSummaryClient_cfi::params, LocalTrajectoryError::positionError(), AlignmentParameters::selectedDerivatives(), mathSSE::sqrt(), theApplyCutsPerComponent, theDataGroup, AlignmentParameters::userVariables(), PV3DBase< T, PVType, FrameType >::x(), and LocalError::xx().

Referenced by run(), and ~HIPAlignmentAlgorithm().

524  {
525  static const unsigned int hitDim = 1;
526  if (hitwt == 0.)
527  return false;
528 
529  // get trajectory impact point
530  LocalPoint alvec = tsos.localPosition();
531  AlgebraicVector pos(hitDim);
532  pos[0] = alvec.x();
533 
534  // get impact point covariance
535  AlgebraicSymMatrix ipcovmat(hitDim);
536  ipcovmat[0][0] = tsos.localError().positionError().xx();
537 
538  // get hit local position and covariance
539  AlgebraicVector coor(hitDim);
540  coor[0] = hit->localPosition().x();
541 
542  AlgebraicSymMatrix covmat(hitDim);
543  covmat[0][0] = hit->localPositionError().xx();
544 
545  // add hit and impact point covariance matrices
546  covmat = covmat + ipcovmat;
547 
548  // calculate the x pull of this hit
549  double xpull = 0.;
550  if (covmat[0][0] != 0.)
551  xpull = (pos[0] - coor[0]) / sqrt(fabs(covmat[0][0]));
552 
553  // get Alignment Parameters
555  HIPUserVariables* uservar = dynamic_cast<HIPUserVariables*>(params->userVariables());
556  uservar->datatype = theDataGroup;
557  // get derivatives
558  AlgebraicMatrix derivs2D = params->selectedDerivatives(tsos, alidet);
559  // calculate user parameters
560  int npar = derivs2D.num_row();
561  AlgebraicMatrix derivs(npar, hitDim, 0); // This is jT
562 
563  for (int ipar = 0; ipar < npar; ipar++) {
564  for (unsigned int idim = 0; idim < hitDim; idim++) {
565  derivs[ipar][idim] = derivs2D[ipar][idim];
566  }
567  }
568 
569  // invert covariance matrix
570  int ierr;
571  covmat.invert(ierr);
572  if (ierr != 0) {
573  edm::LogError("Alignment") << "@SUB=HIPAlignmentAlgorithm::processHit1D"
574  << "Cov. matrix inversion failed!";
575  return false;
576  }
577 
578  double maxHitPullThreshold =
580  bool useThisHit = (maxHitPullThreshold < 0.);
581  useThisHit |= (fabs(xpull) < maxHitPullThreshold);
582  if (!useThisHit) {
583  edm::LogInfo("Alignment") << "@SUB=HIPAlignmentAlgorithm::processHit2D"
584  << "Hit pull (x) " << xpull << " fails the cut " << maxHitPullThreshold;
585  return false;
586  }
587 
588  AlgebraicMatrix covtmp(covmat);
589  AlgebraicMatrix jtvjtmp(derivs * covtmp * derivs.T());
590  AlgebraicSymMatrix thisjtvj(npar);
591  AlgebraicVector thisjtve(npar);
592  thisjtvj.assign(jtvjtmp);
593  thisjtve = derivs * covmat * (pos - coor);
594 
595  AlgebraicVector hitresidual(hitDim);
596  hitresidual[0] = (pos[0] - coor[0]);
597 
598  AlgebraicMatrix hitresidualT;
599  hitresidualT = hitresidual.T();
600 
601  uservar->jtvj += hitwt * thisjtvj;
602  uservar->jtve += hitwt * thisjtve;
603  uservar->nhit++;
604 
605  //for alignable chi squared
606  float thischi2;
607  thischi2 = hitwt * (hitresidualT * covmat * hitresidual)[0];
608 
609  if (verbose && (thischi2 / static_cast<float>(uservar->nhit)) > 10.)
610  edm::LogWarning("Alignment") << "[HIPAlignmentAlgorithm::processHit1D] Added to Chi2 the number " << thischi2
611  << " having " << uservar->nhit << " ndof"
612  << ", X-resid " << hitresidual[0] << ", Cov^-1 matr (covmat):"
613  << " [0][0] = " << covmat[0][0];
614 
615  uservar->alichi2 += thischi2;
616  uservar->alindof += hitDim;
617 
618  return true;
619 }
float xx() const
Definition: LocalError.h:22
HIPAlignableSpecificParameters defaultAlignableSpecs
AlgebraicVector jtve
LocalError positionError() const
AlignmentParameters * alignmentParameters() const
Get the AlignmentParameters.
Definition: Alignable.h:58
AlgebraicSymMatrix jtvj
AlignmentUserVariables * userVariables(void) const
Get pointer to user variables.
CLHEP::HepMatrix AlgebraicMatrix
T sqrt(T t)
Definition: SSEVec.h:19
const LocalTrajectoryError & localError() const
virtual LocalPoint localPosition() const =0
CLHEP::HepVector AlgebraicVector
CLHEP::HepSymMatrix AlgebraicSymMatrix
virtual LocalError localPositionError() const =0
T x() const
Definition: PV3DBase.h:59
virtual AlgebraicMatrix selectedDerivatives(const TrajectoryStateOnSurface &tsos, const AlignableDetOrUnitPtr &alidet) const
bool HIPAlignmentAlgorithm::processHit2D ( const AlignableDetOrUnitPtr alidet,
const Alignable ali,
const HIPAlignableSpecificParameters alispecifics,
const TrajectoryStateOnSurface tsos,
const TrackingRecHit hit,
double  hitwt 
)
private

Definition at line 621 of file HIPAlignmentAlgorithm.cc.

References HIPUserVariables::alichi2, Alignable::alignmentParameters(), HIPUserVariables::alindof, HIPUserVariables::datatype, defaultAlignableSpecs, HIPUserVariables::jtve, HIPUserVariables::jtvj, TrajectoryStateOnSurface::localError(), TrajectoryStateOnSurface::localPosition(), TrackingRecHit::localPosition(), TrackingRecHit::localPositionError(), HIPAlignableSpecificParameters::maxHitPull, HIPUserVariables::nhit, CalibrationSummaryClient_cfi::params, LocalTrajectoryError::positionError(), AlignmentParameters::selectedDerivatives(), mathSSE::sqrt(), theApplyCutsPerComponent, theDataGroup, AlignmentParameters::userVariables(), PV3DBase< T, PVType, FrameType >::x(), LocalError::xx(), LocalError::xy(), PV3DBase< T, PVType, FrameType >::y(), and LocalError::yy().

Referenced by run(), and ~HIPAlignmentAlgorithm().

626  {
627  static const unsigned int hitDim = 2;
628  if (hitwt == 0.)
629  return false;
630 
631  // get trajectory impact point
632  LocalPoint alvec = tsos.localPosition();
633  AlgebraicVector pos(hitDim);
634  pos[0] = alvec.x();
635  pos[1] = alvec.y();
636 
637  // get impact point covariance
638  AlgebraicSymMatrix ipcovmat(hitDim);
639  ipcovmat[0][0] = tsos.localError().positionError().xx();
640  ipcovmat[1][1] = tsos.localError().positionError().yy();
641  ipcovmat[0][1] = tsos.localError().positionError().xy();
642 
643  // get hit local position and covariance
644  AlgebraicVector coor(hitDim);
645  coor[0] = hit->localPosition().x();
646  coor[1] = hit->localPosition().y();
647 
648  AlgebraicSymMatrix covmat(hitDim);
649  covmat[0][0] = hit->localPositionError().xx();
650  covmat[1][1] = hit->localPositionError().yy();
651  covmat[0][1] = hit->localPositionError().xy();
652 
653  // add hit and impact point covariance matrices
654  covmat = covmat + ipcovmat;
655 
656  // calculate the x pull and y pull of this hit
657  double xpull = 0.;
658  double ypull = 0.;
659  if (covmat[0][0] != 0.)
660  xpull = (pos[0] - coor[0]) / sqrt(fabs(covmat[0][0]));
661  if (covmat[1][1] != 0.)
662  ypull = (pos[1] - coor[1]) / sqrt(fabs(covmat[1][1]));
663 
664  // get Alignment Parameters
666  HIPUserVariables* uservar = dynamic_cast<HIPUserVariables*>(params->userVariables());
667  uservar->datatype = theDataGroup;
668  // get derivatives
669  AlgebraicMatrix derivs2D = params->selectedDerivatives(tsos, alidet);
670  // calculate user parameters
671  int npar = derivs2D.num_row();
672  AlgebraicMatrix derivs(npar, hitDim, 0); // This is jT
673 
674  for (int ipar = 0; ipar < npar; ipar++) {
675  for (unsigned int idim = 0; idim < hitDim; idim++) {
676  derivs[ipar][idim] = derivs2D[ipar][idim];
677  }
678  }
679 
680  // invert covariance matrix
681  int ierr;
682  covmat.invert(ierr);
683  if (ierr != 0) {
684  edm::LogError("Alignment") << "@SUB=HIPAlignmentAlgorithm::processHit2D"
685  << "Cov. matrix inversion failed!";
686  return false;
687  }
688 
689  double maxHitPullThreshold =
691  bool useThisHit = (maxHitPullThreshold < 0.);
692  useThisHit |= (fabs(xpull) < maxHitPullThreshold && fabs(ypull) < maxHitPullThreshold);
693  if (!useThisHit) {
694  edm::LogInfo("Alignment") << "@SUB=HIPAlignmentAlgorithm::processHit2D"
695  << "Hit pull (x,y) " << xpull << " , " << ypull << " fails the cut "
696  << maxHitPullThreshold;
697  return false;
698  }
699 
700  AlgebraicMatrix covtmp(covmat);
701  AlgebraicMatrix jtvjtmp(derivs * covtmp * derivs.T());
702  AlgebraicSymMatrix thisjtvj(npar);
703  AlgebraicVector thisjtve(npar);
704  thisjtvj.assign(jtvjtmp);
705  thisjtve = derivs * covmat * (pos - coor);
706 
707  AlgebraicVector hitresidual(hitDim);
708  hitresidual[0] = (pos[0] - coor[0]);
709  hitresidual[1] = (pos[1] - coor[1]);
710 
711  AlgebraicMatrix hitresidualT;
712  hitresidualT = hitresidual.T();
713 
714  uservar->jtvj += hitwt * thisjtvj;
715  uservar->jtve += hitwt * thisjtve;
716  uservar->nhit++;
717 
718  //for alignable chi squared
719  float thischi2;
720  thischi2 = hitwt * (hitresidualT * covmat * hitresidual)[0];
721 
722  if (verbose && (thischi2 / static_cast<float>(uservar->nhit)) > 10.)
723  edm::LogWarning("Alignment") << "[HIPAlignmentAlgorithm::processHit2D] Added to Chi2 the number " << thischi2
724  << " having " << uservar->nhit << " ndof"
725  << ", X-resid " << hitresidual[0] << ", Y-resid " << hitresidual[1]
726  << ", Cov^-1 matr (covmat):"
727  << " [0][0] = " << covmat[0][0] << " [0][1] = " << covmat[0][1]
728  << " [1][0] = " << covmat[1][0] << " [1][1] = " << covmat[1][1];
729 
730  uservar->alichi2 += thischi2;
731  uservar->alindof += hitDim;
732 
733  return true;
734 }
float xx() const
Definition: LocalError.h:22
HIPAlignableSpecificParameters defaultAlignableSpecs
T y() const
Definition: PV3DBase.h:60
AlgebraicVector jtve
LocalError positionError() const
AlignmentParameters * alignmentParameters() const
Get the AlignmentParameters.
Definition: Alignable.h:58
AlgebraicSymMatrix jtvj
AlignmentUserVariables * userVariables(void) const
Get pointer to user variables.
float xy() const
Definition: LocalError.h:23
CLHEP::HepMatrix AlgebraicMatrix
float yy() const
Definition: LocalError.h:24
T sqrt(T t)
Definition: SSEVec.h:19
const LocalTrajectoryError & localError() const
virtual LocalPoint localPosition() const =0
CLHEP::HepVector AlgebraicVector
CLHEP::HepSymMatrix AlgebraicSymMatrix
virtual LocalError localPositionError() const =0
T x() const
Definition: PV3DBase.h:59
virtual AlgebraicMatrix selectedDerivatives(const TrajectoryStateOnSurface &tsos, const AlignableDetOrUnitPtr &alidet) const
int HIPAlignmentAlgorithm::readIterationFile ( std::string  filename)
private

Definition at line 992 of file HIPAlignmentAlgorithm.cc.

References recoMuon::in, and mps_fire::result.

Referenced by startNewLoop(), and ~HIPAlignmentAlgorithm().

992  {
993  int result;
994 
995  std::ifstream inIterFile(filename.c_str(), std::ios::in);
996  if (!inIterFile) {
997  edm::LogError("Alignment") << "[HIPAlignmentAlgorithm::readIterationFile] ERROR! "
998  << "Unable to open Iteration file";
999  result = -1;
1000  } else {
1001  inIterFile >> result;
1002  edm::LogWarning("Alignment") << "[HIPAlignmentAlgorithm::readIterationFile] "
1003  << "Read last iteration number from file: " << result;
1004  }
1005  inIterFile.close();
1006 
1007  return result;
1008 }
void HIPAlignmentAlgorithm::run ( const edm::EventSetup setup,
const EventInfo eventInfo 
)
overridevirtual

Run the algorithm.

Implements AlignmentAlgorithmBase.

Definition at line 737 of file HIPAlignmentAlgorithm.cc.

References Abs(), CompositeAlignmentParameters::alignableFromAlignableDet(), angle(), HIPAlignableSpecificParameters::applyPixelProbCut, TrajectoryMeasurement::backwardPredictedState(), HIPMonitorConfig::checkNevents(), HIPMonitorConfig::checkNhits(), chi2n, className(), SiStripRecHit1D::cluster(), SiStripRecHit2D::cluster(), SiPixelRecHit::cluster(), AlignmentAlgorithmBase::EventInfo::clusterValueMap(), col_cut, TrajectoryStateCombiner::combine(), cos_cut, HLTMuonOfflineAnalyzer_cfi::d0, reco::TrackBase::d0(), PVValHelper::dz, reco::TrackBase::dz(), PVValHelper::eta, reco::TrackBase::eta(), HIPTrackMonitorVariables::fill(), HIPHitMonitorVariables::fill(), HIPMonitorConfig::fillTrackHitMonitoring, HIPMonitorConfig::fillTrackMonitoring, findAlignableSpecs(), TrajectoryMeasurement::forwardPredictedState(), TrackingRecHit::geographicalId(), SiPixelRecHit::hasFilledProb(), TrackingRecHit::hit(), HIPMonitorConfig::hitmonitorvars, reco::TrackBase::hitPattern(), Alignable::id(), isCollector, IsCollision, AlignmentClusterFlag::isTaken(), TrajectoryStateOnSurface::isValid(), TrackingRecHit::isValid(), TrajectoryStateOnSurface::localDirection(), HIPHitMonitorVariables::m_angle, HIPTrackMonitorVariables::m_Chi2n, HIPTrackMonitorVariables::m_d0, m_datatype, HIPHitMonitorVariables::m_detId, HIPTrackMonitorVariables::m_dz, HIPTrackMonitorVariables::m_Eta, HIPHitMonitorVariables::m_hasHitProb, HIPHitMonitorVariables::m_hitwt, HIPTrackMonitorVariables::m_Nhits, HIPTrackMonitorVariables::m_nhPXB, HIPTrackMonitorVariables::m_nhPXF, HIPTrackMonitorVariables::m_nhTEC, HIPTrackMonitorVariables::m_nhTIB, HIPTrackMonitorVariables::m_nhTID, HIPTrackMonitorVariables::m_nhTOB, HIPTrackMonitorVariables::m_P, HIPTrackMonitorVariables::m_Phi, HIPHitMonitorVariables::m_probQ, HIPHitMonitorVariables::m_probXY, HIPTrackMonitorVariables::m_Pt, HIPHitMonitorVariables::m_rawQualityWord, HIPHitMonitorVariables::m_sinTheta, HIPTrackMonitorVariables::m_wt, HIPAlignableSpecificParameters::maxPixelProbQ, HIPAlignableSpecificParameters::maxPixelProbXY, Trajectory::measurements(), HIPAlignableSpecificParameters::minPixelProbQ, HIPAlignableSpecificParameters::minPixelProbXY, reco::TrackBase::normalizedChi2(), reco::TrackBase::numberOfValidHits(), reco::HitPattern::numberOfValidPixelBarrelHits(), reco::HitPattern::numberOfValidPixelEndcapHits(), reco::HitPattern::numberOfValidStripTECHits(), reco::HitPattern::numberOfValidStripTIBHits(), reco::HitPattern::numberOfValidStripTIDHits(), reco::HitPattern::numberOfValidStripTOBHits(), AlCaHLTBitMon_ParallelJobs::p, reco::TrackBase::p(), phi, reco::TrackBase::phi(), pixelClusterTagInfos_cfi::pixelhit, funct::pow(), SiPixelRecHit::probabilityQ(), SiPixelRecHit::probabilityXY(), processHit1D(), processHit2D(), DiDispStaMuonMonitor_cfi::pt, reco::TrackBase::pt(), alignCSCRings::r, SiPixelRecHit::rawQualityWord(), TrajectoryMeasurement::recHit(), Scale, AlignmentParameterStore::selectParameters(), mathSSE::sqrt(), DetId::subdetId(), theAlignableDetAccessor, theAlignmentParameterStore, theDataGroup, theEtaFormula, theMonitorConfig, HLT_2018_cff::track, HIPMonitorConfig::trackmonitorvars, trackPs, PDWG_EXOHSCP_cff::tracks, trackWt, AlignmentAlgorithmBase::EventInfo::trajTrackPairs(), uniEta, HIPAlignableSpecificParameters::usePixelProbXYOrProbQ, PV3DBase< T, PVType, FrameType >::x(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().

Referenced by DTWorkflow.DTWorkflow::all(), Types.EventID::cppID(), Types.LuminosityBlockID::cppID(), o2olib.O2OTool::execute(), and ~HIPAlignmentAlgorithm().

737  {
738  if (isCollector)
739  return;
740 
741  TrajectoryStateCombiner tsoscomb;
742 
744 
745  // loop over tracks
747  for (ConstTrajTrackPairCollection::const_iterator it = tracks.begin(); it != tracks.end(); ++it) {
748  const Trajectory* traj = (*it).first;
749  const reco::Track* track = (*it).second;
750 
751  float pt = track->pt();
752  float eta = track->eta();
753  float phi = track->phi();
754  float p = track->p();
755  float chi2n = track->normalizedChi2();
756  int nhit = track->numberOfValidHits();
757  float d0 = track->d0();
758  float dz = track->dz();
759 
760  int nhpxb = track->hitPattern().numberOfValidPixelBarrelHits();
761  int nhpxf = track->hitPattern().numberOfValidPixelEndcapHits();
762  int nhtib = track->hitPattern().numberOfValidStripTIBHits();
763  int nhtob = track->hitPattern().numberOfValidStripTOBHits();
764  int nhtid = track->hitPattern().numberOfValidStripTIDHits();
765  int nhtec = track->hitPattern().numberOfValidStripTECHits();
766 
767  if (verbose)
768  edm::LogInfo("Alignment") << "New track pt,eta,phi,chi2n,hits: " << pt << "," << eta << "," << phi << "," << chi2n
769  << "," << nhit;
770 
771  double ihitwt = 1;
772  double trkwt = 1;
773  if (trackWt) {
774  trkwt = Scale;
775  // Reweight by the specified eta distribution
776  if (uniEta)
777  trkwt *= theEtaFormula->Eval(fabs(eta));
778  }
779  if (trackPs) {
780  double r = gRandom->Rndm();
781  if (trkwt < r)
782  continue;
783  } else if (trackWt)
784  ihitwt = trkwt;
785 
786  // fill track parameters in root tree
787  {
788  theMonitorConfig.trackmonitorvars.m_Nhits.push_back(nhit);
789  theMonitorConfig.trackmonitorvars.m_Pt.push_back(pt);
791  theMonitorConfig.trackmonitorvars.m_Eta.push_back(eta);
792  theMonitorConfig.trackmonitorvars.m_Phi.push_back(phi);
793  theMonitorConfig.trackmonitorvars.m_Chi2n.push_back(chi2n);
794  theMonitorConfig.trackmonitorvars.m_nhPXB.push_back(nhpxb);
795  theMonitorConfig.trackmonitorvars.m_nhPXF.push_back(nhpxf);
796  theMonitorConfig.trackmonitorvars.m_nhTIB.push_back(nhtib);
797  theMonitorConfig.trackmonitorvars.m_nhTOB.push_back(nhtob);
798  theMonitorConfig.trackmonitorvars.m_nhTID.push_back(nhtid);
799  theMonitorConfig.trackmonitorvars.m_nhTEC.push_back(nhtec);
800  theMonitorConfig.trackmonitorvars.m_d0.push_back(d0);
801  theMonitorConfig.trackmonitorvars.m_dz.push_back(dz);
802  theMonitorConfig.trackmonitorvars.m_wt.push_back(ihitwt);
803  }
804 
805  std::vector<const TransientTrackingRecHit*> hitvec;
806  std::vector<TrajectoryStateOnSurface> tsosvec;
807 
808  // loop over measurements
809  std::vector<TrajectoryMeasurement> measurements = traj->measurements();
810  for (std::vector<TrajectoryMeasurement>::iterator im = measurements.begin(); im != measurements.end(); ++im) {
811  TrajectoryMeasurement meas = *im;
812 
813  // const TransientTrackingRecHit* ttrhit = &(*meas.recHit());
814  // const TrackingRecHit *hit = ttrhit->hit();
815  const TransientTrackingRecHit* hit = &(*meas.recHit());
816 
817  if (hit->isValid() && theAlignableDetAccessor->detAndSubdetInMap(hit->geographicalId())) {
818  // this is the updated state (including the current hit)
819  // TrajectoryStateOnSurface tsos=meas.updatedState();
820  // combine fwd and bwd predicted state to get state
821  // which excludes current hit
822 
824  if (eventInfo.clusterValueMap()) {
825  // check from the PrescalingMap if the hit was taken.
826  // If not skip to the next TM
827  // bool hitTaken=false;
828  AlignmentClusterFlag myflag;
829 
830  int subDet = hit->geographicalId().subdetId();
831  //take the actual RecHit out of the Transient one
832  const TrackingRecHit* rechit = hit->hit();
833  if (subDet > 2) { // AM: if possible use enum instead of hard-coded value
834  const std::type_info& type = typeid(*rechit);
835 
836  if (type == typeid(SiStripRecHit1D)) {
837  const SiStripRecHit1D* stripHit1D = dynamic_cast<const SiStripRecHit1D*>(rechit);
838  if (stripHit1D) {
839  SiStripRecHit1D::ClusterRef stripclust(stripHit1D->cluster());
840  // myflag=PrescMap[stripclust];
841  myflag = (*eventInfo.clusterValueMap())[stripclust];
842  } else
843  edm::LogError("HIPAlignmentAlgorithm")
844  << "ERROR in <HIPAlignmentAlgorithm::run>: Dynamic cast of Strip RecHit failed! "
845  << "TypeId of the RecHit: " << className(*hit);
846  } //end if type = SiStripRecHit1D
847  else if (type == typeid(SiStripRecHit2D)) {
848  const SiStripRecHit2D* stripHit2D = dynamic_cast<const SiStripRecHit2D*>(rechit);
849  if (stripHit2D) {
850  SiStripRecHit2D::ClusterRef stripclust(stripHit2D->cluster());
851  // myflag=PrescMap[stripclust];
852  myflag = (*eventInfo.clusterValueMap())[stripclust];
853  } else
854  edm::LogError("HIPAlignmentAlgorithm")
855  << "ERROR in <HIPAlignmentAlgorithm::run>: Dynamic cast of Strip RecHit failed! "
856  << "TypeId of the TTRH: " << className(*hit);
857  } //end if type == SiStripRecHit2D
858  } //end if hit from strips
859  else {
860  const SiPixelRecHit* pixelhit = dynamic_cast<const SiPixelRecHit*>(rechit);
861  if (pixelhit) {
862  SiPixelClusterRefNew pixelclust(pixelhit->cluster());
863  // myflag=PrescMap[pixelclust];
864  myflag = (*eventInfo.clusterValueMap())[pixelclust];
865  } else
866  edm::LogError("HIPAlignmentAlgorithm")
867  << "ERROR in <HIPAlignmentAlgorithm::run>: Dynamic cast of Pixel RecHit failed! "
868  << "TypeId of the TTRH: " << className(*hit);
869  } //end 'else' it is a pixel hit
870  if (!myflag.isTaken())
871  continue;
872  } //end if Prescaled Hits
874 
876 
877  if (tsos.isValid()) {
878  hitvec.push_back(hit);
879  tsosvec.push_back(tsos);
880  }
881 
882  } //hit valid
883  }
884 
885  // transform RecHit vector to AlignableDet vector
886  std::vector<AlignableDetOrUnitPtr> alidetvec = theAlignableDetAccessor->alignablesFromHits(hitvec);
887 
888  // get concatenated alignment parameters for list of alignables
890 
891  std::vector<TrajectoryStateOnSurface>::const_iterator itsos = tsosvec.begin();
892  std::vector<const TransientTrackingRecHit*>::const_iterator ihit = hitvec.begin();
893 
894  // loop over vectors(hit,tsos)
895  while (itsos != tsosvec.end()) {
896  // get AlignableDet for this hit
897  const GeomDet* det = (*ihit)->det();
898  // int subDet= (*ihit)->geographicalId().subdetId();
899  uint32_t nhitDim = (*ihit)->dimension();
900 
901  AlignableDetOrUnitPtr alidet = theAlignableDetAccessor->alignableFromGeomDet(det);
902 
903  // get relevant Alignable
904  Alignable* ali = aap.alignableFromAlignableDet(alidet);
905 
906  if (ali != nullptr) {
907  const HIPAlignableSpecificParameters* alispecifics = findAlignableSpecs(ali);
908  const TrajectoryStateOnSurface& tsos = *itsos;
909 
910  // LocalVector v = tsos.localDirection();
911  // double proj_z = v.dot(LocalVector(0,0,1));
912 
913  //In fact, sin_theta=Abs(mom_z)
914  double mom_x = tsos.localDirection().x();
915  double mom_y = tsos.localDirection().y();
916  double mom_z = tsos.localDirection().z();
917  double sin_theta = TMath::Abs(mom_z) / sqrt(pow(mom_x, 2) + pow(mom_y, 2) + pow(mom_z, 2));
918  double angle = TMath::ASin(sin_theta);
919  double alihitwt = ihitwt;
920 
921  //Make cut on hit impact angle, reduce collision hits perpendicular to modules
922  if (IsCollision) {
923  if (angle > col_cut)
924  alihitwt = 0;
925  } else {
926  if (angle < cos_cut)
927  alihitwt = 0;
928  }
929 
930  // Fill hit monitor variables
934 
935  // Check pixel XY and Q probabilities
936  if ((*ihit)->hit() != nullptr) {
937  const SiPixelRecHit* pixhit = dynamic_cast<const SiPixelRecHit*>((*ihit)->hit());
938  if (pixhit != nullptr) {
941  // Prob X, Y are deprecated
945  if (alispecifics->applyPixelProbCut) {
946  bool probXYgood = (theMonitorConfig.hitmonitorvars.m_probXY >= alispecifics->minPixelProbXY &&
948  bool probQgood = (theMonitorConfig.hitmonitorvars.m_probQ >= alispecifics->minPixelProbQ &&
950  bool probXYQgood;
951  if (alispecifics->usePixelProbXYOrProbQ)
952  probXYQgood = (probXYgood || probQgood);
953  else
954  probXYQgood = (probXYgood && probQgood);
955  if (!probXYQgood)
956  alihitwt = 0;
957  }
958  }
959  }
960  }
961 
963  bool hitProcessed = false;
964  switch (nhitDim) {
965  case 1:
966  hitProcessed = processHit1D(alidet, ali, alispecifics, tsos, *ihit, alihitwt);
967  break;
968  case 2:
969  hitProcessed = processHit2D(alidet, ali, alispecifics, tsos, *ihit, alihitwt);
970  break;
971  default:
972  edm::LogError("HIPAlignmentAlgorithm")
973  << "ERROR in <HIPAlignmentAlgorithm::run>: Number of hit dimensions = " << nhitDim
974  << " is not supported!" << std::endl;
975  break;
976  }
979  }
980 
981  itsos++;
982  ihit++;
983  }
984  } // end of track loop
985 
986  // fill eventwise root tree (with prescale defined in pset)
989 }
ClusterRef cluster() const
double p() const
momentum vector magnitude
Definition: TrackBase.h:599
type
Definition: HCALResponse.h:21
align::ID id() const
Return the ID of Alignable, i.e. DetId of &#39;first&#39; component GeomDet(Unit).
Definition: Alignable.h:180
std::vector< float > m_P
bool hasFilledProb() const
std::vector< int > m_nhTIB
ConstRecHitPointer const & recHit() const
double d0() const
dxy parameter in perigee convention (d0 = -dxy)
Definition: TrackBase.h:590
AlignmentParameterStore * theAlignmentParameterStore
std::vector< float > m_Eta
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:572
TSOS combine(const TSOS &pTsos1, const TSOS &pTsos2) const
LocalVector localDirection() const
HIPAlignableSpecificParameters * findAlignableSpecs(const Alignable *ali)
T y() const
Definition: PV3DBase.h:60
double phi() const
azimuthal angle of momentum vector
Definition: TrackBase.h:614
Alignable * alignableFromAlignableDet(const AlignableDetOrUnitPtr &adet) const
Get relevant Alignable from AlignableDet.
std::vector< int > m_Nhits
int numberOfValidStripTOBHits() const
Definition: HitPattern.h:825
std::unique_ptr< AlignableNavigator > theAlignableDetAccessor
const ConstTrajTrackPairCollection & trajTrackPairs() const
const bool fillTrackHitMonitoring
std::vector< float > m_Pt
DataContainer const & measurements() const
Definition: Trajectory.h:178
std::vector< int > m_nhPXB
std::vector< float > m_wt
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:617
int numberOfValidPixelBarrelHits() const
Definition: HitPattern.h:805
std::vector< int > m_nhTID
T sqrt(T t)
Definition: SSEVec.h:19
double pt() const
track transverse momentum
Definition: TrackBase.h:602
T z() const
Definition: PV3DBase.h:61
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:48
std::vector< int > m_nhTEC
int numberOfValidStripTIDHits() const
Definition: HitPattern.h:821
ClusterRef cluster() const
unsigned short numberOfValidHits() const
number of valid hits found
Definition: TrackBase.h:740
int numberOfValidStripTECHits() const
Definition: HitPattern.h:829
const bool fillTrackMonitoring
unsigned int m_rawQualityWord
TrajectoryStateOnSurface const & forwardPredictedState() const
Access to forward predicted state (from fitter or builder)
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:596
virtual TrackingRecHit const * hit() const
std::vector< int > m_nhTOB
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
Definition: TrackBase.h:483
HIPTrackMonitorVariables trackmonitorvars
ClusterRef cluster() const
Definition: SiPixelRecHit.h:47
CompositeAlignmentParameters selectParameters(const std::vector< AlignableDet * > &alignabledets) const
bool isValid() const
int numberOfValidStripTIBHits() const
Definition: HitPattern.h:817
std::unique_ptr< TFormula > theEtaFormula
int numberOfValidPixelEndcapHits() const
Definition: HitPattern.h:809
const AliClusterValueMap * clusterValueMap() const
HIPMonitorConfig theMonitorConfig
float probabilityXY() const
Definition: SiPixelRecHit.h:86
std::vector< int > m_nhPXF
bool processHit2D(const AlignableDetOrUnitPtr &alidet, const Alignable *ali, const HIPAlignableSpecificParameters *alispecifics, const TrajectoryStateOnSurface &tsos, const TrackingRecHit *hit, double hitwt)
std::vector< float > m_dz
DetId geographicalId() const
bool processHit1D(const AlignableDetOrUnitPtr &alidet, const Alignable *ali, const HIPAlignableSpecificParameters *alispecifics, const TrajectoryStateOnSurface &tsos, const TrackingRecHit *hit, double hitwt)
T x() const
Definition: PV3DBase.h:59
SiPixelRecHitQuality::QualWordType rawQualityWord() const
Definition: SiPixelRecHit.h:78
std::vector< float > m_Chi2n
float probabilityQ() const
Definition: SiPixelRecHit.h:87
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:30
std::string className(const T &t)
Definition: ClassName.h:31
TrajectoryStateOnSurface const & backwardPredictedState() const
Access to backward predicted state (from smoother)
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
std::vector< ConstTrajTrackPair > ConstTrajTrackPairCollection
void HIPAlignmentAlgorithm::setAlignmentPositionError ( void  )
private

Definition at line 1025 of file HIPAlignmentAlgorithm.cc.

References calcAPE(), mps_fire::i, AlignmentParameterStore::setAlignmentPositionError(), theAlignmentParameterStore, theAPEParameters, theApplyAPE, and theIteration.

Referenced by startNewLoop(), and ~HIPAlignmentAlgorithm().

1025  {
1026  // Check if user wants to override APE
1027  if (!theApplyAPE) {
1028  edm::LogInfo("Alignment") << "[HIPAlignmentAlgorithm::setAlignmentPositionError] No APE applied";
1029  return; // NO APE APPLIED
1030  }
1031 
1032  edm::LogInfo("Alignment") << "[HIPAlignmentAlgorithm::setAlignmentPositionError] Apply APE!";
1033 
1034  double apeSPar[3], apeRPar[3];
1035  for (const auto& alipars : theAPEParameters) {
1036  const auto& alignables = alipars.first;
1037  const auto& pars = alipars.second;
1038 
1039  apeSPar[0] = pars[0];
1040  apeSPar[1] = pars[1];
1041  apeSPar[2] = pars[2];
1042  apeRPar[0] = pars[3];
1043  apeRPar[1] = pars[4];
1044  apeRPar[2] = pars[5];
1045 
1046  int function = pars[6];
1047 
1048  // Printout for debug
1049  printf("APE: %u alignables\n", (unsigned int)alignables.size());
1050  for (int i = 0; i < 21; ++i) {
1051  double apelinstest = calcAPE(apeSPar, i, 0);
1052  double apeexpstest = calcAPE(apeSPar, i, 1);
1053  double apestepstest = calcAPE(apeSPar, i, 2);
1054  double apelinrtest = calcAPE(apeRPar, i, 0);
1055  double apeexprtest = calcAPE(apeRPar, i, 1);
1056  double apesteprtest = calcAPE(apeRPar, i, 2);
1057  printf("APE: iter slin sexp sstep rlin rexp rstep: %5d %12.5f %12.5f %12.5f %12.5f %12.5f %12.5f \n",
1058  i,
1059  apelinstest,
1060  apeexpstest,
1061  apestepstest,
1062  apelinrtest,
1063  apeexprtest,
1064  apesteprtest);
1065  }
1066 
1067  // set APE
1068  double apeshift = calcAPE(apeSPar, theIteration, function);
1069  double aperot = calcAPE(apeRPar, theIteration, function);
1070  theAlignmentParameterStore->setAlignmentPositionError(alignables, apeshift, aperot);
1071  }
1072 }
AlignmentParameterStore * theAlignmentParameterStore
void setAlignmentPositionError(const align::Alignables &alivec, double valshift, double valrot)
Set Alignment position error.
double calcAPE(double *par, int iter, int function)
std::vector< std::pair< align::Alignables, std::vector< double > > > theAPEParameters
void HIPAlignmentAlgorithm::startNewLoop ( void  )
overridevirtual

Called at start of new loop.

Reimplemented from AlignmentAlgorithmBase.

Definition at line 302 of file HIPAlignmentAlgorithm.cc.

References AlignmentParameterStore::applyAlignableAbsolutePositions(), bookRoot(), collector(), ioerr, isCollector, AlignmentParameters::numSelected(), AlignmentIORoot::readAlignableAbsolutePositions(), readIterationFile(), salignedfile, setAlignmentPositionError(), AlignmentParameters::setUserVariables(), siterationfile, theAlignables, theAlignmentParameterStore, theIO, and theIteration.

Referenced by ~HIPAlignmentAlgorithm().

302  {
303  edm::LogInfo("Alignment") << "@SUB=HIPAlignmentAlgorithm::startNewLoop"
304  << "Begin";
305 
306  // iterate over all alignables and attach user variables
307  for (const auto& it : theAlignables) {
308  AlignmentParameters* ap = it->alignmentParameters();
309  int npar = ap->numSelected();
310  HIPUserVariables* userpar = new HIPUserVariables(npar);
311  ap->setUserVariables(userpar);
312  }
313 
314  // try to read in alignment parameters from a previous iteration
315  AlignablePositions theAlignablePositionsFromFile =
316  theIO.readAlignableAbsolutePositions(theAlignables, salignedfile.c_str(), -1, ioerr);
317  int numAlignablesFromFile = theAlignablePositionsFromFile.size();
318  if (numAlignablesFromFile == 0) { // file not there: first iteration
319  // set iteration number to 1 when needed
320  if (isCollector)
321  theIteration = 0;
322  else
323  theIteration = 1;
324  edm::LogWarning("Alignment") << "@SUB=HIPAlignmentAlgorithm::startNewLoop"
325  << "IO alignables file not found for iteration " << theIteration;
326  } else { // there have been previous iterations
327  edm::LogInfo("Alignment") << "@SUB=HIPAlignmentAlgorithm::startNewLoop"
328  << "Alignables Read " << numAlignablesFromFile;
329 
330  // get iteration number from file
332  // Where is the target for this?
334 
335  // increase iteration
336  if (ioerr == 0) {
337  theIteration++;
338  edm::LogWarning("Alignment") << "@SUB=HIPAlignmentAlgorithm::startNewLoop"
339  << "Iteration increased by one and is now " << theIteration;
340  }
341 
342  // now apply psotions of file from prev iteration
343  edm::LogInfo("Alignment") << "@SUB=HIPAlignmentAlgorithm::startNewLoop"
344  << "Apply positions from file ...";
345  theAlignmentParameterStore->applyAlignableAbsolutePositions(theAlignables, theAlignablePositionsFromFile, ioerr);
346  }
347 
348  edm::LogWarning("Alignment") << "@SUB=HIPAlignmentAlgorithm::startNewLoop"
349  << "Current Iteration number: " << theIteration;
350 
351  // book root trees
352  bookRoot();
353 
354  // set alignment position error
356 
357  // run collector job if we are in parallel mode
358  if (isCollector)
359  collector();
360 
361  edm::LogInfo("Alignment") << "@SUB=HIPAlignmentAlgorithm::startNewLoop"
362  << "End";
363 }
AlignmentParameterStore * theAlignmentParameterStore
void applyAlignableAbsolutePositions(const align::Alignables &alis, const AlignablePositions &newpos, int &ierr)
apply absolute positions to alignables
AlignablePositions readAlignableAbsolutePositions(const align::Alignables &alivec, const char *filename, int iter, int &ierr) override
read Alignable current absolute positions
int readIterationFile(std::string filename)
int numSelected(void) const
Get number of selected parameters.
void setUserVariables(AlignmentUserVariables *auv)
Set pointer to user variables.
align::Alignables theAlignables
std::vector< AlignableAbsData > AlignablePositions
Definition: AlignableData.h:47
void HIPAlignmentAlgorithm::terminate ( const edm::EventSetup setup)
overridevirtual

Call at end of job.

Implements AlignmentAlgorithmBase.

Definition at line 366 of file HIPAlignmentAlgorithm.cc.

References Alignable::alignmentParameters(), AlignmentParameterStore::applyParameters(), calcParameters(), fillAlignablesMonitor(), edm::EventSetup::get(), mps_fire::i, Alignable::id(), SurveyResidual::inverseCovariance(), ioerr, isCollector, HIPUserVariables::jtve, HIPUserVariables::jtvj, cmsLHEtoEOSManager::l, m3_Id, m3_ObjId, m3_par, HIPUserVariables::nhit, GloballyPositioned< T >::position(), edm::ESHandle< T >::product(), salignedfile, SurveyResidual::sensorResidual(), SetScanDet, AlignmentParameters::setValid(), siterationfile, Alignable::surface(), suvarfile, theAlignables, theAlignablesMonitorIORootFile, theAlignablesMonitorTree, theAlignmentParameterStore, theHitMonitorTree, theIO, theIteration, theLevels, theSurveyIORootFile, theSurveyTree, theTrackHitMonitorIORootFile, theTrackMonitorTree, AlignmentParameterStore::typeAndLayer(), AlignmentParameters::userVariables(), SurveyResidual::valid(), AlignmentIORoot::writeAlignableAbsolutePositions(), HIPUserVariablesIORoot::writeHIPUserVariables(), writeIterationFile(), and PV3DBase< T, PVType, FrameType >::z().

366  {
367  edm::LogWarning("Alignment") << "[HIPAlignmentAlgorithm] Terminating";
368 
369  // calculating survey residuals
370  if (!theLevels.empty()) {
371  edm::LogWarning("Alignment") << "[HIPAlignmentAlgorithm] Using survey constraint";
372 
373  unsigned int nAlignable = theAlignables.size();
374  edm::ESHandle<TrackerTopology> tTopoHandle;
375  iSetup.get<IdealGeometryRecord>().get(tTopoHandle);
376  const TrackerTopology* const tTopo = tTopoHandle.product();
377  for (unsigned int i = 0; i < nAlignable; ++i) {
378  const Alignable* ali = theAlignables[i];
380  HIPUserVariables* uservar = dynamic_cast<HIPUserVariables*>(ap->userVariables());
381  int nhit = uservar->nhit;
382 
383  // get position
384  std::pair<int, int> tl = theAlignmentParameterStore->typeAndLayer(ali, tTopo);
385  int tmp_Type = tl.first;
386  int tmp_Layer = tl.second;
387  GlobalPoint pos = ali->surface().position();
388  float tmpz = pos.z();
389  if (nhit < 1500 ||
390  (tmp_Type == 5 && tmp_Layer == 4 && fabs(tmpz) > 90)) { // FIXME: Needs revision for hardcoded consts
391  for (unsigned int l = 0; l < theLevels.size(); ++l) {
392  SurveyResidual res(*ali, theLevels[l], true);
393 
394  if (res.valid()) {
395  AlgebraicSymMatrix invCov = res.inverseCovariance();
396 
397  // variable for tree
398  AlgebraicVector sensResid = res.sensorResidual();
399  m3_Id = ali->id();
400  m3_ObjId = theLevels[l];
401  m3_par[0] = sensResid[0];
402  m3_par[1] = sensResid[1];
403  m3_par[2] = sensResid[2];
404  m3_par[3] = sensResid[3];
405  m3_par[4] = sensResid[4];
406  m3_par[5] = sensResid[5];
407 
408  uservar->jtvj += invCov;
409  uservar->jtve += invCov * sensResid;
410 
411  if (theSurveyTree != nullptr)
412  theSurveyTree->Fill();
413  }
414  }
415  }
416  }
417  }
418 
419  // write user variables
421  // don't store userVariable in main, to save time
422  if (!isCollector)
424 
425  // now calculate alignment corrections...
426  int ialigned = 0;
427  // iterate over alignment parameters
428  for (const auto& ali : theAlignables) {
430 
431  if (SetScanDet.at(0) != 0) {
432  edm::LogWarning("Alignment") << "********Starting Scan*********";
433  edm::LogWarning("Alignment") << "det ID=" << SetScanDet.at(0) << ", starting position=" << SetScanDet.at(1)
434  << ", step=" << SetScanDet.at(2) << ", currentDet = " << ali->id();
435  }
436 
437  if ((SetScanDet.at(0) != 0) && (SetScanDet.at(0) != 1) && (ali->id() != SetScanDet.at(0)))
438  continue;
439 
440  bool test = calcParameters(ali, SetScanDet.at(0), SetScanDet.at(1), SetScanDet.at(2));
441  if (test) {
442  if (dynamic_cast<AlignableDetUnit*>(ali) != nullptr) {
443  std::vector<std::pair<int, SurfaceDeformation*>> pairs;
444  ali->surfaceDeformationIdPairs(pairs);
445  edm::LogInfo("Alignment") << "@SUB=HIPAlignmentAlgorithm::terminate"
446  << "The alignable contains " << pairs.size() << " surface deformations";
447  } else
448  edm::LogInfo("Alignment") << "@SUB=HIPAlignmentAlgorithm::terminate"
449  << "The alignable cannot contain surface deformations";
450 
452  // set these parameters 'valid'
453  ali->alignmentParameters()->setValid(true);
454  // increase counter
455  ialigned++;
456  } else
457  par->setValid(false);
458  }
459  //end looping over alignables
460 
461  edm::LogWarning("Alignment") << "[HIPAlignmentAlgorithm::terminate] Aligned units: " << ialigned;
462 
463  // fill alignable wise root tree
464  fillAlignablesMonitor(iSetup);
465 
466  edm::LogWarning("Alignment") << "[HIPAlignmentAlgorithm] Writing aligned parameters to file: " << theAlignables.size()
467  << ", for Iteration " << theIteration;
468 
469  // write user variables
470  if (isCollector)
471  HIPIO.writeHIPUserVariables(theAlignables, suvarfile.c_str(), theIteration, false, ioerr);
472 
473  // write new absolute positions to disk
474  theIO.writeAlignableAbsolutePositions(theAlignables, salignedfile.c_str(), theIteration, false, ioerr);
475 
476  // write alignment parameters to disk
477  //theIO.writeAlignmentParameters(theAlignables,
478  // sparameterfile.c_str(),theIteration,false,ioerr);
479 
480  // write iteration number to file
482 
483  // write out trees and close root file
484  // Survey tree
485  if (theSurveyIORootFile != nullptr) {
486  theSurveyIORootFile->cd();
487  if (theSurveyTree != nullptr)
488  theSurveyTree->Write();
489  delete theSurveyTree;
490  theSurveyTree = nullptr;
491  theSurveyIORootFile->Close();
492  }
493  // Alignable-wise tree is only filled once at iteration 1
494  if (theAlignablesMonitorIORootFile != nullptr) {
496  if (theAlignablesMonitorTree != nullptr)
497  theAlignablesMonitorTree->Write();
499  theAlignablesMonitorTree = nullptr;
501  }
502  // Eventwise and hitwise monitoring trees
503  if (theTrackHitMonitorIORootFile != nullptr) {
505  if (theTrackMonitorTree != nullptr) {
506  theTrackMonitorTree->Write();
507  delete theTrackMonitorTree;
508  theTrackMonitorTree = nullptr;
509  }
510  if (theHitMonitorTree != nullptr) {
511  theHitMonitorTree->Write();
512  delete theHitMonitorTree;
513  theHitMonitorTree = nullptr;
514  }
516  }
517 }
align::ID id() const
Return the ID of Alignable, i.e. DetId of &#39;first&#39; component GeomDet(Unit).
Definition: Alignable.h:180
virtual int surfaceDeformationIdPairs(std::vector< std::pair< int, SurfaceDeformation * > > &) const =0
AlignmentParameterStore * theAlignmentParameterStore
std::pair< int, int > typeAndLayer(const Alignable *ali, const TrackerTopology *tTopo) const
Obtain type and layer from Alignable.
void writeIterationFile(std::string filename, int iter)
void applyParameters(void)
Obsolete: Use AlignableNavigator::alignableDetFromDetId and alignableFromAlignableDet.
AlgebraicVector jtve
AlignmentParameters * alignmentParameters() const
Get the AlignmentParameters.
Definition: Alignable.h:58
Definition: Electron.h:6
void writeHIPUserVariables(const Alignables &alivec, const char *filename, int iter, bool validCheck, int &ierr)
bool calcParameters(Alignable *ali, int setDet, double start, double step)
AlgebraicSymMatrix jtvj
AlignmentUserVariables * userVariables(void) const
Get pointer to user variables.
void setValid(bool v)
Set validity flag.
T z() const
Definition: PV3DBase.h:61
std::vector< double > SetScanDet
const AlignableSurface & surface() const
Return the Surface (global position and orientation) of the object.
Definition: Alignable.h:132
CLHEP::HepVector AlgebraicVector
void writeAlignableAbsolutePositions(const align::Alignables &alivec, const char *filename, int iter, bool validCheck, int &ierr) override
write Alignable current absolute positions
align::StructureType m3_ObjId
align::Alignables theAlignables
void fillAlignablesMonitor(const edm::EventSetup &setup)
CLHEP::HepSymMatrix AlgebraicSymMatrix
const PositionType & position() const
T const * product() const
Definition: ESHandle.h:86
std::vector< align::StructureType > theLevels
void HIPAlignmentAlgorithm::writeIterationFile ( std::string  filename,
int  iter 
)
private

Definition at line 1011 of file HIPAlignmentAlgorithm.cc.

References MillePedeFileConverter_cfg::out.

Referenced by terminate(), and ~HIPAlignmentAlgorithm().

1011  {
1012  std::ofstream outIterFile((filename.c_str()), std::ios::out);
1013  if (!outIterFile)
1014  edm::LogError("Alignment") << "[HIPAlignmentAlgorithm::writeIterationFile] ERROR: Unable to write Iteration file";
1015  else {
1016  outIterFile << iter;
1017  edm::LogWarning("Alignment") << "[HIPAlignmentAlgorithm::writeIterationFile] writing iteration number to file: "
1018  << iter;
1019  }
1020  outIterFile.close();
1021 }

Member Data Documentation

std::unique_ptr<AlignableObjectId> HIPAlignmentAlgorithm::alignableObjectId_
private

Definition at line 84 of file HIPAlignmentAlgorithm.h.

Referenced by initialize().

double HIPAlignmentAlgorithm::col_cut
private

Definition at line 129 of file HIPAlignmentAlgorithm.h.

Referenced by HIPAlignmentAlgorithm(), and run().

double HIPAlignmentAlgorithm::cos_cut
private

Definition at line 129 of file HIPAlignmentAlgorithm.h.

Referenced by HIPAlignmentAlgorithm(), and run().

HIPAlignableSpecificParameters HIPAlignmentAlgorithm::defaultAlignableSpecs
private
const bool HIPAlignmentAlgorithm::doTrackHitMonitoring
private

Definition at line 99 of file HIPAlignmentAlgorithm.h.

Referenced by bookRoot(), collectMonitorTrees(), and collector().

int HIPAlignmentAlgorithm::ioerr
private

Definition at line 90 of file HIPAlignmentAlgorithm.h.

Referenced by collector(), startNewLoop(), and terminate().

bool HIPAlignmentAlgorithm::isCollector
private
bool HIPAlignmentAlgorithm::IsCollision
private

Definition at line 127 of file HIPAlignmentAlgorithm.h.

Referenced by HIPAlignmentAlgorithm(), and run().

int HIPAlignmentAlgorithm::m2_datatype
private

Definition at line 153 of file HIPAlignmentAlgorithm.h.

Referenced by bookRoot(), and fillAlignablesMonitor().

SurfaceDeformationFactory::Type HIPAlignmentAlgorithm::m2_dtype
private

Definition at line 155 of file HIPAlignmentAlgorithm.h.

Referenced by bookRoot(), and fillAlignablesMonitor().

align::ID HIPAlignmentAlgorithm::m2_Id
private

Definition at line 150 of file HIPAlignmentAlgorithm.h.

Referenced by bookRoot(), and fillAlignablesMonitor().

int HIPAlignmentAlgorithm::m2_Layer
private

Definition at line 152 of file HIPAlignmentAlgorithm.h.

Referenced by bookRoot(), and fillAlignablesMonitor().

int HIPAlignmentAlgorithm::m2_Nhit
private

Definition at line 152 of file HIPAlignmentAlgorithm.h.

Referenced by bookRoot(), and fillAlignablesMonitor().

unsigned int HIPAlignmentAlgorithm::m2_nsurfdef
private

Definition at line 156 of file HIPAlignmentAlgorithm.h.

Referenced by bookRoot(), and fillAlignablesMonitor().

align::StructureType HIPAlignmentAlgorithm::m2_ObjId
private

Definition at line 151 of file HIPAlignmentAlgorithm.h.

Referenced by bookRoot(), and fillAlignablesMonitor().

std::vector<float> HIPAlignmentAlgorithm::m2_surfDef
private

Definition at line 157 of file HIPAlignmentAlgorithm.h.

Referenced by bookRoot(), and fillAlignablesMonitor().

int HIPAlignmentAlgorithm::m2_Type
private

Definition at line 152 of file HIPAlignmentAlgorithm.h.

Referenced by bookRoot(), and fillAlignablesMonitor().

float HIPAlignmentAlgorithm::m2_Xpos
private

Definition at line 154 of file HIPAlignmentAlgorithm.h.

Referenced by bookRoot(), and fillAlignablesMonitor().

float HIPAlignmentAlgorithm::m2_Ypos
private

Definition at line 154 of file HIPAlignmentAlgorithm.h.

Referenced by bookRoot(), and fillAlignablesMonitor().

float HIPAlignmentAlgorithm::m2_Zpos
private

Definition at line 154 of file HIPAlignmentAlgorithm.h.

Referenced by bookRoot(), and fillAlignablesMonitor().

align::ID HIPAlignmentAlgorithm::m3_Id
private

Definition at line 160 of file HIPAlignmentAlgorithm.h.

Referenced by bookRoot(), and terminate().

align::StructureType HIPAlignmentAlgorithm::m3_ObjId
private

Definition at line 161 of file HIPAlignmentAlgorithm.h.

Referenced by bookRoot(), and terminate().

float HIPAlignmentAlgorithm::m3_par[6]
private

Definition at line 162 of file HIPAlignmentAlgorithm.h.

Referenced by bookRoot(), and terminate().

int HIPAlignmentAlgorithm::m_datatype
private

Definition at line 147 of file HIPAlignmentAlgorithm.h.

Referenced by bookRoot(), and run().

std::string HIPAlignmentAlgorithm::outfile2
private

Definition at line 101 of file HIPAlignmentAlgorithm.h.

Referenced by bookRoot(), HIPAlignmentAlgorithm(), and initialize().

std::string HIPAlignmentAlgorithm::outpath
private

Definition at line 101 of file HIPAlignmentAlgorithm.h.

Referenced by HIPAlignmentAlgorithm().

bool HIPAlignmentAlgorithm::rewgtPerAli
private

Definition at line 127 of file HIPAlignmentAlgorithm.h.

Referenced by collector(), and HIPAlignmentAlgorithm().

std::string HIPAlignmentAlgorithm::salignedfile
private
double HIPAlignmentAlgorithm::Scale
private

Definition at line 129 of file HIPAlignmentAlgorithm.h.

Referenced by HIPAlignmentAlgorithm(), and run().

std::vector<double> HIPAlignmentAlgorithm::SetScanDet
private

Definition at line 130 of file HIPAlignmentAlgorithm.h.

Referenced by HIPAlignmentAlgorithm(), and terminate().

std::string HIPAlignmentAlgorithm::siterationfile
private
std::string HIPAlignmentAlgorithm::smisalignedfile
private

Definition at line 102 of file HIPAlignmentAlgorithm.h.

Referenced by HIPAlignmentAlgorithm().

std::string HIPAlignmentAlgorithm::sparameterfile
private

Definition at line 101 of file HIPAlignmentAlgorithm.h.

Referenced by HIPAlignmentAlgorithm().

std::string HIPAlignmentAlgorithm::ssurveyfile
private

Definition at line 102 of file HIPAlignmentAlgorithm.h.

Referenced by bookRoot(), HIPAlignmentAlgorithm(), and initialize().

std::string HIPAlignmentAlgorithm::struefile
private

Definition at line 102 of file HIPAlignmentAlgorithm.h.

Referenced by HIPAlignmentAlgorithm().

const std::vector<std::string> HIPAlignmentAlgorithm::surveyResiduals_
private

Definition at line 134 of file HIPAlignmentAlgorithm.h.

Referenced by initialize().

std::string HIPAlignmentAlgorithm::suvarfile
private

Definition at line 101 of file HIPAlignmentAlgorithm.h.

Referenced by HIPAlignmentAlgorithm(), initialize(), and terminate().

std::string HIPAlignmentAlgorithm::suvarfilecore
private

Definition at line 101 of file HIPAlignmentAlgorithm.h.

Referenced by collector(), and HIPAlignmentAlgorithm().

std::unique_ptr<AlignableNavigator> HIPAlignmentAlgorithm::theAlignableDetAccessor
private

Definition at line 87 of file HIPAlignmentAlgorithm.h.

Referenced by initialize(), and run().

align::Alignables HIPAlignmentAlgorithm::theAlignables
private
TFile* HIPAlignmentAlgorithm::theAlignablesMonitorIORootFile
private

Definition at line 141 of file HIPAlignmentAlgorithm.h.

Referenced by bookRoot(), fillAlignablesMonitor(), and terminate().

TTree* HIPAlignmentAlgorithm::theAlignablesMonitorTree
private

Definition at line 142 of file HIPAlignmentAlgorithm.h.

Referenced by bookRoot(), fillAlignablesMonitor(), and terminate().

std::vector<HIPAlignableSpecificParameters> HIPAlignmentAlgorithm::theAlignableSpecifics
private

Definition at line 120 of file HIPAlignmentAlgorithm.h.

Referenced by findAlignableSpecs(), and initialize().

AlignmentParameterStore* HIPAlignmentAlgorithm::theAlignmentParameterStore
private
std::vector<std::pair<align::Alignables, std::vector<double> > > HIPAlignmentAlgorithm::theAPEParameters
private

Definition at line 110 of file HIPAlignmentAlgorithm.h.

Referenced by initialize(), and setAlignmentPositionError().

std::vector<edm::ParameterSet> HIPAlignmentAlgorithm::theAPEParameterSet
private

Definition at line 109 of file HIPAlignmentAlgorithm.h.

Referenced by HIPAlignmentAlgorithm(), and initialize().

bool HIPAlignmentAlgorithm::theApplyAPE
private
bool HIPAlignmentAlgorithm::theApplyCutsPerComponent
private
int HIPAlignmentAlgorithm::theCollectorNJobs
private

Definition at line 124 of file HIPAlignmentAlgorithm.h.

Referenced by collector(), and HIPAlignmentAlgorithm().

std::string HIPAlignmentAlgorithm::theCollectorPath
private

Definition at line 125 of file HIPAlignmentAlgorithm.h.

Referenced by collector(), and HIPAlignmentAlgorithm().

std::vector<edm::ParameterSet> HIPAlignmentAlgorithm::theCutsPerComponent
private

Definition at line 119 of file HIPAlignmentAlgorithm.h.

Referenced by HIPAlignmentAlgorithm(), and initialize().

int HIPAlignmentAlgorithm::theDataGroup
private
std::unique_ptr<TFormula> HIPAlignmentAlgorithm::theEtaFormula
private

Definition at line 132 of file HIPAlignmentAlgorithm.h.

Referenced by HIPAlignmentAlgorithm(), and run().

TTree* HIPAlignmentAlgorithm::theHitMonitorTree
private

Definition at line 140 of file HIPAlignmentAlgorithm.h.

Referenced by bookRoot(), collectMonitorTrees(), and terminate().

AlignmentIORoot HIPAlignmentAlgorithm::theIO
private

Definition at line 89 of file HIPAlignmentAlgorithm.h.

Referenced by startNewLoop(), and terminate().

std::vector<unsigned> HIPAlignmentAlgorithm::theIOVrangeSet
private

Definition at line 105 of file HIPAlignmentAlgorithm.h.

Referenced by HIPAlignmentAlgorithm(), and initialize().

int HIPAlignmentAlgorithm::theIteration
private
std::vector<align::StructureType> HIPAlignmentAlgorithm::theLevels
private

Definition at line 135 of file HIPAlignmentAlgorithm.h.

Referenced by bookRoot(), initialize(), and terminate().

HIPMonitorConfig HIPAlignmentAlgorithm::theMonitorConfig
private

Definition at line 98 of file HIPAlignmentAlgorithm.h.

Referenced by bookRoot(), collectMonitorTrees(), collector(), and run().

bool HIPAlignmentAlgorithm::themultiIOV
private

Definition at line 104 of file HIPAlignmentAlgorithm.h.

Referenced by HIPAlignmentAlgorithm(), and initialize().

TFile* HIPAlignmentAlgorithm::theSurveyIORootFile
private

Definition at line 143 of file HIPAlignmentAlgorithm.h.

Referenced by bookRoot(), and terminate().

TTree* HIPAlignmentAlgorithm::theSurveyTree
private

Definition at line 144 of file HIPAlignmentAlgorithm.h.

Referenced by bookRoot(), and terminate().

TFile* HIPAlignmentAlgorithm::theTrackHitMonitorIORootFile
private

Definition at line 138 of file HIPAlignmentAlgorithm.h.

Referenced by bookRoot(), collectMonitorTrees(), and terminate().

TTree* HIPAlignmentAlgorithm::theTrackMonitorTree
private

Definition at line 139 of file HIPAlignmentAlgorithm.h.

Referenced by bookRoot(), collectMonitorTrees(), and terminate().

bool HIPAlignmentAlgorithm::trackPs
private

Definition at line 127 of file HIPAlignmentAlgorithm.h.

Referenced by HIPAlignmentAlgorithm(), and run().

bool HIPAlignmentAlgorithm::trackWt
private

Definition at line 127 of file HIPAlignmentAlgorithm.h.

Referenced by HIPAlignmentAlgorithm(), and run().

bool HIPAlignmentAlgorithm::uniEta
private

Definition at line 127 of file HIPAlignmentAlgorithm.h.

Referenced by HIPAlignmentAlgorithm(), and run().

std::string HIPAlignmentAlgorithm::uniEtaFormula
private

Definition at line 128 of file HIPAlignmentAlgorithm.h.

Referenced by HIPAlignmentAlgorithm().

const bool HIPAlignmentAlgorithm::verbose
private