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 &)
 
 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 32 of file HIPAlignmentAlgorithm.h.

Constructor & Destructor Documentation

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

Constructor.

Definition at line 46 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.

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

1042  {
1043  // create ROOT files
1045  theTrackHitMonitorIORootFile = TFile::Open(theMonitorConfig.outfile.c_str(), "update");
1047  // book event-wise ROOT Tree
1049  TString tname=Form("T1_%i", theIteration);
1050  theTrackMonitorTree = new TTree(tname, "Eventwise tree");
1051  //theTrackMonitorTree->Branch("Run", &m_Run, "Run/I");
1052  //theTrackMonitorTree->Branch("Event", &m_Event, "Event/I");
1053  theTrackMonitorTree->Branch("DataType", &m_datatype);
1056  }
1057  // book hit-wise ROOT Tree
1059  TString tname_hit=Form("T1_hit_%i", theIteration);
1060  theHitMonitorTree = new TTree(tname_hit, "Hitwise tree");
1061  theHitMonitorTree->Branch("DataType", &m_datatype);
1064  }
1065  }
1066 
1067  // book alignable-wise ROOT Tree
1068  if (isCollector){
1069  TString tname=Form("T2_%i", theIteration);
1070  theAlignablesMonitorIORootFile = TFile::Open(outfile2.c_str(), "update");
1072  theAlignablesMonitorTree = new TTree(tname, "Alignablewise tree");
1073  theAlignablesMonitorTree->Branch("Id", &m2_Id, "Id/i");
1074  theAlignablesMonitorTree->Branch("ObjId", &m2_ObjId, "ObjId/I");
1075  theAlignablesMonitorTree->Branch("Nhit", &m2_Nhit);
1076  theAlignablesMonitorTree->Branch("DataType", &m2_datatype);
1077  theAlignablesMonitorTree->Branch("Type", &m2_Type);
1078  theAlignablesMonitorTree->Branch("Layer", &m2_Layer);
1079  theAlignablesMonitorTree->Branch("Xpos", &m2_Xpos);
1080  theAlignablesMonitorTree->Branch("Ypos", &m2_Ypos);
1081  theAlignablesMonitorTree->Branch("Zpos", &m2_Zpos);
1082  theAlignablesMonitorTree->Branch("DeformationsType", &m2_dtype, "DeformationsType/I");
1083  theAlignablesMonitorTree->Branch("NumDeformations", &m2_nsurfdef);
1084  theAlignablesMonitorTree->Branch("Deformations", &m2_surfDef);
1085  }
1086 
1087  // book survey-wise ROOT Tree only if survey is enabled
1088  if (!theLevels.empty()){
1089  TString tname=Form("T3_%i", theIteration);
1090  theSurveyIORootFile = TFile::Open(ssurveyfile.c_str(), "update");
1091  theSurveyIORootFile->cd();
1092  theSurveyTree = new TTree(tname, "Survey Tree");
1093  theSurveyTree->Branch("Id", &m3_Id, "Id/i");
1094  theSurveyTree->Branch("ObjId", &m3_ObjId, "ObjId/I");
1095  theSurveyTree->Branch("Par", &m3_par, "Par[6]/F");
1096  edm::LogInfo("Alignment") << "[HIPAlignmentAlgorithm::bookRoot] Survey trees booked.";
1097  }
1098  edm::LogInfo("Alignment") << "[HIPAlignmentAlgorithm::bookRoot] Root trees booked.";
1099 }
static char const * tname
Definition: GTSchema.h:13
align::StructureType m2_ObjId
const bool fillTrackHitMonitoring
HIPHitMonitorVariables hitmonitorvars
const bool fillTrackMonitoring
void setTree(TTree *tree_)
HIPTrackMonitorVariables trackmonitorvars
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 1027 of file HIPAlignmentAlgorithm.cc.

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

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

1027  {
1028  double diter=(double)iter;
1029  if (function == 0) return std::max(par[1], par[0]+((par[1]-par[0])/par[2])*diter);
1030  else if (function == 1) return std::max(0., par[0]*(exp(-pow(diter, par[1])/par[2])));
1031  else if (function == 2){
1032  int ipar2 = (int)par[2];
1033  int step = iter/ipar2;
1034  double dstep = (double)step;
1035  return std::max(0., par[0] - par[1]*dstep);
1036  }
1037  else assert(false); // should have been caught in the constructor
1038 }
step
Definition: StallMonitor.cc:94
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
bool HIPAlignmentAlgorithm::calcParameters ( Alignable ali,
int  setDet,
double  start,
double  step 
)
private

Definition at line 1195 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, Alignable::setAlignmentParameters(), AlignmentParameters::setValid(), mathSSE::sqrt(), command_line::start, theApplyCutsPerComponent, theIteration, and AlignmentParameters::userVariables().

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

1195  {
1196  edm::LogInfo("Alignment") << "@SUB=HIPAlignmentAlgorithm::calcParameters" << "Begin: Processing detector " << ali->id();
1197 
1198  // Alignment parameters
1200  const HIPAlignableSpecificParameters* alispecifics = findAlignableSpecs(ali);
1201  // access user variables
1202  HIPUserVariables* uservar = dynamic_cast<HIPUserVariables*>(par->userVariables());
1203  int nhit = uservar->nhit;
1204  // The following variable is needed for the extended 1D/2D hit fix using
1205  // matrix shrinkage and expansion
1206  // int hitdim = uservar->hitdim;
1207 
1208  // Test nhits
1209  int minHitThreshold = (!theApplyCutsPerComponent ? defaultAlignableSpecs.minNHits : alispecifics->minNHits);
1210  if (!isCollector) minHitThreshold=1;
1211  if (setDet==0 && nhit<minHitThreshold){
1212  edm::LogInfo("Alignment") << "@SUB=HIPAlignmentAlgorithm::calcParameters" << "Skipping detector " << ali->id() << " because number of hits = " << nhit << " <= " << minHitThreshold;
1213  par->setValid(false);
1214  return false;
1215  }
1216 
1217  AlgebraicSymMatrix jtvj = uservar->jtvj;
1218  AlgebraicVector jtve = uservar->jtve;
1219 
1220  // these are the alignment corrections+covariance (for selected params)
1221  int npar = jtve.num_row();
1222  AlgebraicVector params(npar);
1223  AlgebraicVector paramerr(npar);
1224  AlgebraicSymMatrix cov(npar);
1225 
1226  // errors of parameters
1227  if (isCollector){
1228  if (setDet==0){
1229  int ierr;
1230  AlgebraicSymMatrix jtvjinv = jtvj.inverse(ierr);
1231  if (ierr!=0){
1232  edm::LogError("Alignment") << "@SUB=HIPAlignmentAlgorithm::calcParameters" << "Matrix inversion failed!";
1233  return false;
1234  }
1235  params = -(jtvjinv * jtve);
1236  cov = jtvjinv;
1237 
1238  double minRelErrThreshold = (!theApplyCutsPerComponent ? defaultAlignableSpecs.minRelParError : alispecifics->minRelParError);
1239  double maxRelErrThreshold = (!theApplyCutsPerComponent ? defaultAlignableSpecs.maxRelParError : alispecifics->maxRelParError);
1240  for (int i=0; i<npar; i++){
1241  double relerr=0;
1242  if (fabs(cov[i][i])>0.) paramerr[i] = sqrt(fabs(cov[i][i]));
1243  else paramerr[i] = params[i];
1244  if (params[i]!=0.) relerr = fabs(paramerr[i]/params[i]);
1245  if ((maxRelErrThreshold>=0. && relerr>maxRelErrThreshold) || relerr<minRelErrThreshold){
1246  edm::LogWarning("Alignment")
1247  << "@SUB=HIPAlignmentAlgorithm::calcParameters" << "RelError = " << relerr
1248  << " > " << maxRelErrThreshold << " or < " << minRelErrThreshold
1249  << ". Setting param = paramerr = 0 for component " << i;
1250  params[i]=0;
1251  paramerr[i]=0;
1252  }
1253  }
1254  }
1255  else{
1256  if (params.num_row()!=1){
1257  edm::LogError("Alignment") << "@SUB=HIPAlignmentAlgorithm::calcParameters" << "For scanning, please only turn on one parameter! check common_cff_py.txt";
1258  return false;
1259  }
1260  if (theIteration==1) params[0] = start;
1261  else params[0]=step;
1262  edm::LogWarning("Alignment") << "@SUB=HIPAlignmentAlgorithm::calcParameters" << "Parameters = " << params;
1263  }
1264  }
1265 
1266  uservar->alipar=params;
1267  uservar->alierr=paramerr;
1268 
1269  AlignmentParameters* parnew = par->cloneFromSelected(params, cov);
1270  ali->setAlignmentParameters(parnew);
1271  parnew->setValid(true);
1272 
1273  edm::LogInfo("Alignment") << "@SUB=HIPAlignmentAlgorithm::calcParameters" << "End: Processing detector " << ali->id();
1274 
1275  return true;
1276 }
align::ID id() const
Return the ID of Alignable, i.e. DetId of &#39;first&#39; component GeomDet(Unit).
Definition: Alignable.h:189
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:61
AlgebraicSymMatrix jtvj
AlignmentUserVariables * userVariables(void) const
Get pointer to user variables.
void setAlignmentParameters(AlignmentParameters *dap)
Set the AlignmentParameters.
Definition: Alignable.cc:127
void setValid(bool v)
Set validity flag.
AlgebraicVector alierr
T sqrt(T t)
Definition: SSEVec.h:18
CLHEP::HepVector AlgebraicVector
CLHEP::HepSymMatrix AlgebraicSymMatrix
step
Definition: StallMonitor.cc:94
void HIPAlignmentAlgorithm::collectMonitorTrees ( const std::vector< std::string > &  filenames)
private

