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");
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
ret
prodAgent to be discontinued
ParameterDescriptionNode * addNode(ParameterDescriptionNode const &node)
edm::ESGetToken< EcalPedestals, EcalPedestalsRcd > pedestalsToken_
EcalUncalibratedRecHit makeRecHit(const C &dataFrame, const double *pedestals, const double *gainRatios, const EcalWeightSet::EcalWeightMatrix **weights, const EcalWeightSet::EcalChi2WeightMatrix **chi2Matrix) override
Compute parameters.
Log< level::Error, false > LogError
EcalUncalibRecHitFixedAlphaBetaAlgo< EEDataFrame > algoEE_
T getUntrackedParameter(std::string const &, T const &) const
EcalPedestalsMap::const_iterator EcalPedestalsMapIterator
Definition: EcalPedestals.h:49
int ic() const
get ECAL/crystal number inside SM
Definition: EBDetId.cc:41
int ism() const
get the ECAL/SM id
Definition: EBDetId.h:59
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:151
edm::ESGetToken< EcalGainRatios, EcalGainRatiosRcd > ratiosToken_
const_iterator find(uint32_t rawId) const
EcalUncalibRecHitFixedAlphaBetaAlgo< EBDataFrame > algoEB_
Log< level::Info, false > LogInfo
float gain12Over6() const
Definition: DetId.h:17
bool run(const edm::Event &evt, const EcalDigiCollection::const_iterator &digi, EcalUncalibratedRecHitCollection &result) override
std::vector< Item >::const_iterator const_iterator
double b
Definition: hdecay.h:118
float gain6Over1() const
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
double a
Definition: hdecay.h:119
#define DEFINE_EDM_PLUGIN(factory, type, name)
const_iterator end() const
std::vector< std::vector< std::pair< double, double > > > alphaBetaValues_
#define LogDebug(id)