99 TCutG::TCutG() : TGraph()
108 TCutG::TCutG(
const TCutG &cutg)
113 fObjectX = cutg.fObjectX ? cutg.fObjectX->Clone() :
nullptr;
114 fObjectY = cutg.fObjectY ? cutg.fObjectY->Clone() :
nullptr;
120 TCutG::TCutG(
const char *name, Int_t n)
126 delete gROOT->GetListOfSpecials()->FindObject(name);
127 gROOT->GetListOfSpecials()->Add(
this);
131 TPaveText *ptitle = (TPaveText*)gPad->FindObject(
"title");
133 TText *ttitle = ptitle->GetLineWith(
":");
134 if (!ttitle) ttitle = ptitle->GetLineWith(
"{");
135 if (!ttitle) ttitle = ptitle->GetLine(0);
137 const char *title = ttitle->GetTitle();
138 Int_t nch = strlen(title);
139 char *vars =
new char[nch+1];
140 strlcpy(vars,title,nch+1);
141 char *col = strstr(vars,
":");
145 char *brak = strstr(col,
" {");
150 char *brak = strstr(vars,
" {");
161 TCutG::TCutG(
const char *name, Int_t n,
const Float_t *x,
const Float_t *y)
167 delete gROOT->GetListOfSpecials()->FindObject(name);
168 gROOT->GetListOfSpecials()->Add(
this);
172 TPaveText *ptitle = (TPaveText*)gPad->FindObject(
"title");
174 TText *ttitle = ptitle->GetLineWith(
":");
175 if (!ttitle) ttitle = ptitle->GetLineWith(
"{");
176 if (!ttitle) ttitle = ptitle->GetLine(0);
178 const char *title = ttitle->GetTitle();
179 Int_t nch = strlen(title);
180 char *vars =
new char[nch+1];
181 strlcpy(vars,title,nch+1);
182 char *col = strstr(vars,
":");
186 char *brak = strstr(col,
" {");
191 char *brak = strstr(vars,
" {");
202 TCutG::TCutG(
const char *name, Int_t n,
const Double_t *x,
const Double_t *y)
208 delete gROOT->GetListOfSpecials()->FindObject(name);
209 gROOT->GetListOfSpecials()->Add(
this);
213 TPaveText *ptitle = (TPaveText*)gPad->FindObject(
"title");
215 TText *ttitle = ptitle->GetLineWith(
":");
216 if (!ttitle) ttitle = ptitle->GetLineWith(
"{");
217 if (!ttitle) ttitle = ptitle->GetLine(0);
219 const char *title = ttitle->GetTitle();
220 Int_t nch = strlen(title);
221 char *vars =
new char[nch+1];
222 strlcpy(vars,title,nch+1);
223 char *col = strstr(vars,
":");
227 char *brak = strstr(col,
" {");
232 char *brak = strstr(vars,
" {");
247 if ( gROOT && !gROOT->TestBit( TObject::kInvalidObject ) )
248 gROOT->GetListOfSpecials()->Remove(
this);
254 TCutG &TCutG::operator=(
const TCutG &rhs)
257 TGraph::operator=(rhs);
260 fObjectX = rhs.fObjectX ? rhs.fObjectX->Clone() :
nullptr;
261 fObjectY = rhs.fObjectY ? rhs.fObjectY->Clone() :
nullptr;
272 Double_t TCutG::Area()
const
276 for (Int_t i=0;i<n-1;i++) {
277 a += (fX[i]-fX[i+1])*(fY[i]+fY[i+1]);
289 void TCutG::Center(Double_t &cx, Double_t &cy)
const
295 for (Int_t i=0;i<n-1;i++) {
296 t = 2*fX[i]*fY[i] + fY[i]*fX[i+1] + fX[i]*fY[i+1] + 2*fX[i+1]*fY[i+1];
297 cx += (fX[i]-fX[i+1])*t;
298 cy += (-fY[i]+fY[i+1])*t;
299 a += (fX[i]-fX[i+1])*(fY[i]+fY[i+1]);
311 Double_t TCutG::IntegralHist(TH2 *h, Option_t *option)
const
315 Double_t xmin= 1e200;
316 Double_t xmax = -xmin;
317 Double_t ymin = xmin;
318 Double_t ymax = xmax;
319 for (Int_t i=0;i<n;i++) {
320 if (fX[i] < xmin) xmin = fX[i];
321 if (fX[i] > xmax) xmax = fX[i];
322 if (fY[i] < ymin) ymin = fY[i];
323 if (fY[i] > ymax) ymax = fY[i];
325 TAxis *xaxis = h->GetXaxis();
326 TAxis *yaxis = h->GetYaxis();
327 Int_t binx1 = xaxis->FindBin(xmin);
328 Int_t binx2 = xaxis->FindBin(xmax);
329 Int_t biny1 = yaxis->FindBin(ymin);
330 Int_t biny2 = yaxis->FindBin(ymax);
331 Int_t nbinsx = h->GetNbinsX();
335 TString opt = option;
337 Bool_t width = kFALSE;
338 if (opt.Contains(
"width")) width = kTRUE;
339 Int_t bin, binx, biny;
340 for (biny=biny1;biny<=biny2;biny++) {
341 Double_t y = yaxis->GetBinCenter(biny);
342 for (binx=binx1;binx<=binx2;binx++) {
343 Double_t x = xaxis->GetBinCenter(binx);
344 if (!IsInside(x,y))
continue;
345 bin = binx +(nbinsx+2)*biny;
346 if (width) integral += h->GetBinContent(bin)*xaxis->GetBinWidth(binx)*yaxis->GetBinWidth(biny);
347 else integral += h->GetBinContent(bin);
356 void TCutG::SavePrimitive(std::ostream &out, Option_t *option )
360 if (gROOT->ClassSaved(TCutG::Class())) {
365 out<<
"cutg = new TCutG("<<quote<<GetName()<<quote<<
","<<fNpoints<<
");"<<std::endl;
366 out<<
" cutg->SetVarX("<<quote<<GetVarX()<<quote<<
");"<<std::endl;
367 out<<
" cutg->SetVarY("<<quote<<GetVarY()<<quote<<
");"<<std::endl;
368 out<<
" cutg->SetTitle("<<quote<<GetTitle()<<quote<<
");"<<std::endl;
370 SaveFillAttributes(out,
"cutg",0,1001);
371 SaveLineAttributes(out,
"cutg",1,1,1);
372 SaveMarkerAttributes(out,
"cutg",1,1,1);
374 for (Int_t i=0;i<fNpoints;i++) {
375 out<<
" cutg->SetPoint("<<i<<
","<<fX[i]<<
","<<fY[i]<<
");"<<std::endl;
378 <<quote<<option<<quote<<
");"<<std::endl;
384 void TCutG::SetObjectX(TObject *obj)
393 void TCutG::SetObjectY(TObject *obj)
402 void TCutG::SetVarX(
const char *varx)
412 void TCutG::SetVarY(
const char *vary)
422 void TCutG::Streamer(TBuffer &R__b)
424 if (R__b.IsReading()) {
425 R__b.ReadClassBuffer(TCutG::Class(),
this);
426 gROOT->GetListOfSpecials()->Add(
this);
428 R__b.WriteClassBuffer(TCutG::Class(),
this);