Definition at line 1417 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().

1417  {
1418  if (!doTrackHitMonitoring) return;
1419  if (!isCollector) throw cms::Exception("LogicError")
1420  << "[HIPAlignmentAlgorithm::collectMonitorTrees] Called in non-collector mode."
1421  << std::endl;
1422 
1423  TString theTrackMonitorTreeName=Form("T1_%i", theIteration);
1424  TString theHitMonitorTreeName=Form("T1_hit_%i", theIteration);
1425 
1426  std::vector<TFile*> finputlist;
1427  TList* eventtrees = new TList;
1428  TList* hittrees = new TList;
1429  for (std::string const& filename : filenames){
1430  TFile* finput = TFile::Open(filename.c_str(), "read");
1431  if (finput!=nullptr){
1432  TTree* tmptree;
1434  tmptree=nullptr;
1435  tmptree = (TTree*)finput->Get(theTrackMonitorTreeName);
1436  if (tmptree!=nullptr) eventtrees->Add(tmptree);
1437  }
1439  tmptree=nullptr;
1440  tmptree = (TTree*)finput->Get(theHitMonitorTreeName);
1441  if (tmptree!=nullptr) hittrees->Add((TTree*)finput->Get(theHitMonitorTreeName));
1442  }
1443  finputlist.push_back(finput);
1444  }
1445  }
1446 
1447  if (theTrackHitMonitorIORootFile!=nullptr){ // This should never happen
1448  edm::LogError("Alignment") << "@SUB=HIPAlignmentAlgorithm::collectMonitorTrees"
1449  << "Monitor file is already open while it is not supposed to be!";
1450  delete theTrackMonitorTree; theTrackMonitorTree=nullptr;
1451  delete theHitMonitorTree; theHitMonitorTree=nullptr;
1453  }
1454  theTrackHitMonitorIORootFile = TFile::Open(theMonitorConfig.outfile.c_str(), "update");
1456  if (eventtrees->GetSize()>0) theTrackMonitorTree = TTree::MergeTrees(eventtrees);
1457  if (hittrees->GetSize()>0) theHitMonitorTree = TTree::MergeTrees(hittrees);
1458  // Leave it to HIPAlignmentAlgorithm::terminate to write the trees and close theTrackHitMonitorIORootFile
1459 
1460  delete hittrees;
1461  delete eventtrees;
1462  for (TFile*& finput : finputlist) finput->Close();
1463 
1464  // Rename the trees to standard names
1465  if (theTrackMonitorTree!=nullptr) theTrackMonitorTree->SetName(theTrackMonitorTreeName);
1466  if (theHitMonitorTree!=nullptr) theHitMonitorTree->SetName(theHitMonitorTreeName);
1467 }
const bool fillTrackHitMonitoring
const bool fillTrackMonitoring
HIPMonitorConfig theMonitorConfig
void HIPAlignmentAlgorithm::collector ( void  )
private

Definition at line 1279 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().

1279  {
1280  edm::LogInfo("Alignment") << "@SUB=HIPAlignmentAlgorithm::collector" << "Called for iteration " << theIteration;
1281 
1282  std::vector<std::string> monitorFileList;
1283  HIPUserVariablesIORoot HIPIO;
1284 
1285  typedef int pawt_t;
1286  std::unordered_map<Alignable*, std::unordered_map<int, pawt_t> > ali_datatypecountpair_map;
1287  if (rewgtPerAli){
1288  edm::LogInfo("Alignment") << "@SUB=HIPAlignmentAlgorithm::collector" << "Per-alignable reweighting is turned on. Iterating over the parallel jobs to sum number of hits per alignable for each data type.";
1289  // Counting step for per-alignable reweighting
1290  for (int ijob=1; ijob<=theCollectorNJobs; ijob++){
1291  edm::LogInfo("Alignment") << "@SUB=HIPAlignmentAlgorithm::collector" << "Pre-reading uservar for job " << ijob;
1292 
1293  std::string str = std::to_string(ijob);
1294  std::string uvfile = theCollectorPath+"/job"+str+"/"+suvarfilecore;
1295 
1296  std::vector<AlignmentUserVariables*> uvarvec = HIPIO.readHIPUserVariables(theAlignables, uvfile.c_str(), theIteration, ioerr);
1297  if (uvarvec.size()!=theAlignables.size()) edm::LogWarning("Alignment")
1298  << "@SUB=HIPAlignmentAlgorithm::collector"
1299  << "Number of alignables = " << theAlignables.size() << " is not the same as number of user variables = " << uvarvec.size()
1300  << ". A mismatch might occur!";
1301  if (ioerr!=0){
1302  edm::LogError("Alignment") << "@SUB=HIPAlignmentAlgorithm::collector" << "Could not read user variable files for job " << ijob << " in iteration " << theIteration;
1303  continue;
1304  }
1305  std::vector<AlignmentUserVariables*>::const_iterator iuvar=uvarvec.begin(); // This vector should have 1-to-1 correspondence with the alignables vector
1306  for (const auto& ali: theAlignables){
1307  // No need for the user variables already attached to the alignables
1308  // Just count from what you read.
1309  HIPUserVariables* uvar = dynamic_cast<HIPUserVariables*>(*iuvar);
1310  if (uvar!=nullptr){
1311  int alijobdtype = uvar->datatype;
1312  pawt_t alijobnhits = uvar->nhit;
1313  if (ali_datatypecountpair_map.find(ali)==ali_datatypecountpair_map.end()){ // This is a new alignable
1314  std::unordered_map<int, pawt_t> newmap;
1315  ali_datatypecountpair_map[ali] = newmap;
1316  ali_datatypecountpair_map[ali][alijobdtype] = alijobnhits;
1317  }
1318  else{ // Alignable already exists in the map
1319  std::unordered_map<int, pawt_t>& theMap = ali_datatypecountpair_map[ali];
1320  if (theMap.find(alijobdtype)==theMap.end()) theMap[alijobdtype]=alijobnhits;
1321  else theMap[alijobdtype] += alijobnhits;
1322  }
1323  delete uvar; // Delete new user variables as they are added
1324  }
1325  iuvar++;
1326  } // End loop over alignables
1327  } // End loop over subjobs
1328  }
1329 
1330  for (int ijob=1; ijob<=theCollectorNJobs; ijob++){
1331  edm::LogInfo("Alignment") << "@SUB=HIPAlignmentAlgorithm::collector" << "Reading uservar for job " << ijob;
1332 
1333  std::string str = std::to_string(ijob);
1334  std::string uvfile = theCollectorPath+"/job"+str+"/"+suvarfilecore;
1335 
1336  std::vector<AlignmentUserVariables*> uvarvec = HIPIO.readHIPUserVariables(theAlignables, uvfile.c_str(), theIteration, ioerr);
1337  if (uvarvec.size()!=theAlignables.size()) edm::LogWarning("Alignment")
1338  << "@SUB=HIPAlignmentAlgorithm::collector"
1339  << "Number of alignables = " << theAlignables.size() << " is not the same as number of user variables = " << uvarvec.size()
1340  << ". A mismatch might occur!";
1341 
1342  if (ioerr!=0){
1343  edm::LogError("Alignment") << "@SUB=HIPAlignmentAlgorithm::collector" << "Could not read user variable files for job " << ijob << " in iteration " << theIteration;
1344  continue;
1345  }
1346 
1347  // add
1348  std::vector<AlignmentUserVariables*> uvarvecadd;
1349  std::vector<AlignmentUserVariables*>::const_iterator iuvarnew=uvarvec.begin();
1350  for (const auto& ali: theAlignables){
1351  AlignmentParameters* ap = ali->alignmentParameters();
1352 
1353  HIPUserVariables* uvarold = dynamic_cast<HIPUserVariables*>(ap->userVariables());
1354  HIPUserVariables* uvarnew = dynamic_cast<HIPUserVariables*>(*iuvarnew);
1355 
1356  HIPUserVariables* uvar = uvarold->clone();
1357  uvar->datatype=theDataGroup; // Set the data type of alignable to that specified for the collector job (-2 by default)
1358 
1359  if (uvarnew!=nullptr){
1360  double peraliwgt=1;
1361  if (rewgtPerAli){
1362  int alijobdtype = uvarnew->datatype;
1363  if (
1364  ali_datatypecountpair_map.find(ali)!=ali_datatypecountpair_map.end()
1365  &&
1366  ali_datatypecountpair_map[ali].find(alijobdtype)!=ali_datatypecountpair_map[ali].end()
1367  ){
1368  peraliwgt = ali_datatypecountpair_map[ali][alijobdtype];
1369  unsigned int nNonZeroTypes=0;
1370  pawt_t sumwgts=0;
1371  for (auto it=ali_datatypecountpair_map[ali].cbegin(); it!=ali_datatypecountpair_map[ali].cend(); ++it){
1372  sumwgts+=it->second;
1373  if (it->second!=pawt_t(0)) nNonZeroTypes++;
1374  }
1375  edm::LogInfo("Alignment") << "@SUB=HIPAlignmentAlgorithm::collector"
1376  << "Reweighting detector " << ali->id() << " / " << ali->alignableObjectId()
1377  << " for data type " << alijobdtype << " by " << sumwgts << "/" << peraliwgt << "/" << nNonZeroTypes;
1378  peraliwgt=((nNonZeroTypes==0 || peraliwgt==double(0)) ? double(1) : double((double(sumwgts))/peraliwgt/(double(nNonZeroTypes))));
1379  }
1380  else if (ali_datatypecountpair_map.find(ali)!=ali_datatypecountpair_map.end())
1381  edm::LogError("Alignment") << "@SUB=HIPAlignmentAlgorithm::collector"
1382  << "Could not find data type " << alijobdtype << " for detector " << ali->id() << " / " << ali->alignableObjectId();
1383  else
1384  edm::LogError("Alignment") << "@SUB=HIPAlignmentAlgorithm::collector"
1385  << "Could not find detector " << ali->id() << " / " << ali->alignableObjectId()
1386  << " in the map ali_datatypecountpair_map";
1387  }
1388 
1389  uvar->nhit = (uvarold->nhit) + (uvarnew->nhit);
1390  uvar->jtvj = (uvarold->jtvj) + peraliwgt*(uvarnew->jtvj);
1391  uvar->jtve = (uvarold->jtve) + peraliwgt*(uvarnew->jtve);
1392  uvar->alichi2 = (uvarold->alichi2) + peraliwgt*(uvarnew->alichi2);
1393  uvar->alindof = (uvarold->alindof) + (uvarnew->alindof);
1394 
1395  delete uvarnew; // Delete new user variables as they are added
1396  }
1397 
1398  uvarvecadd.push_back(uvar);
1399  iuvarnew++;
1400  }
1401 
1402  theAlignmentParameterStore->attachUserVariables(theAlignables, uvarvecadd, ioerr);
1403 
1404  // fill Eventwise Tree
1405  if (doTrackHitMonitoring){
1406  uvfile = theCollectorPath+"/job"+str+"/"+theMonitorConfig.outfilecore;
1407  monitorFileList.push_back(uvfile);
1408  }
1409  } // end loop on jobs
1410 
1411  // Collect monitor (eventwise and hitwise) trees
1412  if (doTrackHitMonitoring) collectMonitorTrees(monitorFileList);
1413 
1414 }
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 1103 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().

