/[PAMELA software]/PamVMC/include/PamVMCRawMgr.h
ViewVC logotype

Contents of /PamVMC/include/PamVMCRawMgr.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (show annotations) (download)
Fri Jun 12 18:39:19 2009 UTC (15 years, 5 months ago) by pam-rm2
Branch: MAIN
CVS Tags: v1r0, HEAD
Changes since 1.1: +10 -5 lines
File MIME type: text/plain
- Introduced user-defined names of output files and random seeds number.
Users can do it use options of PamVMCApplication constructor:
PamVMCApplication(const char* name,  const char *title, const char*
filename="pamtest", Int_t seed=0).
The Random object that I use is TRandom3 object which has astronomical
large period (in case of default initialization 0). All random generators
in the code use this object by calling of gRandom singleton which keeps
it.

- Corrected TOF digitization routine. No problems with TDC hits due to
hadronic interactions anymore.

- Some small changes was done to compile code under Root 5.23. +
geant4_vmc v. 2.6 without any warnings

- Some classes of PamG4RunConfiguartion was changed for geant4_vmc v.
2.6.Some obsolete classes was deleted as soon as developers implemented
regions.

- Navigation was changed from "geomRootToGeant4" to "geomRoot", because on
VMC web page written that as soon as Geant4 has no option ONLY/MANY
translation of overlapped geometry to Geant4 through VGM could be wrong.
I'd like to stay with Root navigation:
http://root.cern.ch/root/vmc/Geant4VMC.html. This should be default
option.

- New Tracker digitization routine written by Sergio was implemented

- PamVMC again became compatible with geant4_vmc v.2.5 and ROOT 5.20.
 The problem was that ROOT developers introduced in TVirtualMC class a new
method SetMagField and new base class:TVirtualMagField from which
user-defined classes shoukd be derived

