source: trunk/Mars/hawc/plot_trace.C@ 19969

Last change on this file since 19969 was 19951, checked in by giangdo, 5 years ago
script to synchronise the data from HAWC's Eye and HAWC
File size: 7.4 KB
Line 
1#include <TStyle.h>
2#include <TCanvas.h>
3#include <TSystem.h>
4#include <TF1.h>
5#include <TProfile.h>
6#include <TProfile2D.h>
7#include <TMath.h>
8#include <TGraph.h>
9#include <TLine.h>
10#include <TFitResultPtr.h>
11#include <TFitResult.h>
12#include <TFile.h>
13#include <TLine.h>
14
15#include <cstdio>
16#include <stdio.h>
17#include <stdint.h>
18
19#include "Getline.h"
20#include "MH.h"
21#include "MArrayI.h"
22#include "MDirIter.h"
23#include "MFillH.h"
24#include "MEvtLoop.h"
25#include "MCamEvent.h"
26#include "MGeomApply.h"
27#include "MTaskList.h"
28#include "MParList.h"
29#include "MContinue.h"
30#include "MBinning.h"
31#include "MDrsCalibApply.h"
32#include "MDrsCalibration.h"
33#include "MRawFitsRead.h"
34#include "MStatusDisplay.h"
35#include "MTaskInteractive.h"
36#include "MPedestalSubtractedEvt.h"
37#include "MGeomCamFAMOUS.h"
38#include "MRawRunHeader.h"
39#include "MPedestalCam.h"
40#include "MPedestalPix.h"
41#include "MParameters.h"
42
43// ==========================================================================
44// ============ see plot_callisto function at the end of the file ===========
45// ==========================================================================
46int HandleInput()
47{
48 // This is a pure man's command line interface to wait for a key input
49 // and allow exit but at the same time allow interaction with the GUI
50 TTimer timer("gSystem->ProcessEvents();", 50, kFALSE);
51
52 // While reading the input process gui events asynchronously
53 timer.TurnOn();
54 const char *gl = Getline("Type 'q' to exit, or event number and <return> to go on: ");
55 timer.TurnOff();
56
57 TString input = gl;
58 if (input=="q\n" || input==".q\n")
59 return kFALSE;
60
61 return kTRUE;
62}
63
64// Create a histogram for the trace
65//TH1D hist("Trace", "Waveform", 1024, -0.25, 511.75); //range = [-0.25,511.75]ns
66TH1D hist("Trace", "Waveform (Pixel 5, Event 1)", 1024, -0.5, 1024-0.5);
67
68// All 'data members' that are required globally
69TCanvas *c;
70MPedestalSubtractedEvt *fEvt = 0;
71
72//
73// Called like all PreProcess functions of tasks. Get the access to
74// the containers necessary for you.
75//
76Int_t PreProcess(MParList *plist)
77{
78 fEvt = (MPedestalSubtractedEvt*)plist->FindObject("MPedestalSubtractedEvt");
79
80 //if (!fEvt)
81 //{
82 // gfLog << err << "MPedestalSubtractedEvt not found... aborting." << endl;
83 // return kFALSE;
84 //}
85
86 // Create a canvas and plot the histogram into it
87 c = new TCanvas();
88 hist.SetStats(kFALSE);
89 hist.Draw();
90 hist.SetXTitle("Samples");
91 hist.SetYTitle("Amplitude [a.u.]");
92
93 //TF1 constant("zero", "[0]", -0.25, 511.75);
94 TF1 constant("zero", "[0]", -0.5, 1024);
95 constant.SetParameter(0, 0);
96 constant.SetLineColor(kBlack);
97 constant.SetLineStyle(kDashed);
98 constant.DrawCopy("same");
99
100 // One p.e.
101 constant.SetParameter(0, 20);
102 constant.SetLineStyle(kDotted);
103 constant.DrawCopy("same");
104
105 constant.SetParameter(0, -20);
106 constant.DrawCopy("same");
107
108
109 return kTRUE;
110}
111
112Int_t Process()
113{
114 int pixel_index = 6; //plot trace only of this pixel
115 int skipstart = 5;
116 int skipend = 10;
117
118 // Number of samples per pixel (usually 1024)
119 int numsamples = fEvt->GetNumSamples();
120 Float_t *cal = fEvt->GetSamples(pixel_index);
121
122 // reset contents of histogram and fill new contents
123 hist.Reset();
124 for (int i=0; i<numsamples; i++)
125 hist.Fill(i, cal[i]); // 0.5ns = 1 sample
126
127 // Reset min/max range
128 hist.SetMinimum(-50);
129 hist.SetMaximum(50);
130
131 //// Set a reasonable range
132 //if (hist.GetMinimum()>-30)
133 // hist.SetMinimum(-20);
134 //if (hist.GetMaximum()<60)
135 // hist.SetMaximum(50);
136
137
138
139 TLine *line = new TLine(skipstart, 50, skipstart, -50);
140 line->SetLineStyle(kSolid);
141 line->SetLineColor(kRed);
142 line->Draw();
143
144 TLine *line2 = new TLine(1024-skipend, 50, 1024-skipend, -50);
145 line2->SetLineStyle(kSolid);
146 line2->SetLineColor(kRed);
147 line2->Draw();
148
149 // Signal root to update the canvas/pad
150 c->Modified();
151 c->Update();
152 //c->SaveAs("/home/giangdo/Documents/Master/MA/pulse/data_single_pe/traces/pixel3/event_0.png");
153
154
155 bool rc = HandleInput();
156
157 // wait for 'return'
158 return rc;
159}
160
161
162/*****************************************************************
163
164 This is an example how to access and display calibrated raw data
165
166 datafile:
167 A data file written by the fadctrl or ceres, e.g.
168 20170727_006.fits.fz or
169 00000015.003_D_MonteCarlo019_Events.fits.fz
170
171 drsfile:
172 Usually the third of the three .drs.fits files from a
173 DRS calibration sequence, e.g. 20170727_004.drs.fits
174
175 To run the macro from the command line (assuming you are in a directory
176 Mars/build where you have built your Mars environment) ou can do
177
178 root ../hawc/plot_trace.C\(\"20191002_018.fits.fz\",\"20191002_013.drs.fits\"\)
179
180 or from within root
181
182 [0] .x ../hawc/plot_trace.C("20191002_018.fits.fz", "20191002_013.drs.fits")
183
184******************************************************************/
185int plot_trace(const char *datafile, const char *drsfile)
186{
187 // ======================================================
188
189 // true: Display correctly mapped pixels in the camera displays
190 // but the value-vs-index plot is in software/spiral indices
191 // false: Display pixels in hardware/linear indices,
192 // but the order is the camera display is distorted.
193 // false is assumed automatically for files with the ISMC flag set.
194 bool usemap = true;
195
196 // mapping file (found in Mars/hawc)
197 const char *mmap = usemap ? "/home/giangdo/Documents/Master/MA/Software/Mars/hawc/HAWCsEyemap181214.txt" : NULL;
198
199 // ======================================================
200
201 // Check if the requested mapping file is available
202 if (mmap && gSystem->AccessPathName(mmap, kFileExists))
203 {
204 gLog << err << "ERROR - Cannot access mapping file '" << mmap << "'" << endl;
205 return 11;
206 }
207
208 // -------------------------------------------------------
209
210 // Check and read the DRS calibration constants
211 MDrsCalibration drscalib300;
212 if (drsfile && !drscalib300.ReadFits(drsfile))
213 return 31;
214
215 // -------------------------------------------------------
216
217 // Setup camera geometry
218 MGeomCamFAMOUS geom;
219
220 // ======================================================
221
222 // Setup task for reading the file
223 MRawFitsRead read;
224 read.LoadMap(mmap);
225 read.AddFile(datafile);
226
227 // Setup task which ensures sizes of containers consistent with camera geometry
228 MGeomApply apply;
229
230 // Setup task for DRS calibration
231 MDrsCalibApply drsapply;
232 drsapply.SetMaxNumPrevEvents(0); // Switched off step-correction -> crashes due to the requirement of N*9 ch
233
234 // Setup intercative task calling the functions defined above
235 MTaskInteractive mytask;
236 mytask.SetPreProcess(PreProcess);
237 mytask.SetProcess(Process);
238
239 // ======================================================
240
241 MTaskList tlist;
242
243 MParList plist;
244 plist.AddToList(&tlist);
245 plist.AddToList(&drscalib300);
246 plist.AddToList(&geom);
247
248 // ------------------ Setup eventloop and run analysis ---------------
249
250 tlist.AddToList(&read);
251 tlist.AddToList(&apply);
252 tlist.AddToList(&drsapply);
253 tlist.AddToList(&mytask);
254
255 // ------------------ Setup and run eventloop ---------------
256
257 MEvtLoop loop(gSystem->BaseName(datafile));
258 loop.SetParList(&plist);
259
260 if (!loop.Eventloop(100))
261 return 4;
262
263 // Print statistics information about your loop
264 tlist.PrintStatistics();
265
266 return 0;
267}
Note: See TracBrowser for help on using the repository browser.