1103  {
1104  if (theAlignablesMonitorIORootFile==(TFile*)nullptr) return;
1105  using std::setw;
1107 
1108  int naligned=0;
1109 
1110  //Retrieve tracker topology from geometry
1111  edm::ESHandle<TrackerTopology> tTopoHandle;
1112  // iSetup.get<IdealGeometryRecord>().get(tTopoHandle);
1113  iSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
1114 
1115  const TrackerTopology* const tTopo = tTopoHandle.product();
1116 
1117  for (const auto& ali: theAlignables){
1118  AlignmentParameters* dap = ali->alignmentParameters();
1119 
1120  // consider only those parameters classified as 'valid'
1121  if (dap->isValid()){
1122  // get number of hits from user variable
1123  HIPUserVariables* uservar = dynamic_cast<HIPUserVariables*>(dap->userVariables());
1124  m2_Nhit = uservar->nhit;
1125  m2_datatype = uservar->datatype;
1126 
1127  // get type/layer
1128  std::pair<int, int> tl = theAlignmentParameterStore->typeAndLayer(ali, tTopo);
1129  m2_Type = tl.first;
1130  m2_Layer = tl.second;
1131 
1132  // get identifier (as for IO)
1133  m2_Id = ali->id();
1134  m2_ObjId = ali->alignableObjectId();
1135 
1136  // get position
1137  GlobalPoint pos = ali->surface().position();
1138  m2_Xpos = pos.x();
1139  m2_Ypos = pos.y();
1140  m2_Zpos = pos.z();
1141 
1142  m2_surfDef.clear();
1143  {
1144  std::vector<std::pair<int, SurfaceDeformation*> > dali_id_pairs;
1145  SurfaceDeformation* dali_obj=nullptr;
1147  std::vector<double> dali;
1148  if (1 == ali->surfaceDeformationIdPairs(dali_id_pairs)){
1149  dali_obj = dali_id_pairs[0].second;
1150  dali = dali_obj->parameters();
1151  dtype = (SurfaceDeformationFactory::Type)dali_obj->type();
1152  }
1153  for (auto& dit : dali) m2_surfDef.push_back((float)dit);
1154  m2_dtype = dtype;
1155  m2_nsurfdef = m2_surfDef.size();
1156  }
1157 
1158  if (verbose){
1159  AlgebraicVector pars = dap->parameters();
1160  edm::LogVerbatim("Alignment")
1161  << "------------------------------------------------------------------------\n"
1162  << " ALIGNABLE: " << setw(6) << naligned
1163  << '\n'
1164  << "hits: " << setw(4) << m2_Nhit
1165  << " type: " << setw(4) << m2_Type
1166  << " layer: " << setw(4) << m2_Layer
1167  << " id: " << setw(4) << m2_Id
1168  << " objId: " << setw(4) << m2_ObjId
1169  << '\n'
1170  << std::fixed << std::setprecision(5)
1171  << "x,y,z: "
1172  << setw(12) << m2_Xpos
1173  << setw(12) << m2_Ypos
1174  << setw(12) << m2_Zpos
1175  << "\nDeformations type, nDeformations: "
1176  << setw(12) << m2_dtype
1177  << setw(12) << m2_nsurfdef
1178  << '\n'
1179  << "params: "
1180  << setw(12) << pars[0]
1181  << setw(12) << pars[1]
1182  << setw(12) << pars[2]
1183  << setw(12) << pars[3]
1184  << setw(12) << pars[4]
1185  << setw(12) << pars[5];
1186  }
1187 
1188  naligned++;
1189  if (theAlignablesMonitorTree!=nullptr) theAlignablesMonitorTree->Fill();
1190  }
1191  }
1192 }
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:63
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:64
CLHEP::HepVector AlgebraicVector
align::Alignables theAlignables
std::vector< float > m2_surfDef
bool isValid(void) const
Get validity flag.
T x() const
Definition: PV3DBase.h:62
T const * product() const
Definition: ESHandle.h:86
SurfaceDeformationFactory::Type m2_dtype
HIPAlignableSpecificParameters * HIPAlignmentAlgorithm::findAlignableSpecs ( const Alignable ali)
private

Definition at line 1470 of file HIPAlignmentAlgorithm.cc.

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

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

1470  {
1471  if (ali!=nullptr){
1472  for (std::vector<HIPAlignableSpecificParameters>::iterator it=theAlignableSpecifics.begin(); it!=theAlignableSpecifics.end(); it++){
1473  if (it->matchAlignable(ali)) return &(*it);
1474  }
1475  edm::LogInfo("Alignment") << "[HIPAlignmentAlgorithm::findAlignableSpecs] Alignment object with id " << ali->id() << " / " << ali->alignableObjectId() << " could not be found. Returning default.";
1476  }
1477  return &defaultAlignableSpecs;
1478 }
align::ID id() const
Return the ID of Alignable, i.e. DetId of &#39;first&#39; component GeomDet(Unit).
Definition: Alignable.h:189
std::vector< 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 125 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, hcalDigis_cfi::level, HIPAlignableSpecificParameters::maxHitPull, HIPAlignableSpecificParameters::maxPixelProbQ, HIPAlignableSpecificParameters::maxPixelProbXY, HIPAlignableSpecificParameters::maxRelParError, HIPAlignableSpecificParameters::minNHits, HIPAlignableSpecificParameters::minPixelProbQ, HIPAlignableSpecificParameters::minPixelProbXY, HIPAlignableSpecificParameters::minRelParError, metsig::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, trackingTruthProducer_cfi::tracker, and HIPAlignableSpecificParameters::usePixelProbXYOrProbQ.

Referenced by ~HIPAlignmentAlgorithm().

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

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

