/[PAMELA software]/PamelaDigitizer/Digitizer.cxx
ViewVC logotype

Annotation of /PamelaDigitizer/Digitizer.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.9 - (hide annotations) (download)
Fri Jun 6 17:28:39 2008 UTC (16 years, 5 months ago) by pamelats
Branch: MAIN
CVS Tags: v3r01
Changes since 1.8: +4 -4 lines
*** empty log message ***

1 pamelats 1.7 // ------ PAMELA Digitizer ------
2     //
3     // Date, release and how-to: see file Pamelagp2Digits.cxx
4     //
5     // NB: Check length physics packet [packet type (0x10 = physics data)]
6     //
7     #include <sstream>
8     #include <fstream>
9     #include <stdlib.h>
10     #include <stdio.h>
11     #include <string.h>
12     #include <ctype.h>
13     #include <time.h>
14     #include "Riostream.h"
15     #include "TFile.h"
16     #include "TDirectory.h"
17     #include "TTree.h"
18     #include "TLeafI.h"
19     #include "TH1.h"
20     #include "TH2.h"
21     #include "TF1.h"
22     #include "TMath.h"
23     #include "TRandom.h"
24     #include "TSQLServer.h"
25     #include "TSystem.h"
26     #include "CalibTrk1Event.h"
27     #include "CalibTrk2Event.h"
28     //
29     #include "Digitizer.h"
30     #include "CRC.h"
31     //
32     #include <PamelaRun.h>
33     #include <physics/calorimeter/CalorimeterEvent.h>
34     #include <CalibCalPedEvent.h>
35     #include "GLTables.h"
36     //
37     extern "C"{
38     short crc(short, short);
39     };
40     //
41    
42 pamelats 1.8 Digitizer::Digitizer(TTree* tree, char* &file_raw,int nspe,int ntof,int ncat,int ncas,int ncar,int ncal,int nnd,int nstr){
43 pamelats 1.7 fhBookTree = tree;
44     fFilename = file_raw;
45     fCounter = 0;
46     fCounterPhys = 0; // SO 5/12/'07
47     fOBT = 0;
48    
49     //
50     // DB connections
51     //
52     TString host = "mysql://localhost/pamelaprod";
53     TString user = "anonymous";
54     TString psw = "";
55     //
56     const char *pamdbhost=gSystem->Getenv("PAM_DBHOST");
57     const char *pamdbuser=gSystem->Getenv("PAM_DBUSER");
58     const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW");
59     if ( !pamdbhost ) pamdbhost = "";
60     if ( !pamdbuser ) pamdbuser = "";
61     if ( !pamdbpsw ) pamdbpsw = "";
62     if ( strcmp(pamdbhost,"") ) host = pamdbhost;
63     if ( strcmp(pamdbuser,"") ) user = pamdbuser;
64     if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw;
65     fDbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
66     //
67     GL_TABLES *glt = new GL_TABLES(host,user,psw);
68     if ( glt->IsConnected(fDbc) ) printf("\n DB INFORMATION:\n SQL: %s Version: %s Host %s Port %i \n\n",fDbc->GetDBMS(),fDbc->ServerInfo(),fDbc->GetHost(),fDbc->GetPort());
69     //
70     // Use UTC in the DB and make timeout bigger
71     //
72     stringstream myquery;
73     myquery.str("");
74     myquery << "SET time_zone='+0:00'";
75     fDbc->Query(myquery.str().c_str());
76     myquery.str("");
77     myquery << "SET wait_timeout=173000;";
78     fDbc->Query(myquery.str().c_str());
79     //
80    
81     std:: cout << "preparing tree" << endl;
82    
83 pamelats 1.8 ntf=(int*)malloc(1 *sizeof(int));
84     *ntf=ntof;
85     Ipltof=(UChar_t*)malloc(ntof *sizeof(UChar_t));
86     Ipaddle=(UChar_t*)malloc(ntof *sizeof(UChar_t));
87 pamelats 1.9 Ipartof=(UShort_t*)malloc(ntof *sizeof(UShort_t));
88     // Ipartof=(UChar_t*)malloc(ntof *sizeof(UChar_t));
89 pamelats 1.8 Xintof=(Float_t*)malloc(ntof *sizeof(Float_t));
90     Yintof=(Float_t*)malloc(ntof *sizeof(Float_t));
91     Zintof=(Float_t*)malloc(ntof *sizeof(Float_t));
92     Xouttof=(Float_t*)malloc(ntof *sizeof(Float_t));
93     Youttof=(Float_t*)malloc(ntof *sizeof(Float_t));
94     Zouttof=(Float_t*)malloc(ntof *sizeof(Float_t));
95     Ereltof=(Float_t*)malloc(ntof *sizeof(Float_t));
96     Timetof=(Float_t*)malloc(ntof *sizeof(Float_t));
97     Pathtof=(Float_t*)malloc(ntof *sizeof(Float_t));
98     P0tof=(Float_t*)malloc(ntof *sizeof(Float_t));
99     Iparcat=(UChar_t*)malloc(ncat *sizeof(UChar_t));
100     Icat=(UChar_t*)malloc(ncat *sizeof(UChar_t));
101     Xincat=(Float_t*)malloc(ncat *sizeof(Float_t));
102     Yincat=(Float_t*)malloc(ncat *sizeof(Float_t));
103     Zincat=(Float_t*)malloc(ncat *sizeof(Float_t));
104     Xoutcat=(Float_t*)malloc(ncat *sizeof(Float_t));
105     Youtcat=(Float_t*)malloc(ncat *sizeof(Float_t));
106     Zoutcat=(Float_t*)malloc(ncat *sizeof(Float_t));
107     Erelcat=(Float_t*)malloc(ncat *sizeof(Float_t));
108     Timecat=(Float_t*)malloc(ncat *sizeof(Float_t));
109     Pathcat=(Float_t*)malloc(ncat *sizeof(Float_t));
110     P0cat=(Float_t*)malloc(ncat *sizeof(Float_t));
111     Iparcas=(UChar_t*)malloc(ncas *sizeof(UChar_t));
112     Icas=(UChar_t*)malloc(ncas *sizeof(UChar_t));
113     Xincas=(Float_t*)malloc(ncas *sizeof(Float_t));
114     Yincas=(Float_t*)malloc(ncas *sizeof(Float_t));
115     Zincas=(Float_t*)malloc(ncas *sizeof(Float_t));
116     Xoutcas=(Float_t*)malloc(ncas *sizeof(Float_t));
117     Youtcas=(Float_t*)malloc(ncas *sizeof(Float_t));
118     Zoutcas=(Float_t*)malloc(ncas *sizeof(Float_t));
119     Erelcas=(Float_t*)malloc(ncas *sizeof(Float_t));
120     Timecas=(Float_t*)malloc(ncas *sizeof(Float_t));
121     Pathcas=(Float_t*)malloc(ncas *sizeof(Float_t));
122     P0cas=(Float_t*)malloc(ncas *sizeof(Float_t));
123 pamelats 1.9 Iparspe=(UShort_t*)malloc(nspe *sizeof(UShort_t));
124     //Iparspe=(UChar_t*)malloc(nspe *sizeof(UChar_t));
125 pamelats 1.8 Itrpb=(UChar_t*)malloc(nspe *sizeof(UChar_t));
126     Itrsl=(UChar_t*)malloc(nspe *sizeof(UChar_t));
127     Itspa=(UChar_t*)malloc(nspe *sizeof(UChar_t));
128     Xinspe=(Float_t*)malloc(nspe *sizeof(Float_t));
129     Yinspe=(Float_t*)malloc(nspe *sizeof(Float_t));
130     Zinspe=(Float_t*)malloc(nspe *sizeof(Float_t));
131     Xoutspe=(Float_t*)malloc(nspe *sizeof(Float_t));
132     Youtspe=(Float_t*)malloc(nspe *sizeof(Float_t));
133     Zoutspe=(Float_t*)malloc(nspe *sizeof(Float_t));
134     Xavspe=(Float_t*)malloc(nspe *sizeof(Float_t));
135     Yavspe=(Float_t*)malloc(nspe *sizeof(Float_t));
136     Zavspe=(Float_t*)malloc(nspe *sizeof(Float_t));
137     Erelspe=(Float_t*)malloc(nspe *sizeof(Float_t));
138     Pathspe=(Float_t*)malloc(nspe *sizeof(Float_t));
139     P0spe=(Float_t*)malloc(nspe *sizeof(Float_t));;
140     Nxmult=(UChar_t*)malloc(nspe *sizeof(UChar_t));
141     Nymult=(UChar_t*)malloc(nspe *sizeof(UChar_t));
142     Istripx=(UShort_t*)malloc(nstr *sizeof(UShort_t));
143     Qstripx=(Float_t*)malloc(nstr *sizeof(Float_t));
144     Xstripx=(Float_t*)malloc(nstr *sizeof(Float_t));
145     Npstripx=(UChar_t*)malloc(nstr *sizeof(UChar_t));
146     Ntstripx=(UChar_t*)malloc(nstr *sizeof(UChar_t));
147     Npstripy=(UChar_t*)malloc(nstr *sizeof(UChar_t));
148     Ntstripy=(UChar_t*)malloc(nstr *sizeof(UChar_t));
149     Istripy=(UShort_t*)malloc(nstr *sizeof(UShort_t));
150     Qstripy=(Float_t*)malloc(nstr *sizeof(Float_t));
151     Ystripy=(Float_t*)malloc(nstr *sizeof(Float_t));
152     Icapl=(UChar_t*)malloc(ncal *sizeof(UChar_t));
153     Icasi=(UChar_t*)malloc(ncal *sizeof(UChar_t));
154     Icast=(UChar_t*)malloc(ncal *sizeof(UChar_t));
155     Xincal=(Float_t*)malloc(ncal *sizeof(Float_t));
156     Yincal=(Float_t*)malloc(ncal *sizeof(Float_t));
157     Zincal=(Float_t*)malloc(ncal *sizeof(Float_t));
158     Erelcal=(Float_t*)malloc(ncal *sizeof(Float_t));
159     Itubend=(UChar_t*)malloc(nnd *sizeof(UChar_t));
160     Iparnd=(UChar_t*)malloc(nnd *sizeof(UChar_t));
161     Xinnd=(Float_t*)malloc(nnd *sizeof(Float_t));
162     Yinnd=(Float_t*)malloc(nnd *sizeof(Float_t));
163     Zinnd=(Float_t*)malloc(nnd *sizeof(Float_t));
164     Xoutnd=(Float_t*)malloc(nnd *sizeof(Float_t));
165     Youtnd=(Float_t*)malloc(nnd *sizeof(Float_t));
166     Zoutnd=(Float_t*)malloc(nnd *sizeof(Float_t));
167     Erelnd=(Float_t*)malloc(nnd *sizeof(Float_t));
168     Timend=(Float_t*)malloc(nnd *sizeof(Float_t));
169     Pathnd=(Float_t*)malloc(nnd *sizeof(Float_t));
170     P0nd=(Float_t*)malloc(nnd *sizeof(Float_t));
171     Iparcard=(UChar_t*)malloc(ncar *sizeof(UChar_t));
172     Icard=(UChar_t*)malloc(ncar *sizeof(UChar_t));
173     Xincard=(Float_t*)malloc(ncar *sizeof(Float_t));
174     Yincard=(Float_t*)malloc(ncar *sizeof(Float_t));
175     Zincard=(Float_t*)malloc(ncar *sizeof(Float_t));
176     Xoutcard=(Float_t*)malloc(ncar *sizeof(Float_t));
177     Youtcard=(Float_t*)malloc(ncar *sizeof(Float_t));
178     Zoutcard=(Float_t*)malloc(ncar *sizeof(Float_t));
179     Erelcard=(Float_t*)malloc(ncar *sizeof(Float_t));
180     Timecard=(Float_t*)malloc(ncar *sizeof(Float_t));
181     Pathcard=(Float_t*)malloc(ncar *sizeof(Float_t));
182     P0card=(Float_t*)malloc(ncar *sizeof(Float_t));
183    
184    
185    
186 pamelats 1.7 // prepare tree//modified by E.Vannuccini 03/08
187     if(fhBookTree->GetBranch("Irun"))fhBookTree->SetBranchAddress("Irun",&Irun);
188     if(fhBookTree->GetBranch("Ievnt"))fhBookTree->SetBranchAddress("Ievnt",&Ievnt);
189     if(fhBookTree->GetBranch("Ipa"))fhBookTree->SetBranchAddress("Ipa",&Ipa);
190     if(fhBookTree->GetBranch("X0"))fhBookTree->SetBranchAddress("X0",&X0);
191     if(fhBookTree->GetBranch("Y0"))fhBookTree->SetBranchAddress("Y0",&Y0);
192     if(fhBookTree->GetBranch("Z0"))fhBookTree->SetBranchAddress("Z0",&Z0);
193     if(fhBookTree->GetBranch("Theta"))fhBookTree->SetBranchAddress("Theta",&Theta);
194     if(fhBookTree->GetBranch("Phi"))fhBookTree->SetBranchAddress("Phi",&Phi);
195     if(fhBookTree->GetBranch("P0"))fhBookTree->SetBranchAddress("P0",&P0);
196     if(fhBookTree->GetBranch("Nthtof"))fhBookTree->SetBranchAddress("Nthtof",&Nthtof);
197 pamelats 1.8 if(fhBookTree->GetBranch("Ipltof"))fhBookTree->SetBranchAddress("Ipltof",Ipltof);///////////////////////////
198 pamelats 1.7 if(fhBookTree->GetBranch("Ipaddle"))fhBookTree->SetBranchAddress("Ipaddle",Ipaddle);
199     if(fhBookTree->GetBranch("Ipartof"))fhBookTree->SetBranchAddress("Ipartof",Ipartof);
200     if(fhBookTree->GetBranch("Xintof"))fhBookTree->SetBranchAddress("Xintof",Xintof);
201     if(fhBookTree->GetBranch("Yintof"))fhBookTree->SetBranchAddress("Yintof",Yintof);
202     if(fhBookTree->GetBranch("Zintof"))fhBookTree->SetBranchAddress("Zintof",Zintof);
203     if(fhBookTree->GetBranch("Xouttof"))fhBookTree->SetBranchAddress("Xouttof",Xouttof);
204     if(fhBookTree->GetBranch("Youttof"))fhBookTree->SetBranchAddress("Youttof",Youttof);
205     if(fhBookTree->GetBranch("Zouttof"))fhBookTree->SetBranchAddress("Zouttof",Zouttof);
206     if(fhBookTree->GetBranch("Ereltof"))fhBookTree->SetBranchAddress("Ereltof",Ereltof);
207     if(fhBookTree->GetBranch("Timetof"))fhBookTree->SetBranchAddress("Timetof",Timetof);
208     if(fhBookTree->GetBranch("Pathtof"))fhBookTree->SetBranchAddress("Pathtof",Pathtof);
209     if(fhBookTree->GetBranch("P0tof"))fhBookTree->SetBranchAddress("P0tof",P0tof);
210     if(fhBookTree->GetBranch("Nthcat"))fhBookTree->SetBranchAddress("Nthcat",&Nthcat);
211     if(fhBookTree->GetBranch("Iparcat"))fhBookTree->SetBranchAddress("Iparcat",Iparcat);
212     if(fhBookTree->GetBranch("Icat"))fhBookTree->SetBranchAddress("Icat",Icat);
213     if(fhBookTree->GetBranch("Xincat"))fhBookTree->SetBranchAddress("Xincat",Xincat);
214     if(fhBookTree->GetBranch("Yincat"))fhBookTree->SetBranchAddress("Yincat",Yincat);
215     if(fhBookTree->GetBranch("Zincat"))fhBookTree->SetBranchAddress("Zincat",Zincat);
216     if(fhBookTree->GetBranch("Xoutcat"))fhBookTree->SetBranchAddress("Xoutcat",Xoutcat);
217     if(fhBookTree->GetBranch("Youtcat"))fhBookTree->SetBranchAddress("Youtcat",Youtcat);
218     if(fhBookTree->GetBranch("Zoutcat"))fhBookTree->SetBranchAddress("Zoutcat",Zoutcat);
219     if(fhBookTree->GetBranch("Erelcat"))fhBookTree->SetBranchAddress("Erelcat",Erelcat);
220     if(fhBookTree->GetBranch("Timecat"))fhBookTree->SetBranchAddress("Timecat",Timecat);
221     if(fhBookTree->GetBranch("Pathcat"))fhBookTree->SetBranchAddress("Pathcat",Pathcat);
222     if(fhBookTree->GetBranch("P0cat"))fhBookTree->SetBranchAddress("P0cat",P0cat);
223     if(fhBookTree->GetBranch("Nthcas"))fhBookTree->SetBranchAddress("Nthcas",&Nthcas);
224     if(fhBookTree->GetBranch("Iparcas"))fhBookTree->SetBranchAddress("Iparcas",Iparcas);
225 pamelats 1.8 if(fhBookTree->GetBranch("Icas"))fhBookTree->SetBranchAddress("Icas",Icas);///////////////////////////////
226 pamelats 1.7 if(fhBookTree->GetBranch("Xincas"))fhBookTree->SetBranchAddress("Xincas",Xincas);
227     if(fhBookTree->GetBranch("Yincas"))fhBookTree->SetBranchAddress("Yincas",Yincas);
228     if(fhBookTree->GetBranch("Zincas"))fhBookTree->SetBranchAddress("Zincas",Zincas);
229     if(fhBookTree->GetBranch("Xoutcas"))fhBookTree->SetBranchAddress("Xoutcas",Xoutcas);
230     if(fhBookTree->GetBranch("Youtcas"))fhBookTree->SetBranchAddress("Youtcas",Youtcas);
231     if(fhBookTree->GetBranch("Zoutcas"))fhBookTree->SetBranchAddress("Zoutcas",Zoutcas);
232     if(fhBookTree->GetBranch("Erelcas"))fhBookTree->SetBranchAddress("Erelcas",Erelcas);
233     if(fhBookTree->GetBranch("Timecas"))fhBookTree->SetBranchAddress("Timecas",Timecas);
234     if(fhBookTree->GetBranch("Pathcas"))fhBookTree->SetBranchAddress("Pathcas",Pathcas);
235     if(fhBookTree->GetBranch("P0cas"))fhBookTree->SetBranchAddress("P0cas",P0cas);
236     if(fhBookTree->GetBranch("Nthspe"))fhBookTree->SetBranchAddress("Nthspe",&Nthspe);
237     if(fhBookTree->GetBranch("Iparspe"))fhBookTree->SetBranchAddress("Iparspe",Iparspe);
238     if(fhBookTree->GetBranch("Itrpb"))fhBookTree->SetBranchAddress("Itrpb",Itrpb);
239     if(fhBookTree->GetBranch("Itrsl"))fhBookTree->SetBranchAddress("Itrsl",Itrsl);
240     if(fhBookTree->GetBranch("Itspa"))fhBookTree->SetBranchAddress("Itspa",Itspa);
241     if(fhBookTree->GetBranch("Xinspe"))fhBookTree->SetBranchAddress("Xinspe",Xinspe);
242     if(fhBookTree->GetBranch("Yinspe"))fhBookTree->SetBranchAddress("Yinspe",Yinspe);
243     if(fhBookTree->GetBranch("Zinspe"))fhBookTree->SetBranchAddress("Zinspe",Zinspe);
244     if(fhBookTree->GetBranch("Xoutspe"))fhBookTree->SetBranchAddress("Xoutspe",Xoutspe);
245     if(fhBookTree->GetBranch("Youtspe"))fhBookTree->SetBranchAddress("Youtspe",Youtspe);
246     if(fhBookTree->GetBranch("Zoutspe"))fhBookTree->SetBranchAddress("Zoutspe",Zoutspe);
247     if(fhBookTree->GetBranch("Xavspe"))fhBookTree->SetBranchAddress("Xavspe",Xavspe);
248     if(fhBookTree->GetBranch("Yavspe"))fhBookTree->SetBranchAddress("Yavspe",Yavspe);
249     if(fhBookTree->GetBranch("Zavspe"))fhBookTree->SetBranchAddress("Zavspe",Zavspe);
250     if(fhBookTree->GetBranch("Erelspe"))fhBookTree->SetBranchAddress("Erelspe",Erelspe);
251     if(fhBookTree->GetBranch("Pathspe"))fhBookTree->SetBranchAddress("Pathspe",Pathspe);
252     if(fhBookTree->GetBranch("P0spe"))fhBookTree->SetBranchAddress("P0spe",P0spe);
253     if(fhBookTree->GetBranch("Nxmult"))fhBookTree->SetBranchAddress("Nxmult",Nxmult);
254     if(fhBookTree->GetBranch("Nymult"))fhBookTree->SetBranchAddress("Nymult",Nymult);
255     if(fhBookTree->GetBranch("Nstrpx"))fhBookTree->SetBranchAddress("Nstrpx",&Nstrpx);
256     if(fhBookTree->GetBranch("Npstripx"))fhBookTree->SetBranchAddress("Npstripx",Npstripx);
257     if(fhBookTree->GetBranch("Ntstripx"))fhBookTree->SetBranchAddress("Ntstripx",Ntstripx);
258     if(fhBookTree->GetBranch("Istripx"))fhBookTree->SetBranchAddress("Istripx",Istripx);
259     if(fhBookTree->GetBranch("Qstripx"))fhBookTree->SetBranchAddress("Qstripx",Qstripx);
260     if(fhBookTree->GetBranch("Xstripx"))fhBookTree->SetBranchAddress("Xstripx",Xstripx);
261     if(fhBookTree->GetBranch("Nstrpy"))fhBookTree->SetBranchAddress("Nstrpy",&Nstrpy);
262     if(fhBookTree->GetBranch("Npstripy"))fhBookTree->SetBranchAddress("Npstripy",Npstripy);
263     if(fhBookTree->GetBranch("Ntstripy"))fhBookTree->SetBranchAddress("Ntstripy",Ntstripy);
264     if(fhBookTree->GetBranch("Istripy"))fhBookTree->SetBranchAddress("Istripy",Istripy);
265 pamelats 1.8 if(fhBookTree->GetBranch("Qstripy"))fhBookTree->SetBranchAddress("Qstripy",Qstripy);///////////////////////
266 pamelats 1.7 if(fhBookTree->GetBranch("Ystripy"))fhBookTree->SetBranchAddress("Ystripy",Ystripy);
267     if(fhBookTree->GetBranch("Nthcali"))fhBookTree->SetBranchAddress("Nthcali",&Nthcali);
268     if(fhBookTree->GetBranch("Icaplane"))fhBookTree->SetBranchAddress("Icaplane",Icaplane);
269     if(fhBookTree->GetBranch("Icastrip"))fhBookTree->SetBranchAddress("Icastrip",Icastrip);
270     if(fhBookTree->GetBranch("Icamod"))fhBookTree->SetBranchAddress("Icamod",Icamod);
271     if(fhBookTree->GetBranch("Enestrip"))fhBookTree->SetBranchAddress("Enestrip",Enestrip);
272     if(fhBookTree->GetBranch("Nthcal"))fhBookTree->SetBranchAddress("Nthcal",&Nthcal);
273     if(fhBookTree->GetBranch("Icapl"))fhBookTree->SetBranchAddress("Icapl",Icapl);
274     if(fhBookTree->GetBranch("Icasi"))fhBookTree->SetBranchAddress("Icasi",Icasi);
275     if(fhBookTree->GetBranch("Icast"))fhBookTree->SetBranchAddress("Icast",Icast);
276     if(fhBookTree->GetBranch("Xincal"))fhBookTree->SetBranchAddress("Xincal",Xincal);
277     if(fhBookTree->GetBranch("Yincal"))fhBookTree->SetBranchAddress("Yincal",Yincal);
278     if(fhBookTree->GetBranch("Zincal"))fhBookTree->SetBranchAddress("Zincal",Zincal);
279     if(fhBookTree->GetBranch("Erelcal"))fhBookTree->SetBranchAddress("Erelcal",Erelcal);
280     if(fhBookTree->GetBranch("Nthnd"))fhBookTree->SetBranchAddress("Nthnd",&Nthnd);
281     if(fhBookTree->GetBranch("Itubend"))fhBookTree->SetBranchAddress("Itubend",Itubend);
282     if(fhBookTree->GetBranch("Iparnd"))fhBookTree->SetBranchAddress("Iparnd",Iparnd);
283 pamelats 1.8 if(fhBookTree->GetBranch("Xinnd"))fhBookTree->SetBranchAddress("Xinnd",Xinnd);/////////////////////////
284 pamelats 1.7 if(fhBookTree->GetBranch("Yinnd"))fhBookTree->SetBranchAddress("Yinnd",Yinnd);
285     if(fhBookTree->GetBranch("Zinnd"))fhBookTree->SetBranchAddress("Zinnd",Zinnd);
286     if(fhBookTree->GetBranch("Xoutnd"))fhBookTree->SetBranchAddress("Xoutnd",Xoutnd);
287     if(fhBookTree->GetBranch("Youtnd"))fhBookTree->SetBranchAddress("Youtnd",Youtnd);
288     if(fhBookTree->GetBranch("Zoutnd"))fhBookTree->SetBranchAddress("Zoutnd",Zoutnd);
289     if(fhBookTree->GetBranch("Erelnd"))fhBookTree->SetBranchAddress("Erelnd",Erelnd);
290     if(fhBookTree->GetBranch("Timend"))fhBookTree->SetBranchAddress("Timend",Timend);
291     if(fhBookTree->GetBranch("Pathnd"))fhBookTree->SetBranchAddress("Pathnd",Pathnd);
292     if(fhBookTree->GetBranch("P0nd"))fhBookTree->SetBranchAddress("P0nd",P0nd);
293 pamelats 1.8 if(fhBookTree->GetBranch("Nthcard"))fhBookTree->SetBranchAddress("Nthcard",&Nthcard);/////////////////////
294 pamelats 1.7 if(fhBookTree->GetBranch("Iparcard"))fhBookTree->SetBranchAddress("Iparcard",Iparcard);
295     if(fhBookTree->GetBranch("Icard"))fhBookTree->SetBranchAddress("Icard",Icard);
296     if(fhBookTree->GetBranch("Xincard"))fhBookTree->SetBranchAddress("Xincard",Xincard);
297     if(fhBookTree->GetBranch("Yincard"))fhBookTree->SetBranchAddress("Yincard",Yincard);
298     if(fhBookTree->GetBranch("Zincard"))fhBookTree->SetBranchAddress("Zincard",Zincard);
299     if(fhBookTree->GetBranch("Xoutcard"))fhBookTree->SetBranchAddress("Xoutcard",Xoutcard);
300 pamelats 1.8 if(fhBookTree->GetBranch("Youtcard"))fhBookTree->SetBranchAddress("Youtcard",Youtcard);/////////////////
301 pamelats 1.7 if(fhBookTree->GetBranch("Zoutcard"))fhBookTree->SetBranchAddress("Zoutcard",Zoutcard);
302     if(fhBookTree->GetBranch("Erelcard"))fhBookTree->SetBranchAddress("Erelcard",Erelcard);
303     if(fhBookTree->GetBranch("Timecard"))fhBookTree->SetBranchAddress("Timecard",Timecard);
304     if(fhBookTree->GetBranch("Pathcard"))fhBookTree->SetBranchAddress("Pathcard",Pathcard);
305 pamelats 1.8 // if(fhBookTree->GetBranch("P0card"))fhBookTree->SetBranchAddress("P0card",P0card);
306 pamelats 1.7 // fhBookTree->SetBranchStatus("*",0); //modified by E.Vannuccini 03/08
307     }
308    
309     void Digitizer::Close(){
310     delete fhBookTree;
311     }
312    
313     void Digitizer::Loop() {
314     //
315     // opens the raw output file and loops over the events
316     //
317     fOutputfile.open(fFilename, ios::out | ios::binary);
318     //fOutputfile.open(Form("Output%s",fFilename), ios::out | ios::binary);
319     //
320     // Load in memory and save at the beginning of file the calorimeter calibration
321     //
322     CaloLoadCalib();
323     DigitizeCALOCALIB();
324    
325     // load, digitize and write tracker calibration
326     LoadTrackCalib();
327    
328     DigitizeTrackCalib(1);
329     UInt_t length=fTracklength*2;
330     DigitizePSCU(length,0x12,fDataPSCU);
331     AddPadding();
332     WriteTrackCalib();
333    
334     DigitizeTrackCalib(2);
335     length=fTracklength*2;
336     DigitizePSCU(length,0x13,fDataPSCU);
337     AddPadding();
338     WriteTrackCalib();
339    
340     DigitizeRunHeader();
341     WriteRunHeader();
342    
343     LoadMipCor(); // some initialization of parameters -not used now-
344     // end loading, digitizing and writing tracker calibration
345     // TOF ------ read calibration file (get A1, A2, lambda1, lambda2)
346     const int np=48;
347 pamelats 1.8 float *atte1,*atte2,*lambda1,*lambda2;
348 pamelats 1.7 atte1=(float *)malloc(np *sizeof(float));
349     atte2=(float *)malloc(np *sizeof(float));
350     lambda1=(float *)malloc(np *sizeof(float));
351     lambda2=(float *)malloc(np *sizeof(float));
352     LoadTOFCalib(np,atte1,atte2,lambda1,lambda2);
353     //end tof calib
354     //
355     // loops over the events
356     //
357    
358     Int_t nentries = fhBookTree->GetEntriesFast();
359     Long64_t nbytes = 0;
360 pamelats 1.8 for (Int_t i=0; i<nentries;i++) {
361     nbytes += fhBookTree->GetEntry(i);
362     // read detectors sequentially:
363     // http://www.ts.infn.it/fileadmin/documents/physics/experiments/wizard/cpu/gen_arch/RM_Acquisition.pdf
364     // on pamelatov: /cvs/yoda/techmodel/physics/NeutronDetectorReader.cpp
365     DigitizeTOF(np,atte1,atte2,lambda1,lambda2);
366     DigitizeAC();
367     DigitizeCALO();
368     DigitizeTrack();
369     DigitizeS4();
370     DigitizeND();
371     //
372     // Add padding to 64 bits
373     //
374     AddPadding();
375     //
376     // Create CPU header, we need packet type (0x10 = physics data) and packet length.
377     //
378     UInt_t length=2*(fCALOlength+fACbuffer+fTracklength+fNDbuffer+fS4buffer)+fPadding+fTOFbuffer+fTRIGGERbuffer;
379     //UInt_t length=2*(fCALOlength+fACbuffer+fTracklength+fNDbuffer)+fPadding+fTOFbuffer+fTRIGGERbuffer;
380     DigitizePSCU(length,0x10,fDataPSCU);
381     if ((i%1000)==0) cout << "writing event " << i << endl;
382     WriteData();
383     }
384 pamelats 1.7 DigitizeRunTrailer();
385     WriteRunTrailer();
386 pamelats 1.8
387 pamelats 1.7 fOutputfile.close();
388 pamelats 1.8 cout << "files closed" << endl;
389 pamelats 1.7 };
390    
391    
392     void Digitizer::ReadData(){
393    
394     UShort_t InData[64];
395    
396     // for debuggigng purposes only, write your own routine if you like (many
397     // hardwired things.
398    
399     ifstream InputFile;
400    
401     // if (!InputFile) {
402    
403     // std::cout << "ERROR" << endl;
404     // // An error occurred!
405     // // myFile.gcount() returns the number of bytes read.
406     // // calling myFile.clear() will reset the stream state
407     // // so it is usable again.
408     // };
409    
410    
411    
412     //InputFile.seekg(0);
413    
414     InputFile.open(fFilename, ios::in | ios::binary);
415     // fOutputfile.seekg(0);
416     if (!InputFile.is_open()) std::cout << "ERROR" << endl;
417    
418     InputFile.seekg(0);
419    
420     for (Int_t k=0; k<=1000; k++){
421     InputFile.read(reinterpret_cast<char*>(InData),384*sizeof(UShort_t));
422    
423     std::cout << "Read back: " << endl << endl;
424    
425     for (Int_t i=0; i<=384; i++){
426     printf("%4x ", InData[i]);
427     if ((i+1)%8 ==0) cout << endl;
428     }
429    
430     }
431     cout << endl;
432     InputFile.close();
433    
434     };

  ViewVC Help
Powered by ViewVC 1.1.23