GRSISort "v4.0.0.5"
An extension of the ROOT analysis Framework
Loading...
Searching...
No Matches
GH1D.cxx
Go to the documentation of this file.
1#include "GH1D.h"
2
3#include <iostream>
4#include <fstream>
5#include <cstring>
6
7#include "TVirtualPad.h"
8#include "TString.h"
9#include "TF1.h"
10#include "TFrame.h"
11//#include "TROOT.h"
12//#include "TSystem.h"
13#include "KeySymbols.h"
14#include "TVirtualX.h"
15
16#include "Globals.h"
17#include "GRootCommands.h"
18#include "GCanvas.h"
19#include "GH2I.h"
20#include "GH2D.h"
21
23
24GH1D::GH1D(const TH1& source) : fParent(nullptr), fProjectionAxis(-1)
25{
26 source.Copy(*this);
27}
28
29GH1D::GH1D(const TH1* source) : fParent(nullptr), fProjectionAxis(-1)
30{
31 source->Copy(*this);
32}
33
34GH1D::GH1D(const TF1& function, Int_t nbinsx, Double_t xlow, Double_t xup)
35 : TH1D(Form("%s_hist", function.GetName()), Form("%s_hist", function.GetName()), nbinsx, xlow, xup), fParent(nullptr),
36 fProjectionAxis(-1)
37{
38 for(int i = 0; i < nbinsx; i++) {
39 Fill(GetBinCenter(i), function.Eval(i));
40 }
41}
42
43bool GH1D::WriteDatFile(const char* outFile)
44{
45 if(strlen(outFile) < 1) {
46 return false;
47 }
48
49 std::ofstream out;
50 out.open(outFile);
51
52 if(!(out.is_open())) {
53 return false;
54 }
55
56 for(int i = 0; i < GetNbinsX(); i++) {
57 out << GetXaxis()->GetBinCenter(i) << "\t" << GetBinContent(i) << std::endl;
58 }
59 out << std::endl;
60 out.close();
61
62 return true;
63}
64
65/*
66GH1D::GH1D(const TH1 *source)
67 : fParent(nullptr), fProjectionAxis(-1) {
68 if(source->GetDiminsion()>1) {
69 return;
70 }
71
72 // Can copy from any 1-d TH1, not just a TH1D
73 source->Copy(*this);
74
75 // Force a refresh of any parameters stored in the option string.
76 SetOption(GetOption());
77}
78
79void GH1D::SetOption(Option_t* opt) {
80 fOption = opt;
81
82 TString sopt = opt;
83 if(sopt.Index("axis:")) {
84 fProjectionAxis = 0;// TODO
85 }
86}
87*/
88
89void GH1D::Clear(Option_t* opt)
90{
91 TH1D::Clear(opt);
92 fParent = nullptr;
93}
94
95void GH1D::Print(Option_t* opt) const
96{
97 TH1D::Print(opt);
98 std::cout << "\tParent: " << fParent.GetObject() << std::endl;
99}
100
101void GH1D::Copy(TObject& obj) const
102{
103 TH1D::Copy(obj);
104
105 static_cast<GH1D&>(obj).fParent = fParent;
106}
107
108void GH1D::Draw(Option_t* opt)
109{
110 TString option(opt);
111 if(option.Contains("new", TString::kIgnoreCase)) {
112 option.ReplaceAll("new", "");
113 new GCanvas;
114 }
115 TH1D::Draw(option.Data());
116 DrawRegions(opt);
117 if(gPad != nullptr) {
118 gPad->Update();
119 gPad->GetFrame()->SetBit(TBox::kCannotMove);
120 SetPad(gPad);
121 }
122}
123
124TH1* GH1D::DrawCopy(Option_t* opt, const char* name_postfix) const
125{
126 TH1* hist = TH1D::DrawCopy(opt, name_postfix);
127 if(gPad != nullptr) {
128 gPad->Update();
129 gPad->GetFrame()->SetBit(TBox::kCannotMove);
130 }
131 return hist;
132}
133
134TH1* GH1D::DrawNormalized(Option_t* opt, Double_t norm) const
135{
136 TH1* hist = TH1D::DrawNormalized(opt, norm);
137 if(gPad != nullptr) {
138 gPad->Update();
139 gPad->GetFrame()->SetBit(TBox::kCannotMove);
140 }
141 return hist;
142}
143
144GH1D* GH1D::GetPrevious(bool DrawEmpty) const
145{
146 if((fParent.GetObject() != nullptr) && fParent.GetObject()->InheritsFrom(GH2Base::Class())) {
147 GH2D* gpar = static_cast<GH2D*>(fParent.GetObject());
148 int first = GetXaxis()->GetFirst();
149 int last = GetXaxis()->GetLast();
150 GH1D* prev = gpar->GetPrevious(this, DrawEmpty);
151 prev->GetXaxis()->SetRange(first, last);
152 return prev; // gpar->GetPrevious(this,DrawEmpty);
153 }
154 return nullptr;
155}
156
157GH1D* GH1D::GetNext(bool DrawEmpty) const
158{
159 if((fParent.GetObject() != nullptr) && fParent.GetObject()->InheritsFrom(GH2Base::Class())) {
160 GH2D* gpar = static_cast<GH2D*>(fParent.GetObject());
161 int first = GetXaxis()->GetFirst();
162 int last = GetXaxis()->GetLast();
163 GH1D* next = gpar->GetNext(this, DrawEmpty);
164 next->GetXaxis()->SetRange(first, last);
165 return next; // gpar->GetNext(this,DrawEmpty);
166 }
167 return nullptr;
168}
169
170GH1D* GH1D::Project(double value_low, double value_high) const
171{
172
173 if((fParent.GetObject() != nullptr) && fParent.GetObject()->InheritsFrom(GH2Base::Class()) && fProjectionAxis != -1) {
174 if(value_low > value_high) {
175 std::swap(value_low, value_high);
176 }
177 GH2D* gpar = static_cast<GH2D*>(fParent.GetObject());
178 if(fProjectionAxis == 0) {
179 int bin_low = gpar->GetXaxis()->FindBin(value_low);
180 int bin_high = gpar->GetXaxis()->FindBin(value_high);
181 return gpar->ProjectionY("_py", bin_low, bin_high);
182 }
183 int bin_low = gpar->GetYaxis()->FindBin(value_low);
184 int bin_high = gpar->GetYaxis()->FindBin(value_high);
185 return gpar->ProjectionX("_px", bin_low, bin_high);
186 }
187 return nullptr;
188}
189
190GH1D* GH1D::Project_Background(double value_low, double value_high, double bg_value_low, double bg_value_high,
191 EBackgroundSubtraction mode) const
192{
193 if((fParent.GetObject() != nullptr) && fParent.GetObject()->InheritsFrom(GH2Base::Class()) && fProjectionAxis != -1) {
194 if(value_low > value_high) {
195 std::swap(value_low, value_high);
196 }
197 if(bg_value_low > bg_value_high) {
198 std::swap(bg_value_low, bg_value_high);
199 }
200
201 GH2D* gpar = static_cast<GH2D*>(fParent.GetObject());
202 if(fProjectionAxis == 0) {
203 int bin_low = gpar->GetXaxis()->FindBin(value_low);
204 int bin_high = gpar->GetXaxis()->FindBin(value_high);
205 int bg_bin_low = gpar->GetXaxis()->FindBin(bg_value_low);
206 int bg_bin_high = gpar->GetXaxis()->FindBin(bg_value_high);
207
208 return gpar->ProjectionY_Background(bin_low, bin_high, bg_bin_low, bg_bin_high, mode);
209 }
210 int bin_low = gpar->GetYaxis()->FindBin(value_low);
211 int bin_high = gpar->GetYaxis()->FindBin(value_high);
212 int bg_bin_low = gpar->GetYaxis()->FindBin(bg_value_low);
213 int bg_bin_high = gpar->GetYaxis()->FindBin(bg_value_high);
214
215 return gpar->ProjectionX_Background(bin_low, bin_high, bg_bin_low, bg_bin_high, mode);
216 }
217 return nullptr;
218}
219
221{
222 GH1D* proj = nullptr;
223 double ymax = GetMinimum();
224 double ymin = GetMaximum();
225 if(bins == -1) {
226 bins = static_cast<int>(std::abs(ymax - ymin));
227 if(bins < 1) {
228 bins = 100;
229 }
230 }
231 proj = new GH1D(Form("%s_y_axis_projection", GetName()), Form("%s_y_axis_projection", GetName()), bins, ymin, ymax);
232 for(int i = 0; i < GetNbinsX(); i++) {
233 if(GetBinContent(i) != 0) {
234 proj->Fill(GetBinContent(i));
235 }
236 }
237
238 return proj;
239}
240
241void GH1D::SetPad(TVirtualPad* pad)
242{
243 fPad = pad;
244 fPad->GetCanvas()->Connect("ProcessedEvent(Int_t, Int_t, Int_t, TObject*)", "GH1D", this, "HandleMovement(Int_t,Int_t,Int_t, TObject*)");
245 gClient->Connect("ProcessedEvent(Event_t*, Window_t)", "GH1D", this, "HandleEvent(Event_t*, Window_t)");
246}
247
248void GH1D::HandleMovement(Int_t eventType, Int_t eventX, Int_t eventY, TObject* selected)
249{
250 double currentX = fPad->PixeltoX(eventX);
251 double currentY = fPad->PixeltoY(eventY - fPad->GetWh());
252
253 if(selected != nullptr && selected->InheritsFrom(TRegion::Class())) {
254 auto* region = static_cast<TRegion*>(selected);
255 if(eventType == kKeyPress && eventX == kKey_d) {
256 RemoveRegion(region);
257 } else if(eventType == kButton1Down) {
258 fStartX = currentX;
259 fStartY = currentY;
261 std::cout << "button 1 down at " << currentX << ", " << currentY << std::endl;
262 }
263 } else if(eventType == kButton1Motion) {
265 std::cout << "button 1 motion at " << currentX << ", " << currentY << std::endl;
266 }
267 } else if(eventType == kButton1Up) {
268 region->Update(fStartX, currentX);
270 std::cout << "button 1 up at " << currentX << ", " << currentY << std::endl;
271 }
272 }
273 } else if(VerboseLevel() > EVerbosity::kLoops) {
274 std::cout << "nullptr selected at " << currentX << ", " << currentY << std::endl;
275 }
276}
277
278void GH1D::HandleEvent(Event_t* event, Window_t window)
279{
280 //auto* tgWindow = gClient->GetWindowById(window);
281
282 if(gPad != fPad && VerboseLevel() < EVerbosity::kAll) {
283 return;
284 }
285
286 if((VerboseLevel() > EVerbosity::kBasicFlow && event->fType != kMotionNotify && event->fType != kLeaveNotify) ||
287 (VerboseLevel() > EVerbosity::kSubroutines && event->fState != 0) ||
289 std::cout << __PRETTY_FUNCTION__ << ", event " << event << ", window " << window << ", type " << event->fType << ", code " << event->fCode << ", state " << event->fState << ", x " << event->fX << ", root-x " << event->fXRoot << ", y " << event->fY << ", root-y " << event->fYRoot << ", x/y coordinates: x " << fPad->PixeltoX(event->fX) << ", y " << fPad->PixeltoY(event->fY - fPad->GetWh()) << ", root-x " << fPad->PixeltoX(event->fXRoot) << ", root-y " << fPad->PixeltoY(event->fYRoot - fPad->GetWh()) << "; fPad " << fPad << " = \"" << fPad->GetName() << "\", gPad " << gPad << " = \"" << gPad->GetName() << "\"" << std::endl; // NOLINT(cppcoreguidelines-pro-type-const-cast, cppcoreguidelines-pro-bounds-array-to-pointer-decay)
290 }
291
292 switch(event->fType) {
293 case kGKeyPress: // if a key is held, this one gets repeated
294 {
295 UInt_t keySymbol = 0;
296 std::array<char, 2> str;
297 gVirtualX->LookupString(event, str.data(), str.size(), keySymbol);
298
299 if((VerboseLevel() > EVerbosity::kBasicFlow && event->fType != kMotionNotify && event->fType != kLeaveNotify) ||
300 (VerboseLevel() > EVerbosity::kSubroutines && event->fState != 0) ||
302 std::cout << "key symbol " << keySymbol << " = " << hex(keySymbol) << std::endl; // NOLINT(cppcoreguidelines-pro-type-const-cast, cppcoreguidelines-pro-bounds-array-to-pointer-decay)
303 }
304
305 if(str[0] == kESC) { // ESC sets the escape flag
306 gROOT->SetEscape();
307 gPad->Modified();
308 }
309 if(str[0] == 3) { // ctrl-c sets the interrupt flag
310 gROOT->SetInterrupt();
311 }
312
313 switch(keySymbol) {
314 case kKey_b:
315 fBackground = true;
316 break;
317 case kKey_g:
318 fGate = true;
319 break;
320 case kKey_r:
321 fRegion = true;
322 break;
323 case kKey_l:
324 // toggle logscale for y
325 if(fPad->GetLogy() == 0) {
326 fPad->SetLogy(1);
327 } else {
328 fPad->SetLogy(0);
329 }
330 // we need to update the pad to get the new frame the histogram is draw in, then update it again after the regions have been re-drawn ...
331 UpdatePad();
332 DrawRegions();
333 UpdatePad();
334 break;
335 case kKey_p:
336 //f2DPlayer->Project();
337 break;
338 case kKey_u:
339 GetXaxis()->UnZoom();
340 GetYaxis()->UnZoom();
341 // we need to update the pad to get the new frame the histogram is draw in, then update it again after the regions have been re-drawn ...
342 UpdatePad();
343 DrawRegions();
344 UpdatePad();
346 PrintRegions();
347 }
348 break;
349 case kKey_U:
350 GetYaxis()->UnZoom();
351 // we need to update the pad to get the new frame the histogram is draw in, then update it again after the regions have been updated ...
352 UpdatePad();
353 DrawRegions();
354 UpdatePad();
356 PrintRegions();
357 }
358 break;
359 case kKey_Escape:
360 if(fGate || fBackground || fRegion) {
362 }
364 std::cout << "Escape!" << std::endl;
365 }
366 break;
367 case kKey_Left:
368 case kKey_Up:
369 case kKey_Right:
370 case kKey_Down:
371 // handle arrow keys
373 std::cout << "Moving histogram" << std::endl;
374 }
375 Move1DHistogram(keySymbol, this);
376 // we need to update the pad to get the new frame the histogram is draw in, then update it again after the regions have been updated ...
377 UpdatePad();
378 DrawRegions();
379 UpdatePad();
381 PrintRegions();
382 }
383 break;
384 }
385 } break;
386 case kKeyRelease:
387 break;
388 case kButtonPress:
389 switch(event->fCode) {
390 case 1:
391 if(event->fState == 0 && (fGate || fBackground || fRegion)) {
392 fStartX = fPad->PixeltoX(event->fX);
393 fStartY = fPad->PixeltoY(event->fY - fPad->GetWh());
395 if(fGate) {
396 fCurrentRegion->SetFillColorAlpha(kRed, 0.2);
397 } else if(fBackground) {
398 fCurrentRegion->SetFillColorAlpha(kBlue, 0.2);
399 } else if(fRegion) {
400 fCurrentRegion->SetFillColorAlpha(fRegionColor[fNofRegions % fRegionColor.size()], 0.2);
401 }
402 fCurrentRegion->Draw();
404 PrintRegions();
405 }
406 }
407 break;
408 case 4:
409 case 5:
410 // code 4 & 5 are wheel down & up, respectively
411 // state 0 - no key, 1 - shift, 4 - control, 8 - option, 16 - command
412 if(event->fState == 0) {
413 // we want to increase/reduce our range by 10% w/o changing the minimum
414 // for wheel down/up, respectively
415 double factor = 0.90;
416 if(event->fCode == 4) {
417 factor = 1.10;
418 }
420 std::cout << "factor " << factor << ": maximum " << GetMinimum() + (GetMaximum() - GetMinimum()) * factor << ", old range " << (GetMaximum() - GetMinimum()) << " = " << GetMaximum() << " - " << GetMinimum() << std::endl;
421 }
422 SetMaximum(GetMinimum() + (GetMaximum() - GetMinimum()) * factor);
424 std::cout << "new range: " << (GetMaximum() - GetMinimum()) << " = " << GetMaximum() << " - " << GetMinimum() << std::endl;
425 }
426 } else if(event->fState == 1) {
427 if(event->fCode == 4) {
428 Move1DHistogram(kKey_Left, this);
429 } else {
430 Move1DHistogram(kKey_Right, this);
431 }
432 }
433 // we need to update the pad to get the new frame the histogram is draw in, then update it again after the regions have been updated ...
434 UpdatePad();
435 DrawRegions();
436 UpdatePad();
438 PrintRegions();
439 }
440 break;
441 default:
442 break;
443 }
444 break;
445 case kMotionNotify:
446 if(event->fState == 256 && (fGate || fBackground || fRegion)) {
447 double currentX = fPad->PixeltoX(event->fX);
448 double currentY = fPad->PixeltoY(event->fY - fPad->GetWh());
450 std::cout << "current box: " << fStartX << " - " << fStartY << ", " << currentX << " - " << currentY << ", canvas: " << fPad->PixeltoX(fPad->GetCanvas()->GetEventX()) << " - " << fPad->PixeltoY(fPad->GetCanvas()->GetEventY()) << std::endl;
451 }
452 fCurrentRegion->SetX2(currentX);
453 fCurrentRegion->SetY2(currentY);
454 fCurrentRegion->Draw();
455 UpdatePad();
457 PrintRegions();
458 }
459 }
460 break;
461 case kButtonRelease:
462 if(event->fCode == 1) {
463 if(event->fState == 0) {
464 if(!fGate && !fBackground && !fRegion) {
465 // check whether we are in the frame or not
466 double currentX = fPad->PixeltoX(event->fX);
467 double currentY = fPad->PixeltoY(event->fY - fPad->GetWh());
468 if(VerboseLevel() > EVerbosity::kBasicFlow) { std::cout << "current x " << currentX << ", current y " << currentY << std::endl; }
469 if(Pad()->GetFrame()->GetX1() < currentX && currentX < Pad()->GetFrame()->GetX2() &&
470 Pad()->GetFrame()->GetY1() < currentY && currentY < Pad()->GetFrame()->GetY2()) {
472 std::cout << "inside frame" << std::endl;
473 }
474 } else {
475 // not a new gate, background, or region, and we're outside the frame => we just zoomed in on the x-axis
476 GetYaxis()->UnZoom();
478 std::cout << "outside frame" << std::endl;
479 }
480 }
481 // we need to update the pad to get the new frame the histogram is draw in, then update it again after the regions have been updated ...
482 UpdatePad();
483 DrawRegions();
484 UpdatePad();
486 PrintRegions();
487 }
488 } else {
489 double stopX = fPad->PixeltoX(event->fX);
490 double stopY = fPad->PixeltoY(event->fY - fPad->GetWh());
491 fCurrentRegion->SetX2(stopX);
492 fCurrentRegion->SetY2(stopY);
493 if(fGate) {
495 std::cout << "new gate: " << fStartX << " - " << stopX << std::endl;
496 }
498 fGate = false;
499 } else if(fBackground) {
501 std::cout << "new background: " << fStartX << " - " << stopX << std::endl;
502 }
504 fBackground = false;
505 } else if(fRegion) {
507 std::cout << "new region: " << fStartX << " - " << stopX << std::endl;
508 }
510 fRegion = false;
511 ++fNofRegions;
512 }
514 static_cast<TRegion*>(fRegions.Last())->Draw();
516 PrintRegions();
517 }
518 }
519 }
520 }
521 break;
522 default:
523 break;
524 }
525}
526
528{
529 for(auto* obj : fRegions) {
530 static_cast<TRegion*>(obj)->Update();
531 }
532}
533
534void GH1D::DrawRegions(Option_t* opt)
535{
536 for(auto* obj : fRegions) {
537 static_cast<TRegion*>(obj)->Draw(opt);
538 }
539}
540
542{
543 std::cout << GetName() << "/" << GetTitle() << " - Regions:" << std::endl;
544 int index = 0;
545 for(auto* obj : *(Pad()->GetListOfPrimitives())) {
546 if(obj->InheritsFrom(TRegion::Class())) {
547 std::cout << index << ": " << obj << " ";
548 obj->Print();
549 ++index;
550 }
551 }
552}
553
555{
556 fGate = false;
557 fBackground = false;
558 fRegion = false;
559 fPad->GetListOfPrimitives()->Remove(fCurrentRegion);
560 delete fCurrentRegion;
561 fCurrentRegion = nullptr;
562}
563
565{
566 fPad->GetListOfPrimitives()->Remove(region);
567 fRegions.Remove(region);
568}
569
570TRegion::TRegion(TBox* box, ERegionType type, GH1D* parent)
571 : TBox(*box), fParent(parent), fType(type), fLowX(box->GetX1()), fHighX(box->GetX2())
572{
573 // make sure that x1 is smaller than x2
574 if(GetX1() > GetX2()) {
575 double tmpX = GetX1();
576 SetX1(GetX2());
577 SetX2(tmpX);
578 std::swap(fLowX, fHighX);
579 }
580 // align the edges of the region with the bins of the histogram
581 auto* axis = parent->GetXaxis();
582 fLowX = axis->GetBinLowEdge(axis->FindBin(fLowX));
583 fHighX = axis->GetBinUpEdge(axis->FindBin(fHighX));
584}
585
587{
588 /// Updates y-range of this region to match the current y-range of the frame the parent is drawn in.
589 /// Also checks the x-range and adjust it to only cover the displayed range if necessary.
590 /// Returns whether the region should be drawn or not.
591 /// Does not update the pad itself!
592
593 bool result = true;
594
595 auto* frame = fParent->Pad()->GetFrame();
597 std::cout << "Frame: " << frame->GetX1() << " - " << frame->GetX2() << ", " << frame->GetY1() << " - " << frame->GetY2() << " -> updating y-range from " << GetY1() << " - " << GetY2();
598 }
599 if(fParent->Pad()->GetLogy() == 0) {
600 // linear scale: set y-range directly from frame
601 SetY1(frame->GetY1());
602 SetY2(frame->GetY2());
603 } else {
604 // logarithmic scale: frame reports the exponent as y1 and y2
605 SetY1(TMath::Power(10., frame->GetY1()));
606 SetY2(TMath::Power(10., frame->GetY2()));
607 }
609 std::cout << " to " << GetY1() << " - " << GetY2() << std::endl;
610 }
611
613 std::cout << "Updating x-range from " << GetX1() << " - " << GetX2() << " (" << fLowX << " - " << fHighX << ")";
614 }
615 if(frame->GetX1() < fLowX && fHighX < frame->GetX2()) {
616 // whole region is visible -> use original range
618 std::cout << " (whole region)";
619 }
620 SetX1(fLowX);
621 SetX2(fHighX);
622 } else if(frame->GetX2() < fLowX || fHighX < frame->GetX1()) {
623 // region is out of frame, do nothing? What if the region is just out of the frame but in the canvas?
624 // Using GetUxmin() and GetUxmax() to set range to values outside the pad range and not just the frame range does not work.
625 // So we simply hide this region whenever it is outside the frame.
626 // This also means we have to actively draw it whenever it is (partly) in frame (in case it was hidden before).
628 std::cout << " (out of " << frame->GetX1() << " - " << frame->GetX2() << ")";
629 }
630 result = false;
631 } else if(fHighX < frame->GetX2()) {
632 // low part of region is out of frame -> adjust low x
634 std::cout << " (high part)";
635 }
636 SetX1(frame->GetX1());
637 SetX2(fHighX);
638 } else if(frame->GetX1() < fLowX) {
639 // high part of region is out of frame -> adjust high x
641 std::cout << " (low part)";
642 }
643 SetX1(fLowX);
644 SetX2(frame->GetX2());
645 } else {
646 // region is larger than visible range on both side -> adjust both
648 std::cout << " (region too big)";
649 }
650 SetX1(frame->GetX1());
651 SetX2(frame->GetX2());
652 }
654 std::cout << " to " << GetX1() << " - " << GetX2() << std::endl;
655 }
656
657 return result;
658}
659
660void TRegion::Draw(Option_t* opt)
661{
662 /// Draw this region. Calls Update() first to update ranges and to check if we actuall want to draw this range.
663 /// If Update() returns false this function will actually hide this region!
664 /// Updates the pad at the end.
665 if(fParent == nullptr) {
666 throw std::runtime_error("Can't draw region without parent histogram!");
667 }
668
669 if(Update()) {
670 if(fParent->Pad()->GetListOfPrimitives()->FindObject(this) == nullptr) {
671 TBox::Draw(opt);
673 std::cout << this << " region " << fLowX << " - " << fHighX << " already has been drawn" << std::endl;
674 }
675 } else {
676 Hide();
677 }
679}
680
682{
683 /// Hide this region. Removes region from list of primitives. Does not update the pad.
684 if(fParent == nullptr) {
685 throw std::runtime_error("Can't draw region without parent histogram!");
686 }
687
688 fParent->Pad()->GetListOfPrimitives()->Remove(this);
690 std::cout << "hid region " << fLowX << " - " << fHighX << std::endl;
692 }
693}
694
695void TRegion::Update(double startX, double stopX)
696{
697 /// Depending on the starting position this function updates the left or right edge of the region to the stopping position.
699 std::cout << "region " << fLowX << " - " << fHighX << ", start x " << startX << ", stop x " << stopX;
700 }
701 if(std::abs(startX - fLowX) < std::abs(startX - fHighX)) {
702 fLowX = stopX;
703 } else {
704 fHighX = stopX;
705 }
707 std::cout << " => " << fLowX << " - " << fHighX << std::endl;
708 }
709 Update();
710}
ERegionType
Definition GH1D.h:111
EBackgroundSubtraction
Definition GH2Base.h:14
bool Move1DHistogram(const Int_t &key, TH1 *histogram=nullptr)
EVerbosity
Definition Globals.h:143
@ kQuiet
Definition Globals.h:144
@ kSubroutines
Definition Globals.h:146
@ kLoops
Definition Globals.h:147
@ kAll
Definition Globals.h:148
@ kBasicFlow
Definition Globals.h:145
std::string hex(T val, int width=-1)
Definition Globals.h:129
TH1D * hist
Definition UserFillObj.h:3
Definition GH1D.h:17
double fStartX
! initial x-position of new region
Definition GH1D.h:94
GH1D * Project_Background(double value_low, double value_high, double bg_value_low, double bg_value_high, EBackgroundSubtraction mode=EBackgroundSubtraction::kRegionBackground) const
Definition GH1D.cxx:190
TVirtualPad * Pad() const
Definition GH1D.h:67
void SetPad(TVirtualPad *pad)
Definition GH1D.cxx:241
void DrawRegions(Option_t *opt="")
Definition GH1D.cxx:534
std::array< int, 3 > fRegionColor
Definition GH1D.h:100
TH1 * DrawNormalized(Option_t *opt="", Double_t norm=1) const override
Definition GH1D.cxx:134
void UpdatePad()
Definition GH1D.h:75
void HandleMovement(Int_t eventType, Int_t eventX, Int_t eventY, TObject *selected)
Definition GH1D.cxx:248
void PrintRegions()
Definition GH1D.cxx:541
void RemoveCurrentRegion()
Definition GH1D.cxx:554
bool fGate
Definition GH1D.h:96
double fStartY
! initial y-position of new region
Definition GH1D.h:95
GH1D * GetNext(bool DrawEmpty=false) const
Definition GH1D.cxx:157
TRef fParent
Definition GH1D.h:90
static EVerbosity fVerboseLevel
! level of verbosity
Definition GH1D.h:104
void Copy(TObject &obj) const override
Definition GH1D.cxx:101
size_t fNofRegions
! counts number of regions in this histogram, only used to set the color of the region
Definition GH1D.h:101
void Print(Option_t *opt="") const override
Definition GH1D.cxx:95
bool WriteDatFile(const char *outFile)
Definition GH1D.cxx:43
void Clear(Option_t *opt="") override
Definition GH1D.cxx:89
TBox * fCurrentRegion
! box for the current region
Definition GH1D.h:99
GH1D * GetPrevious(bool DrawEmpty=false) const
Definition GH1D.cxx:144
static EVerbosity VerboseLevel()
Definition GH1D.h:85
void HandleEvent(Event_t *event, Window_t window)
Definition GH1D.cxx:278
void UpdateRegions()
Definition GH1D.cxx:527
GH1D * Project(int bins=-1)
Definition GH1D.cxx:220
int fProjectionAxis
Definition GH1D.h:91
bool fRegion
Definition GH1D.h:98
TH1 * DrawCopy(Option_t *opt="", const char *name_postfix="copy") const override
Definition GH1D.cxx:124
TList fRegions
Definition GH1D.h:102
TVirtualPad * fPad
!
Definition GH1D.h:92
GH1D()
Definition GH1D.h:19
void RemoveRegion(TRegion *region)
Definition GH1D.cxx:564
bool fBackground
Definition GH1D.h:97
void Draw(Option_t *opt="") override
Definition GH1D.cxx:108
GH1D * GetPrevious(const GH1D *curr, bool DrawEmpty=true)
Definition GH2Base.cxx:198
GH1D * ProjectionY_Background(int firstbin=0, int lastbin=-1, int first_bg_bin=0, int last_bg_bin=-1, EBackgroundSubtraction mode=EBackgroundSubtraction::kRegionBackground)
Definition GH2Base.cxx:192
GH1D * GetNext(const GH1D *curr, bool DrawEmpty=true)
Definition GH2Base.cxx:221
GH1D * ProjectionX_Background(int firstbin=0, int lastbin=-1, int first_bg_bin=0, int last_bg_bin=-1, EBackgroundSubtraction mode=EBackgroundSubtraction::kRegionBackground)
Definition GH2Base.cxx:138
Definition GH2D.h:18
GH1D * ProjectionX(const char *name="_px", int firstbin=0, int lastbin=-1, Option_t *option="")
Definition GH2D.cxx:114
GH1D * ProjectionY(const char *name="_py", int firstbin=0, int lastbin=-1, Option_t *option="")
Definition GH2D.cxx:119
void Draw(Option_t *opt="") override
Definition GH1D.cxx:660
void Hide()
Definition GH1D.cxx:681
TRegion()=default
GH1D * fParent
Definition GH1D.h:133
double fHighX
Definition GH1D.h:136
bool Update()
Definition GH1D.cxx:586
double fLowX
Definition GH1D.h:135