test
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  myId(0), myObjId(0), myNumPar(0),
25  myHitsX(0), myHitsY(0), myLabel(0)
26 {
27  treename = "MillePedeUser";
28  treetxt = "MillePede User Variables";
29  for (unsigned int i=0;i<kMaxNumPar;i++) {
30  myIsValid[i] = 0;
31  myDiffBefore[i] = 0.;
32  myGlobalCor[i] = 0.;
33  myPreSigma[i] = 0.;
34  myParameter[i] = 0.;
35  mySigma[i] = 0.;
36  }
37 }
38 
39 // -------------------------------------------------------------------------------------------------
41 (const std::vector<Alignable*> &alivec, const char *filename, int iter, bool validCheck, int &ierr)
42 {
43  ierr = 0;
44 
45  int iret = this->open(filename, iter, true);
46  if (iret != 0) {
47  ierr = -1;
48  } else {
49  iret = this->write(alivec, validCheck);
50  tree->BuildIndex("Id", "ObjId");
51  if (iret != 0) {
52  ierr = -2;
53  } else {
54  iret = this->close();
55  if (iret != 0) {
56  ierr = -3;
57  }
58  }
59  }
60 
61  return;
62 }
63 
64 // -------------------------------------------------------------------------------------------------
65 std::vector<AlignmentUserVariables*> MillePedeVariablesIORoot::readMillePedeVariables
66 (const std::vector<Alignable*> &alivec, const char *filename, int iter, int &ierr)
67 {
68  std::vector<AlignmentUserVariables*> result;
69  ierr = 0;
70  int iret = this->open(filename, iter, false);
71  if (iret != 0) {
72  ierr = -1;
73  } else {
74  result = this->read(alivec, iret);
75  if (iret != 0) {
76  ierr = -2;
77  } else {
78  iret = this->close();
79  if (iret != 0) {
80  ierr = -3;
81  }
82  }
83  }
84 
85  return result;
86 }
87 
88 // -------------------------------------------------------------------------------------------------
90 {
91  if (!ali || !ali->alignmentParameters()
92  || !dynamic_cast<MillePedeVariables*>(ali->alignmentParameters()->userVariables())) {
93  edm::LogError("Alignment") << "@SUB=MillePedeVariablesIORoot::writeOne"
94  << "No MillePedeVariables found!";
95  return -1;
96  }
97 
98  const MillePedeVariables *mpVar =
99  static_cast<MillePedeVariables*>(ali->alignmentParameters()->userVariables());
100  myNumPar = mpVar->size();
101  if (myNumPar >= kMaxNumPar) {
102  edm::LogError("Alignment") << "@SUB=MillePedeVariablesIORoot::writeOne"
103  << "Ignoring parameters " << static_cast<int>(kMaxNumPar) << " to " << myNumPar-1;
105  }
106 
107  for (unsigned int iPar = 0; iPar < myNumPar; ++iPar) {
108  myIsValid[iPar] = mpVar->isValid()[iPar];
109  myDiffBefore[iPar] = mpVar->diffBefore()[iPar];
110  myGlobalCor[iPar] = mpVar->globalCor()[iPar];
111  myPreSigma[iPar] = mpVar->preSigma()[iPar];
112  myParameter[iPar] = mpVar->parameter()[iPar];
113  mySigma[iPar] = mpVar->sigma()[iPar];
114  }
115  myHitsX = mpVar->hitsX();
116  myHitsY = mpVar->hitsY();
117  myLabel = mpVar->label();
118 
119  myId = ali->id();
120  myObjId = ali->alignableObjectId();
121 
122  tree->Fill();
123 
124  return 0;
125 }
126 
127 // -------------------------------------------------------------------------------------------------
129 {
130  ierr = 0;
131 
132  if (tree->GetEntryWithIndex(ali->id(), ali->alignableObjectId()) < 0) {
133  edm::LogError("Alignment") << "@SUB=MillePedeVariablesIORoot::readOne"
134  << "No index for id/type = (" << ali->id() << "/"
135  << ali->alignableObjectId() << ") found!";
136  ierr = 1;
137  return 0;
138  }
139 
141  for (unsigned int iPar = 0; iPar < myNumPar; ++iPar) {
142  mpVar->isValid()[iPar] = myIsValid[iPar];
143  mpVar->diffBefore()[iPar] = myDiffBefore[iPar];
144  mpVar->globalCor()[iPar] = myGlobalCor[iPar];
145  mpVar->preSigma()[iPar] = myPreSigma[iPar];
146  mpVar->parameter()[iPar] = myParameter[iPar];
147  mpVar->sigma()[iPar] = mySigma[iPar];
148  }
149  mpVar->setHitsX(myHitsX);
150  mpVar->setHitsY(myHitsY);
151 
152  return mpVar;
153 }
154 
155 // -------------------------------------------------------------------------------------------------
157 {
158  tree->Branch("Id", &myId, "Id/i");
159  tree->Branch("ObjId", &myObjId, "ObjId/I");
160  tree->Branch("NumPar", &myNumPar, "NumPar/i");
161  tree->Branch("IsValid", myIsValid, "IsValid[NumPar]/b");
162  tree->Branch("DiffBefore", myDiffBefore,"DiffBefore[NumPar]/F");
163  tree->Branch("GlobalCor", myGlobalCor, "GlobalCor[NumPar]/F");
164  tree->Branch("PreSigma", myPreSigma, "PreSigma[NumPar]/F");
165  tree->Branch("Par", myParameter, "Par[NumPar]/F"); // name as in AlignmentParametersIORoot
166  tree->Branch("Sigma", mySigma, "Sigma[NumPar]/F");
167  tree->Branch("HitsX", &myHitsX, "HitsX/i");
168  tree->Branch("HitsY", &myHitsY, "HitsY/i");
169  tree->Branch("Label", &myLabel, "Label/i");
170 }
171 
172 // -------------------------------------------------------------------------------------------------
174 {
175  tree->SetBranchAddress("Id", &myId);
176  tree->SetBranchAddress("ObjId", &myObjId);
177  tree->SetBranchAddress("NumPar", &myNumPar);
178  tree->SetBranchAddress("IsValid", myIsValid);
179  tree->SetBranchAddress("DiffBefore", myDiffBefore);
180  tree->SetBranchAddress("GlobalCor", myGlobalCor);
181  tree->SetBranchAddress("PreSigma", myPreSigma);
182  tree->SetBranchAddress("Par", myParameter);
183  tree->SetBranchAddress("Sigma", mySigma);
184  tree->SetBranchAddress("HitsX", &myHitsX);
185  tree->SetBranchAddress("HitsY", &myHitsY);
186  tree->SetBranchAddress("Label", &myLabel);
187 }
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:185
std::vector< AlignmentUserVariables * > readMillePedeVariables(const std::vector< Alignable * > &alivec, const char *filename, int iter, int &ierr)
int i
Definition: DBlmapReader.cc:9
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
tuple result
Definition: mps_fire.py:83
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)
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)