00001
00011
00012 #include "Alignment/MillePedeAlignmentAlgorithm/interface/MillePedeVariablesIORoot.h"
00013
00014 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00015
00016 #include "Alignment/CommonAlignment/interface/Alignable.h"
00017 #include "Alignment/CommonAlignment/interface/AlignmentParameters.h"
00018 #include "Alignment/MillePedeAlignmentAlgorithm/interface/MillePedeVariables.h"
00019
00020 #include "TTree.h"
00021
00022
00023 MillePedeVariablesIORoot::MillePedeVariablesIORoot()
00024 {
00025 treename = "MillePedeUser";
00026 treetxt = "MillePede User Variables";
00027 }
00028
00029
00030 void MillePedeVariablesIORoot::writeMillePedeVariables
00031 (const std::vector<Alignable*> &alivec, const char *filename, int iter, bool validCheck, int &ierr)
00032 {
00033 ierr = 0;
00034
00035 int iret = this->open(filename, iter, true);
00036 if (iret != 0) {
00037 ierr = -1;
00038 } else {
00039 iret = this->write(alivec, validCheck);
00040 tree->BuildIndex("Id", "ObjId");
00041 if (iret != 0) {
00042 ierr = -2;
00043 } else {
00044 iret = this->close();
00045 if (iret != 0) {
00046 ierr = -3;
00047 }
00048 }
00049 }
00050
00051 return;
00052 }
00053
00054
00055 std::vector<AlignmentUserVariables*> MillePedeVariablesIORoot::readMillePedeVariables
00056 (const std::vector<Alignable*> &alivec, const char *filename, int iter, int &ierr)
00057 {
00058 std::vector<AlignmentUserVariables*> result;
00059 ierr = 0;
00060 int iret = this->open(filename, iter, false);
00061 if (iret != 0) {
00062 ierr = -1;
00063 } else {
00064 result = this->read(alivec, iret);
00065 if (iret != 0) {
00066 ierr = -2;
00067 } else {
00068 iret = this->close();
00069 if (iret != 0) {
00070 ierr = -3;
00071 }
00072 }
00073 }
00074
00075 return result;
00076 }
00077
00078
00079 int MillePedeVariablesIORoot::writeOne(Alignable* ali)
00080 {
00081 if (!ali || !ali->alignmentParameters()
00082 || !dynamic_cast<MillePedeVariables*>(ali->alignmentParameters()->userVariables())) {
00083 edm::LogError("Alignment") << "@SUB=MillePedeVariablesIORoot::writeOne"
00084 << "No MillePedeVariables found!";
00085 return -1;
00086 }
00087
00088 const MillePedeVariables *mpVar =
00089 dynamic_cast<MillePedeVariables*>(ali->alignmentParameters()->userVariables());
00090 myNumPar = mpVar->size();
00091 if (myNumPar >= kMaxNumPar) {
00092 edm::LogError("Alignment") << "@SUB=MillePedeVariablesIORoot::writeOne"
00093 << "Ignoring parameters " << static_cast<int>(kMaxNumPar) << " to " << myNumPar-1;
00094 myNumPar = kMaxNumPar;
00095 }
00096
00097 for (unsigned int iPar = 0; iPar < myNumPar; ++iPar) {
00098 myIsValid[iPar] = mpVar->isValid()[iPar];
00099 myDiffBefore[iPar] = mpVar->diffBefore()[iPar];
00100 myGlobalCor[iPar] = mpVar->globalCor()[iPar];
00101 myPreSigma[iPar] = mpVar->preSigma()[iPar];
00102 myParameter[iPar] = mpVar->parameter()[iPar];
00103 mySigma[iPar] = mpVar->sigma()[iPar];
00104 }
00105 myHitsX = mpVar->hitsX();
00106 myHitsY = mpVar->hitsY();
00107 myLabel = mpVar->label();
00108
00109 myId = ali->id();
00110 myObjId = ali->alignableObjectId();
00111
00112 tree->Fill();
00113
00114 return 0;
00115 }
00116
00117
00118 AlignmentUserVariables* MillePedeVariablesIORoot::readOne(Alignable *ali, int &ierr)
00119 {
00120 ierr = 0;
00121
00122 if (tree->GetEntryWithIndex(ali->id(), ali->alignableObjectId()) < 0) {
00123 edm::LogError("Alignment") << "@SUB=MillePedeVariablesIORoot::readOne"
00124 << "No index for id/type = (" << ali->id() << "/"
00125 << ali->alignableObjectId() << ") found!";
00126 ierr = 1;
00127 return 0;
00128 }
00129
00130 MillePedeVariables *mpVar = new MillePedeVariables(myNumPar);
00131 for (unsigned int iPar = 0; iPar < myNumPar; ++iPar) {
00132 mpVar->isValid()[iPar] = myIsValid[iPar];
00133 mpVar->diffBefore()[iPar] = myDiffBefore[iPar];
00134 mpVar->globalCor()[iPar] = myGlobalCor[iPar];
00135 mpVar->preSigma()[iPar] = myPreSigma[iPar];
00136 mpVar->parameter()[iPar] = myParameter[iPar];
00137 mpVar->sigma()[iPar] = mySigma[iPar];
00138 }
00139 mpVar->setHitsX(myHitsX);
00140 mpVar->setHitsY(myHitsY);
00141 mpVar->setLabel(myLabel);
00142
00143 return mpVar;
00144 }
00145
00146
00147 void MillePedeVariablesIORoot::createBranches()
00148 {
00149 tree->Branch("Id", &myId, "Id/i");
00150 tree->Branch("ObjId", &myObjId, "ObjId/I");
00151 tree->Branch("NumPar", &myNumPar, "NumPar/i");
00152 tree->Branch("IsValid", myIsValid, "IsValid[NumPar]/b");
00153 tree->Branch("DiffBefore", myDiffBefore,"DiffBefore[NumPar]/F");
00154 tree->Branch("GlobalCor", myGlobalCor, "GlobalCor[NumPar]/F");
00155 tree->Branch("PreSigma", myPreSigma, "PreSigma[NumPar]/F");
00156 tree->Branch("Par", myParameter, "Par[NumPar]/F");
00157 tree->Branch("Sigma", mySigma, "Sigma[NumPar]/F");
00158 tree->Branch("HitsX", &myHitsX, "HitsX/i");
00159 tree->Branch("HitsY", &myHitsY, "HitsY/i");
00160 tree->Branch("Label", &myLabel, "Label/i");
00161 }
00162
00163
00164 void MillePedeVariablesIORoot::setBranchAddresses()
00165 {
00166 tree->SetBranchAddress("Id", &myId);
00167 tree->SetBranchAddress("ObjId", &myObjId);
00168 tree->SetBranchAddress("NumPar", &myNumPar);
00169 tree->SetBranchAddress("IsValid", myIsValid);
00170 tree->SetBranchAddress("DiffBefore", myDiffBefore);
00171 tree->SetBranchAddress("GlobalCor", myGlobalCor);
00172 tree->SetBranchAddress("PreSigma", myPreSigma);
00173 tree->SetBranchAddress("Par", myParameter);
00174 tree->SetBranchAddress("Sigma", mySigma);
00175 tree->SetBranchAddress("HitsX", &myHitsX);
00176 tree->SetBranchAddress("HitsY", &myHitsY);
00177 tree->SetBranchAddress("Label", &myLabel);
00178 }