KaliVeda
Toolkit for HIC analysis
KVIDGrid.h
1 /***************************************************************************
2  KVIDGrid.h - description
3  -------------------
4  begin : Nov 10 2004
5  copyright : (C) 2004 by J.D. Frankland
6  email : frankland@ganil.fr
7 
8 $Id: KVIDGrid.h,v 1.51 2009/04/03 14:30:27 franklan Exp $
9 ***************************************************************************/
10 
11 #ifndef KVIDGrid_H
12 #define KVIDGrid_H
13 
14 #include "KVIDGraph.h"
15 #include "KVIDLine.h"
16 #include "Riostream.h"
17 #include "TObjArray.h"
18 #include <TPad.h>
19 #include "TGWindow.h"
20 #include "TF1.h"
21 #include "TClass.h"
22 #include "TMath.h"
23 
74 class KVIDGrid : public KVIDGraph {
75 
77 
78 protected:
79 
80  void init();
81  void ReadIdentifierFromAsciiFile(TString& name, TString& type, TString& cl, std::ifstream& gridfile);
82 
83 public:
84 
85  KVIDGrid();
86  virtual ~ KVIDGrid();
87 
88  KVIDLine* NewLine(const Char_t* idline_class = "");
89  Int_t GetIDLinesEmbracingPoint(const Char_t* direction, Double_t x, Double_t y) const;
90 
92  Int_t& idx, Int_t& idx_min, Int_t& idx_max, Double_t& dist, Double_t& dist_min, Double_t& dist_max) const
93  {
123 
124  Int_t nlines = GetNumberOfIdentifiers();
125  idx_min = 0; //minimum index
126  idx_max = nlines - 1; // maximum index
127  idx = idx_max / 2; //current index i.e. we begin in the middle
128  dist = dist_min = dist_max = -1.;
129 
130  while (idx_max > idx_min + 1) {
131 
133  Bool_t point_above_line = line->WhereAmI(x, y, position);
134 
135  if (point_above_line) {
137  idx_min = idx;
138  idx += (Int_t)((idx_max - idx) / 2 + 0.5);
139  }
140  else {
142  idx_max = idx;
143  idx -= (Int_t)((idx - idx_min) / 2 + 0.5);
144  }
145  }
148  KVIDLine* upper = (KVIDLine*)GetIdentifierAt(idx_max);
149  KVIDLine* lower = (KVIDLine*)GetIdentifierAt(idx_min);
150  Int_t dummy = 0;
151  dist_max = TMath::Abs(upper->DistanceToLine(x, y, dummy));
152  dist_min = TMath::Abs(lower->DistanceToLine(x, y, dummy));
153  if (dist_max < dist_min) {
154  dist = dist_max;
155  idx = idx_max;
156  return upper;
157  }
158  dist = dist_min;
159  idx = idx_min;
160  return lower;
161  }
162 
163  KVIDLine* FindNearestEmbracingIDLine(Double_t x, Double_t y, const Char_t* position, const Char_t* axis,
164  Int_t& idx, Int_t& idx_min, Int_t& idx_max, Double_t& dist, Double_t& dist_min, Double_t& dist_max) const
165  {
170 
171  Int_t nlines = GetIDLinesEmbracingPoint(axis, x, y);
172  if (!nlines) return 0; // no lines
173  idx_min = 0; //minimum index
174  idx_max = nlines - 1; // maximum index
175  idx = idx_max / 2; //current index i.e. we begin in the middle
176  dist = dist_min = dist_max = -1.;
177 
178  while (idx_max > idx_min + 1) {
179 
181  Bool_t point_above_line = line->WhereAmI(x, y, position);
182 
183  if (point_above_line) {
185  idx_min = idx;
186  idx += (Int_t)((idx_max - idx) / 2 + 0.5);
187  }
188  else {
190  idx_max = idx;
191  idx -= (Int_t)((idx - idx_min) / 2 + 0.5);
192  }
193  }
195  KVIDLine* upper = (KVIDLine*)fEmbracingLines.UncheckedAt(idx_max);
196  KVIDLine* lower = (KVIDLine*)fEmbracingLines.UncheckedAt(idx_min);
197  Int_t dummy = 0;
200  if (idx_max == nlines - 1) {
201  if (upper->WhereAmI(x, y, position)) {
203  idx = idx_min = fIdentifiers.IndexOf(upper); // index of last line
204  idx_max = -1;
205  dist = dist_min = TMath::Abs(upper->DistanceToLine(x, y, dummy));
206  return upper;
207  }
208  }
211  if (idx_min == 0) {
212  if (!lower->WhereAmI(x, y, position)) {
214  idx_min = -1;
215  idx = idx_max = fIdentifiers.IndexOf(lower); // index of first line
216  dist = dist_max = TMath::Abs(lower->DistanceToLine(x, y, dummy));
217  return lower;
218  }
219  }
220 
221  dist_max = TMath::Abs(upper->DistanceToLine(x, y, dummy));
222  dist_min = TMath::Abs(lower->DistanceToLine(x, y, dummy));
224  idx_min = fIdentifiers.IndexOf(lower);
225  idx_max = fIdentifiers.IndexOf(upper);
226  if (dist_max < dist_min) {
227  dist = dist_max;
228  idx = idx_max;
229  return upper;
230  }
231  dist = dist_min;
232  idx = idx_min;
233  return lower;
234  }
235 
236  KVIDLine* FindNextEmbracingLine(Int_t& index, Int_t inc_index, Double_t x, Double_t y, const Char_t* axis) const
237  {
243 
244  Int_t ii = index + inc_index;
245  Int_t nlines = GetNumberOfIdentifiers();
246  KVIDLine* l = 0;
247  while ((ii > -1 && ii < nlines)) {
248  l = (KVIDLine*)GetIdentifierAt(ii);
249  if (l->IsBetweenEndPoints(x, y, axis)) break;
250  ii += inc_index;
251  }
252  if (ii < 0 || ii >= nlines) {
254  index = -1;
255  return 0;
256  }
257  index = ii;
258  return l;
259  }
260 
261 
262  void Initialize();
263 
264  virtual void CalculateLineWidths() {}
265 
267  {
268  return TClass::GetClass("KVIDLine");
269  }
271  {
272  return TClass::GetClass("KVIDLine");
273  }
274 
275 
276  ClassDef(KVIDGrid, 5) //Base class for 2D identification grids
277 };
278 
279 #endif
int Int_t
bool Bool_t
char Char_t
double Double_t
#define ClassDef(name, id)
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
Base class for particle identification in a 2D map.
Definition: KVIDGraph.h:32
KVList fIdentifiers
list of identification objects
Definition: KVIDGraph.h:40
Int_t GetNumberOfIdentifiers() const
Definition: KVIDGraph.h:328
KVIDentifier * GetIdentifierAt(Int_t index) const
Definition: KVIDGraph.h:271
Abstract base class for 2D identification grids in e.g. (dE,E) maps.
Definition: KVIDGrid.h:74
virtual TClass * DefaultIDLineClass()
Definition: KVIDGrid.h:266
virtual void CalculateLineWidths()
Definition: KVIDGrid.h:264
KVIDLine * FindNearestEmbracingIDLine(Double_t x, Double_t y, const Char_t *position, const Char_t *axis, Int_t &idx, Int_t &idx_min, Int_t &idx_max, Double_t &dist, Double_t &dist_min, Double_t &dist_max) const
Definition: KVIDGrid.h:163
KVIDGrid()
Default constructor.
Definition: KVIDGrid.cpp:46
KVIDLine * FindNextEmbracingLine(Int_t &index, Int_t inc_index, Double_t x, Double_t y, const Char_t *axis) const
Definition: KVIDGrid.h:236
virtual TClass * DefaultOKLineClass()
Definition: KVIDGrid.h:270
KVIDLine * FindNearestIDLineFast(Double_t x, Double_t y, const Char_t *position, Int_t &idx, Int_t &idx_min, Int_t &idx_max, Double_t &dist, Double_t &dist_min, Double_t &dist_max) const
Definition: KVIDGrid.h:91
void init()
Initialisations, used by constructors.
Definition: KVIDGrid.cpp:58
KVIDLine * NewLine(const Char_t *idline_class="")
Definition: KVIDGrid.cpp:90
Int_t GetIDLinesEmbracingPoint(const Char_t *direction, Double_t x, Double_t y) const
Definition: KVIDGrid.cpp:191
TObjArray fEmbracingLines
temporary array used by GetIDLinesEmbracingPoint
Definition: KVIDGrid.h:76
virtual ~ KVIDGrid()
void ReadIdentifierFromAsciiFile(TString &name, TString &type, TString &cl, std::ifstream &gridfile)
Definition: KVIDGrid.cpp:143
void Initialize()
Definition: KVIDGrid.cpp:218
Base class for lines/cuts used for particle identification in 2D data maps.
Definition: KVIDLine.h:143
Double_t DistanceToLine(Double_t px, Double_t py, Int_t &)
Definition: KVIDLine.h:246
Bool_t WhereAmI(Double_t px, Double_t py, Option_t *opt)
static TClass * GetClass(Bool_t load=kTRUE, Bool_t silent=kFALSE)
TObject * UncheckedAt(Int_t i) const
virtual Int_t IndexOf(const TObject *obj) const
TLine * line
Double_t y[n]
Double_t x[n]
double dist(AxisAngle const &r1, AxisAngle const &r2)
Double_t Abs(Double_t d)
TLine l