/[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.4 - (show annotations) (download)
Tue Jul 11 14:27:33 2006 UTC (18 years, 4 months ago) by pam-rm2
Branch: MAIN
CVS Tags: v2r00
Changes since 1.3: +123 -100 lines
Tmtc: tolta opzione C dai graph, Header: sostituiti histo con multigraph

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 //if(obt <= firstime) firstime=obt;
152 if(obt >= lastime) lastime=obt;
153 }
154
155 //------------------------ First histogram -----------------------------------//
156 headBr->GetEntry(0);
157 ph = eh->GetPscuHeader();
158 firstime = ph->GetOrbitalTime();
159 obmin=firstime;
160 obmax=lastime;
161
162 oss1.str("");
163 oss1 <<"File name= "<< filename.Data() <<". Start time= " << obmin << ", end time= "<< obmax <<" ms"<<". Physics Packet per minute";
164 Int_t nbin = (lastime-firstime)/60000;
165 TH1F *h1 = new TH1F ("histo1", oss1.str().c_str(), nbin, obmin, obmax);
166
167 //------------- Graph PscuCounter vs FileOffset ---------------------------------
168 const Int_t size = 10000;
169 Int_t ev=0;
170 Double_t PscuCounter[size], FileOffset[size], tempo[size], PcktLenght[size];
171 Int_t m=0;
172 Int_t pag= (nevents/10000)+1;
173
174 TMultiGraph *mg1 = new TMultiGraph();
175 oss1.str("");
176 oss1 << filename.Data() <<": PscuCounter vs FileOffset.";
177 mg1->SetTitle(oss1.str().c_str());
178
179 TMultiGraph *mg2 = new TMultiGraph();
180 oss1.str("");
181 oss1 << filename.Data() <<": OBT vs FileOffset.";
182 mg2->SetTitle(oss1.str().c_str());
183
184 TMultiGraph *mg3 = new TMultiGraph();
185 oss2.str("");
186 oss2 << filename.Data() <<": Lenght of Physic packets";
187 mg3->SetTitle(oss2.str().c_str());
188
189 TMultiGraph *mg4 = new TMultiGraph();
190 oss3.str("");
191 oss3 << filename.Data() <<": Physics Counter";
192 mg4->SetTitle(oss3.str().c_str());
193
194 TCanvas *finalCanv1 = new TCanvas("Header_1", base, 1280, 1024);
195 finalCanv1->Divide(1,3);
196 finalCanv1->SetFillColor(10);
197
198 TCanvas *finalCanv2 = new TCanvas("Header_2", base, 1280, 1024);
199 finalCanv2->Divide(1,2);
200 finalCanv2->SetFillColor(10);
201
202 /////ciclo sulle pagine////////////////////
203 for (Int_t interval=0; interval<pag; interval++){
204
205 for (Int_t l = 0; l < size; l++){ //ciclo su un sottogruppo
206 headBr->GetEntry(ev+l);
207 ph = eh->GetPscuHeader();
208 PscuCounter[l]= ph->GetCounter(); // = PcktCounter[l]
209 FileOffset[l]=ph->GetFileOffset();
210 tempo[l]=ph->GetOrbitalTime();
211 PcktLenght[l]=ph->GetPacketLenght();
212 h1->Fill(ph->GetOrbitalTime());
213 m=l;
214 }
215
216 TGraph *graph1= new TGraph(m, tempo, PcktLenght);
217 graph1->SetMarkerColor(2);
218 graph1->SetMarkerSize(.5);
219 graph1->SetMarkerStyle(21);
220 mg3->Add(graph1);
221
222 TGraph *graph2= new TGraph(m, tempo, PscuCounter);
223 graph2->SetMarkerColor(4);
224 graph2->SetMarkerSize(.5);
225 graph2->SetMarkerStyle(21);
226 mg4->Add(graph2);
227
228 TGraph *graph3= new TGraph(m, FileOffset, PscuCounter);
229 graph3->SetMarkerColor(3);
230 graph3->SetMarkerSize(.5);
231 graph3->SetMarkerStyle(21);
232 mg1->Add(graph3);
233
234 TGraph *graph4= new TGraph(m, FileOffset, tempo);
235 graph4->SetMarkerColor(kBlue);
236 graph4->SetMarkerSize(.5);
237 graph4->SetMarkerStyle(21);
238 mg2->Add(graph4);
239
240 ev=ev+10000;
241 }
242 //------------ First Canvas ---------------------//
243
244 finalCanv1->cd(1);
245 h1->SetStats(kFALSE);
246 h1->GetXaxis()->SetTitle("OBT (ms)");
247 h1->GetXaxis()->CenterTitle();
248 h1->GetXaxis()->SetLabelSize(0.04);
249 h1->GetYaxis()->SetTitle("Number of events ");
250 h1->GetYaxis()->CenterTitle();
251 h1->GetYaxis()->SetTitleSize(0.06);
252 h1->GetYaxis()->SetTitleOffset(0.8);
253 h1->Draw();
254
255 finalCanv1->cd(2);
256 mg3->Draw("AP");
257 mg3->GetXaxis()->SetTitle("OBT (ms)");
258 mg3->GetXaxis()->CenterTitle();
259 mg3->GetXaxis()->SetLabelSize(0.04);
260 mg3->GetYaxis()->SetTitle("Lenght (byte)");
261 mg3->GetYaxis()->CenterTitle();
262 mg3->GetYaxis()->SetLabelSize(0.04);
263 mg3->GetYaxis()->SetTitleSize(0.06);
264 mg3->GetYaxis()->SetTitleOffset(0.8);
265
266
267 finalCanv1->cd(3);
268 mg4->Draw("AP");
269 mg4->GetXaxis()->SetTitle("OBT (ms)");
270 mg4->GetXaxis()->SetTitleSize(0.05);
271 mg4->GetXaxis()->CenterTitle();
272 mg4->GetXaxis()->SetLabelSize(0.04);
273 mg4->GetYaxis()->SetTitle("Counter");
274 mg4->GetYaxis()->SetTitleSize(0.05);
275 mg4->GetYaxis()->CenterTitle();
276 mg4->GetYaxis()->SetLabelSize(0.04);
277 mg4->GetYaxis()->SetTitleSize(0.06);
278 mg4->GetYaxis()->SetTitleOffset(0.8);
279
280 finalCanv1->Update();
281
282 oss.str("");
283 oss << outDir.Data() << filename.Data();
284 oss << "_HeaderScan_1." << format.Data();
285 finalCanv1->SaveAs(oss.str().c_str());
286
287
288
289 //------------ Second Canvas ---------------------//
290 finalCanv2->cd(1);
291 mg1->Draw("AP");
292 mg1->GetXaxis()->SetTitle("File Offset");
293 mg1->GetXaxis()->CenterTitle();
294 mg1->GetXaxis()->SetTitleSize(0.05);
295 mg1->GetXaxis()->SetLabelSize(0.04);
296 mg1->GetYaxis()->SetTitle("Counter");
297 mg1->GetYaxis()->CenterTitle();
298 mg1->GetYaxis()->SetTitleSize(0.05);
299 mg1->GetYaxis()->SetLabelSize(0.04);
300
301 finalCanv2->cd(2);
302 mg2->Draw("AP");
303 mg2->GetXaxis()->SetTitle("File Offset");
304 mg2->GetXaxis()->CenterTitle();
305 mg2->GetXaxis()->SetTitleSize(0.05);
306 mg2->GetXaxis()->SetLabelSize(0.04);
307 mg2->GetYaxis()->SetTitle("OBT");
308 mg2->GetYaxis()->CenterTitle();
309 mg2->GetYaxis()->SetTitleSize(0.05);
310 mg2->GetYaxis()->SetLabelSize(0.04);
311
312 finalCanv2->Update();
313
314 oss1.str("");
315 oss1 << outDir.Data() << filename.Data();
316 oss1 << "_HeaderScan_2"<<"." << format.Data();
317
318 finalCanv2->SaveAs(oss1.str().c_str());
319
320 file->Close();
321
322 }
323
324 int main(int argc, char* argv[]){
325 TString path;
326 TString outDir = "./";
327 TString format = "jpg";
328 if (argc < 2){
329 printf("You have to insert at least the file to analyze \n");
330 printf("Try '--help' for more information. \n");
331 exit(1);
332 }
333 if (!strcmp(argv[1], "--help")){
334 printf( "Usage: HeaderScan FILE [OPTION] \n");
335 printf( "\t --help Print this help and exit \n");
336 printf( "\t -outDir[path] Path where to put the output [default ./] \n");
337 printf( "\t -format[jpg|ps|gif] Format for output files [default 'jpg'] \n");
338 exit(1);
339 }
340 path=argv[1];
341 for (int i = 2; i < argc; i++){
342 if (!strcmp(argv[i], "-outDir")){
343 if (++i >= argc){
344 printf( "-outDir needs arguments. \n");
345 printf( "Try '--help' for more information. \n");
346 exit(1);
347 }
348 else{
349 outDir = argv[i];
350 continue;
351 }
352 }
353 if (!strcmp(argv[i], "-format")){
354 if (++i >= argc){
355 printf( "-format needs arguments. \n");
356 printf( "Try '--help' for more information. \n");
357 exit(1);
358 }
359 else{
360 format = argv[i];
361 continue;
362 }
363 }
364 }
365 HeaderScan(argv[1], outDir, format);
366 }

  ViewVC Help
Powered by ViewVC 1.1.23