| 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); |
| 9 |
ClassImp(CaloLevel1); |
ClassImp(CaloLevel1); |
| 10 |
|
|
| 11 |
|
Float_t CaloStrip::UXal = CTX; |
| 12 |
|
Float_t CaloStrip::UYal = CTY; |
| 13 |
|
Float_t CaloStrip::UZal = CTZ; |
| 14 |
|
Bool_t CaloStrip::paramload = false; |
| 15 |
|
|
| 16 |
/** |
/** |
| 17 |
* CaloStrip default constructor |
* CaloStrip default constructor |
| 18 |
**/ |
**/ |
| 24 |
/** |
/** |
| 25 |
* CaloStrip default constructor |
* CaloStrip default constructor |
| 26 |
**/ |
**/ |
| 27 |
|
CaloStrip::CaloStrip(Bool_t mechalig) { |
| 28 |
|
c1 = 0; |
| 29 |
|
this->Clear(); |
| 30 |
|
if ( mechalig ){ |
| 31 |
|
ismech = true; |
| 32 |
|
paramload = true; |
| 33 |
|
UXal = MECHCTX; |
| 34 |
|
UYal = MECHCTY; |
| 35 |
|
UZal = MECHCTZ; |
| 36 |
|
} else { |
| 37 |
|
ismech = false; |
| 38 |
|
UseStandardAlig(); |
| 39 |
|
}; |
| 40 |
|
}; |
| 41 |
|
|
| 42 |
|
/** |
| 43 |
|
* CaloStrip default constructor |
| 44 |
|
**/ |
| 45 |
CaloStrip::CaloStrip(CaloLevel1 *calo) { |
CaloStrip::CaloStrip(CaloLevel1 *calo) { |
| 46 |
c1 = calo->GetCaloLevel1(); |
c1 = calo->GetCaloLevel1(); |
| 47 |
this->Clear(); |
this->Clear(); |
| 48 |
|
ismech = false; |
| 49 |
|
UseStandardAlig(); |
| 50 |
|
}; |
| 51 |
|
|
| 52 |
|
/** |
| 53 |
|
* CaloStrip default constructor |
| 54 |
|
**/ |
| 55 |
|
CaloStrip::CaloStrip(CaloLevel1 *calo, Bool_t mechalig) { |
| 56 |
|
c1 = calo->GetCaloLevel1(); |
| 57 |
|
this->Clear(); |
| 58 |
|
if ( mechalig ){ |
| 59 |
|
ismech = true; |
| 60 |
|
paramload = true; |
| 61 |
|
UXal = MECHCTX; |
| 62 |
|
UYal = MECHCTY; |
| 63 |
|
UZal = MECHCTZ; |
| 64 |
|
} else { |
| 65 |
|
ismech = false; |
| 66 |
|
UseStandardAlig(); |
| 67 |
|
}; |
| 68 |
}; |
}; |
| 69 |
|
|
| 70 |
/** |
/** |
| 71 |
* Clear variables |
* Clear variables |
| 72 |
**/ |
**/ |
| 73 |
void CaloStrip::Clear() { |
void CaloStrip::Clear(Option_t *t) { |
| 74 |
fE = 0.; |
fE = 0.; |
| 75 |
fX = 0.; |
fX = 0.; |
| 76 |
fY = 0.; |
fY = 0.; |
| 81 |
}; |
}; |
| 82 |
|
|
| 83 |
/** |
/** |
| 84 |
|
* Connect to the DB and retrieve alignement parameters |
| 85 |
|
**/ |
| 86 |
|
void CaloStrip::UseStandardAlig(){ |
| 87 |
|
// |
| 88 |
|
if ( !paramload ){ |
| 89 |
|
// |
| 90 |
|
paramload = true; |
| 91 |
|
ismech = false; |
| 92 |
|
// |
| 93 |
|
stringstream aligfile; |
| 94 |
|
Int_t error = 0; |
| 95 |
|
FILE *f = 0; |
| 96 |
|
ifstream badfile; |
| 97 |
|
GL_PARAM *glparam = new GL_PARAM(); |
| 98 |
|
// |
| 99 |
|
TString host = "mysql://localhost/pamelaprod"; |
| 100 |
|
TString user = "anonymous"; |
| 101 |
|
TString psw = ""; |
| 102 |
|
const char *pamdbhost=gSystem->Getenv("PAM_DBHOST"); |
| 103 |
|
const char *pamdbuser=gSystem->Getenv("PAM_DBUSER"); |
| 104 |
|
const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW"); |
| 105 |
|
if ( !pamdbhost ) pamdbhost = ""; |
| 106 |
|
if ( !pamdbuser ) pamdbuser = ""; |
| 107 |
|
if ( !pamdbpsw ) pamdbpsw = ""; |
| 108 |
|
if ( strcmp(pamdbhost,"") ) host = pamdbhost; |
| 109 |
|
if ( strcmp(pamdbuser,"") ) user = pamdbuser; |
| 110 |
|
if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw; |
| 111 |
|
TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); |
| 112 |
|
// |
| 113 |
|
UXal = 0.; |
| 114 |
|
UYal = 0.; |
| 115 |
|
UZal = 0.; |
| 116 |
|
// |
| 117 |
|
if ( dbc ){ |
| 118 |
|
// |
| 119 |
|
// determine where I can find calorimeter ADC to MIP conversion file |
| 120 |
|
// |
| 121 |
|
printf(" Querying DB for calorimeter parameters files...\n"); |
| 122 |
|
// |
| 123 |
|
// |
| 124 |
|
// |
| 125 |
|
error = 0; |
| 126 |
|
error = glparam->Query_GL_PARAM(1000,102,dbc); |
| 127 |
|
if ( error >= 0 ){ |
| 128 |
|
// |
| 129 |
|
aligfile.str(""); |
| 130 |
|
aligfile << glparam->PATH.Data() << "/"; |
| 131 |
|
aligfile << glparam->NAME.Data(); |
| 132 |
|
// |
| 133 |
|
printf("\n Using parameter file: \n %s \n",aligfile.str().c_str()); |
| 134 |
|
f = fopen(aligfile.str().c_str(),"rb"); |
| 135 |
|
if ( f ){ |
| 136 |
|
// |
| 137 |
|
fread(&UXal,sizeof(UXal),1,f); |
| 138 |
|
fread(&UYal,sizeof(UYal),1,f); |
| 139 |
|
fread(&UZal,sizeof(UZal),1,f); |
| 140 |
|
// |
| 141 |
|
fclose(f); |
| 142 |
|
}; |
| 143 |
|
// |
| 144 |
|
}; |
| 145 |
|
dbc->Close(); |
| 146 |
|
delete dbc; |
| 147 |
|
dbc = 0; |
| 148 |
|
}; |
| 149 |
|
if ( !UXal ){ |
| 150 |
|
// |
| 151 |
|
printf(" No able to query DB for calorimeter parameters files\n Using hard-coded parameters \n"); |
| 152 |
|
UXal = CTX; |
| 153 |
|
UYal = CTY; |
| 154 |
|
UZal = CTZ; |
| 155 |
|
}; |
| 156 |
|
// |
| 157 |
|
}; |
| 158 |
|
// |
| 159 |
|
}; |
| 160 |
|
|
| 161 |
|
/** |
| 162 |
* Given a strip returns its position in the PAMELA reference system |
* Given a strip returns its position in the PAMELA reference system |
| 163 |
**/ |
**/ |
| 164 |
void CaloStrip::Set(Int_t view, Int_t plane, Int_t strip) { |
void CaloStrip::Set(Int_t view, Int_t plane, Int_t strip) { |
| 189 |
fView = view + 1; |
fView = view + 1; |
| 190 |
fPlane = plane + 1; |
fPlane = plane + 1; |
| 191 |
fStrip = strip + 1; |
fStrip = strip + 1; |
| 192 |
|
// |
| 193 |
if ( fPlane%2 ){ |
if ( fPlane%2 ){ |
| 194 |
lShift = -0.5; |
lShift = +0.5; |
| 195 |
} else { |
} else { |
| 196 |
lShift = 0.5; |
lShift = -0.5; |
| 197 |
}; |
}; |
| 198 |
// |
// |
| 199 |
shift_.shift = lShift; |
shift_.shift = lShift; |
| 216 |
// |
// |
| 217 |
// X view |
// X view |
| 218 |
// |
// |
| 219 |
fX = (lPos - CTX)/10.; |
fX = (lPos - UXal)/10.; |
| 220 |
fY = 0.; |
fY = 0.; |
| 221 |
fZ = (zplane[fPlane-1] - 5.81 + CTZ)/10.; |
fZ = (zplane[fPlane-1] - 5.81 + UZal)/10.; |
| 222 |
} else { |
// |
| 223 |
|
} else { |
| 224 |
// |
// |
| 225 |
// Y view |
// Y view |
| 226 |
// |
// |
| 227 |
fX = 0; |
fX = 0; |
| 228 |
fY = (lPos - CTY)/10.; |
fY = (lPos - UYal)/10.; |
| 229 |
fZ = (zplane[fPlane-1] + CTZ)/10.; |
fZ = (zplane[fPlane-1] + UZal)/10.; |
| 230 |
}; |
}; |
| 231 |
// |
// |
| 232 |
}; |
}; |
| 255 |
Float_t dzx[22]; |
Float_t dzx[22]; |
| 256 |
Float_t dzy[22]; |
Float_t dzy[22]; |
| 257 |
for ( Int_t i=0; i < 22; i++){ |
for ( Int_t i=0; i < 22; i++){ |
| 258 |
dzx[i] = fabs(fZ*10. - (zplane[i] - 5.81 + CTZ)); |
dzx[i] = fabs(fZ*10. - (zplane[i] - 5.81 + UZal)); |
| 259 |
dzy[i] = fabs(fZ*10. - (zplane[i] + CTZ)); |
dzy[i] = fabs(fZ*10. - (zplane[i] + UZal)); |
| 260 |
}; |
}; |
| 261 |
// |
// |
| 262 |
Float_t minx = TMath::MinElement(22,dzx); |
Float_t minx = TMath::MinElement(22,dzx); |
| 278 |
if ( fView == 1 ){ |
if ( fView == 1 ){ |
| 279 |
if ( dzx[i] == minx ){ |
if ( dzx[i] == minx ){ |
| 280 |
fPlane = i+1; |
fPlane = i+1; |
| 281 |
pos = fX*10. + CTX; |
pos = fX*10. + UXal; |
| 282 |
}; |
}; |
| 283 |
} else { |
} else { |
| 284 |
if ( dzy[i] == miny ){ |
if ( dzy[i] == miny ){ |
| 285 |
fPlane = i+1; |
fPlane = i+1; |
| 286 |
pos = fY*10. + CTY; |
pos = fY*10. + UYal; |
| 287 |
}; |
}; |
| 288 |
}; |
}; |
| 289 |
}; |
}; |
| 298 |
for ( Int_t i=0; i < 96; i++){ |
for ( Int_t i=0; i < 96; i++){ |
| 299 |
ca->Set(fView-1,fPlane-1,i); |
ca->Set(fView-1,fPlane-1,i); |
| 300 |
if ( fView == 1 ){ |
if ( fView == 1 ){ |
| 301 |
stpos = ca->GetX()*10. + CTX; |
stpos = ca->GetX()*10. + UXal; |
| 302 |
} else { |
} else { |
| 303 |
stpos = ca->GetY()*10. + CTY; |
stpos = ca->GetY()*10. + UYal; |
| 304 |
}; |
}; |
| 305 |
dxy[i] = fabs(pos - stpos); |
dxy[i] = fabs(pos - stpos); |
| 306 |
}; |
}; |
| 315 |
}; |
}; |
| 316 |
|
|
| 317 |
/** |
/** |
| 318 |
|
* Given a point in the space or a strip it returns the Silicon sensor number. Numbering goes like this: |
| 319 |
|
* |
| 320 |
|
* y ^ |
| 321 |
|
* | |
| 322 |
|
* | 6 7 8 |
| 323 |
|
* | 3 4 5 |
| 324 |
|
* | 0 1 2 |
| 325 |
|
* | -----------> x |
| 326 |
|
* |
| 327 |
|
**/ |
| 328 |
|
Int_t CaloStrip::GetSiSensor() { |
| 329 |
|
// |
| 330 |
|
// fX fY fZ // fView fPlane |
| 331 |
|
// |
| 332 |
|
Float_t deadsi = 0.096; |
| 333 |
|
Float_t dead = 0.05; |
| 334 |
|
Float_t sidim = 8.00; |
| 335 |
|
// Float_t stripdim = 0.244; |
| 336 |
|
Float_t sensitarea = 7.808; |
| 337 |
|
// |
| 338 |
|
Float_t xoffset = 0.; |
| 339 |
|
Float_t yoffset = 0.; |
| 340 |
|
// |
| 341 |
|
if ( (fView-1) == 0 && !((fPlane-1)%2) ){ |
| 342 |
|
xoffset = +0.05; |
| 343 |
|
yoffset = 0.0; |
| 344 |
|
}; |
| 345 |
|
if ( (fView-1) == 0 && ((fPlane-1)%2) ){ |
| 346 |
|
xoffset = -0.05; |
| 347 |
|
yoffset = -0.20; |
| 348 |
|
}; |
| 349 |
|
if ( (fView-1) == 1 && !((fPlane-1)%2) ){ |
| 350 |
|
xoffset = +0.10; |
| 351 |
|
yoffset = -0.05; |
| 352 |
|
}; |
| 353 |
|
if ( (fView-1) == 1 && ((fPlane-1)%2) ){ |
| 354 |
|
xoffset = -0.10; |
| 355 |
|
yoffset = -0.15; |
| 356 |
|
}; |
| 357 |
|
// |
| 358 |
|
Int_t iind = -1; |
| 359 |
|
Int_t jind = -1; |
| 360 |
|
// |
| 361 |
|
for (Int_t i = 0; i < 3; i++){ |
| 362 |
|
if ( (fX+xoffset+12.1) >= (deadsi+(sidim+dead)*i) && (fX+xoffset+12.1) <= (sensitarea+deadsi+(sidim+dead)*i) ){ |
| 363 |
|
iind = i; |
| 364 |
|
break; |
| 365 |
|
}; |
| 366 |
|
}; |
| 367 |
|
// |
| 368 |
|
for (Int_t j = 0; j < 3; j++){ |
| 369 |
|
if ( (fY+yoffset+12.1) >= (deadsi+(sidim+dead)*j) && (fY+yoffset+12.1) <= (sensitarea+deadsi+(sidim+dead)*j) ){ |
| 370 |
|
jind = j; |
| 371 |
|
break; |
| 372 |
|
}; |
| 373 |
|
}; |
| 374 |
|
// |
| 375 |
|
Int_t sensor = -1; |
| 376 |
|
if ( iind != -1 && jind != -1 ){ |
| 377 |
|
sensor = iind + jind * 3; |
| 378 |
|
}; |
| 379 |
|
// |
| 380 |
|
// printf(" View %i Plane %i x %f y %f z %f xoffset %f yoffset %f iind %i jind %i \n",fView,fPlane,fX,fY,fZ,xoffset,yoffset,iind,jind); |
| 381 |
|
// |
| 382 |
|
return(sensor); |
| 383 |
|
// |
| 384 |
|
}; |
| 385 |
|
|
| 386 |
|
/** |
| 387 |
* CaloLevel1 constructor |
* CaloLevel1 constructor |
| 388 |
**/ |
**/ |
| 389 |
CaloLevel1::CaloLevel1() { |
CaloLevel1::CaloLevel1() { |
| 397 |
/** |
/** |
| 398 |
* Clear the CaloLevel1 object |
* Clear the CaloLevel1 object |
| 399 |
**/ |
**/ |
| 400 |
void CaloLevel1::Clear() { |
void CaloLevel1::Clear(Option_t *t) { |
| 401 |
// |
// |
| 402 |
istrip = 0; |
istrip = 0; |
| 403 |
estrip.Reset(); |
estrip.Reset(); |
| 435 |
* Given estrip entry returns energy plus view, plane and strip numbers |
* Given estrip entry returns energy plus view, plane and strip numbers |
| 436 |
**/ |
**/ |
| 437 |
Float_t CaloLevel1::DecodeEstrip(Int_t entry, Int_t &view, Int_t &plane, Int_t &strip){ |
Float_t CaloLevel1::DecodeEstrip(Int_t entry, Int_t &view, Int_t &plane, Int_t &strip){ |
| 438 |
|
Bool_t sat = false; |
| 439 |
|
Float_t mip=this->DecodeEstrip(entry,view,plane,strip,sat); |
| 440 |
|
return(mip); |
| 441 |
|
}; |
| 442 |
|
|
| 443 |
|
/** |
| 444 |
|
* Given estrip entry returns energy plus view, plane, strip numbers and saturation info |
| 445 |
|
**/ |
| 446 |
|
Float_t CaloLevel1::DecodeEstrip(Int_t entry, Int_t &view, Int_t &plane, Int_t &strip, Bool_t &saturated){ |
| 447 |
// |
// |
| 448 |
if ( entry>istrip ) return(0.); |
if ( entry>istrip ){ |
| 449 |
|
// |
| 450 |
|
printf(" ERROR: problems decoding entry %i, it seems that number of entries is %i\n",entry,istrip); |
| 451 |
|
// |
| 452 |
|
return(0.); |
| 453 |
|
}; |
| 454 |
// |
// |
| 455 |
// printf(" num lim %f \n",std::numeric_limits<Float_t>::max()); |
// printf(" num lim %f \n",std::numeric_limits<Float_t>::max()); |
| 456 |
// printf(" estrip.At(%i) = %i \n",entry,estrip.At(entry)); |
// printf(" estrip.At(%i) = %i \n",entry,estrip.At(entry)); |
| 492 |
// |
// |
| 493 |
strip = (Int_t)truncf((Float_t)((eval - fbi*1000000000 -plom*10000000)/100000)); |
strip = (Int_t)truncf((Float_t)((eval - fbi*1000000000 -plom*10000000)/100000)); |
| 494 |
// |
// |
| 495 |
Float_t mip = ((Float_t)(eval - fbi*1000000000 -plom*10000000 -strip*100000))/tim; |
Double_t mip = (Double_t)(((Float_t)(eval - fbi*1000000000 -plom*10000000 -strip*100000))/tim); |
| 496 |
// |
// |
| 497 |
if ( mip > 0. && mip < 99999. ) return(mip); |
saturated = false; |
| 498 |
|
if ( mip > 5000. ){ |
| 499 |
|
mip -= 5000.; |
| 500 |
|
saturated = true; |
| 501 |
|
}; |
| 502 |
|
if ( mip > 0. && mip < 99999. ) return((Float_t)mip); |
| 503 |
// |
// |
| 504 |
printf(" WARNING: problems decoding value %i at entry %i \n",estrip.At(entry),entry); |
printf(" ERROR: problems decoding value %i at entry %i \n",estrip.At(entry),entry); |
| 505 |
// |
// |
| 506 |
view = -1; |
view = -1; |
| 507 |
plane = -1; |
plane = -1; |
| 509 |
return(0.); |
return(0.); |
| 510 |
} |
} |
| 511 |
|
|
| 512 |
|
/* |
| 513 |
|
* Returns energy released on plane nplane (where 0<= nplane <= 43, 0 = 1Y, 1 = 1X, 2 = 2Y, 3 = 2X, etc. etc.). |
| 514 |
|
*/ |
| 515 |
|
Float_t CaloLevel1::qtotpl(Int_t nplane){ |
| 516 |
|
Bool_t sat = false; |
| 517 |
|
Float_t mip = this->qtotpl(nplane,sat); |
| 518 |
|
return(mip); |
| 519 |
|
}; |
| 520 |
|
|
| 521 |
|
/* |
| 522 |
|
* Returns energy released on plane nplane (where 0<= nplane <= 43, 0 = 1Y, 1 = 1X, 2 = 2Y, 3 = 2X, etc. etc.). |
| 523 |
|
*/ |
| 524 |
|
Float_t CaloLevel1::qtotpl(Int_t nplane, Bool_t &sat){ |
| 525 |
|
// |
| 526 |
|
sat = false; |
| 527 |
|
Int_t sview = 1; |
| 528 |
|
if ( nplane%2 ) sview = 0; |
| 529 |
|
// |
| 530 |
|
// Int_t splane = nplane-(sview+1)/2; |
| 531 |
|
Int_t splane = (nplane+sview-1)/2; |
| 532 |
|
// |
| 533 |
|
Float_t totmip = qtotpl(sview,splane,sat); |
| 534 |
|
// |
| 535 |
|
return(totmip); |
| 536 |
|
// |
| 537 |
|
}; |
| 538 |
|
|
| 539 |
|
/* |
| 540 |
|
* Returns energy released on view "view" (0 = X, 1 = Y) and plane "plane" ( 0 <= plane <= 21 ). |
| 541 |
|
*/ |
| 542 |
|
Float_t CaloLevel1::qtotpl(Int_t sview, Int_t splane){ |
| 543 |
|
Bool_t sat = false; |
| 544 |
|
Float_t mip = this->qtotpl(sview,splane,sat); |
| 545 |
|
return(mip); |
| 546 |
|
}; |
| 547 |
|
|
| 548 |
|
/* |
| 549 |
|
* Returns energy released on view "view" (0 = X, 1 = Y) and plane "plane" ( 0 <= plane <= 21 ). |
| 550 |
|
*/ |
| 551 |
|
Float_t CaloLevel1::qtotpl(Int_t sview, Int_t splane, Bool_t &sat){ |
| 552 |
|
// |
| 553 |
|
Int_t view = -1; |
| 554 |
|
Int_t plane = -1; |
| 555 |
|
Int_t strip = -1; |
| 556 |
|
Bool_t lsat = false; |
| 557 |
|
sat = false; |
| 558 |
|
// |
| 559 |
|
Float_t mip = 0.; |
| 560 |
|
Float_t totmip = 0.; |
| 561 |
|
// |
| 562 |
|
if ( istrip == 0 ) return(0.); |
| 563 |
|
// |
| 564 |
|
for (Int_t i = 0; i<istrip; i++ ){ |
| 565 |
|
// |
| 566 |
|
mip = DecodeEstrip(i,view,plane,strip,lsat); |
| 567 |
|
// |
| 568 |
|
if ( view == sview && splane == plane ){ |
| 569 |
|
if ( lsat ) sat = true; |
| 570 |
|
totmip += mip; |
| 571 |
|
//printf(" totmip %f mip %f \n",totmip,mip); |
| 572 |
|
}; |
| 573 |
|
// |
| 574 |
|
// entry are ordered by strip, plane and view number. Go out if you pass the input strip |
| 575 |
|
// |
| 576 |
|
if ( view == sview && plane > splane ) return(totmip); |
| 577 |
|
if ( view > sview ) return(totmip); |
| 578 |
|
// |
| 579 |
|
}; |
| 580 |
|
// |
| 581 |
|
return(totmip); |
| 582 |
|
// |
| 583 |
|
}; |