File indexing completed on 2024-04-06 11:56:09
0001 #include "TTree.h"
0002
0003 #include "Alignment/CommonAlignment/interface/Alignable.h"
0004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0005
0006 #include "Alignment/CommonAlignmentAlgorithm/interface/AlignableDataIORoot.h"
0007
0008
0009
0010 AlignableDataIORoot::AlignableDataIORoot(PosType p) : AlignableDataIO(p) {
0011 if (thePosType == Abs) {
0012 treename = "AlignablesAbsPos";
0013 treetxt = "Alignables abs.Pos";
0014 } else if (thePosType == Org) {
0015 treename = "AlignablesOrgPos";
0016 treetxt = "Alignables org.Pos";
0017 } else if (thePosType == Rel) {
0018 treename = "AlignablesRelPos";
0019 treetxt = "Alignables rel.Pos";
0020 }
0021 }
0022
0023
0024
0025
0026 void AlignableDataIORoot::createBranches(void) {
0027 tree->Branch("Id", &Id, "Id/i");
0028 tree->Branch("ObjId", &ObjId, "ObjId/I");
0029 tree->Branch("Pos", &Pos, "Pos[3]/D");
0030 tree->Branch("Rot", &Rot, "Rot[9]/D");
0031
0032 tree->Branch("NumDeform", &numDeformationValues_, "NumDeform/i");
0033 tree->Branch("DeformValues", deformationValues_, "DeformValues[NumDeform]/F");
0034 }
0035
0036
0037
0038
0039 void AlignableDataIORoot::setBranchAddresses(void) {
0040 tree->SetBranchAddress("Id", &Id);
0041 tree->SetBranchAddress("ObjId", &ObjId);
0042 tree->SetBranchAddress("Pos", &Pos);
0043 tree->SetBranchAddress("Rot", &Rot);
0044
0045 tree->SetBranchAddress("NumDeform", &numDeformationValues_);
0046 tree->SetBranchAddress("DeformValues", deformationValues_);
0047 }
0048
0049
0050
0051
0052 int AlignableDataIORoot::findEntry(align::ID id, align::StructureType comp) {
0053 if (newopen) {
0054 edm::LogInfo("Alignment") << "@SUB=AlignableDataIORoot::findEntry"
0055 << "Filling map ...";
0056 treemap.erase(treemap.begin(), treemap.end());
0057 for (int ev = 0; ev < tree->GetEntries(); ev++) {
0058 tree->GetEntry(ev);
0059 treemap[std::make_pair(Id, ObjId)] = ev;
0060 }
0061 newopen = false;
0062 }
0063
0064
0065 treemaptype::iterator imap = treemap.find(std::make_pair(id, comp));
0066 int result = -1;
0067 if (imap != treemap.end())
0068 result = (*imap).second;
0069 return result;
0070 }
0071
0072
0073 int AlignableDataIORoot::writeAbsRaw(const AlignableAbsData& ad) {
0074 const align::GlobalPoint& pos = ad.pos();
0075 align::RotationType rot = ad.rot();
0076 Id = ad.id();
0077 ObjId = ad.objId();
0078 Pos[0] = pos.x();
0079 Pos[1] = pos.y();
0080 Pos[2] = pos.z();
0081 Rot[0] = rot.xx();
0082 Rot[1] = rot.xy();
0083 Rot[2] = rot.xz();
0084 Rot[3] = rot.yx();
0085 Rot[4] = rot.yy();
0086 Rot[5] = rot.yz();
0087 Rot[6] = rot.zx();
0088 Rot[7] = rot.zy();
0089 Rot[8] = rot.zz();
0090
0091 const std::vector<double>& deformPars = ad.deformationParameters();
0092 numDeformationValues_ = (deformPars.size() > kMaxNumPar ? (unsigned)kMaxNumPar : deformPars.size());
0093 for (unsigned int i = 0; i < numDeformationValues_; ++i) {
0094 deformationValues_[i] = deformPars[i];
0095 }
0096
0097 tree->Fill();
0098 return 0;
0099 }
0100
0101
0102 int AlignableDataIORoot::writeRelRaw(const AlignableRelData& ad) {
0103 const align::GlobalVector& pos = ad.pos();
0104 align::RotationType rot = ad.rot();
0105 Id = ad.id();
0106 ObjId = ad.objId();
0107 Pos[0] = pos.x();
0108 Pos[1] = pos.y();
0109 Pos[2] = pos.z();
0110 Rot[0] = rot.xx();
0111 Rot[1] = rot.xy();
0112 Rot[2] = rot.xz();
0113 Rot[3] = rot.yx();
0114 Rot[4] = rot.yy();
0115 Rot[5] = rot.yz();
0116 Rot[6] = rot.zx();
0117 Rot[7] = rot.zy();
0118 Rot[8] = rot.zz();
0119
0120 const std::vector<double>& deformPars = ad.deformationParameters();
0121 numDeformationValues_ = (deformPars.size() > kMaxNumPar ? (unsigned)kMaxNumPar : deformPars.size());
0122 for (unsigned int i = 0; i < numDeformationValues_; ++i) {
0123 deformationValues_[i] = deformPars[i];
0124 }
0125
0126 tree->Fill();
0127 return 0;
0128 }
0129
0130
0131 AlignableAbsData AlignableDataIORoot::readAbsRaw(Alignable* ali, int& ierr) {
0132 align::GlobalPoint pos;
0133 align::RotationType rot;
0134
0135 align::StructureType typeId = ali->alignableObjectId();
0136 align::ID id = ali->id();
0137 std::vector<double> deformPars;
0138 deformPars.reserve(numDeformationValues_);
0139 int entry = findEntry(id, typeId);
0140 if (entry != -1) {
0141 tree->GetEntry(entry);
0142 align::GlobalPoint pos2(Pos[0], Pos[1], Pos[2]);
0143 align::RotationType rot2(Rot[0], Rot[1], Rot[2], Rot[3], Rot[4], Rot[5], Rot[6], Rot[7], Rot[8]);
0144 pos = pos2;
0145 rot = rot2;
0146
0147 for (unsigned int i = 0; i < numDeformationValues_; ++i) {
0148 deformPars.push_back((double)deformationValues_[i]);
0149 }
0150
0151 ierr = 0;
0152 } else
0153 ierr = -1;
0154
0155 return AlignableAbsData(pos, rot, id, typeId, deformPars);
0156 }
0157
0158
0159
0160 AlignableRelData AlignableDataIORoot::readRelRaw(Alignable* ali, int& ierr) {
0161 align::GlobalVector pos;
0162 align::RotationType rot;
0163
0164 align::StructureType typeId = ali->alignableObjectId();
0165 align::ID id = ali->id();
0166 std::vector<double> deformPars;
0167 deformPars.reserve(numDeformationValues_);
0168 int entry = findEntry(id, typeId);
0169 if (entry != -1) {
0170 tree->GetEntry(entry);
0171 align::GlobalVector pos2(Pos[0], Pos[1], Pos[2]);
0172 align::RotationType rot2(Rot[0], Rot[1], Rot[2], Rot[3], Rot[4], Rot[5], Rot[6], Rot[7], Rot[8]);
0173 pos = pos2;
0174 rot = rot2;
0175
0176 for (unsigned int i = 0; i < numDeformationValues_; ++i) {
0177 deformPars.push_back((double)deformationValues_[i]);
0178 }
0179
0180 ierr = 0;
0181 } else
0182 ierr = -1;
0183
0184 return AlignableRelData(pos, rot, id, typeId, deformPars);
0185 }