summaryrefslogtreecommitdiff
path: root/io/root.C
blob: dfcb3c0c50cc31b3a0356e5dc0ab9297e25cbea9 (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
#include <TVector3.h>
#include <vector>
#include <TTree.h>
#include <string>

struct Photon {
  double t;
  TVector3 pos;
  TVector3 dir;
  TVector3 pol;
  double wavelength; // nm
  int state;
  int last_triangle;
  int last_solid;
};

struct MC {
  std::string particle;
  TVector3 gen_pos;
  TVector3 gen_dir;
  double gen_ke;

  std::vector<Photon> photon;

  void clear() {
    particle = "none";
    photon.clear();
  }
};

struct Channel {
  Channel() : channel_id(-1), t(-9999.0), q(-9999.0) { };
  int channel_id;
  double t;
  double q;
};
  
struct Event {
  int event_id;
  MC mc;
  int nhit;
  std::vector<Channel> channel;

  void clear() {
    mc.clear();
    channel.clear();
  }
};

void fill_event(TTree *T,
		Event *ev, int event_id, double *gen_pos, int nchannels, 
		float *channel_times)
{
  ev->clear();
  ev->event_id = event_id;
  MC &mc = ev->mc;
  mc.gen_pos.SetXYZ(gen_pos[0], gen_pos[1], gen_pos[2]);
  ev->nhit = 0;
  Channel ch;
  for (int i=0; i < nchannels; i++) {
    if (channel_times[i] < 1e8) {
      ev->nhit++;
      ch.channel_id = i;
      ch.t = channel_times[i];
      ch.q = 1.0;
      ev->channel.push_back(ch);
    }
  }
  T->Fill();
}


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