--- DarthVader/CalorimeterLevel2/src/CaloLevel1.cpp 2007/01/11 16:08:02 1.3 +++ DarthVader/CalorimeterLevel2/src/CaloLevel1.cpp 2007/03/30 11:22:07 1.7 @@ -3,8 +3,6 @@ * \author Emiliano Mocchiutti * **/ -#include -#include #include // ClassImp(CaloStrip); @@ -21,15 +19,51 @@ /** * CaloStrip default constructor **/ +CaloStrip::CaloStrip(Bool_t mechalig) { + c1 = 0; + this->Clear(); + if ( mechalig ){ + ismech = true; + UXal = MECHCTX; + UYal = MECHCTY; + UZal = MECHCTZ; + } else { + ismech = false; + UseStandardAlig(); + }; +}; + +/** + * CaloStrip default constructor +**/ CaloStrip::CaloStrip(CaloLevel1 *calo) { c1 = calo->GetCaloLevel1(); this->Clear(); + ismech = false; + UseStandardAlig(); +}; + +/** + * CaloStrip default constructor +**/ +CaloStrip::CaloStrip(CaloLevel1 *calo, Bool_t mechalig) { + c1 = calo->GetCaloLevel1(); + this->Clear(); + if ( mechalig ){ + ismech = true; + UXal = MECHCTX; + UYal = MECHCTY; + UZal = MECHCTZ; + } else { + ismech = false; + UseStandardAlig(); + }; }; /** * Clear variables **/ -void CaloStrip::Clear() { +void CaloStrip::Clear() { fE = 0.; fX = 0.; fY = 0.; @@ -40,6 +74,77 @@ }; /** + * Connect to the DB and retrieve alignement parameters + **/ +void CaloStrip::UseStandardAlig(){ + // + ismech = false; + // + stringstream aligfile; + Int_t error = 0; + FILE *f = 0; + ifstream badfile; + GL_PARAM *glparam = new GL_PARAM(); + // + TString host = "mysql://localhost/pamelaprod"; + TString user = "anonymous"; + TString psw = ""; + const char *pamdbhost=gSystem->Getenv("PAM_DBHOST"); + const char *pamdbuser=gSystem->Getenv("PAM_DBUSER"); + const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW"); + if ( !pamdbhost ) pamdbhost = ""; + if ( !pamdbuser ) pamdbuser = ""; + if ( !pamdbpsw ) pamdbpsw = ""; + if ( strcmp(pamdbhost,"") ) host = pamdbhost; + if ( strcmp(pamdbuser,"") ) user = pamdbuser; + if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw; + TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); + // + UXal = 0.; + UYal = 0.; + UZal = 0.; + // + if ( dbc ){ + // + // determine where I can find calorimeter ADC to MIP conversion file + // + printf(" Querying DB for calorimeter parameters files...\n"); + // + // + // + error = 0; + error = glparam->Query_GL_PARAM(1000,102,dbc); + if ( error >= 0 ){ + // + aligfile.str(""); + aligfile << glparam->PATH.Data() << "/"; + aligfile << glparam->NAME.Data(); + // + printf("\n Using parameter file: \n %s \n",aligfile.str().c_str()); + f = fopen(aligfile.str().c_str(),"rb"); + if ( f ){ + // + fread(&UXal,sizeof(UXal),1,f); + fread(&UYal,sizeof(UYal),1,f); + fread(&UZal,sizeof(UZal),1,f); + // + fclose(f); + }; + // + }; + dbc->Close(); + }; + if ( !UXal ){ + // + printf(" No able to query DB for calorimeter parameters files\n Using hard-coded parameters \n"); + UXal = CTX; + UYal = CTY; + UZal = CTZ; + }; + // +}; + +/** * Given a strip returns its position in the PAMELA reference system **/ void CaloStrip::Set(Int_t view, Int_t plane, Int_t strip) { @@ -70,10 +175,11 @@ fView = view + 1; fPlane = plane + 1; fStrip = strip + 1; + // if ( fPlane%2 ){ - lShift = -0.5; + lShift = +0.5; } else { - lShift = 0.5; + lShift = -0.5; }; // shift_.shift = lShift; @@ -96,16 +202,17 @@ // // X view // - fX = (lPos - CTX)/10.; + fX = (lPos - UXal)/10.; fY = 0.; - fZ = (zplane[fPlane-1] - 5.81 + CTZ)/10.; - } else { + fZ = (zplane[fPlane-1] - 5.81 + UZal)/10.; + // + } else { // // Y view // fX = 0; - fY = (lPos - CTY)/10.; - fZ = (zplane[fPlane-1] + CTZ)/10.; + fY = (lPos - UYal)/10.; + fZ = (zplane[fPlane-1] + UZal)/10.; }; // }; @@ -134,8 +241,8 @@ Float_t dzx[22]; Float_t dzy[22]; for ( Int_t i=0; i < 22; i++){ - dzx[i] = fabs(fZ*10. - (zplane[i] - 5.81 + CTZ)); - dzy[i] = fabs(fZ*10. - (zplane[i] + CTZ)); + dzx[i] = fabs(fZ*10. - (zplane[i] - 5.81 + UZal)); + dzy[i] = fabs(fZ*10. - (zplane[i] + UZal)); }; // Float_t minx = TMath::MinElement(22,dzx); @@ -157,12 +264,12 @@ if ( fView == 1 ){ if ( dzx[i] == minx ){ fPlane = i+1; - pos = fX*10. + CTX; + pos = fX*10. + UXal; }; } else { if ( dzy[i] == miny ){ fPlane = i+1; - pos = fY*10. + CTY; + pos = fY*10. + UYal; }; }; }; @@ -177,9 +284,9 @@ for ( Int_t i=0; i < 96; i++){ ca->Set(fView-1,fPlane-1,i); if ( fView == 1 ){ - stpos = ca->GetX()*10. + CTX; + stpos = ca->GetX()*10. + UXal; } else { - stpos = ca->GetY()*10. + CTY; + stpos = ca->GetY()*10. + UYal; }; dxy[i] = fabs(pos - stpos); };