1 | /********************************************************************\
|
---|
2 |
|
---|
3 | rootread.cc
|
---|
4 |
|
---|
5 | Reads rawfile created by the CTX DAQ.
|
---|
6 | Run using '.x rootread.cc++(Filename)'.
|
---|
7 | Generate shared library using make, then load library in root
|
---|
8 | with gSystem->Load("RawDataCTX.so")
|
---|
9 |
|
---|
10 | Oliver Grimm
|
---|
11 |
|
---|
12 | \********************************************************************/
|
---|
13 |
|
---|
14 | #include <stdlib.h>
|
---|
15 |
|
---|
16 | #include <TCanvas.h>
|
---|
17 | #include <TH1.h>
|
---|
18 | #include <TTimer.h>
|
---|
19 | #include <Getline.h>
|
---|
20 | #include <TLegend.h>
|
---|
21 |
|
---|
22 | #include "../../drsdaq/RawDataCTX.h"
|
---|
23 |
|
---|
24 | void rootread(char* Filename) {
|
---|
25 |
|
---|
26 | #ifdef __CINT__
|
---|
27 | printf("Error: This script can only be executed via ACliC\n");
|
---|
28 | return;
|
---|
29 | #endif
|
---|
30 |
|
---|
31 | RawDataCTX *RD = new RawDataCTX();
|
---|
32 |
|
---|
33 | // Open data file and read run header
|
---|
34 | if (RD->OpenDataFile(Filename, NULL) != CTX_OK) {
|
---|
35 | delete RD;
|
---|
36 | return;
|
---|
37 | }
|
---|
38 |
|
---|
39 | // ...for convenience some abbrevations
|
---|
40 | unsigned int Boards = RD->RHeader->NBoards;
|
---|
41 | unsigned int Channels = RD->RHeader->NChips*RD->RHeader->NChannels;
|
---|
42 | unsigned int Samples = RD->RHeader->Samples;
|
---|
43 |
|
---|
44 | // Allocate histograms and legends
|
---|
45 | TH1F* h = new TH1F [Boards*Channels];
|
---|
46 | TLegend* Legend = new TLegend [Boards];
|
---|
47 |
|
---|
48 | // Create a canvas
|
---|
49 | TCanvas* CW = new TCanvas("CW","DRS Waveform",10,10,700,200*Boards);
|
---|
50 | CW->Divide(1, Boards);
|
---|
51 |
|
---|
52 | // Initialise histograms and legends
|
---|
53 | for (unsigned int i=0; i<Boards; i++) {
|
---|
54 | for (unsigned int j=0; j<Channels; j++) {
|
---|
55 | h[i*Channels+j].SetBins(Samples, 0, Samples);
|
---|
56 | h[i*Channels+j].SetLineColor(1+j%8);
|
---|
57 | h[i*Channels+j].SetLineWidth(3);
|
---|
58 | if ((j+1)/8) h[i*Channels+j].SetLineStyle((j+2)%8);
|
---|
59 | Legend[i].AddEntry(&h[i*Channels+j], Form("Ch. %d",j), "L");
|
---|
60 | }
|
---|
61 | h[i*Channels].GetXaxis()->SetTitle(Form("Time slice (%.1f ns/slice)", 1./RD->BStruct[i].NomFreq));
|
---|
62 | h[i*Channels].GetYaxis()->SetTitle("Amplitude (a.u.)");
|
---|
63 |
|
---|
64 | Legend[i].SetX1NDC(0.91);
|
---|
65 | Legend[i].SetY1NDC(0.40);
|
---|
66 | Legend[i].SetX2NDC(0.98);
|
---|
67 | Legend[i].SetY2NDC(0.90);
|
---|
68 | Legend[i].SetFillColor(0);
|
---|
69 | Legend[i].SetLineColor(0);
|
---|
70 | Legend[i].SetBorderSize(0);
|
---|
71 | Legend[i].SetTextSize(0.03);
|
---|
72 | Legend[i].SetHeader(Form("Board %d",i));
|
---|
73 | }
|
---|
74 |
|
---|
75 | // Read and display all events
|
---|
76 | while (RD->ReadEvent(0, stdout) == CTX_OK) {
|
---|
77 | for(unsigned int k=0; k<Boards; k++) {
|
---|
78 | for(unsigned int j=0; j<Channels; j++) {
|
---|
79 | for(unsigned int i=0; i<Samples ; i++)
|
---|
80 | h[k*Channels+j].SetBinContent(i, RD->Data[k*Channels*Samples + j*Samples + i] * RD->BStruct[k].ScaleFactor);
|
---|
81 | }
|
---|
82 |
|
---|
83 | CW->cd(k+1);
|
---|
84 | gPad->SetGrid();
|
---|
85 | for (unsigned int j=0; j<Channels; j++) h[k*Channels+j].DrawCopy(j>0 ? "same":"");
|
---|
86 | Legend[k].Draw();
|
---|
87 | CW->Update();
|
---|
88 | }
|
---|
89 |
|
---|
90 | // Process gui events asynchronously during input
|
---|
91 | TTimer timer("gSystem->ProcessEvents();", 50, kFALSE);
|
---|
92 | timer.TurnOn();
|
---|
93 | TString input = Getline("Type 'q' to exit, <return> to go on: ");
|
---|
94 | timer.TurnOff();
|
---|
95 | if (input=="q\n") break;
|
---|
96 | }
|
---|
97 |
|
---|
98 | delete CW; delete[] Legend; delete[] h; delete RD;
|
---|
99 | }
|
---|