/[PAMELA software]/calo/flight/CaloFranzini/src/CaloFranzini.cpp
ViewVC logotype

Annotation of /calo/flight/CaloFranzini/src/CaloFranzini.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations) (download)
Tue Dec 4 12:05:29 2007 UTC (17 years ago) by mocchiut
Branch: MAIN
Branch point for: v0r00
Initial revision

1 mocchiut 1.1 /**
2     * \file CaloFranzini.cpp
3     * \author Emiliano Mocchiutti (2007/07/18)
4     */
5     //
6     // headers
7     //
8     #include <CaloFranzini.h>
9     //--------------------------------------
10     /**
11     * Default constructor
12     */
13     CaloFranzini::CaloFranzini(){
14     Clear();
15     }
16    
17     CaloFranzini::CaloFranzini(PamLevel2 *l2p){
18     //
19     file = NULL;
20     brig = NULL;
21     nbin = 0;
22     //
23     L2 = l2p;
24     //
25     if ( !L2->IsORB() ) printf(" WARNING: OrbitalInfo Tree is needed, the plugin could not work properly without it \n");
26     //
27     // Default variables
28     //
29     debug = false;
30     dolong = true;
31     dofull = false;
32     //
33     Clear();
34     //
35     }
36    
37     void CaloFranzini::Clear(){
38     //
39     OBT = 0;
40     PKT = 0;
41     atime = 0;
42     longtzeta = 0.;
43     fulltzeta = 0.;
44     memset(estrip, 0, 2*22*96*sizeof(Float_t));
45     memset(qplane, 0, 2*22*sizeof(Float_t));
46     //
47     }
48    
49     void CaloFranzini::Print(){
50     //
51     Process();
52     //
53     printf("========================================================================\n");
54     printf(" OBT: %u PKT: %u ATIME: %u \n",OBT,PKT,atime);
55     printf(" debug [debug flag]:.. %i\n",debug);
56     printf(" longtzeta :.. %f\n",longtzeta);
57     printf(" fulltzeta :.. %f\n",fulltzeta);
58     printf("========================================================================\n");
59     //
60     }
61    
62     void CaloFranzini::Delete(){
63     if ( file ) file->Close();
64     Clear();
65     printf(" ERROR: CaloFranzini variables _NOT_ filled \n");
66     };
67     //
68     if ( debug ) this->Print();
69     if ( debug ) printf(" exit \n");
70     //
71     }
72    
73     Bool_t CaloFranzini::CreateMatrixFile(TString matrixfile){
74     //
75     file = new TFile(matrixfile.Data(),"READ");
76     //
77     if ( !file || file->IsZombie() ){
78     file = new TFile(matrixfile.Data(),"RECREATE");
79     } else {
80     printf(" ERROR: file %s already existing!\n Choose another name or delete the old file\n",matrixfile.Data());
81     return(false);
82     };
83     //
84     return(true);
85     //
86     }
87    
88     void CaloFranzini::WriteNumBin(Int_t numbin){
89     TArrayI nbi(1, &numbin);
90     file->WriteObject(&nbi, "nbinenergy");
91     }
92    
93     void CaloFranzini::WriteRigBin(TArrayF *rigbin){
94     file->WriteObject(&rigbin, "binrig");
95     }
96    
97     void CaloFranzini::WriteLongMean(TArrayF *qpl, Int_t bin){
98     TString name = Form("qplmeann%i",bin);
99     file->WriteObject(&qpl,name.Data());
100     }
101    
102     void CaloFranzini::WriteLongMatrix(TMatrixD *mat, Int_t bin){
103     TString name = Form("matrixn%i",bin);
104     file->WriteObject(&(*mat),name.Data());
105     }
106    
107     void CaloFranzini::CloseMatrixFile(){
108     file->Close();
109     }
110    
111    
112     Bool_t CaloFranzini::Open(TString matrixfile){
113     //
114     // find matrix file
115     //
116     if ( !strcmp(matrixfile.Data(),"") ){
117     if (dolong) matrixfile = (TString)gSystem->ExpandPathName("$PAM_CALIB")+"/cal-param/covmatrix_longel.root";
118     if (dofull) matrixfile = (TString)gSystem->ExpandPathName("$PAM_CALIB")+"/cal-param/covmatrix_fullel.root";
119     };
120     //
121     file = new TFile(matrixfile.Data(),"READ");
122     //
123     if ( !file || file->IsZombie() ){
124     printf(" ERROR: cannot open file %s \n",matrixfile.Data());
125     return(false);
126     };
127     //
128     TArrayI *numbin = (TArrayI*)file->Get("nbinenergy");
129     if ( !numbin ){
130     printf(" ERROR: cannot read number of bins from file %s \n",matrixfile.Data());
131     return(false);
132     };
133     nbin = (Int_t)numbin->At(0);
134     if ( nbin <= 0 ){
135     printf(" ERROR: cannot work with 0 energy bins (from file %s) \n",matrixfile.Data());
136     return(false);
137     };
138     //
139     brig = (TArrayF*)file->Get("binrig");
140     if ( !brig ){
141     printf(" ERROR: cannot read rigidity binning from file %s \n",matrixfile.Data());
142     return(false);
143     };
144     //
145     return(true);
146     //
147     }
148    
149     TMatrixD *CaloFranzini::LoadCovarianceMatrix(Float_t rig){
150     //
151     TString name;
152     for (Int_t i = 0; i<nbin-1; i++){
153     if ( rig>=brig->At(i) && rig < brig->At(i+1) ){
154     name = Form("matrixn%i",i);
155     break;
156     };
157     };
158     if ( rig < brig->At(0) ){
159     printf(" WARNING: Event with rigidity lower than the first covariance matrix bin (rig = %f, lower limit = %f)\n",rig,brig->At(0));
160     name = "matrixn0";
161     printf(" Using matrix %s \n",name.Data());
162     };
163     if ( rig >= brig->At(nbin) ){
164     printf(" WARNING: Event with rigidity higher than the last covariance matrix bin (rig = %f, upper limit = %f)\n",rig,brig->At(nbin));
165     name = Form("matrixn%i",nbin-1);
166     printf(" Using matrix %s \n",name.Data());
167     };
168     //
169     TMatrixD *matrix = (TMatrixD*)file->Get(name.Data());
170     //
171     return(matrix);
172     //
173     }
174    
175    
176     TArrayF *CaloFranzini::LoadLongAverage(Float_t rig){
177     //
178     TString name;
179     for (Int_t i = 0; i<nbin-1; i++){
180     if ( rig>=brig->At(i) && rig < brig->At(i+1) ){
181     name = Form("qplmeann%i",i);
182     break;
183     };
184     };
185     if ( rig < brig->At(0) ){
186     printf(" WARNING: Event with rigidity lower than the first qplmean bin (rig = %f, lower limit = %f)\n",rig,brig->At(0));
187     name = "qplmeann0";
188     printf(" Using qplmean %s \n",name.Data());
189     };
190     if ( rig >= brig->At(nbin) ){
191     printf(" WARNING: Event with rigidity higher than the last qplmean bin (rig = %f, upper limit = %f)\n",rig,brig->At(nbin));
192     name = Form("qplmeann%i",nbin-1);
193     printf(" Using qplmean %s \n",name.Data());
194     };
195     //
196     TArrayF *qplmean = (TArrayF*)file->Get(name.Data());
197     //
198     return(qplmean);
199     //
200     }

  ViewVC Help
Powered by ViewVC 1.1.23