130 {
131 if (infilename.find(
"\\/") == std::string::npos)
filepath = infilename.substr(0, infilename.find_last_of(
"\\/") + 1);
132 boost::char_separator<char> sep(" \t");
134 ++beg;
135 int size = atoi((*beg).c_str());
136
137 int nlines = 0;
138 std::vector<bool> lines;
139 std::string line;
140 for (int i = 0; i < size; i++) {
141 IsEOF = getline(ifile, line).eof();
142 if (line.empty() || line.at(0) == '#') {
143 if (rank == 0) throw std::runtime_error("ERROR: no comments or empty lines in CorrelatedGaussianObservables please! In file " + infilename + " at line number:" + boost::lexical_cast<std::string>(lineNo) + ".\n");
144 else sleep(2);
145 }
146 lineNo++;
147 boost::tokenizer<boost::char_separator<char> > tok(line, sep);
148 beg = tok.begin();
149 std::string type = *beg;
150 ++beg;
151 if (type.compare("Observable") != 0 && type.compare("BinnedObservable") != 0 && type.compare("FunctionObservable") != 0) {
152 if (rank == 0) throw std::runtime_error("ERROR: in line no." + boost::lexical_cast<std::string>(lineNo) + " of file " + infilename + ", expecting an Observable or BinnedObservable or FunctionObservable type here...\n");
153 else sleep(2);
154 }
162 lines.push_back(true);
163 nlines++;
164 } else {
165 Observables.push_back(tmpObs);
166 lines.push_back(false);
167 }
168 } else {
170 if (rank == 0) throw std::runtime_error("ERROR: in line no." + boost::lexical_cast<std::string>(lineNo) + " of file " + infilename + ", Observable/BinnedObservable cannot be set to MCMC in CorrelatedObservable. Use CorrelatedGaussianObservable instead.\n");
171 else sleep(2);
172 } else {
174 nlines++;
175 }
176 if (tmpObs->
getDistr().compare(
"weight") == 0 || tmpObs->
getDistr().compare(
"file") == 0) {
177 if (rank == 0) throw std::runtime_error("ERROR: in line no." + boost::lexical_cast<std::string>(lineNo) + " of file " + infilename + ", Observable/BinnedObservable cannot be set to weight or file in CorrelatedObservable. Use CorrelatedGaussianObservable instead.\n");
178 else sleep(2);
179 }
180 }
181 }
182
183 if (nlines > 1) {
185 TMatrixD myCorr(nlines, nlines);
186 int ni = 0;
187 for (int i = 0; i < size; i++) {
188 IsEOF = getline(ifile, line).eof();
189 if (line.empty() || line.at(0) == '#') {
190 if (rank == 0) throw std::runtime_error("ERROR: no comments or empty lines in CorrelatedGaussianObservables please! In file " + infilename + " at line number:" + boost::lexical_cast<std::string>(lineNo) + ".\n");
191 else sleep(2);
192 }
193 lineNo++;
194 if (lines.at(i)) {
195 boost::tokenizer<boost::char_separator<char> > mytok(line, sep);
196 beg = mytok.begin();
197 int nj = 0;
198 for (int j = 0; j < size; j++) {
199 if ((*beg).compare(0, 1, "0") == 0
200 || (*beg).compare(0, 1, "1") == 0
202 if (std::distance(mytok.begin(), mytok.end()) < size) {
203 if (rank == 0)
throw std::runtime_error((
"ERROR: Correlation matrix is of wrong size in Correlated Gaussian Observables: " +
name + +
" at line number:" + boost::lexical_cast<std::string>(lineNo) +
".\n").c_str());
204 else sleep(2);
205 }
206 if (lines.at(j)) {
207 myCorr(ni, nj) = atof((*beg).c_str());
208 nj++;
209 }
210 beg++;
211 } else {
212 if (rank == 0)
throw std::runtime_error(
"ERROR: invalid correlation matrix for " +
name +
". Check element (" + boost::lexical_cast<std::string>(ni + 1) +
"," + boost::lexical_cast<std::string>(nj + 1) +
") in line number " + boost::lexical_cast<std::string>(lineNo) +
" in file " + infilename +
".\n");
213 else sleep(2);
214 }
215 }
216 ni++;
217 }
218 }
219 if (!myCorr.IsSymmetric()) {
220 if (rank == 0)
throw std::runtime_error(
"ERROR: invalid correlation matrix for " +
name +
". Correlation matrix is not symmetric.\n");
221 else sleep(2);
222 } else {
223 TMatrixDSym mySCorr(nlines);
224 for (int i = 0; i < nlines; i++) {
225 for (int j = 0; j <= i; j++) {
226 mySCorr(i, j) = myCorr(i, j);
227 mySCorr(j, i) = mySCorr(i, j);
228 }
229 }
231 }
232 } else {
233 InvCov.ResizeTo(size, size);
234 }
235 } else {
236 if (rank == 0) std::cout <<
"\nWARNING: Correlated (Gaussian) Observable " <<
name.c_str() <<
" defined with less than two observables" <<
" in file " << infilename <<
". The set is being marked as normal Observables." << std::endl;
238 for (int i = 0; i < size; i++) {
239 IsEOF = getline(ifile, line).eof();
240 lineNo++;
241 }
242 }
243 return lineNo;
244}
bool isTMCMC() const
A method to check if the observable is listed for MCMC.
void setHasInverseCovariance(bool hasInverseCovariance)
A set method to state that the Observable is a part of ObservablesWithInverseCovariance.
void setTho(ThObservable *tho_i)
A set method to fix the pointer to object of type ThObservable.
std::string getThname() const
A get method to access the thname of the observable as defined in ThFactory class.
boost::tokenizer< boost::char_separator< char > >::iterator & ParseObservable(std::string &type, boost::tokenizer< boost::char_separator< char > > *tok, boost::tokenizer< boost::char_separator< char > >::iterator &beg, std::string &filepath, std::string &infilename, int rank)
The parser for Observables.
std::string getDistr() const
A get method to access the name of the distribution of the observable.
ThObservable * CreateThMethod(const std::string &name, StandardModel &model) const
This method checks for the existence of an observable of a specific name in the map thobs and returns...