KaliVeda  1.12/06
Heavy-Ion Analysis Toolkit
KVIDGrid.h
Go to the documentation of this file.
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 
73 class KVIDGrid : public KVIDGraph {
74 
76 
77 protected:
78 
79  void init();
80  void ReadIdentifierFromAsciiFile(TString& name, TString& type, TString& cl, std::ifstream& gridfile);
81 
82 public:
83 
84  KVIDGrid();
85  virtual ~ KVIDGrid();
86 
87  KVIDLine* NewLine(const Char_t* idline_class = "");
88  Int_t GetIDLinesEmbracingPoint(const Char_t* direction, Double_t x, Double_t y) const;
89 
91  Int_t& idx, Int_t& idx_min, Int_t& idx_max, Double_t& dist, Double_t& dist_min, Double_t& dist_max) const
92  {
122 
123  Int_t nlines = GetNumberOfIdentifiers();
124  idx_min = 0; //minimum index
125  idx_max = nlines - 1; // maximum index
126  idx = idx_max / 2; //current index i.e. we begin in the middle
127  dist = dist_min = dist_max = -1.;
128 
129  while (idx_max > idx_min + 1) {
130 
132  Bool_t point_above_line = line->WhereAmI(x, y, position);
133 
134  if (point_above_line) {
136  idx_min = idx;
137  idx += (Int_t)((idx_max - idx) / 2 + 0.5);
138  }
139  else {
141  idx_max = idx;
142  idx -= (Int_t)((idx - idx_min) / 2 + 0.5);
143  }
144  }
147  KVIDLine* upper = (KVIDLine*)GetIdentifierAt(idx_max);
148  KVIDLine* lower = (KVIDLine*)GetIdentifierAt(idx_min);
149  Int_t dummy = 0;
150  dist_max = TMath::Abs(upper->DistanceToLine(x, y, dummy));
151  dist_min = TMath::Abs(lower->DistanceToLine(x, y, dummy));
152  if (dist_max < dist_min) {
153  dist = dist_max;
154  idx = idx_max;
155  return upper;
156  }
157  dist = dist_min;
158  idx = idx_min;
159  return lower;
160  }
161 
162  KVIDLine* FindNearestEmbracingIDLine(Double_t x, Double_t y, const Char_t* position, const Char_t* axis,
163  Int_t& idx, Int_t& idx_min, Int_t& idx_max, Double_t& dist, Double_t& dist_min, Double_t& dist_max) const
164  {
169 
170  Int_t nlines = GetIDLinesEmbracingPoint(axis, x, y);
171  if (!nlines) return 0; // no lines
172  idx_min = 0; //minimum index
173  idx_max = nlines - 1; // maximum index
174  idx = idx_max / 2; //current index i.e. we begin in the middle
175  dist = dist_min = dist_max = -1.;
176 
177  while (idx_max > idx_min + 1) {
178 
180  Bool_t point_above_line = line->WhereAmI(x, y, position);
181 
182  if (point_above_line) {
184  idx_min = idx;
185  idx += (Int_t)((idx_max - idx) / 2 + 0.5);
186  }
187  else {
189  idx_max = idx;
190  idx -= (Int_t)((idx - idx_min) / 2 + 0.5);
191  }
192  }
194  KVIDLine* upper = (KVIDLine*)fEmbracingLines.UncheckedAt(idx_max);
195  KVIDLine* lower = (KVIDLine*)fEmbracingLines.UncheckedAt(idx_min);
196  Int_t dummy = 0;
199  if (idx_max == nlines - 1) {
200  if (upper->WhereAmI(x, y, position)) {
202  idx = idx_min = fIdentifiers->IndexOf(upper); // index of last line
203  idx_max = -1;
204  dist = dist_min = TMath::Abs(upper->DistanceToLine(x, y, dummy));
205  return upper;
206  }
207  }
210  if (idx_min == 0) {
211  if (!lower->WhereAmI(x, y, position)) {
213  idx_min = -1;
214  idx = idx_max = fIdentifiers->IndexOf(lower); // index of first line
215  dist = dist_max = TMath::Abs(lower->DistanceToLine(x, y, dummy));
216  return lower;
217  }
218  }
219 
220  dist_max = TMath::Abs(upper->DistanceToLine(x, y, dummy));
221  dist_min = TMath::Abs(lower->DistanceToLine(x, y, dummy));
223  idx_min = fIdentifiers->IndexOf(lower);
224  idx_max = fIdentifiers->IndexOf(upper);
225  if (dist_max < dist_min) {
226  dist = dist_max;
227  idx = idx_max;
228  return upper;
229  }
230  dist = dist_min;
231  idx = idx_min;
232  return lower;
233  }
234 
235  KVIDLine* FindNextEmbracingLine(Int_t& index, Int_t inc_index, Double_t x, Double_t y, const Char_t* axis) const
236  {
242 
243  Int_t ii = index + inc_index;
244  Int_t nlines = GetNumberOfIdentifiers();
245  KVIDLine* l = 0;
246  while ((ii > -1 && ii < nlines)) {
247  l = (KVIDLine*)GetIdentifierAt(ii);
248  if (l->IsBetweenEndPoints(x, y, axis)) break;
249  ii += inc_index;
250  }
251  if (ii < 0 || ii >= nlines) {
253  index = -1;
254  return 0;
255  }
256  index = ii;
257  return l;
258  }
259 
260 
261  void Initialize();
262 
263  virtual void CalculateLineWidths() {}
264 
266  {
267  return TClass::GetClass("KVIDLine");
268  }
270  {
271  return TClass::GetClass("KVIDLine");
272  }
273 
274 
275  ClassDef(KVIDGrid, 5) //Base class for 2D identification grids
276 };
277 
278 #endif
int Int_t
char Char_t
bool Bool_t
double Double_t
#define ClassDef(name, id)
Base class for particle identification in a 2D map.
Definition: KVIDGraph.h:31
Int_t GetNumberOfIdentifiers() const
Definition: KVIDGraph.h:300
KVList * fIdentifiers
list of identification objects
Definition: KVIDGraph.h:39
KVIDentifier * GetIdentifierAt(Int_t index) const
Definition: KVIDGraph.h:263
Abstract base class for 2D identification grids in e.g. (dE,E) maps.
Definition: KVIDGrid.h:73
virtual TClass * DefaultIDLineClass()
Definition: KVIDGrid.h:265
virtual void CalculateLineWidths()
Definition: KVIDGrid.h:263
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:162
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:235
virtual TClass * DefaultOKLineClass()
Definition: KVIDGrid.h:269
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:90
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:75
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:178
Bool_t WhereAmI(Double_t px, Double_t py, Option_t *opt)
Definition: KVIDLine.h:348
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]
const long double cl
Definition: KVUnits.h:85
double dist(AxisAngle const &r1, AxisAngle const &r2)
Double_t Abs(Double_t d)
auto * l