CMS 3D CMS Logo

Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes

CSCGasGainCorrectionDBConditions Class Reference

#include <CSCGasGainCorrectionDBConditions.h>

Inheritance diagram for CSCGasGainCorrectionDBConditions:
edm::ESProducer edm::EventSetupRecordIntervalFinder edm::ESProxyFactoryProducer edm::eventsetup::DataProxyProvider

List of all members.

Public Types

typedef const
CSCDBGasGainCorrection
ReturnType

Public Member Functions

 CSCGasGainCorrectionDBConditions (const edm::ParameterSet &)
ReturnType produceDBGasGainCorrection (const CSCDBGasGainCorrectionRcd &)
 ~CSCGasGainCorrectionDBConditions ()

Static Public Member Functions

static CSCDBGasGainCorrectionprefillDBGasGainCorrection (bool isForMC, std::string dataCorrFileName)

Private Member Functions

void setIntervalFor (const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &)

Private Attributes

CSCDBGasGainCorrectioncndbGasGainCorr
std::string dataCorrFileName
bool isForMC

Detailed Description

Definition at line 21 of file CSCGasGainCorrectionDBConditions.h.


Member Typedef Documentation

Definition at line 28 of file CSCGasGainCorrectionDBConditions.h.


Constructor & Destructor Documentation

CSCGasGainCorrectionDBConditions::CSCGasGainCorrectionDBConditions ( const edm::ParameterSet iConfig)

Definition at line 10 of file CSCGasGainCorrectionDBConditions.cc.

References cndbGasGainCorr, dataCorrFileName, edm::ParameterSet::getUntrackedParameter(), isForMC, prefillDBGasGainCorrection(), produceDBGasGainCorrection(), and edm::ESProducer::setWhatProduced().

{
  //the following line is needed to tell the framework what
  // data is being produced
  isForMC = iConfig.getUntrackedParameter<bool>("isForMC",true);
  dataCorrFileName= iConfig.getUntrackedParameter<std::string>("dataCorrFileName","empty.txt");
  cndbGasGainCorr = prefillDBGasGainCorrection(isForMC,dataCorrFileName);
  // added by Zhen (changed since 1_2_0)
  setWhatProduced(this,&CSCGasGainCorrectionDBConditions::produceDBGasGainCorrection);
  findingRecord<CSCDBGasGainCorrectionRcd>();
  //now do what ever other initialization is needed

}
CSCGasGainCorrectionDBConditions::~CSCGasGainCorrectionDBConditions ( )

Definition at line 25 of file CSCGasGainCorrectionDBConditions.cc.

References cndbGasGainCorr.

{
 
   // do anything here that needs to be done at desctruction time
   // (e.g. close files, deallocate resources etc.)
  delete cndbGasGainCorr;
}

Member Function Documentation

CSCDBGasGainCorrection * CSCGasGainCorrectionDBConditions::prefillDBGasGainCorrection ( bool  isForMC,
std::string  dataCorrFileName 
) [inline, static]

Definition at line 55 of file CSCGasGainCorrectionDBConditions.h.

References CastorDataFrameFilter_impl::check(), cndbGasGainCorr, gather_cfg::cout, Reference_intrackfit_cff::endcap, groupFilesInBlocks::fin, CSCDBGasGainCorrection::gasGainCorr, i, j, timingPdfMaker::mean, relativeConstraints::ring, and relativeConstraints::station.

Referenced by CSCGasGainCorrectionDBConditions().

