/[PAMELA software]/calo/flight/FUTILITIES/macros/FCaloPULSE.cxx
ViewVC logotype

Annotation of /calo/flight/FUTILITIES/macros/FCaloPULSE.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations) (download)
Mon Sep 22 20:18:46 2008 UTC (16 years, 2 months ago) by mocchiut
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +46 -5 lines
Added -m32 flag for cross compilation on 64bit machines

1 mocchiut 1.1 //
2     // Show pulse distributions of the calorimeter PULSE calibration
3     //
4     // FCaloPULSE.cxx version 1.00 (2006-03-08)
5     //
6     // The only input needed is the path to the directory created by YODA for the data file you want to analyze.
7     //
8     // Changelog:
9     //
10     // 1.00 - 1.01 : Flight version, read unique YODA file.
11     //
12     // 0.00 - 1.00 : clone of CaloPULSE v1r05.
13     //
14     #include <fstream>
15     #include <sstream>
16     #include <TTree.h>
17     #include <TClassEdit.h>
18     #include <TObject.h>
19     #include <TList.h>
20     #include <TSystem.h>
21     #include <TSystemDirectory.h>
22     #include <TString.h>
23     #include <TFile.h>
24     #include <TClass.h>
25     #include <TCanvas.h>
26     #include <TH1.h>
27     #include <TH1F.h>
28     #include <TH2D.h>
29     #include <TLatex.h>
30     #include <TPad.h>
31     #include <TPaveLabel.h>
32     #include <TChain.h>
33     #include <TStyle.h>
34     //
35     #include <PamelaRun.h>
36     #include <physics/calorimeter/CalorimeterEvent.h>
37     #include <physics/trigger/TriggerEvent.h>
38     #include <CalibCalPedEvent.h>
39     #include <CalibCalPulse1Event.h>
40     #include <CalibCalPulse2Event.h>
41     #include <varDump/VarDumpEvent.h>
42     #include <varDump/VarDumpRecord.h>
43     #include <fcalostructs.h>
44     //
45     extern int OLDCaloFindCalibs(TString &, Calib &);
46     extern bool existfile(TString);
47     extern TString getFilename(const TString);
48     extern void PrintFigure(TString, TString, TString, TString, TCanvas&);
49     extern void ColorMIP(Float_t, int&);
50     //
51     using namespace std;
52     //
53     void FCaloPULSE(TString filename, TString outDir = "", Int_t tosave = 0, TString saveas = "eps"){
54     const char* startingdir = gSystem->WorkingDirectory();
55     if ( !strcmp(outDir.Data(),"") ) outDir = startingdir;
56     //
57     if ( !existfile(filename) ){
58     printf(" %s :no such file or directory \n",filename.Data());
59     return;
60     };
61     //
62     TFile *File = new TFile(filename.Data());
63     TTree *tr = (TTree*)File->Get("CalibCalPulse1");
64     pamela::CalibCalPulse1Event *ce = 0;
65     pamela::EventHeader *ceh = new pamela::EventHeader();
66     tr->SetBranchAddress("Header", &ceh);
67     tr->SetBranchAddress("CalibCalPulse1", &ce);
68     //
69     TFile *vdFile = new TFile(filename.Data());
70     TTree *vdtr = (TTree*)vdFile->Get("VarDump");
71     pamela::VarDumpEvent *vde = 0;
72     pamela::VarDumpRecord *vdr = 0;
73     vdtr->SetBranchAddress("VarDump", &vde);
74     Long64_t nevents = vdtr->GetEntries();
75     stringstream ptype;
76     stringstream stno;
77     Int_t tmpSize;
78     for (Int_t i = 0; i < nevents ; i++){
79     vdtr->GetEntry(i);
80     tmpSize = vde->Records->GetEntries();
81     for (Int_t j = 0; j < tmpSize; j++){
82     vdr = (pamela::VarDumpRecord*)vde->Records->At(j);
83     if ( (int)vdr->VAR_VALUE>32760 && (int)vdr->VAR_VALUE<32790 ){
84     printf(" PULSE TYPE = %X ",vdr->VAR_VALUE);
85     ptype.str("");
86     ptype << " PULSE TYPE = ";
87     ptype << hex << vdr->VAR_VALUE;
88     vdr = (pamela::VarDumpRecord*)vde->Records->At(j+1);
89     printf(" STRIP = %X \n",vdr->VAR_VALUE);
90     stno.str("");
91     stno << " STRIP = ";
92     stno << hex << vdr->VAR_VALUE;
93     };
94     };
95     };
96     vdFile->Close();
97     //
98 mocchiut 1.2 TString fififile = getFilename(filename);
99     const char *file = fififile;
100     //
101 mocchiut 1.1 TCanvas *figura2 = new TCanvas("calpulse", "calpulse", 950, 850);
102     figura2->cd();
103 mocchiut 1.2 figura2->Range(0,0,100,100);
104     stringstream errore;
105     figura2->SetFillColor(10);
106     errore.str("");
107     errore << "EXPERT -- File: " << file;
108     errore << " ";
109     TLatex *t=new TLatex();
110     t->SetTextFont(32);
111     t->SetTextColor(1);
112     t->SetTextAlign(12);
113     t->SetTextSize(0.015);
114     t->DrawLatex(2.,99.,errore.str().c_str());
115     //
116 mocchiut 1.1 gPad->SetLogy();
117     Long64_t ncalibs = tr->GetEntries();
118     TH1F *calpulse1;
119     Int_t workornot = 1;
120     int stoppa = 0;
121     for (Int_t ci = 0; ci < ncalibs ; ci++){
122     int stoppa = 0;
123     int per = 0;
124     tr->GetEntry(ci);
125     gDirectory->Delete("calpulse");
126     calpulse1 = new TH1F("calpulse","",96,-0.5,8000.);
127     calpulse1->SetBit(TH1F::kCanRebin);
128     for ( Int_t s=0 ; s<4 ;s++ ){
129     if ( ce->unpackError ) {
130     per = 1;
131     } else {
132     per = 0;
133     for ( Int_t d=0 ; d<11 ;d++ ){
134     for ( Int_t j=0; j<96 ;j++){
135     calpulse1->Fill(ce->calpuls[s][d][j]);
136     if ( ce->calpuls[s][d][j] != 0. ) stoppa = 1;
137     if ( ce->calpuls[s][d][j] < 0. ) workornot = 0;
138     };
139     };
140     };
141     };
142     if ( !per ){
143     figura2->cd();
144     figura2->SetFillColor(10);
145     stringstream titolo;
146     titolo.str("");
147     titolo << "Pulse1 " << ptype.str().c_str();
148     titolo << " " << stno.str().c_str();
149     calpulse1->Draw();
150     calpulse1->SetTitle(titolo.str().c_str());
151     figura2->Modified();
152     figura2->Update();
153     stringstream figsave;
154     figsave.str("");
155     figsave << "pulse1_";
156     figsave << ci;
157     if ( tosave ) PrintFigure(filename,outDir,figsave.str().c_str(),saveas,*figura2);
158     };
159     };
160     //
161     tr = new TTree();
162     tr = (TTree*)File->Get("CalibCalPulse2");
163     ncalibs = tr->GetEntries();
164     pamela::CalibCalPulse2Event *cee = 0;
165     tr->SetBranchAddress("CalibCalPulse2", &cee);
166     //
167     figura2 = new TCanvas("calpulse", "calpulse", 950, 850);
168     figura2->cd();
169 mocchiut 1.2 // stringstream errore;
170     figura2->Range(0,0,100,100);
171     figura2->SetFillColor(10);
172     errore.str("");
173     errore << "EXPERT -- File: " << file;
174     errore << " ";
175     t=new TLatex();
176     t->SetTextFont(32);
177     t->SetTextColor(1);
178     t->SetTextAlign(12);
179     t->SetTextSize(0.015);
180     t->DrawLatex(2.,99.,errore.str().c_str());
181 mocchiut 1.1 gPad->SetLogy();
182     ncalibs = tr->GetEntries();
183     TH1F *calpulse2;
184     for (Int_t ci = 0; ci < ncalibs ; ci++){
185     stoppa = 0;
186     int per = 0;
187     tr->GetEntry(ci);
188     gDirectory->Delete("calpulse");
189     calpulse2 = new TH1F("calpulse","",96,-0.5,8000.);
190     calpulse2->SetBit(TH1F::kCanRebin);
191     for ( Int_t s=0 ; s<4 ;s++ ){
192     if ( cee->unpackError ){
193     per = 1;
194     } else {
195     per = 0;
196     for ( Int_t d=0 ; d<11 ;d++ ){
197     for ( Int_t j=0; j<96 ;j++){
198     calpulse2->Fill(cee->calpuls[s][d][j]);
199     if ( cee->calpuls[s][d][j] != 0. ) {
200     stoppa = 1;
201     };
202     if ( cee->calpuls[s][d][j] < 0. ) workornot = 0;
203     };
204     };
205     };
206     };
207     if ( !per ){
208     figura2->cd();
209     figura2->SetFillColor(10);
210     figura2->Range(0,0,100,100);
211     stringstream titolo;
212     titolo.str("");
213     titolo << "Pulse2 " << ptype.str().c_str();
214     titolo << " " << stno.str().c_str();
215     calpulse2->SetTitle(titolo.str().c_str());
216     calpulse2->Draw();
217     figura2->Modified();
218     figura2->Update();
219     stringstream figsave;
220     figsave.str("");
221     figsave << "pulse2_";
222     figsave << ci;
223     if ( tosave ) PrintFigure(filename,outDir,figsave.str().c_str(),saveas,*figura2);
224     };
225     };
226     if ( stoppa ){
227     if ( workornot ){
228     printf("File %s is ok \n",filename.Data());
229     } else {
230     printf("File %s is NOT OK! \n",filename.Data());
231     };
232     };
233     }
234    
235     void FCaloPULSEMATRA(TString filename, TString outDir = "", Int_t tosave = 0, TString saveas = "eps"){
236     const char* startingdir = gSystem->WorkingDirectory();
237     if ( !strcmp(outDir.Data(),"") ) outDir = startingdir;
238     //
239     if ( !existfile(filename) ){
240     printf(" %s :no such file or directory \n",filename.Data());
241     return;
242     };
243     //
244     struct Calib calib;
245     for (Int_t s=0; s<4;s++){
246     for (Int_t d = 0; d<50; d++){
247     calib.ttime[s][d] = 0 ;
248     if ( d < 49 ) calib.time[s][d] = 0 ;
249     };
250     };
251     //
252     // first of all find the calibrations in the file
253     //
254     OLDCaloFindCalibs(filename, calib);
255     //
256     // print on the screen the results:
257     //
258     printf(" ---------------------------------------------------------- \n \n");
259     Int_t calibex = 0;
260     for (Int_t s=0; s<4;s++){
261     Int_t stop = 0;
262     for (Int_t d = 0; d<48; d++){
263     if ( calib.ttime[s][d] != 0 ) {
264     calibex++;
265     };
266     if ( calib.time[s][0] != 0 ){
267     if ( d == 0 ) printf(" Section %i from time 0 to time %i use calibration at time %i \n",s,calib.time[s][d],calib.ttime[s][d]);
268     if ( calib.time[s][d+1] != 0 ) {
269     printf(" Section %i from time %i to time %i use calibration at time %i \n",s,calib.time[s][d],calib.time[s][d+1],calib.ttime[s][d+1]);
270     } else {
271     if ( !stop ){
272     printf(" Section %i from time %i use calibration at time %i \n",s,calib.time[s][d],calib.ttime[s][d+1]);
273     stop = 1;
274     };
275     };
276     } else {
277     if ( calib.ttime[s][d] != 0 ) printf(" Section %i from time 0 use calibration at time %i \n",s,calib.ttime[s][d]);
278     };
279     };
280     printf("\n");
281     };
282     Int_t workornot = 1;
283     //
284     TFile *vdFile = new TFile(filename.Data());
285     TTree *vdtr = (TTree*)vdFile->Get("VarDump");
286     pamela::VarDumpEvent *vde = 0;
287     pamela::VarDumpRecord *vdr = 0;
288     vdtr->SetBranchAddress("VarDump", &vde);
289     Long64_t nevents = vdtr->GetEntries();
290     //
291     stringstream ptype;
292     stringstream stno;
293     Int_t tmpSize;
294     for (Int_t i = 0; i < nevents ; i++){
295     vdtr->GetEntry(i);
296     tmpSize = vde->Records->GetEntries();
297     for (Int_t j = 0; j < tmpSize; j++){
298     vdr = (pamela::VarDumpRecord*)vde->Records->At(j);
299     if ( (int)vdr->VAR_VALUE>32760 && (int)vdr->VAR_VALUE<32790 ){
300     printf(" PULSE TYPE = %X ",vdr->VAR_VALUE);
301     ptype.str("");
302     ptype << " PULSE TYPE = ";
303     ptype << hex << vdr->VAR_VALUE;
304     vdr = (pamela::VarDumpRecord*)vde->Records->At(j+1);
305     printf(" STRIP = %X \n",vdr->VAR_VALUE);
306     stno.str("");
307     stno << " STRIP = ";
308     stno << hex << vdr->VAR_VALUE;
309     };
310     };
311     };
312     vdFile->Close();
313 mocchiut 1.2 //
314     TString fififile = getFilename(filename);
315     const char *file = fififile;
316     //
317 mocchiut 1.1 TFile *File = new TFile(filename.Data());
318     TTree *tr = (TTree*)File->Get("CalibCalPulse1");
319     tr->AddFriend("CalibCalPulse2", File);
320     pamela::CalibCalPulse1Event *cee1 = 0;
321     pamela::CalibCalPulse2Event *cee = 0;
322     pamela::EventHeader *ceh = new pamela::EventHeader();
323     tr->SetBranchAddress("Header", &ceh);
324     tr->SetBranchAddress("CalibCalPulse1", &cee1);
325     tr->SetBranchAddress("CalibCalPulse2", &cee);
326     //
327     Long64_t ncalibs = tr->GetEntries();
328     //
329     TCanvas *figura2 = new TCanvas("Calorimeter_tracks", "Calorimeter_tracks", 750, 650);
330     figura2->SetFillColor(10);
331 mocchiut 1.2 //
332 mocchiut 1.1 Int_t ci = 0;
333     int stoppa = 0;
334     while ( ci < ncalibs ){
335     stoppa = 0;
336     int per = 0;
337     figura2->Clear();
338 mocchiut 1.2 figura2->Range(0,0,100,100);
339     stringstream errore;
340     //figura2->SetFillColor(10);
341     errore.str("");
342     errore << "EXPERT -- File: " << file;
343     errore << " ";
344     TLatex *t=new TLatex();
345     t->SetTextFont(32);
346     t->SetTextColor(1);
347     t->SetTextAlign(12);
348     t->SetTextSize(0.015);
349     t->DrawLatex(2.,99.,errore.str().c_str());
350 mocchiut 1.1 //
351     // Book the histograms:
352     //
353     stringstream xview;
354     xview.str("");
355     xview << "x-view event " << (ci+1);
356     stringstream yview;
357     yview.str("");
358     yview << "y-view event " << (ci+1);
359     gDirectory->Delete(xview.str().c_str());
360     gDirectory->Delete(yview.str().c_str());
361     TH2F *Xview = new TH2F(xview.str().c_str(),"",96,-0.5,95.5,22,-0.5,21.5);
362     TH2F *Yview = new TH2F(yview.str().c_str(),"",96,-0.5,95.5,22,-0.5,21.5);
363     //
364     // figures:
365     //
366     Int_t bgcolor = 10;
367 mocchiut 1.2 t=new TLatex();
368 mocchiut 1.1 t->SetTextFont(32);
369     t->SetTextColor(1);
370     t->SetTextSize(0.03);
371     t->SetTextAlign(12);
372     //
373     TPad *pd1 = new TPad("pd1","This is pad1",0.02,0.05,0.88,0.49,bgcolor);
374     TPad *pd2 = new TPad("pd2","This is pad2",0.02,0.51,0.88,0.95,bgcolor);
375     TPad *palette = new TPad("palette","This is palette",0.90,0.05,0.98,0.9,bgcolor);
376     figura2->cd();
377     t=new TLatex();
378     t->SetTextFont(32);
379     t->SetTextColor(1);
380     t->SetTextSize(0.03);
381     t->SetTextAlign(12);
382     t->DrawLatex(92.,92.5,"MIP");
383     pd1->Range(0,0,100,100);
384     pd2->Range(0,0,100,100);
385     palette->Range(0,0,100,100);
386     pd1->SetTicks();
387     pd2->SetTicks();
388     pd1->Draw();
389     pd2->Draw();
390     palette->Draw();
391     palette->cd();
392     // palette
393     TPaveLabel *box1 = new TPaveLabel(2,2,98,16.3,"0","");
394     box1->SetTextFont(32);
395     box1->SetTextColor(1);
396     box1->SetTextSize(0.25);
397     box1->SetFillColor(10);
398     box1->Draw();
399     TPaveLabel *box2 = new TPaveLabel(2,18.3,98,32.66,"0-2","");
400     box2->SetTextFont(32);
401     box2->SetTextColor(1);
402     box2->SetTextSize(0.25);
403     box2->SetFillColor(38);
404     box2->Draw();
405     TPaveLabel *box3 = new TPaveLabel(2,34.66,98,48.96,"2-10","");
406     box3->SetTextFont(32);
407     box3->SetTextColor(1);
408     box3->SetTextSize(0.25);
409     box3->SetFillColor(4);
410     box3->Draw();
411     TPaveLabel *box4 = new TPaveLabel(2,50.96,98,65.26,"10-100","");
412     box4->SetTextFont(32);
413     box4->SetTextColor(1);
414     box4->SetTextSize(0.25);
415     box4->SetFillColor(3);
416     box4->Draw();
417     TPaveLabel *box5 = new TPaveLabel(2,67.26,98,81.56,"100-500","");
418     box5->SetTextFont(32);
419     box5->SetTextColor(1);
420     box5->SetTextSize(0.2);
421     box5->SetFillColor(2);
422     box5->Draw();
423     TPaveLabel *box6 = new TPaveLabel(2,83.56,98,97.86,">500","");
424     box6->SetTextFont(32);
425     box6->SetTextColor(1);
426     box6->SetTextSize(0.25);
427     box6->SetFillColor(6);
428     box6->Draw();
429     figura2->cd();
430     gStyle->SetOptDate(1);
431     pd1->cd();
432     gStyle->SetOptStat(0);
433     Xview->SetXTitle("strip");
434     Xview->SetYTitle("X - plane");
435     Xview->GetYaxis()->SetTitleOffset(0.5);
436     Xview->SetFillColor(bgcolor);
437     Xview->Fill(1.,1.,1.);
438     Xview->Draw("box");
439     pd1->Update();
440     pd2->cd();
441     gStyle->SetOptStat(0);
442     Yview->SetXTitle("strip");
443     Yview->SetYTitle("Y - plane");
444     Yview->GetYaxis()->SetTitleOffset(0.5);
445     Yview->SetFillColor(bgcolor);
446     Yview->Fill(1.,1.,1.);
447     Yview->Draw("box");
448     pd2->Update();
449     //
450     Int_t m = 0;
451     Int_t l = 3;
452     Int_t ss = 0;
453     Float_t estrip = 0.;
454     for ( Int_t s=0 ; s<4 ;s++ ){
455     tr->GetEntry(ci);
456     if ( cee->unpackError ){
457     per = 1;
458     } else {
459     if ( s == 0 ) ss = 0;
460     if ( s == 1 ) ss = 2;
461     if ( s == 2 ) ss = 3;
462     if ( s == 3 ) ss = 1;
463     per = 0;
464     for ( Int_t d=0 ; d<11 ;d++ ){
465     Int_t pre = -1;
466     for ( Int_t j=0; j<96 ;j++){
467     figura2->cd();
468     if ( j%16 == 0 ) pre++;
469     estrip = 0.;
470     if ( s == 2 ) m = 2*d+1;
471     if ( s == 3 ) m = 2*d;
472     if ( s == 0 ) m = 2*d;
473     if ( s == 1 ) m = 2*d+1;
474     if ( s == 3 ) l = 0;
475     if ( s == 2 ) l = 0;
476     if ( s == 1 ) l = 1;
477     if ( s == 0 ) l = 1;
478     estrip = (cee->calpuls[ss][d][j]-cee1->calpuls[ss][d][j])/26.;
479     if ( estrip > 0.7 ){
480     xview.str("");
481     xview << "x-view event " << j;
482     xview << " " << m;
483     xview << " " << l;
484     yview.str("");
485     yview << "y-view event " << j;
486     yview << " " << m;
487     yview << " " << l;
488     gDirectory->Delete(xview.str().c_str());
489     gDirectory->Delete(yview.str().c_str());
490     TH2F *Xview = new TH2F(xview.str().c_str(),"",96,-0.5,95.5,22,-0.5,21.5);
491     TH2F *Yview = new TH2F(yview.str().c_str(),"",96,-0.5,95.5,22,-0.5,21.5);
492     Int_t colo;
493     ColorMIP(estrip,colo);
494     Xview->SetFillColor(colo);
495     Yview->SetFillColor(colo);
496     if ( l == 0 ) {
497     Xview->Fill(j,m,1.);
498     pd1->cd();
499     Xview->Draw("box same");
500     };
501     if ( l == 1 ) {
502     Yview->Fill(j,m,1.);
503     pd2->cd();
504     Yview->Draw("box same");
505     };
506     };
507     if ( cee->calpuls[s][d][j] != 0. ) {
508     stoppa = 1;
509     };
510     if ( cee->calpuls[s][d][j] < 0. ) workornot = 0;
511     };
512     };
513     };
514     ci++;
515     };
516     if ( !per ){
517     pd1->Update();
518     pd2->Update();
519     figura2->Modified();
520     figura2->Update();
521     stringstream figsave;
522     figsave.str("");
523     figsave << "pulsematra2_";
524     figsave << ci;
525     if ( tosave ) PrintFigure(filename,outDir,figsave.str().c_str(),saveas,*figura2);
526     };
527     };
528     if ( stoppa ){
529     if ( workornot ){
530     printf("File %s is ok \n",filename.Data());
531     } else {
532     printf("File %s is NOT OK! \n",filename.Data());
533     };
534     };
535     }

  ViewVC Help
Powered by ViewVC 1.1.23