CMS 3D CMS Logo

EcalUncalibRecHitWorkerFixedAlphaBetaFit.cc
Go to the documentation of this file.
1 
9 
14 
16 
19 
21 
24 
25 #include <iostream>
26 #include <cmath>
27 #include <fstream>
28 
32  ratiosToken_(c.esConsumes<EcalGainRatios, EcalGainRatiosRcd>()),
33  pedestalsToken_(c.esConsumes<EcalPedestals, EcalPedestalsRcd>()) {
34  alphaEB_ = ps.getParameter<double>("alphaEB");
35  betaEB_ = ps.getParameter<double>("betaEB");
36  alphaEE_ = ps.getParameter<double>("alphaEE");
37  betaEE_ = ps.getParameter<double>("betaEE");
38 
39  alphabetaFilename_ = ps.getUntrackedParameter<std::string>("AlphaBetaFilename");
40  useAlphaBetaArray_ = setAlphaBeta(); // set crystalwise values of alpha and beta
41  if (!useAlphaBetaArray_) {
42  edm::LogInfo("EcalUncalibRecHitError") << " No alfa-beta file found. Using the deafult values.";
43  }
44 
45  algoEB_.SetMinAmpl(ps.getParameter<double>("MinAmplBarrel"));
46  algoEE_.SetMinAmpl(ps.getParameter<double>("MinAmplEndcap"));
47 
48  bool dyn_pede = ps.getParameter<bool>("UseDynamicPedestal");
49  algoEB_.SetDynamicPedestal(dyn_pede);
50  algoEE_.SetDynamicPedestal(dyn_pede);
51 }
52 
54  // Gain Ratios
55  LogDebug("EcalUncalibRecHitDebug") << "fetching gainRatios....";
57  LogDebug("EcalUncalibRecHitDebug") << "done.";
58 
59  // fetch the pedestals from the cond DB via EventSetup
60  LogDebug("EcalUncalibRecHitDebug") << "fetching pedestals....";
62  LogDebug("EcalUncalibRecHitDebug") << "done.";
63 }
64 
65 //Sets the alphaBetaValues_ vectors by the values provided in alphabetaFilename_
67  std::ifstream file(alphabetaFilename_.c_str());
68  if (!file.is_open())
69  return false;
70 
71  alphaBetaValues_.resize(36);
72 
73  char buffer[100];
74  int sm, cry, ret;
75  float a, b;
76  std::pair<double, double> p(-1, -1);
77 
78  while (!file.getline(buffer, 100).eof()) {
79  ret = sscanf(buffer, "%d %d %f %f", &sm, &cry, &a, &b);
80  if ((ret != 4) || (sm <= 0) || (sm > 36) || (cry <= 0) || (cry > 1700)) {
81  // send warning
82  continue;
83  }
84 
85  if (alphaBetaValues_[sm - 1].empty()) {
86  alphaBetaValues_[sm - 1].resize(1700, p);
87  }
88  alphaBetaValues_[sm - 1][cry - 1].first = a;
89  alphaBetaValues_[sm - 1][cry - 1].second = b;
90  }
91 
92  file.close();
93  return true;
94 }
95 
99  const EcalGainRatioMap& gainMap = pRatio.product()->getMap(); // map of gain ratios
100  EcalGainRatioMap::const_iterator gainIter; // gain iterator
101  EcalMGPAGainRatio aGain; // gain object for a single xtal
102 
103  const EcalPedestalsMap& pedMap = pedHandle.product()->getMap(); // map of pedestals
104  EcalPedestalsMapIterator pedIter; // pedestal iterator
105  EcalPedestals::Item aped; // pedestal object for a single xtal
106 
107  DetId detid(itdg->id());
108 
109  // find pedestals for this channel
110  //LogDebug("EcalUncalibRecHitDebug") << "looking up pedestal for crystal: " << itdg->id();
111  pedIter = pedMap.find(itdg->id());
112  if (pedIter != pedMap.end()) {
113  aped = (*pedIter);
114  } else {
115  edm::LogError("EcalUncalibRecHitWorkerFixedAlphaBetaFit") << "error!! could not find pedestals for channel: ";
116  if (detid.subdetId() == EcalBarrel) {
117  edm::LogError("EcalUncalibRecHitWorkerFixedAlphaBetaFit") << EBDetId(detid);
118  } else {
119  edm::LogError("EcalUncalibRecHitWorkerFixedAlphaBetaFit") << EEDetId(detid);
120  }
121  edm::LogError("EcalUncalibRecHitWorkerFixedAlphaBetaFit") << "\n no uncalib rechit will be made for this digi!";
122  return false;
123  }
124  double pedVec[3];
125  pedVec[0] = aped.mean_x12;
126  pedVec[1] = aped.mean_x6;
127  pedVec[2] = aped.mean_x1;
128 
129  // find gain ratios
130  //LogDebug("EcalUncalibRecHitDebug") << "looking up gainRatios for crystal: " << EBDetId(itdg->id()) ; // FIXME!!!!!!!!
131  gainIter = gainMap.find(itdg->id());
132  if (gainIter != gainMap.end()) {
133  aGain = (*gainIter);
134  } else {
135  edm::LogError("EcalUncalibRecHitWorkerFixedAlphaBetaFit") << "error!! could not find gain ratios for channel: ";
136  if (detid.subdetId() == EcalBarrel) {
137  edm::LogError("EcalUncalibRecHitWorkerFixedAlphaBetaFit") << EBDetId(detid);
138  } else {
139  edm::LogError("EcalUncalibRecHitWorkerFixedAlphaBetaFit") << EEDetId(detid);
140  }
141  edm::LogError("EcalUncalibRecHitWorkerFixedAlphaBetaFit") << "\n no uncalib rechit will be made for this digi!";
142  return false;
143  }
144  double gainRatios[3];
145  gainRatios[0] = 1.;
146  gainRatios[1] = aGain.gain12Over6();
147  gainRatios[2] = aGain.gain6Over1() * aGain.gain12Over6();
148 
149  if (detid.subdetId() == EcalBarrel) {
150  // Define Alpha and Beta either by stored values or by default universal values
151  EBDetId ebDetId(detid);
152  double a, b;
153  if (useAlphaBetaArray_) {
154  if (!alphaBetaValues_[ebDetId.ism() - 1].empty()) {
155  a = alphaBetaValues_[ebDetId.ism() - 1][ebDetId.ic() - 1].first;
156  b = alphaBetaValues_[ebDetId.ism() - 1][ebDetId.ic() - 1].second;
157  if ((a == -1) && (b == -1)) {
158  a = alphaEB_;
159  b = betaEB_;
160  }
161  } else {
162  a = alphaEB_;
163  b = betaEB_;
164  }
165  } else {
166  a = alphaEB_;
167  b = betaEB_;
168  }
170  result.push_back(algoEB_.makeRecHit(*itdg, pedVec, gainRatios, nullptr, nullptr));
171  } else {
172  //FIX ME load in a and b from a file
174  result.push_back(algoEE_.makeRecHit(*itdg, pedVec, gainRatios, nullptr, nullptr));
175  }
176  return true;
177 }
178 
181 
182  psd.addNode(edm::ParameterDescription<double>("alphaEB", 1.138, true) and
183  edm::ParameterDescription<double>("alphaEE", 1.89, true) and
184  edm::ParameterDescription<std::string>("AlphaBetaFilename", "NOFILE", false) and
185  edm::ParameterDescription<double>("betaEB", 1.655, true) and
186  edm::ParameterDescription<double>("MinAmplEndcap", 14.0, true) and
187  edm::ParameterDescription<double>("MinAmplBarrel", 8.0, true) and
188  edm::ParameterDescription<double>("betaEE", 1.4, true) and
189  edm::ParameterDescription<bool>("UseDynamicPedestal", true, true));
190 
191  return psd;
192 }
193 
198  "EcalUncalibRecHitWorkerFixedAlphaBetaFit");
202  "EcalUncalibRecHitWorkerFixedAlphaBetaFit");
ConfigurationDescriptions.h
runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:373
EcalCondObjectContainer::end
const_iterator end() const
Definition: EcalCondObjectContainer.h:76
EcalUncalibRecHitFixedAlphaBetaAlgo::SetDynamicPedestal
void SetDynamicPedestal(bool dyn_pede)
Definition: EcalUncalibRecHitFixedAlphaBetaAlgo.h:415
Handle.h
EcalUncalibRecHitFillDescriptionWorkerFactory.h
MessageLogger.h
ESHandle.h
edm::DataFrameContainer::const_iterator
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
Definition: DataFrameContainer.h:61
EBDetId::ic
int ic() const
get ECAL/crystal number inside SM
Definition: EBDetId.cc:41
EBDetId
Definition: EBDetId.h:17
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
EcalUncalibRecHitWorkerFixedAlphaBetaFit::run
bool run(const edm::Event &evt, const EcalDigiCollection::const_iterator &digi, EcalUncalibratedRecHitCollection &result) override
Definition: EcalUncalibRecHitWorkerFixedAlphaBetaFit.cc:96
EcalUncalibRecHitWorkerFixedAlphaBetaFit::algoEB_
EcalUncalibRecHitFixedAlphaBetaAlgo< EBDataFrame > algoEB_
Definition: EcalUncalibRecHitWorkerFixedAlphaBetaFit.h:42
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
edm::SortedCollection
Definition: SortedCollection.h:49
EcalUncalibratedRecHit.h
EcalUncalibRecHitWorkerFixedAlphaBetaFit::alphaEB_
double alphaEB_
Definition: EcalUncalibRecHitWorkerFixedAlphaBetaFit.h:45
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
EcalUncalibRecHitWorkerFixedAlphaBetaFit::ratiosToken_
edm::ESGetToken< EcalGainRatios, EcalGainRatiosRcd > ratiosToken_
Definition: EcalUncalibRecHitWorkerFixedAlphaBetaFit.h:58
EcalUncalibRecHitWorkerFixedAlphaBetaFit::betaEB_
double betaEB_
Definition: EcalUncalibRecHitWorkerFixedAlphaBetaFit.h:46
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
EcalCondObjectContainer
Definition: EcalCondObjectContainer.h:13
EcalBarrel
Definition: EcalSubdetector.h:10
EcalRecHitCollections.h
edmScanValgrind.buffer
buffer
Definition: edmScanValgrind.py:171
DetId
Definition: DetId.h:17
EcalUncalibRecHitFixedAlphaBetaAlgo::SetMinAmpl
void SetMinAmpl(double ampl)
Definition: EcalUncalibRecHitFixedAlphaBetaAlgo.h:411
MakerMacros.h
EcalUncalibRecHitWorkerFixedAlphaBetaFit::EcalUncalibRecHitWorkerFixedAlphaBetaFit
EcalUncalibRecHitWorkerFixedAlphaBetaFit()
Definition: EcalUncalibRecHitWorkerFixedAlphaBetaFit.h:28
EcalUncalibRecHitWorkerFixedAlphaBetaFit::getAlgoDescription
edm::ParameterSetDescription getAlgoDescription() override
Definition: EcalUncalibRecHitWorkerFixedAlphaBetaFit.cc:179
EcalUncalibRecHitWorkerRunOneDigiBase
Definition: EcalUncalibRecHitWorkerRunOneDigiBase.h:10
EcalUncalibRecHitFixedAlphaBetaAlgo::makeRecHit
EcalUncalibratedRecHit makeRecHit(const C &dataFrame, const double *pedestals, const double *gainRatios, const EcalWeightSet::EcalWeightMatrix **weights, const EcalWeightSet::EcalChi2WeightMatrix **chi2Matrix) override
Compute parameters.
Definition: EcalUncalibRecHitFixedAlphaBetaAlgo.h:118
EcalCondObjectContainer::find
const_iterator find(uint32_t rawId) const
Definition: EcalCondObjectContainer.h:53
EcalUncalibRecHitWorkerFixedAlphaBetaFit::alphaEE_
double alphaEE_
Definition: EcalUncalibRecHitWorkerFixedAlphaBetaFit.h:47
EcalUncalibRecHitWorkerFixedAlphaBetaFit::pedHandle
edm::ESHandle< EcalPedestals > pedHandle
Definition: EcalUncalibRecHitWorkerFixedAlphaBetaFit.h:57
EcalUncalibRecHitWorkerFixedAlphaBetaFit::set
void set(const edm::EventSetup &es) override
Definition: EcalUncalibRecHitWorkerFixedAlphaBetaFit.cc:53
EcalMGPAGainRatio.h
ParameterSetDescription.h
DEFINE_EDM_PLUGIN
#define DEFINE_EDM_PLUGIN(factory, type, name)
Definition: PluginFactory.h:124
b
double b
Definition: hdecay.h:118
EcalMGPAGainRatio::gain12Over6
float gain12Over6() const
Definition: EcalMGPAGainRatio.h:19
EEDetId
Definition: EEDetId.h:14
EcalGainRatiosRcd
Definition: EcalGainRatiosRcd.h:5
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
EcalUncalibRecHitWorkerFixedAlphaBetaFit::alphaBetaValues_
std::vector< std::vector< std::pair< double, double > > > alphaBetaValues_
Definition: EcalUncalibRecHitWorkerFixedAlphaBetaFit.h:50
EcalUncalibRecHitWorkerFixedAlphaBetaFit
Definition: EcalUncalibRecHitWorkerFixedAlphaBetaFit.h:25
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:223
edm::ParameterSet
Definition: ParameterSet.h:47
a
double a
Definition: hdecay.h:119
EcalCondObjectContainer::Item
T Item
Definition: EcalCondObjectContainer.h:15
edmplugin::PluginFactory
Definition: PluginFactory.h:34
EcalPedestalsMapIterator
EcalPedestalsMap::const_iterator EcalPedestalsMapIterator
Definition: EcalPedestals.h:49
FrontierConditions_GlobalTag_cff.file
file
Definition: FrontierConditions_GlobalTag_cff.py:13
edm::EventSetup::getHandle
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:148
EcalUncalibRecHitWorkerFixedAlphaBetaFit::useAlphaBetaArray_
bool useAlphaBetaArray_
Definition: EcalUncalibRecHitWorkerFixedAlphaBetaFit.h:51
EcalUncalibRecHitWorkerFixedAlphaBetaFit::pRatio
edm::ESHandle< EcalGainRatios > pRatio
Definition: EcalUncalibRecHitWorkerFixedAlphaBetaFit.h:56
edm::EventSetup
Definition: EventSetup.h:57
edm::ParameterSetDescription::addNode
ParameterDescriptionNode * addNode(ParameterDescriptionNode const &node)
Definition: ParameterSetDescription.cc:41
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
EcalUncalibRecHitWorkerFactory.h
EcalUncalibRecHitWorkerFixedAlphaBetaFit::betaEE_
double betaEE_
Definition: EcalUncalibRecHitWorkerFixedAlphaBetaFit.h:48
relativeConstraints.empty
bool empty
Definition: relativeConstraints.py:46
EcalMGPAGainRatio::gain6Over1
float gain6Over1() const
Definition: EcalMGPAGainRatio.h:20
EventSetup.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
EcalUncalibRecHitWorkerFixedAlphaBetaFit::algoEE_
EcalUncalibRecHitFixedAlphaBetaAlgo< EEDataFrame > algoEE_
Definition: EcalUncalibRecHitWorkerFixedAlphaBetaFit.h:43
EBDetId::ism
int ism() const
get the ECAL/SM id
Definition: EBDetId.h:59
EcalCondObjectContainer::const_iterator
std::vector< Item >::const_iterator const_iterator
Definition: EcalCondObjectContainer.h:19
mps_fire.result
result
Definition: mps_fire.py:311
ParameterSet.h
EcalPedestalsRcd
Definition: EcalPedestalsRcd.h:5
EcalUncalibRecHitWorkerFixedAlphaBetaFit::pedestalsToken_
edm::ESGetToken< EcalPedestals, EcalPedestalsRcd > pedestalsToken_
Definition: EcalUncalibRecHitWorkerFixedAlphaBetaFit.h:59
EcalUncalibRecHitFixedAlphaBetaAlgo::SetAlphaBeta
void SetAlphaBeta(double alpha, double beta)
Definition: EcalUncalibRecHitFixedAlphaBetaAlgo.h:404
edm::Event
Definition: Event.h:73
EcalUncalibRecHitWorkerFixedAlphaBetaFit::alphabetaFilename_
std::string alphabetaFilename_
Definition: EcalUncalibRecHitWorkerFixedAlphaBetaFit.h:52
edm::ParameterDescription
Definition: ParameterDescription.h:110
edm::ConsumesCollector
Definition: ConsumesCollector.h:45
EcalMGPAGainRatio
Definition: EcalMGPAGainRatio.h:13
EcalUncalibRecHitWorkerFixedAlphaBetaFit.h
EcalUncalibRecHitWorkerFixedAlphaBetaFit::setAlphaBeta
bool setAlphaBeta()
Definition: EcalUncalibRecHitWorkerFixedAlphaBetaFit.cc:66