3 |
* \author Emiliano Mocchiutti |
* \author Emiliano Mocchiutti |
4 |
* |
* |
5 |
**/ |
**/ |
|
#include <TObject.h> |
|
|
#include <TMath.h> |
|
6 |
#include <CaloLevel1.h> |
#include <CaloLevel1.h> |
7 |
// |
// |
8 |
ClassImp(CaloStrip); |
ClassImp(CaloStrip); |
19 |
/** |
/** |
20 |
* CaloStrip default constructor |
* CaloStrip default constructor |
21 |
**/ |
**/ |
22 |
|
CaloStrip::CaloStrip(Bool_t mechalig) { |
23 |
|
c1 = 0; |
24 |
|
this->Clear(); |
25 |
|
if ( mechalig ){ |
26 |
|
ismech = true; |
27 |
|
UXal = MECHCTX; |
28 |
|
UYal = MECHCTY; |
29 |
|
UZal = MECHCTZ; |
30 |
|
} else { |
31 |
|
ismech = false; |
32 |
|
UseStandardAlig(); |
33 |
|
}; |
34 |
|
}; |
35 |
|
|
36 |
|
/** |
37 |
|
* CaloStrip default constructor |
38 |
|
**/ |
39 |
CaloStrip::CaloStrip(CaloLevel1 *calo) { |
CaloStrip::CaloStrip(CaloLevel1 *calo) { |
40 |
c1 = calo->GetCaloLevel1(); |
c1 = calo->GetCaloLevel1(); |
41 |
this->Clear(); |
this->Clear(); |
42 |
|
ismech = false; |
43 |
|
UseStandardAlig(); |
44 |
|
}; |
45 |
|
|
46 |
|
/** |
47 |
|
* CaloStrip default constructor |
48 |
|
**/ |
49 |
|
CaloStrip::CaloStrip(CaloLevel1 *calo, Bool_t mechalig) { |
50 |
|
c1 = calo->GetCaloLevel1(); |
51 |
|
this->Clear(); |
52 |
|
if ( mechalig ){ |
53 |
|
ismech = true; |
54 |
|
UXal = MECHCTX; |
55 |
|
UYal = MECHCTY; |
56 |
|
UZal = MECHCTZ; |
57 |
|
} else { |
58 |
|
ismech = false; |
59 |
|
UseStandardAlig(); |
60 |
|
}; |
61 |
}; |
}; |
62 |
|
|
63 |
/** |
/** |
64 |
* Clear variables |
* Clear variables |
65 |
**/ |
**/ |
66 |
void CaloStrip::Clear() { |
void CaloStrip::Clear() { |
67 |
fE = 0.; |
fE = 0.; |
68 |
fX = 0.; |
fX = 0.; |
69 |
fY = 0.; |
fY = 0.; |
74 |
}; |
}; |
75 |
|
|
76 |
/** |
/** |
77 |
|
* Connect to the DB and retrieve alignement parameters |
78 |
|
**/ |
79 |
|
void CaloStrip::UseStandardAlig(){ |
80 |
|
// |
81 |
|
ismech = false; |
82 |
|
// |
83 |
|
stringstream aligfile; |
84 |
|
Int_t error = 0; |
85 |
|
FILE *f = 0; |
86 |
|
ifstream badfile; |
87 |
|
GL_PARAM *glparam = new GL_PARAM(); |
88 |
|
// |
89 |
|
TString host = "mysql://localhost/pamelaprod"; |
90 |
|
TString user = "anonymous"; |
91 |
|
TString psw = ""; |
92 |
|
const char *pamdbhost=gSystem->Getenv("PAM_DBHOST"); |
93 |
|
const char *pamdbuser=gSystem->Getenv("PAM_DBUSER"); |
94 |
|
const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW"); |
95 |
|
if ( !pamdbhost ) pamdbhost = ""; |
96 |
|
if ( !pamdbuser ) pamdbuser = ""; |
97 |
|
if ( !pamdbpsw ) pamdbpsw = ""; |
98 |
|
if ( strcmp(pamdbhost,"") ) host = pamdbhost; |
99 |
|
if ( strcmp(pamdbuser,"") ) user = pamdbuser; |
100 |
|
if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw; |
101 |
|
TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); |
102 |
|
// |
103 |
|
UXal = 0.; |
104 |
|
UYal = 0.; |
105 |
|
UZal = 0.; |
106 |
|
// |
107 |
|
if ( dbc ){ |
108 |
|
// |
109 |
|
// determine where I can find calorimeter ADC to MIP conversion file |
110 |
|
// |
111 |
|
printf(" Querying DB for calorimeter parameters files...\n"); |
112 |
|
// |
113 |
|
// |
114 |
|
// |
115 |
|
error = 0; |
116 |
|
error = glparam->Query_GL_PARAM(1000,102,dbc); |
117 |
|
if ( error >= 0 ){ |
118 |
|
// |
119 |
|
aligfile.str(""); |
120 |
|
aligfile << glparam->PATH.Data() << "/"; |
121 |
|
aligfile << glparam->NAME.Data(); |
122 |
|
// |
123 |
|
printf("\n Using parameter file: \n %s \n",aligfile.str().c_str()); |
124 |
|
f = fopen(aligfile.str().c_str(),"rb"); |
125 |
|
if ( f ){ |
126 |
|
// |
127 |
|
fread(&UXal,sizeof(UXal),1,f); |
128 |
|
fread(&UYal,sizeof(UYal),1,f); |
129 |
|
fread(&UZal,sizeof(UZal),1,f); |
130 |
|
// |
131 |
|
fclose(f); |
132 |
|
}; |
133 |
|
// |
134 |
|
}; |
135 |
|
dbc->Close(); |
136 |
|
}; |
137 |
|
if ( !UXal ){ |
138 |
|
// |
139 |
|
printf(" No able to query DB for calorimeter parameters files\n Using hard-coded parameters \n"); |
140 |
|
UXal = CTX; |
141 |
|
UYal = CTY; |
142 |
|
UZal = CTZ; |
143 |
|
}; |
144 |
|
// |
145 |
|
}; |
146 |
|
|
147 |
|
/** |
148 |
* Given a strip returns its position in the PAMELA reference system |
* Given a strip returns its position in the PAMELA reference system |
149 |
**/ |
**/ |
150 |
void CaloStrip::Set(Int_t view, Int_t plane, Int_t strip) { |
void CaloStrip::Set(Int_t view, Int_t plane, Int_t strip) { |
175 |
fView = view + 1; |
fView = view + 1; |
176 |
fPlane = plane + 1; |
fPlane = plane + 1; |
177 |
fStrip = strip + 1; |
fStrip = strip + 1; |
178 |
|
// |
179 |
if ( fPlane%2 ){ |
if ( fPlane%2 ){ |
180 |
lShift = -0.5; |
lShift = +0.5; |
181 |
} else { |
} else { |
182 |
lShift = 0.5; |
lShift = -0.5; |
183 |
}; |
}; |
184 |
// |
// |
185 |
shift_.shift = lShift; |
shift_.shift = lShift; |
202 |
// |
// |
203 |
// X view |
// X view |
204 |
// |
// |
205 |
fX = (lPos - CTX)/10.; |
fX = (lPos - UXal)/10.; |
206 |
fY = 0.; |
fY = 0.; |
207 |
fZ = (zplane[fPlane-1] - 5.81 + CTZ)/10.; |
fZ = (zplane[fPlane-1] - 5.81 + UZal)/10.; |
208 |
} else { |
// |
209 |
|
} else { |
210 |
// |
// |
211 |
// Y view |
// Y view |
212 |
// |
// |
213 |
fX = 0; |
fX = 0; |
214 |
fY = (lPos - CTY)/10.; |
fY = (lPos - UYal)/10.; |
215 |
fZ = (zplane[fPlane-1] + CTZ)/10.; |
fZ = (zplane[fPlane-1] + UZal)/10.; |
216 |
}; |
}; |
217 |
// |
// |
218 |
}; |
}; |
241 |
Float_t dzx[22]; |
Float_t dzx[22]; |
242 |
Float_t dzy[22]; |
Float_t dzy[22]; |
243 |
for ( Int_t i=0; i < 22; i++){ |
for ( Int_t i=0; i < 22; i++){ |
244 |
dzx[i] = fabs(fZ*10. - (zplane[i] - 5.81 + CTZ)); |
dzx[i] = fabs(fZ*10. - (zplane[i] - 5.81 + UZal)); |
245 |
dzy[i] = fabs(fZ*10. - (zplane[i] + CTZ)); |
dzy[i] = fabs(fZ*10. - (zplane[i] + UZal)); |
246 |
}; |
}; |
247 |
// |
// |
248 |
Float_t minx = TMath::MinElement(22,dzx); |
Float_t minx = TMath::MinElement(22,dzx); |
264 |
if ( fView == 1 ){ |
if ( fView == 1 ){ |
265 |
if ( dzx[i] == minx ){ |
if ( dzx[i] == minx ){ |
266 |
fPlane = i+1; |
fPlane = i+1; |
267 |
pos = fX*10. + CTX; |
pos = fX*10. + UXal; |
268 |
}; |
}; |
269 |
} else { |
} else { |
270 |
if ( dzy[i] == miny ){ |
if ( dzy[i] == miny ){ |
271 |
fPlane = i+1; |
fPlane = i+1; |
272 |
pos = fY*10. + CTY; |
pos = fY*10. + UYal; |
273 |
}; |
}; |
274 |
}; |
}; |
275 |
}; |
}; |
284 |
for ( Int_t i=0; i < 96; i++){ |
for ( Int_t i=0; i < 96; i++){ |
285 |
ca->Set(fView-1,fPlane-1,i); |
ca->Set(fView-1,fPlane-1,i); |
286 |
if ( fView == 1 ){ |
if ( fView == 1 ){ |
287 |
stpos = ca->GetX()*10. + CTX; |
stpos = ca->GetX()*10. + UXal; |
288 |
} else { |
} else { |
289 |
stpos = ca->GetY()*10. + CTY; |
stpos = ca->GetY()*10. + UYal; |
290 |
}; |
}; |
291 |
dxy[i] = fabs(pos - stpos); |
dxy[i] = fabs(pos - stpos); |
292 |
}; |
}; |
407 |
return(0.); |
return(0.); |
408 |
} |
} |
409 |
|
|
410 |
|
/* |
411 |
|
* Returns energy released on plane nplane (where 0<= nplane <= 43, 0 = 1Y, 1 = 1X, 2 = 2Y, 3 = 2X, etc. etc.). |
412 |
|
*/ |
413 |
|
Float_t CaloLevel1::qtotpl(Int_t nplane){ |
414 |
|
// |
415 |
|
Int_t sview = 1; |
416 |
|
if ( nplane%2 ) sview = 0; |
417 |
|
// |
418 |
|
Int_t splane = nplane-(sview+1)/2; |
419 |
|
// |
420 |
|
Float_t totmip = qtotpl(sview,splane); |
421 |
|
// |
422 |
|
return(totmip); |
423 |
|
// |
424 |
|
}; |
425 |
|
|
426 |
|
/* |
427 |
|
* Returns energy released on view "view" (0 = X, 1 = Y) and plane "plane" ( 0 <= plane <= 21 ). |
428 |
|
*/ |
429 |
|
Float_t CaloLevel1::qtotpl(Int_t sview, Int_t splane){ |
430 |
|
// |
431 |
|
Int_t view = -1; |
432 |
|
Int_t plane = -1; |
433 |
|
Int_t strip = -1; |
434 |
|
// |
435 |
|
Float_t mip = 0.; |
436 |
|
Float_t totmip = 0.; |
437 |
|
// |
438 |
|
if ( istrip == 0 ) return(0.); |
439 |
|
// |
440 |
|
for (Int_t i = 0; i<istrip; i++ ){ |
441 |
|
// |
442 |
|
mip = DecodeEstrip(i,view,plane,strip); |
443 |
|
// |
444 |
|
if ( view == sview && splane == plane ) totmip += mip; |
445 |
|
// |
446 |
|
// entry are ordered by strip, plane and view number. Go out if you pass the input strip |
447 |
|
// |
448 |
|
if ( view == sview && plane > splane ) return(totmip); |
449 |
|
if ( view > sview ) return(totmip); |
450 |
|
// |
451 |
|
}; |
452 |
|
// |
453 |
|
return(totmip); |
454 |
|
// |
455 |
|
}; |