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

Diff of /quicklook/QLflightTmtc_Header/HeaderScan.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1.1.1 by pam-rm2, Fri Jun 16 10:11:54 2006 UTC revision 1.2 by pam-rm2, Thu Jun 22 12:16:18 2006 UTC
# Line 43  Line 43 
43  *                                      There is no default value, without this input the program will not run  *                                      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 = ./)  *              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")  *              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>  #include <sstream>
67  #include <iostream>  #include <iostream>
68  #include "TString.h"  #include "TString.h"
# Line 62  Line 78 
78  #include "EventHeader.h"  #include "EventHeader.h"
79  #include "PscuHeader.h"  #include "PscuHeader.h"
80    
   
81  using namespace std;  using namespace std;
82    
83  void HeaderScan(TString base, TString outDir, TString format)  void HeaderScan(TString base, TString outDir, TString format)
84  {  {
85    
86    TList *list = new TList;    //------------------- Variables initilization -------------------------//
87    Int_t numkey;    Long64_t nevents=0;
88    TObject *key = new TObject;    ULong_t lastime, firstime,obt;
89    const char *name;    double obmin=0.;
90    TTree* tr = new TTree;    double obmax=0.;
91    Long64_t totevents=0, totphysevents=0;    Float_t maxoffset, minoffset;
92    Float_t id;    stringstream oss, oss1, oss2, oss3, noentries;
   Long64_t nevents=0;  
   
93    //------- load root file --------------    //------- load root file --------------
   
94    TFile *file = new TFile(base.Data());    TFile *file = new TFile(base.Data());
     
95    if (!file){    if (!file){
96      printf("No such file in the directory has been found");      printf("No such file in the directory has been found");
97      return;      return;
98    }    }
   if (outDir == "" ) outDir = ".";  
     
   list = file->GetListOfKeys();  
99        
100    numkey = file->GetNkeys();    TTree *PhysicsTr = (TTree*)file->Get("Physics");
101        TBranch *headBr = PhysicsTr->GetBranch("Header");
102    pamela::EventHeader *eh=0;  
103    pamela::PscuHeader *ph=0;    pamela::EventHeader  *eh   = 0;
104        pamela::PscuHeader   *ph   = 0;
105    ///-----to know the total number f events end of physics events----//////  
106        PhysicsTr->SetBranchAddress("Header", &eh);
107    for (Int_t i=0; i<numkey; i++){  
108      key = list->At(i);    nevents = headBr->GetEntries();
     name=(key->GetName());  
     //cout<<name<<"\n";  
     tr = (TTree*)file->Get(name);  
     if (tr->IsZombie()) continue;  
     nevents = tr->GetEntries();  
     totevents+=nevents;  
     tr->SetBranchAddress("Header", &eh);    
     for (Int_t j = 0; j < nevents; j++){  
       tr->GetEntry(j);  
       ph = eh->GetPscuHeader();  
       if(ph->GetPacketId1() == 0x10) ++totphysevents;  
     }  
       
   }  
109    
   const Long64_t totalevents=totevents;  
   const Long64_t totalphysevents=totphysevents;  
     
   /////////////////////////////////////////////////  
     
110    TString filename = ((TObjString*)base.Tokenize('/')->Last())->GetString();    TString filename = ((TObjString*)base.Tokenize('/')->Last())->GetString();
111    filename = ((TObjString*)filename.Tokenize('.')->First())->GetString();    filename = ((TObjString*)filename.Tokenize('.')->First())->GetString();
112    stringstream oss;  
113    oss.str("");    //----------- If nevents < = 0 ---------------------------------/
114    oss << filename.Data();    if (nevents<=0) {
115          printf("nevents = %i \n", nevents);
116    Float_t obt[totalevents], pcktId[totalevents], pcktLenght[totalphysevents], pcktCounter[totalphysevents], offset[totalevents], allCounter[totalevents];      printf(" \n");
117    Float_t obtphysevents=0;  
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        
141        canv->Update();
142        canv->SaveAs(oss.str().c_str());
143    
144    totphysevents=0;      return;
   totevents=0;  
   for (Int_t i=0; i<numkey; i++){  
     key = list->At(i);  
     name=(char *)(key->GetName());  
     tr = (TTree*)file->Get(name);  
     if (tr->IsZombie()) continue;  
     tr->SetBranchAddress("Header", &eh);  
     nevents = tr->GetEntries();  
     for (Int_t j = 0; j < nevents; j++){  
       tr->GetEntry(j);    
       ph = eh->GetPscuHeader();  
       obt[j+totevents]=ph->GetOrbitalTime() ;  
       pcktId[j+totevents]=ph->GetPacketId1();  
       offset[j+totevents]=ph->GetFileOffset();  
       if(pcktId[j+totevents]==16){  
         pcktLenght[totphysevents]=ph->GetPacketLenght();  
         pcktCounter[totphysevents]=ph->GetCounter();  
         totphysevents=totphysevents+1;  
       }  
       offset[j+totevents]=ph->GetFileOffset();  
       allCounter[j+totevents]= ph->GetCounter();  
     }  
     totevents=totevents+nevents;  
145    }    }
146      
147        //-------------- to know the max and min OBT ----------------------------//
148    Float_t  mintime=obt[0], maxtime=obt[0], minlen=pcktLenght[0], maxlen=pcktLenght[0], mincount=pcktCounter[0], maxcount=pcktCounter[0];      for (Int_t i = 0; i < nevents; i++){
149          headBr->GetEntry(i);
150          ph = eh->GetPscuHeader();
151    for (Int_t t=0; t<totalevents; t++){      obt = ph->GetOrbitalTime();
152      if(obt[t]<mintime) mintime=obt[t];      if(obt <= firstime) firstime=obt;
153      if(obt[t]>maxtime) maxtime=obt[t];      if(obt >= lastime) lastime=obt;
154    }      }
155    for (Int_t t=0; t<totalphysevents; t++){    //*************************** Histograms ************************************************************//
156      if(pcktLenght[t]<=minlen) minlen=pcktLenght[t];    //------------------------ First histogram -----------------------------------//
157      if(pcktLenght[t]>=maxlen) maxlen=pcktLenght[t];    obmin=firstime;
158      if(pcktCounter[t]<=mincount) mincount=pcktCounter[t];    obmax=lastime;  
159      if(pcktCounter[t]>=maxcount) maxcount=pcktCounter[t];    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    }    }
185      
186        //****************************** Canvases *******************************//
187    Float_t    nbintime   = (maxtime-mintime)/1000;    //TGaxis::SetMaxDigits(4);
188    Float_t    nbinlen    = (maxlen-minlen)/100;    //------------------- First Canvas --------------------------------//
   Float_t    nbincount  = (maxcount-mincount)/100;  
     
     
   ///---------------------------TO GRAPH---------------------------------------------///  
189    TCanvas *finalCanv1 = new TCanvas("Header_1", base, 1280, 1024);    TCanvas *finalCanv1 = new TCanvas("Header_1", base, 1280, 1024);
190    TCanvas *finalCanv2 = new TCanvas("Header_2", base, 1280, 1024);    finalCanv1->Divide(1,3);
   finalCanv1->Divide(3);  
191    finalCanv1->SetFillColor(10);    finalCanv1->SetFillColor(10);
   finalCanv2->Divide(2);  
   finalCanv2->SetFillColor(10);  
192    
     
   TGraph *grPcktId1 = new TGraph(totalevents, obt, pcktId);  
   TGraph *grPcktLenght = new TGraph(totalevents, obt, pcktLenght);  
   TGraph *grPcktCounter = new TGraph(totalevents, obt, pcktCounter);  
   TGraph *grFileOffset = new TGraph(totalevents, offset, allCounter);  
     
   TGaxis::SetMaxDigits(3);  
   
   //-----canvas 1-------------------------------///  
193    finalCanv1->cd(1);    finalCanv1->cd(1);
194        h1->SetStats(kFALSE);
195    stringstream oss1;    h1->GetXaxis()->SetTitle("OBT   (ms)");
   oss1.str("");  
   oss1 << "OBT (ms) with t0 = " << mintime << "ms";  
     
   gStyle->SetTitleH(0.06);  
   grPcktId1->SetTitle(oss.str().c_str());  
   grPcktId1->GetXaxis()->SetTitle(oss1.str().c_str());  
   grPcktId1->GetXaxis()->CenterTitle();  
   grPcktId1->GetXaxis()->SetLabelSize(0.03);  
   grPcktId1->GetYaxis()->SetTitle("Packet ID");  
   grPcktId1->GetYaxis()->CenterTitle();  
   grPcktId1->SetMarkerSize(4);  
   grPcktId1->Draw("AP");  
     
     
   finalCanv1->cd(2);  
   oss1.str("");  
   oss1 << "OBT (min) with t0 = " << mintime << "ms";  
     
   TH1F *h1 = new TH1F ("h1", oss.str().c_str(), (int)(nbintime/60), mintime, maxtime);  
     
   for (Int_t i=0; i<numkey; i++){  
     key = list->At(i);  
     name=(char *)(key->GetName());  
     tr = (TTree*)file->Get(name);  
     if (tr->IsZombie()) continue;  
     tr->SetBranchAddress("Header", &eh);  
     nevents = tr->GetEntries();  
     for (Int_t j = 0; j < nevents; j++){  
       tr->GetEntry(j);    
       ph = eh->GetPscuHeader();  
       if((ph->GetPacketId1()) == 16){  
         obtphysevents=ph->GetOrbitalTime();  
         h1->Fill(obtphysevents);  
       }  
     }  
   }  
     
   h1->SetMarkerStyle(6);  
   h1->GetXaxis()->SetTitle(oss1.str().c_str());  
196    h1->GetXaxis()->CenterTitle();    h1->GetXaxis()->CenterTitle();
197    h1->GetXaxis()->SetLabelSize(0.03);    h1->GetXaxis()->SetLabelSize(0.04);
198    h1->GetYaxis()->SetTitle("number of Physic packets");    h1->GetYaxis()->SetTitle("Number of events ");
199    h1->GetYaxis()->CenterTitle();    h1->GetYaxis()->CenterTitle();
200      h1->GetYaxis()->SetTitleSize(0.06);
201      h1->GetYaxis()->SetTitleOffset(0.8);
202    h1->Draw();    h1->Draw();
203        
     
   finalCanv1->cd(3);  
   oss1.str("");  
   oss1 << "OBT (ms) with t0 = " << mintime << "ms";  
     
   grPcktLenght->SetTitle(oss.str().c_str());  
   grPcktLenght->GetXaxis()->SetTitle(oss1.str().c_str());  
   grPcktLenght->GetXaxis()->CenterTitle();  
   grPcktLenght->GetXaxis()->SetLabelSize(0.03);  
   grPcktLenght->GetYaxis()->SetTitle("Lenght of Physic packets   (byte)");  
   grPcktLenght->GetYaxis()->CenterTitle();  
   grPcktLenght->GetYaxis()->SetLabelSize(0.03);  
   grPcktLenght->SetMarkerSize(4);  
   grPcktLenght->Draw("AP");  
     
     
204    finalCanv1->cd(2);    finalCanv1->cd(2);
205    h1->Draw();    PcktLenght->SetStats(kFALSE);
206        PcktLenght->GetXaxis()->SetTitle("OBT    (ms)");
207    finalCanv1->Update();    PcktLenght->GetXaxis()->CenterTitle();
208        PcktLenght->GetXaxis()->SetLabelSize(0.04);
209        PcktLenght->GetYaxis()->SetTitle("Lenght  (byte)");
210    ///---------canvas 2-----------------------------//    PcktLenght->GetYaxis()->CenterTitle();
211    finalCanv2->cd(1);    PcktLenght->GetYaxis()->SetLabelSize(0.04);
212        PcktLenght->GetYaxis()->SetTitleSize(0.06);
213    grPcktCounter->SetTitle(oss.str().c_str());    PcktLenght->GetYaxis()->SetTitleOffset(0.8);
214    grPcktCounter->GetXaxis()->SetTitle(oss1.str().c_str());    PcktLenght->SetMarkerColor(2);
215    grPcktCounter->GetXaxis()->SetTitleSize(0.04);    PcktLenght->SetMarkerSize(.5);
216    grPcktCounter->GetXaxis()->CenterTitle();    PcktLenght->SetMarkerStyle(21);
217    grPcktCounter->GetXaxis()->SetLabelSize(0.03);    PcktLenght->Draw("9p");
218    grPcktCounter->GetYaxis()->SetTitle("PacketCounter of Physic packets");  
219    grPcktCounter->GetYaxis()->SetTitleSize(0.04);    finalCanv1->cd(3);
220    grPcktCounter->GetYaxis()->CenterTitle();    PcktCounter->SetStats(kFALSE);
221    grPcktCounter->GetYaxis()->SetLabelSize(0.03);    PcktCounter->GetXaxis()->SetTitle("OBT    (ms)");
222    grPcktCounter->SetMarkerSize(4);    PcktCounter->GetXaxis()->SetTitleSize(0.05);
223    grPcktCounter->SetMinimum(mincount);    PcktCounter->GetXaxis()->CenterTitle();
224    grPcktCounter->SetMaximum(maxcount);    PcktCounter->GetXaxis()->SetLabelSize(0.04);
225    grPcktCounter->Draw("AP");    PcktCounter->GetYaxis()->SetTitle("Counter");
226        PcktCounter->GetYaxis()->SetTitleSize(0.05);
227    finalCanv2->cd(2);    PcktCounter->GetYaxis()->CenterTitle();
228        PcktCounter->GetYaxis()->SetLabelSize(0.04);
229    grFileOffset->SetTitle(oss.str().c_str());    PcktCounter->GetYaxis()->SetTitleSize(0.06);
230    grFileOffset->GetXaxis()->SetTitle("File Offset");    PcktCounter->GetYaxis()->SetTitleOffset(0.8);
231    grFileOffset->GetXaxis()->CenterTitle();    PcktCounter->SetMarkerColor(4);
232    grFileOffset->GetXaxis()->SetTitleSize(0.04);    PcktCounter->SetMarkerSize(.5);
233    grFileOffset->GetXaxis()->SetLabelSize(0.03);    PcktCounter->SetMarkerStyle(21);
234    grFileOffset->GetYaxis()->SetTitle("Packet counter");    PcktCounter->Draw("9p");
235    grFileOffset->GetYaxis()->CenterTitle();  
   grFileOffset->GetYaxis()->SetTitleSize(0.04);  
   grFileOffset->GetYaxis()->SetLabelSize(0.03);  
   grFileOffset->SetMarkerSize(4);  
   grFileOffset->Draw("AP");  
     
   finalCanv1->Update();  
     
     
   //-------to save---------------------------///  
236    oss.str("");    oss.str("");
   oss1.str("");  
     
237    oss << outDir.Data() << filename.Data();    oss << outDir.Data() << filename.Data();
   oss1 << outDir.Data() << filename.Data();  
   
238    oss  << "_HeaderScan_1." << format.Data();    oss  << "_HeaderScan_1." << format.Data();
   oss1 << "_HeaderScan_2." << format.Data();  
     
239    finalCanv1->SaveAs(oss.str().c_str());    finalCanv1->SaveAs(oss.str().c_str());
240    finalCanv2->SaveAs(oss1.str().c_str());    //------------- 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    file->Close();    file->Close();
291        
292  }  }
293    
   
   
294  int main(int argc, char* argv[]){  int main(int argc, char* argv[]){
295    TString path;    TString path;
296    TString outDir     = "./";    TString outDir     = "./";
297    TString format     = "jpg";    TString format     = "jpg";
       
298   if (argc < 2){   if (argc < 2){
299      printf("You have to insert at least the file to analyze \n");      printf("You have to insert at least the file to analyze \n");
300      printf("Try '--help' for more information. \n");      printf("Try '--help' for more information. \n");
301      exit(1);      exit(1);
302    }      }  
   
303    if (!strcmp(argv[1], "--help")){    if (!strcmp(argv[1], "--help")){
304          printf( "Usage: HeaderScan FILE [OPTION] \n");          printf( "Usage: HeaderScan FILE [OPTION] \n");
305          printf( "\t --help                 Print this help and exit \n");          printf( "\t --help                 Print this help and exit \n");
# Line 334  int main(int argc, char* argv[]){ Line 307  int main(int argc, char* argv[]){
307          printf( "\t -format[jpg|ps|gif]    Format for output files [default 'jpg'] \n");          printf( "\t -format[jpg|ps|gif]    Format for output files [default 'jpg'] \n");
308          exit(1);          exit(1);
309    }    }
   
     
310    path=argv[1];    path=argv[1];
311      for (int i = 2; i < argc; i++){
   for (int i = 2; i < argc; i++){  
     
312      if (!strcmp(argv[i], "-outDir")){      if (!strcmp(argv[i], "-outDir")){
313        if (++i >= argc){        if (++i >= argc){
314          printf( "-outDir needs arguments. \n");          printf( "-outDir needs arguments. \n");
# Line 350  int main(int argc, char* argv[]){ Line 319  int main(int argc, char* argv[]){
319          outDir = argv[i];          outDir = argv[i];
320          continue;          continue;
321        }        }
322      }      }  
       
323      if (!strcmp(argv[i], "-format")){      if (!strcmp(argv[i], "-format")){
324        if (++i >= argc){        if (++i >= argc){
325          printf( "-format needs arguments. \n");          printf( "-format needs arguments. \n");
# Line 363  int main(int argc, char* argv[]){ Line 331  int main(int argc, char* argv[]){
331          continue;          continue;
332        }        }
333      }      }
     
   
334    }    }
   
335    HeaderScan(argv[1], outDir, format);    HeaderScan(argv[1], outDir, format);
   
336  }  }

Legend:
Removed from v.1.1.1.1  
changed lines
  Added in v.1.2

  ViewVC Help
Powered by ViewVC 1.1.23