Changeset 9316 for trunk/MagicSoft/Mars/mhist
- Timestamp:
- 02/11/09 12:17:43 (16 years ago)
- Location:
- trunk/MagicSoft/Mars/mhist
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mhist/MHCamera.cc
r9308 r9316 1 1 /* ======================================================================== *\ 2 ! $Name: not supported by cvs2svn $:$Id: MHCamera.cc,v 1.11 4 2009-02-09 11:30:53 tbretz Exp $2 ! $Name: not supported by cvs2svn $:$Id: MHCamera.cc,v 1.115 2009-02-11 12:17:43 tbretz Exp $ 3 3 ! -------------------------------------------------------------------------- 4 4 ! … … 627 627 // 628 628 // The margin != 0 is a workaround for a problem in root 4.02/00 629 pad->Divide(1, 1, 1e-10, 1e-10, col);630 pad->cd(1);631 gPad->SetBorderMode(0);629 //pad->Divide(1, 1, 1e-10, 1e-10, col); 630 //pad->cd(1); 631 //gPad->SetBorderMode(0); 632 632 } 633 633 … … 639 639 // changes gPad... 640 640 // 641 if (!hassame)642 pad->cd();641 // if (!hassame) 642 // pad->cd(); 643 643 } 644 644 … … 651 651 TObject *MHCamera::DrawClone(Option_t *option) const 652 652 { 653 return TObject::Clone(); 654 653 655 // Draw a clone of this object in the current pad 654 656 … … 951 953 } 952 954 953 954 // ------------------------------------------------------------------------955 //956 // Resizes the current pad so that the camera is displayed in its957 // correct aspect ratio958 //959 void MHCamera::SetRange()960 {961 const Float_t range = fGeomCam->GetMaxRadius()*1.05;962 963 //964 // Maintain aspect ratio965 //966 const float ratio = TestBit(kNoLegend) ? 1 : 1.15;967 968 //969 // Calculate width and height of the current pad in pixels970 //971 Float_t w = gPad->GetWw();972 Float_t h = gPad->GetWh()*ratio;973 974 //975 // This prevents the pad from resizing itself wrongly976 //977 if (gPad->GetMother() != gPad)978 {979 w *= gPad->GetMother()->GetAbsWNDC();980 h *= gPad->GetMother()->GetAbsHNDC();981 }982 983 //984 // Set Range (coordinate system) of pad985 //986 gPad->Range(-range, -range, (2*ratio-1)*range, range);987 988 //989 // Resize Pad to given ratio990 //991 if (h<w)992 gPad->SetPad((1.-h/w)/2, 0, (h/w+1.)/2, 1);993 else994 gPad->SetPad(0, (1.-w/h)/2, 1, (w/h+1.)/2);995 }996 997 955 // ------------------------------------------------------------------------ 998 956 // … … 1140 1098 1141 1099 if (!hassame) 1142 {1143 1100 gPad->Clear(); 1144 1101 1102 if (!fGeomCam) 1103 return; 1104 1105 if (!hassame) 1106 { 1145 1107 // Maintain aspect ratio 1146 SetRange(); 1108 const Float_t r = fGeomCam->GetMaxRadius(); 1109 1110 MH::SetPadRange(-r*1.02, -r*1.02, TestBit(kNoLegend) ? r : 1.15*r, r*1.2); 1147 1111 1148 1112 if (GetPainter()) … … 1909 1873 void MHCamera::UpdateLegend(Float_t min, Float_t max, Bool_t islog) 1910 1874 { 1911 const Float_t range = fGeomCam->GetMaxRadius() *1.05;1875 const Float_t range = fGeomCam->GetMaxRadius(); 1912 1876 1913 1877 if (!TestBit(kNoScale)) 1914 1878 { 1915 1879 TArrow arr; 1916 arr.PaintArrow(-range*.9 , -range*.9, -range*.6, -range*.9, 0.025);1917 arr.PaintArrow(-range*.9 , -range*.9, -range*.9, -range*.6, 0.025);1880 arr.PaintArrow(-range*.99, -range*.99, -range*.60, -range*.99, 0.010); 1881 arr.PaintArrow(-range*.99, -range*.99, -range*.99, -range*.60, 0.010); 1918 1882 1919 1883 TString text; … … 1923 1887 TText newtxt2; 1924 1888 newtxt2.SetTextSize(0.04); 1925 newtxt2.PaintText(-range*. 85, -range*.85, text);1889 newtxt2.PaintText(-range*.95, -range*.95, text); 1926 1890 1927 1891 text = MString::Format("%.2f\\circ", range*.3*fGeomCam->GetConvMm2Deg()); … … 1929 1893 1930 1894 TLatex latex; 1931 latex.PaintLatex(-range*. 85, -range*.75, 0, 0.04, text);1895 latex.PaintLatex(-range*.95, -range*.85, 0, 0.04, text); 1932 1896 } 1933 1897 … … 1936 1900 TPaveStats *stats = GetStatisticBox(); 1937 1901 1938 const Float_t hndc = 0. 92- (stats ? stats->GetY1NDC() : 1);1939 const Float_t H = (0. 75-hndc)*range;1902 const Float_t hndc = 0.88 - (stats ? stats->GetY1NDC() : 1); 1903 const Float_t H = (0.80-hndc)*range; 1940 1904 const Float_t offset = hndc*range; 1941 1905 … … 2215 2179 void MHCamera::DrawProjection(Int_t fit) const 2216 2180 { 2217 TArrayI inner(1);2218 inner[0] = 0;2219 2220 TArrayI outer(1);2221 outer[0] = 1;2222 2223 2181 if (fit==5 || fit==6) 2224 2182 { 2225 if (GetGeomCam().InheritsFrom("MGeomCamMagic")) 2183 const UInt_t n = fGeomCam->GetNumAreas(); 2184 2185 TVirtualPad *pad = gPad; 2186 pad->Divide(n, 1, 1e-5, 1e-5);; 2187 2188 for (UInt_t i=0; i<n; i++) 2226 2189 { 2227 TArrayI s0(6); 2228 s0[0] = 6; 2229 s0[1] = 1; 2230 s0[2] = 2; 2231 s0[3] = 3; 2232 s0[4] = 4; 2233 s0[5] = 5; 2234 2235 TArrayI s1(3); 2236 s1[0] = 6; 2237 s1[1] = 1; 2238 s1[2] = 2; 2239 2240 TArrayI s2(3); 2241 s2[0] = 3; 2242 s2[1] = 4; 2243 s2[2] = 5; 2244 2245 gPad->Clear(); 2246 TVirtualPad *pad = gPad; 2247 pad->Divide(2,1); 2248 2249 TH1D *inout[2]; 2250 inout[0] = ProjectionS(s0, inner, "Inner"); 2251 inout[1] = ProjectionS(s0, outer, "Outer"); 2252 2253 inout[0]->SetDirectory(NULL); 2254 inout[1]->SetDirectory(NULL); 2255 2256 for (int i=0; i<2; i++) 2190 pad->cd(i+1); 2191 gPad->SetBorderMode(0); 2192 gPad->SetRightMargin(0.025); 2193 gPad->SetTicks(); 2194 2195 TH1D &h = *ProjectionS(TArrayI(), TArrayI(1, (Int_t*)&i), 2196 MString::Format("%s_%d", GetName(), i)); 2197 h.SetTitle(MString::Format("%s %d", GetTitle(), i)); 2198 h.SetDirectory(NULL); 2199 h.SetBit(kCanDelete); 2200 h.Draw(); 2201 2202 TAxis *xaxe = h.GetXaxis(); 2203 TAxis *yaxe = h.GetYaxis(); 2204 2205 xaxe->CenterTitle(); 2206 yaxe->CenterTitle(); 2207 xaxe->SetTitleSize(0.06); 2208 yaxe->SetTitleSize(0.06); 2209 xaxe->SetTitleOffset(0.8); 2210 yaxe->SetTitleOffset(0.85); 2211 xaxe->SetLabelSize(0.05); 2212 yaxe->SetLabelSize(0.05); 2213 if (i>0) 2214 yaxe->SetTitle(""); 2215 2216 if (fit==5) 2217 continue; 2218 2219 h.Fit("gaus", "Q"); 2220 2221 TF1 *f = h.GetFunction("gaus"); 2222 if (f) 2257 2223 { 2258 pad->cd(i+1); 2259 gPad->SetBorderMode(0); 2260 2261 inout[i]->SetLineColor(kRed+i); 2262 inout[i]->SetBit(kCanDelete); 2263 inout[i]->Draw(); 2264 inout[i]->Fit("gaus","Q"); 2265 2266 if (fit == 6) 2267 { 2268 TH1D *half[2]; 2269 half[0] = ProjectionS(s1, i==0 ? inner : outer , "Sector 6-1-2"); 2270 half[1] = ProjectionS(s2, i==0 ? inner : outer , "Sector 3-4-5"); 2271 2272 for (int j=0; j<2; j++) 2273 { 2274 half[j]->SetLineColor(kRed+i+2*j+1); 2275 half[j]->SetDirectory(NULL); 2276 half[j]->SetBit(kCanDelete); 2277 half[j]->Draw("same"); 2278 } 2279 } 2280 2224 f->SetLineWidth(2); 2225 f->SetLineColor(kBlue); 2281 2226 } 2282 2227 } … … 2289 2234 obj2->SetBit(kCanDelete); 2290 2235 2291 if (fit == 0) 2292 return; 2293 2294 if (GetGeomCam().InheritsFrom("MGeomCamMagic")) 2295 { 2296 TArrayI s0(3); 2297 s0[0] = 6; 2298 s0[1] = 1; 2299 s0[2] = 2; 2300 2301 TArrayI s1(3); 2302 s1[0] = 3; 2303 s1[1] = 4; 2304 s1[2] = 5; 2305 2306 TH1D *halfInOut[4]; 2307 2308 // Just to get the right (maximum) binning 2309 halfInOut[0] = ProjectionS(s0, inner, "Sector 6-1-2 Inner"); 2310 halfInOut[1] = ProjectionS(s1, inner, "Sector 3-4-5 Inner"); 2311 halfInOut[2] = ProjectionS(s0, outer, "Sector 6-1-2 Outer"); 2312 halfInOut[3] = ProjectionS(s1, outer, "Sector 3-4-5 Outer"); 2313 2314 TLegend *leg = new TLegend(0.05,0.65,0.35,0.9); 2315 2316 for (int i=0; i<4; i++) 2317 { 2318 halfInOut[i]->SetLineColor(kRed+i); 2319 halfInOut[i]->SetDirectory(0); 2320 halfInOut[i]->SetBit(kCanDelete); 2321 halfInOut[i]->Draw("same"); 2322 leg->AddEntry(halfInOut[i],halfInOut[i]->GetTitle(),"l"); 2323 } 2324 2325 if (fit==7) 2326 leg->Draw(); 2327 2328 gPad->Modified(); 2329 gPad->Update(); 2330 } 2331 2332 const Double_t min = obj2->GetBinCenter(obj2->GetXaxis()->GetFirst()); 2333 const Double_t max = obj2->GetBinCenter(obj2->GetXaxis()->GetLast()); 2236 if (fit==0) 2237 return; 2238 2239 const Double_t xmin = obj2->GetBinCenter(obj2->GetXaxis()->GetFirst()); 2240 const Double_t xmax = obj2->GetBinCenter(obj2->GetXaxis()->GetLast()); 2334 2241 const Double_t integ = obj2->Integral("width")/2.5; 2242 const Double_t max = obj2->GetMaximum(); 2335 2243 const Double_t mean = obj2->GetMean(); 2336 2244 const Double_t rms = obj2->GetRMS(); 2337 const Double_t width = max-min;2245 const Double_t width = xmax-xmin; 2338 2246 2339 2247 const TString dgausformula = "([0]-[3])/[2]*exp(-0.5*(x-[1])*(x-[1])/[2]/[2])" … … 2347 2255 switch (fit) 2348 2256 { 2349 case 1: 2350 f = new TF1("sgaus", "gaus (0)", min,max);2351 f->SetLineColor(k Yellow);2257 case 1: // Single gauss 2258 f = new TF1("sgaus", "gaus", xmin, xmax); 2259 f->SetLineColor(kBlue); 2352 2260 f->SetBit(kCanDelete); 2353 f->SetParNames(" Area", "#mu", "#sigma");2354 f->SetParameters( integ/rms, mean, rms);2355 f->SetParLimits(0, 0, integ);2356 f->SetParLimits(1, min,max);2357 f->SetParLimits(2, 0, width/1.5);2261 f->SetParNames("Max", "#mu", "#sigma"); 2262 f->SetParameters(max, mean, rms); 2263 f->SetParLimits(0, 0, max*2); 2264 f->SetParLimits(1, xmin, xmax); 2265 f->SetParLimits(2, 0, width/1.5); 2358 2266 2359 2267 obj2->Fit(f, "QLR"); 2360 2268 break; 2361 2269 2362 case 2: 2363 f = new TF1("dgaus", dgausformula.Data(),min,max);2364 f->SetLineColor(k Yellow);2270 case 2: // Double gauss 2271 f = new TF1("dgaus", dgausformula, xmin, xmax); 2272 f->SetLineColor(kBlue); 2365 2273 f->SetBit(kCanDelete); 2366 2274 f->SetParNames("A_{tot}", "#mu1", "#sigma1", "A2", "#mu2", "#sigma2"); 2367 f->SetParameters(integ, (min+mean)/2.,width/4.,2368 integ/width/2., (max+mean)/2.,width/4.);2275 f->SetParameters(integ, (xmin+mean)/2., width/4., 2276 integ/width/2., (xmax+mean)/2., width/4.); 2369 2277 // The left-sided Gauss 2370 f->SetParLimits(0, integ-1.5 ,integ+1.5);2371 f->SetParLimits(1, min+(width/10.), mean);2372 f->SetParLimits(2, 0 ,width/2.);2278 f->SetParLimits(0, integ-1.5, integ+1.5); 2279 f->SetParLimits(1, xmin+(width/10.), mean); 2280 f->SetParLimits(2, 0, width/2.); 2373 2281 // The right-sided Gauss 2374 f->SetParLimits(3, 0 ,integ);2375 f->SetParLimits(4, mean,max-(width/10.));2376 f->SetParLimits(5, 0 ,width/2.);2282 f->SetParLimits(3, 0, integ); 2283 f->SetParLimits(4, mean, xmax-(width/10.)); 2284 f->SetParLimits(5, 0, width/2.); 2377 2285 obj2->Fit(f,"QLRM"); 2378 2286 break; 2379 2287 2380 case 3: 2381 f = new TF1("tgaus", tgausformula.Data(),min,max);2382 f->SetLineColor(k Yellow);2288 case 3: // Triple gauss 2289 f = new TF1("tgaus", tgausformula, xmin,xmax); 2290 f->SetLineColor(kBlue); 2383 2291 f->SetBit(kCanDelete); 2384 2292 f->SetParNames("A_{tot}","#mu_{1}","#sigma_{1}", 2385 2293 "A_{2}","#mu_{2}","#sigma_{2}", 2386 2294 "A_{3}","#mu_{3}","#sigma_{3}"); 2387 f->SetParameters(integ, (min+mean)/2,width/4.,2388 integ/width/3., (max+mean)/2.,width/4.,2389 integ/width/3., mean,width/2.);2295 f->SetParameters(integ, (xmin+mean)/2, width/4., 2296 integ/width/3., (xmax+mean)/2., width/4., 2297 integ/width/3., mean,width/2.); 2390 2298 // The left-sided Gauss 2391 f->SetParLimits(0, integ-1.5,integ+1.5);2392 f->SetParLimits(1, min+(width/10.),mean);2393 f->SetParLimits(2, width/15.,width/2.);2299 f->SetParLimits(0, integ-1.5, integ+1.5); 2300 f->SetParLimits(1, xmin+(width/10.), mean); 2301 f->SetParLimits(2, width/15., width/2.); 2394 2302 // The right-sided Gauss 2395 f->SetParLimits(3, 0.,integ);2396 f->SetParLimits(4, mean,max-(width/10.));2397 f->SetParLimits(5, width/15.,width/2.);2303 f->SetParLimits(3, 0., integ); 2304 f->SetParLimits(4, mean, xmax-(width/10.)); 2305 f->SetParLimits(5, width/15., width/2.); 2398 2306 // The Gauss describing the outliers 2399 f->SetParLimits(6, 0.,integ);2400 f->SetParLimits(7, min,max);2401 f->SetParLimits(8, width/4.,width/1.5);2307 f->SetParLimits(6, 0., integ); 2308 f->SetParLimits(7, xmin, xmax); 2309 f->SetParLimits(8, width/4., width/1.5); 2402 2310 obj2->Fit(f,"QLRM"); 2403 2311 break; … … 2405 2313 case 4: 2406 2314 obj2->Fit("pol0", "Q"); 2407 obj2->GetFunction("pol0")->SetLineColor(k Yellow);2315 obj2->GetFunction("pol0")->SetLineColor(kBlue); 2408 2316 break; 2409 2317 … … 2413 2321 default: 2414 2322 obj2->Fit("gaus", "Q"); 2415 obj2->GetFunction("gaus")->SetLineColor(k Yellow);2323 obj2->GetFunction("gaus")->SetLineColor(kBlue); 2416 2324 break; 2417 2325 } 2418 2326 } 2419 2327 /* 2420 2328 // -------------------------------------------------------------------------- 2421 2329 // … … 2508 2416 } 2509 2417 } 2510 2418 */ 2511 2419 // -------------------------------------------------------------------------- 2512 2420 // … … 2527 2435 // 2528 2436 void MHCamera::CamDraw(TCanvas &c, const Int_t x, const Int_t y, 2529 const Int_t fit, const Int_t rad, const Int_t azi,2437 const Int_t fit, /*const Int_t rad, const Int_t azi,*/ 2530 2438 TObject *notify) 2531 2439 { 2532 2440 c.cd(x); 2533 2441 gPad->SetBorderMode(0); 2442 gPad->SetRightMargin(0.02); 2534 2443 gPad->SetTicks(); 2535 2444 MHCamera *obj1=(MHCamera*)DrawCopy("hist"); 2536 2445 obj1->SetDirectory(NULL); 2446 obj1->SetStats(kFALSE); 2537 2447 2538 2448 if (notify) … … 2545 2455 2546 2456 Int_t cnt = 2; 2547 2457 /* 2548 2458 if (rad) 2549 2459 { … … 2563 2473 cnt++; 2564 2474 } 2565 2566 if ( !fit)2475 */ 2476 if (fit<0) 2567 2477 return; 2568 2478 2569 2479 c.cd(x + cnt*y); 2570 2480 gPad->SetBorderMode(0); 2481 gPad->SetRightMargin(0.025); 2571 2482 gPad->SetTicks(); 2572 2483 DrawProjection(fit); -
trunk/MagicSoft/Mars/mhist/MHCamera.h
r9308 r9316 1 1 /* ======================================================================== *\ 2 ! $Name: not supported by cvs2svn $:$Id: MHCamera.h,v 1.6 7 2009-02-09 11:30:53 tbretz Exp $2 ! $Name: not supported by cvs2svn $:$Id: MHCamera.h,v 1.68 2009-02-11 12:17:43 tbretz Exp $ 3 3 \* ======================================================================== */ 4 4 #ifndef MARS_MHCamera … … 80 80 void Update(Bool_t islog, Bool_t isbox, Bool_t iscol, Bool_t issame); 81 81 void UpdateLegend(Float_t min, Float_t max, Bool_t islog); 82 void SetRange();83 82 84 83 TPaveStats *GetStatisticBox(); … … 231 230 TObject *DrawClone(Option_t *option="") const; 232 231 void DrawProjection (Int_t fit=0) const; 233 void DrawRadialProfile() const;234 void DrawAzimuthProfile() const;232 // void DrawRadialProfile() const; 233 // void DrawAzimuthProfile() const; 235 234 236 235 void SavePrimitive(ostream &out, Option_t *); … … 320 319 321 320 void CamDraw(TCanvas &c, const Int_t x, const Int_t y, 322 const Int_t fit, const Int_t rad=0, const Int_t azi=0,321 const Int_t fit, /*const Int_t rad=0, const Int_t azi=0,*/ 323 322 TObject *notify=NULL); 324 323
Note:
See TracChangeset
for help on using the changeset viewer.