/[PAMELA software]/quicklook/QLflightS4_ND/S4_Calibration_QL.cpp
ViewVC logotype

Contents of /quicklook/QLflightS4_ND/S4_Calibration_QL.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (show annotations) (download)
Tue Sep 5 13:06:41 2006 UTC (18 years, 3 months ago) by pam-rm2
Branch: MAIN
CVS Tags: v2r03, v2r02, v2r01, v2r00
Changes since 1.3: +134 -74 lines
fissati crash S4_QL; modificato S4_Calibration_QL secondo le indicazioni di Volodia; corretto il build.xml

1 /**
2 * S4 Calibration Quick Look
3 * Author Marcelli-Malvezzi
4 * Version 1.00 - 27 February 2006
5 *
6 * Description: The aim of S4 Calibration QL software is to keep under control the bahaviour of S4 Calibration.
7 * It creates only one output canvas relative to the time behaviour of collected calibration data.
8 * See documentation for a more detailed description of the output.
9 *
10 * Parameters:
11 * TSTring base - the path to the root directory for the specific Pamela unpack session
12 * There is no default value, without this input the program will not run
13 * TString outDir - the path where to save the output image (Default = ./)
14 * TString format - the format which will be used fo rsave the produced images (Default = "jpg")
15 *
16 *
17 * Version 1.1 - June 2006
18 * Fixed bugs: for a large namber of events is not possible to initialize vectors, so all graphs have been converted in histograms
19 *
20 * Known bugs: it is no possible to choise the figure format
21 *
22 * Version 1.2 - August 2006
23 * Fixed bugs: is possible to choise figure format; all calibration are drown
24 **************/
25
26 #include <fstream>
27 #include <iostream>
28 #include <iostream>
29 #include <sstream>
30 #include "TStyle.h"
31 #include "TFile.h"
32 #include "TList.h"
33 #include "TTree.h"
34 #include "TLatex.h"
35 #include "TObjString.h"
36 #include "TCanvas.h"
37 #include "TGraph.h"
38 #include "TH1F.h"
39 #include "TF1.h"
40 #include "TGaxis.h"
41 #include "TString.h"
42 #include "TPaveText.h"
43 #include "TMultiGraph.h"
44 #include "TGraphErrors.h"
45 #include "EventHeader.h"
46 #include "PscuHeader.h"
47 #include "physics/S4/S4Event.h"
48 #include "CalibS4Event.h"
49 #include "tmtc/TmtcEvent.h"
50 #include "tmtc/TmtcRecord.h"
51
52 using namespace std;
53
54 //--------------- root function ----------------------------------
55
56 void S4_Calibration_QL(TString base, TString outDir, TString format){
57
58 //--------------- Variables initialization -----------------------------------//
59 const Int_t channels = 4096;
60 Double_t calib_1_MEAN;
61 Double_t calib_2_MEAN;
62 Double_t calib_4_MEAN;
63 Double_t calib_1_RMS;
64 Double_t calib_2_RMS;
65 Double_t calib_4_RMS;
66 Double_t calib_1=0, calib_2=0, calib_4=0;
67 Double_t obt;
68 TString status;
69 Int_t IPM1status, IPM2status;
70 ULong_t lastime, firstime, obt1;
71 double obmin=0.;
72 double obmax=0.;
73 double limitdown=0;
74 double limitup=0;
75
76
77 //------------------------- Open data file -------------------------------------//
78 TFile *file =new TFile(base.Data()) ;
79 TString filename = ((TObjString*)base.Tokenize('/')->Last())->GetString();
80 filename = ((TObjString*)filename.Tokenize('.')->First())->GetString();
81
82 if (!file){
83 printf("No such file in the directory has been found");
84 return;
85 }
86
87 TTree *CalibS4tr = (TTree*)file->Get("CalibS4");
88 TBranch *S4Br = CalibS4tr->GetBranch("CalibS4");
89 TBranch *headBr = CalibS4tr->GetBranch("Header");
90 TTree *tmtcTr = (TTree*)file->Get("Tmtc");
91 TBranch *tmtcBr = tmtcTr->GetBranch("Tmtc");
92
93 pamela::TmtcEvent *tme = 0;
94 pamela::TmtcRecord *tmr = 0;
95 pamela::S4::S4Event *s4Record;
96 pamela::CalibS4Event *s4Event = new pamela::CalibS4Event();
97 pamela::EventHeader *eh = 0;
98 pamela::PscuHeader *ph = 0;
99
100 CalibS4tr->SetBranchAddress("CalibS4", &s4Event);
101 CalibS4tr->SetBranchAddress("Header", &eh);
102 tmtcTr->SetBranchAddress("Tmtc", &tme);
103 Long64_t nevents= CalibS4tr->GetEntries();
104 Long64_t neventstmtc = tmtcBr->GetEntries();
105
106 if (neventstmtc<=0) {
107 printf("Tmtc packet: nevents = %i\n", nevents);
108 printf(" No info about kind of calibration (hot or cold) \n");
109 }
110 //----------------- if nevents = 0 ----------------------------------------------//
111 if (nevents<=0){
112 cout<<"WARNING: No Entries, RETURN"<<"\n";
113
114 TCanvas *canvas4 = new TCanvas("No entries", "No entries ", 400, 200);
115 canvas4->SetFillColor(10);
116 canvas4->cd();
117
118 TLatex *l = new TLatex();
119 l->SetTextAlign(12);
120 l->SetTextSize(0.15);
121 l->SetTextColor(2);
122 stringstream oss, noentries;
123 noentries.str("");
124 noentries<< "S4_Calibration_QL:";
125 l->DrawLatex(0.05, 0.7, noentries.str().c_str());
126 noentries.str("");
127 noentries<< "No entries for this files";
128 l->DrawLatex(0.05, 0.5, noentries.str().c_str());
129
130 if (outDir== "./") {
131 oss.str("");
132 oss << filename.Data() << "_S4_Calibration_QL." << format.Data();
133 } else {
134 oss.str("");
135 oss << outDir.Data() << filename.Data() << "_S4_Calibration_QL." << format.Data();
136 }
137
138 canvas4->Update();
139 canvas4->SaveAs(oss.str().c_str());
140 return;
141 }
142
143 //---------------Look for configuration hot or cold -----------------------//
144 if(neventstmtc!=0){
145 Int_t recordstot=0;
146 for (Int_t i = 0; i < neventstmtc; i++){
147 tmtcBr->GetEntry(i);
148 Long64_t tmpSizetmtc = tme->Records->GetEntries();
149 recordstot=recordstot+tmpSizetmtc;
150 }
151 const Int_t lungmax=16*recordstot;
152 Double_t xrecordobtcc[lungmax], yccdiagacq[lungmax], xrecordobtcc_1[lungmax], yccdiagacq_1[lungmax];
153 recordstot=0;
154 for (Int_t i = 0; i < neventstmtc; i++){
155 tmtcBr->GetEntry(i);
156 Long64_t tmpSizetmtc = tme->Records->GetEntries();
157 Int_t size_b = tmpSizetmtc;
158 for (Int_t j = 0; j < size_b; j++){
159 tmr = (pamela::TmtcRecord*)tme->Records->At(j);
160 for (Int_t k =0; k <16; k++){
161 yccdiagacq[16*recordstot+16*j+k] = (((tmr->TM_DIAG_AND_BILEVEL_ACQ)>>(15-k))&0x0001);
162 xrecordobtcc[16*recordstot+16*j+k] = tmr->TM_RECORD_OBT;
163 }
164 }
165 recordstot=recordstot+tmpSizetmtc;
166 }
167 Int_t riftime = recordstot/2;
168 //CC (0=IPM1=hot; 1=IPM2=cold for S4 calibration)
169 for (Int_t k =0; k<16; k++){
170 for (Int_t i = 0; i < recordstot; i++){
171 yccdiagacq_1[i]= yccdiagacq[16*i+k];
172 xrecordobtcc_1[i]= xrecordobtcc[16*i+k];
173 }
174 if (k==0) IPM1status=(Int_t)yccdiagacq_1[riftime];
175 if (k==1) IPM2status=(Int_t)yccdiagacq_1[riftime];
176 }
177 if (IPM1status==0 && IPM2status==1){
178 status="CONFIGURATION: HOT";
179 }
180 if (IPM1status==1 && IPM2status==0){
181 status="CONFIGURATION: COLD";
182 }
183 }else{
184 status=" No info about kind of calibration (hot or cold)";
185 }
186
187 //----------- search max and min OBT -----------------------------------------------------//
188 headBr->GetEntry(0);
189 ph = eh->GetPscuHeader();
190 firstime = ph->GetOrbitalTime();
191 headBr->GetEntry(nevents-1);
192 ph = eh->GetPscuHeader();
193 lastime = ph->GetOrbitalTime();
194 obmin=firstime;
195 obmax=lastime;
196 if(nevents < 2){
197 for(Int_t kk = 0; kk<nevents; kk++){
198 headBr->GetEntry(kk);
199 ph = eh->GetPscuHeader();
200 if(obmin >= ph->GetOrbitalTime())obmin=ph->GetOrbitalTime();
201 if(obmax <= ph->GetOrbitalTime())obmax=ph->GetOrbitalTime();
202 }
203 limitdown= obmin - 1000000;
204 limitup= obmax + 1000000;
205 }else{
206 for(Int_t kk = 0; kk<nevents; kk++){
207 headBr->GetEntry(kk);
208 ph = eh->GetPscuHeader();
209 //cout<<"OrbitalTime()"<<ph->GetOrbitalTime()<<"\n";
210 if(obmin >= ph->GetOrbitalTime())obmin=ph->GetOrbitalTime();
211 if(obmax <= ph->GetOrbitalTime())obmax=ph->GetOrbitalTime();
212 }
213 limitdown=obmin;
214 limitup=obmax;
215 }
216 //------------- Create and fill histograms -------------------------------------------//
217 stringstream oss1;
218 oss1.str("");
219 oss1 << "S4 Calibration: "<< filename.Data();
220 TH1F *calibS4_1 =new TH1F("S4-1", oss1.str().c_str(), channels, 0, channels);
221 TH1F *calibS4_2 =new TH1F("S4-2", oss1.str().c_str(), channels, 0, channels);
222 TH1F *calibS4_4 =new TH1F("S4-3", oss1.str().c_str(), channels, 0, channels);
223
224 stringstream oss;
225 oss.str("");
226 oss << "S4_Calibration_QL: "<< filename.Data();
227 const Int_t size = nevents;
228 //cout<<"size "<<size <<"\n";
229 TH1F *cal1 =new TH1F("calibS4_1", oss.str().c_str(), size, obmin-1000000, obmax+ 1000000);
230 TH1F *cal2 =new TH1F("calibS4_2", oss.str().c_str(), size, obmin-1000000, obmax+ 1000000);
231 TH1F *cal4 =new TH1F("calibS4_4", oss.str().c_str(), size, obmin-1000000, obmax+ 1000000);
232
233 for(Int_t k = 0; k<nevents; k++){
234 headBr->GetEntry(k);
235 S4Br->GetEntry(k);
236 ph = eh->GetPscuHeader();
237 Int_t tmpSize = s4Event->Records->GetEntries();
238 for (Int_t j = 0; j < 4; j++){
239 for (Int_t i = 0; i < 128; i++){
240 s4Record = (pamela::S4::S4Event*)s4Event->Records->At((j*128 + i));
241 switch (j) {
242 case 0 :{
243 calibS4_1->Fill(s4Record->S4_DATA);
244 calib_1 = calib_1+s4Record->S4_DATA;
245 break;
246 }
247 case 1 :{
248 calibS4_2->Fill(s4Record->S4_DATA);
249 calib_2 = calib_2+s4Record->S4_DATA;
250 break;
251 }
252 case 3 :{
253 calibS4_4->Fill(s4Record->S4_DATA);
254 calib_4 = calib_4+s4Record->S4_DATA;
255 break;
256 }
257 }
258 }
259 }
260
261 //obt=ph->GetOrbitalTime();
262 calib_1_MEAN=calib_1/128;
263 //calib_1_RMS=calibS4_1->GetRMS(1);
264 calib_2_MEAN=calib_2/128;
265 //calib_2_RMS=calibS4_2->GetRMS(1);
266 calib_4_MEAN=calib_4/128;
267 //calib_4_RMS=calibS4_4->GetRMS(1);
268 cal1->Fill(ph->GetOrbitalTime(),calib_1_MEAN);
269 cal2->Fill(ph->GetOrbitalTime(),calib_2_MEAN);
270 cal4->Fill(ph->GetOrbitalTime(),calib_4_MEAN);
271 calib_1=calib_2=calib_4=0;
272
273 }
274
275 //----------------- Create and draw canvas -----------------------------------------//
276 TCanvas *finalCanv = new TCanvas("S4Calib","Calibration_QL", 1280, 1024);
277 finalCanv->SetFillColor(10);
278 finalCanv->Divide(2,2);
279
280 finalCanv->cd(1);
281 gPad->SetLogy();
282 cal1->SetStats(kFALSE);
283 cal1->SetMarkerSize(.5);
284 cal1->SetMarkerStyle(21);
285 cal1->SetMarkerColor(3);
286 cal1->SetMinimum(1);
287 cal1->SetMaximum(10000);
288 cal1->GetYaxis()->SetTitle("S4 mean value (ADC)");
289 cal1->GetYaxis()->SetTitleSize(0.03);
290 cal1->GetYaxis()->SetTitleOffset(1);
291 cal1->GetYaxis()->CenterTitle();
292 cal1->GetYaxis()->SetLabelSize(0.02);
293 cal1->GetXaxis()->CenterTitle();
294 cal1->GetXaxis()->SetTitleSize(0.03);
295 cal1->GetXaxis()->SetTitleOffset(1);
296 cal1->GetXaxis()->SetLabelSize(0.02);
297 cal1->GetXaxis()->SetTitle("OBT (ms)");
298 cal1->Draw("9p");
299
300 cal2->SetStats(kFALSE);
301 cal2->SetMarkerSize(.5);
302 cal2->SetMarkerStyle(21);
303 cal2->SetMarkerColor(6);
304 cal2->SetMinimum(1);
305 cal2->SetMaximum(10000);
306 cal2->Draw("9psame");
307
308 cal4->SetStats(kFALSE);
309 cal4->SetMarkerSize(.5);
310 cal4->SetMarkerStyle(21);
311 cal4->SetMarkerColor(4);
312 cal4->SetMinimum(1);
313 cal4->SetMaximum(10000);
314 cal4->Draw("9psame");
315 if (IPM1status==0 && IPM2status==1){ ////hot configuration
316 TF1 *func1 = new TF1("func1", "1560"); ///valore di riferimento 1300
317 //func1->SetRange(obmin, obmax);
318 func1->SetRange(limitdown, limitup);
319 func1->SetLineColor(4);
320 func1->SetLineStyle(1);
321 func1->SetLineWidth(3);
322 func1->Draw("same");
323 TF1 *func2 = new TF1("func2", "1040"); ///valore di riferimento 1300
324 //func2->SetRange(obmin, obmax);
325 func2->SetRange(limitdown, limitup);
326 func2->SetLineColor(4);
327 func2->SetLineStyle(1);
328 func2->SetLineWidth(3);
329 func2->Draw("same");
330 TF1 *func3 = new TF1("func3", "109"); ///valore di riferimento 95
331 //func3->SetRange(obmin, obmax);
332 func3->SetRange(limitdown, limitup);
333 func3->SetLineColor(6);
334 func3->SetLineStyle(1);
335 func3->SetLineWidth(3);
336 func3->Draw("same");
337 TF1 *func4 = new TF1("func4", "71"); ///valore di riferimento 95
338 //func4->SetRange(obmin, obmax);
339 func4->SetRange(limitdown, limitup);
340 func4->SetLineColor(6);
341 func4->SetLineStyle(1);
342 func4->SetLineWidth(3);
343 func4->Draw("same");
344 TF1 *func5 = new TF1("func5", "38.4"); //valore di riferimento 32
345 //func5->SetRange(obmin, obmax);
346 func5->SetRange(limitdown, limitup);
347 func5->SetLineStyle(1);
348 func5->SetLineColor(3);
349 func5->SetLineWidth(3);
350 func5->Draw("same");
351 TF1 *func6 = new TF1("func6", "25.6"); //valore di riferimento 32
352 //func6->SetRange(obmin, obmax);
353 func6->SetRange(limitdown, limitup);
354 func6->SetLineStyle(1);
355 func6->SetLineColor(3);
356 func6->SetLineWidth(3);
357 func6->Draw("same");
358 }
359
360 if (IPM1status==1 && IPM2status==0){ ////cold configuration
361 TF1 *func1 = new TF1("func1", "2400");
362 //func1->SetRange(obmin, obmax);
363 func1->SetRange(limitdown, limitup);
364 func1->SetLineColor(4);
365 func1->SetLineStyle(1);
366 func1->SetLineWidth(3);
367 func1->Draw("same");
368 TF1 *func2 = new TF1("func2", "1600"); ///valore di riferimento 2000
369 //func2->SetRange(obmin, obmax);
370 func2->SetRange(limitdown, limitup);
371 func2->SetLineColor(4);
372 func2->SetLineStyle(1);
373 func2->SetLineWidth(3);
374 func2->Draw("same");
375 TF1 *func3 = new TF1("func3", "180");
376 //func3->SetRange(obmin, obmax);
377 func3->SetRange(limitdown, limitup);
378 func3->SetLineColor(6);
379 func3->SetLineStyle(1);
380 func3->SetLineWidth(3);
381 func3->Draw("same");
382 TF1 *func4 = new TF1("func4", "120"); ///valore di riferimento 150
383 //func4->SetRange(obmin, obmax);
384 func4->SetRange(limitdown, limitup);
385 func4->SetLineColor(6);
386 func4->SetLineStyle(1);
387 func4->SetLineWidth(3);
388 func4->Draw("same");
389 TF1 *func5 = new TF1("func5", "38.4");
390 //func5->SetRange(obmin, obmax);
391 func5->SetRange(limitdown, limitup);
392 func5->SetLineStyle(1);
393 func5->SetLineColor(3);
394 func5->SetLineWidth(3);
395 func5->Draw("same");
396 TF1 *func6 = new TF1("func6", "25.6"); //valore di riferimento 32
397 //func6->SetRange(obmin, obmax);
398 func6->SetRange(limitdown, limitup);
399 func6->SetLineStyle(1);
400 func6->SetLineColor(3);
401 func6->SetLineWidth(3);
402 func6->Draw("same");
403 }
404
405 //TPad *pad = new TPad("pad","pad", .75, .93, .99, .99);
406 TPad *pad = new TPad("pad","pad", .58, .85, .92, .94);
407 pad->SetFillColor(10);
408 pad->Draw();
409 pad->cd();
410 TLatex *l = new TLatex();
411 l->SetTextAlign(12);
412 l->SetTextSize(0.4);
413 l->SetTextColor(kRed);
414 l->DrawLatex(0.05, 0.65, status.Data());
415
416
417 finalCanv->cd(2);
418 gPad->SetLogy();
419 gStyle->SetOptStat("nemrou");
420 calibS4_1->SetLineColor(kBlack);
421 calibS4_1->SetFillColor(kRed);
422 calibS4_1->GetYaxis()->SetTitle("Number of events");
423 calibS4_1->GetYaxis()->SetTitleSize(0.03);
424 calibS4_1->GetYaxis()->SetTitleOffset(1);
425 calibS4_1->GetYaxis()->CenterTitle();
426 calibS4_1->GetYaxis()->SetLabelSize(0.02);
427 calibS4_1->GetXaxis()->CenterTitle();
428 calibS4_1->GetXaxis()->SetTitleSize(0.03);
429 calibS4_1->GetXaxis()->SetTitleOffset(1);
430 calibS4_1->GetXaxis()->SetLabelSize(0.02);
431 calibS4_1->GetXaxis()->SetTitle("ADC (ch)");
432 calibS4_1->SetAxisRange(0,200);
433 calibS4_1->Draw();
434
435 finalCanv->cd(3);
436 gPad->SetLogy();
437 gStyle->SetOptStat("nemrou");
438 calibS4_2->SetLineColor(kBlack);
439 calibS4_2->SetFillColor(kRed);
440 calibS4_2->GetYaxis()->SetTitle("Number of events");
441 calibS4_2->GetYaxis()->SetTitleSize(0.03);
442 calibS4_2->GetYaxis()->SetTitleOffset(1);
443 calibS4_2->GetYaxis()->CenterTitle();
444 calibS4_2->GetYaxis()->SetLabelSize(0.02);
445 calibS4_2->GetXaxis()->CenterTitle();
446 calibS4_2->GetXaxis()->SetTitleSize(0.03);
447 calibS4_2->GetXaxis()->SetTitleOffset(1);
448 calibS4_2->GetXaxis()->SetLabelSize(0.02);
449 calibS4_2->GetXaxis()->SetTitle("ADC (ch)");
450 calibS4_2->SetAxisRange(50,250);
451 calibS4_2->Draw();
452
453 finalCanv->cd(4);
454 gPad->SetLogy();
455 gStyle->SetOptStat("nemrou");
456 calibS4_4->SetLineColor(kBlack);
457 calibS4_4->SetFillColor(kRed);
458 calibS4_4->GetYaxis()->SetTitle("Number of events");
459 calibS4_4->GetYaxis()->SetTitleSize(0.03);
460 calibS4_4->GetYaxis()->SetTitleOffset(1);
461 calibS4_4->GetYaxis()->CenterTitle();
462 calibS4_4->GetYaxis()->SetLabelSize(0.02);
463 calibS4_4->GetXaxis()->CenterTitle();
464 calibS4_4->GetXaxis()->SetTitleSize(0.03);
465 calibS4_4->GetXaxis()->SetTitleOffset(1);
466 calibS4_4->GetXaxis()->SetLabelSize(0.02);
467 calibS4_4->GetXaxis()->SetTitle("ADC (ch)");
468 calibS4_4->SetAxisRange(500,2500);
469 calibS4_4->Draw();
470
471 oss.str("");
472 if (outDir == "./") {
473 oss << filename.Data() << "_S4_Calibration_QL." << format.Data();
474 } else {
475 oss << outDir.Data() << filename.Data() << "_S4_Calibration_QL." << format.Data();
476 }
477 finalCanv->SaveAs(oss.str().c_str());
478 }
479
480 int main(int argc, char* argv[]){
481 TString path;
482 TString outDir ="./";
483 TString format ="jpg";
484
485 if (argc < 2){
486 printf("You have to insert at least the file to analyze \n");
487 printf("Try '--help' for more information. \n");
488 exit(1);
489 }
490
491 if (!strcmp(argv[1], "--help")){
492 printf( "Usage: S4_Calibration_QL FILE [OPTION] \n");
493 printf( "\t --help Print this help and exit \n");
494 printf( "\t -outDir[path] Path where to put the output [default ./] \n");
495 // printf( "\t -format[] Format for output files [default 'jpg'] \n");
496 exit(1);
497 }
498
499 path=argv[1];
500
501 for (int i = 2; i < argc; i++){
502
503 if (!strcmp(argv[i], "-outDir")){
504 if (++i >= argc){
505 printf( "-outDir needs arguments. \n");
506 printf( "Try '--help' for more information. \n");
507 exit(1);
508 }
509 else{
510 outDir = argv[i];
511 continue;
512 }
513 }
514
515 if (!strcmp(argv[i], "-format")){
516 if (++i >= argc){
517 printf( "-format needs arguments. \n");
518 printf( "Try '--help' for more information. \n");
519 exit(1);
520 }
521 else{
522 format = argv[i];
523 continue;
524 }
525 }
526
527
528 }
529
530
531 S4_Calibration_QL(argv[1], outDir, format);
532
533 }
534
535

  ViewVC Help
Powered by ViewVC 1.1.23