492  {
493  static const unsigned int hitDim = 1;
494  if (hitwt==0.) return false;
495 
496  // get trajectory impact point
497  LocalPoint alvec = tsos.localPosition();
498  AlgebraicVector pos(hitDim);
499  pos[0] = alvec.x();
500 
501  // get impact point covariance
502  AlgebraicSymMatrix ipcovmat(hitDim);
503  ipcovmat[0][0] = tsos.localError().positionError().xx();
504 
505  // get hit local position and covariance
506  AlgebraicVector coor(hitDim);
507  coor[0] = hit->localPosition().x();
508 
509  AlgebraicSymMatrix covmat(hitDim);
510  covmat[0][0] = hit->localPositionError().xx();
511 
512  // add hit and impact point covariance matrices
513  covmat = covmat + ipcovmat;
514 
515  // calculate the x pull of this hit
516  double xpull = 0.;
517  if (covmat[0][0] != 0.) xpull = (pos[0] - coor[0])/sqrt(fabs(covmat[0][0]));
518 
519  // get Alignment Parameters
520  AlignmentParameters* params = ali->alignmentParameters();
521  HIPUserVariables* uservar = dynamic_cast<HIPUserVariables*>(params->userVariables());
522  uservar->datatype = theDataGroup;
523  // get derivatives
524  AlgebraicMatrix derivs2D = params->selectedDerivatives(tsos, alidet);
525  // calculate user parameters
526  int npar = derivs2D.num_row();
527  AlgebraicMatrix derivs(npar, hitDim, 0); // This is jT
528 
529  for (int ipar=0; ipar<npar; ipar++){
530  for (unsigned int idim=0; idim<hitDim; idim++){
531  derivs[ipar][idim] = derivs2D[ipar][idim];
532  }
533  }
534 
535  // invert covariance matrix
536  int ierr;
537  covmat.invert(ierr);
538  if (ierr != 0){
539  edm::LogError("Alignment") << "@SUB=HIPAlignmentAlgorithm::processHit1D" << "Cov. matrix inversion failed!";
540  return false;
541  }
542 
543  double maxHitPullThreshold = (!theApplyCutsPerComponent ? defaultAlignableSpecs.maxHitPull : alispecifics->maxHitPull);
544  bool useThisHit = (maxHitPullThreshold < 0.);
545  useThisHit |= (fabs(xpull) < maxHitPullThreshold);
546  if (!useThisHit){
547  edm::LogInfo("Alignment") << "@SUB=HIPAlignmentAlgorithm::processHit2D" << "Hit pull (x) " << xpull << " fails the cut " << maxHitPullThreshold;
548  return false;
549  }
550 
551  AlgebraicMatrix covtmp(covmat);
552  AlgebraicMatrix jtvjtmp(derivs * covtmp *derivs.T());
553  AlgebraicSymMatrix thisjtvj(npar);
554  AlgebraicVector thisjtve(npar);
555  thisjtvj.assign(jtvjtmp);
556  thisjtve=derivs * covmat * (pos-coor);
557 
558  AlgebraicVector hitresidual(hitDim);
559  hitresidual[0] = (pos[0] - coor[0]);
560 
561  AlgebraicMatrix hitresidualT;
562  hitresidualT = hitresidual.T();
563 
564  uservar->jtvj += hitwt*thisjtvj;
565  uservar->jtve += hitwt*thisjtve;
566  uservar->nhit++;
567 
568  //for alignable chi squared
569  float thischi2;
570  thischi2 = hitwt*(hitresidualT *covmat *hitresidual)[0];
571 
572  if (verbose && (thischi2/ static_cast<float>(uservar->nhit))>10.)
573  edm::LogWarning("Alignment") << "[HIPAlignmentAlgorithm::processHit1D] Added to Chi2 the number " << thischi2 << " having "
574  << uservar->nhit << " ndof"
575  << ", X-resid " << hitresidual[0]
576  << ", Cov^-1 matr (covmat):"
577  << " [0][0] = " << covmat[0][0];
578 
579  uservar->alichi2 += thischi2;
580  uservar->alindof += hitDim;
581 
582  return true;
583 }
float xx() const
Definition: LocalError.h:24
HIPAlignableSpecificParameters defaultAlignableSpecs
AlgebraicVector jtve
LocalError positionError() const
AlignmentParameters * alignmentParameters() const
Get the AlignmentParameters.
Definition: Alignable.h:61
AlgebraicSymMatrix jtvj
AlignmentUserVariables * userVariables(void) const
Get pointer to user variables.
CLHEP::HepMatrix AlgebraicMatrix
T sqrt(T t)
Definition: SSEVec.h:18
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:62
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 585 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, 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().

592  {
593  static const unsigned int hitDim = 2;
594  if (hitwt==0.) return false;
595 
596  // get trajectory impact point
597  LocalPoint alvec = tsos.localPosition();
598  AlgebraicVector pos(hitDim);
599  pos[0] = alvec.x();
600  pos[1] = alvec.y();
601 
602  // get impact point covariance
603  AlgebraicSymMatrix ipcovmat(hitDim);
604  ipcovmat[0][0] = tsos.localError().positionError().xx();
605  ipcovmat[1][1] = tsos.localError().positionError().yy();
606  ipcovmat[0][1] = tsos.localError().positionError().xy();
607 
608  // get hit local position and covariance
609  AlgebraicVector coor(hitDim);
610  coor[0] = hit->localPosition().x();
611  coor[1] = hit->localPosition().y();
612 
613  AlgebraicSymMatrix covmat(hitDim);
614  covmat[0][0] = hit->localPositionError().xx();
615  covmat[1][1] = hit->localPositionError().yy();
616  covmat[0][1] = hit->localPositionError().xy();
617 
618  // add hit and impact point covariance matrices
619  covmat = covmat + ipcovmat;
620 
621  // calculate the x pull and y pull of this hit
622  double xpull = 0.;
623  double ypull = 0.;
624  if (covmat[0][0] != 0.) xpull = (pos[0] - coor[0])/sqrt(fabs(covmat[0][0]));
625  if (covmat[1][1] != 0.) ypull = (pos[1] - coor[1])/sqrt(fabs(covmat[1][1]));
626 
627  // get Alignment Parameters
628  AlignmentParameters* params = ali->alignmentParameters();
629  HIPUserVariables* uservar = dynamic_cast<HIPUserVariables*>(params->userVariables());
630  uservar->datatype = theDataGroup;
631  // get derivatives
632  AlgebraicMatrix derivs2D = params->selectedDerivatives(tsos, alidet);
633  // calculate user parameters
634  int npar = derivs2D.num_row();
635  AlgebraicMatrix derivs(npar, hitDim, 0); // This is jT
636 
637  for (int ipar=0; ipar<npar; ipar++){
638  for (unsigned int idim=0; idim<hitDim; idim++){
639  derivs[ipar][idim] = derivs2D[ipar][idim];
640  }
641  }
642 
643  // invert covariance matrix
644  int ierr;
645  covmat.invert(ierr);
646  if (ierr != 0){
647  edm::LogError("Alignment") << "@SUB=HIPAlignmentAlgorithm::processHit2D" << "Cov. matrix inversion failed!";
648  return false;
649  }
650 
651  double maxHitPullThreshold = (!theApplyCutsPerComponent ? defaultAlignableSpecs.maxHitPull : alispecifics->maxHitPull);
652  bool useThisHit = (maxHitPullThreshold < 0.);
653  useThisHit |= (fabs(xpull) < maxHitPullThreshold && fabs(ypull) < maxHitPullThreshold);
654  if (!useThisHit){
655  edm::LogInfo("Alignment") << "@SUB=HIPAlignmentAlgorithm::processHit2D" << "Hit pull (x,y) " << xpull << " , " << ypull << " fails the cut " << maxHitPullThreshold;
656  return false;
657  }
658 
659  AlgebraicMatrix covtmp(covmat);
660  AlgebraicMatrix jtvjtmp(derivs * covtmp *derivs.T());
661  AlgebraicSymMatrix thisjtvj(npar);
662  AlgebraicVector thisjtve(npar);
663  thisjtvj.assign(jtvjtmp);
664  thisjtve=derivs * covmat * (pos-coor);
665 
666  AlgebraicVector hitresidual(hitDim);
667  hitresidual[0] = (pos[0] - coor[0]);
668  hitresidual[1] = (pos[1] - coor[1]);
669 
670  AlgebraicMatrix hitresidualT;
671  hitresidualT = hitresidual.T();
672 
673  uservar->jtvj += hitwt*thisjtvj;
674  uservar->jtve += hitwt*thisjtve;
675  uservar->nhit++;
676 
677  //for alignable chi squared
678  float thischi2;
679  thischi2 = hitwt*(hitresidualT *covmat *hitresidual)[0];
680 
681  if (verbose && (thischi2/ static_cast<float>(uservar->nhit))>10.)
682  edm::LogWarning("Alignment") << "[HIPAlignmentAlgorithm::processHit2D] Added to Chi2 the number " << thischi2 << " having "
683  << uservar->nhit << " ndof"
684  << ", X-resid " << hitresidual[0]
685  << ", Y-resid " << hitresidual[1]
686  << ", Cov^-1 matr (covmat):"
687  << " [0][0] = " << covmat[0][0]
688  << " [0][1] = " << covmat[0][1]
689  << " [1][0] = " << covmat[1][0]
690  << " [1][1] = " << covmat[1][1];
691 
692  uservar->alichi2 += thischi2;
693  uservar->alindof += hitDim;
694 
695  return true;
696 }
float xx() const
Definition: LocalError.h:24
HIPAlignableSpecificParameters defaultAlignableSpecs
T y() const
Definition: PV3DBase.h:63
AlgebraicVector jtve
LocalError positionError() const
AlignmentParameters * alignmentParameters() const
Get the AlignmentParameters.
Definition: Alignable.h:61
AlgebraicSymMatrix jtvj
AlignmentUserVariables * userVariables(void) const
Get pointer to user variables.
float xy() const
Definition: LocalError.h:25
CLHEP::HepMatrix AlgebraicMatrix
float yy() const
Definition: LocalError.h:26
T sqrt(T t)
Definition: SSEVec.h:18
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:62
virtual AlgebraicMatrix selectedDerivatives(const TrajectoryStateOnSurface &tsos, const AlignableDetOrUnitPtr &alidet) const
int HIPAlignmentAlgorithm::readIterationFile ( std::string  filename)
private

