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

Annotation of /quicklook/QLflightS4_ND/S4_Calibration_QL.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (hide annotations) (download)
Tue Aug 22 09:06:35 2006 UTC (18 years, 3 months ago) by pam-rm2
Branch: MAIN
CVS Tags: v1r06
Changes since 1.2: +21 -4 lines
modificato S4 calibration

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

  ViewVC Help
Powered by ViewVC 1.1.23