CMS 3D CMS Logo

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

calculate the best DAC value to obtain a pedestal = 200 More...

#include <EcalPedOffset.h>

Inheritance diagram for EcalPedOffset:
edm::EDAnalyzer edm::EDConsumerBase

Public Member Functions

void analyze (edm::Event const &event, edm::EventSetup const &eventSetup) override
 ! Analyze More...
 
void beginRun (edm::Run const &, edm::EventSetup const &eventSetup) override
 BeginRun. More...
 
 EcalPedOffset (const edm::ParameterSet &ps)
 Constructor. More...
 
void endJob (void) override
 EndJob. More...
 
void makePlots ()
 create the plots of the DAC pedestal trend More...
 
void writeDb ()
 WriteDB. More...
 
void writeXMLFiles (std::string fileName)
 write the results into xml format More...
 
 ~EcalPedOffset () override
 Destructor. More...
 
- 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

std::string intToString (int num)
 
void readDACs (const edm::Handle< EBDigiCollection > &pDigis, const std::map< int, int > &DACvalues)
 
void readDACs (const edm::Handle< EEDigiCollection > &pDigis, const std::map< int, int > &DACvalues)
 

Private Attributes

const EcalElectronicsMappingecalElectronicsMap_
 
edm::InputTag m_barrelDigiCollection
 secondary name given to collection of digis More...
 
int m_bestPed
 
bool m_create_moniov
 
int m_DACmax
 
int m_DACmin
 
std::string m_dbHostName
 database host name More...
 
int m_dbHostPort
 database More...
 
std::string m_dbName
 database name More...
 
std::string m_dbPassword
 database user password More...
 
std::string m_dbUserName
 database user name More...
 
edm::InputTag m_endcapDigiCollection
 secondary name given to collection of digis More...
 
edm::InputTag m_headerCollection
 name of module/plugin/producer making headers More...
 
std::string m_location
 
double m_maxChi2OverNDFAllowed_
 max chi2/ndf allowed for linearity test More...
 
double m_maxSlopeAllowed_
 max slope (in magnitude) allowed for linearity test More...
 
double m_minSlopeAllowed_
 min slope (in magnitude) allowed for linearity test More...
 
std::map< int, TPedResult * > m_pedResult
 
std::map< int, TPedValues * > m_pedValues
 
std::string m_plotting
 the root file where to store the detail plots More...
 
double m_RMSmax
 
int m_run
 run number More...
 
std::string m_xmlFile
 name of the xml file to be saved More...
 

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

calculate the best DAC value to obtain a pedestal = 200

Author
P. Govoni (pietr.nosp@m.o.go.nosp@m.voni@.nosp@m.cern.nosp@m.NOSPA.nosp@m.M.ch)

Definition at line 28 of file EcalPedOffset.h.

Constructor & Destructor Documentation

EcalPedOffset::EcalPedOffset ( const edm::ParameterSet ps)

Constructor.

ctor

Definition at line 38 of file EcalPedOffset.cc.

References m_bestPed, m_DACmax, m_DACmin, and m_RMSmax.

