CMS 3D CMS Logo

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