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

Annotation of /quicklook/QLflightTmtc_Header/HeaderScan.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations) (download)
Thu Jun 22 12:16:18 2006 UTC (18 years, 5 months ago) by pam-rm2
Branch: MAIN
CVS Tags: v1r05
Changes since 1.1: +196 -232 lines
implementate nuove canvases nell'HeaderScan

1 pam-rm2 1.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 pam-rm2 1.2 *
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 pam-rm2 1.1 */
58    
59    
60 pam-rm2 1.2 #include <fstream>
61     #include <math.h>
62     #include "TLatex.h"
63     #include "TF1.h"
64     #include "TPaveText.h"
65     #include "TMultiGraph.h"
66 pam-rm2 1.1 #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 pam-rm2 1.2 //------------------- Variables initilization -------------------------//
87     Long64_t nevents=0;
88     ULong_t lastime, firstime,obt;
89     double obmin=0.;
90     double obmax=0.;
91     Float_t maxoffset, minoffset;
92     stringstream oss, oss1, oss2, oss3, noentries;
93 pam-rm2 1.1 //------- load root file --------------
94     TFile *file = new TFile(base.Data());
95     if (!file){
96     printf("No such file in the directory has been found");
97     return;
98     }
99    
100 pam-rm2 1.2 TTree *PhysicsTr = (TTree*)file->Get("Physics");
101     TBranch *headBr = PhysicsTr->GetBranch("Header");
102    
103     pamela::EventHeader *eh = 0;
104     pamela::PscuHeader *ph = 0;
105    
106     PhysicsTr->SetBranchAddress("Header", &eh);
107    
108     nevents = headBr->GetEntries();
109 pam-rm2 1.1
110     TString filename = ((TObjString*)base.Tokenize('/')->Last())->GetString();
111     filename = ((TObjString*)filename.Tokenize('.')->First())->GetString();
112 pam-rm2 1.2
113     //----------- If nevents < = 0 ---------------------------------/
114     if (nevents<=0) {
115     printf("nevents = %i \n", nevents);
116     printf(" \n");
117    
118     TCanvas *canv = new TCanvas("No entries", "No entries ", 400, 200);
119     canv->SetFillColor(10);
120     canv->cd();
121    
122     TLatex *l = new TLatex();
123     l->SetTextAlign(12);
124     l->SetTextSize(0.15);
125     l->SetTextColor(2);
126     noentries.str("");
127     noentries<< "HeaderScan_QL:";
128     l->DrawLatex(0.05, 0.7, noentries.str().c_str());
129     noentries.str("");
130     noentries<< "No Physics entries for this files";
131     l->DrawLatex(0.05, 0.5, noentries.str().c_str());
132    
133     if (outDir == "./") {
134     oss.str("");
135     oss << filename.Data() << "_HeaderScan_QL." << format.Data();
136     } else {
137     oss.str("");
138     oss << outDir.Data() << filename.Data() << "_HeaderScan_QL." << format.Data();
139     }
140 pam-rm2 1.1
141 pam-rm2 1.2 canv->Update();
142     canv->SaveAs(oss.str().c_str());
143 pam-rm2 1.1
144 pam-rm2 1.2 return;
145 pam-rm2 1.1 }
146 pam-rm2 1.2
147     //-------------- to know the max and min OBT ----------------------------//
148     for (Int_t i = 0; i < nevents; i++){
149     headBr->GetEntry(i);
150     ph = eh->GetPscuHeader();
151     obt = ph->GetOrbitalTime();
152     if(obt <= firstime) firstime=obt;
153     if(obt >= lastime) lastime=obt;
154     }
155     //*************************** Histograms ************************************************************//
156     //------------------------ First histogram -----------------------------------//
157     obmin=firstime;
158     obmax=lastime;
159     oss1.str("");
160     oss1 <<"File name= "<< filename.Data() <<". Start time= " << obmin << ", end time= "<< obmax <<" ms"<<". Physics Packet per minute";
161     Int_t nbin = (lastime-firstime)/60000;
162     TH1F *h1 = new TH1F ("histo1", oss1.str().c_str(), nbin, obmin, obmax);
163    
164     //------------------------ Second histogram -----------------------------------//
165     oss2.str("");
166     oss2 << " Lenght of Physic packets;";
167     Int_t nint = (lastime-firstime);
168     TH1F *PcktLenght = new TH1F ("histo2", oss2.str().c_str(), nint, obmin, obmax);
169    
170     //------------------------ Third histogram -----------------------------------//
171     oss3.str("");
172     oss3 << " Physics Counter";
173     TH1F *PcktCounter = new TH1F ("histo3", oss3.str().c_str(), nint, obmin, obmax);
174    
175     //**************************************************************************************************//
176     //------- fill histograms ---------//
177    
178     for (Int_t i = 0; i < nevents; i++){
179     headBr->GetEntry(i);
180     ph = eh->GetPscuHeader();
181     h1->Fill(ph->GetOrbitalTime());
182     PcktLenght->Fill(ph->GetOrbitalTime(),ph->GetPacketLenght());
183     PcktCounter->Fill(ph->GetOrbitalTime(),ph->GetCounter());
184 pam-rm2 1.1 }
185 pam-rm2 1.2
186     //****************************** Canvases *******************************//
187     //TGaxis::SetMaxDigits(4);
188     //------------------- First Canvas --------------------------------//
189 pam-rm2 1.1 TCanvas *finalCanv1 = new TCanvas("Header_1", base, 1280, 1024);
190 pam-rm2 1.2 finalCanv1->Divide(1,3);
191 pam-rm2 1.1 finalCanv1->SetFillColor(10);
192    
193     finalCanv1->cd(1);
194 pam-rm2 1.2 h1->SetStats(kFALSE);
195     h1->GetXaxis()->SetTitle("OBT (ms)");
196 pam-rm2 1.1 h1->GetXaxis()->CenterTitle();
197 pam-rm2 1.2 h1->GetXaxis()->SetLabelSize(0.04);
198     h1->GetYaxis()->SetTitle("Number of events ");
199 pam-rm2 1.1 h1->GetYaxis()->CenterTitle();
200 pam-rm2 1.2 h1->GetYaxis()->SetTitleSize(0.06);
201     h1->GetYaxis()->SetTitleOffset(0.8);
202 pam-rm2 1.1 h1->Draw();
203    
204 pam-rm2 1.2 finalCanv1->cd(2);
205     PcktLenght->SetStats(kFALSE);
206     PcktLenght->GetXaxis()->SetTitle("OBT (ms)");
207     PcktLenght->GetXaxis()->CenterTitle();
208     PcktLenght->GetXaxis()->SetLabelSize(0.04);
209     PcktLenght->GetYaxis()->SetTitle("Lenght (byte)");
210     PcktLenght->GetYaxis()->CenterTitle();
211     PcktLenght->GetYaxis()->SetLabelSize(0.04);
212     PcktLenght->GetYaxis()->SetTitleSize(0.06);
213     PcktLenght->GetYaxis()->SetTitleOffset(0.8);
214     PcktLenght->SetMarkerColor(2);
215     PcktLenght->SetMarkerSize(.5);
216     PcktLenght->SetMarkerStyle(21);
217     PcktLenght->Draw("9p");
218    
219 pam-rm2 1.1 finalCanv1->cd(3);
220 pam-rm2 1.2 PcktCounter->SetStats(kFALSE);
221     PcktCounter->GetXaxis()->SetTitle("OBT (ms)");
222     PcktCounter->GetXaxis()->SetTitleSize(0.05);
223     PcktCounter->GetXaxis()->CenterTitle();
224     PcktCounter->GetXaxis()->SetLabelSize(0.04);
225     PcktCounter->GetYaxis()->SetTitle("Counter");
226     PcktCounter->GetYaxis()->SetTitleSize(0.05);
227     PcktCounter->GetYaxis()->CenterTitle();
228     PcktCounter->GetYaxis()->SetLabelSize(0.04);
229     PcktCounter->GetYaxis()->SetTitleSize(0.06);
230     PcktCounter->GetYaxis()->SetTitleOffset(0.8);
231     PcktCounter->SetMarkerColor(4);
232     PcktCounter->SetMarkerSize(.5);
233     PcktCounter->SetMarkerStyle(21);
234     PcktCounter->Draw("9p");
235    
236 pam-rm2 1.1 oss.str("");
237     oss << outDir.Data() << filename.Data();
238     oss << "_HeaderScan_1." << format.Data();
239     finalCanv1->SaveAs(oss.str().c_str());
240 pam-rm2 1.2 //------------- Graph PscuCounter vs FileOffset ---------------------------------
241     const Int_t size = 100000;
242     Int_t ev=0;
243     Double_t PscuCounter[size], FileOffset[size];
244     Int_t m=0;
245     Int_t pag= (nevents/100000)+1;
246    
247     TCanvas *finalCanv2 = new TCanvas("Header_2", base, 1280, 1024);
248     finalCanv2->SetFillColor(10);
249    
250     /////ciclo sulle pagine////////////////////
251     for (Int_t interval=0; interval<pag; interval++){
252    
253     for (Int_t l = 0; l < size; l++){ //ciclo su un sottogruppo
254     headBr->GetEntry(ev+l);
255     ph = eh->GetPscuHeader();
256     PscuCounter[l]= ph->GetCounter();
257     FileOffset[l]=ph->GetFileOffset();
258     m=l;
259     }
260    
261     oss1.str("");
262     oss1 << filename.Data() <<": PscuCounter vs FileOffset. Canvas n."<< (interval+1);
263     TGraph *graph= new TGraph(m, FileOffset, PscuCounter);
264    
265     finalCanv2->cd();
266     graph->SetTitle(oss1.str().c_str());
267     graph->GetXaxis()->SetTitle("File Offset");
268     graph->GetXaxis()->CenterTitle();
269     graph->GetXaxis()->SetTitleSize(0.04);
270     graph->GetXaxis()->SetLabelSize(0.02);
271     graph->GetYaxis()->SetTitle("Counter");
272     graph->GetYaxis()->CenterTitle();
273     graph->GetYaxis()->SetTitleSize(0.04);
274     graph->GetYaxis()->SetLabelSize(0.02);
275     graph->SetMarkerColor(3);
276     graph->SetMarkerSize(.5);
277     graph->SetMarkerStyle(21);
278     graph->Draw("AP");
279    
280     oss1.str("");
281     oss1 << outDir.Data() << filename.Data();
282     oss1 << "_HeaderScan_2_"<<(interval+1)<<"." << format.Data();
283    
284     finalCanv2->SaveAs(oss1.str().c_str());
285     finalCanv2->Clear();
286    
287     ev=ev+100000;
288     }
289    
290 pam-rm2 1.1 file->Close();
291    
292     }
293    
294     int main(int argc, char* argv[]){
295     TString path;
296     TString outDir = "./";
297     TString format = "jpg";
298     if (argc < 2){
299     printf("You have to insert at least the file to analyze \n");
300     printf("Try '--help' for more information. \n");
301     exit(1);
302     }
303     if (!strcmp(argv[1], "--help")){
304     printf( "Usage: HeaderScan FILE [OPTION] \n");
305     printf( "\t --help Print this help and exit \n");
306     printf( "\t -outDir[path] Path where to put the output [default ./] \n");
307     printf( "\t -format[jpg|ps|gif] Format for output files [default 'jpg'] \n");
308     exit(1);
309     }
310     path=argv[1];
311 pam-rm2 1.2 for (int i = 2; i < argc; i++){
312 pam-rm2 1.1 if (!strcmp(argv[i], "-outDir")){
313     if (++i >= argc){
314     printf( "-outDir needs arguments. \n");
315     printf( "Try '--help' for more information. \n");
316     exit(1);
317     }
318     else{
319     outDir = argv[i];
320     continue;
321     }
322 pam-rm2 1.2 }
323 pam-rm2 1.1 if (!strcmp(argv[i], "-format")){
324     if (++i >= argc){
325     printf( "-format needs arguments. \n");
326     printf( "Try '--help' for more information. \n");
327     exit(1);
328     }
329     else{
330     format = argv[i];
331     continue;
332     }
333     }
334     }
335     HeaderScan(argv[1], outDir, format);
336     }

  ViewVC Help
Powered by ViewVC 1.1.23