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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

1 mocchiut 1.1 //
2     //- Emiliano Mocchiutti
3     //
4     // FCaloCALIBSCAN.cxx version 1.01 (2006-03-08)
5     //
6     // The only input needed is
7     //
8     // Changelog:
9     //
10     // 1.00 - 1.01 (2006-03-08): Flight version, read unique YODA file.
11     //
12     // 0.00 - 1.00 (2006-03-08): Clone of CaloCALIBSCAN.
13     //
14     #include <fstream>
15     #include <sstream>
16     #include <string>
17     #include <TTree.h>
18     #include <TClassEdit.h>
19     #include <TObject.h>
20     #include <TList.h>
21     #include <TSystem.h>
22     #include <TSystemDirectory.h>
23     #include <TString.h>
24     #include <TFile.h>
25     #include <TClass.h>
26     #include <TCanvas.h>
27     #include <TH1.h>
28     #include <TH1F.h>
29     #include <TH2D.h>
30     #include <TLatex.h>
31     #include <TPad.h>
32     #include <TPaveLabel.h>
33     #include <TChain.h>
34     #include <TStyle.h>
35     //
36     #include <PamelaRun.h>
37     #include <physics/calorimeter/CalorimeterEvent.h>
38     #include <physics/trigger/TriggerEvent.h>
39     #include <CalibCalPedEvent.h>
40     #include <fcalostructs.h>
41     //
42     extern bool existfile(TString);
43     extern void stringcopy(TString&, const TString&, Int_t, Int_t);
44     extern TString getFilename(const TString);
45     //
46     #include <caloclassesfun.h>
47     //
48     using namespace std;
49     //
50    
51     short int FCaloCALIBSCAN(TString Filename, TString flist=""){
52     const char* startingdir = gSystem->WorkingDirectory();
53     TString calcalib;
54     struct Calib calib;
55     //
56     stringstream file5;
57     file5.str("");
58     file5 << startingdir << "/CaloCALIBdata.root";
59     //
60     Int_t nfile = 0;
61     Int_t calibex = 0;
62     Int_t fileup = 0;
63     if ( flist != "" ){
64     printf("\n You have given an input file list \n\n Files: \n");
65     ifstream in;
66     in.open(flist, ios::in);
67     char ctime[20];
68     while (1) {
69     in >> ctime;
70     if (!in.good()) break;
71     printf(" File number %i = %s \n",nfile+1,ctime);
72     nfile++;
73     };
74     in.close();
75     if ( !nfile ) {
76     printf("\n\n The list is empty, exiting... \n\n");
77     return(0);
78     };
79     } else {
80     nfile = 1;
81     };
82     printf("\n");
83     //
84     // First check if the calibration file exists:
85     //
86     Int_t EFILE = 0;
87     printf(" Check the existence of CaloCALIBdata.root file: \n\n");
88     //
89     if ( !existfile((TString)file5.str().c_str()) ){
90     printf(" %s :no such file or directory \n",file5.str().c_str());
91     printf("\n OK, I will create it!\n\n");
92     EFILE = 0;
93     } else {
94     printf(" The file already exists! It will be updated \n\n");
95     EFILE = 1;
96     }
97     //
98     // this must be done for each file.
99     //
100     Long64_t neven = 0;
101     TTree *trl1 = 0;
102     TFile *hfl1 = 0;
103     CalorimeterCalibScan *calo = new CalorimeterCalibScan();
104     if ( EFILE == 1 ){
105     //
106     // If the file doesn't exist create it
107     //
108     hfl1 = new TFile(file5.str().c_str(),"UPDATE","Calorimeter calib data");
109 mocchiut 1.2 // calo = new CalorimeterCalibScan();
110 mocchiut 1.1 //
111     trl1 = (TTree*)hfl1->Get("CaloCALIBdata");
112     trl1->SetBranchAddress("Event", &calo);
113     neven = trl1->GetEntries()-1;
114     trl1->GetEntry(neven);
115     calibex = calo->evno;
116     } else {
117     //
118     // If the file doesn't exist create it
119     //
120     hfl1 = new TFile(file5.str().c_str(),"RECREATE","Calorimeter calib data");
121     //
122 mocchiut 1.2 // calo = new CalorimeterCalibScan();
123 mocchiut 1.1 //
124     trl1 = new TTree("CaloCALIBdata","PAMELA calorimeter calibration data");
125     trl1->Branch("Event","CalorimeterCalibScan",&calo);
126     };
127     //
128     const char *filename2 = Filename;
129     //
130     TString lfile;
131     TString sfile;
132     //
133     Int_t e = 0;
134     ifstream in;
135     in.open(flist, ios::in);
136     char ctime[20];
137     const char *nome;
138     //
139     TString fififile;
140     const char *file;
141     TString filename;
142     //
143     stringstream lfillo;
144     //
145     pamela::CalibCalPedEvent *ce = 0;
146     pamela::PscuHeader *cph = 0;
147     pamela::EventHeader *ceh = 0;
148     Long64_t ncalibs = 0;
149     Int_t s = -1;
150     Int_t l = 0;
151     Int_t m = 0;
152     Int_t ss = 0;
153 mocchiut 1.2 TTree *tr = 0;
154     TFile *File = 0;
155 mocchiut 1.1 //
156     while ( e < nfile ){
157     if ( flist != "" ){
158     in >> ctime;
159     lfillo.str("");
160     lfillo << filename2 << "/";
161     lfillo << ctime;
162     lfile = (TString)lfillo.str().c_str();
163     fififile = getFilename(lfile);
164     file = fififile;
165     lfillo.str("");
166     lfillo << file;
167     sfile = (TString)lfillo.str().c_str();
168     } else {
169     lfillo.str("");
170     lfillo << filename2;
171     lfile = (TString)lfillo.str().c_str();
172     fififile = getFilename(lfile);
173     file = fififile;
174     lfillo.str("");
175     lfillo << file;
176     sfile = (TString)lfillo.str().c_str();
177     };
178     //
179     filename = lfile;
180     nome = filename;
181     printf("\n Processing file number %i: %s \n\n",e+1,nome);
182     //
183 mocchiut 1.2 const string fil = (const char *)(gSystem->BaseName(filename));
184     Int_t posiz = 0;
185     // Int_t posiz = fil.find("dw_");
186     // if ( posiz == -1 ) posiz = fil.find("DW_");
187     // if ( posiz == -1 ) return(-1);
188     TString filenam2=(TString)(gSystem->BaseName(filename));
189     TString year;
190     stringcopy(year,filenam2,posiz,posiz+5);
191     const char *ye = year;
192     TString month;
193     stringcopy(month,filenam2,posiz+7,posiz+9);
194     const char *mo = month;
195     TString day;
196     stringcopy(day,filenam2,posiz+11,posiz+13);
197     const char *da = day;
198     // TString fno;
199     // stringcopy(fno,filename,posiz+10,posiz+13);
200     // const char *fn = fno;
201     stringstream unino;
202     unino.str("");
203     unino << ye << mo;
204     unino << da;
205     // unino << da << fn;
206     //
207     // stringstream unino;
208     // unino.str("");
209     // unino << (e+1);
210     // unino << ye;
211     //
212     // printf("unino is %s \n",unino.str().c_str());
213 mocchiut 1.1 //
214     // upgrade data...
215     //
216     if ( !existfile(filename) ){
217     printf(" %s :no such file or directory \n",filename.Data());
218     goto jumpfile;
219     };
220     File = new TFile(filename.Data());
221 mocchiut 1.2 // tr = new TTree;
222 mocchiut 1.1 tr = (TTree*)File->Get("CalibCalPed");
223     tr->SetBranchAddress("Header", &ceh);
224     tr->SetBranchAddress("CalibCalPed", &ce);
225     ncalibs = tr->GetEntries();
226     if ( ncalibs == 0 ) goto oltre;
227 mocchiut 1.2 //calo = new CalorimeterCalibScan();
228 mocchiut 1.1 s = -1;
229     l = 0;
230     m = 0;
231 mocchiut 1.2 calo->Clear();
232 mocchiut 1.1 for (Int_t ci = 0; ci < ncalibs ; ci++){
233 mocchiut 1.2 // calo = new CalorimeterCalibScan();
234 mocchiut 1.1 tr->GetEntry(ci);
235     //
236     s++;
237     if ( s == 4 ) s = 0;
238     if ( s == 0 ) ss = 0;
239     if ( s == 1 ) ss = 2;
240     if ( s == 2 ) ss = 3;
241     if ( s == 3 ) ss = 1;
242     //
243     if ( s == 0 ){
244     Double_t noca = (double)ci/100.;
245     Double_t calno = atof(unino.str().c_str())+noca;
246     calo->calno = calno;
247     calibex++;
248     calo->evno = calibex;
249     };
250     //
251     //
252     if (ce->cstwerr[s] != 0 && ce->cperror[s] == 0 ) {
253     cph = ceh->GetPscuHeader();
254     calo->etime[ss] = cph->GetOrbitalTime();
255     for ( Int_t d=0 ; d<11 ;d++ ){
256     Int_t pre = -1;
257     if ( s == 2 ) m = 2*d+1;
258     if ( s == 3 ) m = 2*d;
259     if ( s == 0 ) m = 2*d;
260     if ( s == 1 ) m = 2*d+1;
261     if ( s == 3 ) l = 0;
262     if ( s == 2 ) l = 0;
263     if ( s == 1 ) l = 1;
264     if ( s == 0 ) l = 1;
265     for ( Int_t j=0; j<96 ;j++){
266     if ( j%16 == 0 ) pre++;
267     calo->calped[l][m][j] = ce->calped[ss][d][j];
268     calo->cstwerr[ss] = ce->cstwerr[s];
269     calo->cperror[ss] = ce->cperror[s];
270     calo->calgood[l][m][j] = ce->calgood[ss][d][j];
271     calo->calthr[l][m][pre] = ce->calthr[ss][d][pre];
272     calo->calrms[l][m][j] = ce->calrms[ss][d][j]/4.;
273     calo->calbase[l][m][pre] = ce->calbase[ss][d][pre];
274     calo->calvar[l][m][pre] = ce->calvar[ss][d][pre];
275     };
276     };
277     };
278     //
279     if ( s == 3 ){
280     trl1->Fill();
281 mocchiut 1.2 calo->Clear();
282     // calo = new CalorimeterCalibScan();
283 mocchiut 1.1 };
284     };
285 mocchiut 1.2 //
286     //if ( calo ) delete calo;
287     //
288 mocchiut 1.1 fileup++;
289     //
290     goto oltre;
291     jumpfile: printf(" File not processed! \n ");
292     oltre:
293 mocchiut 1.2 if ( File ) File->Close();
294     // if ( tr ) delete tr;
295 mocchiut 1.1 e++;
296     };
297     hfl1->Write();
298     hfl1->Close();
299     return(0);
300     }

  ViewVC Help
Powered by ViewVC 1.1.23