// 06/27/05 Alex Melnitchouk melnit@fnal.gov // took this file from Paul Russo // to test and release it // This code simplifies smt calibration // part of d0reco: // -- saves 80MB of memory // -- eliminates redundant calls to // offline calibration database // -- allows not to use 6 componets of smtraw // -- allows not to use calibration_management package // -- allows not to use smt_calibdata package // -- allows not to use smt_config package // -- everything is now done in // smt_calibration package and // SmtRawUnp2Data component of smtraw //------------------------------------------------------------------ // 07/14/05 Alex Melnitchouk melnit@fnal.gov // added L0 //------------------------------------------------------------------ // 09/19/05 Alex Melnitchouk melnit@fnal.gov // upon request from L3 folks // replaced in long SmtCalibrater::getStatus(int calid, int chip, int chan) // "return 1L;" (1L means SmtCalibrater::status=DEAD) // with // "return 0L;" (0L means SmtCalibrater::status=OK) //------------------------------------------------------------------ // SmtCalibrater.cpp #include "smt_calibration/SmtCalibrater.hpp" #include "d0stream/d0_RefTo.hpp" #include "smt_calibdata/StripCalib.hpp" #include "smt_calibration/SmtCalibrations.hpp" #include "smt_calibration/SmtPedCalibrations.hpp" #include "smt_calibration/SmtPedCollections.hpp" #include "smt_calibration/SmtPedSets.hpp" #include "smt_calibration/SmtPedestals.hpp" #include "smtutil/StripAddress.hpp" #include "smtutil/StripFEAddress.hpp" #include #include #include #include #include #include using namespace smt_calibration; using namespace std; namespace { void fill_arrays(d0_RefTo& calib, float fdisk_peds[12][2][12][8][128], float hdisk_peds[4][2][24][6][128], float barrel_peds[6][8][12][9][128], float l0barrel_peds[8][2][6][2][128], float fdisk_peds_sigma[12][2][12][8][128], float hdisk_peds_sigma[4][2][24][6][128], float barrel_peds_sigma[6][8][12][9][128], float l0barrel_peds_sigma[8][2][6][2][128]) { // F Disk // Initialize to -1.0F to signify no data in database. for (int disk = 0; disk < 12; ++disk) { for (int view = 0; view < 2; ++view) { for (int wedge = 0; wedge < 12; ++wedge) { for (int chip = 0; chip < 8; ++chip) { for (int channel = 0; channel < 128; ++channel) { fdisk_peds[disk][view][wedge][chip][channel] = -1.0F; fdisk_peds_sigma[disk][view][wedge][chip][channel] = -1.0F; } } } } } // H Disk // Initialize to -1.0F to signify no data in database. for (int disk = 0; disk < 4; ++disk) { for (int view = 0; view < 2; ++view) { for (int wedge = 0; wedge < 24; ++wedge) { for (int chip = 0; chip < 6; ++chip) { for (int channel = 0; channel < 128; ++channel) { hdisk_peds[disk][view][wedge][chip][channel] = -1.0F; hdisk_peds_sigma[disk][view][wedge][chip][channel] = -1.0F; } } } } } // Barrel // Initialize to -1.0F to signify no data in database. for (int barrel = 0; barrel < 6; ++barrel) { for (int layer = 0; layer < 8; ++layer) { for (int ladder = 0; ladder < 12; ++ladder) { for (int chip = 0; chip < 9; ++chip) { for (int channel = 0; channel < 128; ++channel) { barrel_peds[barrel][layer][ladder][chip][channel] = -1.0F; barrel_peds_sigma[barrel][layer][ladder][chip][channel] = -1.0F; } } } } } // L0 Barrel // Initialize to -1.0F to signify no data in database. for (int l0barrel = 0; l0barrel < 8; ++l0barrel) { for (int l0layer = 0; l0layer < 2; ++l0layer) { for (int l0ladder = 0; l0ladder < 6; ++l0ladder) { for (int l0chip = 0; l0chip < 2; ++l0chip) { for (int l0channel = 0; l0channel < 128; ++l0channel) { l0barrel_peds[l0barrel][l0layer][l0ladder][l0chip][l0channel] = -1.0F; l0barrel_peds_sigma[l0barrel][l0layer][l0ladder][l0chip][l0channel] = -1.0F; } } } } } //------- BEGIN CODE FOR READING L0SMT PEDESTALS FROM TEXT FILE --------- //B1-6-12-0-0 9879552 56.0031 3.49637 //B1-6-12-0-1 9879553 68.4547 3.75713 //B1-6-12-0-2 9879554 69.0184 3.81813 //B1-6-12-0-3 9879555 69.9877 3.69238 //B1-6-12-0-4 9879556 70.0737 3.81706 string idstring; int skipthis; float pedestal; float sigma; ifstream fin; fin.open("/work/sibir-clued0/nayeem/silicon/calib/p200100/output/230956_output_5ADC/channel_id_ped.txt"); assert(fin); int linecount =0; while (fin && linecount<574754) { linecount++; fin>>idstring>>skipthis>>pedestal>>sigma; cout<1){ std::string::size_type n = idstring.rfind("-",len); if (n != string::npos) { indices[index_count] = atoi((idstring.substr(n+1,len)).c_str()); idstring= idstring.substr(0,n); index_count--; len = idstring.length(); } } //extracting itype const char *tmp = idstring.c_str(); if (tmp[0]=='B') indices[0]=1; if (tmp[0]=='F') indices[0]=2; if (tmp[0]=='H') indices[0]=3; if (tmp[0]=='L') indices[0]=0; //extracting barrrel(disk) indices[1]=atoi(idstring.substr(1,len-1).c_str()); for (int j=0; j<6;j++) cout<, smt_calibration::SmtPedCalibrationsRefType> PCols; // typedef d0_RefBy, smt_calibration::SmtPedSetsRefType> Peds; // // PCols& pcols = calib->get_SmtPedCalibrations()->get_SmtPedCollections(); // // // Loop over HDI's in detector. // for (PCols::iterator ped_it = pcols.begin(); ped_it != pcols.end(); ++ped_it) { // Peds& peds = ped_it->get_SmtPedSets()->get_SmtPedestals(); // // Loop over channels for one HDI. // for (Peds::iterator ped_iter = peds.begin(); ped_iter != peds.end(); ++ped_iter) { // long chid = ped_iter->get_channelId(); // int chip = (chid >> 8) & 0xF; // int chan = chid & 0xFF; // long calid = ped_iter->get_calId(); // int det = (calid >> 10) & 0x3; // int l0pattern = (calid >> 8) & 0xF; // if (l0pattern != 0x8){ // switch (det) { // // F Disk // case 0: // { // int disk = (calid >> 6) & 0xF; // int view = (calid >> 4) & 0x3; // int wedge = calid & 0xF; // fdisk_peds[disk-1][view-1][wedge-1][chip][chan] = ped_iter->get_value(); // fdisk_peds_sigma[disk-1][view-1][wedge-1][chip][chan] = ped_iter->get_sigma(); // } // break; // // H Disk // case 1: // { // int disk = (calid >> 7) & 0x7; // int view = (calid >> 5) & 0x3; // int wedge = calid & 0x1F; // hdisk_peds[disk-1][view-1][wedge-1][chip][chan] = ped_iter->get_value(); // hdisk_peds_sigma[disk-1][view-1][wedge-1][chip][chan] = ped_iter->get_sigma(); // } // break; // // Barrel // default: // { // int barrel = (calid >> 8) & 0x7; // int layer = (calid >> 4) & 0xF; // int ladder = calid & 0xF; // barrel_peds[barrel-1][layer-1][ladder-1][chip][chan] = ped_iter->get_value(); // barrel_peds_sigma[barrel-1][layer-1][ladder-1][chip][chan] = ped_iter->get_sigma(); // } // break; // }//switch (det) // } // else { // int l0barrel = (calid >> 5) & 0x7; // int l0layer = (calid >> 3) & 0x3; // int l0ladder = calid & 0x7; // l0barrel_peds[l0barrel][l0layer-1][l0ladder-1][chip][chan] = ped_iter->get_value();// in calid l0barrel is stored as 0,...,7 // l0barrel_peds_sigma[l0barrel][l0layer-1][l0ladder-1][chip][chan] = ped_iter->get_sigma();// in calid l0barrel is stored as 0,...,7 // }//if (l0pattern != 0x8) // } // Loop over channels // // Release the memory holding the pedestal // // data fetched from the database. // // N.B.: This improves our virtual memory performance. // ped_it->get_SmtPedSets().clear(); // } // Loop over HDI's // // Release the memory holding the contents of the // // intermediate tables we navigated through. // calib.clear(); //------- END COMMENTING OUT CODE THAT READS PEDESTALS FROM THE DB -- } } // unnamed namespace SmtCalibrater::SmtCalibrater() : xDetCalibrater("SMT_CALIB_ID", 12, "SMT_CALIBRATIONS") {} SmtCalibrater::~SmtCalibrater() {} bool SmtCalibrater::update_constants(d0_RefTo& newcalib) { // Given a row in the SmtCalibrations table, update our in-memory // copy of the calibration data from the database. _calib = newcalib; fill_arrays(newcalib, _fdisk_peds, _hdisk_peds, _barrel_peds, _l0barrel_peds, _fdisk_peds_sigma, _hdisk_peds_sigma, _barrel_peds_sigma, _l0barrel_peds_sigma); return true; } void SmtCalibrater::get_calib(const StripFEAddress& feaddr, const StripAddress& addr, float* pedestal, float* pedestal_sigma, float* gain, int* strip_status) const { // Given a Front End Address and the corresponding Physics Address // (after applying the address translation) of a channel, retrieve // the calibration data for that channel (pedestal, pedestal_sigma, // gain, and strip status). int chip = feaddr.ChipIndex(); int chan = feaddr.SvxChanIndex(); *pedestal = -256.0F; *pedestal_sigma = -256.0F; *gain = 0.00352567; *strip_status = smthit::GOOD; int det = addr.DetType(); switch (det) { // Barrel case 1: { int barrel, layer, ladder, view, strip; addr.unpackStripAddress(barrel, layer, ladder, view, strip); *pedestal = _barrel_peds[barrel-1][layer-1][ladder-1][chip][chan]; *pedestal_sigma = _barrel_peds_sigma[barrel-1][layer-1][ladder-1][chip][chan]; } break; // L0 Barrel case 0: { int l0barrel, l0layer, l0ladder, l0view, l0strip; addr.unpackStripAddress(l0barrel, l0layer, l0ladder, l0view, l0strip); *pedestal = _l0barrel_peds[l0barrel-1][l0layer-1][l0ladder-1][chip][chan]; *pedestal_sigma = _l0barrel_peds_sigma[l0barrel-1][l0layer-1][l0ladder-1][chip][chan]; } break; // F Disk case 2: { int disk, wedge, view, strip; addr.unpackStripAddress(disk, wedge, view, strip); *pedestal = _fdisk_peds[disk-1][view-1][wedge-1][chip][chan]; *pedestal_sigma = _fdisk_peds_sigma[disk-1][view-1][wedge-1][chip][chan]; } break; // H Disk case 3: { int disk, wedge, view, strip; addr.unpackStripAddress(disk, wedge, view, strip); *pedestal = _hdisk_peds[disk-1][view-1][wedge-1][chip][chan]; *pedestal_sigma = _hdisk_peds_sigma[disk-1][view-1][wedge-1][chip][chan]; } break; } // Calculate the strip status the way SmtConfigurator does. // Note that we use the untruncated pedestal and pedestal_sigma // values here. if (*pedestal < 10.0F) { *strip_status = smthit::DEAD; } if (*pedestal_sigma > 6.0F) { *strip_status = smthit::NOISY; } // Modify the pedestal and the pedestal_sigma the way smt_calibdata/src/Chip.cpp does. *pedestal_sigma = static_cast(static_cast(*pedestal_sigma)); float truncated_pedestal = static_cast(static_cast(*pedestal)); if (std::abs(*pedestal - truncated_pedestal) > 0.5F) { *pedestal = truncated_pedestal + 0.5F; } else { *pedestal = truncated_pedestal; } // Modify the pedestal the way smtraw/src/SmtCalibMgr.cpp does. if ((*strip_status != smthit::GOOD) && (*strip_status != smthit::NOISY)) { *pedestal = 255.0F; } // Modify the gain the way smtraw/src/SmtCalibMgr.cpp does. if (*strip_status != smthit::GOOD) { *gain = 0.0F; } } float SmtCalibrater::getPedestal(int calid, int chip, int chan) { // Backwards compatibility interface for l3smt_calib. // Return the unmodified pedestal value as stored in the database. float pedestal = -1.0F; // Decode the detector type from the calid. int det = 0; if ((calid >> 11) & 0x1) { // Barrel det = 1; // L0 if (((calid >> 8) & 0xF) == 0x8) det = 0; } else if (((calid >> 10) & 0x11) == 0) { // F Disk det = 2; } else { // H Disk det = 3; } // Based on detector type decode the rest of the calid // and fetch the pedestal value. switch (det) { // L0 case 0: { // calid = 1000BBBYYLLL int l0barrel, l0layer, l0ladder, l0view, l0strip; unsigned int l0tmp = calid; l0ladder = l0tmp & 0x7; l0tmp >>= 3; l0layer = l0tmp & 0x3; l0tmp >>= 2; l0barrel = l0tmp & 0x7; pedestal = _l0barrel_peds[l0barrel][l0layer-1][l0ladder-1][chip][chan];// in calid l0barrel is stored as 0,...,7 } break; // Barrel case 1: { // calid = 1BBBYYYYLLLL int barrel, layer, ladder, view, strip; unsigned int tmp = calid; ladder = tmp & 0xF; tmp >>= 4; layer = tmp & 0xF; tmp >>= 4; barrel = tmp & 0x7; pedestal = _barrel_peds[barrel-1][layer-1][ladder-1][chip][chan]; } break; // F Disk case 2: { // calid = 00DDDDVVWWWW int disk, wedge, view, strip; unsigned int tmp = calid; wedge = tmp & 0xF; tmp >>= 4; view = tmp & 0x3; tmp >> 2; disk = tmp & 0xF; pedestal = _fdisk_peds[disk-1][view-1][wedge-1][chip][chan]; } break; // H Disk case 3: { // calid = 01DDDVVWWWWW int disk, wedge, view, strip; unsigned int tmp = calid; wedge = tmp & 0x1F; tmp >>= 5; view = tmp & 0x3; tmp >> 2; disk = tmp & 0x7; pedestal = _hdisk_peds[disk-1][view-1][wedge-1][chip][chan]; } break; } return pedestal; } long SmtCalibrater::getStatus(int calid, int chip, int chan) { // Backwards compatibility interface for l3smt_calib. // The original code returns the count of rows satisfying // a query for the existence of the channel in the database. // This is clearly not the right thing to do, but hey, that // is what is expected. return 0L; // Septeber 19, 2005 Alex Melnitchouk melnit@fnal.gov replaced // "return 1L;" (1L means SmtCalibrater::status=DEAD) // with // "return 0L;" (0L means SmtCalibrater::status=OK) }