CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/Alignment/MuonAlignmentAlgorithms/plugins/CSCAlignmentCorrections.cc

Go to the documentation of this file.
00001 #include "FWCore/ServiceRegistry/interface/Service.h"
00002 #include "CommonTools/UtilAlgos/interface/TFileService.h"
00003 
00004 #include "Alignment/MuonAlignmentAlgorithms/plugins/CSCAlignmentCorrections.h"
00005 #include "Alignment/MuonAlignmentAlgorithms/plugins/CSCPairResidualsConstraint.h"
00006 
00007 void CSCAlignmentCorrections::plot() {
00008   edm::Service<TFileService> tFileService;
00009 
00010   for (unsigned int i = 0;  i < m_coefficient.size();  i++) {
00011     std::string modifiedName = m_fitterName;
00012     if (modifiedName[0] == 'M'  &&  modifiedName[1] == 'E') {
00013        if (modifiedName[2] == '-') modifiedName[2] = 'm';
00014        else if (modifiedName[2] == '+') modifiedName[2] = 'p';
00015        if (modifiedName[4] == '/') modifiedName[4] = '_';
00016        if (modifiedName[6] == '/') modifiedName[6] = '_';
00017     }
00018     else if (modifiedName[0] == 'Y'  &&  modifiedName[1] == 'E') {
00019        if (modifiedName[2] == '-') modifiedName[2] = 'm';
00020        else if (modifiedName[2] == '+') modifiedName[2] = 'p';
00021     }
00022 
00023     std::stringstream histname, histtitle;
00024     histname << modifiedName << "_mode_" << i;
00025     histtitle << m_error[i];
00026 
00027     TH1F *hist = tFileService->make<TH1F>(histname.str().c_str(), histtitle.str().c_str(), m_coefficient[i].size(), 0.5, m_coefficient[i].size() + 0.5);
00028 
00029     bool showed_full_name = false;
00030     for (unsigned int j = 0;  j < m_coefficient[i].size();  j++) {
00031       hist->SetBinContent(j+1, m_coefficient[i][j]);
00032 
00033       if (m_modeid[i][j] == -1  ||  !showed_full_name) {
00034         hist->GetXaxis()->SetBinLabel(j+1, m_modename[i][j].c_str());
00035       }
00036       else {
00037         std::stringstream shortname;
00038         shortname << m_modename[i][j][7] << m_modename[i][j][8];
00039         hist->GetXaxis()->SetBinLabel(j+1, shortname.str().c_str());
00040       }
00041       if (m_modeid[i][j] != -1) showed_full_name = true;
00042     }
00043 
00044     th1f_modes.push_back(hist);
00045   }
00046 }
00047 
00048 void CSCAlignmentCorrections::report(std::ofstream &report) {
00049   report << "cscReports.append(CSCFitterReport(\"" << m_fitterName << "\", " << m_oldchi2 << ", " << m_newchi2 << "))" << std::endl;
00050   
00051   for (unsigned int i = 0;  i < m_name.size();  i++) {
00052     report << "cscReports[-1].addChamberCorrection(\"" << m_name[i] << "\", " << m_id[i].rawId() << ", " << m_value[i] << ")" << std::endl;
00053   }
00054 
00055   for (unsigned int i = 0;  i < m_coefficient.size();  i++) {
00056     report << "cscReports[-1].addErrorMode(" << m_error[i] << ")" << std::endl;
00057 
00058     for (unsigned int j = 0;  j < m_coefficient[i].size();  j++) {
00059       report << "cscReports[-1].addErrorModeTerm(\"" << m_modename[i][j] << "\", " << m_modeid[i][j] << ", " << m_coefficient[i][j] << ")" << std::endl;
00060     }
00061   }
00062 
00063   for (unsigned int i = 0;  i < m_i.size();  i++) {
00064     report << "cscReports[-1].addCSCConstraintResidual(\"" << m_i[i] << "\", \"" << m_j[i] << "\", " << m_before[i] << ", " << m_uncert[i] << ", " << m_residual[i] << ", " << m_pull[i] << ")" << std::endl;
00065   }
00066 
00067   report << std::endl;
00068 }
00069 
00070 void CSCAlignmentCorrections::applyAlignment(AlignableNavigator *alignableNavigator, AlignmentParameterStore *alignmentParameterStore, int mode, bool combineME11) {
00071   for (unsigned int i = 0;  i < m_name.size();  i++) {
00072     // CSC sign conventions
00073     bool backward = ((m_id[i].endcap() == 1  &&  m_id[i].station() >= 3)  ||  (m_id[i].endcap() == 2  &&  m_id[i].station() < 3));
00074 
00075     // get the alignable (or two alignables if in ME1/1)
00076     const DetId id(m_id[i]);
00077     Alignable *alignable = alignableNavigator->alignableFromDetId(id).alignable();
00078     Alignable *also = NULL;
00079     if (combineME11  &&  m_id[i].station() == 1  &&  m_id[i].ring() == 1) {
00080       CSCDetId alsoid(m_id[i].endcap(), 1, 4, m_id[i].chamber(), 0);
00081       const DetId alsoid2(alsoid);
00082       also = alignableNavigator->alignableFromDetId(alsoid2).alignable();
00083     }
00084 
00085     AlgebraicVector params(6);
00086     AlgebraicSymMatrix cov(6);
00087 
00088     if (mode == CSCPairResidualsConstraint::kModePhiy) {
00089       params[4] = m_value[i];
00090       cov[4][4] = 1e-6;
00091     }
00092     else if (mode == CSCPairResidualsConstraint::kModePhiPos) {
00093       GlobalPoint center = alignable->surface().toGlobal(LocalPoint(0., 0., 0.));
00094       double radius = sqrt(center.x()*center.x() + center.y()*center.y());
00095 
00096       double phi_correction = m_value[i];
00097       params[0] = -radius * sin(phi_correction) * (backward ? -1. : 1.);
00098       params[1] = radius * (cos(phi_correction) - 1.);
00099       params[5] = phi_correction * (backward ? -1. : 1.);
00100 
00101       cov[0][0] = 1e-6;
00102       cov[1][1] = 1e-6;
00103       cov[5][5] = 1e-6;
00104     }
00105     else if (mode == CSCPairResidualsConstraint::kModePhiz) {
00106       params[5] = m_value[i] * (backward ? -1. : 1.);
00107       cov[5][5] = 1e-6;
00108     }
00109     else assert(false);
00110 
00111     AlignmentParameters *parnew = alignable->alignmentParameters()->cloneFromSelected(params, cov);
00112     alignable->setAlignmentParameters(parnew);
00113     alignmentParameterStore->applyParameters(alignable);
00114     alignable->alignmentParameters()->setValid(true);
00115     if (also != NULL) {
00116       AlignmentParameters *parnew2 = also->alignmentParameters()->cloneFromSelected(params, cov);
00117       also->setAlignmentParameters(parnew2);
00118       alignmentParameterStore->applyParameters(also);
00119       also->alignmentParameters()->setValid(true);
00120     }
00121   }
00122 }