CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ESTrivialConditionRetriever.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <fstream>
3 #include <vector>
4 
5 
9 
11 
12 //#include "DataFormats/Provenance/interface/Timestamp.h"
13 
15 
16 
17 using namespace edm;
18 
20 {
21 
22  // initilize parameters used to produce cond DB objects
23  adcToGeVLowConstant_ = ps.getUntrackedParameter<double>("adcToGeVLowConstant",1.0);
24  adcToGeVHighConstant_ = ps.getUntrackedParameter<double>("adcToGeVHighConstant",1.0);
25 
26  intercalibConstantMean_ = ps.getUntrackedParameter<double>("intercalibConstantMean",1.0);
27  intercalibConstantSigma_ = ps.getUntrackedParameter<double>("intercalibConstantSigma",0.0);
28 
29  // intercalibErrorMean_ = ps.getUntrackedParameter<double>("IntercalibErrorMean",0.0);
30 
31  ESpedMean_ = ps.getUntrackedParameter<double>("ESpedMean", 200.);
32  ESpedRMS_ = ps.getUntrackedParameter<double>("ESpedRMS", 1.00);
33 
34  getWeightsFromFile_ = ps.getUntrackedParameter<bool>("getWeightsFromFile",false);
35 
36 
37  std::string path="CalibCalorimetry/EcalTrivialCondModules/data/";
38  std::string weightType;
39  std::ostringstream str;
40 
41  weightType = str.str();
42 
43  amplWeightsFile_ = ps.getUntrackedParameter<std::string>("amplWeightsFile",path+"ampWeightsES"+weightType);
44 
45  // default weights for MGPA shape after pedestal subtraction
46  getWeightsFromConfiguration(ps);
47 
48  producedESPedestals_ = ps.getUntrackedParameter<bool>("producedESPedestals",true);
49  producedESWeights_ = ps.getUntrackedParameter<bool>("producedESWeights",true);
50 
51  producedESADCToGeVConstant_ = ps.getUntrackedParameter<bool>("producedESADCToGeVConstant",true);
52 
53  verbose_ = ps.getUntrackedParameter<int>("verbose", 0);
54 
55  //Tell Producer what we produce
56  //setWhatproduce(this);
57  if (producedESPedestals_)
58  setWhatProduced(this, &ESTrivialConditionRetriever::produceESPedestals );
59 
60  if (producedESWeights_) {
62  setWhatProduced(this, &ESTrivialConditionRetriever::produceESTBWeights );
63  }
64 
65  if (producedESADCToGeVConstant_)
67 
68  // intercalibration constants
69  producedESIntercalibConstants_ = ps.getUntrackedParameter<bool>("producedESIntercalibConstants",true);
70  intercalibConstantsFile_ = ps.getUntrackedParameter<std::string>("intercalibConstantsFile","") ;
71 
72  if (producedESIntercalibConstants_) { // user asks to produce constants
73  if(intercalibConstantsFile_ == "") { // if file provided read constants
74  // setWhatProduced (this, &ESTrivialConditionRetriever::getIntercalibConstantsFromConfiguration ) ;
75  // } else { // set all constants to 1. or smear as specified by user
77  }
78  findingRecord<ESIntercalibConstantsRcd> () ;
79  }
80 
81  // intercalibration constants errors
82  /* producedESIntercalibErrors_ = ps.getUntrackedParameter<bool>("producedESIntercalibErrors",true);
83  intercalibErrorsFile_ = ps.getUntrackedParameter<std::string>("intercalibErrorsFile","") ;
84 
85  if (producedESIntercalibErrors_) { // user asks to produce constants
86  if(intercalibErrorsFile_ != "") { // if file provided read constants
87  setWhatProduced (this, &ESTrivialConditionRetriever::getIntercalibErrorsFromConfiguration ) ;
88  } else { // set all constants to 1. or smear as specified by user
89  setWhatProduced (this, &ESTrivialConditionRetriever::produceESIntercalibErrors ) ;
90  }
91  findingRecord<ESIntercalibErrorsRcd> () ;
92  }
93  */
94 
95  // channel status
96  producedESChannelStatus_ = ps.getUntrackedParameter<bool>("producedESChannelStatus",true);
97  channelStatusFile_ = ps.getUntrackedParameter<std::string>("channelStatusFile","");
98 
99  if ( producedESChannelStatus_ ) {
100  if ( channelStatusFile_ != "" ) { // if file provided read channel map
102  } else { // set all channels to working -- FIXME might be changed
103  setWhatProduced( this, &ESTrivialConditionRetriever::produceESChannelStatus );
104  }
105  findingRecord<ESChannelStatusRcd>();
106  }
107 
108  //Tell Finder what records we find
109  if (producedESPedestals_) findingRecord<ESPedestalsRcd>();
110 
111  if (producedESWeights_) {
112  findingRecord<ESWeightStripGroupsRcd>();
113  findingRecord<ESTBWeightsRcd>();
114  }
115 
116  if (producedESADCToGeVConstant_) findingRecord<ESADCToGeVConstantRcd>();
117 
118 }
119 
121 {
122 }
123 
124 //
125 // member functions
126 //
127 void
129  const edm::IOVSyncValue& iTime,
130  edm::ValidityInterval& oValidity)
131 {
132  if(verbose_>=1) std::cout << "ESTrivialConditionRetriever::setIntervalFor(): record key = " << rk.name() << "\ttime: " << iTime.time().value() << std::endl;
133  //For right now, we will just use an infinite interval of validity
135 }
136 
137 //produce methods
138 std::auto_ptr<ESPedestals>
140  std::cout<< " producing pedestals"<< std::endl;
141  std::auto_ptr<ESPedestals> peds = std::auto_ptr<ESPedestals>( new ESPedestals() );
142  ESPedestals::Item ESitem;
143  ESitem.mean = ESpedMean_;
144  ESitem.rms = ESpedRMS_;
145 
146  for (int istrip=ESDetId::ISTRIP_MIN;istrip<=ESDetId::ISTRIP_MAX;istrip++) {
147  for (int ix=ESDetId::IX_MIN;ix<=ESDetId::IX_MAX;ix++){
148  for (int iy=ESDetId::IY_MIN;iy<=ESDetId::IY_MAX;iy++){
149  for ( int iplane=1; iplane<=2; iplane++){
150  for(int izeta=-1; izeta<=1 ;++izeta) {
151  if(izeta==0) continue;
152  try {
153  //ESDetId Plane iplane Zside izeta
154  ESDetId aPositiveId(istrip,ix,iy,iplane,izeta);
155  peds->insert(std::make_pair(aPositiveId.rawId(),ESitem));
156  }
157  catch ( cms::Exception &e )
158  {
159  }
160  }
161  }
162  }
163  }
164  }
165  //return std::auto_ptr<ESPedestals>( peds );
166  std::cout<< " produced pedestals"<< std::endl;
167  return peds;
168 }
169 
170 std::auto_ptr<ESWeightStripGroups>
172 {
173  std::auto_ptr<ESWeightStripGroups> xtalGroups = std::auto_ptr<ESWeightStripGroups>( new ESWeightStripGroups() );
174  ESStripGroupId defaultGroupId(1);
175  std::cout << "entering produce weight groups"<< std::endl;
176  for (int istrip=ESDetId::ISTRIP_MIN;istrip<=ESDetId::ISTRIP_MAX;istrip++) {
177  for (int ix=ESDetId::IX_MIN;ix<=ESDetId::IX_MAX;ix++){
178  for (int iy=ESDetId::IY_MIN;iy<=ESDetId::IY_MAX;iy++){
179  for ( int iplane=1; iplane<=2; iplane++){
180  for(int izeta=-1; izeta<=1 ;++izeta) {
181  if(izeta==0) continue;
182  try {
183  //ESDetId Plane iplane Zside izeta
184  ESDetId anESId(istrip,ix,iy,iplane,izeta);
185  // xtalGroups->setValue(ebid.rawId(), ESStripGroupId(ieta) ); // define rings in eta
186  xtalGroups->setValue(anESId.rawId(), defaultGroupId ); // define rings in eta
187  }
188  catch ( cms::Exception &e )
189  {
190  }
191  }
192  }
193  }
194  }
195  }
196  std::cout << "done with produce weight groups"<< std::endl;
197 
198  return xtalGroups;
199 }
200 
201 std::auto_ptr<ESIntercalibConstants>
203 {
204  std::auto_ptr<ESIntercalibConstants> ical = std::auto_ptr<ESIntercalibConstants>( new ESIntercalibConstants() );
205  std::cout << "entring produce intercalib "<< std::endl;
206 
207  for (int istrip=ESDetId::ISTRIP_MIN;istrip<=ESDetId::ISTRIP_MAX;istrip++) {
208  for (int ix=ESDetId::IX_MIN;ix<=ESDetId::IX_MAX;ix++){
209  for (int iy=ESDetId::IY_MIN;iy<=ESDetId::IY_MAX;iy++){
210  for ( int iplane=1; iplane<=2; iplane++){
211  for(int izeta=-1; izeta<=1 ;++izeta) {
212  if(izeta==0) continue;
213  try {
214  //ESDetId Plane iplane Zside izeta
215  ESDetId anESId(istrip,ix,iy,iplane,izeta);
216  double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
217  ical->setValue( anESId.rawId(), intercalibConstantMean_ + r*intercalibConstantSigma_ );
218  }
219  catch ( cms::Exception &e )
220  {
221  }
222  }
223  }
224  }
225  }
226  }
227  std::cout << "done produce intercalib"<< std::endl;
228 
229  return ical;
230 }
231 
232 
233 std::auto_ptr<ESADCToGeVConstant>
235 {
236  return std::auto_ptr<ESADCToGeVConstant>( new ESADCToGeVConstant(adcToGeVLowConstant_,adcToGeVHighConstant_) );
237 }
238 
239 std::auto_ptr<ESTBWeights>
241 {
242  // create weights for the test-beam
243  std::auto_ptr<ESTBWeights> tbwgt = std::auto_ptr<ESTBWeights>( new ESTBWeights() );
244 
245  int igrp=1;
246  ESWeightSet wgt = ESWeightSet(amplWeights_);
247  // ESWeightSet::ESWeightMatrix& mat1 = wgt.getWeights();
248 
249  tbwgt->setValue(igrp,wgt);
250 
251 
252  return tbwgt;
253 }
254 
255 
256 
258 {
259 
261 
262  if (!getWeightsFromFile_ )
263  {
264 
265  // vampl.set(1.);
266 
267  // amplwgtv[0]= ps.getUntrackedParameter< std::vector<double> >("amplWeights", vampl);
268  }
269  else if (getWeightsFromFile_)
270  {
271  edm::LogInfo("ESTrivialConditionRetriever") << "Reading amplitude weights from file " << edm::FileInPath(amplWeightsFile_).fullPath().c_str() ;
272  std::ifstream amplFile(edm::FileInPath(amplWeightsFile_).fullPath().c_str());
273  while (!amplFile.eof() )
274  {
275  for(int j = 0; j < 2; ++j) {
276  std::vector<float> vec(3) ;
277  for(int k = 0; k < 3; ++k) {
278  float ww;
279  amplFile >> ww;
280  vec[k]=ww;
281  }
282  // vampl.putRow(vec);
283  }
284  }
285  }
286  else
287  {
288  //Not supported
289  edm::LogError("ESTrivialConditionRetriever") << "Configuration not supported. Exception is raised ";
290  throw cms::Exception("WrongConfig");
291  }
292 
293 
294  amplWeights_=ESWeightSet(vampl);
295 
296 }
297 
298 // --------------------------------------------------------------------------------
299 
300 std::auto_ptr<ESChannelStatus>
302 {
303  std::auto_ptr<ESChannelStatus> ecalStatus = std::auto_ptr<ESChannelStatus>( new ESChannelStatus() );
304 
305 
306  // start by setting all statuses to 0
307 
308 
309  for (int istrip=ESDetId::ISTRIP_MIN;istrip<=ESDetId::ISTRIP_MAX;istrip++) {
310  for (int ix=ESDetId::IX_MIN;ix<=ESDetId::IX_MAX;ix++){
311  for (int iy=ESDetId::IY_MIN;iy<=ESDetId::IY_MAX;iy++){
312  for ( int iplane=1; iplane<=2; iplane++){
313  for(int izeta=-1; izeta<=1 ;++izeta) {
314  if(izeta==0) continue;
315  try {
316  //ESDetId Plane iplane Zside izeta
317  ESDetId anESId(istrip,ix,iy,iplane,izeta);
318  // xtalGroups->setValue(ebid.rawId(), ESStripGroupId(ieta) ); // define rings in eta
319  ecalStatus->setValue( anESId, 0 );
320  }
321  catch ( cms::Exception &e )
322  {
323  }
324  }
325  }
326  }
327  }
328  }
329 
330  // overwrite the statuses which are in the file
331 
332  edm::LogInfo("ESTrivialConditionRetriever") << "Reading channel statuses from file " << edm::FileInPath(channelStatusFile_).fullPath().c_str() ;
333  std::ifstream statusFile(edm::FileInPath(channelStatusFile_).fullPath().c_str());
334  if ( !statusFile.good() ) {
335  edm::LogError ("ESTrivialConditionRetriever")
336  << "*** Problems opening file: " << channelStatusFile_ ;
337  throw cms::Exception ("Cannot open ECAL channel status file") ;
338  }
339 
340  std::string ESSubDet;
341  std::string str;
342  int hashIndex(0);
343  int status(0);
344 
345  while (!statusFile.eof())
346  {
347  statusFile >> ESSubDet;
348  if (ESSubDet!=std::string("ES") )
349  {
350  std::getline(statusFile,str);
351  continue;
352  }
353  else
354  {
355  statusFile>> hashIndex >> status;
356  }
357  // std::cout << ESSubDet << " " << hashIndex << " " << status;
358 
359  if(ESSubDet==std::string("ES"))
360  {
361  ESDetId esid = ESDetId::unhashIndex(hashIndex);
362  ecalStatus->setValue( esid, status );
363  }
364  else
365  {
366  edm::LogError ("ESTrivialConditionRetriever")
367  << " *** " << ESSubDet << " is not ES ";
368  }
369  }
370  // the file is supposed to be in the form
371  // ES hashed_index status
372  // ES 132332 1 --> higher than 0 means bad
373 
374  statusFile.close();
375  return ecalStatus;
376 }
377 
378 
379 
380 std::auto_ptr<ESChannelStatus>
382 {
383 
384  std::auto_ptr<ESChannelStatus> ical = std::auto_ptr<ESChannelStatus>( new ESChannelStatus() );
385  for (int istrip=ESDetId::ISTRIP_MIN;istrip<=ESDetId::ISTRIP_MAX;istrip++) {
386  for (int ix=ESDetId::IX_MIN;ix<=ESDetId::IX_MAX;ix++){
387  for (int iy=ESDetId::IY_MIN;iy<=ESDetId::IY_MAX;iy++){
388  for ( int iplane=1; iplane<=2; iplane++){
389  for(int izeta=-1; izeta<=1 ;++izeta) {
390  if(izeta==0) continue;
391  try {
392  //ESDetId Plane iplane Zside izeta
393  ESDetId anESId(istrip,ix,iy,iplane,izeta);
394  // xtalGroups->setValue(ebid.rawId(), ESStripGroupId(ieta) ); // define rings in eta
395  ical->setValue( anESId, 0 );
396  }
397  catch ( cms::Exception &e )
398  {
399  }
400  }
401  }
402  }
403  }
404  }
405 
406  return ical;
407 }
408 
409 
410 
411 // --------------------------------------------------------------------------------
412 
413 
414 
virtual void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &)
virtual std::auto_ptr< ESChannelStatus > produceESChannelStatus(const ESChannelStatusRcd &)
T getUntrackedParameter(std::string const &, T const &) const
virtual std::auto_ptr< ESChannelStatus > getChannelStatusFromConfiguration(const ESChannelStatusRcd &)
static const int IY_MAX
Definition: ESDetId.h:73
static const IOVSyncValue & endOfTime()
Definition: IOVSyncValue.cc:97
std::pair< Time_t, Time_t > ValidityInterval
Definition: Time.h:19
math::Matrix< 2, 3 >::type ESWeightMatrix
Definition: ESWeightSet.h:14
static const int ISTRIP_MAX
Definition: ESDetId.h:75
virtual std::auto_ptr< ESWeightStripGroups > produceESWeightStripGroups(const ESWeightStripGroupsRcd &)
ESPedestalsMap ESPedestals
Definition: ESPedestals.h:32
ESChannelStatusMap ESChannelStatus
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
virtual std::auto_ptr< ESTBWeights > produceESTBWeights(const ESTBWeightsRcd &)
tuple path
else: Piece not in the list, fine.
static const IOVSyncValue & beginOfTime()
ESTrivialConditionRetriever(const edm::ParameterSet &pset)
int j
Definition: DBlmapReader.cc:9
void getWeightsFromConfiguration(const edm::ParameterSet &ps)
float mean
Definition: ESPedestals.h:14
int k[5][pyjets_maxn]
static const int IY_MIN
Definition: ESDetId.h:71
virtual std::auto_ptr< ESPedestals > produceESPedestals(const ESPedestalsRcd &)
ESIntercalibConstantMap ESIntercalibConstants
static const int IX_MAX
Definition: ESDetId.h:72
Signal rand(Signal arg)
Definition: vlib.cc:442
const Timestamp & time() const
Definition: IOVSyncValue.h:44
tuple cout
Definition: gather_cfg.py:121
static ESDetId unhashIndex(int hi)
get a DetId from a compact index for arrays
Definition: ESDetId.cc:87
std::string fullPath() const
Definition: FileInPath.cc:165
tuple status
Definition: ntuplemaker.py:245
virtual std::auto_ptr< ESADCToGeVConstant > produceESADCToGeVConstant(const ESADCToGeVConstantRcd &)
static const int ISTRIP_MIN
Definition: ESDetId.h:74
TimeValue_t value() const
Definition: Timestamp.h:56
virtual std::auto_ptr< ESIntercalibConstants > produceESIntercalibConstants(const ESIntercalibConstantsRcd &)
static const int IX_MIN
Definition: ESDetId.h:70
ESCondObjectContainer< ESStripGroupId > ESWeightStripGroups