42 edm::LogWarning(
"Alignment") <<
"[MuonMillepedeAlgorithm] constructed.";
71 edm::LogWarning(
"Alignment") <<
"[MuonMillepedeAlgorithm] Initializing...";
87 std::map<std::string, TMatrixD *>
map;
93 TFile file_it(name_f);
95 if(file_it.IsZombie())
98 TList *m_list = file_it.GetListOfKeys();
99 if(m_list ==
nullptr) {
102 TKey *
index = (TKey *)m_list->First();
103 if(index ==
nullptr) {
105 if( index !=
nullptr )
111 TMatrixD *mat = (TMatrixD *)index->ReadObj();
112 std::map<std::string, TMatrixD *>::iterator node = map.find(
objectName);
113 if(node == map.end())
115 TMatrixD *n_mat =
new TMatrixD(mat->GetNrows(), mat->GetNcols());
119 index = (TKey*)m_list->After(index);
120 }
while(index !=
nullptr);
129 std::map<std::string, TMatrixD *>::iterator m_it = map.begin();
130 for(; m_it != map.end(); ++m_it)
132 if(m_it->first.find(
"_invCov") != std::string::npos)
134 std::string id_s = m_it->first.substr(0, m_it->first.find(
"_invCov"));
141 TMatrixD invMat( m_it->second->GetNrows(), m_it->second->GetNcols());
142 invMat = *(m_it->second);
145 TMatrixD weightMat( m_it->second->GetNcols(), 1);
146 weightMat = *(map[id_w]);
148 TMatrixD solution( m_it->second->GetNrows(), 1);
149 solution = invMat * weightMat;
154 invMat.Write(cov.c_str());
155 n.Write(id_n.c_str());
156 solution.Write(sol.c_str());
176 edm::LogWarning(
"Alignment") <<
"[MuonMillepedeAlgorithm] Terminating";
185 ali->alignmentParameters()->setValid(
true);
189 edm::LogWarning(
"Alignment") <<
"[MuonMillepedeAlgorithm] Writing aligned parameters to file: " << theAlignables.size();
193 std::map<std::string, AlgebraicMatrix *>::iterator invCov_it =
map_invCov.begin();
194 std::map<std::string, AlgebraicMatrix *>::iterator weightRes_it =
map_weightRes.begin();
195 std::map<std::string, AlgebraicMatrix *>::iterator n_it =
map_N.begin();
196 for(; n_it !=
map_N.end(); ++invCov_it, ++weightRes_it, ++n_it)
198 TMatrixD tmat_invcov(0,0);
199 this->
toTMat(invCov_it->second, &tmat_invcov);
200 TMatrixD tmat_weightres(0,0);
201 this->
toTMat(weightRes_it->second, &tmat_weightres);
202 TMatrixD tmat_n(0,0);
203 this->
toTMat(n_it->second, &tmat_n);
205 tmat_invcov.Write(invCov_it->first.c_str());
206 tmat_weightres.Write(weightRes_it->first.c_str());
207 tmat_n.Write(n_it->first.c_str());
218 tmat_mat->ResizeTo(am_mat->num_row(), am_mat->num_col());
219 for(
int c_i = 0; c_i < am_mat->num_row(); ++c_i) {
220 for(
int c_j = 0; c_j < am_mat->num_col(); ++c_j) {
221 (*tmat_mat)(c_i, c_j) = (*am_mat)[c_i][c_j];
242 for( ConstTrajTrackPairCollection::const_iterator it=tracks.begin();
243 it!=tracks.end();it++) {
248 float pt = track->
pt();
257 <<
"New track pt,eta,phi,chi2n,hits: " 258 << pt <<
"," << eta <<
"," << phi <<
"," << chi2n <<
"," << nhit;
266 std::vector<const TransientTrackingRecHit*> hitvec;
267 std::vector<TrajectoryStateOnSurface> tsosvec;
269 std::vector<TrajectoryMeasurement> measurements = traj->
measurements();
272 for (std::vector<TrajectoryMeasurement>::iterator im=measurements.begin();
273 im!=measurements.end(); im++)
284 hitvec.push_back(hit);
285 tsosvec.push_back(tsos);
291 std::vector <AlignableDetOrUnitPtr> alidetvec =
298 std::vector<TrajectoryStateOnSurface>::const_iterator itsos=tsosvec.begin();
299 std::vector<const TransientTrackingRecHit*>::const_iterator ihit=hitvec.begin();
304 while (itsos != tsosvec.end())
307 const GeomDet* det=(*ihit)->det();
315 if ( ali!=
nullptr && (*ihit)->geographicalId().subdetId() == 1)
319 if((*ihit)->dimension() == 4 || ((*ihit)->dimension() == 2 && m_Chamber.station() == 4))
339 int m_index[] = {2,3,0,1};
340 for(
int c_ei = 0; c_ei < 4; ++c_ei)
342 for(
int c_ej = 0; c_ej < 4; ++c_ej)
344 CovMat[m_index[c_ei]][m_index[c_ej]] = rawCovMat(c_ei+1,c_ej+1);
350 CovMat.invert(inv_check);
351 if (inv_check != 0) {
352 edm::LogError(
"Alignment") <<
"Covariance Matrix inversion failed";
362 if(m_Chamber.station() == 4)
365 residuals[0][0] = ihit4D[2]-alivec[3];
366 residuals[1][0] = 0.0;
367 residuals[2][0] = ihit4D[0]-alivec[1];
368 residuals[3][0] = 0.0;
370 CovMat[1][0] = 0.0; CovMat[1][1] = 0.0; CovMat[1][2] = 0.0;
371 CovMat[1][3] = 0.0; CovMat[0][1] = 0.0; CovMat[2][1] = 0.0;
372 CovMat[3][1] = 0.0; CovMat[3][0] = 0.0; CovMat[3][2] = 0.0;
373 CovMat[3][3] = 0.0; CovMat[0][3] = 0.0; CovMat[2][3] = 0.0;
378 residuals[0][0] = ihit4D[2]-alivec[3];
379 residuals[1][0] = ihit4D[3]-alivec[4];
380 residuals[2][0] = ihit4D[0]-alivec[1];
381 residuals[3][0] = ihit4D[1]-alivec[2];
387 std::vector<bool> mb4_mask;
390 mb4_mask.push_back(
true); mb4_mask.push_back(
false); mb4_mask.push_back(
true);
391 mb4_mask.push_back(
true); mb4_mask.push_back(
true); mb4_mask.push_back(
false);
392 selection.push_back(
true); selection.push_back(
true); selection.push_back(
false);
393 selection.push_back(
false); selection.push_back(
false); selection.push_back(
false);
395 if(m_Chamber.station() == 4)
397 for(
int icor = 0; icor < 6; ++icor)
399 if(mb4_mask[icor] && selection[icor]) nAlignParam++;
404 nAlignParam = derivsAux.num_row();
408 if(m_Chamber.station() == 4)
411 for(
int icor = 0; icor < 6; ++icor)
413 if(mb4_mask[icor] && selection[icor])
415 for(
int ccor = 0; ccor < 4; ++ccor)
417 derivs[der_c][ccor] = derivsAux[icor][ccor];
446 snprintf(name,
sizeof(name),
447 "Chamber_%d_%d_%d", m_Chamber.wheel(), m_Chamber.station(), m_Chamber.sector());
469 this->
updateInfo(invCov, weightRes, residuals, chamId);
508 std::map<std::string, AlgebraicMatrix *>::iterator node =
map_invCov.find(id_invCov);
515 map_invCov.insert(make_pair(id_invCov, f_invCov));
517 map_N.insert(make_pair(id_n, f_n));
519 for(
int iCount = 0; iCount < 4; ++iCount)
522 snprintf(name,
sizeof(name),
"%s_var_%d",
id.c_str(), iCount);
528 TH1D *
histo =
fs->
make<TH1D>(idName.c_str(), idName.c_str(), 200, -range, range );
529 histoMap.insert(make_pair(idName, histo));
535 (*
map_N[id_n])[0][0]++;
537 for(
int iCount = 0; iCount < 4; ++iCount)
540 snprintf(name,
sizeof(name),
"%s_var_%d",
id.c_str(), iCount);
T getParameter(std::string const &) const
std::map< std::string, AlgebraicMatrix * > map_weightRes
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.
def setup(process, global_tag, zero_tesla=False)
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.
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
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.
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 &)
ROOT::Math::SVector< double, 5 > AlgebraicVector5
std::string outputCollName
AlignmentParameterStore * theAlignmentParameterStore
CompositeAlignmentParameters selectParameters(const std::vector< AlignableDet * > &alignabledets) const
std::map< std::string, AlgebraicMatrix * > map_N
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.
std::map< std::string, TH1D * > histoMap
#define DEFINE_EDM_PLUGIN(factory, type, name)
eventInfo
add run, event number and lumi section
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...
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
std::map< std::string, AlgebraicMatrix * > map_invCov
virtual AlgebraicMatrix selectedDerivatives(const TrajectoryStateOnSurface &tsos, const AlignableDetOrUnitPtr &alidet) const
std::vector< ConstTrajTrackPair > ConstTrajTrackPairCollection