1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
|
// COCOA class implementation file
//Id: FittedEntriesManager.cc
//CAT: Model
//
// History: v1.0
// Pedro Arce
#include <map>
#include <fstream>
#include <iostream>
#include <iomanip>
#include "Alignment/CocoaFit/interface/FittedEntriesManager.h"
#include "Alignment/CocoaModel/interface/Model.h"
#include "Alignment/CocoaUtilities/interface/ALIUtils.h"
#include "Alignment/CocoaUtilities/interface/GlobalOptionMgr.h"
FittedEntriesManager* FittedEntriesManager::instance = nullptr;
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//@@ Gets the only instance of Model
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
FittedEntriesManager* FittedEntriesManager::getInstance() {
if (!instance) {
instance = new FittedEntriesManager;
}
return instance;
}
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//@@ add a new set of fitted entries
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
void FittedEntriesManager::AddFittedEntriesSet(FittedEntriesSet* fents) { theFittedEntriesSets.push_back(fents); }
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//@@ dump data to histograms
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//tvoid FittedEntriesManager::WriteHeader()
void FittedEntriesManager::MakeHistos() {
//----------- Get
//----------- Loop entries
//- vfescite = theFittedEntriesSets.begin();
// std::vector< FittedEntry* > vfe = theFittedEntriesSets.begin()->FittedEntries();
// std::vector< FittedEntry* >::const_iterator vfecite2;
//-- Number of fitted entries (equal for all Fitted Entries Sets )
if (ALIUtils::debug >= 5)
std::cout << "No sets2 " << theFittedEntriesSets.size() << " No ent "
<< ((*(theFittedEntriesSets.begin()))->FittedEntries()).size() << std::endl;
std::ofstream fout;
std::ofstream fout2;
fout.open("fittedEntries.out");
fout2.open("longFittedEntries.out");
//---------- Dump dimensions
ALIUtils::dumpDimensions(fout);
ALIUtils::dumpDimensions(fout2);
AddFittedEntriesSet(new FittedEntriesSet(theFittedEntriesSets)); //add a new set that averages all the others
//---------- Loop sets of entries
std::vector<FittedEntriesSet*>::const_iterator vfescite;
std::vector<FittedEntry*>::const_iterator vfecite;
ALIint jj = 1;
for (vfescite = theFittedEntriesSets.begin(); vfescite != theFittedEntriesSets.end(); ++vfescite) {
//---------- Loop entries
if (vfescite == theFittedEntriesSets.begin()) {
//----- dump entries names if first set
fout << " ";
ALIint ii = 0;
for (vfecite = ((*vfescite)->FittedEntries()).begin(); vfecite != ((*vfescite)->FittedEntries()).end();
++vfecite) {
ALIstring filename = createFileName((*vfecite)->getOptOName(), (*vfecite)->getEntryName());
fout << ii << ": " << std::setw(13) << filename << " ";
;
if (ALIUtils::debug >= 3)
std::cout << ii << ": " << std::setw(13) << filename << " = " << (*vfecite)->getName() << std::endl;
if (ALIUtils::debug >= 3)
std::cout << filename << " ";
if (ALIUtils::debug >= 3)
std::cout << "OPENING FITTED ENTRIES file " << filename << std::endl;
ii++;
}
// fout << std::setw(17) << "2:-4:";
fout << std::endl;
if (ALIUtils::debug >= 3)
std::cout << std::endl;
}
//----- Dump entry set number
fout << jj << " ";
fout2 << jj << " ";
//----- Dump measurements date
GlobalOptionMgr* gomgr = GlobalOptionMgr::getInstance();
if (gomgr->GlobalOptions()["DumpDateInFittedEntries"] >= 1) {
fout << (*vfescite)->getDate() << " " << (*vfescite)->getTime() << " ";
fout2 << (*vfescite)->getDate() << " " << (*vfescite)->getTime() << " ";
}
//ALIint ii = 0;
for (vfecite = ((*vfescite)->FittedEntries()).begin(); vfecite != ((*vfescite)->FittedEntries()).end(); ++vfecite) {
// std::cout << ii << *vfescite << " FITTEDENTRY: " << vfecite << " " <<*vfecite << " " << (*vfecite)->Value() << std::endl;
// if( ii == 2 || ii == 4 ) {
fout << std::setprecision(8) << std::setw(10) << (*vfecite)->getValue() << " " << (*vfecite)->getSigma() << " ";
//- fout << std::setw(9) << std::setprecision(6) << (*vfecite)->getValue() << " +- " << (*vfecite)->getSigma() << " ";
// }
if (ALIUtils::debug >= 3)
std::cout << " FITTEDENTRY:" << std::setprecision(5) << std::setw(8) << (*vfecite)->getValue() << " +- "
<< (*vfecite)->getSigma() << std::endl;
ALIstring filename = createFileName((*vfecite)->getOptOName(), (*vfecite)->getEntryName());
fout2 << std::setprecision(8) << std::setw(10) << filename << " " << (*vfecite)->getValue() << " "
<< (*vfecite)->getSigma() << " ";
//ii++;
}
// dumpEntriesSubstraction( fout, *(*vfescite), 2, 4);
fout << std::endl;
fout2 << std::endl;
if (ALIUtils::debug >= 3)
std::cout << std::endl;
jj++;
}
fout.close();
fout2.close();
GetDifferentBetweenLasers();
}
#include "Alignment/CocoaModel/interface/LightRay.h"
#include "Alignment/CocoaModel/interface/OpticalObject.h"
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
void FittedEntriesManager::GetDifferentBetweenLasers() {
std::vector<OpticalObject*> optoList = Model::OptOList();
std::vector<OpticalObject*>::const_iterator ite;
std::map<ALIstring, LightRay*> lrays;
for (ite = optoList.begin(); ite != optoList.end(); ++ite) {
if ((*ite)->type() == "laser") {
LightRay* lightray = new LightRay;
lightray->startLightRay(*ite);
lrays[(*ite)->parent()->name()] = lightray;
}
}
std::map<ALIstring, LightRay*>::const_iterator lite1, lite2;
for (lite1 = lrays.begin(); lite1 != lrays.end(); ++lite1) {
lite2 = lite1;
++lite2;
for (; lite2 != lrays.end(); ++lite2) {
if (lite1 == lite2)
continue;
CLHEP::Hep3Vector dirdiff = ((*lite1).second->direction() - (*lite2).second->direction());
if (ALIUtils::debug >= 0) {
std::cout << "LASER DIFF " << (*lite1).first << " & " << (*lite2).first << " " << dirdiff.mag() * 180. / M_PI
<< "o " << dirdiff.mag() << " rad " << dirdiff << std::endl;
(*lite1).second->dumpData(ALIstring(" laser ") + (*lite1).first);
(*lite2).second->dumpData(ALIstring(" laser ") + (*lite2).first);
}
}
}
}
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//@@ create file name to dump fitted entries values taking the last name of optoName and the full entryName with space converted to '.'
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
ALIstring FittedEntriesManager::createFileName(const ALIstring& optoName, const ALIstring& entryName) {
// std::cout << "in createFileName " << optoName << " " << entryName << std::endl;
ALIstring filename;
//- std::cout << "o" << optoName << " e " << entryName << std::endl;
/* ALIint last_slash = optoName.rfind('/');
ALIint size = optoName.length();
//- std::cout << last_slash << " " << size << "optoname " << optoName << std::endl;
filename = optoName.substr( last_slash+1, size );
*/
//----- substitute '/' by '.' in opto name
filename = optoName.substr(2, optoName.size()); // skip the first 's/'
ALIint slash = -1;
for (;;) {
slash = filename.find('/', slash + 1);
if (slash == -1)
break;
filename[slash] = '.';
}
//----- Check if there is a ' ' in entry (should not happen now)
ALIint space = entryName.rfind(' ');
filename.append(".");
ALIstring en = entryName;
if (space != -1)
en[space] = '_';
//----- Merge opto and entry names
// now it is not used as filename filename.append( en + ".out");
filename.append(en);
if (ALIUtils::debug >= 3)
std::cout << "filename " << filename << std::endl;
return filename;
}
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//@@ create file name to dump fitted entries values taking the last name of optoName and the full entryName with space converted to '-'
// entry1/2 are the entries name including OptO name
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
void FittedEntriesManager::dumpEntriesSubstraction(std::ofstream& fout,
FittedEntriesSet& fes,
ALIint order1,
ALIint order2) {
//---------- Found order of entry1 and entry2 in FittedEntriesSet fes
// (the order will be the same for every FittedEntriesSet
//std::vector< FittedEntriesSet* >::const_iterator vfescite = theFittedEntriesSets.begin();
/* std::vector< FittedEntry* >::const_iterator vfecite;
ALIint order1, order2;
ALIint jj=0;
for( vfecite = (fes.FittedEntries()).begin(); vfecite != (fes.FittedEntries()).end(); vfecite++) {
ALIstring entryTemp = (*vfecite)->OptOName() + "/" + (*vfecite)->EntryName();
if(entryTemp == entry1) order1 = jj;
if(entryTemp == entry2) order2 = jj;
jj++;
}
*/
FittedEntry* fe1 = *((fes.FittedEntries()).begin() + order1);
FittedEntry* fe2 = *((fes.FittedEntries()).begin() + order2);
//-------- Substract values of entry1 and entry2 (with errors)
ALIdouble val1 = fe1->getValue();
ALIdouble val2 = fe2->getValue();
ALIdouble sig1 = fe1->getSigma();
ALIdouble sig2 = fe2->getSigma();
ALIdouble val = val1 - val2;
ALIdouble sig = sqrt(sig1 * sig1 + sig2 * sig2);
//- std::cout << "CHECK " << val1 << " "<< val2 << " "<< sig1 << " "<< sig2 << std::endl;
fout << std::setprecision(6) << std::setw(8) << val << " +- " << sig << " ";
if (ALIUtils::debug >= 3)
std::cout << " FITTEDENTRY:" << std::setprecision(5) << std::setw(8) << val << " +- " << sig << std::endl;
}
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
/*void FittedEntriesManager::MakeHistos1()
{
std::vector< FittedEntriesSet* >::const_iterator vfescite;
std::vector< FittedEntry* >::const_iterator vfecite;
//----------- Get
//----------- Loop entries
vfescite = theFittedEntriesSets.begin();
// std::vector< FittedEntry* > vfe = theFittedEntriesSets.begin()->FittedEntries();
// std::vector< FittedEntry* >::const_iterator vfecite2;
ALIint ii;
//-- Number of fitted entries (equal for all Fitted Entries Sets
ALIint NoFitEnt = ( ( *(theFittedEntriesSets.begin()) )->FittedEntries() ).size();
if( ALIUtils::debug >= 3) std::cout << "No sets1 " << theFittedEntriesSets.size() << " No ent " << NoFitEnt << std::endl;
std::ofstream fout;
ALIint jj;
for( ii = 0; ii < NoFitEnt; ii++) {
jj = 1;
for( vfescite = theFittedEntriesSets.begin(); vfescite != theFittedEntriesSets.end(); vfescite++) {
vfecite = ((*vfescite)->FittedEntries()).begin() + ii;
//----- create file name
if( vfescite == theFittedEntriesSets.begin() ) {
if( ALIUtils::debug >= 3) std::cout << " create filename " << (*vfecite)->OptOName() << (*vfecite)->EntryName() << std::endl;
ALIstring filename = createFileName( (*vfecite)->OptOName(), (*vfecite)->EntryName() );
fout.open( filename.c_str() );
if( ALIUtils::debug >= 3) std::cout << "OPENING FITTED ENTRIES file " << filename << std::endl;
}
// std::cout << ii << *vfescite << " FITTEDENTRY: " << vfecite << " " <<*vfecite << " " << (*vfecite)->Value() << std::endl;
fout << jj << " " << (*vfecite)->Value() << (*vfecite)->Sigma() << std::endl;
if( ALIUtils::debug >= 3) std::cout << ii << " FITTEDENTRY: " << (*vfecite)->OptOName() << " / " << (*vfecite)->EntryName() << " " << (*vfecite)->Value() << " " << (*vfecite)->Sigma() << std::endl;
jj++;
}
fout.close();
}
}
*/
|