/[PAMELA software]/DarthVader/CalorimeterLevel2/src/CaloLevel2.cpp
ViewVC logotype

Contents of /DarthVader/CalorimeterLevel2/src/CaloLevel2.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (show annotations) (download)
Fri Aug 4 10:31:26 2006 UTC (18 years, 3 months ago) by mocchiut
Branch: MAIN
Changes since 1.4: +20 -37 lines
Small memory leaks fixed

1 /**
2 * \file src/CaloLevel2.cpp
3 * \author Emiliano Mocchiutti
4 *
5 **/
6 #include <TObject.h>
7 #include <CaloLevel2.h>
8 ClassImp(CaloTrkVar);
9 ClassImp(CaloLevel2);
10
11 /**
12 * CaloTrkVar constructor
13 **/
14 CaloTrkVar::CaloTrkVar() {
15 trkseqno = 0;
16 noint = 0;
17 ncore = 0;
18 qcore = 0.;
19 ncyl = 0;
20 qcyl = 0.;
21 qtrack = 0.;
22 qtrackx = 0.;
23 qtracky = 0.;
24 dxtrack = 0.;
25 dytrack = 0.;
26 qlast = 0.;
27 nlast = 0;
28 qpre = 0.;
29 npre = 0;
30 qpresh = 0.;
31 npresh = 0;
32 qtr = 0.;
33 ntr = 0;
34 planetot = 0;
35 qmean = 0.;
36 qlow = 0.;
37 nlow = 0;
38 dX0l = 0.;
39 memset(tbar, 0, 2*22*sizeof(Float_t));
40 memset(tibar, 0, 2*22*sizeof(Int_t));
41 }
42
43 /**
44 * Copies from t to this
45 **/
46 CaloTrkVar::CaloTrkVar(const CaloTrkVar &t){
47 trkseqno = t.trkseqno;
48 noint = t.noint;
49 ncore = t.ncore;
50 qcore = t.qcore;
51 ncyl = t.ncyl;
52 qcyl = t.qcyl;
53 qtrack = t.qtrack;
54 qtrackx = t.qtrackx;
55 qtracky = t.qtracky;
56 dxtrack = t.dxtrack;
57 dytrack = t.dytrack;
58 qlast = t.qlast;
59 nlast = t.nlast;
60 qpre = t.qpre;
61 npre = t.npre;
62 qpresh = t.qpresh;
63 npresh = t.npresh;
64 qtr = t.qtr;
65 ntr = t.ntr;
66 planetot = t.planetot;
67 qmean = t.qmean;
68 dX0l = t.dX0l;
69 qlow = t.qlow;
70 nlow = t.nlow;
71 memcpy(tibar,t.tibar,sizeof(tibar));
72 memcpy(tbar,t.tbar,sizeof(tbar));
73 }
74
75 /**
76 * CaloLevel2 constructor
77 **/
78 CaloLevel2::CaloLevel2() {
79 //
80 CaloTrk = new TClonesArray("CaloTrkVar",1);
81 //
82 nstrip = 0;
83 qtot = 0.;
84 impx = 0.;
85 impy = 0.;
86 tanx = 0.;
87 tany = 0.;
88 qmax = 0.;
89 nx22 = 0;
90 qx22 = 0.;
91 elen = 0.;
92 selen = 0.;
93 memset(perr, 0, 4*sizeof(Int_t));
94 memset(swerr, 0, 4*sizeof(Int_t));
95 memset(crc, 0, 4*sizeof(Int_t));
96 memset(qq, 0, 4*sizeof(Int_t));
97 memset(varcfit, 0, 2*sizeof(Float_t));
98 memset(npcfit, 0, 2*sizeof(Int_t));
99 memset(planemax, 0, 2*sizeof(Int_t));
100 memset(cibar, 0, 2*22*sizeof(Int_t));
101 memset(cbar, 0, 2*22*sizeof(Float_t));
102 good = 0;
103 selftrigger = 0;
104 estrip = TArrayF(0,NULL);
105 };
106
107 void CaloLevel2::Clear() {
108 //
109 CaloTrk->Clear();
110 //
111 nstrip = 0;
112 qtot = 0.;
113 impx = 0.;
114 impy = 0.;
115 tanx = 0.;
116 tany = 0.;
117 qmax = 0.;
118 nx22 = 0;
119 qx22 = 0.;
120 elen = 0.;
121 selen = 0.;
122 memset(perr, 0, 4*sizeof(Int_t));
123 memset(swerr, 0, 4*sizeof(Int_t));
124 memset(crc, 0, 4*sizeof(Int_t));
125 memset(qq, 0, 4*sizeof(Int_t));
126 memset(varcfit, 0, 2*sizeof(Float_t));
127 memset(npcfit, 0, 2*sizeof(Int_t));
128 memset(planemax, 0, 2*sizeof(Int_t));
129 memset(cibar, 0, 2*22*sizeof(Int_t));
130 memset(cbar, 0, 2*22*sizeof(Float_t));
131 good = 0;
132 selftrigger = 0;
133 estrip.Reset();
134 };
135
136
137 /**
138 * Fills a struct cCaloLevel2 with values from a CaloLevel2 object (to put data into a F77 common).
139 */
140 void CaloLevel2::GetLevel2Struct(cCaloLevel2 *l2) const {
141
142 l2->good = good;
143 l2->selftrigger = selftrigger;
144 l2->nstrip = nstrip;
145 l2->nx22 = nx22;
146 l2->qtot = qtot;
147 l2->qx22 = qx22;
148 l2->qmax = qmax;
149 l2->impx = impx;
150 l2->impy = impy;
151 l2->tanx = tanx;
152 l2->tany = tany;
153 l2->elen = elen;
154 l2->selen = selen;
155
156 for(Int_t i=0;i<2;i++){
157 l2->planemax[i] = planemax[i];
158 l2->varcfit[i] = varcfit[i];
159 l2->npcfit[i] = npcfit[i];
160 }
161 for(Int_t i=0;i<4;i++){
162 l2->perr[i] = perr[i];
163 l2->swerr[i] = swerr[i];
164 l2->calcrc[i] = crc[i];
165 l2->qq[i] = qq[i];
166 }
167
168 l2->calntrk = CaloTrk->GetEntries();
169
170 for(Int_t i=0;i<l2->calntrk;i++){
171 l2->caltrkseqno[i] = ((CaloTrkVar *)CaloTrk->At(i))->trkseqno;
172 l2->ncore[i] = ((CaloTrkVar *)CaloTrk->At(i))->ncore;
173 l2->noint[i] = ((CaloTrkVar *)CaloTrk->At(i))->noint;
174 l2->ncyl[i] = ((CaloTrkVar *)CaloTrk->At(i))->ncyl;
175 l2->nlast[i] = ((CaloTrkVar *)CaloTrk->At(i))->nlast;
176 l2->npre[i] = ((CaloTrkVar *)CaloTrk->At(i))->npre;
177 l2->npresh[i] = ((CaloTrkVar *)CaloTrk->At(i))->npresh;
178 l2->ntr[i] = ((CaloTrkVar *)CaloTrk->At(i))->ntr;
179 l2->planetot[i] = ((CaloTrkVar *)CaloTrk->At(i))->planetot;
180 l2->nlow[i] = ((CaloTrkVar *)CaloTrk->At(i))->nlow;
181 l2->qcore[i] =((CaloTrkVar *)CaloTrk->At(i))->qcore ;
182 l2->qcyl[i] = ((CaloTrkVar *)CaloTrk->At(i))->qcyl;
183 l2->qlast[i] = ((CaloTrkVar *)CaloTrk->At(i))->qlast;
184 l2->qpre[i] = ((CaloTrkVar *)CaloTrk->At(i))->qpre;
185 l2->qpresh[i] = ((CaloTrkVar *)CaloTrk->At(i))->qpresh;
186 l2->qtr[i] = ((CaloTrkVar *)CaloTrk->At(i))->qtr;
187 l2->qtrack[i] = ((CaloTrkVar *)CaloTrk->At(i))->qtrack;
188 l2->qtrackx[i] = ((CaloTrkVar *)CaloTrk->At(i))->qtrackx;
189 l2->qtracky[i] = ((CaloTrkVar *)CaloTrk->At(i))->qtracky;
190 l2->dxtrack[i] = ((CaloTrkVar *)CaloTrk->At(i))->dxtrack;
191 l2->dytrack[i] = ((CaloTrkVar *)CaloTrk->At(i))->dytrack;
192 l2->qmean[i] = ((CaloTrkVar *)CaloTrk->At(i))->qmean;
193 l2->qlow[i] = ((CaloTrkVar *)CaloTrk->At(i))->qlow;
194 l2->dX0l[i] = ((CaloTrkVar *)CaloTrk->At(i))->dX0l;
195 }
196
197 }
198
199 /**
200 * Gives the detected energy for the given strip once loaded the event
201 **/
202 Float_t CaloLevel2::GetEstrip(Int_t view, Int_t plane, Int_t strip){
203 Int_t splane = 0;
204 Int_t sstrip = 0;
205 //
206 if ( nstrip == 0 ) return(0.);
207 //
208 for (Int_t i = 0; i<nstrip; i++ ){
209 if ( view == 0 ){
210 if ( estrip.At(i) > 0. ){
211 splane = (Int_t)trunc(estrip.At(i)/1000000.);
212 sstrip = (Int_t)trunc((estrip.At(i)-((Float_t)splane*1000000.))/10000.);
213 if ( splane == plane && sstrip == strip ) return(estrip.At(i)-(Float_t)splane*1000000.-(Float_t)sstrip*10000.);
214 };
215 } else {
216 if ( estrip.At(i) < 0. ){
217 splane = (Int_t)trunc(-estrip.At(i)/1000000.);
218 sstrip = (Int_t)trunc((-estrip.At(i)-((Float_t)splane*1000000.))/10000.);
219 if ( splane == plane && sstrip == strip ) return(-estrip.At(i)-(Float_t)splane*1000000.-(Float_t)sstrip*10000.);
220 };
221 };
222 };
223 return(0.);
224 };
225
226 /**
227 * Given estrip entry returns energy and strip
228 **/
229 Float_t CaloLevel2::DecodeEstrip(Int_t entry, Int_t &view, Int_t &plane, Int_t &strip){
230 if ( entry>nstrip ) return(0.);
231 //
232 if ( estrip.At(entry) > 0. ){
233 view = 0;
234 plane = (Int_t)trunc(estrip.At(entry)/1000000.);
235 strip = (Int_t)trunc((estrip.At(entry)-((Float_t)plane*1000000.))/10000.);
236 return(estrip.At(entry)-(Float_t)plane*1000000.-(Float_t)strip*10000.);
237 };
238 if ( estrip.At(entry) < 0. ){
239 view = 1;
240 plane = (Int_t)trunc(-estrip.At(entry)/1000000.);
241 strip = (Int_t)trunc((-estrip.At(entry)-((Float_t)plane*1000000.))/10000.);
242 return(-estrip.At(entry)-(Float_t)plane*1000000.-(Float_t)strip*10000.);
243 };
244 //
245 printf(" WARNING: problems decoding value %f at entry %i \n",estrip.At(entry),entry);
246 //
247 view = -1;
248 plane = -1;
249 strip = -1;
250 return(0.);
251 }
252
253 void CaloLevel2::GetElectronEnergy(Float_t &energy, Float_t &sigma){
254 if ( nstrip == 0 ) return;
255 energy = qtot * 40.82 * 0.000106;
256 sigma = 0.;
257 if ( energy > 0. ) sigma = energy * (0.01183 + 0.121/sqrt(energy));
258 return;
259 };
260
261 /**
262 * Returns pointer to the set of track-related variables "itrk"
263 **/
264 CaloTrkVar *CaloLevel2::GetCaloTrkVar(Int_t itrk){
265 //
266 if(itrk >= ntrk()){
267 printf(" CaloLevel2 ERROR: track related variables set %i does not exists! \n",itrk);
268 printf(" stored track related variables = %i \n",ntrk());
269 return(NULL);
270 }
271 TClonesArray &t = *(CaloTrk);
272 CaloTrkVar *calotrack = (CaloTrkVar*)t[itrk];
273 return calotrack;
274 }

  ViewVC Help
Powered by ViewVC 1.1.23