39  : m_barrelDigiCollection(paramSet.getParameter<edm::InputTag>("EBdigiCollection")),
40  m_endcapDigiCollection(paramSet.getParameter<edm::InputTag>("EEdigiCollection")),
41  m_headerCollection(paramSet.getParameter<edm::InputTag>("headerCollection")),
42  m_xmlFile(paramSet.getParameter<std::string>("xmlFile")),
43  m_DACmin(paramSet.getUntrackedParameter<int>("DACmin", 0)),
44  m_DACmax(paramSet.getUntrackedParameter<int>("DACmax", 256)),
45  m_RMSmax(paramSet.getUntrackedParameter<double>("RMSmax", 2)),
46  m_bestPed(paramSet.getUntrackedParameter<int>("bestPed", 200)),
47  m_dbHostName(paramSet.getUntrackedParameter<std::string>("dbHostName", "0")),
48  m_dbName(paramSet.getUntrackedParameter<std::string>("dbName", "0")),
49  m_dbUserName(paramSet.getUntrackedParameter<std::string>("dbUserName")),
50  m_dbPassword(paramSet.getUntrackedParameter<std::string>("dbPassword")),
51  m_dbHostPort(paramSet.getUntrackedParameter<int>("dbHostPort", 1521)),
52  m_create_moniov(paramSet.getUntrackedParameter<bool>("createMonIOV", false)),
53  m_location(paramSet.getUntrackedParameter<std::string>("location", "H4")),
54  m_run(-1),
55  m_plotting(paramSet.getParameter<std::string>("plotting")),
56  m_maxSlopeAllowed_(paramSet.getUntrackedParameter<double>("maxSlopeAllowed", -29)),
57  m_minSlopeAllowed_(paramSet.getUntrackedParameter<double>("minSlopeAllowed", -18)),
58  m_maxChi2OverNDFAllowed_(paramSet.getUntrackedParameter<double>("maxChi2OverNDF", 5)) {
59  edm::LogInfo("EcalPedOffset") << " reading "
60  << " m_DACmin: " << m_DACmin << " m_DACmax: " << m_DACmax << " m_RMSmax: " << m_RMSmax
61  << " m_bestPed: " << m_bestPed;
62 }
double m_maxChi2OverNDFAllowed_
max chi2/ndf allowed for linearity test
edm::InputTag m_barrelDigiCollection
secondary name given to collection of digis
Definition: EcalPedOffset.h:61
std::string m_dbHostName
database host name
Definition: EcalPedOffset.h:76
std::string m_dbName
database name
Definition: EcalPedOffset.h:78
std::string m_xmlFile
name of the xml file to be saved
Definition: EcalPedOffset.h:65
double m_minSlopeAllowed_
min slope (in magnitude) allowed for linearity test
Definition: EcalPedOffset.h:98
std::string m_dbPassword
database user password
Definition: EcalPedOffset.h:82
std::string m_plotting
the root file where to store the detail plots
Definition: EcalPedOffset.h:94
int m_dbHostPort
database
Definition: EcalPedOffset.h:84
std::string m_dbUserName
database user name
Definition: EcalPedOffset.h:80
bool m_create_moniov
Definition: EcalPedOffset.h:87
edm::InputTag m_headerCollection
name of module/plugin/producer making headers
Definition: EcalPedOffset.h:63
int m_run
run number
Definition: EcalPedOffset.h:91
std::string m_location
Definition: EcalPedOffset.h:89
double m_maxSlopeAllowed_
max slope (in magnitude) allowed for linearity test
Definition: EcalPedOffset.h:96
edm::InputTag m_endcapDigiCollection
secondary name given to collection of digis
Definition: EcalPedOffset.h:62
EcalPedOffset::~EcalPedOffset ( )
override

Destructor.

dtor

Definition at line 67 of file EcalPedOffset.cc.

References m_pedResult, and m_pedValues.

67  {
68  for (std::map<int, TPedValues *>::iterator mapIt = m_pedValues.begin(); mapIt != m_pedValues.end(); ++mapIt)
69  delete mapIt->second;
70  for (std::map<int, TPedResult *>::iterator mapIt = m_pedResult.begin(); mapIt != m_pedResult.end(); ++mapIt)
71  delete mapIt->second;
72 }
std::map< int, TPedResult * > m_pedResult
Definition: EcalPedOffset.h:68
std::map< int, TPedValues * > m_pedValues
Definition: EcalPedOffset.h:67

Member Function Documentation

void EcalPedOffset::analyze ( edm::Event const &  event,
edm::EventSetup const &  eventSetup 
)
overridevirtual

! Analyze

perform the analysis

Implements edm::EDAnalyzer.

Definition at line 88 of file EcalPedOffset.cc.

References ftlUncalibratedRecHits_cfi::barrelDigis, edm::SortedCollection< T, SORT >::begin(), edm::DataFrameContainer::empty(), edm::SortedCollection< T, SORT >::end(), ftlUncalibratedRecHits_cfi::endcapDigis, edm::HandleBase::isValid(), LogDebug, m_barrelDigiCollection, m_endcapDigiCollection, m_headerCollection, m_run, EcalDCCHeaderBlock::EcalDCCEventSettings::ped_offset, and readDACs().

