KaliVeda  1.13/01
Heavy-Ion Analysis Toolkit
KVIDGrid.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  KVIDGrid.cpp - description
3  -------------------
4  begin : Nov 10 2004
5  copyright : (C) 2004 by J.D. Frankland
6  email : frankland@ganil.fr
7 
8 $Id: KVIDGrid.cpp,v 1.60 2009/05/05 15:57:52 franklan Exp $
9 ***************************************************************************/
10 
11 /***************************************************************************
12  * *
13  * This program is free software; you can redistribute it and/or modify *
14  * it under the terms of the GNU General Public License as published by *
15  * the Free Software Foundation; either version 2 of the License, or *
16  * (at your option) any later version. *
17  * *
18  ***************************************************************************/
19 
20 #include "KVIDGrid.h"
21 #include "TCanvas.h"
22 #include "TObjString.h"
23 #include "Riostream.h"
24 #include "TObjArray.h"
25 #include "TROOT.h"
26 #include "KVString.h"
27 #include "TVirtualFitter.h"
28 #include "TClass.h"
29 #include "TContextMenu.h"
30 #include "TSystem.h"
31 #include "TF1.h"
32 #include "KVIDZALine.h"
33 #include "KVIDCutLine.h"
34 
35 
36 using namespace std;
37 
39 
40 //________________________________________________________________________________
41 
42 
43 
47 {
48  //Default constructor
49  init();
50 }
51 
52 
53 
54 
57 
59 {
60  //Initialisations, used by constructors
61 }
62 
63 
64 
65 
67 
68 KVIDGrid::~KVIDGrid()
69 {
70 }
71 
72 
73 
74 
89 
90 KVIDLine* KVIDGrid::NewLine(const Char_t* idline_class)
91 {
92  // Create a new line compatible with this grid.
93  //
94  // If idline_class = "id" or "ID":
95  // create default identification line object for this grid
96  //
97  // If idline_class = "ok" or "OK":
98  // create default 'OK' line object for this grid
99  //
100  // If idline_class = class name:
101  // create line object of given class
102  //
103  // If idline_class = "":
104  // create KVIDLine object
105 
106  TString _cl, _type(idline_class);
107  _type.ToUpper();
108  TClass* clas = 0;
109 
110  if (_type == "ID") clas = DefaultIDLineClass();
111  else if (_type == "OK") clas = DefaultOKLineClass();
112  else _cl = idline_class;
113 
114  if (_cl == "") _cl = "KVIDLine";
115  if (!clas) clas = gROOT->GetClass(_cl.Data());
116 
117  KVIDLine* line = 0;
118 
119  if (!clas) {
120  Error("AddIDLine",
121  "%s is not a valid classname. No known class.", _cl.Data());
122  }
123  else {
124  if (!clas->InheritsFrom("KVIDLine")) {
125  Error("AddIDLine",
126  "%s is not a valid class deriving from KVIDLine.",
127  _cl.Data());
128  }
129  else {
130  line = (KVIDLine*) clas->New();
131  }
132  }
133  return line;
134 }
135 
136 
137 
138 
142 
143 void KVIDGrid::ReadIdentifierFromAsciiFile(TString& name, TString& type, TString& cl, ifstream& gridfile)
144 {
145  // Read in new identifier object from file
146  // Backwards-compatibility fixes
147 
148  KVIDentifier* line = 0;
149  /************ BACKWARDS COMPATIBILITY FIX *************
150  transform all 'OK' KVIDLines into KVIDCutLines
151  */
152  Bool_t oldcutline = kFALSE;
153  if (type == "OK" && cl == "KVIDLine") {
154  oldcutline = kTRUE;
155  }
156  /************ BACKWARDS COMPATIBILITY FIX *************
157  transform all 'ID' KVIDZLines into KVIDZALines
158  */
159  Bool_t zline = kFALSE;
160  if (type == "ID" && cl == "KVIDZLine") {
161  cl = "KVIDZALine";
162  zline = kTRUE;
163  }
164  line = New(cl.Data());
165  //now use ReadAscii method of class to read coordinates and other informations
166  /************ BACKWARDS COMPATIBILITY FIX *************
167  special read method for old KVIDZLines
168  */
169  if (zline)((KVIDZALine*)line)->ReadAsciiFile_KVIDZLine(gridfile);
170  else {
171  line->ReadAsciiFile(gridfile);
172  line->SetName(name.Data());
173  }
174  if (oldcutline) {
175  KVIDentifier* oldcut = line;
176  line = new KVIDCutLine;
177  line->CopyGraph(oldcut);
178  delete oldcut;
179  }
180  if (type == "OK") line->SetName(name.Data());
181  Add(type, line);
182 }
183 
184 
185 
186 
190 
192 {
193  //Replaces contents of fEmbracingLines with subset of ID lines for which IsBetweenEndPoints(x,y,direction) == kTRUE.
194  //nlines = number of lines in list
195 
196  TIter next(GetIdentifiers());
197  Int_t nlines = 0;
198  KVIDLine* line;
199  fEmbracingLines.Clear();
200  while ((line = (KVIDLine*) next())) {
201  if (line->IsBetweenEndPoints(x, y, direction)) {
202  fEmbracingLines.Add(line);
203  nlines++;
204  }
205  }
206  return nlines;
207 }
208 
209 
210 
211 
217 
219 {
220  // General initialisation method for identification grid.
221  // This method MUST be called once before using the grid for identifications.
222  // The ID lines are sorted.
223  // The natural line widths of all ID lines are calculated.
224 
225  SortIdentifiers();
226  CalculateLineWidths();
227 }
228 
229 
230 
int Int_t
ClassImp(KVPartitionList) void KVPartitionList
Initialisation.
char Char_t
const Bool_t kFALSE
bool Bool_t
double Double_t
const Bool_t kTRUE
int type
#define gROOT
Line in ID grid used to delimit regions where no identification is possible.
Definition: KVIDCutLine.h:22
Abstract base class for 2D identification grids in e.g. (dE,E) maps.
Definition: KVIDGrid.h:73
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
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:142
Base class for identification ridge lines corresponding to different nuclear species.
Definition: KVIDZALine.h:32
Base class for graphical cuts used in particle identification.
Definition: KVIDentifier.h:27
void * New(ENewType defConstructor=kClassNew, Bool_t quiet=kFALSE) const
Bool_t InheritsFrom(const char *cl) const
virtual void Clear(Option_t *="")
void ToUpper()
const char * Data() const
TLine * line
Double_t y[n]
Double_t x[n]
const long double cl
Definition: KVUnits.h:85
void Add(RHist< DIMENSIONS, PRECISION, STAT_TO... > &to, const RHist< DIMENSIONS, PRECISION, STAT_FROM... > &from)
void Error(const char *location, const char *va_(fmt),...)