KaliVeda
Toolkit for HIC analysis
Loading...
Searching...
No Matches
KVDP2toIDGridConvertor.cpp
1/*
2$Id: KVDP2toIDGridConvertor.cpp,v 1.2 2009/03/06 08:59:18 franklan Exp $
3$Revision: 1.2 $
4$Date: 2009/03/06 08:59:18 $
5*/
6
7//Created by KVClassFactory on Thu Oct 9 17:21:55 2008
8//Author: franklan
9
10#include "KVDP2toIDGridConvertor.h"
11#include "TList.h"
12#include "KVIDGrid.h"
13#include "KVError.h"
14#include "KVIDGridManager.h"
15
16using namespace std;
17
19
20
21
23
25{
26 // Default constructor
27 fGridClass = 0;
28 fGrids = 0;
29}
30
31
33
34
37
39{
40 // Destructor
41 if (fGrids) {
42 fGrids->Clear();
43 delete fGrids;
44 }
45}
46
47
49
50
52
54{
55 fGridClass = TClass::GetClass(cl);
56 if (!fGridClass) Error(KV__ERROR(SetGridClass), "Unknown grid class %s", cl);
57}
58
59
61
62
64
66{
67 if (fGrids) fGrids->Clear();
68 else fGrids = new TList;
70 if (gIDGridManager) gIDGridManager->GetGrids()->AddAll(fGrids);
71 else Error(KV__ERROR(Convert), "gIDGridManager=0x0: create an ID grid manager first!");
72}
73
74
76
77
80
82{
83 // Read grids in file and add to fGrids list
84
85 if (!fGridClass) {
86 Error(KV__ERROR(ReadFile),
87 "Set class of ID grids to generate first!");
88 return;
89 }
90
91 ifstream datfile;
92 datfile.open(filename);
93
94 if (!datfile.good()) {
95 Error(KV__ERROR(ReadFile),
96 "Problem reading file %s", filename);
97 return;
98 }
99 KVString s;
100
101 s.ReadLine(datfile);
102
103 while (datfile.good()) {
104
105 if (s == "") {
106 s.ReadLine(datfile);
107 continue;
108 }
109
110 if (!s.BeginsWith('#')) { //'#' sign signals comments
111 int ring, modu, frun, lrun, totpoints;
112 if (sscanf(s.Data(), "%d %d %d %d", &ring, &modu, &frun, &lrun) !=
113 4) {
114 Error(KV__ERROR(ReadFile), "Problem reading file %s\nLast line read: %s",
115 filename, s.Data());
116 return;
117 };
118 KVIDGrid* grid = (KVIDGrid*) fGridClass->New(); //create new grid
119
120 //add to list of grids
121 fGrids->Add(grid);
122
123 grid->GetParameters()->SetValue("First run", frun);
124 grid->GetParameters()->SetValue("Last run", lrun);
125 grid->GetParameters()->SetValue("Ring min", ring);
126 grid->GetParameters()->SetValue("Ring max", ring);
127 grid->GetParameters()->SetValue("Mod min", modu);
128 grid->GetParameters()->SetValue("Mod max", modu);
129 int nlines;
130 datfile >> nlines;
131 totpoints = 0;
132 //read Z,A and number of points in each line
133 for (int i = 0; i < nlines; i++) {
134 int z, a, npoints;
135 datfile >> z >> a >> npoints;
136 totpoints += 2 * npoints;
137 if (z > 0) {
138 //identification line
139 KVIDLine* line = (KVIDLine*)grid->NewLine("id");
140 line->SetZ(z);
141 line->SetA(a);
142 line->Set(npoints);
143 grid->Add("id", line);
144 }
145 else {
146 //"ok" line
147 KVIDLine* line = (KVIDLine*)grid->NewLine("ok");
148 line->Set(npoints);
149 grid->Add("ok", line);
150 }
151 }
152 ReadLineCoords(grid, datfile);
153 //calculate line widths in grid
154 grid->CalculateLineWidths();
155 }
156 s.ReadLine(datfile);
157 }
158 datfile.close();
159}
160
161
162
166
168{
169 // Read coordinates of lines in the order they were created.
170 // We assume that the 'ID' lines are first, then the 'OK' lines
171
172 TIter nextID(grid->GetIdentifiers());
174 while ((line = (KVIDentifier*) nextID())) {
175 //read in points
176 for (int i = 0; i < line->GetN(); i++) {
177 Double_t x, y;
178 datfile >> x >> y;
179 line->SetPoint(i, x, y);
180 }
181 }
182 TIter nextOK(grid->GetCuts());
183 while ((line = (KVIDentifier*) nextOK())) {
184 //read in points
185 for (int i = 0; i < line->GetN(); i++) {
186 Double_t x, y;
187 datfile >> x >> y;
188 line->SetPoint(i, x, y);
189 }
190 }
191}
192
193
char Char_t
double Double_t
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
Converts dp2-format grids to KVIDGrids.
virtual void SetGridClass(const Char_t *cl)
TList * fGrids
list of new grids
TClass * fGridClass
class of grid to create from dp2 file
virtual ~KVDP2toIDGridConvertor()
Destructor.
virtual void ReadFile(const Char_t *filename)
Read grids in file and add to fGrids list.
void Convert(const Char_t *filename)
virtual void ReadLineCoords(KVIDGrid *, std::ifstream &)
void Add(TString, KVIDentifier *)
const KVNameValueList * GetParameters() const
Definition KVIDGraph.h:288
const KVList * GetIdentifiers() const
Definition KVIDGraph.h:298
const KVList * GetCuts() const
Definition KVIDGraph.h:308
KVList * GetGrids()
Abstract base class for 2D identification grids in e.g. (dE,E) maps.
Definition KVIDGrid.h:74
virtual void CalculateLineWidths()
Definition KVIDGrid.h:264
KVIDLine * NewLine(const Char_t *idline_class="")
Definition KVIDGrid.cpp:90
Base class for lines/cuts used for particle identification in 2D data maps.
Definition KVIDLine.h:143
Base class for graphical cuts used in particle identification.
void SetValue(const Char_t *name, value_type value)
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
Definition KVString.h:73
void * New(ENewType defConstructor=kClassNew, Bool_t quiet=kFALSE) const
virtual void AddAll(const TCollection *col)
void Clear(Option_t *option="") override
void Add(TObject *obj) override
TLine * line
Double_t y[n]
Double_t x[n]
void Error(const char *location, const char *fmt,...)
TArc a
ClassImp(TPyArg)