CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
SiStripApvGainBuilderFromTag Class Reference

#include <SiStripApvGainBuilderFromTag.h>

Inheritance diagram for SiStripApvGainBuilderFromTag:
edm::EDAnalyzer edm::EDConsumerBase

Public Member Functions

void analyze (const edm::Event &, const edm::EventSetup &) override
 
 SiStripApvGainBuilderFromTag (const edm::ParameterSet &iConfig)
 
 ~SiStripApvGainBuilderFromTag () override
 
- Public Member Functions inherited from edm::EDAnalyzer
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzer ()
 
SerialTaskQueueglobalLuminosityBlocksQueue ()
 
SerialTaskQueueglobalRunsQueue ()
 
ModuleDescription const & moduleDescription () const
 
std::string workerType () const
 
 ~EDAnalyzer () override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ESProxyIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProxyIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Member Functions

void fillParameters (std::map< int, std::vector< double > > &mapToFill, const std::string &parameterName) const
 Fills the parameters read from cfg and matching the name in the given map. More...
 
void fillSubDetParameter (std::map< int, std::vector< double > > &mapToFill, const std::vector< double > &v, const int subDet, const unsigned short layers) const
 

Private Attributes

bool printdebug_
 
edm::ParameterSet pset_
 

Additional Inherited Members

- Public Types inherited from edm::EDAnalyzer
typedef EDAnalyzer ModuleType
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::EDAnalyzer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &)
 
static bool wantsGlobalLuminosityBlocks ()
 
static bool wantsGlobalRuns ()
 
static bool wantsStreamLuminosityBlocks ()
 
static bool wantsStreamRuns ()
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Produces a tag for the apvGain object starting from an already existing tag in the db.
The input tag is used as starting point and all the values for missing apvs are filled with the meanGain specified via cfg.
It will optionally apply a correction specified via cfg if the applyTuning bool is true.
The resulting new gain values can optionally be smeared with a gaussian of sigma specified in the cfg.
Note: we are not using the usual DummyCondDBWriter because we cannot pass an input tag to a service without several changes to the base classes used together with it.

Definition at line 31 of file SiStripApvGainBuilderFromTag.h.

Constructor & Destructor Documentation

SiStripApvGainBuilderFromTag::SiStripApvGainBuilderFromTag ( const edm::ParameterSet iConfig)
explicit

Definition at line 14 of file SiStripApvGainBuilderFromTag.cc.

14  :
15  printdebug_(iConfig.getUntrackedParameter<uint32_t>("printDebug",1)),
16  pset_(iConfig)
17 {}
T getUntrackedParameter(std::string const &, T const &) const
SiStripApvGainBuilderFromTag::~SiStripApvGainBuilderFromTag ( )
inlineoverride

Member Function Documentation

void SiStripApvGainBuilderFromTag::analyze ( const edm::Event evt,
const edm::EventSetup iSetup 
)
override

Definition at line 19 of file SiStripApvGainBuilderFromTag.cc.

References cond::service::PoolDBOutputService::appendSinceTime(), cond::service::PoolDBOutputService::beginOfTime(), KineDebug3::count(), cond::service::PoolDBOutputService::createNewIOV(), cond::service::PoolDBOutputService::currentTime(), SoftLeptonByDistance_cfi::distance, cond::service::PoolDBOutputService::endOfTime(), cmsRelvalreport::exit, spr::find(), edm::EventSetup::get(), SiStripDetInfoFileReader::getAllData(), SiStripApvGain::getApvGain(), SiStripApvGain::getDetIds(), SiStripFakeAPVParameters::getIndex(), edm::ParameterSet::getParameter(), SiStripApvGain::getRange(), edm::ParameterSet::getUntrackedParameter(), estimatePileup::inputRange, edm::Service< T >::isAvailable(), cond::service::PoolDBOutputService::isNewTagRequest(), LogDebug, haddnano::obj, printdebug_, edm::ESHandle< T >::product(), pset_, SiStripApvGain::put(), matplotRender::reader, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by ~SiStripApvGainBuilderFromTag().

