76 if (isCollector)
edm::LogWarning(
"Alignment") <<
"[HIPAlignmentAlgorithm] Collector mode";
83 const std::vector<std::string>& levels = cfg.
getUntrackedParameter<std::vector<std::string> >(
"surveyResiduals");
85 for (
unsigned int l = 0;
l < levels.size(); ++
l) {
100 edm::LogWarning(
"Alignment") <<
"[HIPAlignmentAlgorithm] Initializing...";
122 for (std::vector<edm::ParameterSet>::const_iterator setiter =
theAPEParameterSet.begin();
125 std::vector<Alignable*> alignables;
130 if (alignParams.size() == 1 && alignParams[0] == std::string(
"selected")) {
138 std::vector<double> apeSPar = setiter->getParameter<std::vector<double> >(
"apeSPar");
139 std::vector<double> apeRPar = setiter->getParameter<std::vector<double> >(
"apeRPar");
140 std::string
function = setiter->getParameter<std::string>(
"function");
142 if (apeSPar.size() != 3 || apeRPar.size() != 3)
143 throw cms::Exception(
"BadConfig") <<
"apeSPar and apeRPar must have 3 values each" << std::endl;
145 for (std::vector<double>::const_iterator
i = apeRPar.begin();
i != apeRPar.end(); ++
i) {
146 apeSPar.push_back(*
i);
149 if (
function == std::string(
"linear")) {
150 apeSPar.push_back(0.);
152 else if (
function == std::string(
"exponential")) {
153 apeSPar.push_back(1.);
155 else if (
function == std::string(
"step")) {
156 apeSPar.push_back(2.);
159 throw cms::Exception(
"BadConfig") <<
"APE function must be \"linear\" or \"exponential\"." << std::endl;
162 theAPEParameters.push_back(std::pair<std::vector<Alignable*>, std::vector<double> >(alignables, apeSPar));
172 for( vector<Alignable*>::const_iterator it=
theAlignables.begin();
186 int numAlignablesFromFile = theAlignablePositionsFromFile.size();
188 if (numAlignablesFromFile==0) {
209 edm::LogWarning(
"Alignment") <<
"[HIPAlignmentAlgorithm] Alignables Read "
210 << numAlignablesFromFile;
217 edm::LogWarning(
"Alignment") <<
"[HIPAlignmentAlgorithm] Iteration increased by one!";
220 edm::LogWarning(
"Alignment") <<
"[HIPAlignmentAlgorithm] Apply positions from file ...";
222 theAlignablePositionsFromFile,
ioerr);
226 edm::LogWarning(
"Alignment") <<
"[HIPAlignmentAlgorithm] Current Iteration number: "
311 edm::LogWarning(
"Alignment") <<
"[HIPAlignmentAlgorithm] Using survey constraint";
315 for (
unsigned int i = 0;
i < nAlignable; ++
i)
339 uservar->
jtvj += invCov;
340 uservar->
jtve += invCov * sensResid;
374 for(vector<Alignable*>::const_iterator
394 edm::LogWarning(
"Alignment") <<
"[HIPAlignmentAlgorithm::terminate] Aligned units: " << ialigned;
439 static const unsigned int hitDim = 1;
458 covmat = covmat + ipcovmat;
462 if (covmat[0][0] != 0.) xpull = (pos[0] - coor[0])/
sqrt(fabs(covmat[0][0]));
469 int npar = derivs2D.num_row();
473 for (
int ipar=0;ipar<npar;ipar++) {
474 for (
unsigned int idim=0;idim<hitDim;idim++) {
475 derivs[ipar][idim] = derivs2D[ipar][idim];
494 if (!useThisHit)
return false;
509 thisjtvj.assign(jtvjtmp);
511 thisjtve=derivs * covmat * (pos-coor);
514 hitresidual[0] = (pos[0] - coor[0]);
517 hitresidualT = hitresidual.T();
522 uservar->
jtvj += thisjtvj;
523 uservar->
jtve += thisjtve;
531 thischi2 = (hitresidualT *covmat *hitresidual)[0];
533 if (
verbose && ((thischi2/ static_cast<float>(uservar->
nhit)) >10.0) ) {
534 edm::LogWarning(
"Alignment") <<
"Added to Chi2 the number " << thischi2 <<
" having "
535 << uservar->
nhit <<
" dof " << std::endl <<
"X-resid "
536 << hitresidual[0] <<
" Y-resid "
537 << hitresidual[1] << std::endl <<
" Cov^-1 matr (covmat): [0][0]= "
538 << covmat[0][0] <<
" [0][1]= "
539 << covmat[0][1] <<
" [1][0]= "
540 << covmat[1][0] <<
" [1][1]= "
541 << covmat[1][1] << std::endl;
555 static const unsigned int hitDim = 2;
580 covmat = covmat + ipcovmat;
585 if (covmat[0][0] != 0.) xpull = (pos[0] - coor[0])/
sqrt(fabs(covmat[0][0]));
586 if (covmat[1][1] != 0.) ypull = (pos[1] - coor[1])/
sqrt(fabs(covmat[1][1]));
593 int npar = derivs2D.num_row();
597 for (
int ipar=0;ipar<npar;ipar++) {
598 for (
unsigned int idim=0;idim<hitDim;idim++) {
599 derivs[ipar][idim] = derivs2D[ipar][idim];
618 if (!useThisHit)
return false;
633 thisjtvj.assign(jtvjtmp);
635 thisjtve=derivs * covmat * (pos-coor);
638 hitresidual[0] = (pos[0] - coor[0]);
639 hitresidual[1] = (pos[1] - coor[1]);
646 hitresidualT = hitresidual.T();
650 uservar->
jtvj += thisjtvj;
651 uservar->
jtve += thisjtve;
659 thischi2 = (hitresidualT *covmat *hitresidual)[0];
661 if (
verbose && ((thischi2/ static_cast<float>(uservar->
nhit)) >10.0) ) {
662 edm::LogWarning(
"Alignment") <<
"Added to Chi2 the number " << thischi2 <<
" having "
663 << uservar->
nhit <<
" dof " << std::endl <<
"X-resid "
664 << hitresidual[0] <<
" Y-resid "
665 << hitresidual[1] << std::endl <<
" Cov^-1 matr (covmat): [0][0]= "
666 << covmat[0][0] <<
" [0][1]= "
667 << covmat[0][1] <<
" [1][0]= "
668 << covmat[1][0] <<
" [1][1]= "
669 << covmat[1][1] << std::endl;
689 for(itr=0;itr<
MAXREC;++itr){
708 for (ConstTrajTrackPairCollection::const_iterator it=tracks.begin();
715 float pt = track->
pt();
718 float p = track->
p();
721 float d0 = track->
d0();
722 float dz = track->
dz();
757 vector<const TransientTrackingRecHit*> hitvec;
758 vector<TrajectoryStateOnSurface> tsosvec;
761 vector<TrajectoryMeasurement> measurements = traj->
measurements();
762 for (vector<TrajectoryMeasurement>::iterator im=measurements.begin();
763 im!=measurements.end();
780 bool skiphit =
false;
791 const std::type_info &
type =
typeid(*rechit);
802 <<
"ERROR in <HIPAlignmentAlgorithm::run>: Dynamic cast of Strip RecHit failed! "
803 <<
"TypeId of the RecHit: " <<
className(*hit) <<endl;
816 <<
"ERROR in <HIPAlignmentAlgorithm::run>: Dynamic cast of Strip RecHit failed! "
818 <<
"TypeId of the TTRH: " <<
className(*hit) << endl;
831 <<
"ERROR in <HIPAlignmentAlgorithm::run>: Dynamic cast of Pixel RecHit failed! "
833 <<
"TypeId of the TTRH: " <<
className(*hit) << endl;
846 <<
"ERROR in <HIPAlignmentAlgorithm::run>: this hit should have been skipped!"
855 hitvec.push_back(hit);
856 tsosvec.push_back(tsos);
868 vector<TrajectoryStateOnSurface>::const_iterator itsos=tsosvec.begin();
869 vector<const TransientTrackingRecHit*>::const_iterator ihit=hitvec.begin();
872 while (itsos != tsosvec.end()) {
875 const GeomDet* det = (*ihit)->det();
877 uint32_t nhitDim = (*ihit)->dimension();
887 }
else if (nhitDim==2) {
913 ifstream inIterFile((
char*)filename.c_str(),
ios::in);
915 edm::LogError(
"Alignment") <<
"[HIPAlignmentAlgorithm::readIterationFile] ERROR! "
916 <<
"Unable to open Iteration file";
921 edm::LogWarning(
"Alignment") <<
"[HIPAlignmentAlgorithm::readIterationFile] "
922 <<
"Read last iteration number from file: " <<
result;
933 ofstream outIterFile((
char*)(filename.c_str()),
ios::out);
935 edm::LogError(
"Alignment") <<
"[HIPAlignmentAlgorithm::writeIterationFile] ERROR: Unable to write Iteration file";
939 edm::LogWarning(
"Alignment") <<
"[HIPAlignmentAlgorithm::writeIterationFile] writing iteration number to file: " << iter;
955 edm::LogWarning(
"Alignment") <<
"[HIPAlignmentAlgorithm::setAlignmentPositionError] No APE applied";
960 edm::LogWarning(
"Alignment") <<
"[HIPAlignmentAlgorithm::setAlignmentPositionError] Apply APE!";
962 double apeSPar[3], apeRPar[3];
963 for (std::vector<std::pair<std::vector<Alignable*>, std::vector<double> > >::const_iterator alipars =
theAPEParameters.begin();
966 const std::vector<Alignable*> &alignables = alipars->first;
967 const std::vector<double> &pars = alipars->second;
969 apeSPar[0] = pars[0];
970 apeSPar[1] = pars[1];
971 apeSPar[2] = pars[2];
972 apeRPar[0] = pars[3];
973 apeRPar[1] = pars[4];
974 apeRPar[2] = pars[5];
976 double function = pars[6];
979 printf(
"APE: %u alignables\n", (
unsigned int)alignables.size());
980 for (
int i=0;
i<21; ++
i ) {
981 double apelinstest=
calcAPE(apeSPar,
i,0.);
982 double apeexpstest=
calcAPE(apeSPar,
i,1.);
983 double apelinrtest=
calcAPE(apeRPar,
i,0.);
984 double apeexprtest=
calcAPE(apeRPar,
i,1.);
985 printf(
"APE: iter slin sexp rlin rexp: %5d %12.5f %12.5f %12.5f %12.5f\n",
986 i,apelinstest,apeexpstest,apelinrtest,apeexprtest);
1003 double diter=(double)iter;
1010 if (
function == 0.) {
1011 return max(par[1],par[0]+((par[1]-par[0])/par[2])*diter);
1013 else if (
function == 1.) {
1014 return max(0.,par[0]*(
exp(-
pow(diter,par[1])/par[2])));
1016 else if (
function == 2.) {
1017 int ipar2 = (int) par[2];
1018 int step = iter/ipar2;
1019 double dstep = (double) step;
1020 return max(0.0, par[0] - par[1]*dstep);
1039 snprintf(iterString,
sizeof(iterString),
"%i",
theIteration);
1041 tname.Append(iterString);
1043 theTree =
new TTree(tname,
"Eventwise tree");
1064 theTree2 =
new TTree(
"T2",
"Alignablewise tree");
1080 edm::LogWarning(
"Alignment") <<
"[HIPAlignmentAlgorithm::bookRoot] Survey trees booked.";
1083 theTree3 =
new TTree(tname,
"Survey Tree");
1089 edm::LogWarning(
"Alignment") <<
"[HIPAlignmentAlgorithm::bookRoot] Root trees booked.";
1102 for (vector<Alignable*>::const_iterator it=
theAlignables.begin();
1136 <<
"------------------------------------------------------------------------\n"
1137 <<
" ALIGNABLE: " << setw(6) << naligned
1139 <<
"hits: " << setw(4) <<
m2_Nhit
1140 <<
" type: " << setw(4) <<
m2_Type
1141 <<
" layer: " << setw(4) <<
m2_Layer
1142 <<
" id: " << setw(4) <<
m2_Id
1143 <<
" objId: " << setw(4) <<
m2_ObjId
1145 << fixed << setprecision(5)
1155 << setw(12) << pars[0]
1156 << setw(12) << pars[1]
1157 << setw(12) << pars[2]
1158 << setw(12) << pars[3]
1159 << setw(12) << pars[4]
1160 << setw(12) << pars[5];
1177 int nhit = uservar->
nhit;
1235 int npar = params.num_row();
1238 for (
int i=0;
i<npar;
i++) {
1240 else paramerr[
i] = params[
i];
1241 relerr[
i] =
abs(paramerr[i]/params[i]);
1290 edm::LogWarning(
"Alignment") <<
"[HIPAlignmentAlgorithm::collector] called for iteration "
1305 vector<AlignmentUserVariables*> uvarvec =
1310 edm::LogWarning(
"Alignment") <<
"[HIPAlignmentAlgorithm::collector] could not read user variable files for job "
1316 vector<AlignmentUserVariables*> uvarvecadd;
1317 vector<AlignmentUserVariables*>::const_iterator iuvarnew=uvarvec.begin();
1318 for (vector<Alignable*>::const_iterator it=
theAlignables.begin();
1337 uvarvecadd.push_back(uvar);
1360 snprintf(treeName,
sizeof(treeName),
"T1_%d", iter);
1362 TFile *jobfile =
new TFile(filename,
"READ");
1364 TTree *jobtree = (TTree*)jobfile->Get(treeName);
1366 static const int nmaxtrackperevent = 1000;
1367 int jobNtracks, jobNhitspertrack[nmaxtrackperevent], jobnhPXB[nmaxtrackperevent], jobnhPXF[nmaxtrackperevent];
1368 float jobP[nmaxtrackperevent], jobPt[nmaxtrackperevent], jobEta[nmaxtrackperevent] , jobPhi[nmaxtrackperevent];
1369 float jobd0[nmaxtrackperevent], jobdz[nmaxtrackperevent] , jobChi2n[nmaxtrackperevent];
1371 jobtree->SetBranchAddress(
"Ntracks", &jobNtracks);
1372 jobtree->SetBranchAddress(
"Nhits", jobNhitspertrack);
1373 jobtree->SetBranchAddress(
"nhPXB", jobnhPXB);
1374 jobtree->SetBranchAddress(
"nhPXF", jobnhPXF);
1375 jobtree->SetBranchAddress(
"Pt", jobPt);
1376 jobtree->SetBranchAddress(
"P", jobP);
1377 jobtree->SetBranchAddress(
"d0", jobd0);
1378 jobtree->SetBranchAddress(
"dz", jobdz);
1379 jobtree->SetBranchAddress(
"Eta", jobEta);
1380 jobtree->SetBranchAddress(
"Phi", jobPhi);
1381 jobtree->SetBranchAddress(
"Chi2n", jobChi2n);
1383 for (ievent=0;ievent<jobtree->GetEntries();++ievent) {
1384 jobtree->GetEntry(ievent);
1394 m_Nhits[ntrk] = jobNhitspertrack[ntrk];
1395 m_Pt[ntrk] = jobPt[ntrk];
1396 m_P[ntrk] = jobP[ntrk];
1397 m_nhPXB[ntrk] = jobnhPXB[ntrk];
1398 m_nhPXF[ntrk] = jobnhPXF[ntrk];
1399 m_Eta[ntrk] = jobEta[ntrk];
1400 m_Phi[ntrk] = jobPhi[ntrk];
1401 m_Chi2n[ntrk] = jobChi2n[ntrk];
1402 m_d0[ntrk] = jobd0[ntrk];
1403 m_dz[ntrk] = jobdz[ntrk];
1406 edm::LogWarning(
"Alignment") <<
"[HIPAlignmentAlgorithm::fillEventwiseTree] Number of tracks in Eventwise tree exceeds MAXREC: "
1407 <<
m_Ntracks <<
" Skipping exceeding tracks.";
ClusterRef cluster() const
void attachUserVariables(const align::Alignables &alivec, const std::vector< AlignmentUserVariables * > &uvarvec, int &ierr)
Attach User Variables to given alignables.
double p() const
momentum vector magnitude
T getParameter(std::string const &) const
align::ID id() const
Return the ID of Alignable, i.e. DetId of 'first' component GeomDet(Unit).
T getUntrackedParameter(std::string const &, T const &) const
double d0() const
dxy parameter in perigee convention (d0 = - dxy)
AlignableDetOrUnitPtr alignableFromGeomDet(const GeomDet *geomDet)
Returns AlignableDetOrUnitPtr corresponding to given GeomDet.
AlignmentParameterStore * theAlignmentParameterStore
bool calcParameters(Alignable *ali)
double normalizedChi2() const
chi-squared divided by n.d.o.f. (or chi-squared * 1e6 if n.d.o.f. is zero)
TSOS combine(const TSOS &pTsos1, const TSOS &pTsos2) const
int fillEventwiseTree(const char *filename, int iter, int ierr)
TrajectoryStateOnSurface forwardPredictedState() const
Access to forward predicted state (from fitter or builder)
void setAlignmentPositionError(const align::Alignables &alivec, double valshift, double valrot)
Set Alignment position error.
LocalPoint localPosition() const
void writeAlignableOriginalPositions(const align::Alignables &alivec, const char *filename, int iter, bool validCheck, int &ierr)
write Alignable original (before misalignment) absolute positions
align::StructureType m2_ObjId
Geom::Phi< T > phi() const
Alignable * alignableFromAlignableDet(AlignableDetOrUnitPtr adet) const
Get relevant Alignable from AlignableDet.
virtual const TrackingRecHit * hit() const =0
double phi() const
azimuthal angle of momentum vector
ConstRecHitPointer recHit() const
void writeIterationFile(std::string filename, int iter)
void applyParameters(void)
Obsolete: Use AlignableNavigator::alignableDetFromDetId and alignableFromAlignableDet.
HIPUserVariables * clone(void) const
void applyAlignableAbsolutePositions(const align::Alignables &alis, const AlignablePositions &newpos, int &ierr)
apply absolute positions to alignables
LocalError positionError() const
AlignmentParameters * alignmentParameters() const
Get the AlignmentParameters.
const ConstTrajTrackPairCollection & trajTrackPairs() const
define event information passed to algorithms
void writeHIPUserVariables(const Alignables &alivec, const char *filename, int iter, bool validCheck, int &ierr)
std::vector< std::pair< std::vector< Alignable * >, std::vector< double > > > theAPEParameters
const AlgebraicVector & parameters(void) const
Get alignment parameters.
DataContainer const & measurements() const
AlignmentUserVariables * userVariables(void) const
Get pointer to user variables.
AlignablePositions readAlignableAbsolutePositions(const align::Alignables &alivec, const char *filename, int iter, int &ierr)
read Alignable current absolute positions
void clear()
remove all selected Alignables and geometrical restrictions
double eta() const
pseudorapidity of momentum vector
double calcAPE(double *par, int iter, double function)
void startNewLoop(void)
Called at start of new loop.
int numberOfValidPixelBarrelHits() const
std::vector< AlignmentUserVariables * > readHIPUserVariables(const Alignables &alivec, const char *filename, int iter, int &ierr)
void setAlignmentParameters(AlignmentParameters *dap)
Set the AlignmentParameters.
CLHEP::HepMatrix AlgebraicMatrix
HIPAlignmentAlgorithm(const edm::ParameterSet &cfg)
Constructor.
const T & max(const T &a, const T &b)
void setValid(bool v)
Set validity flag.
double pt() const
track transverse momentum
void initialize(const edm::EventSetup &setup, AlignableTracker *tracker, AlignableMuon *muon, AlignableExtras *extras, AlignmentParameterStore *store)
Call at beginning of job.
virtual StructureType alignableObjectId() const =0
Return the alignable type identifier.
std::string siterationfile
AlignableNavigator * theAlignableDetAccessor
Allows conversion between type and name, and vice-versa.
ClusterRef cluster() const
int readIterationFile(std::string filename)
unsigned short numberOfValidHits() const
number of valid hits found
const LocalTrajectoryError & localError() const
void setAlignmentPositionError(void)
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
const AlignableSurface & surface() const
Return the Surface (global position and orientation) of the object.
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...
const align::Alignables & selectedAlignables() const
vector of alignables selected so far
int numSelected(void) const
Get number of selected parameters.
CLHEP::HepVector AlgebraicVector
bool processHit1D(const AlignableDetOrUnitPtr alidet, const Alignable *ali, const TrajectoryStateOnSurface &tsos, const TransientTrackingRecHit *hit)
void setUserVariables(AlignmentUserVariables *auv)
Set pointer to user variables.
virtual LocalError localPositionError() const =0
ClusterRef cluster() const
void writeAlignmentParameters(const align::Alignables &alivec, const char *filename, int iter, bool validCheck, int &ierr)
write AlignmentParameters
CompositeAlignmentParameters selectParameters(const std::vector< AlignableDet * > &alignabledets) const
AlgebraicSymMatrix inverseCovariance() const
Get inverse of survey covariance wrt given structure type in constructor.
std::string smisalignedfile
std::vector< edm::ParameterSet > theAPEParameterSet
align::StructureType m3_ObjId
align::StructureType nameToType(const std::string &name) const
Convert name to type.
int numberOfValidPixelEndcapHits() const
AlgebraicVector sensorResidual() const
std::vector< AlignableDetOrUnitPtr > alignablesFromHits(const std::vector< const TransientTrackingRecHit * > &hitvec)
Returns vector AlignableDetOrUnitPtr for given vector of Hits.
const AliClusterValueMap * clusterValueMap() const
bool isValid(void) const
Get validity flag.
bool processHit2D(const AlignableDetOrUnitPtr alidet, const Alignable *ali, const TrajectoryStateOnSurface &tsos, const TransientTrackingRecHit *hit)
CLHEP::HepSymMatrix AlgebraicSymMatrix
unsigned int addSelections(const edm::ParameterSet &pSet)
bool theFillTrackMonitoring
void terminate(void)
Call at end of job.
std::vector< AlignableAbsData > AlignablePositions
void writeAlignableAbsolutePositions(const align::Alignables &alivec, const char *filename, int iter, bool validCheck, int &ierr)
write Alignable current absolute positions
DetId geographicalId() const
virtual AlignmentParameters * cloneFromSelected(const AlgebraicVector &par, const AlgebraicSymMatrix &cov) const =0
bool detAndSubdetInMap(const DetId &detid) const
Given a DetId, returns true if DetIds with this detector and subdetector id are in the map (not neces...
Constructor of the full muon geometry.
virtual LocalPoint localPosition() const =0
double theMaxRelParameterError
const PositionType & position() const
std::vector< align::StructureType > theLevels
double theMaxAllowedHitPull
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
std::vector< Alignable * > theAlignables
Power< A, B >::type pow(const A &a, const B &b)
TrajectoryStateOnSurface backwardPredictedState() const
Access to backward predicted state (from smoother)
const align::Alignables & alignables(void) const
get all alignables
std::vector< ConstTrajTrackPair > ConstTrajTrackPairCollection
std::string className(const T &t)
int theMinimumNumberOfHits
std::pair< int, int > typeAndLayer(const Alignable *ali) const
Obtain type and layer from Alignable.
std::string theCollectorPath
void run(const edm::EventSetup &setup, const EventInfo &eventInfo)
Run the algorithm.
virtual AlgebraicMatrix selectedDerivatives(const TrajectoryStateOnSurface &tsos, const AlignableDetOrUnitPtr &alidet) const
std::string sparameterfile