source: tools/rootread/rootread.cc@ 9534

Last change on this file since 9534 was 64, checked in by ogrimm, 16 years ago
Updated for new event format including trigger cells
File size: 3.2 KB
Line 
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
24void 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 int *TrigPnt = (int *) RD->Data;
78 short *DataPnt = (short *) RD->Data + Boards*RD->RHeader->NChips*sizeof(int);
79
80 printf("Trigger cells: ");
81 for(unsigned int i=0; i<Boards*RD->RHeader->NChips; i++) printf("%d ", *(TrigPnt + i));
82 printf("\n");
83
84 for(unsigned int k=0; k<Boards; k++) {
85 for(unsigned int j=0; j<Channels; j++) {
86 for(unsigned int i=0; i<Samples ; i++)
87 h[k*Channels+j].SetBinContent(i, DataPnt[k*Channels*Samples +
88 j*Samples + i] * RD->BStruct[k].ScaleFactor);
89 }
90
91 CW->cd(k+1);
92 gPad->SetGrid();
93 for (unsigned int j=0; j<Channels; j++) h[k*Channels+j].DrawCopy(j>0 ? "same":"");
94 Legend[k].Draw();
95 CW->Update();
96 }
97
98 // Process gui events asynchronously during input
99 TTimer timer("gSystem->ProcessEvents();", 50, kFALSE);
100 timer.TurnOn();
101 TString input = Getline("Type 'q' to exit, <return> to go on: ");
102 timer.TurnOff();
103 if (input=="q\n") break;
104 }
105
106 delete CW; delete[] Legend; delete[] h; delete RD;
107}
Note: See TracBrowser for help on using the repository browser.