20 {
21  //Retrieve tracker topology from geometry
23  iSetup.get<IdealGeometryRecord>().get(tTopoHandle);
24  const TrackerTopology* const tTopo = tTopoHandle.product();
25 
26  // unsigned int run=evt.id().run();
27 
28  std::string genMode = pset_.getParameter<std::string>("genMode");
29  bool applyTuning = pset_.getParameter<bool>("applyTuning");
30 
31  double meanGain_=pset_.getParameter<double>("MeanGain");
32  double sigmaGain_=pset_.getParameter<double>("SigmaGain");
33  double minimumPosValue_=pset_.getParameter<double>("MinPositiveGain");
34 
35  uint32_t printdebug_ = pset_.getUntrackedParameter<uint32_t>("printDebug", 5);
36 
37  //parameters for layer/disk level correction; not used if applyTuning=false
38  SiStripFakeAPVParameters correct{pset_, "correct"};
39 
40  // Read the gain from the given tag
41  edm::ESHandle<SiStripApvGain> inputApvGain;
42  iSetup.get<SiStripApvGainRcd>().get( inputApvGain );
43  std::vector<uint32_t> inputDetIds;
44  inputApvGain->getDetIds(inputDetIds);
45 
46  // Prepare the new object
48 
50  uint32_t count = 0;
51  const std::map<uint32_t, SiStripDetInfoFileReader::DetInfo >& DetInfos = reader->getAllData();
52  for(std::map<uint32_t, SiStripDetInfoFileReader::DetInfo >::const_iterator it = DetInfos.begin(); it != DetInfos.end(); it++) {
53 
54  // Find if this DetId is in the input tag and if so how many are the Apvs for which it contains information
56  size_t inputRangeSize = 0;
57  if( find( inputDetIds.begin(), inputDetIds.end(), it->first ) != inputDetIds.end() ) {
58  inputRange = inputApvGain->getRange(it->first);
59  inputRangeSize = distance(inputRange.first, inputRange.second);
60  }
61 
62  std::vector<float> theSiStripVector;
63  for(unsigned short j=0; j<it->second.nApvs; j++){
64 
65  double gainValue = meanGain_;
66 
67  if( j < inputRangeSize ) {
68  gainValue = inputApvGain->getApvGain(j, inputRange);
69  // cout << "Gain = " << gainValue <<" from input tag for DetId = " << it->first << " and apv = " << j << endl;
70  }
71  // else {
72  // cout << "No gain in input tag for DetId = " << it->first << " and apv = " << j << " using value from cfg = " << gainValue << endl;
73  // }
74 
75 
76  // corrections at layer/disk level:
77  uint32_t detId = it->first;
79  //unsigned short nApvs = it->second.nApvs;
80  if (applyTuning) {
81  double correction = correct.get(sl);
82  gainValue *= correction;
83  }
84 
85  // smearing:
86  if (genMode == "gaussian") {
87  gainValue = CLHEP::RandGauss::shoot(gainValue, sigmaGain_);
88  if(gainValue<=minimumPosValue_) gainValue=minimumPosValue_;
89  }
90  else if( genMode != "default" ) {
91  LogDebug("SiStripApvGain") << "ERROR: wrong genMode specifier : " << genMode << ", please select one of \"default\" or \"gaussian\"" << std::endl;
92  exit(1);
93  }
94 
95  if (count<printdebug_) {
96  edm::LogInfo("SiStripApvGainGeneratorFromTag") << "detid: " << it->first << " Apv: " << j << " gain: " << gainValue << std::endl;
97  }
98  theSiStripVector.push_back(gainValue);
99  }
100  count++;
101  SiStripApvGain::Range range(theSiStripVector.begin(),theSiStripVector.end());
102  if ( ! obj->put(it->first,range) )
103  edm::LogError("SiStripApvGainGeneratorFromTag")<<" detid already exists"<<std::endl;
104  }
105 
106  //End now write data in DB
108 
109  if( mydbservice.isAvailable() ){
110  if( mydbservice->isNewTagRequest("SiStripApvGainRcd2") ){
111  mydbservice->createNewIOV<SiStripApvGain>(obj,mydbservice->beginOfTime(),mydbservice->endOfTime(),"SiStripApvGainRcd2");
112  }
113  else {
114  mydbservice->appendSinceTime<SiStripApvGain>(obj,mydbservice->currentTime(),"SiStripApvGainRcd2");
115  }
116  }
117  else {
118  edm::LogError("SiStripApvGainBuilderFromTag")<<"Service is unavailable"<<std::endl;
119  }
120 }
#define LogDebug(id)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
static float getApvGain(uint16_t apv, const Range &range)
static index getIndex(const TrackerTopology *tTopo, DetId id)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
void getDetIds(std::vector< uint32_t > &DetIds_) const
bool put(const uint32_t &detID, Range input)
const std::map< uint32_t, DetInfo > & getAllData() const
void appendSinceTime(T *payloadObj, cond::Time_t sinceTime, const std::string &recordName, bool withlogging=false)
bool isNewTagRequest(const std::string &recordName)
bool isAvailable() const
Definition: Service.h:40
std::pair< ContainerIterator, ContainerIterator > Range
void createNewIOV(T *firstPayloadObj, cond::Time_t firstSinceTime, cond::Time_t firstTillTime, const std::string &recordName, bool withlogging=false)
inputRange
Get input source.
T get() const
Definition: EventSetup.h:71
const Range getRange(const uint32_t detID) const
T const * product() const
Definition: ESHandle.h:86
void SiStripApvGainBuilderFromTag::fillParameters ( std::map< int, std::vector< double > > &  mapToFill,
const std::string &  parameterName 
) const
private

Fills the parameters read from cfg and matching the name in the given map.

Referenced by ~SiStripApvGainBuilderFromTag().

void SiStripApvGainBuilderFromTag::fillSubDetParameter ( std::map< int, std::vector< double > > &  mapToFill,
const std::vector< double > &  v,
const int  subDet,
const unsigned short  layers 
) const
private

Fills the map with the paramters for the given subdetector.
Each vector "v" holds the parameters for the layers/rings, if the vector has only one parameter all the layers/rings get that parameter.
The only other possibility is that the number of parameters equals the number of layers, otherwise an exception of type "Configuration" will be thrown.

Referenced by ~SiStripApvGainBuilderFromTag().

Member Data Documentation

bool SiStripApvGainBuilderFromTag::printdebug_
private

Definition at line 53 of file SiStripApvGainBuilderFromTag.h.

Referenced by analyze().

edm::ParameterSet SiStripApvGainBuilderFromTag::pset_
private

Definition at line 54 of file SiStripApvGainBuilderFromTag.h.

Referenced by analyze().