CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/CalibTracker/SiStripESProducers/src/SiStripLorentzAngleGenerator.cc

Go to the documentation of this file.
00001 #include "CalibTracker/SiStripESProducers/interface/SiStripLorentzAngleGenerator.h"
00002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00003 #include <boost/cstdint.hpp>
00004 #include "CalibTracker/SiStripCommon/interface/SiStripDetInfoFileReader.h"
00005 #include "FWCore/ParameterSet/interface/FileInPath.h"
00006 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
00007 #include "DataFormats/SiStripDetId/interface/TECDetId.h"
00008 #include "CLHEP/Random/RandGauss.h"
00009 #include "CLHEP/Random/RandFlat.h"
00010 
00011 #include<cmath>
00012 #include<algorithm>
00013 #include<numeric>
00014 
00015 // Defined inside a nameless namespace so that it is local to this file
00016 namespace {
00017   double computeSigma(const double & value, const double & perCentError) {
00018     return (perCentError/100)*value;
00019   }
00020 }
00021 
00022 SiStripLorentzAngleGenerator::SiStripLorentzAngleGenerator(const edm::ParameterSet& iConfig,const edm::ActivityRegistry& aReg):
00023   SiStripCondObjBuilderBase<SiStripLorentzAngle>::SiStripCondObjBuilderBase(iConfig)
00024 {
00025   edm::LogInfo("SiStripLorentzAngleGenerator") <<  "[SiStripLorentzAngleGenerator::SiStripLorentzAngleGenerator]";
00026 }
00027 
00028 
00029 SiStripLorentzAngleGenerator::~SiStripLorentzAngleGenerator() { 
00030   edm::LogInfo("SiStripLorentzAngleGenerator") <<  "[SiStripLorentzAngleGenerator::~SiStripLorentzAngleGenerator]";
00031 }
00032 
00033 void SiStripLorentzAngleGenerator::setHallMobility(const double & meanMin, const double & meanMax, const double & sigma, const bool uniform) {
00034   if( uniform ) hallMobility_ = CLHEP::RandFlat::shoot(meanMin, meanMax);
00035   else if( sigma>0 ) hallMobility_ = CLHEP::RandGauss::shoot(meanMin, sigma);
00036   else hallMobility_ = meanMin;
00037 }
00038 
00039 void SiStripLorentzAngleGenerator::setUniform(const std::vector<double> & estimatedValuesMin, const std::vector<double> & estimatedValuesMax, std::vector<bool> & uniform) {
00040   if( estimatedValuesMax.size() != 0 ) {
00041     std::vector<double>::const_iterator min = estimatedValuesMin.begin();
00042     std:: vector<double>::const_iterator max = estimatedValuesMax.begin();
00043     std::vector<bool>::iterator uniformIt = uniform.begin();
00044     for( ; min != estimatedValuesMin.end(); ++min, ++max, ++uniformIt ) {
00045       if( *min != *max ) *uniformIt = true;
00046     }
00047   }
00048 }
00049 
00050 void SiStripLorentzAngleGenerator::createObject()
00051 {
00052   obj_ = new SiStripLorentzAngle();
00053 
00054   edm::FileInPath fp_                 = _pset.getParameter<edm::FileInPath>("file");
00055 
00056   std::vector<double> TIB_EstimatedValuesMin(_pset.getParameter<std::vector<double> >("TIB_EstimatedValuesMin"));
00057   std::vector<double> TIB_EstimatedValuesMax(_pset.getParameter<std::vector<double> >("TIB_EstimatedValuesMax"));
00058   std::vector<double> TOB_EstimatedValuesMin(_pset.getParameter<std::vector<double> >("TOB_EstimatedValuesMin"));
00059   std::vector<double> TOB_EstimatedValuesMax(_pset.getParameter<std::vector<double> >("TOB_EstimatedValuesMax"));
00060   std::vector<double> TIB_PerCent_Errs(_pset.getParameter<std::vector<double> >("TIB_PerCent_Errs"));
00061   std::vector<double> TOB_PerCent_Errs(_pset.getParameter<std::vector<double> >("TOB_PerCent_Errs"));
00062 
00063   // If max values are passed they must be equal in number to the min values.
00064   if( (TIB_EstimatedValuesMax.size() != 0 && (TIB_EstimatedValuesMin.size() != TIB_EstimatedValuesMax.size())) ||
00065       (TOB_EstimatedValuesMax.size() != 0 && (TOB_EstimatedValuesMin.size() != TOB_EstimatedValuesMax.size())) ) {
00066     std::cout << "ERROR: size of min and max values is different" << std::endl;
00067     std::cout << "TIB_EstimatedValuesMin.size() = " << TIB_EstimatedValuesMin.size() << ", TIB_EstimatedValuesMax.size() " << TIB_EstimatedValuesMax.size() << std::endl;
00068     std::cout << "TOB_EstimatedValuesMin.size() = " << TOB_EstimatedValuesMin.size() << ", TOB_EstimatedValuesMax.size() " << TOB_EstimatedValuesMax.size() << std::endl;
00069   }
00070   std::vector<bool> uniformTIB(TIB_EstimatedValuesMin.size(), false);
00071   std::vector<bool> uniformTOB(TOB_EstimatedValuesMin.size(), false);
00072 
00073   setUniform(TIB_EstimatedValuesMin, TIB_EstimatedValuesMax, uniformTIB);
00074   setUniform(TOB_EstimatedValuesMin, TOB_EstimatedValuesMax, uniformTOB);
00075   
00076   SiStripDetInfoFileReader reader(fp_.fullPath());
00077 
00078   // Compute standard deviations
00079   std::vector<double> StdDevs_TIB(TIB_EstimatedValuesMin.size(), 0);
00080   std::vector<double> StdDevs_TOB(TOB_EstimatedValuesMin.size(), 0);
00081   transform(TIB_EstimatedValuesMin.begin(), TIB_EstimatedValuesMin.end(), TIB_PerCent_Errs.begin(), StdDevs_TIB.begin(), computeSigma);
00082   transform(TOB_EstimatedValuesMin.begin(), TOB_EstimatedValuesMin.end(), TOB_PerCent_Errs.begin(), StdDevs_TOB.begin(), computeSigma);
00083 
00084   // Compute mean values to be used with TID and TEC
00085   double TIBmeanValueMin = std::accumulate( TIB_EstimatedValuesMin.begin(), TIB_EstimatedValuesMin.end(), 0.)/double(TIB_EstimatedValuesMin.size());
00086   double TIBmeanValueMax = std::accumulate( TIB_EstimatedValuesMax.begin(), TIB_EstimatedValuesMax.end(), 0.)/double(TIB_EstimatedValuesMax.size());
00087   double TOBmeanValueMin = std::accumulate( TOB_EstimatedValuesMin.begin(), TOB_EstimatedValuesMin.end(), 0.)/double(TOB_EstimatedValuesMin.size());
00088   double TOBmeanValueMax = std::accumulate( TOB_EstimatedValuesMax.begin(), TOB_EstimatedValuesMax.end(), 0.)/double(TOB_EstimatedValuesMax.size());
00089   double TIBmeanPerCentError = std::accumulate( TIB_PerCent_Errs.begin(), TIB_PerCent_Errs.end(), 0.)/double(TIB_PerCent_Errs.size());
00090   double TOBmeanPerCentError = std::accumulate( TOB_PerCent_Errs.begin(), TOB_PerCent_Errs.end(), 0.)/double(TOB_PerCent_Errs.size());
00091   double TIBmeanStdDev = (TIBmeanPerCentError/100)*TIBmeanValueMin;
00092   double TOBmeanStdDev = (TOBmeanPerCentError/100)*TOBmeanValueMin;
00093 
00094   const std::vector<uint32_t> DetIds = reader.getAllDetIds();
00095   for(std::vector<uint32_t>::const_iterator detit=DetIds.begin(); detit!=DetIds.end(); detit++){
00096     
00097     hallMobility_ = 0;
00098 
00099     StripSubdetector subid(*detit);
00100 
00101     int layerId = 0;
00102 
00103     if(subid.subdetId() == int (StripSubdetector::TIB)) {
00104       TIBDetId theTIBDetId(*detit);
00105       layerId = theTIBDetId.layer() - 1;
00106       setHallMobility( TIB_EstimatedValuesMin[layerId], TIB_EstimatedValuesMax[layerId], StdDevs_TIB[layerId], uniformTIB[layerId] );
00107     }
00108     else if(subid.subdetId() == int (StripSubdetector::TOB)) {
00109       TOBDetId theTOBDetId(*detit);
00110       layerId = theTOBDetId.layer() - 1;
00111       setHallMobility( TOB_EstimatedValuesMin[layerId], TOB_EstimatedValuesMax[layerId], StdDevs_TOB[layerId], uniformTOB[layerId] );
00112     }
00113     else if(subid.subdetId() == int (StripSubdetector::TID)) {
00114       // ATTENTION: as of now the uniform generation for TID is decided by the setting for layer 0 of TIB
00115       setHallMobility( TIBmeanValueMin, TIBmeanValueMax, TIBmeanStdDev, uniformTIB[0] );
00116     }
00117     if(subid.subdetId() == int (StripSubdetector::TEC)){
00118       TECDetId TECid = TECDetId(*detit); 
00119       if(TECid.ringNumber()<5){
00120         // ATTENTION: as of now the uniform generation for TEC is decided by the setting for layer 0 of TIB
00121         setHallMobility( TIBmeanValueMin, TIBmeanValueMax, TIBmeanStdDev, uniformTIB[0] );
00122       }else{
00123         // ATTENTION: as of now the uniform generation for TEC is decided by the setting for layer 0 of TOB
00124         setHallMobility( TOBmeanValueMin, TOBmeanValueMax, TOBmeanStdDev, uniformTOB[0] );
00125       }
00126     }
00127       
00128     if ( ! obj_->putLorentzAngle(*detit, hallMobility_) ) {
00129       edm::LogError("SiStripLorentzAngleGenerator")<<" detid already exists"<<std::endl;
00130     }
00131   }
00132 }