37 edm::LogWarning(
"Alignment") <<
"[MuonMillepedeAlgorithm] constructed.";
61 edm::LogWarning(
"Alignment") <<
"[MuonMillepedeAlgorithm] Initializing...";
74 std::map<std::string, TMatrixD *>
map;
79 TFile file_it(name_f);
81 if (file_it.IsZombie())
84 TList *m_list = file_it.GetListOfKeys();
85 if (m_list ==
nullptr) {
88 TKey *
index = (TKey *)m_list->First();
89 if (index ==
nullptr) {
91 if (index !=
nullptr) {
94 TMatrixD *mat = (TMatrixD *)index->ReadObj();
95 std::map<std::string, TMatrixD *>::iterator node = map.find(
objectName);
96 if (node == map.end()) {
97 TMatrixD *n_mat =
new TMatrixD(mat->GetNrows(), mat->GetNcols());
101 index = (TKey *)m_list->After(index);
102 }
while (index !=
nullptr);
110 std::map<std::string, TMatrixD *>::iterator m_it = map.begin();
111 for (; m_it != map.end(); ++m_it) {
112 if (m_it->first.find(
"_invCov") != std::string::npos) {
113 std::string id_s = m_it->first.substr(0, m_it->first.find(
"_invCov"));
120 TMatrixD invMat(m_it->second->GetNrows(), m_it->second->GetNcols());
121 invMat = *(m_it->second);
124 TMatrixD weightMat(m_it->second->GetNcols(), 1);
125 weightMat = *(map[id_w]);
127 TMatrixD solution(m_it->second->GetNrows(), 1);
128 solution = invMat * weightMat;
133 invMat.Write(cov.c_str());
134 n.Write(id_n.c_str());
135 solution.Write(sol.c_str());
150 edm::LogWarning(
"Alignment") <<
"[MuonMillepedeAlgorithm] Terminating";
159 ali->alignmentParameters()->setValid(
true);
162 edm::LogWarning(
"Alignment") <<
"[MuonMillepedeAlgorithm] Writing aligned parameters to file: " 163 << theAlignables.size();
167 std::map<std::string, AlgebraicMatrix *>::iterator invCov_it =
map_invCov.begin();
168 std::map<std::string, AlgebraicMatrix *>::iterator weightRes_it =
map_weightRes.begin();
169 std::map<std::string, AlgebraicMatrix *>::iterator n_it =
map_N.begin();
170 for (; n_it !=
map_N.end(); ++invCov_it, ++weightRes_it, ++n_it) {
171 TMatrixD tmat_invcov(0, 0);
172 this->
toTMat(invCov_it->second, &tmat_invcov);
173 TMatrixD tmat_weightres(0, 0);
174 this->
toTMat(weightRes_it->second, &tmat_weightres);
175 TMatrixD tmat_n(0, 0);
176 this->
toTMat(n_it->second, &tmat_n);
178 tmat_invcov.Write(invCov_it->first.c_str());
179 tmat_weightres.Write(weightRes_it->first.c_str());
180 tmat_n.Write(n_it->first.c_str());
188 tmat_mat->ResizeTo(am_mat->num_row(), am_mat->num_col());
189 for (
int c_i = 0; c_i < am_mat->num_row(); ++c_i) {
190 for (
int c_j = 0; c_j < am_mat->num_col(); ++c_j) {
191 (*tmat_mat)(c_i, c_j) = (*am_mat)[c_i][c_j];
206 for (ConstTrajTrackPairCollection::const_iterator it = tracks.begin(); it != tracks.end(); it++) {
210 float pt = track->
pt();
218 LogDebug(
"Alignment") <<
"New track pt,eta,phi,chi2n,hits: " << pt <<
"," << eta <<
"," << phi <<
"," << chi2n
224 std::vector<const TransientTrackingRecHit *> hitvec;
225 std::vector<TrajectoryStateOnSurface> tsosvec;
227 std::vector<TrajectoryMeasurement> measurements = traj->
measurements();
230 for (std::vector<TrajectoryMeasurement>::iterator im = measurements.begin(); im != measurements.end(); im++) {
238 hitvec.push_back(hit);
239 tsosvec.push_back(tsos);
250 std::vector<TrajectoryStateOnSurface>::const_iterator itsos = tsosvec.begin();
251 std::vector<const TransientTrackingRecHit *>::const_iterator ihit = hitvec.begin();
255 while (itsos != tsosvec.end()) {
257 const GeomDet *det = (*ihit)->det();
264 if (ali !=
nullptr && (*ihit)->geographicalId().subdetId() == 1) {
267 if ((*ihit)->dimension() == 4 || ((*ihit)->dimension() == 2 && m_Chamber.station() == 4))
287 int m_index[] = {2, 3, 0, 1};
288 for (
int c_ei = 0; c_ei < 4; ++c_ei) {
289 for (
int c_ej = 0; c_ej < 4; ++c_ej) {
290 CovMat[m_index[c_ei]][m_index[c_ej]] = rawCovMat(c_ei + 1, c_ej + 1);
296 CovMat.invert(inv_check);
297 if (inv_check != 0) {
298 edm::LogError(
"Alignment") <<
"Covariance Matrix inversion failed";
306 if (m_Chamber.station() == 4) {
308 residuals[0][0] = ihit4D[2] - alivec[3];
309 residuals[1][0] = 0.0;
310 residuals[2][0] = ihit4D[0] - alivec[1];
311 residuals[3][0] = 0.0;
327 residuals[0][0] = ihit4D[2] - alivec[3];
328 residuals[1][0] = ihit4D[3] - alivec[4];
329 residuals[2][0] = ihit4D[0] - alivec[1];
330 residuals[3][0] = ihit4D[1] - alivec[2];
336 std::vector<bool> mb4_mask;
339 mb4_mask.push_back(
true);
340 mb4_mask.push_back(
false);
341 mb4_mask.push_back(
true);
342 mb4_mask.push_back(
true);
343 mb4_mask.push_back(
true);
344 mb4_mask.push_back(
false);
345 selection.push_back(
true);
346 selection.push_back(
true);
347 selection.push_back(
false);
348 selection.push_back(
false);
349 selection.push_back(
false);
350 selection.push_back(
false);
352 if (m_Chamber.station() == 4) {
353 for (
int icor = 0; icor < 6; ++icor) {
354 if (mb4_mask[icor] && selection[icor])
358 nAlignParam = derivsAux.num_row();
362 if (m_Chamber.station() == 4) {
364 for (
int icor = 0; icor < 6; ++icor) {
365 if (mb4_mask[icor] && selection[icor]) {
366 for (
int ccor = 0; ccor < 4; ++ccor) {
367 derivs[der_c][ccor] = derivsAux[icor][ccor];
394 name,
sizeof(name),
"Chamber_%d_%d_%d", m_Chamber.wheel(), m_Chamber.station(), m_Chamber.sector());
416 this->
updateInfo(invCov, weightRes, residuals, chamId);
448 std::map<std::string, AlgebraicMatrix *>::iterator node =
map_invCov.find(id_invCov);
454 map_invCov.insert(make_pair(id_invCov, f_invCov));
456 map_N.insert(make_pair(id_n, f_n));
458 for (
int iCount = 0; iCount < 4; ++iCount) {
460 snprintf(name,
sizeof(name),
"%s_var_%d",
id.c_str(), iCount);
467 histoMap.insert(make_pair(idName, histo));
473 (*
map_N[id_n])[0][0]++;
475 for (
int iCount = 0; iCount < 4; ++iCount) {
477 snprintf(name,
sizeof(name),
"%s_var_%d",
id.c_str(), iCount);
std::map< std::string, AlgebraicMatrix * > map_weightRes
std::map< std::string, AlgebraicMatrix * > map_invCov
T getParameter(std::string const &) const
AlignableNavigator * theAlignableDetAccessor
ConstRecHitPointer const & recHit() const
AlignableDetOrUnitPtr alignableFromGeomDet(const GeomDet *geomDet)
Returns AlignableDetOrUnitPtr corresponding to given GeomDet.
double normalizedChi2() const
chi-squared divided by n.d.o.f. (or chi-squared * 1e6 if n.d.o.f. is zero)
void initialize(const edm::EventSetup &setup, AlignableTracker *tracker, AlignableMuon *muon, AlignableExtras *extras, AlignmentParameterStore *store) override
Call at beginning of job.
double phi() const
azimuthal angle of momentum vector
T * make(const Args &...args) const
make new ROOT object
void applyParameters(void)
Obsolete: Use AlignableNavigator::alignableDetFromDetId and alignableFromAlignableDet.
Alignable * alignableFromAlignableDet(const AlignableDetOrUnitPtr &adet) const
Get relevant Alignable from AlignableDet.
AlignmentParameters * alignmentParameters() const
Get the AlignmentParameters.
edm::Service< TFileService > fs
const ConstTrajTrackPairCollection & trajTrackPairs() const
void toTMat(AlgebraicMatrix *, TMatrixD *)
define event information passed to algorithms
DataContainer const & measurements() const
double eta() const
pseudorapidity of momentum vector
CLHEP::HepMatrix AlgebraicMatrix
double pt() const
track transverse momentum
MuonMillepedeAlgorithm(const edm::ParameterSet &cfg)
Constructor.
ROOT::Math::SVector< double, 5 > AlgebraicVector5
DetId geographicalId() const
The label of this GeomDet.
void updateInfo(const AlgebraicMatrix &, const AlgebraicMatrix &, const AlgebraicMatrix &, std::string)
unsigned short numberOfValidHits() const
number of valid hits found
TrajectoryStateOnSurface const & forwardPredictedState() const
Access to forward predicted state (from fitter or builder)
CLHEP::HepVector AlgebraicVector
void printM(const AlgebraicMatrix &)
std::string outputCollName
AlignmentParameterStore * theAlignmentParameterStore
CompositeAlignmentParameters selectParameters(const std::vector< AlignableDet * > &alignabledets) const
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
std::map< std::string, TH1D * > histoMap
virtual void terminate()
Called at end of job (must be implemented in derived class)
std::vector< AlignableDetOrUnitPtr > alignablesFromHits(const std::vector< const TransientTrackingRecHit * > &hitvec)
Returns vector AlignableDetOrUnitPtr for given vector of Hits.
#define DEFINE_EDM_PLUGIN(factory, type, name)
DetId geographicalId() const
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...
std::map< std::string, AlgebraicMatrix * > map_N
Constructor of the full muon geometry.
align::Alignables theAlignables
void run(const edm::EventSetup &setup, const EventInfo &eventInfo) override
Run the algorithm.
const align::Alignables & alignables(void) const
get all alignables
virtual AlgebraicMatrix selectedDerivatives(const TrajectoryStateOnSurface &tsos, const AlignableDetOrUnitPtr &alidet) const
std::vector< ConstTrajTrackPair > ConstTrajTrackPairCollection