| 3 | * \author Emiliano Mocchiutti | * \author Emiliano Mocchiutti | 
| 4 | * | * | 
| 5 | **/ | **/ | 
|  | #include <TObject.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() { | 
| 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 |  | }; | 
| 147 |  | if ( !UXal ){ | 
| 148 |  | // | 
| 149 |  | printf(" No able to query DB for calorimeter parameters files\n Using hard-coded parameters \n"); | 
| 150 |  | UXal = CTX; | 
| 151 |  | UYal = CTY; | 
| 152 |  | UZal = CTZ; | 
| 153 |  | }; | 
| 154 |  | // | 
| 155 |  | }; | 
| 156 |  | // | 
| 157 |  | }; | 
| 158 |  |  | 
| 159 |  | /** | 
| 160 | * Given a strip returns its position in the PAMELA reference system | * Given a strip returns its position in the PAMELA reference system | 
| 161 | **/ | **/ | 
| 162 | void CaloStrip::Set(Int_t view, Int_t plane, Int_t strip) { | void CaloStrip::Set(Int_t view, Int_t plane, Int_t strip) { | 
| 187 | fView = view + 1; | fView = view + 1; | 
| 188 | fPlane = plane + 1; | fPlane = plane + 1; | 
| 189 | fStrip = strip + 1; | fStrip = strip + 1; | 
| 190 |  | // | 
| 191 | if ( fPlane%2 ){ | if ( fPlane%2 ){ | 
| 192 | lShift = -0.5; | lShift = +0.5; | 
| 193 | } else { | } else { | 
| 194 | lShift = 0.5; | lShift = -0.5; | 
| 195 | }; | }; | 
| 196 | // | // | 
| 197 | shift_.shift = lShift; | shift_.shift = lShift; | 
| 214 | // | // | 
| 215 | // X view | // X view | 
| 216 | // | // | 
| 217 | fX = (lPos - CTX)/10.; | fX = (lPos - UXal)/10.; | 
| 218 | fY = 0.; | fY = 0.; | 
| 219 | fZ = (zplane[fPlane-1] - 5.81 + CTZ)/10.; | fZ = (zplane[fPlane-1] - 5.81 + UZal)/10.; | 
| 220 | } else { | // | 
| 221 |  | } else { | 
| 222 | // | // | 
| 223 | // Y view | // Y view | 
| 224 | // | // | 
| 225 | fX = 0; | fX = 0; | 
| 226 | fY = (lPos - CTY)/10.; | fY = (lPos - UYal)/10.; | 
| 227 | fZ = (zplane[fPlane-1] + CTZ)/10.; | fZ = (zplane[fPlane-1] + UZal)/10.; | 
| 228 | }; | }; | 
| 229 | // | // | 
| 230 | }; | }; | 
| 234 | **/ | **/ | 
| 235 | void CaloStrip::Set(Float_t X, Float_t Y, Float_t Z) { | void CaloStrip::Set(Float_t X, Float_t Y, Float_t Z) { | 
| 236 | // | // | 
| 237 | //   Float_t lShift = 0.; | fX = X; | 
| 238 | //   Float_t lPos = 0.; | fY = Y; | 
| 239 | //   extern struct shift shift; | fZ = Z; | 
| 240 | //   // | // | 
| 241 | //   fView = view++; | Float_t zplane[22]; | 
| 242 | //   fPlane = plane++; | zplane[0] = 0.; | 
| 243 | //   fStrip = strip++; | Int_t ii = 0; | 
| 244 | //   if ( fPlane%2 ){ | for ( Int_t i = 2; i < 23; i++){ | 
| 245 | //     lShift = -0.5; | ii = i-1; | 
| 246 | //   } else { | if ( i%2 ){ | 
| 247 | //     lShift = 0.5; | zplane[ii] = zplane[ii-1] - 10.09; | 
| 248 | //   }; | } else { | 
| 249 | //   // | zplane[ii] = zplane[ii-1] - 8.09; | 
| 250 | //   shift.shift = lShift; | }; | 
| 251 | //   // | }; | 
| 252 | //   Float_t zplane[22]; | // | 
| 253 | //   zplane[0] = 0.; | Float_t dzx[22]; | 
| 254 | //   Int_t ii = 0; | Float_t dzy[22]; | 
| 255 | //   for ( Int_t i = 2; i < 23; i++){ | for ( Int_t i=0; i < 22; i++){ | 
| 256 | //     ii = i-1; | dzx[i] = fabs(fZ*10. - (zplane[i] - 5.81 + UZal)); | 
| 257 | //     if ( i%2 ){ | dzy[i] = fabs(fZ*10. - (zplane[i] + UZal)); | 
| 258 | //       zplane[ii] = zplane[ii-1] - 10.09 + CTZ; | }; | 
| 259 | //     } else { | // | 
| 260 | //       zplane[ii] = zplane[ii-1] - 8.09 + CTZ; | Float_t minx = TMath::MinElement(22,dzx); | 
| 261 | //     }; | Float_t miny = TMath::MinElement(22,dzy); | 
| 262 | //   }; | // | 
| 263 | //   // | // find view | 
| 264 | //   millim_(&fStrip,&lPos); | // | 
| 265 | //   // | if ( minx < miny ){ | 
| 266 | //   if ( fView == 1 ){ | fView = 1; | 
| 267 | //     // | } else { | 
| 268 | //     // X view | fView = 2; | 
| 269 | //     // | }; | 
| 270 | //     fX = lPos; | // | 
| 271 | //     fY = 0.; | // find plane | 
| 272 | //     fZ = zplane[fPlane-1] - 5.81; | // | 
| 273 | //   } else { | Float_t pos = 0.; | 
| 274 | //     // | // | 
| 275 | //     // Y view | for ( Int_t i=0; i < 22; i++){ | 
| 276 | //     // | if ( fView == 1 ){ | 
| 277 | //     fX = 0.; | if ( dzx[i] == minx ){ | 
| 278 | //     fY = lPos; | fPlane = i+1; | 
| 279 | //     fZ = zplane[fPlane-1]; | pos = fX*10. + UXal; | 
| 280 | //   }; | }; | 
| 281 |  | } else { | 
| 282 |  | if ( dzy[i] == miny ){ | 
| 283 |  | fPlane = i+1; | 
| 284 |  | pos = fY*10. + UYal; | 
| 285 |  | }; | 
| 286 |  | }; | 
| 287 |  | }; | 
| 288 |  | // | 
| 289 |  | // find strip | 
| 290 |  | // | 
| 291 |  | Float_t dxy[96]; | 
| 292 |  | Float_t stpos = 0.; | 
| 293 |  | // | 
| 294 |  | CaloStrip *ca = new CaloStrip(); | 
| 295 |  | // | 
| 296 |  | for ( Int_t i=0; i < 96; i++){ | 
| 297 |  | ca->Set(fView-1,fPlane-1,i); | 
| 298 |  | if ( fView == 1 ){ | 
| 299 |  | stpos = ca->GetX()*10. + UXal; | 
| 300 |  | } else { | 
| 301 |  | stpos = ca->GetY()*10. + UYal; | 
| 302 |  | }; | 
| 303 |  | dxy[i] = fabs(pos - stpos); | 
| 304 |  | }; | 
| 305 |  | // | 
| 306 |  | delete ca; | 
| 307 | // | // | 
| 308 |  | Float_t mins =  TMath::MinElement(96,dxy); | 
| 309 |  | // | 
| 310 |  | for ( Int_t i=0; i < 96; i++){ | 
| 311 |  | if ( dxy[i] == mins ) fStrip = i+1; | 
| 312 |  | }; | 
| 313 | }; | }; | 
|  | //                      DISTY = PIANO(I) |  | 
|  | //                      YY(I) = DISTY * TG(2) + CY |  | 
|  | //                      BAR(M,I) = YY(I) |  | 
|  | //                      CBAR(M,I) = (-YALIG + YY(I))/10. |  | 
|  | // C |  | 
|  | //                   ENDIF |  | 
|  | //                   CALL LASTRISCIA(BAR(M,I),IBAR(M,I)) |  | 
|  | //                   CIBAR(M,I) = IBAR(M,I) |  | 
|  | //                ENDDO |  | 
|  | //             ENDIF |  | 
|  | // C |  | 
|  | //          ENDDO |  | 
|  |  |  | 
|  |  |  | 
| 314 |  |  | 
| 315 | /** | /** | 
| 316 | * CaloLevel1 constructor | * CaloLevel1 constructor | 
| 364 | * Given estrip entry returns energy plus view, plane and strip numbers | * Given estrip entry returns energy plus view, plane and strip numbers | 
| 365 | **/ | **/ | 
| 366 | 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){ | 
| 367 |  | Bool_t sat = false; | 
| 368 |  | Float_t mip=this->DecodeEstrip(entry,view,plane,strip,sat); | 
| 369 |  | return(mip); | 
| 370 |  | }; | 
| 371 |  |  | 
| 372 |  | /** | 
| 373 |  | * Given estrip entry returns energy plus view, plane, strip numbers and saturation info | 
| 374 |  | **/ | 
| 375 |  | Float_t CaloLevel1::DecodeEstrip(Int_t entry, Int_t &view, Int_t &plane, Int_t &strip, Bool_t &saturated){ | 
| 376 | // | // | 
| 377 | if ( entry>istrip ) return(0.); | if ( entry>istrip ){ | 
| 378 |  | // | 
| 379 |  | printf(" ERROR: problems decoding entry %i, it seems that number of entries is %i\n",entry,istrip); | 
| 380 |  | // | 
| 381 |  | return(0.); | 
| 382 |  | }; | 
| 383 | // | // | 
| 384 | //  printf(" num lim %f \n",std::numeric_limits<Float_t>::max()); | //  printf(" num lim %f \n",std::numeric_limits<Float_t>::max()); | 
| 385 | //  printf(" estrip.At(%i) = %i \n",entry,estrip.At(entry)); | //  printf(" estrip.At(%i) = %i \n",entry,estrip.At(entry)); | 
| 423 | // | // | 
| 424 | Float_t mip = ((Float_t)(eval - fbi*1000000000 -plom*10000000 -strip*100000))/tim; | Float_t mip = ((Float_t)(eval - fbi*1000000000 -plom*10000000 -strip*100000))/tim; | 
| 425 | // | // | 
| 426 |  | saturated = false; | 
| 427 |  | if ( mip > 5000. ){ | 
| 428 |  | mip -= 5000.; | 
| 429 |  | saturated = true; | 
| 430 |  | }; | 
| 431 | if ( mip > 0. && mip < 99999. ) return(mip); | if ( mip > 0. && mip < 99999. ) return(mip); | 
| 432 | // | // | 
| 433 | 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); | 
| 434 | // | // | 
| 435 | view = -1; | view = -1; | 
| 436 | plane = -1; | plane = -1; | 
| 438 | return(0.); | return(0.); | 
| 439 | } | } | 
| 440 |  |  | 
| 441 |  | /* | 
| 442 |  | * Returns energy released on plane nplane (where 0<= nplane <= 43, 0 = 1Y, 1 = 1X, 2 = 2Y, 3 = 2X, etc. etc.). | 
| 443 |  | */ | 
| 444 |  | Float_t CaloLevel1::qtotpl(Int_t nplane){ | 
| 445 |  | Bool_t sat = false; | 
| 446 |  | Float_t mip = this->qtotpl(nplane,sat); | 
| 447 |  | return(mip); | 
| 448 |  | }; | 
| 449 |  |  | 
| 450 |  | /* | 
| 451 |  | * Returns energy released on plane nplane (where 0<= nplane <= 43, 0 = 1Y, 1 = 1X, 2 = 2Y, 3 = 2X, etc. etc.). | 
| 452 |  | */ | 
| 453 |  | Float_t CaloLevel1::qtotpl(Int_t nplane, Bool_t &sat){ | 
| 454 |  | // | 
| 455 |  | sat = false; | 
| 456 |  | Int_t sview = 1; | 
| 457 |  | if ( nplane%2 ) sview = 0; | 
| 458 |  | // | 
| 459 |  | Int_t splane = nplane-(sview+1)/2; | 
| 460 |  | // | 
| 461 |  | Float_t totmip = qtotpl(sview,splane,sat); | 
| 462 |  | // | 
| 463 |  | return(totmip); | 
| 464 |  | // | 
| 465 |  | }; | 
| 466 |  |  | 
| 467 |  | /* | 
| 468 |  | * Returns energy released on view "view" (0 = X, 1 = Y) and plane "plane" ( 0 <= plane <= 21 ). | 
| 469 |  | */ | 
| 470 |  | Float_t CaloLevel1::qtotpl(Int_t sview, Int_t splane){ | 
| 471 |  | Bool_t sat = false; | 
| 472 |  | Float_t mip = this->qtotpl(sview,splane,sat); | 
| 473 |  | return(mip); | 
| 474 |  | }; | 
| 475 |  |  | 
| 476 |  | /* | 
| 477 |  | * Returns energy released on view "view" (0 = X, 1 = Y) and plane "plane" ( 0 <= plane <= 21 ). | 
| 478 |  | */ | 
| 479 |  | Float_t CaloLevel1::qtotpl(Int_t sview, Int_t splane, Bool_t &sat){ | 
| 480 |  | // | 
| 481 |  | Int_t view = -1; | 
| 482 |  | Int_t plane = -1; | 
| 483 |  | Int_t strip = -1; | 
| 484 |  | Bool_t lsat = false; | 
| 485 |  | sat = false; | 
| 486 |  | // | 
| 487 |  | Float_t mip = 0.; | 
| 488 |  | Float_t totmip = 0.; | 
| 489 |  | // | 
| 490 |  | if ( istrip == 0 ) return(0.); | 
| 491 |  | // | 
| 492 |  | for (Int_t i = 0; i<istrip; i++ ){ | 
| 493 |  | // | 
| 494 |  | mip = DecodeEstrip(i,view,plane,strip,lsat); | 
| 495 |  | // | 
| 496 |  | if ( view == sview && splane == plane ){ | 
| 497 |  | if ( lsat ) sat = true; | 
| 498 |  | totmip += mip; | 
| 499 |  | }; | 
| 500 |  | // | 
| 501 |  | // entry are ordered by strip, plane and view number. Go out if you pass the input strip | 
| 502 |  | // | 
| 503 |  | if ( view == sview && plane > splane ) return(totmip); | 
| 504 |  | if ( view > sview ) return(totmip); | 
| 505 |  | // | 
| 506 |  | }; | 
| 507 |  | // | 
| 508 |  | return(totmip); | 
| 509 |  | // | 
| 510 |  | }; |