CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalUncalibRecHitWorkerFixedAlphaBetaFit.cc
Go to the documentation of this file.
1 
9 
14 
16 
19 
22 
26 
27 #include <iostream>
28 #include <cmath>
29 #include <fstream>
30 
33 {
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","NOFILE");
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 
53 
54 void
56 {
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_
69 bool
71  std::ifstream file(alphabetaFilename_.c_str());
72  if (! file.is_open())
73  return false;
74 
75  alphaBetaValues_.resize(36);
76 
77  char buffer[100];
78  int sm, cry,ret;
79  float a,b;
80  std::pair<double,double> p(-1,-1);
81 
82  while( ! file.getline(buffer,100).eof() ){
83  ret=sscanf(buffer,"%d %d %f %f", &sm, &cry, &a, &b);
84  if ((ret!=4)||
85  (sm<=0) ||(sm>36)||
86  (cry<=0)||(cry>1700)){
87  // send warning
88  continue;
89  }
90 
91  if (alphaBetaValues_[sm-1].size()==0){
92  alphaBetaValues_[sm-1].resize(1700,p);
93  }
94  alphaBetaValues_[sm-1][cry-1].first = a;
95  alphaBetaValues_[sm-1][cry-1].second = b;
96 
97  }
98 
99  file.close();
100  return true;
101 }
102 
103 bool
107 {
108 
109  const EcalGainRatioMap& gainMap = pRatio.product()->getMap(); // map of gain ratios
110  EcalGainRatioMap::const_iterator gainIter; // gain iterator
111  EcalMGPAGainRatio aGain; // gain object for a single xtal
112 
113  const EcalPedestalsMap & pedMap = pedHandle.product()->getMap(); // map of pedestals
114  EcalPedestalsMapIterator pedIter; // pedestal iterator
115  EcalPedestals::Item aped; // pedestal object for a single xtal
116 
117  DetId detid( itdg->id() );
118 
119  // find pedestals for this channel
120  //LogDebug("EcalUncalibRecHitDebug") << "looking up pedestal for crystal: " << itdg->id();
121  pedIter = pedMap.find(itdg->id());
122  if( pedIter != pedMap.end() ) {
123  aped = (*pedIter);
124  } else {
125  edm::LogError("EcalUncalibRecHitWorkerFixedAlphaBetaFit") << "error!! could not find pedestals for channel: ";
126  if ( detid.subdetId() == EcalBarrel ) {
127  edm::LogError("EcalUncalibRecHitWorkerFixedAlphaBetaFit") << EBDetId( detid );
128  } else {
129  edm::LogError("EcalUncalibRecHitWorkerFixedAlphaBetaFit") << EEDetId( detid );
130  }
131  edm::LogError("EcalUncalibRecHitWorkerFixedAlphaBetaFit") << "\n no uncalib rechit will be made for this digi!";
132  return false;
133  }
134  double pedVec[3];
135  pedVec[0] = aped.mean_x12;
136  pedVec[1] = aped.mean_x6;
137  pedVec[2] = aped.mean_x1;
138 
139  // find gain ratios
140  //LogDebug("EcalUncalibRecHitDebug") << "looking up gainRatios for crystal: " << EBDetId(itdg->id()) ; // FIXME!!!!!!!!
141  gainIter = gainMap.find(itdg->id());
142  if( gainIter != gainMap.end() ) {
143  aGain = (*gainIter);
144  } else {
145  edm::LogError("EcalUncalibRecHitWorkerFixedAlphaBetaFit") << "error!! could not find gain ratios for channel: ";
146  if ( detid.subdetId() == EcalBarrel ) {
147  edm::LogError("EcalUncalibRecHitWorkerFixedAlphaBetaFit") << EBDetId( detid );
148  } else {
149  edm::LogError("EcalUncalibRecHitWorkerFixedAlphaBetaFit") << EEDetId( detid );
150  }
151  edm::LogError("EcalUncalibRecHitWorkerFixedAlphaBetaFit") << "\n no uncalib rechit will be made for this digi!";
152  return false;
153  }
154  double gainRatios[3];
155  gainRatios[0] = 1.;
156  gainRatios[1] = aGain.gain12Over6();
157  gainRatios[2] = aGain.gain6Over1()*aGain.gain12Over6();
158 
159  if ( detid.subdetId() == EcalBarrel ) {
160  // Define Alpha and Beta either by stored values or by default universal values
161  EBDetId ebDetId( detid );
162  double a, b;
163  if (useAlphaBetaArray_){
164  if ( alphaBetaValues_[ ebDetId.ism()-1 ].size() != 0 ) {
165  a = alphaBetaValues_[ebDetId.ism()-1][ebDetId.ic()-1].first;
166  b = alphaBetaValues_[ebDetId.ism()-1][ebDetId.ic()-1].second;
167  if ( ( a == -1 ) && ( b == -1 ) ) {
168  a = alphaEB_;
169  b = betaEB_;
170  }
171  } else {
172  a = alphaEB_;
173  b = betaEB_;
174  }
175  } else {
176  a = alphaEB_;
177  b = betaEB_;
178  }
179  algoEB_.SetAlphaBeta(a,b);
180  result.push_back( algoEB_.makeRecHit( *itdg, pedVec, gainRatios, 0, 0) );
181  } else {
182  //FIX ME load in a and b from a file
184  result.push_back( algoEE_.makeRecHit(*itdg, pedVec, gainRatios, 0 , 0) );
185  }
186  return true;
187 }
188 
#define LogDebug(id)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
std::vector< std::vector< std::pair< double, double > > > alphaBetaValues_
void push_back(T const &t)
EcalUncalibRecHitFixedAlphaBetaAlgo< EEDataFrame > algoEE_
int ism() const
get the ECAL/SM id
Definition: EBDetId.h:62
virtual EcalUncalibratedRecHit makeRecHit(const C &dataFrame, const double *pedestals, const double *gainRatios, const EcalWeightSet::EcalWeightMatrix **weights, const EcalWeightSet::EcalChi2WeightMatrix **chi2Matrix)
Compute parameters.
EcalPedestalsMap::const_iterator EcalPedestalsMapIterator
Definition: EcalPedestals.h:37
tuple result
Definition: query.py:137
float gain6Over1() const
bool run(const edm::Event &evt, const EcalDigiCollection::const_iterator &digi, EcalUncalibratedRecHitCollection &result)
int ic() const
get ECAL/crystal number inside SM
Definition: EBDetId.cc:46
EcalUncalibRecHitFixedAlphaBetaAlgo< EBDataFrame > algoEB_
Definition: DetId.h:20
const T & get() const
Definition: EventSetup.h:55
std::vector< Item >::const_iterator const_iterator
double b
Definition: hdecay.h:120
float gain12Over6() const
double a
Definition: hdecay.h:121
const_iterator find(uint32_t rawId) const
#define DEFINE_EDM_PLUGIN(factory, type, name)
const_iterator end() const
tuple size
Write out results.