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  AlignableChi2(0.), AlignableNdof(0)
19 {
20  treename = "T9";
21  treetxt = "HIP User Variables";
22 
23  for (int i=0;i<nparmax*(nparmax+1)/2;++i)
24  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 
34 {
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("Nparj", &Nparj, "Nparj/I");
40  tree->Branch("Jtvj", &Jtvj, "Jtvj[Nparj]/D");
41  tree->Branch("Npare", &Npare, "Npare/I");
42  tree->Branch("Jtve", &Jtve, "Jtve[Npare]/D");
43  tree->Branch("AlignableChi2", &AlignableChi2, "AlignableChi2/D");
44  tree->Branch("AlignableNdof", &AlignableNdof, "AlignableNdof/i");
45  tree->Branch("Par", &Par, "Par[Npare]/D");
46  tree->Branch("ParError", &ParError, "ParError[Npare]/D");
47 }
48 
49 // ----------------------------------------------------------------------------
50 
52 {
53  tree->SetBranchAddress("Id", &Id);
54  tree->SetBranchAddress("ObjId", &ObjId);
55 
56  tree->SetBranchAddress("Nhit", &Nhit);
57  tree->SetBranchAddress("Nparj", &Nparj);
58  tree->SetBranchAddress("Jtvj", &Jtvj);
59  tree->SetBranchAddress("Npare", &Npare);
60  tree->SetBranchAddress("Jtve", &Jtve);
61  tree->SetBranchAddress("AlignableChi2", &AlignableChi2);
62  tree->SetBranchAddress("AlignableNdof", &AlignableNdof);
63  tree->SetBranchAddress("Par", &Par);
64  tree->SetBranchAddress("ParError", &ParError);
65 }
66 
67 // ----------------------------------------------------------------------------
68 // find tree entry based on detID and typeID
69 
70 int HIPUserVariablesIORoot::findEntry(unsigned int detId,int comp)
71 {
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 
100 {
102 
103  if ((ap->userVariables())==0) {
104  edm::LogError("Alignment") <<"UserVariables not found!";
105  return -1;
106  }
107 
108  HIPUserVariables* uvar =
109  dynamic_cast<HIPUserVariables*>(ap->userVariables());
110 
111  AlgebraicSymMatrix jtvj = uvar->jtvj;
112  AlgebraicVector jtve = uvar->jtve;
113  AlgebraicVector alipar = uvar->alipar;
114  AlgebraicVector alierr = uvar->alierr;
115  int nhit=uvar->nhit;
116  int np=jtve.num_row();
117 
118  Nhit=nhit;
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=0;col<np;col++){
127  if(row-1<col){Jtvj[count]=jtvj[row][col];count++;}
128  }
129  }
130  Id = ali->id();
131  ObjId = ali->alignableObjectId();
132 
133  //Chi^2 of alignable
134  AlignableChi2= uvar->alichi2 ;
135  AlignableNdof= uvar->alindof ;
136  tree->Fill();
137  return 0;
138 }
139 
140 // ----------------------------------------------------------------------------
141 
143  int& ierr)
144 {
145  ierr=0;
146  HIPUserVariables* uvar;
147 
148  int entry = findEntry(ali->id(), ali->alignableObjectId());
149  if(entry!=-1) {
150  tree->GetEntry(entry);
151 
152  int np=Npare;
153  AlgebraicVector jtve(np,0);
154  AlgebraicSymMatrix jtvj(np,0);
155  AlgebraicVector alipar(np,0);
156  AlgebraicVector alierr(np,0);
157  int count=0;
158  for(int row=0;row<np;row++) {
159  jtve[row]=Jtve[row];
160  alipar[row]=Par[row];
161  alierr[row]=ParError[row];
162  for(int col=0; col < np;col++) {
163  if(row-1<col) {jtvj[row][col]=Jtvj[count];count++;}
164  }
165  }
166 
167  uvar = new HIPUserVariables(np);
168  uvar->jtvj=jtvj;
169  uvar->jtve=jtve;
170  uvar->nhit=Nhit;
171  uvar->alipar=alipar;
172  uvar->alierr=alierr;
173  //Chi2n
174  uvar->alichi2=AlignableChi2;
175  uvar->alindof=AlignableNdof;
176 
177  return uvar;
178  }
179 
180  // ierr=-1;
181  return 0 ;
182 }
183 
184 //-----------------------------------------------------------------------------
185 
186 void
188  const char* filename, int iter, bool validCheck, int& ierr)
189 {
190  ierr=0;
191  int iret;
192  iret = open(filename,iter,true);
193  if (iret!=0) { ierr=-1; return;}
194  iret = write(alivec,validCheck);
195  if (iret!=0) { ierr=-2; return;}
196  iret = close();
197  if (iret!=0) { ierr=-3; return;}
198 }
199 
200 //-----------------------------------------------------------------------------
201 
202 std::vector<AlignmentUserVariables*>
204  const char* filename, int iter, int& ierr)
205 {
206  std::vector<AlignmentUserVariables*> result;
207  ierr=0;
208  int iret;
209  iret = open(filename,iter,false);
210  if (iret!=0) { ierr=-1; return result;}
211  result = read(alivec,iret);
212  if (iret!=0) { ierr=-2; return result;}
213  iret = close();
214  if (iret!=0) { ierr=-3; return result;}
215 
216  return result;
217 }
int writeOne(Alignable *ali)
align::ID id() const
Return the ID of Alignable, i.e. DetId of &#39;first&#39; component GeomDet(Unit).
Definition: Alignable.h:189
int findEntry(unsigned int detId, int comp)
int open(const char *filename, int iteration, bool writemode)
std::vector< Alignable * > Alignables
AlignmentUserVariables * readOne(Alignable *ali, int &ierr)
void setBranchAddresses(void)
set root branches
void createBranches(void)
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.
int np
Definition: AMPTWrapper.h:33
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