@@ -57,18 +57,8 @@ TScatter can be drawn with the following options:
5757
5858TScatter::TScatter ()
5959{
60- fNpoints = -1 ;
61- fMaxSize = -1 ;
62-
63- fGraph = nullptr ;
64- fHistogram = nullptr ;
65- fScale = 5 .;
66- fMargin = 0.1 ;
67- fSize = nullptr ;
68- fColor = nullptr ;
6960}
7061
71-
7262// //////////////////////////////////////////////////////////////////////////////
7363// / TScatter normal constructor.
7464// /
@@ -79,7 +69,6 @@ TScatter::TScatter(Int_t n)
7969 fGraph = new TGraph (n);
8070 fNpoints = fGraph ->GetN ();
8171 fMaxSize = fGraph ->GetMaxSize ();
82- fHistogram = nullptr ;
8372
8473 fColor = new Double_t[fMaxSize ];
8574 fSize = new Double_t[fMaxSize ];
@@ -101,16 +90,16 @@ TScatter::TScatter(Int_t n, const Double_t *x, const Double_t *y, const Double_t
10190 fGraph = new TGraph (n, x, y);
10291 fNpoints = fGraph ->GetN ();
10392 fMaxSize = fGraph ->GetMaxSize ();
104- fHistogram = nullptr ;
105-
106- fColor = new Double_t[fMaxSize ];
107- fSize = new Double_t[fMaxSize ];
10893
109- n = sizeof (Double_t) * fNpoints ;
110- if (col) memcpy (fColor , col, n);
111- else fColor = nullptr ;
112- if (size) memcpy (fSize , size, n);
113- else fSize = nullptr ;
94+ Int_t bufsize = sizeof (Double_t) * fNpoints ;
95+ if (col) {
96+ fColor = new Double_t[fMaxSize ];
97+ memcpy (fColor , col, bufsize);
98+ }
99+ if (size) {
100+ fSize = new Double_t[fMaxSize ];
101+ memcpy (fSize , size, bufsize);
102+ }
114103
115104 fScale = 5 .;
116105 fMargin = 0.1 ;
@@ -138,8 +127,9 @@ TScatter::~TScatter()
138127Int_t TScatter::DistancetoPrimitive (Int_t px, Int_t py)
139128{
140129 TVirtualGraphPainter *painter = TVirtualGraphPainter::GetPainter ();
141- if (painter) return painter->DistancetoPrimitiveHelper (this ->GetGraph (), px, py);
142- else return 0 ;
130+ if (painter)
131+ return painter->DistancetoPrimitiveHelper (this ->GetGraph (), px, py);
132+ return 0 ;
143133}
144134
145135
@@ -170,23 +160,19 @@ TH2F *TScatter::GetHistogram() const
170160 // do not add the histogram to gDirectory
171161 // use local TDirectory::TContect that will set temporarly gDirectory to a nullptr and
172162 // will avoid that histogram is added in the global directory
173- {
174- TDirectory::TContext ctx (nullptr );
175- double rwxmin, rwymin, rwxmax, rwymax;
176- int npt = 50 ;
177- fGraph ->ComputeRange (rwxmin, rwymin, rwxmax, rwymax);
178- double dx = (rwxmax-rwxmin)*fMargin ;
179- double dy = (rwymax-rwymin)*fMargin ;
180- auto h = new TH2F (TString::Format (" %s_h" ,GetName ()),GetTitle (),npt,rwxmin,rwxmax,npt,rwymin,rwymax);
163+ TDirectory::TContext ctx (nullptr );
164+ double rwxmin, rwymin, rwxmax, rwymax;
165+ int npt = 50 ;
166+ fGraph ->ComputeRange (rwxmin, rwymin, rwxmax, rwymax);
167+ double dx = (rwxmax-rwxmin)*fMargin ;
168+ double dy = (rwymax-rwymin)*fMargin ;
169+ auto h = new TH2F (TString::Format (" %s_h" ,GetName ()),GetTitle (),npt,rwxmin-dx,rwxmax+dx,npt,rwymin-dy,rwymax+dy);
181170// h->SetMinimum(rwymin-dy);
182171// h->SetMaximum(rwymax+dy);
183- h->GetXaxis ()->SetLimits (rwxmin-dx,rwxmax+dx);
184- h->GetYaxis ()->SetLimits (rwymin-dy,rwymax+dy);
185- h->SetBit (TH1::kNoStats );
186- h->SetDirectory (0 );
187- h->Sumw2 (kFALSE );
188- ((TScatter*)this )->fHistogram = h;
189- }
172+ h->SetBit (TH1::kNoStats );
173+ h->SetDirectory (nullptr );
174+ h->Sumw2 (kFALSE );
175+ const_cast <TScatter *>(this )->fHistogram = h;
190176 }
191177 return fHistogram ;
192178}
@@ -258,27 +244,29 @@ void TScatter::SavePrimitive(std::ostream &out, Option_t *option /*= ""*/)
258244 for (i = 0 ; i < fNpoints -1 ; i++) out << " " << fSize [i] << " ," << std::endl;
259245 out << " " << fSize [fNpoints -1 ] << " };" << std::endl;
260246
261- if (gROOT ->ClassSaved (TScatter::Class ())) out << " " ;
262- else out << " TScatter * " ;
263- out << " scat = new TScatter( " << fNpoints << " , "
264- << fXName << " , " << fYName << " , "
265- << fColorName << " ," << fSizeName << " ); "
266- << std::endl;
247+ if (gROOT ->ClassSaved (TScatter::Class ()))
248+ out << " " ;
249+ else
250+ out << " TScatter * " ;
251+ out << " scat = new TScatter( " << fNpoints << " , " << fXName << " ," << fYName << " , "
252+ << fColorName << " , " << fSizeName << " ); " << std::endl;
267253
268254 out << " scat->SetName(" << quote << GetName () << quote << " );" << std::endl;
269255 out << " scat->SetTitle(" << quote << GetTitle () << quote << " );" << std::endl;
256+ out << " scat->SetMargin(" << GetMargin () << " );" << std::endl;
257+ out << " scat->SetScale(" << GetScale () << " );" << std::endl;
270258
271259 SaveFillAttributes (out, " scat" , 0 , 1001 );
272260 SaveLineAttributes (out, " scat" , 1 , 1 , 1 );
273261 SaveMarkerAttributes (out, " scat" , 1 , 1 , 1 );
274262
275263 if (fHistogram ) {
276264 TString hname = fHistogram ->GetName ();
277- hname += frameNumber;
278- fHistogram ->SetName (TString::Format (" Graph_%s" , hname.Data ()));
265+ fHistogram ->SetName (TString::Format (" Graph_%s%d" , hname.Data (), frameNumber));
279266 fHistogram ->SavePrimitive (out, " nodraw" );
280267 out << " scat->SetHistogram(" << fHistogram ->GetName () << " );" << std::endl;
281268 out << " " << std::endl;
269+ fHistogram ->SetName (hname);
282270 }
283271
284272 out << " scat->Draw(" << quote << option << quote << " );" << std::endl;
0 commit comments