CMS 3D CMS Logo

AlignableDataIORoot.cc
Go to the documentation of this file.
1 #include "TTree.h"
2 
5 
7 
8 // ----------------------------------------------------------------------------
9 // constructor
12 {
13  if (thePosType == Abs) {
14  treename = "AlignablesAbsPos";
15  treetxt = "Alignables abs.Pos";
16  }
17  else if (thePosType == Org) {
18  treename = "AlignablesOrgPos";
19  treetxt = "Alignables org.Pos";
20  }
21  else if (thePosType == Rel) {
22  treename = "AlignablesRelPos";
23  treetxt = "Alignables rel.Pos";
24  }
25 }
26 
27 // ----------------------------------------------------------------------------
28 // create root tree branches (for writing)
29 
31 {
32  tree->Branch("Id", &Id, "Id/i");
33  tree->Branch("ObjId", &ObjId, "ObjId/I");
34  tree->Branch("Pos", &Pos, "Pos[3]/D");
35  tree->Branch("Rot", &Rot, "Rot[9]/D");
36 
37  tree->Branch("NumDeform", &numDeformationValues_, "NumDeform/i");
38  tree->Branch("DeformValues", deformationValues_, "DeformValues[NumDeform]/F");
39 }
40 
41 // ----------------------------------------------------------------------------
42 // set root tree branch addresses (for reading)
43 
45 {
46  tree->SetBranchAddress("Id", &Id);
47  tree->SetBranchAddress("ObjId", &ObjId);
48  tree->SetBranchAddress("Pos", &Pos);
49  tree->SetBranchAddress("Rot", &Rot);
50 
51  tree->SetBranchAddress("NumDeform", &numDeformationValues_);
52  tree->SetBranchAddress("DeformValues", deformationValues_);
53 }
54 
55 // ----------------------------------------------------------------------------
56 // find root tree entry based on IDs
57 
59 {
60  if (newopen) { // we're here first time
61  edm::LogInfo("Alignment") << "@SUB=AlignableDataIORoot::findEntry"
62  << "Filling map ...";
63  treemap.erase(treemap.begin(),treemap.end());
64  for (int ev = 0;ev<tree->GetEntries();ev++) {
65  tree->GetEntry(ev);
66  treemap[ std::make_pair(Id,ObjId) ] = ev;
67  }
68  newopen=false;
69  }
70 
71  // now we have filled the map
72  treemaptype::iterator imap = treemap.find( std::make_pair(id,comp) );
73  int result=-1;
74  if (imap != treemap.end()) result=(*imap).second;
75  return result;
76 
77 }
78 
79 // ----------------------------------------------------------------------------
81 {
82  const align::GlobalPoint& pos = ad.pos();
84  Id = ad.id();
85  ObjId = ad.objId();
86  Pos[0]=pos.x(); Pos[1]=pos.y(); Pos[2]=pos.z();
87  Rot[0]=rot.xx(); Rot[1]=rot.xy(); Rot[2]=rot.xz();
88  Rot[3]=rot.yx(); Rot[4]=rot.yy(); Rot[5]=rot.yz();
89  Rot[6]=rot.zx(); Rot[7]=rot.zy(); Rot[8]=rot.zz();
90 
91  const std::vector<double> &deformPars = ad.deformationParameters();
92  numDeformationValues_ = (deformPars.size() > kMaxNumPar ? kMaxNumPar : deformPars.size());
93  for (unsigned int i = 0; i < numDeformationValues_; ++i) {
94  deformationValues_[i] = deformPars[i];
95  }
96 
97  tree->Fill();
98  return 0;
99 }
100 
101 // ----------------------------------------------------------------------------
103 {
104  const align::GlobalVector& pos = ad.pos();
105  align::RotationType rot = ad.rot();
106  Id = ad.id();
107  ObjId = ad.objId();
108  Pos[0]=pos.x(); Pos[1]=pos.y(); Pos[2]=pos.z();
109  Rot[0]=rot.xx(); Rot[1]=rot.xy(); Rot[2]=rot.xz();
110  Rot[3]=rot.yx(); Rot[4]=rot.yy(); Rot[5]=rot.yz();
111  Rot[6]=rot.zx(); Rot[7]=rot.zy(); Rot[8]=rot.zz();
112 
113  const std::vector<double> &deformPars = ad.deformationParameters();
114  numDeformationValues_ = (deformPars.size() > kMaxNumPar ? kMaxNumPar : deformPars.size());
115  for (unsigned int i = 0; i < numDeformationValues_; ++i) {
116  deformationValues_[i] = deformPars[i];
117  }
118 
119  tree->Fill();
120  return 0;
121 }
122 
123 // ----------------------------------------------------------------------------
125 {
128 
129  align::StructureType typeId = ali->alignableObjectId();
130  align::ID id = ali->id();
131  std::vector<double> deformPars; deformPars.reserve(numDeformationValues_);
132  int entry = findEntry(id,typeId);
133  if(entry!=-1) {
134  tree->GetEntry(entry);
135  align::GlobalPoint pos2(Pos[0],Pos[1],Pos[2]);
136  align::RotationType rot2(Rot[0],Rot[1],Rot[2],
137  Rot[3],Rot[4],Rot[5],
138  Rot[6],Rot[7],Rot[8]);
139  pos=pos2;
140  rot=rot2;
141 
142  for (unsigned int i = 0; i < numDeformationValues_; ++i) {
143  deformPars.push_back((double)deformationValues_[i]);
144  }
145 
146  ierr=0;
147  }
148  else ierr=-1;
149 
150  return AlignableAbsData(pos,rot,id,typeId,deformPars);
151 }
152 
153 // ----------------------------------------------------------------------------
154 
156 {
159 
160  align::StructureType typeId = ali->alignableObjectId();
161  align::ID id = ali->id();
162  std::vector<double> deformPars; deformPars.reserve(numDeformationValues_);
163  int entry = findEntry(id,typeId);
164  if(entry!=-1) {
165  tree->GetEntry(entry);
166  align::GlobalVector pos2(Pos[0],Pos[1],Pos[2]);
167  align::RotationType rot2(Rot[0],Rot[1],Rot[2],
168  Rot[3],Rot[4],Rot[5],
169  Rot[6],Rot[7],Rot[8]);
170  pos=pos2;
171  rot=rot2;
172 
173  for (unsigned int i = 0; i < numDeformationValues_; ++i) {
174  deformPars.push_back((double)deformationValues_[i]);
175  }
176 
177  ierr=0;
178  }
179  else ierr=-1;
180 
181  return AlignableRelData(pos,rot,id,typeId,deformPars);
182 }
T xx() const
align::StructureType objId() const
Definition: AlignableData.h:30
AlignableDataIORoot(PosType p)
constructor
align::ID id() const
Return the ID of Alignable, i.e. DetId of &#39;first&#39; component GeomDet(Unit).
Definition: Alignable.h:189
void setBranchAddresses(void) override
set root branches
AlignableAbsData readAbsRaw(Alignable *ali, int &ierr) override
read absolute positions
uint32_t ID
Definition: Definitions.h:26
AlignableRelData readRelRaw(Alignable *ali, int &ierr) override
read relative positions
T y() const
Definition: PV3DBase.h:63
T yx() const
bool ev
AlignableData< align::GlobalVector > AlignableRelData
relative position/rotation
Definition: AlignableData.h:49
T zx() const
T xy() const
T zz() const
Float_t deformationValues_[kMaxNumPar]
virtual StructureType alignableObjectId() const =0
Return the alignable type identifier.
T z() const
Definition: PV3DBase.h:64
int findEntry(align::ID, align::StructureType)
T zy() const
T yy() const
void createBranches(void) override
create root branches
int writeRelRaw(const AlignableRelData &ad) override
write relative positions
align::StructureType ObjId
root tree contents
int writeAbsRaw(const AlignableAbsData &ad) override
write absolute positions
AlignableData< align::GlobalPoint > AlignableAbsData
Absolute position/rotation.
Definition: AlignableData.h:47
T xz() const
const std::vector< double > deformationParameters() const
Definition: AlignableData.h:32
Definition: tree.py:1
const T & pos() const
accessors
Definition: AlignableData.h:28
T x() const
Definition: PV3DBase.h:62
T yz() const
const align::RotationType & rot() const
Definition: AlignableData.h:29
align::ID id() const
Definition: AlignableData.h:31