Changeset 1668 for trunk/MagicSoft/Mars/mhist/MHGamma.cc
- Timestamp:
- 11/25/02 09:12:47 (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mhist/MHGamma.cc
r1422 r1668 38 38 #include <math.h> 39 39 40 #include <TH1.h>41 40 #include <TH2.h> 42 41 #include <TH3.h> 43 42 43 #include "MHAlphaEnergyTheta.h" 44 44 45 #include "MLog.h" 45 46 #include "MLogManip.h" … … 52 53 // Default Constructor. 53 54 // 54 MHGamma::MHGamma() 55 { 55 MHGamma::MHGamma(const TString &name, const TString &title) 56 : fHist(NULL), fProject(NULL) 57 { 58 fName = name.IsNull() ? (TString)"MHGamma" : name; 59 fTitle = title.IsNull() ? (TString)"3D-histogram of Alpha, E_est, Theta (Gamma sample)" : title; 56 60 } 57 61 … … 64 68 return kTRUE; 65 69 } 70 71 TH3D *MHGamma::Subtract(const MHAlphaEnergyTheta &h1, const MHAlphaEnergyTheta &h2) 72 { 73 return Subtract(h1.GetHist(), h2.GetHist()); 74 } 75 76 TObject *MHGamma::DrawClone(Option_t *opt="") const 77 { 78 DrawClone1(); 79 DrawClone2(); 80 81 return NULL; 82 } 83 84 void MHGamma::DrawClone1() const 85 { 86 if (!fHist) 87 return; 88 89 // 90 // ------------- Part 1 --------------------- 91 // 92 TString titlex = fHist->GetXaxis()->GetTitle(); 93 TString titley = fHist->GetYaxis()->GetTitle(); 94 TString titlez = fHist->GetYaxis()->GetTitle(); 95 96 TString canvtitle = "3D-plot "; //of "; 97 /* 98 canvtitle += titlex; 99 canvtitle += ", "; 100 canvtitle += titley; 101 canvtitle += ", "; 102 canvtitle += titlez+" "; 103 */ 104 canvtitle += "for \'gamma\' sample"; 105 106 TCanvas &c = *MakeDefCanvas("Alpha", canvtitle); 107 108 c.Divide(2, 2); 109 110 gROOT->SetSelectedPad(NULL); 111 112 TH1 *h; 113 114 c.cd(1); 115 h = ((TH3D*)(fHist))->Project3D(fName+"_ex"); 116 117 TString title= "Source-Antisource: "; 118 h->SetTitle(title + titlex); 119 h->SetXTitle(titlex); 120 h->SetYTitle("Counts"); 121 122 h->Draw(); 123 h->SetBit(kCanDelete); 124 125 c.cd(2); 126 h = ((TH3D*)(fHist))->Project3D(fName+"_ey"); 127 128 h->SetTitle(title + titley); 129 h->SetXTitle(titley); 130 h->SetYTitle("Counts"); 131 132 h->Draw(); 133 h->SetBit(kCanDelete); 134 gPad->SetLogx(); 135 136 c.cd(3); 137 h = ((TH3D*)(fHist))->Project3D(fName+"_ez"); 138 139 h->SetTitle(title + titlez); 140 h->SetXTitle(titlez); 141 h->SetYTitle("Counts"); 142 143 h->Draw(); 144 h->SetBit(kCanDelete); 145 146 c.cd(4); 147 ((TH3D*)fHist)->DrawCopy(); 148 149 c.Modified(); 150 c.Update(); 151 } 152 66 153 67 154 // -------------------------------------------------------------------------- … … 70 157 // fHist(gamma) = h1(source) - h2(antisource) 71 158 // 72 TH3D *MHGamma::Subtract(const TH3D *h1, const TH3D *h2, 73 const char *name, const char *title, 74 Bool_t Draw) 75 { 76 TH3D *fHist; 77 fHist = new TH3D(); 78 fHist->SetName(name); 79 fHist->SetTitle(title); 80 159 TH3D *MHGamma::Subtract(const TH3D *h1, const TH3D *h2) 160 { 161 if (fHist) 162 delete fHist; 163 164 fHist = new TH3D; 165 fHist->SetName(fName); 166 fHist->SetTitle(fTitle); 81 167 fHist->SetDirectory(NULL); 82 168 83 // SetBinning((TH3D*)fHist, (TH3D*)h1);84 169 SetBinning((TH1*)fHist, (TH1*)h1); 85 170 86 TString strg1 = (((TH1*)h1)->GetXaxis())->GetTitle(); 87 TString strg2 = (((TH1*)h1)->GetYaxis())->GetTitle(); 88 TString strg3 = (((TH1*)h1)->GetZaxis())->GetTitle(); 89 fHist->SetXTitle(strg1); 90 fHist->SetYTitle(strg2); 91 fHist->SetZTitle(strg3); 171 fHist->SetXTitle((((TH1*)h1)->GetXaxis())->GetTitle()); 172 fHist->SetYTitle((((TH1*)h1)->GetYaxis())->GetTitle()); 173 fHist->SetZTitle((((TH1*)h1)->GetZaxis())->GetTitle()); 92 174 93 175 fHist->Add((TH1*)h1, (TH1*)h2, 1, -1); // ROOT: FIXME! 94 95 //...........................................................96 // draw histogram97 if (Draw == kTRUE)98 {99 TString strg7 = "3D-plot of ";100 strg7 += strg1;101 strg7 += ",";102 strg7 += strg2;103 strg7 += ",";104 strg7 += strg3;105 strg7 += " for \'gamma\' sample";106 107 TCanvas &c = *MakeDefCanvas("Alpha", strg7);108 109 c.Divide(2, 2);110 111 gROOT->SetSelectedPad(NULL);112 113 TH1 *h;114 115 c.cd(1);116 h = ((TH3D*)(fHist))->Project3D("ex");117 118 TString strg0 = "SRC-ASRC : ";119 TString strg4 = strg0 + strg1;120 h->SetTitle(strg4);121 h->SetXTitle(strg1);122 h->SetYTitle("Counts");123 124 h->Draw();125 h->SetBit(kCanDelete);126 127 c.cd(2);128 h = ((TH3D*)(fHist))->Project3D("ey");129 130 TString strg5 = strg0 + strg2;131 h->SetTitle(strg5);132 h->SetXTitle(strg2);133 h->SetYTitle("Counts");134 135 h->Draw();136 h->SetBit(kCanDelete);137 gPad->SetLogx();138 139 c.cd(3);140 h = ((TH3D*)(fHist))->Project3D("ez");141 142 TString strg6 = strg0 + strg3;143 h->SetTitle(strg6);144 h->SetXTitle(strg3);145 h->SetYTitle("Counts");146 147 h->Draw();148 h->SetBit(kCanDelete);149 150 c.cd(4);151 ((TH3D*)fHist)->DrawCopy();152 153 c.Modified();154 c.Update();155 }156 176 157 177 return fHist; … … 162 182 // Integrate fHist(gamma) in the alpha range (lo, up) 163 183 // 164 TH2D *MHGamma::GetAlphaProjection(TH3D *fHist, Axis_t lo, Axis_t up, 165 Bool_t Drawp) 184 TH2D *MHGamma::GetAlphaProjection(Axis_t lo, Axis_t up) 166 185 { 167 186 if (up < lo) … … 204 223 axe.SetRange(ilo, iup); 205 224 206 TH2D &h2D = *(TH2D *)fHist->Project3D("ezy"); 207 208 TString strg0 = "2D-plot of "; 209 TString strg1 = (fHist->GetYaxis())->GetTitle(); 210 TString strg2 = (fHist->GetZaxis())->GetTitle(); 211 strg0 += strg2; 212 strg0 += " vs. "; 213 strg0 += strg1; 214 h2D.SetTitle(strg0); 215 h2D.SetXTitle(strg1); 216 h2D.SetYTitle(strg2); 217 218 219 //........................................................... 220 // draw histogram 221 if (Drawp == kTRUE) 222 { 223 char txt[100]; 224 TString strg3 = "No.of Gammas vs. "; 225 strg3 += strg1; 226 strg3 += " and "; 227 strg3 += strg2; 228 sprintf(txt, " (%.1f < alpha < %.1f deg)", lo, up); 229 strg3 += txt; 230 231 TCanvas &c = *MakeDefCanvas("Gamma", strg3); 232 233 c.Divide(2, 2); 234 235 gROOT->SetSelectedPad(NULL); 236 237 TH1 *h; 238 239 c.cd(1); 240 h = h2D.ProjectionX("xpro", -1, 9999, "E"); 241 TString strg0 = "No.of gammas : "; 242 TString strg7 = strg0 + strg1; 243 h->SetTitle(strg7); 244 h->SetXTitle(strg1); 245 h->SetYTitle("Counts"); 246 247 h->Draw(); 248 h->SetBit(kCanDelete); 249 gPad->SetLogx(); 250 251 c.cd(2); 252 h = h2D.ProjectionY("ypro", -1, 9999, "E"); 253 TString strg8 = strg0 + strg2; 254 h->SetTitle(strg8); 255 h->SetXTitle(strg2); 256 h->SetYTitle("Counts"); 257 258 h->Draw(); 259 h->SetBit(kCanDelete); 260 261 c.cd(3); 262 263 h2D.DrawCopy(); 264 gPad->SetLogx(); 265 266 c.Modified(); 267 c.Update(); 268 } 269 //........................................................... 270 271 return &h2D; 272 } 225 fLo = lo; 226 fHi = up; 227 228 if (fProject) 229 delete fProject; 230 fProject = (TH2D*)fHist->Project3D(fName+"_ezy"); 231 232 const TString title = "2D-plot of "; 233 const TString titley = fHist->GetYaxis()->GetTitle(); 234 const TString titlez = fHist->GetZaxis()->GetTitle(); 235 236 fProject->SetTitle(title + titley + " vs. " + titlez); 237 fProject->SetXTitle(titley); 238 fProject->SetYTitle(titlez); 239 240 return fProject; 241 } 242 243 void MHGamma::DrawClone2() const 244 { 245 if (!fProject) 246 return; 247 248 const TString titley = fHist->GetYaxis()->GetTitle(); 249 const TString titlez = fHist->GetZaxis()->GetTitle(); 250 251 TString canvtitle = "No.of Gammas ";//vs. "; 252 /* 253 canvtitle += titley; 254 canvtitle += " and "; 255 canvtitle += titlez; 256 */ 257 canvtitle += Form("(%.1f < alpha < %.1f deg)", fLo, fHi); 258 259 TCanvas &c = *MakeDefCanvas("Gamma", canvtitle); 260 261 c.Divide(2, 2); 262 263 gROOT->SetSelectedPad(NULL); 264 265 TH1 *h; 266 267 c.cd(1); 268 h = fProject->ProjectionX(fName+"_xpro", -1, 9999, "E"); 269 TString title = "No.of gammas: "; 270 h->SetTitle(title+titley); 271 h->SetXTitle(titley); 272 h->SetYTitle("Counts"); 273 274 h->Draw(); 275 h->SetBit(kCanDelete); 276 gPad->SetLogx(); 277 278 c.cd(2); 279 h = fProject->ProjectionY(fName+"_ypro", -1, 9999, "E"); 280 h->SetTitle(title+titlez); 281 h->SetXTitle(titlez); 282 h->SetYTitle("Counts"); 283 284 h->Draw(); 285 h->SetBit(kCanDelete); 286 287 c.cd(3); 288 289 fProject->DrawCopy(); 290 gPad->SetLogx(); 291 292 c.Modified(); 293 c.Update(); 294 }
Note:
See TracChangeset
for help on using the changeset viewer.