CMS 3D CMS Logo

EcalUncalibRecHitWorkerFixedAlphaBetaFit.cc
Go to the documentation of this file.
1 
27 
28 #include <cmath>
29 #include <fstream>
30 #include <iostream>
31 
33 public:
37 
38  void set(const edm::EventSetup& es) override;
39  bool run(const edm::Event& evt,
42 
44 
45 private:
46  double AmplThrEB_;
47  double AmplThrEE_;
48 
51 
52  double alphaEB_;
53  double betaEB_;
54  double alphaEE_;
55  double betaEE_;
56  std::vector<std::vector<std::pair<double, double> > >
57  alphaBetaValues_; // List of alpha and Beta values [SM#][CRY#](alpha, beta)
60 
61  bool setAlphaBeta(); // Sets the alphaBetaValues_ vectors by the values provided in alphabetaFilename_
62 
67 };
68 
72  ratiosToken_(c.esConsumes<EcalGainRatios, EcalGainRatiosRcd>()),
73  pedestalsToken_(c.esConsumes<EcalPedestals, EcalPedestalsRcd>()) {
74  alphaEB_ = ps.getParameter<double>("alphaEB");
75  betaEB_ = ps.getParameter<double>("betaEB");
76  alphaEE_ = ps.getParameter<double>("alphaEE");
77  betaEE_ = ps.getParameter<double>("betaEE");
78 
79  alphabetaFilename_ = ps.getUntrackedParameter<std::string>("AlphaBetaFilename");
80  useAlphaBetaArray_ = setAlphaBeta(); // set crystalwise values of alpha and beta
81  if (!useAlphaBetaArray_) {
82  edm::LogInfo("EcalUncalibRecHitError") << " No alfa-beta file found. Using the deafult values.";
83  }
84 
85  algoEB_.SetMinAmpl(ps.getParameter<double>("MinAmplBarrel"));
86  algoEE_.SetMinAmpl(ps.getParameter<double>("MinAmplEndcap"));
87 
88  bool dyn_pede = ps.getParameter<bool>("UseDynamicPedestal");
89  algoEB_.SetDynamicPedestal(dyn_pede);
90  algoEE_.SetDynamicPedestal(dyn_pede);
91 }
92 
94  // Gain Ratios
95  LogDebug("EcalUncalibRecHitDebug") << "fetching gainRatios....";
97  LogDebug("EcalUncalibRecHitDebug") << "done.";
98 
99  // fetch the pedestals from the cond DB via EventSetup
100  LogDebug("EcalUncalibRecHitDebug") << "fetching pedestals....";
102  LogDebug("EcalUncalibRecHitDebug") << "done.";
103 }
104 
105 //Sets the alphaBetaValues_ vectors by the values provided in alphabetaFilename_
107  std::ifstream file(alphabetaFilename_.c_str());
108  if (!file.is_open())
109  return false;
110 
111  alphaBetaValues_.resize(36);
112 
113  char buffer[100];
114  int sm, cry, ret;
115  float a, b;
116  std::pair<double, double> p(-1, -1);
117 
118  while (!file.getline(buffer, 100).eof()) {
119  ret = sscanf(buffer, "%d %d %f %f", &sm, &cry, &a, &b);
120  if ((ret != 4) || (sm <= 0) || (sm > 36) || (cry <= 0) || (cry > 1700)) {
121  // send warning
122  continue;
123  }
124 
125  if (alphaBetaValues_[sm - 1].empty()) {
126  alphaBetaValues_[sm - 1].resize(1700, p);
127  }
128  alphaBetaValues_[sm - 1][cry - 1].first = a;
129  alphaBetaValues_[sm - 1][cry - 1].second = b;
130  }
131 
132  file.close();
133  return true;
134 }
135 
139  const EcalGainRatioMap& gainMap = pRatio.product()->getMap(); // map of gain ratios
140  EcalGainRatioMap::const_iterator gainIter; // gain iterator
141  EcalMGPAGainRatio aGain; // gain object for a single xtal
142 
143  const EcalPedestalsMap& pedMap = pedHandle.product()->getMap(); // map of pedestals
144  EcalPedestalsMapIterator pedIter; // pedestal iterator
145  EcalPedestals::Item aped; // pedestal object for a single xtal
146 
147  DetId detid(itdg->id());
148 
149  // find pedestals for this channel
150  //LogDebug("EcalUncalibRecHitDebug") << "looking up pedestal for crystal: " << itdg->id();
151  pedIter = pedMap.find(itdg->id());
152  if (pedIter != pedMap.end()) {
153  aped = (*pedIter);
154  } else {
155  edm::LogError("EcalUncalibRecHitWorkerFixedAlphaBetaFit") << "error!! could not find pedestals for channel: ";
156  if (detid.subdetId() == EcalBarrel) {
157  edm::LogError("EcalUncalibRecHitWorkerFixedAlphaBetaFit") << EBDetId(detid);
158  } else {
159  edm::LogError("EcalUncalibRecHitWorkerFixedAlphaBetaFit") << EEDetId(detid);
160  }
161  edm::LogError("EcalUncalibRecHitWorkerFixedAlphaBetaFit") << "\n no uncalib rechit will be made for this digi!";
162  return false;
163  }
164  double pedVec[3];
165  pedVec[0] = aped.mean_x12;
166  pedVec[1] = aped.mean_x6;
167  pedVec[2] = aped.mean_x1;
168 
169  // find gain ratios
170  //LogDebug("EcalUncalibRecHitDebug") << "looking up gainRatios for crystal: " << EBDetId(itdg->id()) ; // FIXME!!!!!!!!
171  gainIter = gainMap.find(itdg->id());
172  if (gainIter != gainMap.end()) {
173  aGain = (*gainIter);
174  } else {
175  edm::LogError("EcalUncalibRecHitWorkerFixedAlphaBetaFit") << "error!! could not find gain ratios for channel: ";
176  if (detid.subdetId() == EcalBarrel) {
177  edm::LogError("EcalUncalibRecHitWorkerFixedAlphaBetaFit") << EBDetId(detid);
178  } else {
179  edm::LogError("EcalUncalibRecHitWorkerFixedAlphaBetaFit") << EEDetId(detid);
180  }
181  edm::LogError("EcalUncalibRecHitWorkerFixedAlphaBetaFit") << "\n no uncalib rechit will be made for this digi!";
182  return false;
183  }
184  double gainRatios[3];
185  gainRatios[0] = 1.;
186  gainRatios[1] = aGain.gain12Over6();
187  gainRatios[2] = aGain.gain6Over1() * aGain.gain12Over6();
188 
189  if (detid.subdetId() == EcalBarrel) {
190  // Define Alpha and Beta either by stored values or by default universal values
191  EBDetId ebDetId(detid);
192  double a, b;
193  if (useAlphaBetaArray_) {
194  if (!alphaBetaValues_[ebDetId.ism() - 1].empty()) {
195  a = alphaBetaValues_[ebDetId.ism() - 1][ebDetId.ic() - 1].first;
196  b = alphaBetaValues_[ebDetId.ism() - 1][ebDetId.ic() - 1].second;
197  if ((a == -1) && (b == -1)) {
198  a = alphaEB_;
199  b = betaEB_;
200  }
201  } else {
202  a = alphaEB_;
203  b = betaEB_;
204  }
205  } else {
206  a = alphaEB_;
207  b = betaEB_;
208  }
210  result.push_back(algoEB_.makeRecHit(*itdg, pedVec, gainRatios, nullptr, nullptr));
211  } else {
212  //FIX ME load in a and b from a file
214  result.push_back(algoEE_.makeRecHit(*itdg, pedVec, gainRatios, nullptr, nullptr));
215  }
216  return true;
217 }
218 
221 
222  psd.addNode(edm::ParameterDescription<double>("alphaEB", 1.138, true) and
223  edm::ParameterDescription<double>("alphaEE", 1.89, true) and
224  edm::ParameterDescription<std::string>("AlphaBetaFilename", "NOFILE", false) and
225  edm::ParameterDescription<double>("betaEB", 1.655, true) and
226  edm::ParameterDescription<double>("MinAmplEndcap", 14.0, true) and
227  edm::ParameterDescription<double>("MinAmplBarrel", 8.0, true) and
228  edm::ParameterDescription<double>("betaEE", 1.4, true) and
229  edm::ParameterDescription<bool>("UseDynamicPedestal", true, true));
230 
231  return psd;
232 }
233 
238  "EcalUncalibRecHitWorkerFixedAlphaBetaFit");
242  "EcalUncalibRecHitWorkerFixedAlphaBetaFit");
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
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:130
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:120
float gain6Over1() const
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
double a
Definition: hdecay.h:121
#define DEFINE_EDM_PLUGIN(factory, type, name)
const_iterator end() const
std::vector< std::vector< std::pair< double, double > > > alphaBetaValues_
#define LogDebug(id)