{
  if (isMC)
    printf("\n Generating fake DB constants for MC\n");
  else {
    printf("\n Reading gas gain corrections from file %s \n",filename.data());
  }
  
  CSCIndexer indexer;

  const int MAX_SIZE = 55944;

  CSCDBGasGainCorrection * cndbGasGainCorr = new CSCDBGasGainCorrection();

  CSCDBGasGainCorrection::GasGainContainer & itemvector = cndbGasGainCorr->gasGainCorr;
  itemvector.resize(MAX_SIZE);

  //Filling corrections for MC is very simple
  if (isMC){
    for (int i=0;i<MAX_SIZE;i++){
      itemvector[i].gainCorr = 1.;
    }
    return cndbGasGainCorr;
  }

  struct gain_info {
    int   gas_gain_index     ;
    int   endcap             ;
    int   station            ;
    int   ring               ;
    int   chamber            ;
    int   layer              ;
    int   hvsegment          ;
    int   cfeb               ;
    int   nentries           ;
    float mean               ;
    float truncated_mean     ;
    float gas_gain_correction;
  } gains[MAX_SIZE];


  for (int j=0; j<MAX_SIZE; j++) {
    gains[j].gas_gain_index     = -999;
    gains[j].endcap             = -999;
    gains[j].station            = -999;
    gains[j].ring               = -999;
    gains[j].chamber            = -999;
    gains[j].layer              = -999;
    gains[j].hvsegment          = -999;
    gains[j].cfeb               = -999;
    gains[j].nentries           = -999;
    gains[j].mean               = -999.;
    gains[j].truncated_mean     = -999.;
    gains[j].gas_gain_correction= -999.;
  }

  FILE *fin = fopen(filename.data(),"r");

  int linecounter = 0;  // set the line counter to the first serial number in the file....

  while (!feof(fin)){
    //note space at end of format string to convert last \n
    int check = fscanf(fin,"%d %d %d %d %d %d %d %d %d %f %f %f \n",
                       &gains[linecounter].gas_gain_index     ,
                       &gains[linecounter].endcap             ,
                       &gains[linecounter].station            ,
                       &gains[linecounter].ring               ,
                       &gains[linecounter].chamber            ,
                       &gains[linecounter].layer              ,
                       &gains[linecounter].hvsegment          ,
                       &gains[linecounter].cfeb               ,
                       &gains[linecounter].nentries           ,
                       &gains[linecounter].mean               ,
                       &gains[linecounter].truncated_mean     ,
                       &gains[linecounter].gas_gain_correction);

    if (check != 12){
      printf("The input file format is not as expected\n");
      assert(0);
    }

    linecounter++;

  }

  fclose(fin);      

  if (linecounter == MAX_SIZE) {
    std::cout << "Total number of gas gains read in = " << linecounter << std::endl;
  } else {
    std::cout << "ERROR:  Total number of gas-gains read in = " << linecounter 
              << " while total number expected = " << MAX_SIZE << std::endl;
  }

  // Fill the chip corrections with values from the file
  for (int i=0;i<MAX_SIZE;i++){

    itemvector[i].gainCorr = 0.;

    if (gains[i].gas_gain_correction > 0.) {
      itemvector[i].gainCorr = gains[i].gas_gain_correction;
    } else {
      // if there is no value, this should be fixed...
      std::cout << "ERROR:  gas_gain_correction < 0 for index " << gains[i].gas_gain_index << std::endl;
    }
  }
 
  return cndbGasGainCorr;
}
CSCGasGainCorrectionDBConditions::ReturnType CSCGasGainCorrectionDBConditions::produceDBGasGainCorrection ( const CSCDBGasGainCorrectionRcd iRecord)

Definition at line 40 of file CSCGasGainCorrectionDBConditions.cc.

References cndbGasGainCorr.

Referenced by CSCGasGainCorrectionDBConditions().

{
  //need a new object so to not be deleted at exit
  CSCDBGasGainCorrection* mydata=new CSCDBGasGainCorrection( *cndbGasGainCorr );
  return mydata;
  
}
void CSCGasGainCorrectionDBConditions::setIntervalFor ( const edm::eventsetup::EventSetupRecordKey ,
const edm::IOVSyncValue ,
edm::ValidityInterval oValidity 
) [private, virtual]

Member Data Documentation

Definition at line 40 of file CSCGasGainCorrectionDBConditions.h.

Referenced by CSCGasGainCorrectionDBConditions().

Definition at line 38 of file CSCGasGainCorrectionDBConditions.h.

Referenced by CSCGasGainCorrectionDBConditions().