Changeset 4991 for trunk/MagicSoft/Mars/mhbase
- Timestamp:
- 09/14/04 12:13:07 (20 years ago)
- Location:
- trunk/MagicSoft/Mars/mhbase
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mhbase/MFillH.cc
r4058 r4991 18 18 ! Author(s): Thomas Bretz, 07/2001 <mailto:tbretz@astro.uni-wuerzburg.de> 19 19 ! 20 ! Copyright: MAGIC Software Development, 2000-200 320 ! Copyright: MAGIC Software Development, 2000-2004 21 21 ! 22 22 ! … … 24 24 25 25 ////////////////////////////////////////////////////////////////////////////// 26 // // 27 // MFillH // 28 // // 29 // This is a common interface (task) to fill mars histograms. Every mars // 30 // histogram which is derived from MH can be filled with this task. // 31 // // 32 // There are two options to use: // 33 // // 34 // 1) You specifiy the parameter container with which data the // 35 // histogram container should be filled, and the histogram container // 36 // which has to be filled. This can be done by either specifing the // 37 // name of the objects in the parameter list or by specifiing a pointer // 38 // to the object. (s. Constructor) // 39 // // 40 // 2) You specify the name and/or type of the histogram to become filled. // 41 // Any other action imust be taken by the histogram class. // 42 // // 43 // PreProcess: In the preprocessing of this task we setup all pointers // 44 // to instances which are needed and call FillSetup of the // 45 // histogram class with the parameter list as an argument. // 46 // // 47 // Process: The process function calls the Fill member function of the // 48 // histogram class instance (inheriting from MH) with either // 49 // a NULL pointer or a pointer to the corresponding container // 50 // as an argument. // 51 // // 52 // To use a weight for each event filled in a histogram call // 53 // SetWeight(). You can eithe use the name of a MWeight container stored // 54 // in the parameter list or a pointer to it as an argument. // 55 // // 56 // // 57 // WARNING: // 58 // Because MFillH is a generalized task to fill histograms it doesn't // 59 // know about which branches from a file are necessary to fill the // 60 // histograms. If you are reading data from a file which is directly // 61 // filled into a histogram via MFillH, please call either // 62 // MReadTree::DisableAutoScheme() or enable the necessary branches by // 63 // yourself, using MReadTree::EnableBranch() // 64 // // 65 // Checkout the Warning in MTaskList. // 66 // // 67 // Input Containers: // 68 // A parameter container // 69 // // 70 // Output Containers: // 71 // A histogram container // 72 // // 26 // 27 // MFillH 28 // 29 // This is a common interface (task) to fill mars histograms. Every mars 30 // histogram which is derived from MH can be filled with this task. 31 // 32 // There are two options to use: 33 // 34 // 1) You specifiy the parameter container with which data the 35 // histogram container should be filled, and the histogram container 36 // which has to be filled. This can be done by either specifing the 37 // name of the objects in the parameter list or by specifiing a pointer 38 // to the object. (s. Constructor) 39 // 40 // 2) You specify the name and/or type of the histogram to become filled. 41 // Any other action imust be taken by the histogram class. 42 // 43 // PreProcess: In the preprocessing of this task we setup all pointers 44 // to instances which are needed and call FillSetup of the 45 // histogram class with the parameter list as an argument. 46 // 47 // Process: The process function calls the Fill member function of the 48 // histogram class instance (inheriting from MH) with either 49 // a NULL pointer or a pointer to the corresponding container 50 // as an argument. 51 // 52 // To use a weight for each event filled in a histogram call 53 // SetWeight(). You can eithe use the name of a MWeight container stored 54 // in the parameter list or a pointer to it as an argument. 55 // 56 // 57 // WARNING: 58 // Because MFillH is a generalized task to fill histograms it doesn't 59 // know about which branches from a file are necessary to fill the 60 // histograms. If you are reading data from a file which is directly 61 // filled into a histogram via MFillH, please call either 62 // MReadTree::DisableAutoScheme() or enable the necessary branches by 63 // yourself, using MReadTree::EnableBranch() 64 // 65 // Checkout the Warning in MTaskList. 66 // 67 // Version 2: 68 // ---------- 69 // - added fNumExcutions 70 // 71 // 72 // Input Containers: 73 // A parameter container 74 // 75 // Output Containers: 76 // A histogram container 77 // 73 78 ////////////////////////////////////////////////////////////////////////////// 74 79 #include "MFillH.h" … … 457 462 // 458 463 fH->SetSerialNumber(GetSerialNumber()); 464 fH->SetNumExecutions(0); 459 465 if (!fH->SetupFill(pList)) 460 466 { … … 519 525 ((MHArray*)fH)->SetIndex(idx); 520 526 */ 521 527 /* 522 528 TVirtualPad *save = gPad; 523 529 if (fCanvas) 524 530 fCanvas->cd(); 525 531 */ 526 532 const Bool_t rc = fH->Fill(fParContainer, fWeight?fWeight->GetWeight():1); 527 533 fH->SetNumExecutions(GetNumExecutions()+1); 534 /* 528 535 if (save && fCanvas) 529 536 save->cd(); 530 537 */ 531 538 return rc; 532 539 } -
trunk/MagicSoft/Mars/mhbase/MH.cc
r4966 r4991 1271 1271 const char* name, const char* title) 1272 1272 { 1273 const Int_t size = array.GetSize(); 1274 1275 TH1I *h1=0; 1276 1277 //check if histogram with identical name exist 1278 TObject *h1obj = gROOT->FindObject(name); 1279 if (h1obj && h1obj->InheritsFrom("TH1I")) 1280 { 1281 h1 = (TH1I*)h1obj; 1282 h1->Reset(); 1283 } 1284 1285 Double_t min = size>0 ? array[0] : 0; 1286 Double_t max = size>0 ? array[0] : 1; 1287 1288 // first loop over array to find the min and max 1289 for (Int_t i=1; i<size;i++) 1290 { 1291 max = TMath::Max((Double_t)array[i], max); 1292 min = TMath::Min((Double_t)array[i], min); 1293 } 1294 1295 Int_t newbins = 0; 1296 FindGoodLimits(nbins, newbins, min, max, kFALSE); 1297 1298 if (!h1) 1299 { 1300 h1 = new TH1I(name, title, nbins, min, max); 1301 h1->SetXTitle(""); 1302 h1->SetYTitle("Counts"); 1303 h1->SetDirectory(gROOT); 1304 } 1305 1306 // Second loop to fill the histogram 1307 for (Int_t i=0;i<size;i++) 1308 h1->Fill(array[i]); 1309 1310 return h1; 1273 const TArrayF arr(array.GetSize(), array.GetArray()); 1274 return ProjectArray(array, nbins, name, title); 1311 1275 } 1312 1276 … … 1317 1281 TH1I* MH::ProjectArray(const MArrayD &array, Int_t nbins, const char* name, const char* title) 1318 1282 { 1319 const Int_t size = array.GetSize(); 1320 TH1I *h1=0; 1321 1322 //check if histogram with identical name exist 1323 TObject *h1obj = gROOT->FindObject(name); 1324 if (h1obj && h1obj->InheritsFrom("TH1I")) 1325 { 1326 h1 = (TH1I*)h1obj; 1327 h1->Reset(); 1328 } 1329 1330 Double_t min = size>0 ? array[0] : 0; 1331 Double_t max = size>0 ? array[0] : 1; 1332 1333 // first loop over array to find the min and max 1334 for (Int_t i=1; i<size;i++) 1335 { 1336 max = TMath::Max(array[i], max); 1337 min = TMath::Min(array[i], min); 1338 } 1339 1340 Int_t newbins = 0; 1341 FindGoodLimits(nbins, newbins, min, max, kFALSE); 1342 1343 if (!h1) 1344 { 1345 h1 = new TH1I(name, title, newbins, min, max); 1346 h1->SetXTitle(""); 1347 h1->SetYTitle("Counts"); 1348 h1->SetDirectory(gROOT); 1349 } 1350 1351 // Second loop to fill the histogram 1352 for (Int_t i=0;i<size;i++) 1353 h1->Fill(array[i]); 1354 1355 return h1; 1356 } 1357 1283 const TArrayD arr(array.GetSize(), array.GetArray()); 1284 return ProjectArray(array, nbins, name, title); 1285 } 1286 1287 // -------------------------------------------------------------------------- 1288 // 1289 // See MTask::PrintSkipped 1290 // 1291 void MH::PrintSkipped(UInt_t n, const char *str) 1292 { 1293 *fLog << " " << setw(7) << n << " ("; 1294 *fLog << setw(3) << (int)(100.*n/GetNumExecutions()); 1295 *fLog << "%) Evts skipped: " << str << endl; 1296 } -
trunk/MagicSoft/Mars/mhbase/MH.h
r4966 r4991 24 24 { 25 25 private: 26 Byte_t fSerialNumber; 26 Byte_t fSerialNumber; // Serial number (eg of telecope) 27 UInt_t fNumExecutions; // Number of calls to Fill function 27 28 28 29 public: 29 30 MH(const char *name=NULL, const char *title=NULL); 30 31 31 32 32 virtual void SetSerialNumber(Byte_t num) { fSerialNumber = num; } … … 34 34 TString AddSerialNumber(const char *str) const { TString s(str); if (fSerialNumber==0) return s; s += ";"; s += fSerialNumber; return s; } 35 35 TString AddSerialNumber(const TString &str) const { return AddSerialNumber((const char*)str); } 36 37 UInt_t GetNumExecutions() const { return fNumExecutions; } 38 void SetNumExecutions(UInt_t n) { fNumExecutions=n; } 39 40 void PrintSkipped(UInt_t n, const char *str); 36 41 37 42 Bool_t OverwritesDraw(TClass *cls=NULL) const; … … 110 115 static TObject *FindObjectInPad(const char *name, TVirtualPad *pad=NULL); 111 116 112 ClassDef(MH, 1) //A base class for Mars histograms117 ClassDef(MH, 2) //A base class for Mars histograms 113 118 }; 114 119
Note:
See TracChangeset
for help on using the changeset viewer.