88  {
89  LogDebug("EcalPedOffset") << "entering analyze ...";
90 
91  // get the headers
92  // (one header for each supermodule)
94  event.getByLabel(m_headerCollection, DCCHeaders);
95 
96  std::map<int, int> DACvalues;
97 
98  if (m_run == -1)
99  m_run = event.id().run();
100 
101  // loop over the headers
102  for (EcalRawDataCollection::const_iterator headerItr = DCCHeaders->begin(); headerItr != DCCHeaders->end();
103  ++headerItr) {
104  EcalDCCHeaderBlock::EcalDCCEventSettings settings = headerItr->getEventSettings();
105  int FEDid = 600 + headerItr->id();
106  DACvalues[FEDid] = settings.ped_offset;
107  LogDebug("EcalPedOffset") << "Found FED: " << FEDid << " in DCC header";
108  }
109 
110  bool barrelDigisFound = true;
111  bool endcapDigisFound = true;
112  // get the barrel digis
113  // (one digi for each crystal)
115  event.getByLabel(m_barrelDigiCollection, barrelDigis);
116  if (!barrelDigis.isValid()) {
117  edm::LogError("EcalPedOffset") << "Error! can't get the product " << m_barrelDigiCollection
118  << "; not reading barrel digis";
119  barrelDigisFound = false;
120  }
121 
122  if (barrelDigis->empty()) {
123  edm::LogInfo("EcalPedOffset") << "Size of EBDigiCollection is zero;"
124  << " not reading barrel digis";
125  barrelDigisFound = false;
126  }
127 
128  // get the endcap digis
129  // (one digi for each crystal)
131  event.getByLabel(m_endcapDigiCollection, endcapDigis);
132  if (!endcapDigis.isValid()) {
133  edm::LogError("EcalPedOffset") << "Error! can't get the product " << m_endcapDigiCollection
134  << "; not reading endcap digis";
135  endcapDigisFound = false;
136  }
137 
138  if (endcapDigis->empty()) {
139  edm::LogInfo("EcalPedOffset") << "Size of EEDigiCollection is zero;"
140  << " not reading endcap digis";
141  endcapDigisFound = false;
142  }
143 
144  if (barrelDigisFound)
145  readDACs(barrelDigis, DACvalues);
146  if (endcapDigisFound)
147  readDACs(endcapDigis, DACvalues);
148  if (!barrelDigisFound && !endcapDigisFound)
149  edm::LogError("EcalPedOffset") << "No digis found in the event!";
150 }
#define LogDebug(id)
edm::InputTag m_barrelDigiCollection
secondary name given to collection of digis
Definition: EcalPedOffset.h:61
std::vector< T >::const_iterator const_iterator
void readDACs(const edm::Handle< EBDigiCollection > &pDigis, const std::map< int, int > &DACvalues)
bool isValid() const
Definition: HandleBase.h:74
const_iterator end() const
edm::InputTag m_headerCollection
name of module/plugin/producer making headers
Definition: EcalPedOffset.h:63
int m_run
run number
Definition: EcalPedOffset.h:91
edm::InputTag m_endcapDigiCollection
secondary name given to collection of digis
Definition: EcalPedOffset.h:62
const_iterator begin() const
void EcalPedOffset::beginRun ( edm::Run const &  ,
edm::EventSetup const &  eventSetup 
)
overridevirtual

BeginRun.

begin the run

Reimplemented from edm::EDAnalyzer.

Definition at line 77 of file EcalPedOffset.cc.

References ecalElectronicsMap_, edm::EventSetup::get(), cmsBatch::handle, LogDebug, and edm::ESHandle< T >::product().

77  {
78  LogDebug("EcalPedOffset") << "entering beginRun...";
79 
81  eventSetup.get<EcalMappingRcd>().get(handle);
82  ecalElectronicsMap_ = handle.product();
83 }
#define LogDebug(id)
const EcalElectronicsMapping * ecalElectronicsMap_
Definition: EcalPedOffset.h:55
T const * product() const
Definition: ESHandle.h:86
void EcalPedOffset::endJob ( void  )
overridevirtual

EndJob.

perform the minimization and write results

Reimplemented from edm::EDAnalyzer.

Definition at line 223 of file EcalPedOffset.cc.

References m_DACmax, m_DACmin, m_dbHostName, m_pedResult, m_pedValues, m_plotting, m_xmlFile, makePlots(), writeDb(), and writeXMLFiles().

Referenced by o2olib.O2ORunMgr::executeJob().

223  {
224  for (std::map<int, TPedValues *>::const_iterator smPeds = m_pedValues.begin(); smPeds != m_pedValues.end();
225  ++smPeds) {
226  m_pedResult[smPeds->first] = new TPedResult((smPeds->second)->terminate(m_DACmin, m_DACmax));
227  }
228  edm::LogInfo("EcalPedOffset") << " results map size " << m_pedResult.size();
230 
231  if (m_plotting != '0')
232  makePlots();
233  if (m_dbHostName != '0')
234  writeDb();
235 }
std::string m_dbHostName
database host name
Definition: EcalPedOffset.h:76
std::string m_xmlFile
name of the xml file to be saved
Definition: EcalPedOffset.h:65
std::string m_plotting
the root file where to store the detail plots
Definition: EcalPedOffset.h:94
void writeDb()
WriteDB.
void makePlots()
create the plots of the DAC pedestal trend
std::map< int, TPedResult * > m_pedResult
Definition: EcalPedOffset.h:68
void writeXMLFiles(std::string fileName)
write the results into xml format
std::map< int, TPedValues * > m_pedValues
Definition: EcalPedOffset.h:67
std::string EcalPedOffset::intToString ( int  num)
private

Definition at line 457 of file EcalPedOffset.cc.

Referenced by writeXMLFiles().

457  {
458  // outputs the number into the string stream and then flushes
459  // the buffer (makes sure the output is put into the stream)
460  std::ostringstream myStream;
461  myStream << num << std::flush;
462  return (myStream.str()); // returns the string form of the stringstream object
463 }
void EcalPedOffset::makePlots ( )

create the plots of the DAC pedestal trend

Definition at line 428 of file EcalPedOffset.cc.

References LogDebug, m_maxChi2OverNDFAllowed_, m_maxSlopeAllowed_, m_minSlopeAllowed_, m_pedValues, m_plotting, and indexGen::rootFile.

