/[PAMELA software]/quicklook/tracker/flight/src/TrkQLook_BASIC.cpp
ViewVC logotype

Contents of /quicklook/tracker/flight/src/TrkQLook_BASIC.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (show annotations) (download)
Wed May 10 09:57:36 2006 UTC (18 years, 8 months ago) by pam-fi
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +0 -0 lines
FILE REMOVED
.cpp files removed

1 #include <utils/yodaUtility.h>
2 #include "TrkFunctions.cpp"
3 #include <iostream>
4 #include <TPaveText.h>
5 #include <TLatex.h>
6 #include <TCanvas.h>
7 #include <TGraph.h>
8 #include <PscuHeader.h>
9 #include <EventHeader.h>
10 #include <RunHeaderEvent.h>
11 #include <TStyle.h>
12 #include <TObjString.h>
13 #include <physics/tracker/TrackerEvent.h>
14
15 /**
16 * TrkQLook_BASIC.cpp
17 *
18 * autor: D.Fedele
19 * version 1.0
20 * Parameters:
21 * base - the path to the root directory for the specific
22 * Pamela unpack session
23 * fromevent - first event to analyse
24 * toevent - last event to analyse
25 * outdir - total path of output file
26 * outfile - extension of output file (pdf,ps,gif,jpg)
27 *
28 */
29
30 void TrkQLook_BASIC(TString file,Int_t fromevent,Int_t toevent, TString outdir,TString outfile)
31 {
32 //
33 // obtain information about the data file and select the output dir
34 const string filepath=file.Data();
35 Int_t dwpos = filepath.find("DW_");
36 Int_t dwpos1 = filepath.find(".root");
37 TString fpath=(filepath.c_str());
38 TString base,ffile ;
39 stringcopy(ffile,fpath,dwpos,dwpos1);
40 stringcopy(base,fpath,0,dwpos);
41
42 TString out;
43 if(outdir.Length()==0){
44 out = base;
45 }else{
46 out = outdir;
47 }
48
49 //
50 // inizialise the variables and open the file
51 pamela::tracker::TrackerEvent *te=0;
52 pamela::EventHeader *eh=0,*eH=0;
53 pamela::RunHeaderEvent *reh=0;
54 pamela::PscuHeader *ph=0,*pH=0;
55
56 TFile *datafile = new TFile(file);
57 TTree *otr = (TTree*)datafile->Get("RunHeader");
58 otr->SetBranchAddress("Header",&eH);
59 otr->SetBranchAddress("RunHeader",&reh);
60 TTree *tr = (TTree*)datafile->Get("Physics");
61 tr->SetBranchAddress("Tracker",&te);
62 tr->SetBranchAddress("Header",&eh);
63
64
65 Long64_t nevent = tr->GetEntries();
66 Long64_t neventH = otr->GetEntries();
67 Int_t minevent=0;
68 Int_t maxevent=0;
69 // cout<<"Total n.events "<<nevent<<" e neventH= "<<neventH<<endl;
70
71 if (nevent<=0){
72 datafile->Close();
73 return;
74 }
75 if ( fromevent > toevent && toevent>0 ){
76 printf("It must be fromevent < toevent \n");
77 return;
78 }
79 if ( fromevent > nevent || fromevent < 0 ) {
80 printf("You can choose fromevent between 0 (all) and %lld \n",nevent);
81 return;
82 }
83 if ( toevent > nevent || toevent < 0 ) {
84 printf("You can choose toevent between 0 (all) and %lld \n",nevent);
85 return;
86 }
87 if ( fromevent == 0 ) {
88 minevent = 0;
89 maxevent = nevent;
90 } else {
91 minevent = fromevent;
92 if ( toevent > 0 ){
93 maxevent = toevent+1;
94 } else if (toevent > nevent) {
95 maxevent = nevent;
96 } else {
97 maxevent = toevent+1;
98 }
99 nevent=maxevent-minevent ;
100 }
101
102 //
103 // other variables definitions
104 stringstream oss,fromfile,isfile;
105 const Int_t size=nevent;
106 Int_t dsp=0,count=0,trk_cal_us[50];
107 Double_t perc;
108 Double_t yd[size*12], x[size+1];
109 Double_t yyd[size+1],yyb[size], xb[size];
110 ULong64_t HOBT[50];
111 TGraph *dataletime,*dataletime1;
112
113 for (Int_t i=0; i<50;i++){
114 HOBT[i]=0;
115 trk_cal_us[i]=0;
116 }
117
118 //***************************************************************************************
119 // LOOP on each event
120 //***************************************************************************************
121
122 //
123 // information about trk_calib_used
124 for (Int_t ev=0; ev<neventH; ev++){
125 otr->GetEntry(ev);
126 pH = eH->GetPscuHeader();
127 HOBT[ev]= pH->GetOrbitalTime();
128 trk_cal_us[ev]=reh->TRK_CALIB_USED;
129 }
130
131
132 //
133 // information about datalength
134 x[0]=(Double_t)HOBT[0];
135 for (Int_t ev=minevent; ev<maxevent; ev++){
136 tr->GetEntry(ev);
137 ph = eh->GetPscuHeader();
138
139 x[(ev-minevent)+1]= ph->GetOrbitalTime();
140 dsp=0;
141 for(Int_t i=0; i<12; i++){
142 dsp=te->DSPnumber[i]-1;
143 yd[(ev-minevent)*12+dsp]= te->DATAlength[i];
144 }
145 };
146 datafile->Close();
147
148
149 //****************************************************************************************
150 //Output figure
151 //****************************************************************************************
152
153 TCanvas *DataTimeCanv=new TCanvas("Tracker_Detector_Report_","",900,1200);
154 DataTimeCanv->SetFillColor(10);
155 DataTimeCanv->Range(0,0,100,100);
156 fromfile<<"TrackerQLookBasic File: "<<ffile;
157 isfile<<"DATALENGTH vs. ORBITALTIME ";
158
159 TLatex *t=new TLatex();
160 t->SetTextFont(32);
161 t->SetTextColor(1);
162 t->SetTextAlign(12);
163 t->SetTextSize(0.02);
164 t->DrawLatex(2.,98.7,fromfile.str().c_str());
165 TLatex *t1=new TLatex();
166 t1->SetTextFont(32);
167 t1->SetTextColor(1);
168 t1->SetTextAlign(12);
169 t1->SetTextSize(0.02);
170 t1->DrawLatex(70.,98.7,isfile.str().c_str());
171 fromfile.str("");
172 isfile.str("");
173
174
175 //*************************************************************************************
176 //book pads and histos
177 //***************************************************************************************
178 gStyle->SetLabelSize(0.06,"x");
179 gStyle->SetLabelSize(0.06,"y");
180 gStyle->SetStatFontSize(0.075);
181 gStyle->SetOptStat(1110);
182 gStyle->SetFillColor(10);
183 gStyle->SetTitleFontSize(0.1);
184 gStyle->SetTitleOffset(0.8,"y");
185 gStyle->SetTitleOffset(0.9,"x");
186 gStyle->SetTitleSize(0.06,"y");
187 gStyle->SetTitleSize(0.055,"x");
188
189 TPad *pad[12]; //pad for histos
190 Double_t posy = 0.95; // up y-coord - top pads
191 Double_t hpad = 0; // pad height
192 Double_t posx1=0; // left x-coord - pad column
193 Double_t posx0=0; // x-coord - column division
194 Double_t wrel = 0; // relative x size of first sub-column
195 Double_t marg = 0.004; // margin among pads
196
197 hpad = (posy-marg*11)/6;
198 wrel = (1-marg*4)/2;
199 stringstream title;
200 stringstream hid;
201
202 for(Int_t n = 0; n<12; n++) {
203 if ( (n+1)%2==1 ) {
204 if(n>1) posy = posy-(marg*2+hpad);
205 posx1 = marg;
206 posx0 = posx1 + wrel;
207 }
208 else {
209 posx1 = posx0 + 2*marg;
210 posx0 = posx1 + wrel;
211 }
212
213 /* -----------> pad for histograms */
214 pad[n] = new TPad("pad"," ",posx1,posy-hpad,posx0,posy,18,0,0);
215 };
216
217 TLine li;
218 li.SetLineColor(1);
219 li.SetLineStyle(1);
220 li.SetLineWidth(1);
221 //**********************************************************************************
222 // Fill Graphs and Histos
223 //**********************************************************************************
224 stringstream calus;
225 TLatex *t2=new TLatex();
226 t2->SetTextFont(32);
227 t2->SetTextColor(1);
228 t2->SetTextAlign(13);
229 t2->SetTextSize(0.08);
230
231 for (Int_t i=0; i<12 ; i++){
232 perc=0;
233 count=0;
234 yyd[0]=-10000.;
235 for (Int_t ev=minevent; ev<maxevent; ev++){
236 yyd[(ev-minevent)+1]=yd[12*(ev-minevent)+i];
237 if(i==6){
238 if(yyd[(ev-minevent)+1]>1500){
239 if(yyd[(ev-minevent)+1]<3075){
240 yyb[count]= yyd[(ev-minevent)+1];
241 xb[count]= x[(ev-minevent)+1];
242 count++;
243 }
244 }
245 }
246 else{
247 if(yyd[(ev-minevent)+1]>750){
248 if(yyd[(ev-minevent)+1]<3075){
249 yyb[count]= yyd[(ev-minevent)+1];
250 xb[count]= x[(ev-minevent)+1];
251 count++;
252 }
253 }
254 }
255 }
256
257 if((maxevent-minevent)>100) perc=(count*100)/(maxevent-minevent);
258 else perc=(count*10)/(maxevent-minevent);
259
260 Double_t min,max;
261 if((maxevent-minevent)<100){
262 min=x[0];
263 max=x[size]*1.0001;
264 }
265 else{
266 min=x[0];
267 max=x[size-1]*1.0005;
268 }
269 oss<<"DSP "<<i+1;
270 DataTimeCanv->cd();
271 if(perc>1) pad[i]->SetFillColor(2);
272 else pad[i]->SetFillColor(10);
273 pad[i]->SetFrameFillColor(10);
274 pad[i]->Draw();
275 pad[i]->cd();
276 dataletime= new TGraph((maxevent-minevent)+1,x,yyd);
277 dataletime->SetTitle(oss.str().c_str());
278 dataletime->GetXaxis()->SetTitle("OBT (ms)");
279 dataletime->GetXaxis()->CenterTitle();
280 dataletime->GetXaxis()->SetRangeUser(min,max);
281 dataletime->GetYaxis()->SetTitle("datalength (Word 13 bit)");
282 dataletime->GetYaxis()->CenterTitle();
283 dataletime->GetYaxis()->SetRangeUser(0,3500);
284 dataletime->SetMarkerStyle(21);
285 if((maxevent-minevent)<50) dataletime->SetMarkerSize(0.5);
286 else dataletime->SetMarkerSize(0.3);
287 dataletime->SetMarkerColor(1);
288 dataletime->Draw("ap");
289 if(perc>1){
290 dataletime1= new TGraph(count,xb,yyb);
291 dataletime1->SetMarkerStyle(21);
292 if((maxevent-minevent)<50) dataletime1->SetMarkerSize(0.5);
293 else dataletime1->SetMarkerSize(0.3);
294 dataletime1->SetMarkerColor(2);
295 dataletime1->Draw("psame");
296 }
297 li.SetLineColor(1);
298 li.SetLineStyle(1);
299 li.SetLineWidth(1);
300 if(i!=6) li.DrawLine(min,750,max,750);
301 else li.DrawLine(min,1500,max,1500);
302 li.DrawLine(min,3075,max,3075);
303 for(Int_t j=0;j<neventH;j++){
304 li.SetLineColor(12);
305 li.SetLineStyle(4);
306 li.SetLineWidth(1);
307 li.DrawLine(HOBT[j],0.,HOBT[j],3500.);
308 if(trk_cal_us[j]==104){
309 calus<<"D";
310 t2->SetTextColor(6);
311 t2->DrawLatex(HOBT[j],3350.,calus.str().c_str());
312 calus.str("");
313 }
314 else{
315 calus<<trk_cal_us[j];
316 t2->SetTextColor(3);
317 t2->DrawLatex(HOBT[j],3350.,calus.str().c_str());
318 calus.str("");
319 }
320 }
321 oss.str("");
322 };
323
324 DataTimeCanv->Update();
325
326 //*************************************************************************
327 // Save output Files
328 //*************************************************************************
329 stringstream out1;
330
331 // if(!strcmp(outfile.Data(),"pdf")){
332 // stringstream com;
333 // out1<<ffile<<"_TrkQLook_BASIC.ps";
334 // DataTimeCanv->Print(out+out1.str().c_str());
335 // com<<"ps2pdf13 "<<out<<ffile<<"_TrkQLook_BASIC.ps "<<out<<ffile<<"_TrkQLook_BASIC.pdf";
336 // system(com.str().c_str());
337 // com.str("");
338 // com<<"rm -f "<<out<<ffile<<"_TrkQLook_BASIC.ps ";
339 // system(com.str().c_str());
340 // com.str("");
341 // }
342 // else{
343 out1<<ffile<<"_TrkQLook_BASIC."<<outfile.Data();
344 DataTimeCanv->Print(out+out1.str().c_str());
345 out1.str("");
346 // }
347
348 dataletime->Delete();
349 delete DataTimeCanv;
350
351 gROOT->Reset();
352 // printf("... end of packets. \n");
353 return;
354 }

  ViewVC Help
Powered by ViewVC 1.1.23