Definition at line 949 of file HIPAlignmentAlgorithm.cc.

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

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

949  {
950  int result;
951 
952  std::ifstream inIterFile(filename.c_str(), std::ios::in);
953  if (!inIterFile) {
954  edm::LogError("Alignment") << "[HIPAlignmentAlgorithm::readIterationFile] ERROR! "
955  << "Unable to open Iteration file";
956  result = -1;
957  }
958  else {
959  inIterFile >> result;
960  edm::LogWarning("Alignment") << "[HIPAlignmentAlgorithm::readIterationFile] "
961  << "Read last iteration number from file: " << result;
962  }
963  inIterFile.close();
964 
965  return result;
966 }
void HIPAlignmentAlgorithm::run ( const edm::EventSetup setup,
const EventInfo eventInfo 
)
overridevirtual

Run the algorithm.

Implements AlignmentAlgorithmBase.

Definition at line 699 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, allConversions_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(), funct::pow(), SiPixelRecHit::probabilityQ(), SiPixelRecHit::probabilityXY(), processHit1D(), processHit2D(), EnergyCorrector::pt, reco::TrackBase::pt(), alignCSCRings::r, SiPixelRecHit::rawQualityWord(), TrajectoryMeasurement::recHit(), Scale, AlignmentParameterStore::selectParameters(), mathSSE::sqrt(), DetId::subdetId(), theAlignableDetAccessor, theAlignmentParameterStore, theDataGroup, theEtaFormula, theMonitorConfig, HiIsolationCommonParameters_cff::track, HIPMonitorConfig::trackmonitorvars, trackPs, l1t::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().

699  {
700  if (isCollector) return;
701 
702  TrajectoryStateCombiner tsoscomb;
703 
705 
706  // loop over tracks
708  for (ConstTrajTrackPairCollection::const_iterator it=tracks.begin(); it!=tracks.end(); ++it){
709  const Trajectory* traj = (*it).first;
710  const reco::Track* track = (*it).second;
711 
712  float pt = track->pt();
713  float eta = track->eta();
714  float phi = track->phi();
715  float p = track->p();
716  float chi2n = track->normalizedChi2();
717  int nhit = track->numberOfValidHits();
718  float d0 = track->d0();
719  float dz = track->dz();
720 
721  int nhpxb = track->hitPattern().numberOfValidPixelBarrelHits();
722  int nhpxf = track->hitPattern().numberOfValidPixelEndcapHits();
723  int nhtib = track->hitPattern().numberOfValidStripTIBHits();
724  int nhtob = track->hitPattern().numberOfValidStripTOBHits();
725  int nhtid = track->hitPattern().numberOfValidStripTIDHits();
726  int nhtec = track->hitPattern().numberOfValidStripTECHits();
727 
728  if (verbose) edm::LogInfo("Alignment")
729  << "New track pt,eta,phi,chi2n,hits: "
730  << pt << ","
731  << eta << ","
732  << phi << ","
733  << chi2n << ","
734  << nhit;
735 
736  double ihitwt = 1;
737  double trkwt = 1;
738  if (trackWt){
739  trkwt=Scale;
740  // Reweight by the specified eta distribution
741  if (uniEta) trkwt *= theEtaFormula->Eval(fabs(eta));
742  }
743  if (trackPs){
744  double r = gRandom->Rndm();
745  if (trkwt < r) continue;
746  }
747  else if (trackWt) ihitwt=trkwt;
748 
749  // fill track parameters in root tree
750  {
751  theMonitorConfig.trackmonitorvars.m_Nhits.push_back(nhit);
752  theMonitorConfig.trackmonitorvars.m_Pt.push_back(pt);
754  theMonitorConfig.trackmonitorvars.m_Eta.push_back(eta);
755  theMonitorConfig.trackmonitorvars.m_Phi.push_back(phi);
756  theMonitorConfig.trackmonitorvars.m_Chi2n.push_back(chi2n);
757  theMonitorConfig.trackmonitorvars.m_nhPXB.push_back(nhpxb);
758  theMonitorConfig.trackmonitorvars.m_nhPXF.push_back(nhpxf);
759  theMonitorConfig.trackmonitorvars.m_nhTIB.push_back(nhtib);
760  theMonitorConfig.trackmonitorvars.m_nhTOB.push_back(nhtob);
761  theMonitorConfig.trackmonitorvars.m_nhTID.push_back(nhtid);
762  theMonitorConfig.trackmonitorvars.m_nhTEC.push_back(nhtec);
763  theMonitorConfig.trackmonitorvars.m_d0.push_back(d0);
764  theMonitorConfig.trackmonitorvars.m_dz.push_back(dz);
765  theMonitorConfig.trackmonitorvars.m_wt.push_back(ihitwt);
766  }
767 
768  std::vector<const TransientTrackingRecHit*> hitvec;
769  std::vector<TrajectoryStateOnSurface> tsosvec;
770 
771  // loop over measurements
772  std::vector<TrajectoryMeasurement> measurements = traj->measurements();
773  for (std::vector<TrajectoryMeasurement>::iterator im=measurements.begin(); im!=measurements.end(); ++im){
774 
775  TrajectoryMeasurement meas = *im;
776 
777  // const TransientTrackingRecHit* ttrhit = &(*meas.recHit());
778  // const TrackingRecHit *hit = ttrhit->hit();
779  const TransientTrackingRecHit* hit = &(*meas.recHit());
780 
781  if (hit->isValid() && theAlignableDetAccessor->detAndSubdetInMap(hit->geographicalId())){
782  // this is the updated state (including the current hit)
783  // TrajectoryStateOnSurface tsos=meas.updatedState();
784  // combine fwd and bwd predicted state to get state
785  // which excludes current hit
786 
788  if (eventInfo.clusterValueMap()){
789  // check from the PrescalingMap if the hit was taken.
790  // If not skip to the next TM
791  // bool hitTaken=false;
792  AlignmentClusterFlag myflag;
793 
794  int subDet = hit->geographicalId().subdetId();
795  //take the actual RecHit out of the Transient one
796  const TrackingRecHit *rechit=hit->hit();
797  if (subDet>2){ // AM: if possible use enum instead of hard-coded value
798  const std::type_info &type = typeid(*rechit);
799 
800  if (type == typeid(SiStripRecHit1D)){
801 
802  const SiStripRecHit1D* stripHit1D = dynamic_cast<const SiStripRecHit1D*>(rechit);
803  if (stripHit1D){
804  SiStripRecHit1D::ClusterRef stripclust(stripHit1D->cluster());
805  // myflag=PrescMap[stripclust];
806  myflag = (*eventInfo.clusterValueMap())[stripclust];
807  }
808  else edm::LogError("HIPAlignmentAlgorithm")
809  << "ERROR in <HIPAlignmentAlgorithm::run>: Dynamic cast of Strip RecHit failed! "
810  << "TypeId of the RecHit: " << className(*hit);
811  }//end if type = SiStripRecHit1D
812  else if (type == typeid(SiStripRecHit2D)){
813 
814  const SiStripRecHit2D* stripHit2D = dynamic_cast<const SiStripRecHit2D*>(rechit);
815  if (stripHit2D){
816  SiStripRecHit2D::ClusterRef stripclust(stripHit2D->cluster());
817  // myflag=PrescMap[stripclust];
818  myflag = (*eventInfo.clusterValueMap())[stripclust];
819  }
820  else edm::LogError("HIPAlignmentAlgorithm")
821  << "ERROR in <HIPAlignmentAlgorithm::run>: Dynamic cast of Strip RecHit failed! "
822  << "TypeId of the TTRH: " << className(*hit);
823  } //end if type == SiStripRecHit2D
824  } //end if hit from strips
825  else{
826  const SiPixelRecHit* pixelhit= dynamic_cast<const SiPixelRecHit*>(rechit);
827  if (pixelhit){
828  SiPixelClusterRefNew pixelclust(pixelhit->cluster());
829  // myflag=PrescMap[pixelclust];
830  myflag = (*eventInfo.clusterValueMap())[pixelclust];
831  }
832  else edm::LogError("HIPAlignmentAlgorithm")
833  << "ERROR in <HIPAlignmentAlgorithm::run>: Dynamic cast of Pixel RecHit failed! "
834  << "TypeId of the TTRH: " << className(*hit);
835  } //end 'else' it is a pixel hit
836  if (!myflag.isTaken()) continue;
837  }//end if Prescaled Hits
839 
840  TrajectoryStateOnSurface tsos = tsoscomb.combine(
841  meas.forwardPredictedState(),
843  );
844 
845  if (tsos.isValid()){
846  hitvec.push_back(hit);
847  tsosvec.push_back(tsos);
848  }
849 
850  } //hit valid
851  }
852 
853  // transform RecHit vector to AlignableDet vector
854  std::vector<AlignableDetOrUnitPtr> alidetvec = theAlignableDetAccessor->alignablesFromHits(hitvec);
855 
856  // get concatenated alignment parameters for list of alignables
858 
859  std::vector<TrajectoryStateOnSurface>::const_iterator itsos=tsosvec.begin();
860  std::vector<const TransientTrackingRecHit*>::const_iterator ihit=hitvec.begin();
861 
862  // loop over vectors(hit,tsos)
863  while (itsos != tsosvec.end()){
864  // get AlignableDet for this hit
865  const GeomDet* det = (*ihit)->det();
866  // int subDet= (*ihit)->geographicalId().subdetId();
867  uint32_t nhitDim = (*ihit)->dimension();
868 
869  AlignableDetOrUnitPtr alidet = theAlignableDetAccessor->alignableFromGeomDet(det);
870 
871  // get relevant Alignable
872  Alignable* ali = aap.alignableFromAlignableDet(alidet);
873 
874  if (ali!=nullptr){
875  const HIPAlignableSpecificParameters* alispecifics = findAlignableSpecs(ali);
876  const TrajectoryStateOnSurface& tsos = *itsos;
877 
878  // LocalVector v = tsos.localDirection();
879  // double proj_z = v.dot(LocalVector(0,0,1));
880 
881  //In fact, sin_theta=Abs(mom_z)
882  double mom_x = tsos.localDirection().x();
883  double mom_y = tsos.localDirection().y();
884  double mom_z = tsos.localDirection().z();
885  double sin_theta = TMath::Abs(mom_z) / sqrt(pow(mom_x, 2)+pow(mom_y, 2)+pow(mom_z, 2));
886  double angle = TMath::ASin(sin_theta);
887  double alihitwt=ihitwt;
888 
889  //Make cut on hit impact angle, reduce collision hits perpendicular to modules
890  if (IsCollision){ if (angle>col_cut)alihitwt=0; }
891  else{ if (angle<cos_cut)alihitwt=0; }
892 
893  // Fill hit monitor variables
897 
898  // Check pixel XY and Q probabilities
899  if ((*ihit)->hit()!=nullptr){
900  const SiPixelRecHit* pixhit = dynamic_cast<const SiPixelRecHit*>((*ihit)->hit());
901  if (pixhit!=nullptr){
904  // Prob X, Y are deprecated
908  if (alispecifics->applyPixelProbCut){
910  bool probQgood = (theMonitorConfig.hitmonitorvars.m_probQ>=alispecifics->minPixelProbQ && theMonitorConfig.hitmonitorvars.m_probQ<=alispecifics->maxPixelProbQ);
911  bool probXYQgood;
912  if (alispecifics->usePixelProbXYOrProbQ) probXYQgood = (probXYgood || probQgood);
913  else probXYQgood = (probXYgood && probQgood);
914  if (!probXYQgood) alihitwt=0;
915  }
916  }
917  }
918  }
919 
921  bool hitProcessed=false;
922  switch (nhitDim){
923  case 1:
924  hitProcessed=processHit1D(alidet, ali, alispecifics, tsos, *ihit, alihitwt);
925  break;
926  case 2:
927  hitProcessed=processHit2D(alidet, ali, alispecifics, tsos, *ihit, alihitwt);
928  break;
929  default:
930  edm::LogError("HIPAlignmentAlgorithm")
931  << "ERROR in <HIPAlignmentAlgorithm::run>: Number of hit dimensions = "
932  << nhitDim << " is not supported!"
933  << std::endl;
934  break;
935  }
937  }
938 
939  itsos++;
940  ihit++;
941  }
942  } // end of track loop
943 
944  // fill eventwise root tree (with prescale defined in pset)
946 }
ClusterRef cluster() const
double p() const
momentum vector magnitude
Definition: TrackBase.h:654
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:189
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:636
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:600
TSOS combine(const TSOS &pTsos1, const TSOS &pTsos2) const
LocalVector localDirection() const
HIPAlignableSpecificParameters * findAlignableSpecs(const Alignable *ali)
T y() const
Definition: PV3DBase.h:63
double phi() const
azimuthal angle of momentum vector
Definition: TrackBase.h:684
Alignable * alignableFromAlignableDet(const AlignableDetOrUnitPtr &adet) const
Get relevant Alignable from AlignableDet.
std::vector< int > m_Nhits
int numberOfValidStripTOBHits() const
Definition: HitPattern.h:946
std::unique_ptr< AlignableNavigator > theAlignableDetAccessor
const ConstTrajTrackPairCollection & trajTrackPairs() const
const bool fillTrackHitMonitoring
std::vector< float > m_Pt
DataContainer const & measurements() const
Definition: Trajectory.h:196
std::vector< int > m_nhPXB
std::vector< float > m_wt
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:690
int numberOfValidPixelBarrelHits() const
Definition: HitPattern.h:921
std::vector< int > m_nhTID
T sqrt(T t)
Definition: SSEVec.h:18
double pt() const
track transverse momentum
Definition: TrackBase.h:660
T z() const
Definition: PV3DBase.h:64
std::vector< float > m_Phi
HIPHitMonitorVariables hitmonitorvars
T Abs(T a)
Definition: MathUtil.h:49
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:41
std::vector< int > m_nhTEC
int numberOfValidStripTIDHits() const
Definition: HitPattern.h:941
ClusterRef cluster() const
unsigned short numberOfValidHits() const
number of valid hits found
Definition: TrackBase.h:901
int numberOfValidStripTECHits() const
Definition: HitPattern.h:951
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:648
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:485
HIPTrackMonitorVariables trackmonitorvars
ClusterRef cluster() const
Definition: SiPixelRecHit.h:49
CompositeAlignmentParameters selectParameters(const std::vector< AlignableDet * > &alignabledets) const
bool isValid() const
int numberOfValidStripTIBHits() const
Definition: HitPattern.h:936
std::unique_ptr< TFormula > theEtaFormula
int numberOfValidPixelEndcapHits() const
Definition: HitPattern.h:926
const AliClusterValueMap * clusterValueMap() const
HIPMonitorConfig theMonitorConfig
float probabilityXY() const
Definition: SiPixelRecHit.h:96
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:62
SiPixelRecHitQuality::QualWordType rawQualityWord() const
Definition: SiPixelRecHit.h:81
std::vector< float > m_Chi2n
float probabilityQ() const
Definition: SiPixelRecHit.h:99
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
std::string className(const T &t)
Definition: ClassName.h:30
TrajectoryStateOnSurface const & backwardPredictedState() const
Access to backward predicted state (from smoother)
Our base class.
Definition: SiPixelRecHit.h:23
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 982 of file HIPAlignmentAlgorithm.cc.

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

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

