/[PAMELA software]/quicklook/tof/src/TofScan.cpp
ViewVC logotype

Annotation of /quicklook/tof/src/TofScan.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (hide annotations) (download) (vendor branch)
Thu May 11 10:07:39 2006 UTC (18 years, 6 months ago) by campana
Branch: ToF
CVS Tags: v1r00, start
Changes since 1.1: +0 -0 lines
ToF QuickLook script

1 campana 1.1 /**
2     * TOFScan
3     * Author Nagni
4     * Version 1.2
5     * Modified by G.De Rosa
6     * Date 27 Apr 2006
7     *
8     * Description:
9     * Describe the performance of the TOF.
10     *
11     * Parameters:
12     * TString base - the path to the root directory for the specific Pamela unpack session
13     * TString outDirectory - the path where to save the output image (Default = base)
14     * TString format - the format which will be used fo rsave the produced images (Default = "gif")
15     */
16    
17     #include <TString.h>
18     #include <TObjString.h>
19     #include <TTree.h>
20     #include <TBranch.h>
21     #include <TGraph.h>
22     #include <TStyle.h>
23     #include <TH2S.h>
24     #include <TPaveText.h>
25     #include <TCanvas.h>
26     #include <physics/tof/TofEvent.h>
27    
28    
29     #include <iostream>
30     using namespace std;
31    
32     void TofScan(TString base, TString outDirectory = "", TString format = ""){
33    
34     std::stringstream sst;
35     if (outDirectory == "") outDirectory = base.Data();
36     TString filename = ((TObjString*)base.Tokenize('/')->Last())->GetString();
37    
38     TFile *file =new TFile(base.Data()) ;
39     if (!file){
40     printf("file not Found \n");
41     return;
42     }
43    
44     TTree *PhysicsTr = (TTree*)file->Get("Physics");
45     TBranch *TofBr = PhysicsTr->GetBranch("Tof");
46     pamela::tof::TofEvent *tofEvent = 0;
47     PhysicsTr->SetBranchAddress("Tof", &tofEvent);
48    
49     Long64_t nevents = TofBr->GetEntries();
50     if (nevents <= 0) {
51     printf("nevents = %llu \n", nevents);
52     file->Close();
53     return;
54     }
55    
56     TH2S *tdcHisto = new TH2S("tdcHisto", sst.str().c_str(), 409, 0, 4096, 48, 0, 48);
57     TH2S *adcHisto = new TH2S("adcHisto", sst.str().c_str(), 409, 0, 4096, 48, 0, 48);
58    
59    
60     /*
61     * Array to convert hdc/adc to the real Photomultiplier
62     * The array rows definitions are:
63     * tof[0][] = chxxA (strip or channel xxA)
64     * tof[1][] = hbxxA (halfboard xxA)
65     * tof[2][] = chxxB (strip or channel xxB)
66     * tof[3][] = hbxxB (halfboard xxB)
67     *
68     * Each single row is a sequence of photomultipliers in this shape
69     * - The elements from 0 to 7 correspond to S11_1->S11_8
70     * - The elements from 8 to 13 correspond to S12_1->S12_6
71     * - The elements from 14 to 15 correspond to S21_1->S21_2
72     * - The elements from 16 to 17 correspond to S22_1->S22_2
73     * - The elements from 18 to 20 correspond to S31_1->S31_3
74     * - The elements from 21 to 23 correspond to S32_1->S32_3
75     *
76     * Example:
77     * -------> the tdc of the S12_3B photomultiplier correspond to tdc[(tof[2][10])][(tof[3][10])]
78     * -------> the tdc of the S31_3A photomultiplier correspond to tdc[(tof[0][20])][(tof[1][20])]
79     */
80     short tof[4][24] = {
81     {4, 4, 4, 4, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 1, 1, 1, 1, 2, 3, 3, 3, 3, 4},
82     {1, 3, 5, 7, 10, 12, 2, 4, 2, 4, 6, 8, 10, 12, 1, 5, 3, 9, 7, 9, 11, 1, 5, 9},
83     {2, 2, 2, 2, 1, 1, 1, 1, 4, 4, 4, 4, 4, 4, 2, 1, 2, 1, 2, 2, 2, 3, 3, 4},
84     {6, 8, 12, 10, 8, 6, 4, 2, 12, 10, 8, 6, 4, 2, 9, 7, 11, 11, 5, 3, 1, 3, 7, 11}
85     };
86    
87     TString photoS[48] = {
88     "S11_1A", "S11_1B", "S11_2A", "S11_2B", "S11_3A", "S11_3B", "S11_4A", "S11_4B",
89     "S11_5A", "S11_5B", "S11_6A", "S11_6B", "S11_7A", "S11_7B", "S11_8A", "S11_8B",
90     "S12_1A", "S12_1B", "S12_2A", "S12_2B", "S12_3A", "S12_3B", "S12_4A", "S12_4B", "S12_5A", "S12_5B", "S12_6A", "S12_6B",
91     "S21_1A", "S21_1B", "S21_2A", "S21_2B",
92     "S22_1A", "S22_1B", "S22_2A", "S22_2B",
93     "S31_1A", "S31_1B", "S31_2A", "S31_2B", "S31_3A", "S31_3B",
94     "S32_1A", "S32_1B", "S32_2A", "S32_2B", "S32_3A", "S32_3B"
95     };
96    
97     int i = 0;
98     int j = 0;
99     int k = 0;
100     int z = 0;
101     int ch = 0;
102     int hb = 0;
103    
104     while(i < nevents){
105     TofBr->GetEntry(i);
106     k = 0;
107     while (k < 24){
108     j = 0;
109     while (j < 2){
110     ch = tof[2*j][k] - 1;
111     hb = tof[2*j + 1][k] - 1;
112     tdcHisto->Fill(tofEvent->tdc[ch][hb], 2*k + j);
113     adcHisto->Fill(tofEvent->adc[ch][hb], 2*k + j);
114     j++;
115     }
116     k++;
117     }
118     i++;
119     }
120    
121     TH1D *tpADC = 0;
122     TH1D *tpTDC = 0;
123     TH1D *tpADCall = 0;
124     TH1D *tpTDCall = 0;
125    
126     float *X = new float[48];
127     float *means = new float[48];
128     float *entries = new float[48];
129     int *entriestdc = new int[48];
130     int *entriesadc = new int[48];
131    
132     const char *saveas = format;
133    
134     // all range ADC/TDC
135    
136     j = 0;
137     while (j < 12){
138     k = 0;
139     z = 0;
140    
141     while(k < 4){
142     if (k > 1) z = 2;
143     i = j*4 + k;
144     X[i] = i;
145    
146     tpTDCall = tdcHisto->ProjectionX(" ", i+1, i+1);
147     tpTDCall->SetAxisRange(0,4095);
148     entriestdc[i] = (Int_t)tpTDCall->Integral();
149    
150     tpADCall = adcHisto->ProjectionX(" ", i+1, i+1);
151     tpADCall->SetAxisRange(0,4095);
152     entriesadc[i] = (Int_t)tpADCall->Integral();
153    
154     k++;
155     }
156    
157     j++;
158    
159     }
160    
161     gStyle->SetStatW(0.4);
162     gStyle->SetStatH(0.4);
163     gStyle->SetOptStat("nmri");
164     gStyle->SetTitleH(0.10);
165     gStyle->SetTitleW(0.96);
166    
167     TCanvas *SCanvas = new TCanvas("SCanvas","SCanvas", 1280, 1024);
168     SCanvas->Divide(4,2);
169     j = 0;
170     while (j < 12){
171     k = 0;
172     z = 0;
173     if (gROOT->IsBatch()) {
174     SCanvas = new TCanvas("SCanvas","SCanvas", 1280, 1024);
175     SCanvas->Divide(4,2);
176     } else {
177     if (j > 0) SCanvas->DrawClone();
178     }
179    
180    
181     while(k < 4){
182     if (k > 1) z = 2;
183     i = j*4 + k;
184     X[i] = i;
185    
186     SCanvas->cd(k+3+z);
187     tpTDC = tdcHisto->ProjectionX(" ", i+1, i+1);
188     sst.str("");
189     sst << "TDC - " << photoS[i].Data() << " (Nev < 4096 = " << entriestdc[i] << ")";
190     tpTDC->SetTitle(sst.str().c_str());
191     tpTDC->SetTitleSize(10);
192     tpTDC->SetAxisRange(690,1510);
193     tpTDC->DrawCopy();
194     tpTDC->ComputeIntegral();
195     entries[i] = tpTDC->Integral();
196    
197     SCanvas->cd(k+1+z);
198     tpADC = adcHisto->ProjectionX(" ", i+1, i+1);
199     sst.str("");
200     sst << "ADC - " << photoS[i].Data() << " (Nev < 4096 = " << entriesadc[i] << ")";
201     tpADC->SetTitle(sst.str().c_str());
202     tpADC->SetAxisRange(-10,710);
203     tpADC->DrawCopy();
204     means[i] = tpADC->GetMean();
205    
206     k++;
207     }
208     if ( !strcmp(saveas,"ps") ) {
209     sst.str("");
210     sst << outDirectory.Data() << filename.Data() << "TOFScan.ps(";
211     SCanvas->Print(sst.str().c_str());
212     } else {
213     sst.str("");
214     sst << outDirectory.Data() << filename.Data() << "TOFScan" << j+1 << "." << saveas;
215     SCanvas->SaveAs(sst.str().c_str());
216    
217     }
218     j++;
219     }
220     if (gROOT->IsBatch()) SCanvas->Close();
221    
222     /*
223     * This Canvas will represent a summary of the performances for TOF TDC/ADC channels
224     */
225     TCanvas *performanceCanvas = new TCanvas("performanceCanvas","performanceCanvas", 1280, 1024);
226     performanceCanvas->Divide(1,2);
227    
228     gStyle->SetTitleW(.9);
229    
230     performanceCanvas->cd(1);
231     TGraph *adcMeans = new TGraph(48, X, means);
232     sst.str("");
233     sst << "ADCMean" << " - Data in " << base.Data() << " - Nevents in the run = " << nevents;
234     adcMeans->SetTitle(sst.str().c_str());
235     adcMeans->SetFillColor(2);
236     adcMeans->GetXaxis()->SetTitle("Photomultipliers");
237     adcMeans->GetXaxis()->CenterTitle();
238     adcMeans->GetXaxis()->SetLimits(-0.5, 47.5);
239     adcMeans->GetYaxis()->SetTitle("ADCMean");
240     adcMeans->GetYaxis()->CenterTitle();
241     adcMeans->Draw("AB");
242    
243     performanceCanvas->cd(2);
244     TGraph *tdcEntries = new TGraph(48, X, entries);
245     sst.str("");
246     sst << "TDCEntries" << " - Data in " << base.Data() << " - Nevents in the run = " << nevents;
247     tdcEntries->SetTitle(sst.str().c_str());
248     tdcEntries->SetFillColor(2);
249     tdcEntries->GetXaxis()->SetTitle("Photomultipliers");
250     tdcEntries->GetXaxis()->CenterTitle();
251     tdcEntries->GetXaxis()->SetLimits(-0.5, 47.5);
252     tdcEntries->GetYaxis()->SetTitle("TDCIntegral");
253     tdcEntries->GetYaxis()->CenterTitle();
254     tdcEntries->Draw("AB");
255    
256     //------print the ps
257    
258     if ( !strcmp(saveas,"ps") ) {
259     sst.str("");
260     sst << outDirectory.Data() << filename.Data() << "TOFScan.ps)";
261     performanceCanvas->Print(sst.str().c_str());
262    
263     } else {
264     sst.str("");
265     sst << outDirectory.Data() << filename.Data() << "TOFScan13." << saveas;
266     performanceCanvas->SaveAs(sst.str().c_str());
267     }
268     if (gROOT->IsBatch()) {
269     SCanvas->Close();
270     performanceCanvas->Close();
271     }
272    
273     }
274    
275     int main(int argc, char* argv[]){
276     TString path;
277     TString outDir ="./";
278     TString format ="ps";
279    
280     if (argc < 2){
281     printf("You have to insert at least the file to analyze \n");
282     printf("Try '--help' for more information. \n");
283     exit(1);
284     }
285    
286     if (!strcmp(argv[1], "--help")){
287     printf( "Usage: TofScan FILE [OPTION] \n");
288     printf( "\t --help Print this help and exit \n");
289     printf( "\t -outDir[path] Path where to put the output [default ./] \n");
290     printf( "\t -format[ps] Format for output files [default 'ps'] \n");
291     exit(1);
292     }
293    
294    
295     path=argv[1];
296    
297     for (int i = 2; i < argc; i++){
298    
299     if (!strcmp(argv[i], "-outDir")){
300     if (++i >= argc){
301     printf( "-outDir needs arguments. \n");
302     printf( "Try '--help' for more information. \n");
303     exit(1);
304     }
305     else{
306     outDir = argv[i];
307     continue;
308     }
309     }
310    
311    
312    
313     if (!strcmp(argv[i], "-format")){
314     if (++i >= argc){
315     printf( "-format needs arguments. \n");
316     printf( "Try '--help' for more information. \n");
317     exit(1);
318     }
319     else{
320     format = argv[i];
321     continue;
322     }
323     }
324     }
325    
326     TofScan(argv[1], outDir, format);
327    
328     }

  ViewVC Help
Powered by ViewVC 1.1.23