80 if (isCollector)
edm::LogWarning(
"Alignment") <<
"[HIPAlignmentAlgorithm] Collector mode";
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( std::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(std::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 std::vector<const TransientTrackingRecHit*> hitvec;
758 std::vector<TrajectoryStateOnSurface> tsosvec;
761 std::vector<TrajectoryMeasurement> measurements = traj->
measurements();
762 for (std::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) <<std::endl;
816 <<
"ERROR in <HIPAlignmentAlgorithm::run>: Dynamic cast of Strip RecHit failed! "
818 <<
"TypeId of the TTRH: " <<
className(*hit) << std::endl;
831 <<
"ERROR in <HIPAlignmentAlgorithm::run>: Dynamic cast of Pixel RecHit failed! "
833 <<
"TypeId of the TTRH: " <<
className(*hit) << std::endl;
846 <<
"ERROR in <HIPAlignmentAlgorithm::run>: this hit should have been skipped!"
855 hitvec.push_back(hit);
856 tsosvec.push_back(tsos);
868 std::vector<TrajectoryStateOnSurface>::const_iterator itsos=tsosvec.begin();
869 std::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 std::ifstream inIterFile(filename.c_str(),
std::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 std::ofstream outIterFile((filename.c_str()),
std::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 std::max(par[1],par[0]+((par[1]-par[0])/par[2])*diter);
1013 else if (
function == 1.) {
1016 else if (
function == 2.) {
1017 int ipar2 = (int) par[2];
1018 int step = iter/ipar2;
1019 double dstep = (double) step;
1020 return std::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.";
1108 for (std::vector<Alignable*>::const_iterator it=
theAlignables.begin();
1142 <<
"------------------------------------------------------------------------\n"
1143 <<
" ALIGNABLE: " << setw(6) << naligned
1145 <<
"hits: " << setw(4) <<
m2_Nhit
1146 <<
" type: " << setw(4) <<
m2_Type
1147 <<
" layer: " << setw(4) <<
m2_Layer
1148 <<
" id: " << setw(4) <<
m2_Id
1149 <<
" objId: " << setw(4) <<
m2_ObjId
1151 << std::fixed << std::setprecision(5)
1161 << setw(12) << pars[0]
1162 << setw(12) << pars[1]
1163 << setw(12) << pars[2]
1164 << setw(12) << pars[3]
1165 << setw(12) << pars[4]
1166 << setw(12) << pars[5];
1183 int nhit = uservar->
nhit;
1241 int npar = params.num_row();
1244 for (
int i=0;
i<npar;
i++) {
1246 else paramerr[
i] = params[
i];
1247 relerr[
i] =
abs(paramerr[i]/params[i]);
1296 edm::LogWarning(
"Alignment") <<
"[HIPAlignmentAlgorithm::collector] called for iteration "
1305 std::stringstream
ss;
1311 std::vector<AlignmentUserVariables*> uvarvec =
1316 edm::LogWarning(
"Alignment") <<
"[HIPAlignmentAlgorithm::collector] could not read user variable files for job "
1322 std::vector<AlignmentUserVariables*> uvarvecadd;
1323 std::vector<AlignmentUserVariables*>::const_iterator iuvarnew=uvarvec.begin();
1324 for (std::vector<Alignable*>::const_iterator it=
theAlignables.begin();
1343 uvarvecadd.push_back(uvar);
1366 snprintf(treeName,
sizeof(treeName),
"T1_%d", iter);
1368 TFile *jobfile =
new TFile(filename,
"READ");
1370 TTree *jobtree = (TTree*)jobfile->Get(treeName);
1372 static const int nmaxtrackperevent = 1000;
1373 int jobNtracks, jobNhitspertrack[nmaxtrackperevent], jobnhPXB[nmaxtrackperevent], jobnhPXF[nmaxtrackperevent];
1374 float jobP[nmaxtrackperevent], jobPt[nmaxtrackperevent], jobEta[nmaxtrackperevent] , jobPhi[nmaxtrackperevent];
1375 float jobd0[nmaxtrackperevent], jobdz[nmaxtrackperevent] , jobChi2n[nmaxtrackperevent];
1377 jobtree->SetBranchAddress(
"Ntracks", &jobNtracks);
1378 jobtree->SetBranchAddress(
"Nhits", jobNhitspertrack);
1379 jobtree->SetBranchAddress(
"nhPXB", jobnhPXB);
1380 jobtree->SetBranchAddress(
"nhPXF", jobnhPXF);
1381 jobtree->SetBranchAddress(
"Pt", jobPt);
1382 jobtree->SetBranchAddress(
"P", jobP);
1383 jobtree->SetBranchAddress(
"d0", jobd0);
1384 jobtree->SetBranchAddress(
"dz", jobdz);
1385 jobtree->SetBranchAddress(
"Eta", jobEta);
1386 jobtree->SetBranchAddress(
"Phi", jobPhi);
1387 jobtree->SetBranchAddress(
"Chi2n", jobChi2n);
1389 for (ievent=0;ievent<jobtree->GetEntries();++ievent) {
1390 jobtree->GetEntry(ievent);
1400 m_Nhits[ntrk] = jobNhitspertrack[ntrk];
1401 m_Pt[ntrk] = jobPt[ntrk];
1402 m_P[ntrk] = jobP[ntrk];
1403 m_nhPXB[ntrk] = jobnhPXB[ntrk];
1404 m_nhPXF[ntrk] = jobnhPXF[ntrk];
1405 m_Eta[ntrk] = jobEta[ntrk];
1406 m_Phi[ntrk] = jobPhi[ntrk];
1407 m_Chi2n[ntrk] = jobChi2n[ntrk];
1408 m_d0[ntrk] = jobd0[ntrk];
1409 m_dz[ntrk] = jobdz[ntrk];
1412 edm::LogWarning(
"Alignment") <<
"[HIPAlignmentAlgorithm::fillEventwiseTree] Number of tracks in Eventwise tree exceeds MAXREC: "
1413 <<
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
void terminate(const edm::EventSetup &setup)
Call at end of job.
ConstRecHitPointer const & recHit() const
double d0() const
dxy parameter in perigee convention (d0 = -dxy)
AlignableDetOrUnitPtr alignableFromGeomDet(const GeomDet *geomDet)
Returns AlignableDetOrUnitPtr corresponding to given GeomDet.
AlignmentParameterStore * theAlignmentParameterStore
std::pair< int, int > typeAndLayer(const Alignable *ali, const TrackerTopology *tTopo) const
Obtain type and layer from Alignable.
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)
void setAlignmentPositionError(const align::Alignables &alivec, double valshift, double valrot)
Set Alignment position error.
LocalPoint localPosition() const
static char const * tname
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
double phi() const
azimuthal angle of momentum vector
void writeIterationFile(std::string filename, int iter)
void applyParameters(void)
Obsolete: Use AlignableNavigator::alignableDetFromDetId and alignableFromAlignableDet.
Alignable * alignableFromAlignableDet(const AlignableDetOrUnitPtr &adet) const
Get relevant Alignable from AlignableDet.
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)
static align::StructureType stringToId(const char *)
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.
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
Abs< T >::type abs(const T &t)
bool processHit2D(const AlignableDetOrUnitPtr &alidet, const Alignable *ali, const TrajectoryStateOnSurface &tsos, const TrackingRecHit *hit)
AlignableNavigator * theAlignableDetAccessor
ClusterRef cluster() const
void fillRoot(const edm::EventSetup &setup)
int readIterationFile(std::string filename)
unsigned short numberOfValidHits() const
number of valid hits found
bool processHit1D(const AlignableDetOrUnitPtr &alidet, const Alignable *ali, const TrajectoryStateOnSurface &tsos, const TrackingRecHit *hit)
const LocalTrajectoryError & localError() const
void setAlignmentPositionError(void)
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.
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...
const align::Alignables & selectedAlignables() const
vector of alignables selected so far
int numSelected(void) const
Get number of selected parameters.
virtual TrackingRecHit const * hit() const
CLHEP::HepVector AlgebraicVector
void setUserVariables(AlignmentUserVariables *auv)
Set pointer to user variables.
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
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
T const * product() 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
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.
CLHEP::HepSymMatrix AlgebraicSymMatrix
unsigned int addSelections(const edm::ParameterSet &pSet)
bool theFillTrackMonitoring
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)
const align::Alignables & alignables(void) const
get all alignables
std::vector< ConstTrajTrackPair > ConstTrajTrackPairCollection
std::string className(const T &t)
TrajectoryStateOnSurface const & backwardPredictedState() const
Access to backward predicted state (from smoother)
int theMinimumNumberOfHits
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