CMS 3D CMS Logo

HIPUserVariablesIORoot.cc
Go to the documentation of this file.
1 #include "TTree.h"
2 
4 
8 
9 
10 // this class's header
12 
13 // ----------------------------------------------------------------------------
14 // constructor
15 
17 ObjId(0), Id(0), Nhit(0), Nparj(0), Npare(0),
18 DataType(-1),
19 AlignableChi2(0.), AlignableNdof(0)
20 {
21  treename = "T9";
22  treetxt = "HIP User Variables";
23 
24  for (int i=0; i<nparmax*(nparmax+1)/2; ++i) Jtvj[i] = 0.;
25  for (int i=0; i<nparmax; ++i){
26  Jtve[i] = 0.;
27  Par[i] = 0.;
28  ParError[i] = 0.;
29  }
30 }
31 
32 // ----------------------------------------------------------------------------
33 
35  tree->Branch("Id", &Id, "Id/i");
36  tree->Branch("ObjId", &ObjId, "ObjId/I");
37 
38  tree->Branch("Nhit", &Nhit, "Nhit/I");
39  tree->Branch("DataType", &DataType, "DataType/I");
40  tree->Branch("Nparj", &Nparj, "Nparj/I");
41  tree->Branch("Jtvj", &Jtvj, "Jtvj[Nparj]/D");
42  tree->Branch("Npare", &Npare, "Npare/I");
43  tree->Branch("Jtve", &Jtve, "Jtve[Npare]/D");
44  tree->Branch("AlignableChi2", &AlignableChi2, "AlignableChi2/D");
45  tree->Branch("AlignableNdof", &AlignableNdof, "AlignableNdof/i");
46  tree->Branch("Par", &Par, "Par[Npare]/D");
47  tree->Branch("ParError", &ParError, "ParError[Npare]/D");
48 }
49 
50 // ----------------------------------------------------------------------------
51 
53  tree->SetBranchAddress("Id", &Id);
54  tree->SetBranchAddress("ObjId", &ObjId);
55 
56  tree->SetBranchAddress("Nhit", &Nhit);
57  tree->SetBranchAddress("DataType", &DataType);
58  tree->SetBranchAddress("Nparj", &Nparj);
59  tree->SetBranchAddress("Jtvj", &Jtvj);
60  tree->SetBranchAddress("Npare", &Npare);
61  tree->SetBranchAddress("Jtve", &Jtve);
62  tree->SetBranchAddress("AlignableChi2", &AlignableChi2);
63  tree->SetBranchAddress("AlignableNdof", &AlignableNdof);
64  tree->SetBranchAddress("Par", &Par);
65  tree->SetBranchAddress("ParError", &ParError);
66 }
67 
68 // ----------------------------------------------------------------------------
69 // find tree entry based on detID and typeID
70 
71 int HIPUserVariablesIORoot::findEntry(unsigned int detId, int comp){
72  if (newopen) { // we're here for the first time
73  edm::LogInfo("Alignment") << "[HIPUserVariablesIORoot::findEntry] fill map ...";
74  treemap.erase(treemap.begin(), treemap.end());
75  for (int ev = 0; ev<tree->GetEntries(); ev++){
76  tree->GetEntry(ev);
77  treemap[std::make_pair(Id, ObjId)]=ev;
78  }
79  newopen=false;
80  }
81 
82  // now we have filled the map
83  treemaptype::iterator imap = treemap.find(std::make_pair(detId, comp));
84  int result=-1;
85  if (imap != treemap.end()) result=(*imap).second;
86  return result;
87 
88 
89  //double noAliPar = tree->GetEntries();
90  //for (int ev = 0;ev<noAliPar;ev++) {
91  // tree->GetEntry(ev);
92  // if(Id==detId&&comp==ObjId) return (ev);
93  //}
94  //return(-1);
95 }
96 
97 // ----------------------------------------------------------------------------
98 
101 
102  if ((ap->userVariables())==nullptr){
103  edm::LogError("Alignment") << "UserVariables not found!";
104  return -1;
105  }
106 
107  HIPUserVariables* uvar = dynamic_cast<HIPUserVariables*>(ap->userVariables());
108 
109  AlgebraicSymMatrix jtvj = uvar->jtvj;
110  AlgebraicVector jtve = uvar->jtve;
111  AlgebraicVector alipar = uvar->alipar;
112  AlgebraicVector alierr = uvar->alierr;
113  int nhit=uvar->nhit;
114  int datatype=uvar->datatype;
115  int np=jtve.num_row();
116 
117  Nhit=nhit;
118  DataType=datatype;
119  Npare=np;
120  Nparj=np*(np+1)/2;
121  int count=0;
122  for (int row=0; row<np; row++){
123  Jtve[row]=jtve[row];
124  Par[row]=alipar[row];
125  ParError[row]=alierr[row];
126  for (int col=row; col<np; col++){
127  Jtvj[count]=jtvj[row][col];
128  count++;
129  }
130  }
131  Id = ali->id();
132  ObjId = ali->alignableObjectId();
133 
134  //Chi^2 of alignable
135  AlignableChi2= uvar->alichi2;
136  AlignableNdof= uvar->alindof;
137  tree->Fill();
138  return 0;
139 }
140 
141 // ----------------------------------------------------------------------------
142 
144  ierr=0;
145  HIPUserVariables* uvar;
146 
147  int entry = findEntry(ali->id(), ali->alignableObjectId());
148  if (entry!=-1){
149  tree->GetEntry(entry);
150 
151  int np=Npare;
152  AlgebraicVector jtve(np, 0);
153  AlgebraicSymMatrix jtvj(np, 0);
154  AlgebraicVector alipar(np, 0);
155  AlgebraicVector alierr(np, 0);
156  int count=0;
157  for (int row=0; row<np; row++){
158  jtve[row]=Jtve[row];
159  alipar[row]=Par[row];
160  alierr[row]=ParError[row];
161  for (int col=row; col < np; col++){
162  jtvj[row][col]=Jtvj[count];
163  count++;
164  }
165  }
166 
167  uvar = new HIPUserVariables(np);
168  uvar->jtvj=jtvj;
169  uvar->jtve=jtve;
170  uvar->nhit=Nhit;
171  uvar->datatype=DataType;
172  uvar->alipar=alipar;
173  uvar->alierr=alierr;
174  //Chi2n
175  uvar->alichi2=AlignableChi2;
176  uvar->alindof=AlignableNdof;
177 
178  return uvar;
179  }
180 
181  // ierr=-1;
182  return nullptr;
183 }
184 
185 //-----------------------------------------------------------------------------
186 
188  const Alignables& alivec,
189  const char* filename, int iter, bool validCheck, int& ierr
190  ){
191  ierr=0;
192  int iret;
193  iret = open(filename, iter, true);
194  if (iret!=0) { ierr=-1; return; }
195  iret = write(alivec, validCheck);
196  if (iret!=0) { ierr=-2; return; }
197  iret = close();
198  if (iret!=0) { ierr=-3; return; }
199 }
200 
201 //-----------------------------------------------------------------------------
202 
203 std::vector<AlignmentUserVariables*> HIPUserVariablesIORoot::readHIPUserVariables(
204  const Alignables& alivec,
205  const char* filename, int iter, int& ierr
206  ){
207  std::vector<AlignmentUserVariables*> result;
208  ierr=0;
209  int iret;
210  iret = open(filename, iter, false);
211  if (iret!=0) { ierr=-1; return result; }
212  result = read(alivec, iret);
213  if (iret!=0) { ierr=-2; return result; }
214  iret = close();
215  if (iret!=0) { ierr=-3; return result; }
216 
217  return result;
218 }
align::ID id() const
Return the ID of Alignable, i.e. DetId of &#39;first&#39; component GeomDet(Unit).
Definition: Alignable.h:189
AlignmentUserVariables * readOne(Alignable *ali, int &ierr) override
int findEntry(unsigned int detId, int comp)
std::vector< Alignable * > Alignables
void createBranches(void) override
create root branches
AlgebraicVector alipar
bool ev
AlgebraicVector jtve
AlignmentParameters * alignmentParameters() const
Get the AlignmentParameters.
Definition: Alignable.h:61
void writeHIPUserVariables(const Alignables &alivec, const char *filename, int iter, bool validCheck, int &ierr)
AlgebraicSymMatrix jtvj
AlignmentUserVariables * userVariables(void) const
Get pointer to user variables.
void setBranchAddresses(void) override
set root branches
int np
Definition: AMPTWrapper.h:33
int writeOne(Alignable *ali) override
virtual StructureType alignableObjectId() const =0
Return the alignable type identifier.
std::vector< AlignmentUserVariables * > readHIPUserVariables(const Alignables &alivec, const char *filename, int iter, int &ierr)
AlgebraicVector alierr
double Jtvj[nparmax *(nparmax+1)/2]
(Abstract) Base class for alignment algorithm user variables
CLHEP::HepVector AlgebraicVector
int write(const align::Alignables &alivec, bool validCheck)
std::vector< AlignmentUserVariables * > read(const align::Alignables &alivec, int &ierr)
col
Definition: cuy.py:1008
CLHEP::HepSymMatrix AlgebraicSymMatrix
Definition: tree.py:1
int open(const char *filename, int iteration, bool writemode) override