Changeset 3112 for trunk/MagicSoft/Mars/mhbase
- Timestamp:
- 02/12/04 11:34:32 (21 years ago)
- Location:
- trunk/MagicSoft/Mars/mhbase
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mhbase/MH.cc
r3081 r3112 1082 1082 } 1083 1083 1084 TH1I* MH::ProjectArray(const TArrayF *array, Int_t nbins, const char* name, const char* title) 1085 { 1086 1087 const Int_t size = array->GetSize(); 1088 TH1I *h1=0; 1089 1090 //check if histogram with identical name exist 1091 TObject *h1obj = gROOT->FindObject(name); 1092 if (h1obj && h1obj->InheritsFrom("TH1I")) { 1093 h1 = (TH1I*)h1obj; 1094 h1->Reset(); 1095 } 1096 1097 Double_t max = 0.; 1098 Double_t min = 0.; 1099 Int_t newbins = 0; 1100 1101 // first loop over array to find the maximum: 1102 for (Int_t i=0; i<size;i++) 1103 if (array->At(i) > max) 1104 max = array->At(i); 1105 1106 FindGoodLimits(nbins, newbins, min, max, kFALSE); 1107 1108 if (!h1) 1109 { 1110 h1 = new TH1I(name, title, newbins, min, max); 1111 h1->SetXTitle(""); 1112 h1->SetYTitle("Counts"); 1113 h1->SetDirectory(NULL); 1114 } 1115 1084 // -------------------------------------------------------------------------- 1085 // 1086 // M.Gaug added this withouz Documentation 1087 // 1088 TH1I* MH::ProjectArray(const TArrayF &array, Int_t nbins, const char* name, const char* title) 1089 { 1090 const Int_t size = array.GetSize(); 1091 1092 TH1I *h1=0; 1093 1094 //check if histogram with identical name exist 1095 TObject *h1obj = gROOT->FindObject(name); 1096 if (h1obj && h1obj->InheritsFrom("TH1I")) 1097 { 1098 h1 = (TH1I*)h1obj; 1099 h1->Reset(); 1100 } 1101 1102 Double_t min = size>0 ? array[0] : 0; 1103 Double_t max = size>0 ? array[0] : 1; 1104 1105 // first loop over array to find the min and max 1106 for (Int_t i=1; i<size;i++) 1107 { 1108 max = TMath::Max((Double_t)array[i], max); 1109 min = TMath::Min((Double_t)array[i], min); 1110 } 1111 1112 Int_t newbins = 0; 1113 FindGoodLimits(nbins, newbins, min, max, kFALSE); 1114 1115 if (!h1) 1116 { 1117 h1 = new TH1I(name, title, newbins, min, max); 1118 h1->SetXTitle(""); 1119 h1->SetYTitle("Counts"); 1120 h1->SetDirectory(gROOT); 1121 } 1122 1116 1123 // Second loop to fill the histogram 1117 for (Int_t i=0;i<size;i++) 1118 h1->Fill(array->At(i)); 1119 1120 h1->SetEntries(size); 1121 1124 for (Int_t i=0;i<size;i++) 1125 h1->Fill(array[i]); 1126 1122 1127 return h1; 1123 1128 } 1124 1129 1125 TH1I* MH::ProjectArray(const TArrayD *array, Int_t nbins, const char* name, const char* title) 1126 { 1127 1128 const Int_t size = array->GetSize(); 1129 1130 TH1I *h1=0; 1131 1132 //check if histogram with identical name exist 1133 TObject *h1obj = gROOT->FindObject(name); 1134 if (h1obj && h1obj->InheritsFrom("TH1I")) { 1135 h1 = (TH1I*)h1obj; 1136 h1->Reset(); 1137 } 1138 1139 Double_t max = 0.; 1140 Double_t min = 0.; 1141 Int_t newbins = 0; 1142 1143 // first loop over array to find the maximum: 1144 for (Int_t i=0; i<size;i++) 1145 if (array->At(i) > max) 1146 max = array->At(i); 1147 1148 FindGoodLimits( nbins, newbins, min, max, kFALSE); 1149 1150 if (!h1) 1151 { 1152 h1 = new TH1I(name, title, newbins, min, max); 1153 h1->SetXTitle(""); 1154 h1->SetYTitle("Counts"); 1155 h1->SetDirectory(NULL); 1156 } 1157 1130 // -------------------------------------------------------------------------- 1131 // 1132 // M.Gaug added this withouz Documentation 1133 // 1134 TH1I* MH::ProjectArray(const TArrayD &array, Int_t nbins, const char* name, const char* title) 1135 { 1136 const Int_t size = array.GetSize(); 1137 TH1I *h1=0; 1138 1139 //check if histogram with identical name exist 1140 TObject *h1obj = gROOT->FindObject(name); 1141 if (h1obj && h1obj->InheritsFrom("TH1I")) 1142 { 1143 h1 = (TH1I*)h1obj; 1144 h1->Reset(); 1145 } 1146 1147 Double_t min = size>0 ? array[0] : 0; 1148 Double_t max = size>0 ? array[0] : 1; 1149 1150 // first loop over array to find the min and max 1151 for (Int_t i=1; i<size;i++) 1152 { 1153 max = TMath::Max(array[i], max); 1154 min = TMath::Min(array[i], min); 1155 } 1156 1157 Int_t newbins = 0; 1158 FindGoodLimits(nbins, newbins, min, max, kFALSE); 1159 1160 if (!h1) 1161 { 1162 h1 = new TH1I(name, title, newbins, min, max); 1163 h1->SetXTitle(""); 1164 h1->SetYTitle("Counts"); 1165 h1->SetDirectory(gROOT); 1166 } 1167 1158 1168 // Second loop to fill the histogram 1159 for (Int_t i=0;i<size;i++) 1160 h1->Fill(array->At(i)); 1161 1162 h1->SetEntries(size); 1163 1169 for (Int_t i=0;i<size;i++) 1170 h1->Fill(array[i]); 1171 1164 1172 return h1; 1165 1173 } -
trunk/MagicSoft/Mars/mhbase/MH.h
r3081 r3112 92 92 static Int_t CutEdges(TH1 *h, Int_t nbins); 93 93 94 static TH1I* ProjectArray(const TArrayF *array, Int_t nbins=30, const char* name="ProjectArray",95 96 static TH1I* ProjectArray(const TArrayD *array, Int_t nbins=30, const char* name="ProjectArray",97 94 static TH1I* ProjectArray(const TArrayF &array, Int_t nbins=30, 95 const char* name="ProjectArray", const char* title="Projected Array"); 96 static TH1I* ProjectArray(const TArrayD &array, Int_t nbins=30, 97 const char* name="ProjectArray", const char* title="Projected Array"); 98 98 99 99 static void ProjectionX(TH1D &dest, const TH2 &src, Int_t firstybin=-1, Int_t lastybin=9999);
Note:
See TracChangeset
for help on using the changeset viewer.