Hall A ROOT/C++ Analyzer (podd)
Loading...
Searching...
No Matches
tst1190_main.cxx
Go to the documentation of this file.
1#include <iostream>
2#include <fstream>
3#include <cstdlib>
4#include <cstdio>
5#include <numeric>
6#include <ctime>
7#include "THaCodaFile.h"
8#include "CodaDecoder.h"
9#include "Caen1190Module.h"
10#include "TString.h"
11#include "TROOT.h"
12#include "TFile.h"
13#include "TH1.h"
14#include "TDirectory.h"
15#include "TCanvas.h"
16
17//#define DEBUG
18//#define WITH_DEBUG
19
20#define CRATE1 1 // HMS single arm setup
21#define CRATE3 3 // HMS DC setup
22#define SLOTMIN 3
23#define NUMSLOTS 21
24#define NTDCCHAN 128
25#define NUMEVENTS 10
26#define NUMRAWEVENTS 10
27
28using namespace std;
29using namespace Decoder;
30
34
35void GeneratePlots(uint32_t islot, uint32_t chan) {
36 // Slot directory
37 slot_dir[islot] = dynamic_cast <TDirectory*> (hfile->Get(Form("slot_%d", islot)));
38 if (!slot_dir[islot]) {slot_dir[islot] = hfile->mkdir(Form("slot_%d", islot)); slot_dir[islot]->cd();}
39 else hfile->cd(Form("/slot_%d", islot));
40 // Histos
41 if (!h_occupancy[islot]) h_occupancy[islot] = new TH1I("h_occupancy", Form("CAEN1190 TDC Occupancy Slot %d", islot), 128, 0, 127);
42 // Channel directory
43 chan_dir[chan] = dynamic_cast <TDirectory*> (slot_dir[islot]->Get(Form("chan_%d", chan)));
44 if (!chan_dir[chan]) {chan_dir[chan] = slot_dir[islot]->mkdir(Form("chan_%d", chan)); chan_dir[chan]->cd();}
45 else hfile->cd(Form("/slot_%d/chan_%d", islot, chan));
46 // Histos
47 if (!h_rawtdc[islot][chan]) h_rawtdc[islot][chan] = new TH1I("h_rawtdc", Form("CAEN1190 RAW TDC Slot %d Channel %d", islot, chan), 50001, 0, 50000);
48}
49
50int main(int /* argc */, char** /* argv */)
51{
52 // Initialize the analysis clock
53 clock_t t;
54 t = clock();
55
56 // Define the data file to be analyzed
57 TString filename("snippet.dat");
58
59 // Define the analysis debug output
60 auto *debugfile = new ofstream;
61 // debugfile->open ("tst1190_main_debug.txt");
62
63 // Initialize the CODA decoder
64 THaCodaFile datafile;
65 if (datafile.codaOpen(filename) != CODA_OK) {
66 cerr << "ERROR: Cannot open CODA data" << endl;
67 cerr << "Perhaps you mistyped it" << endl;
68 cerr << "... exiting." << endl;
69 exit(2);
70 }
71 auto *evdata = new CodaDecoder();
72 evdata->SetCodaVersion(datafile.getCodaVersion());
73
74 // Initialize the evdata debug output
75 evdata->SetDebug(1);
76 evdata->SetDebugFile(debugfile);
77
78 // Initialize root and output
79 TROOT fadcana("tst1190root", "Hall C analysis");
80 hfile = new TFile("tst1190.root", "RECREATE", "1190 module data");
81
82 // Loop over events
83 cout << "***************************************" << endl;
84 cout << NUMEVENTS << " events will be processed" << endl;
85 cout << "***************************************" << endl;
86 int status = 0;
87 uint32_t iievent = 1;
88 //for(uint32_t ievent = 0; ievent < NUMEVENTS + 1; ievent++) {
89 for(uint32_t ievent = 0; ievent < iievent; ievent++) {
90 // Read in data file
91 status = datafile.codaRead();
92 if (status == CODA_OK) {
93 status = evdata->LoadEvent(datafile.getEvBuffer());
94 if( status != CodaDecoder::HED_OK && status != CodaDecoder::HED_WARN ) {
95 cerr << "ERROR " << status << " while decoding event " << ievent
96 << ". Exiting." << endl;
97 break;
98 }
99
100 if (debugfile) *debugfile << "****************" << endl;
101 if (debugfile) *debugfile << "Event Number = " << evdata->GetEvNum() << endl;
102 if (debugfile) *debugfile << "****************\n" << endl;
103
104 // Loop over slots
105 for(uint32_t islot = SLOTMIN; islot < NUMSLOTS; islot++) {
106 if (evdata->GetNumRaw(CRATE3, islot) != 0) { // HMS Single arm setup
107 auto *tdc =
108 dynamic_cast <Caen1190Module*> (evdata->GetModule(CRATE3, islot)); // HMS single arm setup
109 if (tdc != nullptr) {
110 if (debugfile) *debugfile << "\n///////////////////////////////\n"
111 << "Results for crate "
112 << tdc->GetCrate() << ", slot "
113 << tdc->GetSlot() << endl;
114
115 if (debugfile) *debugfile << hex << "tdc pointer = " << tdc << "\n" << dec
116 << "///////////////////////////////\n" << endl;
117
118 // Loop over channels
119 for (uint32_t chan = 0; chan < NTDCCHAN; chan++) {
120 // Generate FADC plots
121 GeneratePlots(islot, chan);
122 for (Int_t hitno = 0; hitno < 16; hitno++) { // Assume for now up-to 16 hits???
123 if (tdc->GetData(chan, hitno) != 0)
124 h_rawtdc[islot][chan]->Fill(tdc->GetData(chan, hitno));
125 } // TDC hit loop
126 } // TDC channel loop
127 } // TDC module found condition
128 else
129 if (debugfile) *debugfile << "TDC MODULE NOT FOUND!!!" << endl;
130 } // Number raw words condition
131 } // Slot loop
132 } else if( status != EOF ) {
133 cerr << "ERROR " << status << " while reading CODA event " << ievent
134 << ". Twonk." << endl;
135 break;
136 } // CODA file read status condition
137 if (iievent % 1000 == 0)
138 //if (iievent % 1 == 0)
139 cout << iievent << " events have been processed" << endl;
140 iievent++;
141 if (status == EOF) break;
142 } // Event loop
143
144 cout << "***************************************" << endl;
145 cout << iievent - 1 << " events were processed" << endl;
146 cout << "***************************************" << endl;
147
148 // Write and clode the data file
149 hfile->Write();
150 hfile->Close();
151 datafile.codaClose();
152
153 // Calculate the analysis rate
154 t = clock() - t;
155 printf ("The analysis took %.1f seconds \n", ((float) t) / CLOCKS_PER_SEC);
156 printf ("The analysis event rate is %.1f Hz \n", (iievent - 1) / (((float) t) / CLOCKS_PER_SEC));
157
158 return status;
159} // main()
int Int_t
uint32_t chan
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
#define CODA_OK
Definition THaCodaData.h:28
char * Form(const char *fmt,...)
virtual UInt_t GetCrate() const
Definition Module.h:101
UInt_t * getEvBuffer()
Definition THaCodaData.h:76
virtual Int_t getCodaVersion()
virtual Int_t codaOpen(const char *filename, Int_t mode=1)
virtual Int_t codaClose()
virtual Int_t codaRead()
Bool_t cd() override
T * Get(const char *namecycle)
TDirectory * mkdir(const char *name, const char *title="", Bool_t returnExistingDirectory=kFALSE) override
virtual TObject * Get(const char *namecycle)
virtual Bool_t cd()
virtual TDirectory * mkdir(const char *name, const char *title="", Bool_t returnExistingDirectory=kFALSE)
Int_t Write(const char *name=nullptr, Int_t opt=0, Int_t bufsiz=0) const override
void Close(Option_t *option="") override
virtual Int_t Fill(const char *name, Double_t w)
int main()
STL namespace.
void GeneratePlots(uint32_t islot, uint32_t chan)
#define SLOTMIN
TH1I * h_occupancy[NUMSLOTS]
#define NUMEVENTS
#define CRATE3
TH1I * h_rawtdc[NUMSLOTS][NTDCCHAN]
#define NTDCCHAN
TDirectory * chan_dir[NTDCCHAN]
TFile * hfile
#define NUMSLOTS
TDirectory * slot_dir[NUMSLOTS]