1 #ifndef PAMVMCRAWMGR_H
2 #define PAMVMCRAWMGR_H
3 #include "CRC.h"
4 #include <iostream>
5 #include <fstream>
6 #include <vector>
7 #include <stdlib.h>
8 #include <TObject.h>
9 #include <TRandom.h>
10 #include "TString.h"
11
12 using namespace std;
13
14 typedef vector<char> PamVMCBuffer;
15 typedef vector<UChar_t> UCBuffer;
16 typedef vector<UShort_t> USBuffer;
17
18 class PamVMCRawMgr: public TObject {
19
20 private:
21
22 static PamVMCRawMgr * frm;
23
24 UInt_t fCounter;
25 UInt_t fCounterPhys;
26 UInt_t fOBT;
27
28 const char* fFilename;
29 std::ofstream fFile;
30
31
32 UInt_t fLen;
33
34 UCBuffer fEvtDataPSCU; //event
35 UCBuffer fEvtDataPadding;
36 UInt_t fEvtPadding;
37
38 //++++++++++//
39 // BUFFER //
40 //++++++++++//
41
42 PamVMCBuffer* fbuffer;
43
44 protected:
45 PamVMCRawMgr() {
46 fCounter=fCounterPhys=fOBT=0;
47 fbuffer = new PamVMCBuffer(0);
48 };
49
50 public:
51
52 ~PamVMCRawMgr(){
53
54 delete fbuffer;
55 delete fFilename;
56
57 }
58
59 static PamVMCRawMgr * Instance();
60
61 void CreateOutFile(const char* fname){
62 fFilename = fname;
63 cout<<"OUTPUT RAWFILE: "<<fFilename<<endl;
64 fFile.open(fFilename,ios::out | ios::binary);
65 }
66
67 UInt_t GetCounter(){ return fCounter; }
68
69 void AddCounter(){ fCounter++; }
70
71 void SetCounter(UInt_t count){ fCounter = count; }
72
73 void AddCounterPhys(){ fCounterPhys++; }
74
75 UInt_t GetCounterPhys(){ return fCounterPhys; }
76
77 void SetCounterPhys(UInt_t phcount){ fCounterPhys = phcount; }
78
79 UInt_t GetOBT(){ return fOBT; }
80
81 void SetOBT(UInt_t obt){ fOBT = obt; }
82
83 UInt_t GetLen(){ return fLen; }
84
85 void SetLen(UInt_t len){ fLen = len; }
86
87 void WritePSCU(const UCBuffer* b){ CopyUCharToBuff(b); }
88
89 void WritePadding(const UCBuffer* b){ CopyUCharToBuff(b); }
90
91 void WriteEvent(){
92 fEvtPadding = 0;
93 //fLen=fbuffer->size();
94 //AddPadding(fEvtPadding,&fEvtDataPadding);
95 UInt_t length = fbuffer->size()+fEvtPadding; // DATA+Padding size;
96 DigitizePSCU(length, 0x10, &fEvtDataPSCU);
97
98 //cout<<"PADDING "<<fEvtPadding<<" bytes"<<endl;
99 UCBuffer::const_iterator p = fEvtDataPSCU.begin();
100 while( p!=fEvtDataPSCU.end() )
101 {
102 char t = char(*p);
103 fFile.write(&t,sizeof(char));
104 p++;
105 }
106 fEvtDataPSCU.clear();
107
108 WriteToFile(); //WRITE BUFFER CONTENT TO FILE
109
110 if(fEvtPadding){
111 UCBuffer::const_iterator p = fEvtDataPadding.begin();
112 while( p!=fEvtDataPadding.end() )
113 {
114 char t = char(*p);
115 fFile.write(&t,sizeof(char));
116 p++;
117 }
118 fEvtDataPadding.clear();
119 }
120 }
121
122 void WriteToFile(){
123 cout<<"BUFFER SIZE: "<<fbuffer->size()<<endl;
124 PamVMCBuffer::const_iterator p = fbuffer->begin();
125 while( p!=fbuffer->end() )
126 {
127 fFile.write(&(*p),sizeof(char));
128 p++;
129 }
130 fbuffer->clear(); //cleaning MAIN buffer
131 }
132
133 void FinishRun(){
134 WriteToFile();
135 Int_t end = EOF;
136 char t = char(end);
137 fFile.write(&t, sizeof(char));
138 fFile.close();
139 }
140
141 void CopyUCharToBuff (const UCBuffer * b){
142 UCBuffer::const_iterator p = b->begin();
143 cout<<"size of UChar DATA:"<<b->size()<<endl;
144 while( p!=b->end() )
145 {
146 //cout<<Int_t(*p)<<endl;
147 fbuffer->push_back(char(*p));
148 p++;
149 }
150 }
151
152
153 void CopyUShortToBuff (const USBuffer * b){
154 USBuffer::const_iterator p = b->begin();
155 cout<<"size of UShort DATA:"<<b->size()<<endl;
156 UShort_t Data;
157 UChar_t tmp[2];
158 while( p!=b->end() )
159 {
160 Data=(*p);
161 memcpy(tmp,&Data,sizeof(UShort_t));
162 //cout<<Int_t(*p)<<" "<<hex<<tmp[1]<<" "<<hex<<tmp[0]<<endl;
163 fbuffer->push_back(char(tmp[1]));
164 fbuffer->push_back(char(tmp[0]));
165 p++;
166 }
167 }
168
169
170 void AddPadding(UInt_t & pad, UCBuffer * b){
171
172 Float_t pd0 = (fLen+16)/32.;
173 Float_t pd1 = pd0 - (Float_t)Int_t(pd0);
174 Float_t padfrac = 32. - pd1 * 32.;
175
176 UInt_t padbytes = (UInt_t)padfrac;
177 b->clear();
178 if ( padbytes > 0 && padbytes < 32 ){
179 //
180 // here the padding length
181 //
182 pad = padbytes+32;
183 //
184 // random padding bytes
185 //
186 UShort_t Data;
187 UChar_t tmp[2];
188 for (Int_t ur=0; ur<16; ur++){
189 Data=(UShort_t)gRandom->Uniform(0.,RAND_MAX);
190 memcpy(tmp,&Data,sizeof(UShort_t));
191 //cout<<"DATA"<<hex<<Data<<endl;
192 //tmp[1] should be first (swapping bytes)
193 //b->push_back(tmp[1]);
194 //b->push_back(tmp[0]);
195 };
196 };
197
198 }
199
200
201 void DigitizePSCU(UInt_t length, UChar_t type, UCBuffer * b){
202 //
203 UChar_t buff[16];
204 //
205 // CPU signature
206 //
207 buff[0] = 0xFA;
208 buff[1] = 0xFE;
209 buff[2] = 0xDE;
210 //
211 // packet type (twice)
212 //
213 buff[3] = type;
214 buff[4] = type;
215 //
216 // counter
217 //
218 fCounter++;
219 while ( fCounter > 16777215 ){
220 fCounter-=16777215;
221 };
222 //
223 buff[5] = (UChar_t)(fCounter >> 16);
224 buff[6] = (UChar_t)(fCounter >> 8);
225 buff[7] = (UChar_t)fCounter;
226 //
227 // on board time
228 //
229 ULong64_t obt = fOBT + 30LL;
230 //
231 while ( obt > 4294967295LL ){
232 obt -= 4294967295LL;
233 };
234 fOBT = UInt_t(obt);
235 //
236 buff[8] = (UChar_t)(fOBT >> 24);
237 buff[9] = (UChar_t)(fOBT >> 16);
238 buff[10] = (UChar_t)(fOBT >> 8);
239 buff[11] = (UChar_t)fOBT;
240 //
241 // Packet length
242 //
243 fLen = length;
244 //
245 buff[12] = (UChar_t)(fLen >> 16);
246 buff[13] = (UChar_t)(fLen >> 8) ;
247 buff[14] = (UChar_t)fLen;
248 //
249 // CPU header CRC
250 //
251 buff[15] = (BYTE)CM_Compute_CRC16((UINT16)0, (BYTE*)&buff, (UINT32)15);
252
253 cout<<"Digitizer::DigitizePSCU... OK " <<endl;
254
255 b->clear();
256
257 for (Int_t i=0; i<16; i++) b->push_back(buff[i]);
258 }
259
260
261 void PrintBinaryUns(unsigned char val){
262 for(Int_t i =7; i>=0; i--){
263 if(val & (1<<i))
264 cout<<"1";
265 else
266 cout<<"0";
267 };
268 cout<<endl;
269 }
270
271
272 };
273 #endif

  ViewVC Help
Powered by ViewVC 1.1.23