#include <Alignment/MuonStandaloneAlgorithm/plugins/StandaloneMerger.h>
Public Member Functions | |
void | analyze (const edm::Event &event, const edm::EventSetup &eventSetup) |
virtual void | beginJob (const edm::EventSetup &eventSetup) |
virtual void | endJob () |
StandaloneMerger (const edm::ParameterSet &pset) | |
Constructor. | |
virtual | ~StandaloneMerger () |
Destructor. | |
Private Member Functions | |
void | BuildDelta () |
bool | CalculateSolution () |
void | mergeMatrix () |
void | surveyAdd () |
void | updateMatrix (TMatrixD *, TMatrixD *, TMatrixD *, TMatrixD *) |
Private Attributes | |
TMatrixD | b |
TMatrixD | C |
TMatrixD | CMatrixInvert |
TMatrixD | Delta |
TFile * | f |
TMatrixD | IndependentVector |
int | maxFiles |
TMatrixD | N |
std::string | outputFile |
TMatrixD | Q |
TMatrixD | R |
std::string | submatrices |
std::string | surveyFileName |
TMatrixD | SurveyMatrix |
TMatrixD | SurveyVector |
TFile * | theFile |
TMatrixD | theIndex |
TMatrixD | TotalMatrix |
TMatrixD | TotalVector |
Static Private Attributes | |
static const int | NDOFAlign = 6 |
static const int | NDOFChamber = 4 |
static const int | NDOFCoor = 4 |
static const int | NDOFTrack = 5 |
Definition at line 31 of file StandaloneMerger.h.
StandaloneMerger::StandaloneMerger | ( | const edm::ParameterSet & | pset | ) |
Constructor.
Definition at line 45 of file StandaloneMerger.cc.
References edm::ParameterSet::getParameter(), maxFiles, outputFile, submatrices, and surveyFileName.
00045 { 00046 00047 maxFiles = pset.getParameter<int>("maxFiles"); 00048 surveyFileName = pset.getParameter<std::string>("surveyFileName"); 00049 outputFile = pset.getParameter<std::string>("outputFileName"); 00050 submatrices = pset.getParameter<std::string>("subMatrixDir"); 00051 }
StandaloneMerger::~StandaloneMerger | ( | ) | [virtual] |
void StandaloneMerger::analyze | ( | const edm::Event & | event, | |
const edm::EventSetup & | eventSetup | |||
) | [virtual] |
void StandaloneMerger::beginJob | ( | const edm::EventSetup & | eventSetup | ) | [virtual] |
Reimplemented from edm::EDAnalyzer.
Definition at line 133 of file StandaloneMerger.cc.
References b, C, CMatrixInvert, GenMuonPlsPt100GeV_cfg::cout, Delta, lat::endl(), mergeMatrix(), N, surveyAdd(), theIndex, TotalMatrix, and TotalVector.
00133 { 00134 00135 00136 //Set the size of Matrizes to 0 00137 C.ResizeTo(0,0); 00138 b.ResizeTo(0,0); 00139 theIndex.ResizeTo(0,0); 00140 N.ResizeTo(1,1); 00141 00142 00143 mergeMatrix(); // This method reads matrizes in C and alignables vector 00144 surveyAdd(); 00145 CMatrixInvert.ResizeTo(C.GetNrows(), C.GetNcols()); 00146 CMatrixInvert = TotalMatrix; 00147 CMatrixInvert.Invert(); 00148 Delta.ResizeTo(C.GetNrows(), 1); 00149 Delta = CMatrixInvert*TotalVector; 00150 TMatrixD unit, unit2; 00151 unit.ResizeTo(C.GetNrows(), C.GetNcols()); 00152 unit2.ResizeTo(C.GetNrows(), C.GetNcols()); 00153 unit.UnitMatrix(); 00154 unit2 = unit-CMatrixInvert*TotalMatrix; 00155 std::cout << "Inversion check: " << unit2.E2Norm() << std::endl; 00156 00157 }
void StandaloneMerger::BuildDelta | ( | ) | [private] |
Definition at line 161 of file StandaloneMerger.cc.
References C, Delta, i, IndependentVector, j, and R.
00161 { 00162 00163 Delta.ResizeTo(C.GetNrows(), 1); 00164 for(int j = C.GetNrows()-1; j >= 0; --j) { 00165 double acum = 0.0; 00166 for(int i = C.GetNrows()-1; i > j; --i) { 00167 acum += R(j, i)*Delta(i,0); 00168 } 00169 Delta(j,0) = (IndependentVector(j,0)-acum)/R(j,j); 00170 } 00171 }
bool StandaloneMerger::CalculateSolution | ( | ) | [private] |
Definition at line 176 of file StandaloneMerger.cc.
References CMatrixInvert, IndependentVector, Q, and R.
00176 { 00177 00178 //Decomp = new TDecompQRH(CMatrixInvert, 1e-30); 00179 Q.ResizeTo(CMatrixInvert.GetNrows(), CMatrixInvert.GetNcols()); 00180 R.ResizeTo(CMatrixInvert.GetNrows(), CMatrixInvert.GetNcols()); 00181 IndependentVector.ResizeTo(CMatrixInvert.GetNrows(), 1); 00182 return true; 00183 /*if(Decomp->Decompose()) { 00184 Q = Decomp->GetQ(); 00185 R = Decomp->GetR(); 00186 IndependentVector = Q*TotalVector; 00187 BuildDelta(); 00188 //delete Decomp; 00189 return true; 00190 } else { 00191 //delete Decomp; 00192 return false; 00193 }*/ 00194 }
Reimplemented from edm::EDAnalyzer.
Definition at line 197 of file StandaloneMerger.cc.
References b, C, CMatrixInvert, Delta, N, outputFile, SurveyMatrix, SurveyVector, theFile, theIndex, TotalMatrix, and TotalVector.
00197 { 00198 00199 //Output root file is opened for writting 00200 00201 theFile = TFile::Open(outputFile.c_str(), "RECREATE"); 00202 theFile->cd(); 00203 00204 C.Write("CMatrix"); 00205 b.Write("bMatrix"); 00206 Delta.Write("Delta"); 00207 CMatrixInvert.Write("CMatrixInvert"); 00208 theIndex.Write("Index"); 00209 N.Write("numberOfTracks"); 00210 SurveyMatrix.Write("SurveyMatrix"); 00211 SurveyVector.Write("SurveyVector"); 00212 TotalMatrix.Write("TotalMatrix"); 00213 TotalVector.Write("TotalVector"); 00214 //Q.Write("Q"); 00215 //R.Write("R"); 00216 //IndependentVector.Write("IndependentVector"); 00217 00218 theFile->Close(); 00219 00220 }
void StandaloneMerger::mergeMatrix | ( | ) | [private] |
Definition at line 108 of file StandaloneMerger.cc.
References GenMuonPlsPt100GeV_cfg::cout, lat::endl(), f, in, maxFiles, name, submatrices, and updateMatrix().
Referenced by beginJob().
00108 { 00109 00110 for(int counterOfFiles = 0; counterOfFiles < maxFiles; ++counterOfFiles) { 00111 00112 char name[100]; 00113 sprintf(name, "%s/SubMatrices_%d.root", submatrices.c_str(), counterOfFiles); 00114 00115 f = new TFile(name, "READ"); 00116 if(f->IsZombie()) continue; 00117 std::cout << "Analyzing: " << name << std::endl; 00118 TMatrixD *Cm = (TMatrixD *)f->Get("CMatrix"); 00119 TMatrixD *bm = (TMatrixD *)f->Get("bMatrix"); 00120 TMatrixD *in = (TMatrixD *)f->Get("Index"); 00121 TMatrixD *numberOfTracks = (TMatrixD *)f->Get("numberOfTracks"); 00122 updateMatrix(Cm, bm, in, numberOfTracks); 00123 00124 f->Close(); 00125 delete f; 00126 delete Cm; 00127 delete bm; 00128 delete in; 00129 } 00130 }
void StandaloneMerger::surveyAdd | ( | ) | [private] |
Definition at line 227 of file StandaloneMerger.cc.
References b, C, counter(), i, j, NDOFAlign, surveyFileName, SurveyMatrix, SurveyVector, theIndex, TotalMatrix, and TotalVector.
Referenced by beginJob().
00227 { 00228 00229 SurveyMatrix.ResizeTo(theIndex.GetNrows()*NDOFAlign, theIndex.GetNrows()*NDOFAlign); 00230 SurveyVector.ResizeTo(theIndex.GetNrows()*NDOFAlign, 1); 00231 TotalMatrix.ResizeTo(theIndex.GetNrows()*NDOFAlign, theIndex.GetNrows()*NDOFAlign); 00232 TotalVector.ResizeTo(theIndex.GetNrows()*NDOFAlign, 1); 00233 00234 00235 00236 TMatrixD SurveyDat(theIndex.GetNrows()*NDOFAlign, 1); 00237 00238 TFile surveyFile(surveyFileName.c_str()); 00239 TMatrixD *SurveyCov = (TMatrixD *)surveyFile.Get("SurveyCov"); 00240 TMatrixD *SurveyData = (TMatrixD *)surveyFile.Get("SurveyData"); 00241 TMatrixD *SurveyIndex = (TMatrixD *)surveyFile.Get("SurveyIndex"); 00242 00243 00244 00245 std::vector<long> realIndex; 00246 for(int counter = 0; counter < theIndex.GetNrows(); ++counter) { 00247 for(int counterC = 0; counterC < SurveyIndex->GetNrows(); ++counterC) { 00248 if(theIndex(counter,0) == (*SurveyIndex)(counterC,0)) { 00249 realIndex.push_back(counterC); 00250 break; 00251 } 00252 } 00253 } 00254 00255 for(int counteri = 0; counteri < theIndex.GetNrows(); ++counteri) { 00256 for(int alignN = 0; alignN < NDOFAlign; ++alignN) { 00257 SurveyDat(counteri*NDOFAlign+alignN, 0) = (*SurveyData)(realIndex.at(counteri)*NDOFAlign+alignN, 0); 00258 for(int alignN2 = 0; alignN2 < NDOFAlign; ++alignN2) { 00259 for(int counterj = 0; counterj < theIndex.GetNrows(); ++counterj) { 00260 SurveyMatrix(counteri*NDOFAlign+alignN, counterj*NDOFAlign+alignN2) = (*SurveyCov)(realIndex.at(counteri)*NDOFAlign+alignN, realIndex.at(counterj)*NDOFAlign+alignN2); 00261 } 00262 } 00263 } 00264 } 00265 00266 SurveyVector = SurveyMatrix*SurveyDat; 00267 00268 for(int i = 0; i < SurveyMatrix.GetNrows(); ++i) { 00269 for(int j = 0; j < SurveyMatrix.GetNcols(); ++j) { 00270 SurveyMatrix(i,j) = SurveyMatrix(i,j); 00271 } 00272 SurveyVector(i,0) = SurveyVector(i,0); 00273 } 00274 00275 00276 TotalMatrix = SurveyMatrix + C; 00277 TotalVector = SurveyVector + b; 00278 00279 00280 00281 surveyFile.Close(); 00282 00283 }
void StandaloneMerger::updateMatrix | ( | TMatrixD * | Cm, | |
TMatrixD * | bm, | |||
TMatrixD * | in, | |||
TMatrixD * | numberOfTracks | |||
) | [private] |
Definition at line 58 of file StandaloneMerger.cc.
References b, C, GenMuonPlsPt100GeV_cfg::cout, lat::endl(), N, NDOFAlign, and theIndex.
Referenced by mergeMatrix().
00058 { 00059 00060 00061 /*if(Cm->E2Norm() > 1e7 || bm->E2Norm() > 1.0e5) { 00062 std::cout << "Bad Matrix. Skipping file" << std::endl; 00063 return; 00064 }*/ 00065 00066 //Cm->Print("CMatrix"); 00067 //bm->Print("bMatrix"); 00068 00069 00070 TMatrixD realIndex(in->GetNrows(), 1); 00071 00072 N(0,0) += (*numberOfTracks)(0,0); 00073 00074 for(int indexCounter = 0; indexCounter < in->GetNrows(); ++indexCounter) { 00075 bool oldIndex = false; 00076 for(int theIndexCounter = 0; theIndexCounter < theIndex.GetNrows(); ++theIndexCounter) { 00077 if(theIndex(theIndexCounter, 0) == (*in)(indexCounter, 0)) { 00078 realIndex(indexCounter, 0) = theIndexCounter; 00079 oldIndex = true; 00080 break; 00081 } 00082 } 00083 if(oldIndex == false) { 00084 theIndex.ResizeTo(theIndex.GetNrows()+1,1); 00085 C.ResizeTo(C.GetNrows()+NDOFAlign, C.GetNcols()+NDOFAlign); 00086 b.ResizeTo(b.GetNrows()+NDOFAlign, 1); 00087 theIndex(theIndex.GetNrows()-1, 0) = (*in)(indexCounter, 0); 00088 realIndex(indexCounter, 0) = theIndex.GetNrows()-1; 00089 } 00090 } 00091 00092 for(int param = 0; param < NDOFAlign; param++) { 00093 for(int rowCounter = 0; rowCounter < in->GetNrows(); rowCounter++) { 00094 for(int param2 = 0; param2 < NDOFAlign; param2++) { 00095 for(int columnCounter = 0; columnCounter < in->GetNrows(); columnCounter++) { 00096 C((int)realIndex(rowCounter,0)*NDOFAlign+param, (int)realIndex(columnCounter,0)*NDOFAlign+param2) += (*Cm)(rowCounter*NDOFAlign+param, columnCounter*NDOFAlign+param2); 00097 if(C((int)realIndex(rowCounter,0)*NDOFAlign+param, (int)realIndex(columnCounter,0)*NDOFAlign+param2) > 1e100) { 00098 std::cout << "Error. Anormal values of matrix: " << std::endl; 00099 } 00100 } 00101 } 00102 b((int)realIndex(rowCounter,0)*NDOFAlign+param,0) += (*bm)(rowCounter*NDOFAlign+param, 0); 00103 } 00104 } 00105 }
TMatrixD StandaloneMerger::b [private] |
Definition at line 64 of file StandaloneMerger.h.
Referenced by beginJob(), endJob(), surveyAdd(), and updateMatrix().
TMatrixD StandaloneMerger::C [private] |
Definition at line 62 of file StandaloneMerger.h.
Referenced by beginJob(), BuildDelta(), endJob(), surveyAdd(), and updateMatrix().
TMatrixD StandaloneMerger::CMatrixInvert [private] |
Definition at line 63 of file StandaloneMerger.h.
Referenced by beginJob(), CalculateSolution(), and endJob().
TMatrixD StandaloneMerger::Delta [private] |
Definition at line 65 of file StandaloneMerger.h.
Referenced by beginJob(), BuildDelta(), and endJob().
TFile* StandaloneMerger::f [private] |
TMatrixD StandaloneMerger::IndependentVector [private] |
Definition at line 74 of file StandaloneMerger.h.
Referenced by BuildDelta(), and CalculateSolution().
int StandaloneMerger::maxFiles [private] |
Definition at line 77 of file StandaloneMerger.h.
Referenced by mergeMatrix(), and StandaloneMerger().
TMatrixD StandaloneMerger::N [private] |
Definition at line 69 of file StandaloneMerger.h.
Referenced by beginJob(), endJob(), and updateMatrix().
const int StandaloneMerger::NDOFAlign = 6 [static, private] |
const int StandaloneMerger::NDOFChamber = 4 [static, private] |
Definition at line 84 of file StandaloneMerger.h.
const int StandaloneMerger::NDOFCoor = 4 [static, private] |
Definition at line 85 of file StandaloneMerger.h.
const int StandaloneMerger::NDOFTrack = 5 [static, private] |
Definition at line 82 of file StandaloneMerger.h.
std::string StandaloneMerger::outputFile [private] |
TMatrixD StandaloneMerger::Q [private] |
TMatrixD StandaloneMerger::R [private] |
Definition at line 73 of file StandaloneMerger.h.
Referenced by BuildDelta(), and CalculateSolution().
std::string StandaloneMerger::submatrices [private] |
Definition at line 80 of file StandaloneMerger.h.
Referenced by mergeMatrix(), and StandaloneMerger().
std::string StandaloneMerger::surveyFileName [private] |
Definition at line 78 of file StandaloneMerger.h.
Referenced by StandaloneMerger(), and surveyAdd().
TMatrixD StandaloneMerger::SurveyMatrix [private] |
TMatrixD StandaloneMerger::SurveyVector [private] |
TFile* StandaloneMerger::theFile [private] |
TMatrixD StandaloneMerger::theIndex [private] |
Definition at line 66 of file StandaloneMerger.h.
Referenced by beginJob(), endJob(), surveyAdd(), and updateMatrix().
TMatrixD StandaloneMerger::TotalMatrix [private] |
Definition at line 70 of file StandaloneMerger.h.
Referenced by beginJob(), endJob(), and surveyAdd().
TMatrixD StandaloneMerger::TotalVector [private] |
Definition at line 71 of file StandaloneMerger.h.
Referenced by beginJob(), endJob(), and surveyAdd().