GRSISort
Created by P.C. Bender
Developement Team: P.C. Bender, R. Dunlop, V. Bildstein
An extension of the ROOT analysis Framework
TCalList.cxx
Go to the documentation of this file.
1 #include "TCalList.h"
2 #include "Globals.h"
3 
4 #include <iostream>
5 
6 /// \cond CLASSIMP
8 /// \endcond
9 
11  : TNamed()
12 {
13  Clear();
14 }
15 
16 TCalList::~TCalList() = default;
17 
18 TCalList::TCalList(const char* name, const char* title) : TNamed(name, title)
19 {
20  Clear();
21 }
22 
23 TCalList::TCalList(const TCalList& copy) : TNamed(copy)
24 {
25  copy.Copy(*this);
26 }
27 
28 void TCalList::Copy(TObject& obj) const
29 {
30  TNamed::Copy(obj);
31  static_cast<TCalList&>(obj).Clear();
32  for(auto it : fCalList) {
33  static_cast<TCalList&>(obj).AddPoint(it.second);
34  }
35 }
36 
37 void TCalList::AddPoint(const TCalPoint& point)
38 {
39  AddPoint(std::floor(point.Centroid()), point);
40 }
41 
42 void TCalList::AddPoint(const UInt_t& idx, const TCalPoint& point)
43 {
44  fCalList.insert(std::make_pair(idx, point));
45 }
46 
47 bool TCalList::SetPointIndex(const UInt_t& old_idx, const UInt_t& new_idx)
48 {
49  auto it = fCalList.find(old_idx);
50  if(it != fCalList.end()) {
51  // This means we found the old index! no go ahead and save the pair
52  TCalPoint sav_pt = it->second;
53  // delete the old pair
54  fCalList.erase(it);
55  // insert the new pair
56  fCalList.insert(std::make_pair(new_idx, sav_pt));
57  return true;
58  }
59  // didn't find it, return false
60  return false;
61 }
62 
63 void TCalList::Print(Option_t*) const
64 {
65  int idx = 0;
66  std::cout<<GetName()<<" "<<GetTitle()<<std::endl;
67  for(auto it : fCalList) {
68  std::cout<<idx++<<" "<<it.first<<std::endl;
69  it.second.Print();
70  }
71 }
72 
73 void TCalList::Clear(Option_t*)
74 {
75  fCalList.clear();
76 }
77 
78 void TCalList::FillGraph(TGraph* graph) const
79 {
80  graph->Clear();
81  Int_t i = 0;
82  TGraphErrors* ge = static_cast<TGraphErrors*>(graph);
83 
84  for(auto it : fCalList) {
85  graph->SetPoint(i, it.second.Centroid(), it.second.Area());
86  if(ge != nullptr) {
87  ge->SetPointError(i++, it.second.CentroidErr(), it.second.AreaErr());
88  }
89  }
90 }
bool SetPointIndex(const UInt_t &old_idx, const UInt_t &new_idx)
Definition: TCalList.cxx:47
void Print(Option_t *opt="") const override
Definition: TCalList.cxx:63
void Copy(TObject &obj) const override
Definition: TCalList.cxx:28
TCalList()
Definition: TCalList.cxx:10
void FillGraph(TGraph *graph) const
Definition: TCalList.cxx:78
~TCalList() override
void Clear(Option_t *opt="") override
Definition: TCalList.cxx:73
Double_t Centroid() const
Definition: TCalPoint.h:32
ClassImp(TGRSIMnemonic) void TGRSIMnemonic
void AddPoint(const TCalPoint &point)
Definition: TCalList.cxx:37
std::map< UInt_t, TCalPoint > fCalList
Definition: TCalList.h:36