CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MillePedeVariablesIORoot.cc
Go to the documentation of this file.
1 
11 // this class's header
13 
15 
19 
20 #include "TTree.h"
21 
22 // -------------------------------------------------------------------------------------------------
24 {
25  treename = "MillePedeUser";
26  treetxt = "MillePede User Variables";
27 }
28 
29 // -------------------------------------------------------------------------------------------------
31 (const std::vector<Alignable*> &alivec, const char *filename, int iter, bool validCheck, int &ierr)
32 {
33  ierr = 0;
34 
35  int iret = this->open(filename, iter, true);
36  if (iret != 0) {
37  ierr = -1;
38  } else {
39  iret = this->write(alivec, validCheck);
40  tree->BuildIndex("Id", "ObjId");
41  if (iret != 0) {
42  ierr = -2;
43  } else {
44  iret = this->close();
45  if (iret != 0) {
46  ierr = -3;
47  }
48  }
49  }
50 
51  return;
52 }
53 
54 // -------------------------------------------------------------------------------------------------
55 std::vector<AlignmentUserVariables*> MillePedeVariablesIORoot::readMillePedeVariables
56 (const std::vector<Alignable*> &alivec, const char *filename, int iter, int &ierr)
57 {
58  std::vector<AlignmentUserVariables*> result;
59  ierr = 0;
60  int iret = this->open(filename, iter, false);
61  if (iret != 0) {
62  ierr = -1;
63  } else {
64  result = this->read(alivec, iret);
65  if (iret != 0) {
66  ierr = -2;
67  } else {
68  iret = this->close();
69  if (iret != 0) {
70  ierr = -3;
71  }
72  }
73  }
74 
75  return result;
76 }
77 
78 // -------------------------------------------------------------------------------------------------
80 {
81  if (!ali || !ali->alignmentParameters()
82  || !dynamic_cast<MillePedeVariables*>(ali->alignmentParameters()->userVariables())) {
83  edm::LogError("Alignment") << "@SUB=MillePedeVariablesIORoot::writeOne"
84  << "No MillePedeVariables found!";
85  return -1;
86  }
87 
88  const MillePedeVariables *mpVar =
89  static_cast<MillePedeVariables*>(ali->alignmentParameters()->userVariables());
90  myNumPar = mpVar->size();
91  if (myNumPar >= kMaxNumPar) {
92  edm::LogError("Alignment") << "@SUB=MillePedeVariablesIORoot::writeOne"
93  << "Ignoring parameters " << static_cast<int>(kMaxNumPar) << " to " << myNumPar-1;
95  }
96 
97  for (unsigned int iPar = 0; iPar < myNumPar; ++iPar) {
98  myIsValid[iPar] = mpVar->isValid()[iPar];
99  myDiffBefore[iPar] = mpVar->diffBefore()[iPar];
100  myGlobalCor[iPar] = mpVar->globalCor()[iPar];
101  myPreSigma[iPar] = mpVar->preSigma()[iPar];
102  myParameter[iPar] = mpVar->parameter()[iPar];
103  mySigma[iPar] = mpVar->sigma()[iPar];
104  }
105  myHitsX = mpVar->hitsX();
106  myHitsY = mpVar->hitsY();
107  myLabel = mpVar->label();
108 
109  myId = ali->id();
110  myObjId = ali->alignableObjectId();
111 
112  tree->Fill();
113 
114  return 0;
115 }
116 
117 // -------------------------------------------------------------------------------------------------
119 {
120  ierr = 0;
121 
122  if (tree->GetEntryWithIndex(ali->id(), ali->alignableObjectId()) < 0) {
123  edm::LogError("Alignment") << "@SUB=MillePedeVariablesIORoot::readOne"
124  << "No index for id/type = (" << ali->id() << "/"
125  << ali->alignableObjectId() << ") found!";
126  ierr = 1;
127  return 0;
128  }
129 
131  for (unsigned int iPar = 0; iPar < myNumPar; ++iPar) {
132  mpVar->isValid()[iPar] = myIsValid[iPar];
133  mpVar->diffBefore()[iPar] = myDiffBefore[iPar];
134  mpVar->globalCor()[iPar] = myGlobalCor[iPar];
135  mpVar->preSigma()[iPar] = myPreSigma[iPar];
136  mpVar->parameter()[iPar] = myParameter[iPar];
137  mpVar->sigma()[iPar] = mySigma[iPar];
138  }
139  mpVar->setHitsX(myHitsX);
140  mpVar->setHitsY(myHitsY);
141 
142  return mpVar;
143 }
144 
145 // -------------------------------------------------------------------------------------------------
147 {
148  tree->Branch("Id", &myId, "Id/i");
149  tree->Branch("ObjId", &myObjId, "ObjId/I");
150  tree->Branch("NumPar", &myNumPar, "NumPar/i");
151  tree->Branch("IsValid", myIsValid, "IsValid[NumPar]/b");
152  tree->Branch("DiffBefore", myDiffBefore,"DiffBefore[NumPar]/F");
153  tree->Branch("GlobalCor", myGlobalCor, "GlobalCor[NumPar]/F");
154  tree->Branch("PreSigma", myPreSigma, "PreSigma[NumPar]/F");
155  tree->Branch("Par", myParameter, "Par[NumPar]/F"); // name as in AlignmentParametersIORoot
156  tree->Branch("Sigma", mySigma, "Sigma[NumPar]/F");
157  tree->Branch("HitsX", &myHitsX, "HitsX/i");
158  tree->Branch("HitsY", &myHitsY, "HitsY/i");
159  tree->Branch("Label", &myLabel, "Label/i");
160 }
161 
162 // -------------------------------------------------------------------------------------------------
164 {
165  tree->SetBranchAddress("Id", &myId);
166  tree->SetBranchAddress("ObjId", &myObjId);
167  tree->SetBranchAddress("NumPar", &myNumPar);
168  tree->SetBranchAddress("IsValid", myIsValid);
169  tree->SetBranchAddress("DiffBefore", myDiffBefore);
170  tree->SetBranchAddress("GlobalCor", myGlobalCor);
171  tree->SetBranchAddress("PreSigma", myPreSigma);
172  tree->SetBranchAddress("Par", myParameter);
173  tree->SetBranchAddress("Sigma", mySigma);
174  tree->SetBranchAddress("HitsX", &myHitsX);
175  tree->SetBranchAddress("HitsY", &myHitsY);
176  tree->SetBranchAddress("Label", &myLabel);
177 }
unsigned int hitsX() const
get number of hits for x-measurement
unsigned int label() const
get alignable label as used by pede
const std::vector< float > & globalCor() const
get global correlation array
align::ID id() const
Return the ID of Alignable, i.e. DetId of &#39;first&#39; component GeomDet(Unit).
Definition: Alignable.h:180
std::vector< AlignmentUserVariables * > readMillePedeVariables(const std::vector< Alignable * > &alivec, const char *filename, int iter, int &ierr)
unsigned int size() const
number of parameters
const std::vector< float > & parameter() const
get array of parameters
virtual AlignmentUserVariables * readOne(Alignable *ali, int &ierr)
AlignmentParameters * alignmentParameters() const
Get the AlignmentParameters.
Definition: Alignable.h:57
AlignmentUserVariables * userVariables(void) const
Get pointer to user variables.
void setHitsY(unsigned int hitsY)
const std::vector< float > & preSigma() const
get array of presigmas (&lt;= 0: means fixed)
tuple result
Definition: query.py:137
unsigned int hitsY() const
get number of hits for y-measurement
const std::vector< float > & sigma() const
get array of sigmas
virtual StructureType alignableObjectId() const =0
Return the alignable type identifier.
(Abstract) Base class for alignment algorithm user variables
void writeMillePedeVariables(const std::vector< Alignable * > &alivec, const char *filename, int iter, bool validCheck, int &ierr)
virtual void setBranchAddresses()
set root branche addresses
const std::vector< float > & diffBefore() const
get array of differences to start value
const std::vector< bool > & isValid() const
get valid flag array
tuple filename
Definition: lut2db_cfg.py:20
virtual void createBranches()
create root branches
virtual int writeOne(Alignable *ali)
void setHitsX(unsigned int hitsX)