982  {
983  // Check if user wants to override APE
984  if (!theApplyAPE){
985  edm::LogInfo("Alignment") <<"[HIPAlignmentAlgorithm::setAlignmentPositionError] No APE applied";
986  return; // NO APE APPLIED
987  }
988 
989  edm::LogInfo("Alignment") <<"[HIPAlignmentAlgorithm::setAlignmentPositionError] Apply APE!";
990 
991  double apeSPar[3], apeRPar[3];
992  for (const auto& alipars: theAPEParameters) {
993  const auto& alignables = alipars.first;
994  const auto& pars = alipars.second;
995 
996  apeSPar[0] = pars[0];
997  apeSPar[1] = pars[1];
998  apeSPar[2] = pars[2];
999  apeRPar[0] = pars[3];
1000  apeRPar[1] = pars[4];
1001  apeRPar[2] = pars[5];
1002 
1003  int function = pars[6];
1004 
1005  // Printout for debug
1006  printf("APE: %u alignables\n", (unsigned int)alignables.size());
1007  for (int i=0; i<21; ++i) {
1008  double apelinstest=calcAPE(apeSPar, i, 0);
1009  double apeexpstest=calcAPE(apeSPar, i, 1);
1010  double apestepstest=calcAPE(apeSPar, i, 2);
1011  double apelinrtest=calcAPE(apeRPar, i, 0);
1012  double apeexprtest=calcAPE(apeRPar, i, 1);
1013  double apesteprtest=calcAPE(apeRPar, i, 2);
1014  printf("APE: iter slin sexp sstep rlin rexp rstep: %5d %12.5f %12.5f %12.5f %12.5f %12.5f %12.5f \n",
1015  i, apelinstest, apeexpstest, apestepstest, apelinrtest, apeexprtest, apesteprtest);
1016  }
1017 
1018  // set APE
1019  double apeshift = calcAPE(apeSPar, theIteration, function);
1020  double aperot = calcAPE(apeRPar, theIteration, function);
1021  theAlignmentParameterStore->setAlignmentPositionError(alignables, apeshift, aperot);
1022  }
1023 }
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 289 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().