Referenced by endJob().

428  {
429  LogDebug("EcalPedOffset") << " entering makePlots ...";
430 
431  edm::LogInfo("EcalPedOffset") << " map size: " << m_pedValues.size();
432 
433  // create the ROOT file
434  m_plotting += ".root";
435 
436  TFile *rootFile = new TFile(m_plotting.c_str(), "RECREATE");
437 
438  // loop over the supermodules
439  for (std::map<int, TPedValues *>::const_iterator smPeds = m_pedValues.begin(); smPeds != m_pedValues.end();
440  ++smPeds) {
441  // make a folder in the ROOT file
442  char folderName[120];
443  sprintf(folderName, "FED%02d", smPeds->first);
444  rootFile->mkdir(folderName);
445  smPeds->second->makePlots(rootFile, folderName, m_maxSlopeAllowed_, m_minSlopeAllowed_, m_maxChi2OverNDFAllowed_);
446  }
447 
448  rootFile->Close();
449  delete rootFile;
450 
451  LogDebug("EcalPedOffset") << " DONE";
452 }
#define LogDebug(id)
double m_maxChi2OverNDFAllowed_
max chi2/ndf allowed for linearity test
double m_minSlopeAllowed_
min slope (in magnitude) allowed for linearity test
Definition: EcalPedOffset.h:98
std::string m_plotting
the root file where to store the detail plots
Definition: EcalPedOffset.h:94
std::map< int, TPedValues * > m_pedValues
Definition: EcalPedOffset.h:67
double m_maxSlopeAllowed_
max slope (in magnitude) allowed for linearity test
Definition: EcalPedOffset.h:96
void EcalPedOffset::readDACs ( const edm::Handle< EBDigiCollection > &  pDigis,
const std::map< int, int > &  DACvalues 
)
private

Definition at line 154 of file EcalPedOffset.cc.

References ecalMGPA::adc(), edm::DataFrameContainer::begin(), EcalElectronicsId::dccId(), ecalElectronicsMap_, edm::DataFrameContainer::end(), ecalMGPA::gainId(), EcalElectronicsMapping::getElectronicsId(), EBDetId::ic(), LogDebug, m_bestPed, m_pedValues, m_RMSmax, EcalDataFrame::MAXSAMPLES, and simplePhotonAnalyzer_cfi::sample.

Referenced by analyze().

