summaryrefslogtreecommitdiff
path: root/fileio/root.C
blob: 2b39b1b123da82689e168d486baf890660fa04d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#include <TVector3.h>
#include <vector>
#include <TTree.h>
#include <string>

struct Vertex {
  std::string particle_name;
  TVector3 pos;
  TVector3 dir;
  TVector3 pol;
  double ke;
  double t0;

  ClassDef(Vertex, 1);
};

struct Photon {
  double t;
  TVector3 pos;
  TVector3 dir;
  TVector3 pol;
  double wavelength; // nm
  unsigned int flag;
  int last_hit_triangle;

  ClassDef(Photon, 1);
};

struct Channel {
  Channel() : id(-1), t(-1e9), q(-1e9) { };
  int id;
  double t;
  double q;
  unsigned int flag;

  ClassDef(Channel, 1);
};

struct Event {
  int id;
  unsigned int nhit;
  unsigned int nchannels;

  Vertex primary_vertex;

  std::vector<Vertex> vertices;
  std::vector<Photon> photons_beg;
  std::vector<Photon> photons_end;
  std::vector<Channel> channels;

  ClassDef(Event, 1);
};

void fill_channels(Event *ev, unsigned int nhit, unsigned int *ids, float *t,
		   float *q, unsigned int *flags, unsigned int nchannels)
{
  ev->nhit = 0;
  ev->nchannels = nchannels;
  ev->channels.resize(0);

  Channel ch;
  unsigned int id;
  for (unsigned int i=0; i < nhit; i++) {
      ev->nhit++;
      id = ids[i];
      ch.id = id;
      ch.t = t[id];
      ch.q = q[id];
      ch.flag = flags[id];
      ev->channels.push_back(ch);
  }
}

void get_channels(Event *ev, int *hit, float *t, float *q, unsigned int *flags)
{
  for (unsigned int i=0; i < ev->nchannels; i++) {
    hit[i] = 0;
    t[i] = -1e9f;
    q[i] = -1e9f;
    flags[i] = 0;
  }

  unsigned int id;
  for (unsigned int i=0; i < ev->channels.size(); i++) {
    id = ev->channels[i].id;

    if (id < ev->nchannels) {
      hit[id] = 1;
      t[id] = ev->channels[i].t;
      q[id] = ev->channels[i].q;
      flags[id] = ev->channels[i].flag;
    }
  }
}

void get_photons(const std::vector<Photon> &photons, float *pos, float *dir,
		 float *pol, float *wavelengths, float *t,
		 int *last_hit_triangles, unsigned int *flags)
{
  for (unsigned int i=0; i < photons.size(); i++) {
    const Photon &photon = photons[i];
    pos[3*i] = photon.pos.X();
    pos[3*i+1] = photon.pos.Y();
    pos[3*i+2] = photon.pos.Z();

    dir[3*i] = photon.dir.X();
    dir[3*i+1] = photon.dir.Y();
    dir[3*i+2] = photon.dir.Z();
    
    pol[3*i] = photon.pol.X();
    pol[3*i+1] = photon.pol.Y();
    pol[3*i+2] = photon.pol.Z();

    wavelengths[i] = photon.wavelength;
    t[i] = photon.t;
    flags[i] = photon.flag;
    last_hit_triangles[i] = photon.last_hit_triangle;
  }
}
		 
void fill_photons(std::vector<Photon> &photons,
		  unsigned int nphotons, float *pos, float *dir,
		  float *pol, float *wavelengths, float *t,
		  int *last_hit_triangles, unsigned int *flags)
{
  photons.resize(nphotons);
  
  for (unsigned int i=0; i < nphotons; i++) {
    Photon &photon = photons[i];
    photon.t = t[i];
    photon.pos.SetXYZ(pos[3*i], pos[3*i + 1], pos[3*i + 2]);
    photon.dir.SetXYZ(dir[3*i], dir[3*i + 1], dir[3*i + 2]);
    photon.pol.SetXYZ(pol[3*i], pol[3*i + 1], pol[3*i + 2]);
    photon.wavelength = wavelengths[i];
    photon.last_hit_triangle = last_hit_triangles[i];
    photon.flag = flags[i];

  }
}

#ifdef __MAKECINT__
#pragma link C++ class vector<Vertex>;
#pragma link C++ class vector<Photon>;
#pragma link C++ class vector<Channel>;
#endif