289  {
290  edm::LogInfo("Alignment") << "@SUB=HIPAlignmentAlgorithm::startNewLoop" << "Begin";
291 
292  // iterate over all alignables and attach user variables
293  for (const auto& it: theAlignables){
294  AlignmentParameters* ap = it->alignmentParameters();
295  int npar=ap->numSelected();
296  HIPUserVariables* userpar = new HIPUserVariables(npar);
297  ap->setUserVariables(userpar);
298  }
299 
300  // try to read in alignment parameters from a previous iteration
301  AlignablePositions theAlignablePositionsFromFile = theIO.readAlignableAbsolutePositions(theAlignables, salignedfile.c_str(), -1, ioerr);
302  int numAlignablesFromFile = theAlignablePositionsFromFile.size();
303  if (numAlignablesFromFile==0){ // file not there: first iteration
304  // set iteration number to 1 when needed
305  if (isCollector) theIteration=0;
306  else theIteration=1;
307  edm::LogWarning("Alignment") << "@SUB=HIPAlignmentAlgorithm::startNewLoop" << "IO alignables file not found for iteration " << theIteration;
308  }
309  else{ // there have been previous iterations
310  edm::LogInfo("Alignment") << "@SUB=HIPAlignmentAlgorithm::startNewLoop" << "Alignables Read " << numAlignablesFromFile;
311 
312  // get iteration number from file
314  // Where is the target for this?
316 
317  // increase iteration
318  if (ioerr==0){
319  theIteration++;
320  edm::LogWarning("Alignment") << "@SUB=HIPAlignmentAlgorithm::startNewLoop" << "Iteration increased by one and is now " << theIteration;
321  }
322 
323  // now apply psotions of file from prev iteration
324  edm::LogInfo("Alignment") << "@SUB=HIPAlignmentAlgorithm::startNewLoop" << "Apply positions from file ...";
325  theAlignmentParameterStore->applyAlignableAbsolutePositions(theAlignables, theAlignablePositionsFromFile, ioerr);
326  }
327 
328  edm::LogWarning("Alignment") << "@SUB=HIPAlignmentAlgorithm::startNewLoop" << "Current Iteration number: " << theIteration;
329 
330 
331  // book root trees
332  bookRoot();
333 
334  // set alignment position error
336 
337  // run collector job if we are in parallel mode
338  if (isCollector) collector();
339 
340  edm::LogInfo("Alignment") << "@SUB=HIPAlignmentAlgorithm::startNewLoop" << "End";
341 }
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 344 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, checklumidiff::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().

344  {
345  edm::LogWarning("Alignment") << "[HIPAlignmentAlgorithm] Terminating";
346 
347  // calculating survey residuals
348  if (!theLevels.empty()){
349  edm::LogWarning("Alignment") << "[HIPAlignmentAlgorithm] Using survey constraint";
350 
351  unsigned int nAlignable = theAlignables.size();
352  edm::ESHandle<TrackerTopology> tTopoHandle;
353  iSetup.get<IdealGeometryRecord>().get(tTopoHandle);
354  const TrackerTopology* const tTopo = tTopoHandle.product();
355  for (unsigned int i = 0; i < nAlignable; ++i){
356  const Alignable* ali = theAlignables[i];
358  HIPUserVariables* uservar = dynamic_cast<HIPUserVariables*>(ap->userVariables());
359  int nhit = uservar->nhit;
360 
361  // get position
362  std::pair<int, int> tl = theAlignmentParameterStore->typeAndLayer(ali, tTopo);
363  int tmp_Type = tl.first;
364  int tmp_Layer = tl.second;
365  GlobalPoint pos = ali->surface().position();
366  float tmpz = pos.z();
367  if (nhit< 1500 || (tmp_Type==5 && tmp_Layer==4 && fabs(tmpz)>90)){ // FIXME: Needs revision for hardcoded consts
368  for (unsigned int l = 0; l < theLevels.size(); ++l){
369  SurveyResidual res(*ali, theLevels[l], true);
370 
371  if (res.valid()){
372  AlgebraicSymMatrix invCov = res.inverseCovariance();
373 
374  // variable for tree
375  AlgebraicVector sensResid = res.sensorResidual();
376  m3_Id = ali->id();
377  m3_ObjId = theLevels[l];
378  m3_par[0] = sensResid[0]; m3_par[1] = sensResid[1]; m3_par[2] = sensResid[2];
379  m3_par[3] = sensResid[3]; m3_par[4] = sensResid[4]; m3_par[5] = sensResid[5];
380 
381  uservar->jtvj += invCov;
382  uservar->jtve += invCov * sensResid;
383 
384  if (theSurveyTree!=nullptr) theSurveyTree->Fill();
385  }
386  }
387  }
388  }
389  }
390 
391  // write user variables
393  // don't store userVariable in main, to save time
395 
396  // now calculate alignment corrections...
397  int ialigned=0;
398  // iterate over alignment parameters
399  for (const auto& ali: theAlignables){
401 
402  if (SetScanDet.at(0)!=0){
403  edm::LogWarning("Alignment") << "********Starting Scan*********";
404  edm::LogWarning("Alignment") <<"det ID="<<SetScanDet.at(0)<<", starting position="<<SetScanDet.at(1)<<", step="<<SetScanDet.at(2)<<", currentDet = "<<ali->id();
405  }
406 
407  if ((SetScanDet.at(0)!=0)&&(SetScanDet.at(0)!=1)&&(ali->id()!=SetScanDet.at(0))) continue;
408 
409  bool test = calcParameters(ali, SetScanDet.at(0), SetScanDet.at(1), SetScanDet.at(2));
410  if (test){
411  if (dynamic_cast<AlignableDetUnit*>(ali)!=nullptr){
412  std::vector<std::pair<int, SurfaceDeformation*>> pairs;
413  ali->surfaceDeformationIdPairs(pairs);
414  edm::LogInfo("Alignment") << "@SUB=HIPAlignmentAlgorithm::terminate" << "The alignable contains " << pairs.size() << " surface deformations";
415  }
416  else edm::LogInfo("Alignment") << "@SUB=HIPAlignmentAlgorithm::terminate" << "The alignable cannot contain surface deformations";
417 
419  // set these parameters 'valid'
420  ali->alignmentParameters()->setValid(true);
421  // increase counter
422  ialigned++;
423  }
424  else par->setValid(false);
425  }
426  //end looping over alignables
427 
428  edm::LogWarning("Alignment") << "[HIPAlignmentAlgorithm::terminate] Aligned units: " << ialigned;
429 
430  // fill alignable wise root tree
431  fillAlignablesMonitor(iSetup);
432 
433  edm::LogWarning("Alignment")
434  << "[HIPAlignmentAlgorithm] Writing aligned parameters to file: " << theAlignables.size()
435  << ", for Iteration " << theIteration;
436 
437 
438  // write user variables
439  if (isCollector) HIPIO.writeHIPUserVariables(theAlignables, suvarfile.c_str(), theIteration, false, ioerr);
440 
441  // write new absolute positions to disk
442  theIO.writeAlignableAbsolutePositions(theAlignables, salignedfile.c_str(), theIteration, false, ioerr);
443 
444  // write alignment parameters to disk
445  //theIO.writeAlignmentParameters(theAlignables,
446  // sparameterfile.c_str(),theIteration,false,ioerr);
447 
448  // write iteration number to file
450 
451  // write out trees and close root file
452  // Survey tree
453  if (theSurveyIORootFile!=nullptr){
454  theSurveyIORootFile->cd();
455  if (theSurveyTree!=nullptr) theSurveyTree->Write();
456  delete theSurveyTree;
457  theSurveyTree=nullptr;
458  theSurveyIORootFile->Close();
459  }
460  // Alignable-wise tree is only filled once at iteration 1
461  if (theAlignablesMonitorIORootFile!=nullptr){
463  if (theAlignablesMonitorTree!=nullptr) theAlignablesMonitorTree->Write();
465  theAlignablesMonitorTree=nullptr;
467  }
468  // Eventwise and hitwise monitoring trees
469  if (theTrackHitMonitorIORootFile!=nullptr){
471  if (theTrackMonitorTree!=nullptr){
472  theTrackMonitorTree->Write();
473  delete theTrackMonitorTree;
474  theTrackMonitorTree=nullptr;
475  }
476  if (theHitMonitorTree!=nullptr){
477  theHitMonitorTree->Write();
478  delete theHitMonitorTree;
479  theHitMonitorTree=nullptr;
480  }
482  }
483 }
align::ID id() const
Return the ID of Alignable, i.e. DetId of &#39;first&#39; component GeomDet(Unit).
Definition: Alignable.h:189
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:61
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:64
std::vector< double > SetScanDet
const AlignableSurface & surface() const
Return the Surface (global position and orientation) of the object.
Definition: Alignable.h:135
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 969 of file HIPAlignmentAlgorithm.cc.

References MillePedeFileConverter_cfg::out.

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

969  {
970  std::ofstream outIterFile((filename.c_str()), std::ios::out);
971  if (!outIterFile) edm::LogError("Alignment")
972  << "[HIPAlignmentAlgorithm::writeIterationFile] ERROR: Unable to write Iteration file";
973  else{
974  outIterFile << iter;
975  edm::LogWarning("Alignment") <<"[HIPAlignmentAlgorithm::writeIterationFile] writing iteration number to file: " << iter;
976  }
977  outIterFile.close();
978 }

Member Data Documentation

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

Definition at line 90 of file HIPAlignmentAlgorithm.h.

Referenced by initialize().

double HIPAlignmentAlgorithm::col_cut
private

Definition at line 135 of file HIPAlignmentAlgorithm.h.

Referenced by HIPAlignmentAlgorithm(), and run().

