/[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.1 - (show annotations) (download)
Thu Jun 15 14:00:30 2006 UTC (18 years, 5 months ago) by pam-rm2
Branch: MAIN
Branch point for: QLflightS4_ND
Initial revision

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
23 #include <fstream>
24 #include <iostream>
25 #include <iostream>
26 #include <sstream>
27 #include "TStyle.h"
28 #include "TFile.h"
29 #include "TList.h"
30 #include "TTree.h"
31 #include "TLatex.h"
32 #include "TObjString.h"
33 #include "TCanvas.h"
34 #include "TGraph.h"
35 #include "TH1F.h"
36 #include "TF1.h"
37 #include "TGaxis.h"
38 #include "TString.h"
39 #include "TPaveText.h"
40 #include "TMultiGraph.h"
41 #include "TGraphErrors.h"
42 #include "EventHeader.h"
43 #include "PscuHeader.h"
44 #include "physics/S4/S4Event.h"
45 #include "CalibS4Event.h"
46 #include "tmtc/TmtcEvent.h"
47 #include "tmtc/TmtcRecord.h"
48
49 using namespace std;
50
51 //--------------- root function ----------------------------------
52
53 void S4_Calibration_QL(TString base, TString outDir, TString format){
54
55 //--------------- Variables initialization -----------------------------------//
56 const Int_t channels = 4096;
57 Double_t calib_1;
58 Double_t calib_2;
59 Double_t calib_4;
60 Double_t calib_1_RMS;
61 Double_t calib_2_RMS;
62 Double_t calib_4_RMS;
63 Double_t obt;
64 TString status;
65 Int_t IPM1status, IPM2status;
66 //------------------------- Open data file -------------------------------------//
67 TFile *file =new TFile(base.Data()) ;
68 TString filename = ((TObjString*)base.Tokenize('/')->Last())->GetString();
69 filename = ((TObjString*)filename.Tokenize('.')->First())->GetString();
70
71 if (!file){
72 printf("No such file in the directory has been found");
73 return;
74 }
75
76 TTree *CalibS4tr = (TTree*)file->Get("CalibS4");
77 TBranch *S4Br = CalibS4tr->GetBranch("CalibS4");
78 TBranch *headBr = CalibS4tr->GetBranch("Header");
79 TTree *tmtcTr = (TTree*)file->Get("Tmtc");
80 TBranch *tmtcBr = tmtcTr->GetBranch("Tmtc");
81
82 pamela::TmtcEvent *tme = 0;
83 pamela::TmtcRecord *tmr = 0;
84 pamela::S4::S4Event *s4Record;
85 pamela::CalibS4Event *s4Event = new pamela::CalibS4Event();
86 pamela::EventHeader *eh = 0;
87 pamela::PscuHeader *ph = 0;
88
89 CalibS4tr->SetBranchAddress("CalibS4", &s4Event);
90 CalibS4tr->SetBranchAddress("Header", &eh);
91 tmtcTr->SetBranchAddress("Tmtc", &tme);
92 Long64_t nevents= CalibS4tr->GetEntries();
93 Long64_t neventstmtc = tmtcBr->GetEntries();
94
95 if (neventstmtc<=0) {
96 printf("Tmtc packet: nevents = %i\n", nevents);
97 printf(" No info about kind of calibration (hot or cold) \n");
98 }
99 //----------------- if nevents = 0 ----------------------------------------------//
100 if (nevents<=0){
101 cout<<"WARNING: No Entries, RETURN"<<"\n";
102
103 TCanvas *canvas4 = new TCanvas("No entries", "No entries ", 400, 200);
104 canvas4->SetFillColor(10);
105 canvas4->cd();
106
107 TLatex *l = new TLatex();
108 l->SetTextAlign(12);
109 l->SetTextSize(0.15);
110 l->SetTextColor(2);
111 stringstream oss, noentries;
112 noentries.str("");
113 noentries<< "S4_Calibration_QL:";
114 l->DrawLatex(0.05, 0.7, noentries.str().c_str());
115 noentries.str("");
116 noentries<< "No entries for this files";
117 l->DrawLatex(0.05, 0.5, noentries.str().c_str());
118
119 if (outDir== "./") {
120 oss.str("");
121 oss << filename.Data() << "_S4_Calibration_QL." << format.Data();
122 } else {
123 oss.str("");
124 oss << outDir.Data() << filename.Data() << "_S4_Calibration_QL." << format.Data();
125 }
126
127 canvas4->Update();
128 canvas4->SaveAs(oss.str().c_str());
129 return;
130 }
131
132 //---------------Look for configuration hot or cold -----------------------//
133 Int_t recordstot=0;
134 for (Int_t i = 0; i < neventstmtc; i++){
135 tmtcBr->GetEntry(i);
136 Long64_t tmpSizetmtc = tme->Records->GetEntries();
137 recordstot=recordstot+tmpSizetmtc;
138 }
139 const Int_t lungmax=16*recordstot;
140 Double_t xrecordobtcc[lungmax], yccdiagacq[lungmax], xrecordobtcc_1[lungmax], yccdiagacq_1[lungmax];
141 recordstot=0;
142 for (Int_t i = 0; i < neventstmtc; i++){
143 tmtcBr->GetEntry(i);
144 Long64_t tmpSizetmtc = tme->Records->GetEntries();
145 Int_t size_b = tmpSizetmtc;
146 for (Int_t j = 0; j < size_b; j++){
147 tmr = (pamela::TmtcRecord*)tme->Records->At(j);
148 for (Int_t k =0; k <16; k++){
149 yccdiagacq[16*recordstot+16*j+k] = (((tmr->TM_DIAG_AND_BILEVEL_ACQ)>>(15-k))&0x0001);
150 xrecordobtcc[16*recordstot+16*j+k] = tmr->TM_RECORD_OBT;
151 }
152 }
153 recordstot=recordstot+tmpSizetmtc;
154 }
155 Int_t riftime = recordstot/2;
156 //CC (0=IPM1=hot; 1=IPM2=cold for S4 calibration)
157 for (Int_t k =0; k<16; k++){
158 for (Int_t i = 0; i < recordstot; i++){
159 yccdiagacq_1[i]= yccdiagacq[16*i+k];
160 xrecordobtcc_1[i]= xrecordobtcc[16*i+k];
161 }
162 if (k==0) IPM1status=(Int_t)yccdiagacq_1[riftime];
163 if (k==1) IPM2status=(Int_t)yccdiagacq_1[riftime];
164 }
165 if (IPM1status==0 && IPM2status==1){
166 status="CONFIGURATION: HOT";
167 }
168 if (IPM1status==1 && IPM2status==0){
169 status="CONFIGURATION: COLD";
170 }
171
172 //------------- Create and fill histograms -------------------------------------------//
173
174 TH1F *calibS4_1 =new TH1F("calibS4_1", "calibS4_1", channels, 0, channels);
175 TH1F *calibS4_2 =new TH1F("calibS4_2", "calibS4_2", channels, 0, channels);
176 TH1F *calibS4_4 =new TH1F("calibS4_4", "calibS4_4", channels, 0, channels);
177 ULong_t lastime, firstime;
178 double obmin=0.;
179 double obmax=0.;
180 const Int_t size = nevents;
181 headBr->GetEntry(0);
182 ph = eh->GetPscuHeader();
183 firstime = ph->GetOrbitalTime();
184 headBr->GetEntry(nevents-1);
185 ph = eh->GetPscuHeader();
186 lastime = ph->GetOrbitalTime();
187 obmin=firstime;
188 obmax=lastime;
189 stringstream oss;
190 oss.str("");
191 oss << "S4_Calibration_QL: "<< filename.Data();
192 TH1F *cal1 =new TH1F("calibS4_1", oss.str().c_str(), size, obmin, obmax);
193 TH1F *cal2 =new TH1F("calibS4_2", oss.str().c_str(), size, obmin, obmax);
194 TH1F *cal4 =new TH1F("calibS4_4", oss.str().c_str(), size, obmin, obmax);
195
196 for(Int_t k = 0; k<nevents; k++){
197 headBr->GetEntry(k);
198 S4Br->GetEntry(k);
199 ph = eh->GetPscuHeader();
200 Int_t tmpSize = s4Event->Records->GetEntries();
201 for (Int_t j = 0; j < 4; j++){
202 for (Int_t i = 0; i < 128; i++){
203 s4Record = (pamela::S4::S4Event*)s4Event->Records->At((j*128 + i));
204 switch (j) {
205 case 0 :{
206 calibS4_1->Fill(s4Record->S4_DATA);
207 break;
208 }
209 case 1 :{
210 calibS4_2->Fill(s4Record->S4_DATA);
211 break;
212 }
213 case 3 :{
214 calibS4_4->Fill(s4Record->S4_DATA);
215 break;
216 }
217 }
218 }
219 }
220
221 obt=ph->GetOrbitalTime();
222 calib_1=calibS4_1->GetMean(1);
223 //calib_1_RMS=calibS4_1->GetRMS(1);
224 calib_2=calibS4_2->GetMean(1);
225 //calib_2_RMS=calibS4_2->GetRMS(1);
226 calib_4=calibS4_4->GetMean(1);
227 //calib_4_RMS=calibS4_4->GetRMS(1);
228 cal1->Fill(obt,calib_1);
229 cal2->Fill(obt,calib_2);
230 cal4->Fill(obt,calib_4);
231
232 //cout<<calib_1_RMS<<"\n";
233 //cout<<calib_2_RMS<<"\n";
234 //cout<<calib_4_RMS<<"\n";
235 //cout<<k<<" "<<obt<<" \n "<<calib_1<<" "<<calib_2<<" "<<calib_4<<"\n";
236
237 }
238
239 //----------------- Create and draw canvas -----------------------------------------//
240 TCanvas *finalCanv = new TCanvas("S4Calib","Calibration_QL", 1280, 1024);
241 finalCanv->SetFillColor(10);
242
243 finalCanv->cd();
244 gPad->SetLogy();
245
246 cal1->SetStats(kFALSE);
247 cal1->SetMarkerSize(.5);
248 cal1->SetMarkerStyle(21);
249 cal1->SetMarkerColor(3);
250 cal1->SetMinimum(1);
251 cal1->SetMaximum(10000);
252 cal1->GetYaxis()->SetTitle("S4 mean value (ADC)");
253 cal1->GetYaxis()->SetTitleSize(0.03);
254 cal1->GetYaxis()->SetTitleOffset(1);
255 cal1->GetYaxis()->CenterTitle();
256 cal1->GetYaxis()->SetLabelSize(0.02);
257 cal1->GetXaxis()->CenterTitle();
258 cal1->GetXaxis()->SetTitleSize(0.03);
259 cal1->GetXaxis()->SetTitleOffset(1);
260 cal1->GetXaxis()->SetLabelSize(0.02);
261 cal1->GetXaxis()->SetTitle("OBT (ms)");
262 cal1->Draw("9p");
263
264 cal2->SetStats(kFALSE);
265 cal2->SetMarkerSize(.5);
266 cal2->SetMarkerStyle(21);
267 cal2->SetMarkerColor(6);
268 cal2->SetMinimum(1);
269 cal2->SetMaximum(10000);
270 cal2->Draw("9psame");
271
272 cal4->SetStats(kFALSE);
273 cal4->SetMarkerSize(.5);
274 cal4->SetMarkerStyle(21);
275 cal4->SetMarkerColor(4);
276 cal4->SetMinimum(1);
277 cal4->SetMaximum(10000);
278 cal4->Draw("9psame");
279 if (IPM1status==0 && IPM2status==1){ ////hot configuration
280 TF1 *func1 = new TF1("func1", "1560"); ///valore di riferimento 1300
281 func1->SetRange(obmin, obmax);
282 func1->SetLineColor(4);
283 func1->SetLineStyle(4);
284 func1->SetLineWidth(4);
285 func1->Draw("same");
286 TF1 *func2 = new TF1("func2", "1040"); ///valore di riferimento 1300
287 func2->SetRange(obmin, obmax);
288 func2->SetLineColor(4);
289 func2->SetLineStyle(4);
290 func2->SetLineWidth(4);
291 func2->Draw("same");
292 TF1 *func3 = new TF1("func3", "109"); ///valore di riferimento 95
293 func3->SetRange(obmin, obmax);
294 func3->SetLineColor(6);
295 func3->SetLineStyle(4);
296 func3->SetLineWidth(4);
297 func3->Draw("same");
298 TF1 *func4 = new TF1("func4", "71"); ///valore di riferimento 95
299 func4->SetRange(obmin, obmax);
300 func4->SetLineColor(6);
301 func4->SetLineStyle(4);
302 func4->SetLineWidth(4);
303 func4->Draw("same");
304 TF1 *func5 = new TF1("func5", "38.4"); //valore di riferimento 32
305 func5->SetRange(obmin, obmax);
306 func5->SetLineStyle(4);
307 func5->SetLineColor(3);
308 func5->SetLineWidth(4);
309 func5->Draw("same");
310 TF1 *func6 = new TF1("func6", "25.6"); //valore di riferimento 32
311 func6->SetRange(obmin, obmax);
312 func6->SetLineStyle(4);
313 func6->SetLineColor(3);
314 func6->SetLineWidth(4);
315 func6->Draw("same");
316 }
317
318 if (IPM1status==1 && IPM2status==0){ ////cold configuration
319 TF1 *func1 = new TF1("func1", "2400");
320 func1->SetRange(obmin, obmax);
321 func1->SetLineColor(4);
322 func1->SetLineStyle(4);
323 func1->SetLineWidth(4);
324 func1->Draw("same");
325 TF1 *func2 = new TF1("func2", "1600"); ///valore di riferimento 2000
326 func2->SetRange(obmin, obmax);
327 func2->SetLineColor(4);
328 func2->SetLineStyle(4);
329 func2->SetLineWidth(4);
330 func2->Draw("same");
331 TF1 *func3 = new TF1("func3", "180");
332 func3->SetRange(obmin, obmax);
333 func3->SetLineColor(6);
334 func3->SetLineStyle(4);
335 func3->SetLineWidth(4);
336 func3->Draw("same");
337 TF1 *func4 = new TF1("func4", "120"); ///valore di riferimento 150
338 func4->SetRange(obmin, obmax);
339 func4->SetLineColor(6);
340 func4->SetLineStyle(4);
341 func4->SetLineWidth(4);
342 func4->Draw("same");
343 TF1 *func5 = new TF1("func5", "38.4");
344 func5->SetRange(obmin, obmax);
345 func5->SetLineStyle(4);
346 func5->SetLineColor(3);
347 func5->SetLineWidth(4);
348 func5->Draw("same");
349 TF1 *func6 = new TF1("func6", "25.6"); //valore di riferimento 32
350 func6->SetRange(obmin, obmax);
351 func6->SetLineStyle(4);
352 func6->SetLineColor(3);
353 func6->SetLineWidth(4);
354 func6->Draw("same");
355 }
356
357 TPad *pad = new TPad("pad","pad", .75, .93, .99, .99);
358 pad->SetFillColor(10);
359 pad->Draw();
360 pad->cd();
361 TLatex *l = new TLatex();
362 l->SetTextAlign(12);
363 l->SetTextSize(0.35);
364 l->SetTextColor(8);
365 l->DrawLatex(0.05, 0.65, status.Data());
366
367 oss.str("");
368 if (outDir == "./") {
369 oss << filename.Data() << "_S4_Calibration_QL." << format.Data();
370 } else {
371 oss << outDir.Data() << filename.Data() << "_S4_Calibration_QL." << format.Data();
372 }
373 finalCanv->SaveAs(oss.str().c_str());
374
375
376
377
378
379 }
380
381 int main(int argc, char* argv[]){
382 TString path;
383 TString outDir ="./";
384 TString format ="jpg";
385
386 if (argc < 2){
387 printf("You have to insert at least the file to analyze \n");
388 printf("Try '--help' for more information. \n");
389 exit(1);
390 }
391
392 if (!strcmp(argv[1], "--help")){
393 printf( "Usage: S4_Calibration_QL FILE [OPTION] \n");
394 printf( "\t --help Print this help and exit \n");
395 printf( "\t -outDir[path] Path where to put the output [default ./] \n");
396 // printf( "\t -format[] Format for output files [default 'jpg'] \n");
397 exit(1);
398 }
399
400 path=argv[1];
401
402 for (int i = 2; i < argc; i++){
403
404 if (!strcmp(argv[i], "-outDir")){
405 if (++i >= argc){
406 printf( "-outDir needs arguments. \n");
407 printf( "Try '--help' for more information. \n");
408 exit(1);
409 }
410 else{
411 outDir = argv[i];
412 continue;
413 }
414 }
415
416 /* if (!strcmp(argv[i], "-format")){
417 if (++i >= argc){
418 printf( "-format needs arguments. \n");
419 printf( "Try '--help' for more information. \n");
420 exit(1);
421 }
422 else{
423 format = argv[i];
424 continue;
425 }
426 }*/
427
428
429 }
430
431
432 S4_Calibration_QL(argv[1], outDir, format);
433
434 }
435
436

  ViewVC Help
Powered by ViewVC 1.1.23