KaliVeda
Toolkit for HIC analysis
Loading...
Searching...
No Matches
KVDP2toCsIGridConvertor.cpp
1/*
2$Id: KVDP2toCsIGridConvertor.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:23:14 2008
8//Author: franklan
9
10#include "KVDP2toCsIGridConvertor.h"
11#include "TList.h"
12#include "KVIDGrid.h"
13#include "KVIDGridManager.h"
14#include "KVError.h"
15
16using namespace std;
17
19
20
21
23
25{
26 // Default constructor
27}
28
29
30
33
38
39
41
42
46
47void KVDP2toCsIGridConvertor::Convert(const Char_t* id_and_imf_file, const Char_t* gamma_file)
48{
49 //Read ID and Gamma-line files for CsI R-L identifications.
50 //Initialise grids in KVIDCsI telescopes
51
52 if (fGrids) fGrids->Clear();
53 else fGrids = new TList;
54 ReadFile(id_and_imf_file);
55 // set name of all IMF lines
56 TIter nextGrid(fGrids);
57 KVIDGrid* grid;
59 while ((grid = (KVIDGrid*)nextGrid())) {
60 TIter nextOK(grid->GetCuts());
61 while ((line = (KVIDentifier*) nextOK())) {
62 line->SetName("IMF_line");
63 }
64 }
65 ReadGammaFile(gamma_file);
66 if (gIDGridManager) gIDGridManager->GetGrids()->AddAll(fGrids);
67 else Error(KV__ERROR(Convert), "gIDGridManager=0x0: create an ID grid manager first!");
68}
69
70
72
73
75
77{
78 ifstream gamfile;
79 gamfile.open(gammafile);
80
81 if (!gamfile.good()) {
82 Error(KV__ERROR(ReadGammaFile),
83 "Problem reading file %s", gammafile);
84 return;
85 }
86 KVString s;
87
88 s.ReadLine(gamfile);
89
90 while (gamfile.good()) {
91
92 if (s == "") {
93 s.ReadLine(gamfile);
94 continue;
95 }
96
97 if (!s.BeginsWith('#')) { //'#' sign signals comments
98 int ring, modu, frun, lrun;
99 if (sscanf(s.Data(), "%d %d %d %d", &ring, &modu, &frun, &lrun) !=
100 4) {
101 Error(KV__ERROR(ReadGammaFile), "Problem reading file %s\nLast line read: %s",
102 gammafile, s.Data());
103 return;
104 };
105 //get grid for this ring,mod
107 name.
108 Form
109 ("CsI R-L Grid First run=%d Last run=%d Ring min=%d Ring max=%d Mod min=%d Mod max=%d",
110 frun, lrun, ring, ring, modu, modu);
111 KVIDGrid* grid = (KVIDGrid*)fGrids->FindObject(name.Data());
112 if (!grid) {
113 Error(KV__ERROR(ReadGammaFile), "Can't find grid %s", name.Data());
114 }
115 int npoints;
116 gamfile >> npoints;
117 //found gamma line
118 KVIDLine* line = 0;
119 if (grid) {
120 line = grid->NewLine("ok");
121 line->SetName("gamma_line");
122 line->Set(npoints);
123 grid->Add("ok", line);
124 }
125 //read in points
126 for (int i = 0; i < npoints; i++) {
127 Double_t x, y;
128 gamfile >> x >> y;
129 if (grid)
130 line->SetPoint(i, x, y);
131 }
132 }
133 s.ReadLine(gamfile);
134 }
135 gamfile.close();
136}
137
138
char Char_t
double Double_t
char name[80]
char * Form(const char *fmt,...)
Converts dp2-format CsI R-L grids to KVIDGrids.
virtual ~KVDP2toCsIGridConvertor()
Destructor.
virtual void ReadGammaFile(const Char_t *gammafile)
void Convert(const Char_t *id_and_imf_file, const Char_t *gamma_file)
TList * fGrids
list of new grids
virtual void ReadFile(const Char_t *filename)
Read grids in file and add to fGrids list.
void Add(TString, KVIDentifier *)
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
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.
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
Definition KVString.h:73
virtual void AddAll(const TCollection *col)
void Clear(Option_t *option="") override
TObject * FindObject(const char *name) const override
TLine * line
Double_t y[n]
Double_t x[n]
void Error(const char *location, const char *fmt,...)
ClassImp(TPyArg)