154  {
155  std::map<int, int> DACvalues = _DACvalues;
156  // loop over the digis
157  for (EBDigiCollection::const_iterator itdigi = pDigis->begin(); itdigi != pDigis->end(); ++itdigi) {
158  int gainId = ((EBDataFrame)(*itdigi)).sample(0).gainId();
159  EBDetId detId = EBDetId(itdigi->id());
161  int FEDid = 600 + elecId.dccId();
162  int crystalId = detId.ic();
163 
164  // TODO: Behavior here
165  if (DACvalues.find(FEDid) == DACvalues.end()) {
166  edm::LogError("EcalPedOffset") << "Error! EB DCCid of digi does not "
167  "match any DCCid found in DCC headers"
168  << FEDid;
169  }
170 
171  if (!m_pedValues.count(FEDid)) {
172  LogDebug("EcalPedOffset") << "Inserting new TPedValues object for FED:" << FEDid;
173  m_pedValues[FEDid] = new TPedValues(m_RMSmax, m_bestPed);
174  }
175 
176  // loop over the samples
177  for (int iSample = 0; iSample < EcalDataFrame::MAXSAMPLES; ++iSample) {
178  m_pedValues[FEDid]->insert(
179  gainId, crystalId, DACvalues[FEDid], ((EBDataFrame)(*itdigi)).sample(iSample).adc(), crystalId);
180  }
181 
182  } // end loop over digis
183 }
#define LogDebug(id)
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
Ecal readout channel identification [32:20] Unused (so far) [19:13] DCC id [12:6] tower [5:3] strip [...
const_iterator begin() const
EcalElectronicsId getElectronicsId(const DetId &id) const
Get the electronics id for this det id.
constexpr int adc(sample_type sample)
get the ADC sample (12 bits)
int dccId() const
get the DCC (Ecal Local DCC value not global one) id
int ic() const
get ECAL/crystal number inside SM
Definition: EBDetId.cc:41
std::map< int, TPedValues * > m_pedValues
Definition: EcalPedOffset.h:67
const_iterator end() const
constexpr int gainId(sample_type sample)
get the gainId (2 bits)
const EcalElectronicsMapping * ecalElectronicsMap_
Definition: EcalPedOffset.h:55
static constexpr int MAXSAMPLES
Definition: EcalDataFrame.h:48
void EcalPedOffset::readDACs ( const edm::Handle< EEDigiCollection > &  pDigis,
const std::map< int, int > &  DACvalues 
)
private

Definition at line 187 of file EcalPedOffset.cc.

References ecalMGPA::adc(), edm::DataFrameContainer::begin(), EcalElectronicsId::dccId(), ecalElectronicsMap_, edm::DataFrameContainer::end(), ecalMGPA::gainId(), EcalElectronicsMapping::getElectronicsId(), LogDebug, m_bestPed, m_pedValues, m_RMSmax, EcalDataFrame::MAXSAMPLES, and simplePhotonAnalyzer_cfi::sample.

187  {
188  std::map<int, int> DACvalues = _DACvalues;
189  // loop over the digis
190  for (EEDigiCollection::const_iterator itdigi = pDigis->begin(); itdigi != pDigis->end(); ++itdigi) {
191  int gainId = ((EEDataFrame)(*itdigi)).sample(0).gainId();
192  // int gainId = itdigi->sample(0).gainId();
193  EEDetId detId = EEDetId(itdigi->id());
195  int FEDid = 600 + elecId.dccId();
196  int crystalId = 25 * elecId.towerId() + 5 * elecId.stripId() + elecId.xtalId();
197  int endcapCrystalId = 100 * elecId.towerId() + 5 * (elecId.stripId() - 1) + elecId.xtalId();
198 
199  // TODO: Behavior here
200  if (DACvalues.find(FEDid) == DACvalues.end()) {
201  edm::LogError("EcalPedOffset") << "Error! EE DCCid of digi does not "
202  "match any DCCid found in DCC headers: "
203  << FEDid;
204  }
205 
206  if (!m_pedValues.count(FEDid)) {
207  LogDebug("EcalPedOffset") << "Inserting new TPedValues object for FED:" << FEDid;
208  m_pedValues[FEDid] = new TPedValues(m_RMSmax, m_bestPed);
209  }
210 
211  // loop over the samples
212  for (int iSample = 0; iSample < EcalDataFrame::MAXSAMPLES; ++iSample) {
213  m_pedValues[FEDid]->insert(
214  gainId, crystalId, DACvalues[FEDid], ((EEDataFrame)(*itdigi)).sample(iSample).adc(), endcapCrystalId);
215  }
216 
217  } // end loop over digis
218 }
#define LogDebug(id)
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
Ecal readout channel identification [32:20] Unused (so far) [19:13] DCC id [12:6] tower [5:3] strip [...
const_iterator begin() const
EcalElectronicsId getElectronicsId(const DetId &id) const
Get the electronics id for this det id.
constexpr int adc(sample_type sample)
get the ADC sample (12 bits)
int dccId() const
get the DCC (Ecal Local DCC value not global one) id
std::map< int, TPedValues * > m_pedValues
Definition: EcalPedOffset.h:67
const_iterator end() const
constexpr int gainId(sample_type sample)
get the gainId (2 bits)
const EcalElectronicsMapping * ecalElectronicsMap_
Definition: EcalPedOffset.h:55
static constexpr int MAXSAMPLES
Definition: EcalDataFrame.h:48
void EcalPedOffset::writeDb ( )

WriteDB.

write the m_pedResult in the DB FIXME divide into sub-tasks

Definition at line 241 of file EcalPedOffset.cc.

References MillePedeFileConverter_cfg::e, runTauDisplay::eid, EcalCondDBInterface::fetchMonRunIOV(), EcalCondDBInterface::fetchRunIOV(), EcalCondDBInterface::getEcalLogicID(), RunIOV::getRunTag(), EcalCondDBInterface::insertDataSet(), LogDebug, m_create_moniov, m_dbHostName, m_dbHostPort, m_dbName, m_dbPassword, m_dbUserName, m_location, m_pedResult, m_pedValues, m_run, mps_fire::result, writedatasetfile::run, MonPedestalOffsetsDat::setDACG1(), MonPedestalOffsetsDat::setDACG12(), MonPedestalOffsetsDat::setDACG6(), RunTag::setGeneralTag(), MonRunTag::setGeneralTag(), LocationDef::setLocation(), RunTag::setLocationDef(), MonVersionDef::setMonitoringVersion(), MonRunIOV::setMonRunTag(), MonRunTag::setMonVersionDef(), MonRunIOV::setRunIOV(), RunTypeDef::setRunType(), RunTag::setRunTypeDef(), MonRunIOV::setSubRunNumber(), MonRunIOV::setSubRunStart(), MonPedestalOffsetsDat::setTaskStatus(), and Tm::setToCurrentGMTime().

Referenced by endJob().

241  {
242  LogDebug("EcalPedOffset") << " entering writeDb ...";
243 
244  // connect to the database
245  EcalCondDBInterface *DBconnection;
246  try {
247  LogInfo("EcalPedOffset") << "Opening DB connection with TNS_ADMIN ...";
249  } catch (std::runtime_error &e) {
250  LogError("EcalPedOffset") << e.what();
251  if (!m_dbHostName.empty()) {
252  try {
253  LogInfo("EcalPedOffset") << "Opening DB connection without TNS_ADMIN ...";
255  } catch (std::runtime_error &e) {
256  LogError("EcalPedOffset") << e.what();
257  return;
258  }
259  } else
260  return;
261  }
262 
263  // define the query for RunIOV to get the right place in the database
264  RunTag runtag;
265  LocationDef locdef;
266  RunTypeDef rundef;
267  locdef.setLocation(m_location);
268 
269  runtag.setGeneralTag("PEDESTAL-OFFSET");
270  rundef.setRunType("PEDESTAL-OFFSET");
271  // rundef.setRunType ("TEST");
272  // runtag.setGeneralTag ("TEST");
273 
274  runtag.setLocationDef(locdef);
275  runtag.setRunTypeDef(rundef);
276 
277  run_t run = m_run; // FIXME dal config file
278  // RunIOV runiov = DBconnection->fetchRunIOV (&runtag, run);
279  RunIOV runiov = DBconnection->fetchRunIOV(m_location, run);
280 
281  // MonRunIOV
282  MonVersionDef monverdef;
283  monverdef.setMonitoringVersion("test01");
284  MonRunTag montag;
285  montag.setMonVersionDef(monverdef);
286  montag.setGeneralTag("CMSSW");
287 
288  subrun_t subrun = 1; // hardcoded!
289 
290  MonRunIOV moniov;
291 
292  try {
293  runtag = runiov.getRunTag();
294  moniov = DBconnection->fetchMonRunIOV(&runtag, &montag, run, subrun);
295  } catch (std::runtime_error &e) {
296  if (m_create_moniov) {
297  // if not already in the DB create a new MonRunIOV
298  Tm startSubRun;
299  startSubRun.setToCurrentGMTime();
300  // setup the MonIOV
301  moniov.setRunIOV(runiov);
302  moniov.setSubRunNumber(subrun);
303  moniov.setSubRunStart(startSubRun);
304  moniov.setMonRunTag(montag);
305  LogDebug("EcalPedOffset") << " creating a new MonRunIOV";
306  } else {
307  edm::LogError("EcalPedOffset") << " no MonRunIOV existing in the DB";
308  edm::LogError("EcalPedOffset") << " the result will not be stored into the DB";
309  if (DBconnection) {
310  delete DBconnection;
311  }
312  return;
313  }
314  }
315 
316  // create the table to be filled and the map to be inserted
317  EcalLogicID ecid;
318  std::map<EcalLogicID, MonPedestalOffsetsDat> DBdataset;
319  MonPedestalOffsetsDat DBtable;
320 
321  // fill the table
322 
323  // loop over the super-modules
324  for (std::map<int, TPedResult *>::const_iterator result = m_pedResult.begin(); result != m_pedResult.end();
325  ++result) {
326  // loop over the crystals
327  for (int xtal = 0; xtal < 1700; ++xtal) {
328  DBtable.setDACG1(result->second->m_DACvalue[2][xtal]);
329  DBtable.setDACG6(result->second->m_DACvalue[1][xtal]);
330  DBtable.setDACG12(result->second->m_DACvalue[0][xtal]);
331  DBtable.setTaskStatus(true); // FIXME to be set correctly
332 
333  // fill the table
334  if (DBconnection) {
335  try {
336  int fedid = result->first;
337  int eid = m_pedValues[fedid]->getCrystalNumber(xtal);
338  // If eid is zero, that crystal was not present in digis
339  if (eid == 0)
340  continue;
341 
342  if (fedid >= 601 && fedid <= 609) {
343  // Add the FEDid part in for DB
344  eid = eid + 10000 * (fedid - 600);
345  ecid = DBconnection->getEcalLogicID("EE_elec_crystal_number", eid);
346  } else if (fedid >= 610 && fedid <= 627) {
347  ecid = DBconnection->getEcalLogicID("EB_crystal_number", fedid - 610 + 19, eid);
348  } else if (fedid >= 628 && fedid <= 645) {
349  ecid = DBconnection->getEcalLogicID("EB_crystal_number", fedid - 628 + 1, eid);
350  } else if (fedid >= 646 && fedid <= 654) {
351  // Add the FEDid part in for DB
352  eid = eid + 10000 * (fedid - 600);
353  ecid = DBconnection->getEcalLogicID("EE_elec_crystal_number", eid);
354  } else
355  LogError("EcalPedOffset") << "FEDid is out of range 601-654";
356 
357  DBdataset[ecid] = DBtable;
358  } catch (std::runtime_error &e) {
359  edm::LogError("EcalPedOffset") << e.what();
360  }
361  }
362  } // loop over the crystals
363  } // loop over the super-modules
364 
365  // insert the map of tables in the database
366  if (DBconnection) {
367  try {
368  LogDebug("EcalPedOffset") << "Inserting dataset ... " << std::flush;
369  if (!DBdataset.empty())
370  DBconnection->insertDataSet(&DBdataset, &moniov);
371  LogDebug("EcalPedOffset") << "done.";
372  } catch (std::runtime_error &e) {
373  edm::LogError("EcalPedOffset") << e.what();
374  }
375  }
376 
377  if (DBconnection) {
378  delete DBconnection;
379  }
380 }
#define LogDebug(id)
void setTaskStatus(bool status)
void setRunTypeDef(const RunTypeDef &runTypeDef)
Definition: RunTag.cc:70
int run_t
Definition: CaliIOV.h:11
std::string m_dbHostName
database host name
Definition: EcalPedOffset.h:76
MonRunIOV fetchMonRunIOV(RunTag *runtag, MonRunTag *montag, run_t run, subrun_t monrun) noexcept(false)
EcalLogicID getEcalLogicID(std::string name, int id1=EcalLogicID::NULLID, int id2=EcalLogicID::NULLID, int id3=EcalLogicID::NULLID, std::string mapsTo="") noexcept(false)
Definition: RunTag.h:13
std::string m_dbName
database name
Definition: EcalPedOffset.h:78
void setRunIOV(const RunIOV &iov)
Definition: MonRunIOV.cc:53
void setToCurrentGMTime()
Definition: Tm.cc:177
void setGeneralTag(std::string tag)
Definition: MonRunTag.cc:33
std::string m_dbPassword
database user password
Definition: EcalPedOffset.h:82
int m_dbHostPort
database
Definition: EcalPedOffset.h:84
std::string m_dbUserName
database user name
Definition: EcalPedOffset.h:80
RunTag getRunTag() const
Definition: RunIOV.cc:96
RunIOV fetchRunIOV(RunTag *tag, run_t run) noexcept(false)
int subrun_t
Definition: MODRunIOV.h:11
void setSubRunNumber(subrun_t subrun)
Definition: MonRunIOV.cc:67
void setMonVersionDef(const MonVersionDef &ver)
Definition: MonRunTag.cc:49
bool m_create_moniov
Definition: EcalPedOffset.h:87
void setSubRunStart(const Tm &start)
Definition: MonRunIOV.cc:84
void setLocationDef(const LocationDef &locDef)
Definition: RunTag.cc:53
std::map< int, TPedResult * > m_pedResult
Definition: EcalPedOffset.h:68
int m_run
run number
Definition: EcalPedOffset.h:91
void setRunType(std::string runtype)
Definition: RunTypeDef.cc:33
void setMonRunTag(const MonRunTag &tag)
Definition: MonRunIOV.cc:36
std::map< int, TPedValues * > m_pedValues
Definition: EcalPedOffset.h:67
void setMonitoringVersion(std::string ver)
void insertDataSet(const std::map< EcalLogicID, DATT > *data, IOVT *iov) noexcept(false)
void setLocation(std::string loc)
Definition: LocationDef.cc:33
std::string m_location
Definition: EcalPedOffset.h:89
void setGeneralTag(std::string tag)
Definition: RunTag.cc:36
Definition: RunIOV.h:13
Definition: Tm.h:13
void EcalPedOffset::writeXMLFiles ( std::string  fileName)

write the results into xml format

write the m_pedResults to XML files

Definition at line 385 of file EcalPedOffset.cc.

References MillePedeFileConverter_cfg::fileName, intToString(), m_pedResult, m_pedValues, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by endJob().

385  {
386  // loop over the super-modules
387  for (std::map<int, TPedResult *>::const_iterator smRes = m_pedResult.begin(); smRes != m_pedResult.end(); ++smRes) {
388  std::string thisSMFileName = fileName;
389  // open the output stream
390  thisSMFileName += "_";
391  thisSMFileName += intToString(smRes->first);
392  thisSMFileName += ".xml";
393  std::ofstream xml_outfile;
394  xml_outfile.open(thisSMFileName.c_str());
395 
396  // write the header file
397  xml_outfile << "<offsets>" << std::endl;
398  xml_outfile << "<PEDESTAL_OFFSET_RELEASE VERSION_ID = \"SM1_VER1\"> \n";
399  xml_outfile << " <RELEASE_ID>RELEASE_1</RELEASE_ID>\n";
400  xml_outfile << " <SUPERMODULE>";
401  xml_outfile << smRes->first;
402  xml_outfile << "</SUPERMODULE>\n";
403  xml_outfile << " <TIME_STAMP> 070705 </TIME_STAMP>" << std::endl;
404 
405  // loop over the crystals
406  for (int xtal = 0; xtal < 1700; ++xtal) {
407  int crystalNumber = m_pedValues[smRes->first]->getCrystalNumber(xtal);
408  if (crystalNumber == 0)
409  continue;
410  xml_outfile << " <PEDESTAL_OFFSET>\n";
411  xml_outfile << " <HIGH>" << ((smRes->second)->m_DACvalue)[0][xtal] << "</HIGH>\n";
412  xml_outfile << " <MED>" << ((smRes->second)->m_DACvalue)[1][xtal] << "</MED>\n";
413  xml_outfile << " <LOW>" << ((smRes->second)->m_DACvalue)[2][xtal] << "</LOW>\n";
414  xml_outfile << " <CRYSTAL> " << crystalNumber << " </CRYSTAL>\n";
415  xml_outfile << " </PEDESTAL_OFFSET>" << std::endl;
416  }
417 
418  // close the open tags
419  xml_outfile << " </PEDESTAL_OFFSET_RELEASE>" << std::endl;
420  xml_outfile << "</offsets>" << std::endl;
421  xml_outfile.close();
422  } // loop over the super-modules
423 }
std::string intToString(int num)
std::map< int, TPedResult * > m_pedResult
Definition: EcalPedOffset.h:68
std::map< int, TPedValues * > m_pedValues
Definition: EcalPedOffset.h:67

Member Data Documentation

const EcalElectronicsMapping* EcalPedOffset::ecalElectronicsMap_
private

Definition at line 55 of file EcalPedOffset.h.

Referenced by beginRun(), and readDACs().

edm::InputTag EcalPedOffset::m_barrelDigiCollection
private

secondary name given to collection of digis

Definition at line 61 of file EcalPedOffset.h.

Referenced by analyze().

int EcalPedOffset::m_bestPed
private

Definition at line 73 of file EcalPedOffset.h.

Referenced by EcalPedOffset(), and readDACs().

bool EcalPedOffset::m_create_moniov
private

allow the creation of a new moniov if not existing in the DB by default it is false.

Definition at line 87 of file EcalPedOffset.h.

Referenced by writeDb().

int EcalPedOffset::m_DACmax
private

Definition at line 71 of file EcalPedOffset.h.

Referenced by EcalPedOffset(), and endJob().

int EcalPedOffset::m_DACmin
private

Definition at line 70 of file EcalPedOffset.h.

Referenced by EcalPedOffset(), and endJob().

std::string EcalPedOffset::m_dbHostName
private

database host name

Definition at line 76 of file EcalPedOffset.h.

Referenced by endJob(), and writeDb().

int EcalPedOffset::m_dbHostPort
private

database

Definition at line 84 of file EcalPedOffset.h.

Referenced by writeDb().

std::string EcalPedOffset::m_dbName
private

database name

Definition at line 78 of file EcalPedOffset.h.

Referenced by writeDb().

std::string EcalPedOffset::m_dbPassword
private

database user password

Definition at line 82 of file EcalPedOffset.h.

Referenced by writeDb().

std::string EcalPedOffset::m_dbUserName
private

database user name

Definition at line 80 of file EcalPedOffset.h.

Referenced by writeDb().

edm::InputTag EcalPedOffset::m_endcapDigiCollection
private

secondary name given to collection of digis

Definition at line 62 of file EcalPedOffset.h.

Referenced by analyze().

edm::InputTag EcalPedOffset::m_headerCollection
private

name of module/plugin/producer making headers

Definition at line 63 of file EcalPedOffset.h.

Referenced by analyze().

std::string EcalPedOffset::m_location
private

Definition at line 89 of file EcalPedOffset.h.

Referenced by writeDb().

double EcalPedOffset::m_maxChi2OverNDFAllowed_
private

max chi2/ndf allowed for linearity test

Definition at line 100 of file EcalPedOffset.h.

Referenced by makePlots().

double EcalPedOffset::m_maxSlopeAllowed_
private

max slope (in magnitude) allowed for linearity test

Definition at line 96 of file EcalPedOffset.h.

Referenced by makePlots().

double EcalPedOffset::m_minSlopeAllowed_
private

min slope (in magnitude) allowed for linearity test

Definition at line 98 of file EcalPedOffset.h.

Referenced by makePlots().

std::map<int, TPedResult *> EcalPedOffset::m_pedResult
private

Definition at line 68 of file EcalPedOffset.h.

Referenced by endJob(), writeDb(), writeXMLFiles(), and ~EcalPedOffset().

std::map<int, TPedValues *> EcalPedOffset::m_pedValues
private

Definition at line 67 of file EcalPedOffset.h.

Referenced by endJob(), makePlots(), readDACs(), writeDb(), writeXMLFiles(), and ~EcalPedOffset().

std::string EcalPedOffset::m_plotting
private

the root file where to store the detail plots

Definition at line 94 of file EcalPedOffset.h.

Referenced by endJob(), and makePlots().

double EcalPedOffset::m_RMSmax
private

Definition at line 72 of file EcalPedOffset.h.

Referenced by EcalPedOffset(), and readDACs().

int EcalPedOffset::m_run
private

run number

Definition at line 91 of file EcalPedOffset.h.

Referenced by analyze(), and writeDb().

std::string EcalPedOffset::m_xmlFile
private

name of the xml file to be saved

Definition at line 65 of file EcalPedOffset.h.

Referenced by endJob().