64 void setSmearing(
bool doScale,
bool doSmear,
double the_scaleFactor,
double the_smearFactor){
89 std::unique_ptr<SiStripApvGain> getNewObject(
const std::map<std::pair<uint32_t,int>,
float>& theMap);
91 std::vector<sistripsummary::TrackerRegion> getRegionsFromDetId(
const TrackerTopology* tTopo,
DetId detid);
92 virtual void endJob()
override;
105 m_gainType{iConfig.getUntrackedParameter<uint32_t>(
"gainType",1)},
106 m_parameters{iConfig.getParameter<std::vector<edm::ParameterSet> >(
"params")}
129 const auto*
const tTopo = tTopoHandle.
product();
137 if(
std::find(partitions.begin(), partitions.end(), partition) == partitions.end()) {
138 partitions.push_back(partition);
142 std::map<sistripsummary::TrackerRegion,ApvGain::GainSmearings> mapOfSmearings;
144 for(
auto& thePSet : m_parameters){
149 bool m_doScale(thePSet.getParameter<
bool>(
"doScale"));
150 bool m_doSmear(thePSet.getParameter<
bool>(
"doSmear"));
151 double m_scaleFactor(thePSet.getParameter<
double>(
"scaleFactor"));
152 double m_smearFactor(thePSet.getParameter<
double>(
"smearFactor"));
155 params.
setSmearing(m_doScale,m_doSmear,m_scaleFactor,m_smearFactor);
156 mapOfSmearings[region]=params;
163 std::map<std::pair<uint32_t,int>,
float> theMap;
164 std::shared_ptr<TRandom3>
random(
new TRandom3(1));
166 std::vector<uint32_t> detid;
168 for (
const auto &
d : detid) {
179 for (
unsigned int j=0; j<
regions.size();j++){
180 bool checkRegion = (mapOfSmearings.count(
regions[j]) != 0);
187 params = mapOfSmearings[
regions[j]];
192 for(
int it=0;it<range.second-range.first;it++){
195 std::pair<uint32_t,int>
index = std::make_pair(
d,nAPV);
197 if(params.m_doScale){
198 Gain*=params.m_scaleFactor;
201 if(params.m_doSmear){
202 float smearedGain = random->Gaus(Gain,params.m_smearFactor);
211 std::unique_ptr<SiStripApvGain> theAPVGains = this->
getNewObject(theMap);
219 throw std::runtime_error(
"PoolDBService required.");
237 std::unique_ptr<SiStripApvGain>
240 std::unique_ptr<SiStripApvGain>
obj = std::unique_ptr<SiStripApvGain>(
new SiStripApvGain());
242 std::vector<float> theSiStripVector;
243 uint32_t PreviousDetId = 0;
244 for(
const auto &element : theMap){
245 uint32_t
DetId = element.first.first;
246 if(DetId != PreviousDetId){
247 if(!theSiStripVector.empty()){
249 if ( !obj->put(PreviousDetId,range) ) printf(
"Bug to put detId = %i\n",PreviousDetId);
251 theSiStripVector.clear();
252 PreviousDetId = DetId;
254 theSiStripVector.push_back(element.second);
256 edm::LogInfo(
"SiStripChannelGainFromDBMiscalibrator")<<
" DetId: "<<DetId
257 <<
" APV: "<<element.first.second
258 <<
" Gain: "<<element.second
262 if(!theSiStripVector.empty()){
264 if ( !obj->put(PreviousDetId,range) ) printf(
"Bug to put detId = %i\n",PreviousDetId);
276 desc.
setComment(
"Creates rescaled / smeared SiStrip Gain payload. Can be used for both G1 and G2." 277 "PoolDBOutputService must be set up for 'SiStripApvGainRcd'.");
280 descScaler.
setComment(
"ParameterSet specifying the Strip tracker partition to be scaled / smeared " 281 "by a given factor.");
284 descScaler.
add<
bool>(
"doScale",
true);
285 descScaler.
add<
bool>(
"doSmear",
true);
286 descScaler.
add<
double>(
"scaleFactor", 1.0);
287 descScaler.
add<
double>(
"smearFactor", 1.0);
288 desc.
addVPSet(
"params", descScaler, std::vector<edm::ParameterSet>(1));
293 descriptions.
add(
"scaleAndSmearSiStripGains", desc);
301 if(region.find(
"Tracker")!=std::string::npos){
303 }
else if(region.find(
"TIB")!=std::string::npos){
309 }
else if(region.find(
"TOB")!=std::string::npos){
317 }
else if(region.find(
"TID")!=std::string::npos){
318 if(region.find(
"TIDM")!=std::string::npos){
323 }
else if(region.find(
"TIDP")!=std::string::npos){
329 }
else if(region.find(
"TEC")!=std::string::npos) {
330 if(region.find(
"TECM")!=std::string::npos){
341 }
else if(region.find(
"TECP")!=std::string::npos){
354 edm::LogError(
"LogicError") <<
"Unknown partition: " << region;
368 std::vector<sistripsummary::TrackerRegion> ret;
372 layer = m_trackerTopo->
tibLayer(detid);
376 layer = m_trackerTopo->
tobLayer(detid);
381 layer = m_trackerTopo->
tidWheel(detid);
382 side = m_trackerTopo->
tidSide(detid);
387 layer = m_trackerTopo->
tecWheel(detid);
388 side = m_trackerTopo->
tecSide(detid);
393 detCode = (subdet*10)+layer;
395 ret.push_back(static_cast<sistripsummary::TrackerRegion>(detCode));
398 ret.push_back(static_cast<sistripsummary::TrackerRegion>(subdet/10));
401 ret.push_back(static_cast<sistripsummary::TrackerRegion>(subdet));
T getUntrackedParameter(std::string const &, T const &) const
ParameterDescriptionBase * addVPSet(U const &iLabel, ParameterSetDescription const &validator, std::vector< ParameterSet > const &defaults)
unsigned int tibLayer(const DetId &id) const
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
virtual example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
#define DEFINE_FWK_MODULE(type)
unsigned int tidWheel(const DetId &id) const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
SiStripChannelGainFromDBMiscalibrator(const edm::ParameterSet &)
const uint32_t m_gainType
static float getApvGain(const uint16_t &apv, const SiStripApvGain::Range &range)
void setComment(std::string const &value)
unsigned int tidSide(const DetId &id) const
void setSmearing(bool doScale, bool doSmear, double the_scaleFactor, double the_smearFactor)
std::vector< sistripsummary::TrackerRegion > getRegionsFromDetId(const TrackerTopology *tTopo, DetId detid)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::pair< ContainerIterator, ContainerIterator > Range
void writeOne(T *payload, Time_t time, const std::string &recordName, bool withlogging=false)
~SiStripChannelGainFromDBMiscalibrator()
ParameterDescriptionBase * add(U const &iLabel, T const &value)
int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
void getDetIds(std::vector< uint32_t > &DetIds_) const
ATTENTION: we assume the detIds are the same as those from the first gain.
virtual void analyze(const edm::Event &, const edm::EventSetup &) override
std::unique_ptr< SiStripApvGain > getNewObject(const std::map< std::pair< uint32_t, int >, float > &theMap)
virtual void beginJob() override
virtual void endJob() override
void add(std::string const &label, ParameterSetDescription const &psetDescription)
const std::vector< edm::ParameterSet > m_parameters
cond::Time_t currentTime() const
sistripsummary::TrackerRegion getRegionFromString(std::string region)
unsigned int tecWheel(const DetId &id) const
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
T const * product() const
const std::string m_Record
unsigned int tobLayer(const DetId &id) const
unsigned int tecSide(const DetId &id) const
const SiStripApvGain::Range getRange(uint32_t detID) const