source: fact/tools/rawtoroot/rawtoroot.cc@ 13408

Last change on this file since 13408 was 9888, checked in by neise, 14 years ago
initial commit of rawtoroot.
File size: 3.4 KB
Line 
1/********************************************************************\
2
3 rawtoroot.cc
4
5 Reads rawfile created by the CTX DAQ.
6 Run using '.x rawtoroot.cc++("raw-filename")'.
7 Generate shared library using make, then load library in root
8 with gSystem->Load("RawDataCTX.so")
9
10 Dominik Neise
11 based on rootread.cc by Oliver Grimm
12
13\********************************************************************/
14
15#include <stdlib.h>
16#include <iostream>
17
18#include <TCanvas.h>
19#include <TH1.h>
20#include <TTree.h>
21#include <TFile.h>
22#include <TTimer.h>
23#include <Getline.h>
24#include <TLegend.h>
25
26#include <string.h>
27#include "../../drsdaq/RawDataCTX.h"
28
29void rawtoroot(char* Filename) {
30
31
32 string c=Filename;
33 c.replace(c.length()-3,3,"root");
34
35 TFile *myf = new TFile(c.c_str(),"RECREATE","Demo ROOT file with histograms & trees");
36
37 #ifdef __CINT__
38 printf("Error: This script can only be executed via ACliC\n");
39 return;
40 #endif
41
42 RawDataCTX *RD = new RawDataCTX();
43
44 // Open data file and read run header
45 if (RD->OpenDataFile(Filename, NULL) != CTX_OK) {
46 delete RD;
47 return;
48 }
49
50 // ...for convenience some abbrevations
51 unsigned int Boards = RD->RHeader->NBoards;
52 unsigned int Channels = RD->RHeader->NChips*RD->RHeader->NChannels;
53 unsigned int Samples = RD->RHeader->Samples;
54 if (Samples != 1024) {
55 cout << "Error: ROI is not 1024, but data is shifted according to physical pipeline. Makes no sense." << endl;
56 }
57
58 int stopcell;
59 unsigned int channel,drs,Eventnumber,channelindex;
60
61 TH1F* hist = new TH1F();
62
63
64 TTree *tree = new TTree("T","event data tree");
65
66 tree->Branch("drs",&drs,"drs/I"); // from 0 .. 3
67 tree->Branch("channel",&channel,"channel/I"); // from 0 .. 8
68 tree->Branch("channelindex", &channelindex, "channelindex/I"); // from 0 .. 35
69 tree->Branch("hist","TH1F",&hist);
70 tree->Branch("samples",&Samples,"samples/I"); // size of ROI
71
72 // note: not the real Eventnumber from RAW file is used
73 // TODO
74 tree->Branch("Eventnumber", &Eventnumber, "Eventnumber/I"); // Eventnumber 0..N
75
76 // the data is shifted, which makes only sense for ROI=samples=1024
77 tree->Branch("stopcell", &stopcell, "stopcell/I");
78
79int num=0;
80
81 // Read and display all events
82 while (RD->ReadEvent(0, stdout) == CTX_OK) {
83 Eventnumber = num;
84 int *TrigPnt = (int *) RD->Data;
85
86 // apparently it is necessary to step back 8 byte ... I don't know why, but it works.
87 short *DataPnt = (short *) RD->Data + (Boards*RD->RHeader->NChips)*sizeof(int) - 8 * sizeof(char);
88
89 printf("Trigger cells: ");
90 for(unsigned int i=0; i<Boards*RD->RHeader->NChips; i++) printf("%d ", *(TrigPnt + i));
91 printf("\n");
92
93 for(unsigned int k=0; k<Boards; k++) {
94 for(unsigned int j=0; j<Channels; j++) {
95 TH1F* a = new TH1F();
96 a->SetBins(Samples, -0.5, Samples-0.5);
97 a->SetLineColor(1);
98 a->SetLineWidth(2);
99 a->SetLineStyle(1);
100 a->GetXaxis()->SetTitle(Form("Time slice (%.1f ns/slice)", 1./RD->BStruct[k].NomFreq));
101 a->GetYaxis()->SetTitle("Amplitude (a.u.)");
102 drs = j/9;
103 channel = j%9;
104 channelindex = j;
105 stopcell = *(TrigPnt + drs);
106 for(unsigned int i=0; i<Samples ; i++) {
107 a->SetBinContent((i+stopcell)%Samples+1, DataPnt[k*Channels*Samples + j*Samples + i] * RD->BStruct[k].ScaleFactor);
108 }
109
110
111 hist=a;
112 tree->Fill();
113 delete a;
114 }
115 }
116
117 ++num;
118 }
119
120 tree->BuildIndex("Eventnumber", "channelindex");
121
122 myf->Write();
123 myf->Close();
124 delete RD;
125}
Note: See TracBrowser for help on using the repository browser.