CMS 3D CMS Logo

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