/[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.2 - (hide annotations) (download)
Fri Jul 7 09:19:22 2006 UTC (18 years, 4 months ago) by pam-rm2
Branch: MAIN
CVS Tags: v1r04, v1r05, v1r03
Changes since 1.1: +66 -44 lines
S4_Calibration: implementata l'opzione format

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     **************/
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 pam-rm2 1.2 ULong_t lastime, firstime, obt1;
178 pam-rm2 1.1 double obmin=0.;
179 pam-rm2 1.2 double obmax=0.;
180     double limitdown=0;
181     double limitup=0;
182 pam-rm2 1.1 const Int_t size = nevents;
183 pam-rm2 1.2
184 pam-rm2 1.1 headBr->GetEntry(0);
185     ph = eh->GetPscuHeader();
186     firstime = ph->GetOrbitalTime();
187     headBr->GetEntry(nevents-1);
188     ph = eh->GetPscuHeader();
189     lastime = ph->GetOrbitalTime();
190     obmin=firstime;
191     obmax=lastime;
192 pam-rm2 1.2 if(nevents < 2){
193     limitdown= obmin - 1000000;
194     limitup= obmax + 1000000;
195     }else{
196     limitdown=obmin;
197     limitup=obmax;
198     }
199 pam-rm2 1.1 stringstream oss;
200     oss.str("");
201     oss << "S4_Calibration_QL: "<< filename.Data();
202     TH1F *cal1 =new TH1F("calibS4_1", oss.str().c_str(), size, obmin, obmax);
203     TH1F *cal2 =new TH1F("calibS4_2", oss.str().c_str(), size, obmin, obmax);
204     TH1F *cal4 =new TH1F("calibS4_4", oss.str().c_str(), size, obmin, obmax);
205    
206     for(Int_t k = 0; k<nevents; k++){
207     headBr->GetEntry(k);
208     S4Br->GetEntry(k);
209     ph = eh->GetPscuHeader();
210     Int_t tmpSize = s4Event->Records->GetEntries();
211     for (Int_t j = 0; j < 4; j++){
212     for (Int_t i = 0; i < 128; i++){
213     s4Record = (pamela::S4::S4Event*)s4Event->Records->At((j*128 + i));
214     switch (j) {
215     case 0 :{
216     calibS4_1->Fill(s4Record->S4_DATA);
217     break;
218     }
219     case 1 :{
220     calibS4_2->Fill(s4Record->S4_DATA);
221     break;
222     }
223     case 3 :{
224     calibS4_4->Fill(s4Record->S4_DATA);
225     break;
226     }
227     }
228     }
229     }
230    
231 pam-rm2 1.2 //obt=ph->GetOrbitalTime();
232 pam-rm2 1.1 calib_1=calibS4_1->GetMean(1);
233     //calib_1_RMS=calibS4_1->GetRMS(1);
234     calib_2=calibS4_2->GetMean(1);
235     //calib_2_RMS=calibS4_2->GetRMS(1);
236     calib_4=calibS4_4->GetMean(1);
237     //calib_4_RMS=calibS4_4->GetRMS(1);
238 pam-rm2 1.2 cal1->Fill(ph->GetOrbitalTime(),calib_1);
239     cal2->Fill(ph->GetOrbitalTime(),calib_2);
240     cal4->Fill(ph->GetOrbitalTime(),calib_4);
241 pam-rm2 1.1
242     //cout<<calib_1_RMS<<"\n";
243     //cout<<calib_2_RMS<<"\n";
244     //cout<<calib_4_RMS<<"\n";
245     //cout<<k<<" "<<obt<<" \n "<<calib_1<<" "<<calib_2<<" "<<calib_4<<"\n";
246    
247     }
248    
249     //----------------- Create and draw canvas -----------------------------------------//
250     TCanvas *finalCanv = new TCanvas("S4Calib","Calibration_QL", 1280, 1024);
251     finalCanv->SetFillColor(10);
252    
253     finalCanv->cd();
254     gPad->SetLogy();
255    
256     cal1->SetStats(kFALSE);
257     cal1->SetMarkerSize(.5);
258     cal1->SetMarkerStyle(21);
259     cal1->SetMarkerColor(3);
260     cal1->SetMinimum(1);
261     cal1->SetMaximum(10000);
262     cal1->GetYaxis()->SetTitle("S4 mean value (ADC)");
263     cal1->GetYaxis()->SetTitleSize(0.03);
264     cal1->GetYaxis()->SetTitleOffset(1);
265     cal1->GetYaxis()->CenterTitle();
266     cal1->GetYaxis()->SetLabelSize(0.02);
267     cal1->GetXaxis()->CenterTitle();
268     cal1->GetXaxis()->SetTitleSize(0.03);
269     cal1->GetXaxis()->SetTitleOffset(1);
270     cal1->GetXaxis()->SetLabelSize(0.02);
271     cal1->GetXaxis()->SetTitle("OBT (ms)");
272     cal1->Draw("9p");
273    
274     cal2->SetStats(kFALSE);
275     cal2->SetMarkerSize(.5);
276     cal2->SetMarkerStyle(21);
277     cal2->SetMarkerColor(6);
278     cal2->SetMinimum(1);
279     cal2->SetMaximum(10000);
280     cal2->Draw("9psame");
281    
282     cal4->SetStats(kFALSE);
283     cal4->SetMarkerSize(.5);
284     cal4->SetMarkerStyle(21);
285     cal4->SetMarkerColor(4);
286     cal4->SetMinimum(1);
287     cal4->SetMaximum(10000);
288     cal4->Draw("9psame");
289     if (IPM1status==0 && IPM2status==1){ ////hot configuration
290     TF1 *func1 = new TF1("func1", "1560"); ///valore di riferimento 1300
291 pam-rm2 1.2 //func1->SetRange(obmin, obmax);
292     func1->SetRange(limitdown, limitup);
293 pam-rm2 1.1 func1->SetLineColor(4);
294 pam-rm2 1.2 func1->SetLineStyle(1);
295     func1->SetLineWidth(3);
296 pam-rm2 1.1 func1->Draw("same");
297     TF1 *func2 = new TF1("func2", "1040"); ///valore di riferimento 1300
298 pam-rm2 1.2 //func2->SetRange(obmin, obmax);
299     func2->SetRange(limitdown, limitup);
300 pam-rm2 1.1 func2->SetLineColor(4);
301 pam-rm2 1.2 func2->SetLineStyle(1);
302     func2->SetLineWidth(3);
303 pam-rm2 1.1 func2->Draw("same");
304     TF1 *func3 = new TF1("func3", "109"); ///valore di riferimento 95
305 pam-rm2 1.2 //func3->SetRange(obmin, obmax);
306     func3->SetRange(limitdown, limitup);
307 pam-rm2 1.1 func3->SetLineColor(6);
308 pam-rm2 1.2 func3->SetLineStyle(1);
309     func3->SetLineWidth(3);
310 pam-rm2 1.1 func3->Draw("same");
311     TF1 *func4 = new TF1("func4", "71"); ///valore di riferimento 95
312 pam-rm2 1.2 //func4->SetRange(obmin, obmax);
313     func4->SetRange(limitdown, limitup);
314 pam-rm2 1.1 func4->SetLineColor(6);
315 pam-rm2 1.2 func4->SetLineStyle(1);
316     func4->SetLineWidth(3);
317 pam-rm2 1.1 func4->Draw("same");
318     TF1 *func5 = new TF1("func5", "38.4"); //valore di riferimento 32
319 pam-rm2 1.2 //func5->SetRange(obmin, obmax);
320     func5->SetRange(limitdown, limitup);
321     func5->SetLineStyle(1);
322 pam-rm2 1.1 func5->SetLineColor(3);
323 pam-rm2 1.2 func5->SetLineWidth(3);
324 pam-rm2 1.1 func5->Draw("same");
325     TF1 *func6 = new TF1("func6", "25.6"); //valore di riferimento 32
326 pam-rm2 1.2 //func6->SetRange(obmin, obmax);
327     func6->SetRange(limitdown, limitup);
328     func6->SetLineStyle(1);
329 pam-rm2 1.1 func6->SetLineColor(3);
330 pam-rm2 1.2 func6->SetLineWidth(3);
331 pam-rm2 1.1 func6->Draw("same");
332     }
333    
334     if (IPM1status==1 && IPM2status==0){ ////cold configuration
335     TF1 *func1 = new TF1("func1", "2400");
336 pam-rm2 1.2 //func1->SetRange(obmin, obmax);
337     func1->SetRange(limitdown, limitup);
338 pam-rm2 1.1 func1->SetLineColor(4);
339 pam-rm2 1.2 func1->SetLineStyle(1);
340     func1->SetLineWidth(3);
341 pam-rm2 1.1 func1->Draw("same");
342     TF1 *func2 = new TF1("func2", "1600"); ///valore di riferimento 2000
343 pam-rm2 1.2 //func2->SetRange(obmin, obmax);
344     func2->SetRange(limitdown, limitup);
345 pam-rm2 1.1 func2->SetLineColor(4);
346 pam-rm2 1.2 func2->SetLineStyle(1);
347     func2->SetLineWidth(3);
348 pam-rm2 1.1 func2->Draw("same");
349     TF1 *func3 = new TF1("func3", "180");
350 pam-rm2 1.2 //func3->SetRange(obmin, obmax);
351     func3->SetRange(limitdown, limitup);
352 pam-rm2 1.1 func3->SetLineColor(6);
353 pam-rm2 1.2 func3->SetLineStyle(1);
354     func3->SetLineWidth(3);
355 pam-rm2 1.1 func3->Draw("same");
356     TF1 *func4 = new TF1("func4", "120"); ///valore di riferimento 150
357 pam-rm2 1.2 //func4->SetRange(obmin, obmax);
358     func4->SetRange(limitdown, limitup);
359 pam-rm2 1.1 func4->SetLineColor(6);
360 pam-rm2 1.2 func4->SetLineStyle(1);
361     func4->SetLineWidth(3);
362 pam-rm2 1.1 func4->Draw("same");
363     TF1 *func5 = new TF1("func5", "38.4");
364 pam-rm2 1.2 //func5->SetRange(obmin, obmax);
365     func5->SetRange(limitdown, limitup);
366     func5->SetLineStyle(1);
367 pam-rm2 1.1 func5->SetLineColor(3);
368 pam-rm2 1.2 func5->SetLineWidth(3);
369 pam-rm2 1.1 func5->Draw("same");
370     TF1 *func6 = new TF1("func6", "25.6"); //valore di riferimento 32
371 pam-rm2 1.2 //func6->SetRange(obmin, obmax);
372     func6->SetRange(limitdown, limitup);
373     func6->SetLineStyle(1);
374 pam-rm2 1.1 func6->SetLineColor(3);
375 pam-rm2 1.2 func6->SetLineWidth(3);
376 pam-rm2 1.1 func6->Draw("same");
377     }
378    
379     TPad *pad = new TPad("pad","pad", .75, .93, .99, .99);
380     pad->SetFillColor(10);
381     pad->Draw();
382     pad->cd();
383     TLatex *l = new TLatex();
384     l->SetTextAlign(12);
385     l->SetTextSize(0.35);
386     l->SetTextColor(8);
387     l->DrawLatex(0.05, 0.65, status.Data());
388    
389     oss.str("");
390     if (outDir == "./") {
391     oss << filename.Data() << "_S4_Calibration_QL." << format.Data();
392     } else {
393     oss << outDir.Data() << filename.Data() << "_S4_Calibration_QL." << format.Data();
394     }
395     finalCanv->SaveAs(oss.str().c_str());
396    
397    
398    
399    
400    
401     }
402    
403     int main(int argc, char* argv[]){
404     TString path;
405     TString outDir ="./";
406     TString format ="jpg";
407    
408     if (argc < 2){
409     printf("You have to insert at least the file to analyze \n");
410     printf("Try '--help' for more information. \n");
411     exit(1);
412     }
413    
414     if (!strcmp(argv[1], "--help")){
415     printf( "Usage: S4_Calibration_QL FILE [OPTION] \n");
416     printf( "\t --help Print this help and exit \n");
417     printf( "\t -outDir[path] Path where to put the output [default ./] \n");
418     // printf( "\t -format[] Format for output files [default 'jpg'] \n");
419     exit(1);
420     }
421    
422     path=argv[1];
423    
424     for (int i = 2; i < argc; i++){
425    
426     if (!strcmp(argv[i], "-outDir")){
427     if (++i >= argc){
428     printf( "-outDir needs arguments. \n");
429     printf( "Try '--help' for more information. \n");
430     exit(1);
431     }
432     else{
433     outDir = argv[i];
434     continue;
435     }
436     }
437    
438 pam-rm2 1.2 if (!strcmp(argv[i], "-format")){
439 pam-rm2 1.1 if (++i >= argc){
440     printf( "-format needs arguments. \n");
441     printf( "Try '--help' for more information. \n");
442     exit(1);
443     }
444     else{
445     format = argv[i];
446     continue;
447     }
448 pam-rm2 1.2 }
449 pam-rm2 1.1
450    
451     }
452    
453    
454     S4_Calibration_QL(argv[1], outDir, format);
455    
456     }
457    
458    

  ViewVC Help
Powered by ViewVC 1.1.23