/[PAMELA software]/quicklook/QLflightTmtc_Header/HeaderScan.cpp
ViewVC logotype

Contents of /quicklook/QLflightTmtc_Header/HeaderScan.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (show annotations) (download)
Mon Jun 26 09:42:17 2006 UTC (18 years, 5 months ago) by pam-rm2
Branch: MAIN
CVS Tags: v1r06, v1r07, v1r08, v1r09
Changes since 1.2: +31 -24 lines
modificato l'HeaderScan in modo da avere solo 2 canvases

1 /**
2 * Header Scan
3 * Author Nagni
4 * version 1.0
5 *
6 * Version 1.1 - 28 December 2004
7 * If outList does not exist the function exit to prompt
8 * If nevents = 0 the function exit to promt
9 *
10 * Version 1.2 - 3 January 2005
11 * Two canvases are created to see the graphs better
12 *
13 * Version 1.25 - 13 January 2005
14 * Changed Int_t to Float because of variable range size
15 * (UInt_t has been excluded beacuse of uncompatibility with TGraph)
16 *
17 * version 1.3 - 22 February 2005 - Nagni
18 * For compatibility with batch mode excution:
19 * 1) Added "include <iostream>" and "using namespace std"
20 * 2) Removed gROOT->Reset()
21 *
22 * Version 1.4
23 * Date 08 March 2005
24 * Added "format" parameter for saving the produced image in various formats
25 * (for a complete list of types refer to TPad::SaveAs method)
26 *
27 * Version 1.5
28 * Date 09 February 2006 - Marcelli
29 * Update to work with new Yoda output
30 *
31 * Version 1.6
32 * Date 27 February 2006 - Marcelli
33 * For compilation:
34 * Added function "int main(int argc, char* argv[])"
35 *
36 *
37 * Description: This script creates two canvases with five pads. The first pad shows packetID variable (for all packets) vs. OBT.
38 * The second pad shows the number of physic packets vs. OBT. The third pad shows the lenght of Physic packets (byte) vs. OBT.
39 * The fourth pad shows the packetcounter of physic packets vs. OBT. The fifth pad shows PacketCounter vs. File Offset.
40 *
41 * Parameters:
42 * TSTring base - the path to the root directory for the specific Pamela unpack session
43 * There is no default value, without this input the program will not run
44 * TString outDir - the path where to save the output image (Default = ./)
45 * TString format - the format which will be used fo rsave the produced images (Default = "jpg")
46 *
47 *
48 * Version 1.7
49 * Date 16 June 2006 - Malvezzi
50 *
51 * Description of changes:
52 * Implementation of the case: numebr of events <= 0.
53 * Remove graph "grPcktId1"; see PacketScan for the same information.
54 * Fixed bugs: for a large namber of events is not possible to have vectors, so I have subsituted graphs with histograms
55 * or divided the graphs in more than one canvas.
56 *
57 */
58
59
60 #include <fstream>
61 #include <math.h>
62 #include "TLatex.h"
63 #include "TF1.h"
64 #include "TPaveText.h"
65 #include "TMultiGraph.h"
66 #include <sstream>
67 #include <iostream>
68 #include "TString.h"
69 #include "TStyle.h"
70 #include "TFile.h"
71 #include "TList.h"
72 #include "TTree.h"
73 #include "TObjString.h"
74 #include "TCanvas.h"
75 #include "TGraph.h"
76 #include "TH1F.h"
77 #include "TGaxis.h"
78 #include "EventHeader.h"
79 #include "PscuHeader.h"
80
81 using namespace std;
82
83 void HeaderScan(TString base, TString outDir, TString format)
84 {
85
86 //------------------- Variables initilization -------------------------//
87 Long64_t nevents=0;
88 ULong_t lastime, firstime,obt, offset, lastoffset, firstoffset;
89 double obmin=0.;
90 double obmax=0.;
91 stringstream oss, oss1, oss2, oss3, noentries;
92 //------- load root file --------------
93 TFile *file = new TFile(base.Data());
94 if (!file){
95 printf("No such file in the directory has been found");
96 return;
97 }
98
99 TTree *PhysicsTr = (TTree*)file->Get("Physics");
100 TBranch *headBr = PhysicsTr->GetBranch("Header");
101
102 pamela::EventHeader *eh = 0;
103 pamela::PscuHeader *ph = 0;
104
105 PhysicsTr->SetBranchAddress("Header", &eh);
106
107 nevents = headBr->GetEntries();
108
109 TString filename = ((TObjString*)base.Tokenize('/')->Last())->GetString();
110 filename = ((TObjString*)filename.Tokenize('.')->First())->GetString();
111
112 //----------- If nevents < = 0 ---------------------------------/
113 if (nevents<=0) {
114 printf("nevents = %i \n", nevents);
115 printf(" \n");
116
117 TCanvas *canv = new TCanvas("No entries", "No entries ", 400, 200);
118 canv->SetFillColor(10);
119 canv->cd();
120
121 TLatex *l = new TLatex();
122 l->SetTextAlign(12);
123 l->SetTextSize(0.15);
124 l->SetTextColor(2);
125 noentries.str("");
126 noentries<< "HeaderScan_QL:";
127 l->DrawLatex(0.05, 0.7, noentries.str().c_str());
128 noentries.str("");
129 noentries<< "No Physics entries for this files";
130 l->DrawLatex(0.05, 0.5, noentries.str().c_str());
131
132 if (outDir == "./") {
133 oss.str("");
134 oss << filename.Data() << "_HeaderScan_QL." << format.Data();
135 } else {
136 oss.str("");
137 oss << outDir.Data() << filename.Data() << "_HeaderScan_QL." << format.Data();
138 }
139
140 canv->Update();
141 canv->SaveAs(oss.str().c_str());
142
143 return;
144 }
145
146 //-------------- to know the max and min OBT ----------------------------//
147 for (Int_t i = 0; i < nevents; i++){
148 headBr->GetEntry(i);
149 ph = eh->GetPscuHeader();
150 obt = ph->GetOrbitalTime();
151 offset=ph->GetFileOffset();
152 if(obt <= firstime) firstime=obt;
153 if(obt >= lastime) lastime=obt;
154 }
155
156 //*************************** Histograms ************************************************************//
157 //------------------------ First histogram -----------------------------------//
158 obmin=firstime;
159 obmax=lastime;
160 oss1.str("");
161 oss1 <<"File name= "<< filename.Data() <<". Start time= " << obmin << ", end time= "<< obmax <<" ms"<<". Physics Packet per minute";
162 Int_t nbin = (lastime-firstime)/60000;
163 TH1F *h1 = new TH1F ("histo1", oss1.str().c_str(), nbin, obmin, obmax);
164
165 //------------------------ Second histogram -----------------------------------//
166 oss2.str("");
167 oss2 << " Lenght of Physic packets;";
168 Int_t nint = (lastime-firstime);
169 TH1F *PcktLenght = new TH1F ("histo2", oss2.str().c_str(), nint, obmin, obmax);
170
171 //------------------------ Third histogram -----------------------------------//
172 oss3.str("");
173 oss3 << " Physics Counter";
174 TH1F *PcktCounter = new TH1F ("histo3", oss3.str().c_str(), nint, obmin, obmax);
175
176 //**************************************************************************************************//
177 //------- fill histograms ---------//
178 Int_t l=0;
179 for (Int_t i = 0; i < nevents; i++){
180 headBr->GetEntry(i);
181 ph = eh->GetPscuHeader();
182 h1->Fill(ph->GetOrbitalTime());
183 PcktLenght->Fill(ph->GetOrbitalTime(),ph->GetPacketLenght());
184 PcktCounter->Fill(ph->GetOrbitalTime(),ph->GetCounter());
185 }
186
187 //****************************** Canvases *******************************//
188 //TGaxis::SetMaxDigits(4);
189 //------------------- First Canvas --------------------------------//
190 TCanvas *finalCanv1 = new TCanvas("Header_1", base, 1280, 1024);
191 finalCanv1->Divide(1,3);
192 finalCanv1->SetFillColor(10);
193
194 finalCanv1->cd(1);
195 h1->SetStats(kFALSE);
196 h1->GetXaxis()->SetTitle("OBT (ms)");
197 h1->GetXaxis()->CenterTitle();
198 h1->GetXaxis()->SetLabelSize(0.04);
199 h1->GetYaxis()->SetTitle("Number of events ");
200 h1->GetYaxis()->CenterTitle();
201 h1->GetYaxis()->SetTitleSize(0.06);
202 h1->GetYaxis()->SetTitleOffset(0.8);
203 h1->Draw();
204
205 finalCanv1->cd(2);
206 PcktLenght->SetStats(kFALSE);
207 PcktLenght->GetXaxis()->SetTitle("OBT (ms)");
208 PcktLenght->GetXaxis()->CenterTitle();
209 PcktLenght->GetXaxis()->SetLabelSize(0.04);
210 PcktLenght->GetYaxis()->SetTitle("Lenght (byte)");
211 PcktLenght->GetYaxis()->CenterTitle();
212 PcktLenght->GetYaxis()->SetLabelSize(0.04);
213 PcktLenght->GetYaxis()->SetTitleSize(0.06);
214 PcktLenght->GetYaxis()->SetTitleOffset(0.8);
215 PcktLenght->SetMarkerColor(2);
216 PcktLenght->SetMarkerSize(.5);
217 PcktLenght->SetMarkerStyle(21);
218 PcktLenght->Draw("9p");
219
220 finalCanv1->cd(3);
221 PcktCounter->SetStats(kFALSE);
222 PcktCounter->GetXaxis()->SetTitle("OBT (ms)");
223 PcktCounter->GetXaxis()->SetTitleSize(0.05);
224 PcktCounter->GetXaxis()->CenterTitle();
225 PcktCounter->GetXaxis()->SetLabelSize(0.04);
226 PcktCounter->GetYaxis()->SetTitle("Counter");
227 PcktCounter->GetYaxis()->SetTitleSize(0.05);
228 PcktCounter->GetYaxis()->CenterTitle();
229 PcktCounter->GetYaxis()->SetLabelSize(0.04);
230 PcktCounter->GetYaxis()->SetTitleSize(0.06);
231 PcktCounter->GetYaxis()->SetTitleOffset(0.8);
232 PcktCounter->SetMarkerColor(4);
233 PcktCounter->SetMarkerSize(.5);
234 PcktCounter->SetMarkerStyle(21);
235 PcktCounter->Draw("9p");
236
237 oss.str("");
238 oss << outDir.Data() << filename.Data();
239 oss << "_HeaderScan_1." << format.Data();
240 finalCanv1->SaveAs(oss.str().c_str());
241
242 //------------- Graph PscuCounter vs FileOffset ---------------------------------
243 const Int_t size = 100000;
244 Int_t ev=0;
245 Double_t PscuCounter[size], FileOffset[size];
246 Int_t m=0;
247 Int_t pag= (nevents/100000)+1;
248
249 TMultiGraph *mg1 = new TMultiGraph();
250 oss1.str("");
251 oss1 << filename.Data() <<": PscuCounter vs FileOffset.";
252 mg1->SetTitle(oss1.str().c_str());
253
254 TCanvas *finalCanv2 = new TCanvas("Header_2", base, 1280, 1024);
255 finalCanv2->SetFillColor(10);
256
257 /////ciclo sulle pagine////////////////////
258 for (Int_t interval=0; interval<pag; interval++){
259
260 for (Int_t l = 0; l < size; l++){ //ciclo su un sottogruppo
261 headBr->GetEntry(ev+l);
262 ph = eh->GetPscuHeader();
263 PscuCounter[l]= ph->GetCounter();
264 FileOffset[l]=ph->GetFileOffset();
265 m=l;
266 }
267
268 TGraph *graph= new TGraph(m, FileOffset, PscuCounter);
269 graph->SetMarkerColor(3);
270 graph->SetMarkerSize(.5);
271 graph->SetMarkerStyle(21);
272 mg1->Add(graph);
273
274 ev=ev+100000;
275 }
276 finalCanv2->cd();
277 mg1->Draw("AP");
278 mg1->SetTitle(oss1.str().c_str());
279 mg1->GetXaxis()->SetTitle("File Offset");
280 mg1->GetXaxis()->CenterTitle();
281 mg1->GetXaxis()->SetTitleSize(0.04);
282 mg1->GetXaxis()->SetLabelSize(0.02);
283 mg1->GetYaxis()->SetTitle("Counter");
284 mg1->GetYaxis()->CenterTitle();
285 mg1->GetYaxis()->SetTitleSize(0.04);
286 mg1->GetYaxis()->SetLabelSize(0.02);
287
288
289 finalCanv2->Update();
290
291 oss1.str("");
292 oss1 << outDir.Data() << filename.Data();
293 oss1 << "_HeaderScan_2"<<"." << format.Data();
294
295 finalCanv2->SaveAs(oss1.str().c_str());
296
297 file->Close();
298
299 }
300
301 int main(int argc, char* argv[]){
302 TString path;
303 TString outDir = "./";
304 TString format = "jpg";
305 if (argc < 2){
306 printf("You have to insert at least the file to analyze \n");
307 printf("Try '--help' for more information. \n");
308 exit(1);
309 }
310 if (!strcmp(argv[1], "--help")){
311 printf( "Usage: HeaderScan FILE [OPTION] \n");
312 printf( "\t --help Print this help and exit \n");
313 printf( "\t -outDir[path] Path where to put the output [default ./] \n");
314 printf( "\t -format[jpg|ps|gif] Format for output files [default 'jpg'] \n");
315 exit(1);
316 }
317 path=argv[1];
318 for (int i = 2; i < argc; i++){
319 if (!strcmp(argv[i], "-outDir")){
320 if (++i >= argc){
321 printf( "-outDir needs arguments. \n");
322 printf( "Try '--help' for more information. \n");
323 exit(1);
324 }
325 else{
326 outDir = argv[i];
327 continue;
328 }
329 }
330 if (!strcmp(argv[i], "-format")){
331 if (++i >= argc){
332 printf( "-format needs arguments. \n");
333 printf( "Try '--help' for more information. \n");
334 exit(1);
335 }
336 else{
337 format = argv[i];
338 continue;
339 }
340 }
341 }
342 HeaderScan(argv[1], outDir, format);
343 }

  ViewVC Help
Powered by ViewVC 1.1.23