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