Changeset 5971 for trunk/MagicSoft/Mars/mhbase
- Timestamp:
- 01/24/05 16:58:21 (20 years ago)
- Location:
- trunk/MagicSoft/Mars/mhbase
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mhbase/MBinning.cc
r5803 r5971 151 151 } 152 152 153 // -------------------------------------------------------------------------- 154 // 155 // Removes the first edge 156 // 153 157 void MBinning::RemoveFirstEdge() 154 158 { … … 159 163 } 160 164 165 // -------------------------------------------------------------------------- 166 // 167 // Removes the last edge 168 // 161 169 void MBinning::RemoveLastEdge() 162 170 { … … 205 213 // -------------------------------------------------------------------------- 206 214 // 215 // Set edged from text. With the following structure: 216 // 217 // n lo hi [type [title]] 218 // 219 // n: number of bins 220 // lo: lowest edge 221 // hi: highest edge 222 // type: "lin" <default>, "log", "cos" (without quotationmarks) 223 // title: Whatever the title might be 224 // 225 // For example: 226 // SetEdgesRaw("12 0 1 lin This is the title"); 227 // 228 Bool_t MBinning::SetEdgesRaw(const char *txt) 229 { 230 Int_t nbins = 0; 231 Float_t loedge = 0; 232 Float_t upedge = 0; 233 Int_t len = 0; 234 if (3!=sscanf(txt, " %d %f %f %n", &nbins, &loedge, &upedge, &len)) 235 { 236 *fLog << warn << GetDescriptor() << "::SetEdges: Not enough arguments... ignored." << endl; 237 return kFALSE; 238 } 239 240 if (loedge>=upedge) 241 { 242 *fLog << warn << GetDescriptor() << "::SetEdges: Lowest edge >= highest edge... ignored." << endl; 243 return kFALSE; 244 } 245 246 TString str(txt); 247 str.Remove(0, len); 248 str = str.Strip(TString::kBoth); 249 250 TString typ; 251 Ssiz_t pos = str.First(' '); 252 if (pos>=0) 253 { 254 typ = str(0, pos); 255 if (typ!=(TString)"lin" && typ!=(TString)"log" && typ!=(TString)"cos") 256 { 257 *fLog << warn << GetDescriptor() << "::SetEdges: Type " << typ << " unknown... ignored." << endl; 258 return kFALSE; 259 } 260 } 261 262 SetEdges(nbins, loedge, upedge, typ.Data()); 263 264 str = str.Strip(TString::kBoth); 265 266 if (!str.IsNull()) 267 fTitle = str; 268 269 return kTRUE; 270 } 271 /* 272 // -------------------------------------------------------------------------- 273 // 274 // Set edged from text. With the following structure: 275 // 276 // n= lo= hi= type= title="my title" 277 // 278 // n: number of bins 279 // lo: lowest edge 280 // hi: highest edge 281 // type: "lin" <default>, "log", "cos" (without quotationmarks) 282 // title: Whatever the title might be 283 // 284 // For example: 285 // SetEdgesRaw("12 0 1 lin This is the title"); 286 // 287 Bool_t MBinning::SetEdgesRaw(const char *txt) 288 { 289 Int_t nbins = 0; 290 Float_t loedge = 0; 291 Float_t upedge = 0; 292 Int_t len = 0; 293 if (3!=sscanf(txt, " %d %f %f %n", &nbins, &loedge, &upedge, &len)) 294 { 295 *fLog << warn << GetDescriptor() << "::SetEdges: Not enough arguments... ignored." << endl; 296 return kFALSE; 297 } 298 299 if (loedge>=upedge) 300 { 301 *fLog << warn << GetDescriptor() << "::SetEdges: Lowest edge >= highest edge... ignored." << endl; 302 return kFALSE; 303 } 304 305 TString str(txt); 306 str.Remove(0, len); 307 str = str.Strip(TString::kBoth); 308 309 TString typ; 310 Ssiz_t pos = str.First(' '); 311 if (pos>=0) 312 { 313 typ = str(0, pos); 314 if (typ!=(TString)"lin" && typ!=(TString)"log" && typ!=(TString)"cos") 315 { 316 *fLog << warn << GetDescriptor() << "::SetEdges: Type " << typ << " unknown... ignored." << endl; 317 return kFALSE; 318 } 319 } 320 321 SetEdges(nbins, loedge, upedge, typ.Data()); 322 323 str = str.Strip(TString::kBoth); 324 325 if (!str.IsNull()) 326 fTitle = str; 327 328 return kTRUE; 329 } 330 */ 331 // -------------------------------------------------------------------------- 332 // 207 333 // Calls SetEdgesLog if opt contains "log" 208 334 // Calls SetEdgesCos if opt contains "cos" … … 276 402 277 403 MH::SetBinning(&h, this); 404 } 405 406 // -------------------------------------------------------------------------- 407 // 408 // Print binning. 409 // 410 void MBinning::Print(Option_t *o) const 411 { 412 *fLog << all; 413 *fLog << GetDescriptor() << ": nbins=" << GetNumBins() << " ["; 414 *fLog << GetEdgeLo() << ", " << GetEdgeHi() << "] "; 415 switch (fType) 416 { 417 case kIsDefault: *fLog << "deafult"; break; 418 case kIsLinear: *fLog << "linear"; break; 419 case kIsLogarithmic: *fLog << "logarithmic"; break; 420 case kIsCosinic: *fLog << "consinic"; break; 421 case kIsUserArray: *fLog << "user-array"; break; 422 } 423 *fLog << ">"; 424 425 if (fTitle!=gsDefTitle) 426 *fLog << " title=" << fTitle; 427 428 *fLog << endl; 278 429 } 279 430 … … 317 468 out << " }" << endl; 318 469 } 470 471 // -------------------------------------------------------------------------- 472 // 473 // Allows reading a binning from resource files. The structure is as follows 474 // 475 Int_t MBinning::ReadEnv(const TEnv &env, TString prefix, Bool_t print) 476 { 477 Bool_t rc = kFALSE; 478 479 UInt_t nbins = GetNumBins(); 480 Float_t edgelo = GetEdgeLo(); 481 Float_t edgehi = GetEdgeHi(); 482 TString type; 483 if (IsEnvDefined(env, prefix, "NumBins", print)) 484 { 485 nbins = GetEnvValue(env, prefix, "NumBins", GetNumBins()); 486 rc = kTRUE; 487 } 488 if (IsEnvDefined(env, prefix, "EdgeLo", print)) 489 { 490 edgelo = GetEnvValue(env, prefix, "EdgeLo", GetEdgeLo()); 491 rc = kTRUE; 492 } 493 if (IsEnvDefined(env, prefix, "EdgeHi", print)) 494 { 495 edgehi = GetEnvValue(env, prefix, "EdgeHi", GetEdgeHi()); 496 rc = kTRUE; 497 } 498 if (rc==kTRUE && (type==kIsUserArray || type==kIsDefault)) 499 type = kIsLinear; 500 501 if (IsEnvDefined(env, prefix, "Type", print)) 502 { 503 type = GetEnvValue(env, prefix, "Type", "lin"); 504 if (type!=(TString)"lin" && type!=(TString)"log" && type!=(TString)"cos") 505 { 506 *fLog << warn << GetDescriptor() << "::ReadEnv - WARNING: Type is not lin, log nor cos... assuming lin." << endl; 507 type = "lin"; 508 } 509 rc = kTRUE; 510 } 511 if (IsEnvDefined(env, prefix, "Edges", print)) 512 { 513 if (rc==kTRUE) 514 *fLog << warn << GetDescriptor() << "::ReadEnv - WARNING: 'Edges' found... ignoring any 'NumBins', 'EdgeLo' and 'EdgeHi'" << endl; 515 516 const TString type = GetEnvValue(env, prefix, "Edges", ""); 517 //type = kIsUserArray; 518 /* MISSING */ 519 rc = kTRUE; 520 *fLog << err << " SORRY USER ARRAY NOT YET IMPLEMENTED" << endl; 521 return kERROR; 522 } 523 524 const Bool_t raw = IsEnvDefined(env, prefix, "Raw", print); 525 //const Bool_t fullbins = IsEnvDefined(env, prefix, "Binning", print); 526 if (!raw && /*!fullbins &&*/ rc==kTRUE) 527 SetEdges(nbins, edgelo, edgehi, type.Data()); 528 529 if (rc==kTRUE) 530 *fLog << warn << GetDescriptor() << "::ReadEnv - WARNING: 'Binning' found... ignoring any 'NumBins', 'EdgeLo', 'EdgeHi' and 'Edges'" << endl; 531 532 if (IsEnvDefined(env, prefix, "Title", print)) 533 { 534 fTitle = GetEnvValue(env, prefix, "Title", gsDefTitle.Data()); 535 rc = kTRUE; 536 } 537 538 if (raw) 539 { 540 const TString txt = GetEnvValue(env, prefix, "Raw", ""); 541 if (!SetEdgesRaw(txt.Data())) 542 return kERROR; 543 } 544 /* 545 if (fullbins) 546 { 547 TString txt = GetEnvValue(env, prefix, "Binning", ""); 548 SetEdgesRaw(txt.Data()); 549 } 550 */ 551 552 return rc; 553 } -
trunk/MagicSoft/Mars/mhbase/MBinning.h
r5803 r5971 55 55 56 56 Bool_t SetEdges(const MParList &list, const char *name=0); 57 Bool_t SetEdgesRaw(const char *txt); 58 //Bool_t SetEdges(const char *txt); 57 59 void SetEdges(const TAxis &axe); 58 60 void SetEdges(const MBinning &bins) { SetEdges(bins.fEdges); fType = bins.fType; fTitle = bins.fTitle; } … … 104 106 void Apply(TH1 &) const; 105 107 108 void Print(Option_t *o="") const; 109 110 Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print=kFALSE); 111 106 112 ClassDef(MBinning, 1) //Container to store the binning of a histogram 107 113 };
Note:
See TracChangeset
for help on using the changeset viewer.