File indexing completed on 2024-04-06 11:56:37
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "Alignment/MillePedeAlignmentAlgorithm/interface/MillePedeVariablesIORoot.h"
0010
0011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0012
0013 #include "Alignment/CommonAlignment/interface/Alignable.h"
0014 #include "Alignment/CommonAlignment/interface/AlignmentParameters.h"
0015 #include "Alignment/MillePedeAlignmentAlgorithm/interface/MillePedeVariables.h"
0016
0017 #include "TTree.h"
0018
0019
0020 MillePedeVariablesIORoot::MillePedeVariablesIORoot()
0021 : myId(0), myObjId(0), myNumPar(0), myHitsX(0), myHitsY(0), myLabel(0), myName(""), myNamePtr(&myName) {
0022 treename = "MillePedeUser";
0023 treetxt = "MillePede User Variables";
0024 for (unsigned int i = 0; i < kMaxNumPar; i++) {
0025 myIsValid[i] = 0;
0026 myDiffBefore[i] = 0.;
0027 myGlobalCor[i] = 0.;
0028 myPreSigma[i] = 0.;
0029 myParameter[i] = 0.;
0030 mySigma[i] = 0.;
0031 }
0032 }
0033
0034
0035 void MillePedeVariablesIORoot::writeMillePedeVariables(
0036 const align::Alignables &alivec, const char *filename, int iter, bool validCheck, int &ierr) {
0037 ierr = 0;
0038
0039 int iret = this->open(filename, iter, true);
0040 if (iret != 0) {
0041 ierr = -1;
0042 } else {
0043 iret = this->write(alivec, validCheck);
0044 tree->BuildIndex("Id", "ObjId");
0045 if (iret != 0) {
0046 ierr = -2;
0047 } else {
0048 iret = this->close();
0049 if (iret != 0) {
0050 ierr = -3;
0051 }
0052 }
0053 }
0054
0055 return;
0056 }
0057
0058
0059 std::vector<AlignmentUserVariables *> MillePedeVariablesIORoot::readMillePedeVariables(const align::Alignables &alivec,
0060 const char *filename,
0061 int iter,
0062 int &ierr) {
0063 std::vector<AlignmentUserVariables *> result;
0064 ierr = 0;
0065 int iret = this->open(filename, iter, false);
0066 if (iret != 0) {
0067 ierr = -1;
0068 } else {
0069 result = this->read(alivec, iret);
0070 if (iret != 0) {
0071 ierr = -2;
0072 } else {
0073 iret = this->close();
0074 if (iret != 0) {
0075 ierr = -3;
0076 }
0077 }
0078 }
0079
0080 return result;
0081 }
0082
0083
0084 int MillePedeVariablesIORoot::writeOne(Alignable *ali) {
0085 if (!ali || !ali->alignmentParameters() ||
0086 !dynamic_cast<MillePedeVariables *>(ali->alignmentParameters()->userVariables())) {
0087 edm::LogError("Alignment") << "@SUB=MillePedeVariablesIORoot::writeOne"
0088 << "No MillePedeVariables found!";
0089 return -1;
0090 }
0091
0092 const MillePedeVariables *mpVar = static_cast<MillePedeVariables *>(ali->alignmentParameters()->userVariables());
0093 myNumPar = mpVar->size();
0094 if (myNumPar >= kMaxNumPar) {
0095 edm::LogError("Alignment") << "@SUB=MillePedeVariablesIORoot::writeOne"
0096 << "Ignoring parameters " << static_cast<int>(kMaxNumPar) << " to " << myNumPar - 1;
0097 myNumPar = kMaxNumPar;
0098 }
0099
0100 for (unsigned int iPar = 0; iPar < myNumPar; ++iPar) {
0101 myIsValid[iPar] = mpVar->isValid()[iPar];
0102 myDiffBefore[iPar] = mpVar->diffBefore()[iPar];
0103 myGlobalCor[iPar] = mpVar->globalCor()[iPar];
0104 myPreSigma[iPar] = mpVar->preSigma()[iPar];
0105 myParameter[iPar] = mpVar->parameter()[iPar];
0106 mySigma[iPar] = mpVar->sigma()[iPar];
0107 }
0108 myHitsX = mpVar->hitsX();
0109 myHitsY = mpVar->hitsY();
0110 myLabel = mpVar->label();
0111 myName = mpVar->name();
0112
0113 myId = ali->id();
0114 myObjId = ali->alignableObjectId();
0115
0116 tree->Fill();
0117
0118 return 0;
0119 }
0120
0121
0122 AlignmentUserVariables *MillePedeVariablesIORoot::readOne(Alignable *ali, int &ierr) {
0123 ierr = 0;
0124
0125 if (tree->GetEntryWithIndex(ali->id(), ali->alignableObjectId()) < 0) {
0126 edm::LogError("Alignment") << "@SUB=MillePedeVariablesIORoot::readOne"
0127 << "No index for id/type = (" << ali->id() << "/" << ali->alignableObjectId()
0128 << ") found!";
0129 ierr = 1;
0130 return nullptr;
0131 }
0132
0133 MillePedeVariables *mpVar = new MillePedeVariables(myNumPar, myLabel, myName);
0134 for (unsigned int iPar = 0; iPar < myNumPar; ++iPar) {
0135 mpVar->isValid()[iPar] = myIsValid[iPar];
0136 mpVar->diffBefore()[iPar] = myDiffBefore[iPar];
0137 mpVar->globalCor()[iPar] = myGlobalCor[iPar];
0138 mpVar->preSigma()[iPar] = myPreSigma[iPar];
0139 mpVar->parameter()[iPar] = myParameter[iPar];
0140 mpVar->sigma()[iPar] = mySigma[iPar];
0141 }
0142 mpVar->setHitsX(myHitsX);
0143 mpVar->setHitsY(myHitsY);
0144
0145 return mpVar;
0146 }
0147
0148
0149 void MillePedeVariablesIORoot::createBranches() {
0150 tree->Branch("Id", &myId, "Id/i");
0151 tree->Branch("ObjId", &myObjId, "ObjId/I");
0152 tree->Branch("NumPar", &myNumPar, "NumPar/i");
0153 tree->Branch("IsValid", myIsValid, "IsValid[NumPar]/b");
0154 tree->Branch("DiffBefore", myDiffBefore, "DiffBefore[NumPar]/F");
0155 tree->Branch("GlobalCor", myGlobalCor, "GlobalCor[NumPar]/F");
0156 tree->Branch("PreSigma", myPreSigma, "PreSigma[NumPar]/F");
0157 tree->Branch("Par", myParameter, "Par[NumPar]/F");
0158 tree->Branch("Sigma", mySigma, "Sigma[NumPar]/F");
0159 tree->Branch("HitsX", &myHitsX, "HitsX/i");
0160 tree->Branch("HitsY", &myHitsY, "HitsY/i");
0161 tree->Branch("Label", &myLabel, "Label/i");
0162 tree->Branch("Name", &myNamePtr);
0163 }
0164
0165
0166 void MillePedeVariablesIORoot::setBranchAddresses() {
0167 tree->SetBranchAddress("Id", &myId);
0168 tree->SetBranchAddress("ObjId", &myObjId);
0169 tree->SetBranchAddress("NumPar", &myNumPar);
0170 tree->SetBranchAddress("IsValid", myIsValid);
0171 tree->SetBranchAddress("DiffBefore", myDiffBefore);
0172 tree->SetBranchAddress("GlobalCor", myGlobalCor);
0173 tree->SetBranchAddress("PreSigma", myPreSigma);
0174 tree->SetBranchAddress("Par", myParameter);
0175 tree->SetBranchAddress("Sigma", mySigma);
0176 tree->SetBranchAddress("HitsX", &myHitsX);
0177 tree->SetBranchAddress("HitsY", &myHitsY);
0178 tree->SetBranchAddress("Label", &myLabel);
0179 tree->SetBranchAddress("Name", &myNamePtr);
0180 }