double HIPAlignmentAlgorithm::cos_cut
private

Definition at line 135 of file HIPAlignmentAlgorithm.h.

Referenced by HIPAlignmentAlgorithm(), and run().

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

Definition at line 105 of file HIPAlignmentAlgorithm.h.

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

int HIPAlignmentAlgorithm::ioerr
private

Definition at line 96 of file HIPAlignmentAlgorithm.h.

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

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

Definition at line 133 of file HIPAlignmentAlgorithm.h.

Referenced by HIPAlignmentAlgorithm(), and run().

int HIPAlignmentAlgorithm::m2_datatype
private

Definition at line 160 of file HIPAlignmentAlgorithm.h.

Referenced by bookRoot(), and fillAlignablesMonitor().

SurfaceDeformationFactory::Type HIPAlignmentAlgorithm::m2_dtype
private

Definition at line 162 of file HIPAlignmentAlgorithm.h.

Referenced by bookRoot(), and fillAlignablesMonitor().

align::ID HIPAlignmentAlgorithm::m2_Id
private

Definition at line 157 of file HIPAlignmentAlgorithm.h.

Referenced by bookRoot(), and fillAlignablesMonitor().

int HIPAlignmentAlgorithm::m2_Layer
private

Definition at line 159 of file HIPAlignmentAlgorithm.h.

Referenced by bookRoot(), and fillAlignablesMonitor().

int HIPAlignmentAlgorithm::m2_Nhit
private

Definition at line 159 of file HIPAlignmentAlgorithm.h.

Referenced by bookRoot(), and fillAlignablesMonitor().

unsigned int HIPAlignmentAlgorithm::m2_nsurfdef
private

Definition at line 163 of file HIPAlignmentAlgorithm.h.

Referenced by bookRoot(), and fillAlignablesMonitor().

align::StructureType HIPAlignmentAlgorithm::m2_ObjId
private

Definition at line 158 of file HIPAlignmentAlgorithm.h.

Referenced by bookRoot(), and fillAlignablesMonitor().

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

Definition at line 164 of file HIPAlignmentAlgorithm.h.

Referenced by bookRoot(), and fillAlignablesMonitor().

int HIPAlignmentAlgorithm::m2_Type
private

Definition at line 159 of file HIPAlignmentAlgorithm.h.

Referenced by bookRoot(), and fillAlignablesMonitor().

float HIPAlignmentAlgorithm::m2_Xpos
private

Definition at line 161 of file HIPAlignmentAlgorithm.h.

Referenced by bookRoot(), and fillAlignablesMonitor().

float HIPAlignmentAlgorithm::m2_Ypos
private

Definition at line 161 of file HIPAlignmentAlgorithm.h.

Referenced by bookRoot(), and fillAlignablesMonitor().

float HIPAlignmentAlgorithm::m2_Zpos
private

Definition at line 161 of file HIPAlignmentAlgorithm.h.

Referenced by bookRoot(), and fillAlignablesMonitor().

align::ID HIPAlignmentAlgorithm::m3_Id
private

Definition at line 167 of file HIPAlignmentAlgorithm.h.

Referenced by bookRoot(), and terminate().

align::StructureType HIPAlignmentAlgorithm::m3_ObjId
private

Definition at line 168 of file HIPAlignmentAlgorithm.h.

Referenced by bookRoot(), and terminate().

float HIPAlignmentAlgorithm::m3_par[6]
private

Definition at line 169 of file HIPAlignmentAlgorithm.h.

Referenced by bookRoot(), and terminate().

int HIPAlignmentAlgorithm::m_datatype
private

Definition at line 154 of file HIPAlignmentAlgorithm.h.

Referenced by bookRoot(), and run().

std::string HIPAlignmentAlgorithm::outfile2
private

Definition at line 107 of file HIPAlignmentAlgorithm.h.

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

std::string HIPAlignmentAlgorithm::outpath
private

Definition at line 107 of file HIPAlignmentAlgorithm.h.

Referenced by HIPAlignmentAlgorithm().

bool HIPAlignmentAlgorithm::rewgtPerAli
private

Definition at line 133 of file HIPAlignmentAlgorithm.h.

Referenced by collector(), and HIPAlignmentAlgorithm().

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

Definition at line 135 of file HIPAlignmentAlgorithm.h.

Referenced by HIPAlignmentAlgorithm(), and run().

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

Definition at line 136 of file HIPAlignmentAlgorithm.h.

Referenced by HIPAlignmentAlgorithm(), and terminate().

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

Definition at line 108 of file HIPAlignmentAlgorithm.h.

Referenced by HIPAlignmentAlgorithm().

std::string HIPAlignmentAlgorithm::sparameterfile
private

Definition at line 107 of file HIPAlignmentAlgorithm.h.

Referenced by HIPAlignmentAlgorithm().

std::string HIPAlignmentAlgorithm::ssurveyfile
private

Definition at line 108 of file HIPAlignmentAlgorithm.h.

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

std::string HIPAlignmentAlgorithm::struefile
private

Definition at line 108 of file HIPAlignmentAlgorithm.h.

Referenced by HIPAlignmentAlgorithm().

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

Definition at line 141 of file HIPAlignmentAlgorithm.h.

Referenced by initialize().

std::string HIPAlignmentAlgorithm::suvarfile
private

Definition at line 107 of file HIPAlignmentAlgorithm.h.

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

std::string HIPAlignmentAlgorithm::suvarfilecore
private

Definition at line 107 of file HIPAlignmentAlgorithm.h.

Referenced by collector(), and HIPAlignmentAlgorithm().

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

Definition at line 93 of file HIPAlignmentAlgorithm.h.

Referenced by initialize(), and run().

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

Definition at line 148 of file HIPAlignmentAlgorithm.h.

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

TTree* HIPAlignmentAlgorithm::theAlignablesMonitorTree
private

Definition at line 149 of file HIPAlignmentAlgorithm.h.

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

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

Definition at line 126 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 116 of file HIPAlignmentAlgorithm.h.

Referenced by initialize(), and setAlignmentPositionError().

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

Definition at line 115 of file HIPAlignmentAlgorithm.h.

Referenced by HIPAlignmentAlgorithm(), and initialize().

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

Definition at line 130 of file HIPAlignmentAlgorithm.h.

Referenced by collector(), and HIPAlignmentAlgorithm().

std::string HIPAlignmentAlgorithm::theCollectorPath
private

Definition at line 131 of file HIPAlignmentAlgorithm.h.

Referenced by collector(), and HIPAlignmentAlgorithm().

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

Definition at line 125 of file HIPAlignmentAlgorithm.h.

Referenced by HIPAlignmentAlgorithm(), and initialize().

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

Definition at line 138 of file HIPAlignmentAlgorithm.h.

Referenced by HIPAlignmentAlgorithm(), and run().

TTree* HIPAlignmentAlgorithm::theHitMonitorTree
private

Definition at line 147 of file HIPAlignmentAlgorithm.h.

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

AlignmentIORoot HIPAlignmentAlgorithm::theIO
private

Definition at line 95 of file HIPAlignmentAlgorithm.h.

Referenced by startNewLoop(), and terminate().

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

Definition at line 111 of file HIPAlignmentAlgorithm.h.

Referenced by HIPAlignmentAlgorithm(), and initialize().

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

Definition at line 142 of file HIPAlignmentAlgorithm.h.

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

HIPMonitorConfig HIPAlignmentAlgorithm::theMonitorConfig
private

Definition at line 104 of file HIPAlignmentAlgorithm.h.

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

bool HIPAlignmentAlgorithm::themultiIOV
private

Definition at line 110 of file HIPAlignmentAlgorithm.h.

Referenced by HIPAlignmentAlgorithm(), and initialize().

TFile* HIPAlignmentAlgorithm::theSurveyIORootFile
private

Definition at line 150 of file HIPAlignmentAlgorithm.h.

Referenced by bookRoot(), and terminate().

TTree* HIPAlignmentAlgorithm::theSurveyTree
private

Definition at line 151 of file HIPAlignmentAlgorithm.h.

Referenced by bookRoot(), and terminate().

TFile* HIPAlignmentAlgorithm::theTrackHitMonitorIORootFile
private

Definition at line 145 of file HIPAlignmentAlgorithm.h.

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

TTree* HIPAlignmentAlgorithm::theTrackMonitorTree
private

Definition at line 146 of file HIPAlignmentAlgorithm.h.

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

bool HIPAlignmentAlgorithm::trackPs
private

Definition at line 133 of file HIPAlignmentAlgorithm.h.

Referenced by HIPAlignmentAlgorithm(), and run().

bool HIPAlignmentAlgorithm::trackWt
private

Definition at line 133 of file HIPAlignmentAlgorithm.h.

Referenced by HIPAlignmentAlgorithm(), and run().

bool HIPAlignmentAlgorithm::uniEta
private

Definition at line 133 of file HIPAlignmentAlgorithm.h.

Referenced by HIPAlignmentAlgorithm(), and run().

std::string HIPAlignmentAlgorithm::uniEtaFormula
private

Definition at line 134 of file HIPAlignmentAlgorithm.h.

Referenced by HIPAlignmentAlgorithm().

const bool HIPAlignmentAlgorithm::verbose
private