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 |
|
|
149 |
|
|
150 |
|
|
151 |
|
|
152 |
|
/** |
153 |
* Given a strip returns its position in the PAMELA reference system |
* Given a strip returns its position in the PAMELA reference system |
154 |
**/ |
**/ |
155 |
void CaloStrip::Set(Int_t view, Int_t plane, Int_t strip) { |
void CaloStrip::Set(Int_t view, Int_t plane, Int_t strip) { |
186 |
lShift = 0.5; |
lShift = 0.5; |
187 |
}; |
}; |
188 |
// |
// |
189 |
|
if ( fView == 2 ) lShift = - lShift; |
190 |
|
// |
191 |
shift_.shift = lShift; |
shift_.shift = lShift; |
192 |
// |
// |
193 |
Float_t zplane[22]; |
Float_t zplane[22]; |
208 |
// |
// |
209 |
// X view |
// X view |
210 |
// |
// |
211 |
fX = (lPos - CTX)/10.; |
fX = (lPos - UXal)/10.; |
212 |
fY = 0.; |
fY = 0.; |
213 |
fZ = (zplane[fPlane-1] - 5.81 + CTZ)/10.; |
fZ = (zplane[fPlane-1] - 5.81 + UZal)/10.; |
214 |
} else { |
} else { |
215 |
// |
// |
216 |
// Y view |
// Y view |
217 |
// |
// |
218 |
fX = 0; |
fX = 0; |
219 |
fY = (lPos - CTY)/10.; |
fY = (lPos - UYal)/10.; |
220 |
fZ = (zplane[fPlane-1] + CTZ)/10.; |
fZ = (zplane[fPlane-1] + UZal)/10.; |
221 |
}; |
}; |
222 |
// |
// |
223 |
}; |
}; |
246 |
Float_t dzx[22]; |
Float_t dzx[22]; |
247 |
Float_t dzy[22]; |
Float_t dzy[22]; |
248 |
for ( Int_t i=0; i < 22; i++){ |
for ( Int_t i=0; i < 22; i++){ |
249 |
dzx[i] = fabs(fZ*10. - (zplane[i] - 5.81 + CTZ)); |
dzx[i] = fabs(fZ*10. - (zplane[i] - 5.81 + UZal)); |
250 |
dzy[i] = fabs(fZ*10. - (zplane[i] + CTZ)); |
dzy[i] = fabs(fZ*10. - (zplane[i] + UZal)); |
251 |
}; |
}; |
252 |
// |
// |
253 |
Float_t minx = TMath::MinElement(22,dzx); |
Float_t minx = TMath::MinElement(22,dzx); |
269 |
if ( fView == 1 ){ |
if ( fView == 1 ){ |
270 |
if ( dzx[i] == minx ){ |
if ( dzx[i] == minx ){ |
271 |
fPlane = i+1; |
fPlane = i+1; |
272 |
pos = fX*10. + CTX; |
pos = fX*10. + UXal; |
273 |
}; |
}; |
274 |
} else { |
} else { |
275 |
if ( dzy[i] == miny ){ |
if ( dzy[i] == miny ){ |
276 |
fPlane = i+1; |
fPlane = i+1; |
277 |
pos = fY*10. + CTY; |
pos = fY*10. + UYal; |
278 |
}; |
}; |
279 |
}; |
}; |
280 |
}; |
}; |
289 |
for ( Int_t i=0; i < 96; i++){ |
for ( Int_t i=0; i < 96; i++){ |
290 |
ca->Set(fView-1,fPlane-1,i); |
ca->Set(fView-1,fPlane-1,i); |
291 |
if ( fView == 1 ){ |
if ( fView == 1 ){ |
292 |
stpos = ca->GetX()*10. + CTX; |
stpos = ca->GetX()*10. + UXal; |
293 |
} else { |
} else { |
294 |
stpos = ca->GetY()*10. + CTY; |
stpos = ca->GetY()*10. + UYal; |
295 |
}; |
}; |
296 |
dxy[i] = fabs(pos - stpos); |
dxy[i] = fabs(pos - stpos); |
297 |
}; |
}; |