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 
29 
30 #include <iostream>
31 #include <cmath>
32 #include <fstream>
33 
36 {
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 
56 
57 void
59 {
60  // Gain Ratios
61  LogDebug("EcalUncalibRecHitDebug") << "fetching gainRatios....";
62  es.get<EcalGainRatiosRcd>().get(pRatio);
63  LogDebug("EcalUncalibRecHitDebug") << "done." ;
64 
65  // fetch the pedestals from the cond DB via EventSetup
66  LogDebug("EcalUncalibRecHitDebug") << "fetching pedestals....";
67  es.get<EcalPedestalsRcd>().get( pedHandle );
68  LogDebug("EcalUncalibRecHitDebug") << "done." ;
69 }
70 
71 //Sets the alphaBetaValues_ vectors by the values provided in alphabetaFilename_
72 bool
74  std::ifstream file(alphabetaFilename_.c_str());
75  if (! file.is_open())
76  return false;
77 
78  alphaBetaValues_.resize(36);
79 
80  char buffer[100];
81  int sm, cry,ret;
82  float a,b;
83  std::pair<double,double> p(-1,-1);
84 
85  while( ! file.getline(buffer,100).eof() ){
86  ret=sscanf(buffer,"%d %d %f %f", &sm, &cry, &a, &b);
87  if ((ret!=4)||
88  (sm<=0) ||(sm>36)||
89  (cry<=0)||(cry>1700)){
90  // send warning
91  continue;
92  }
93 
94  if (alphaBetaValues_[sm-1].size()==0){
95  alphaBetaValues_[sm-1].resize(1700,p);
96  }
97  alphaBetaValues_[sm-1][cry-1].first = a;
98  alphaBetaValues_[sm-1][cry-1].second = b;
99 
100  }
101 
102  file.close();
103  return true;
104 }
105 
106 bool
110 {
111 
112  const EcalGainRatioMap& gainMap = pRatio.product()->getMap(); // map of gain ratios
113  EcalGainRatioMap::const_iterator gainIter; // gain iterator
114  EcalMGPAGainRatio aGain; // gain object for a single xtal
115 
116  const EcalPedestalsMap & pedMap = pedHandle.product()->getMap(); // map of pedestals
117  EcalPedestalsMapIterator pedIter; // pedestal iterator
118  EcalPedestals::Item aped; // pedestal object for a single xtal
119 
120  DetId detid( itdg->id() );
121 
122  // find pedestals for this channel
123  //LogDebug("EcalUncalibRecHitDebug") << "looking up pedestal for crystal: " << itdg->id();
124  pedIter = pedMap.find(itdg->id());
125  if( pedIter != pedMap.end() ) {
126  aped = (*pedIter);
127  } else {
128  edm::LogError("EcalUncalibRecHitWorkerFixedAlphaBetaFit") << "error!! could not find pedestals for channel: ";
129  if ( detid.subdetId() == EcalBarrel ) {
130  edm::LogError("EcalUncalibRecHitWorkerFixedAlphaBetaFit") << EBDetId( detid );
131  } else {
132  edm::LogError("EcalUncalibRecHitWorkerFixedAlphaBetaFit") << EEDetId( detid );
133  }
134  edm::LogError("EcalUncalibRecHitWorkerFixedAlphaBetaFit") << "\n no uncalib rechit will be made for this digi!";
135  return false;
136  }
137  double pedVec[3];
138  pedVec[0] = aped.mean_x12;
139  pedVec[1] = aped.mean_x6;
140  pedVec[2] = aped.mean_x1;
141 
142  // find gain ratios
143  //LogDebug("EcalUncalibRecHitDebug") << "looking up gainRatios for crystal: " << EBDetId(itdg->id()) ; // FIXME!!!!!!!!
144  gainIter = gainMap.find(itdg->id());
145  if( gainIter != gainMap.end() ) {
146  aGain = (*gainIter);
147  } else {
148  edm::LogError("EcalUncalibRecHitWorkerFixedAlphaBetaFit") << "error!! could not find gain ratios for channel: ";
149  if ( detid.subdetId() == EcalBarrel ) {
150  edm::LogError("EcalUncalibRecHitWorkerFixedAlphaBetaFit") << EBDetId( detid );
151  } else {
152  edm::LogError("EcalUncalibRecHitWorkerFixedAlphaBetaFit") << EEDetId( detid );
153  }
154  edm::LogError("EcalUncalibRecHitWorkerFixedAlphaBetaFit") << "\n no uncalib rechit will be made for this digi!";
155  return false;
156  }
157  double gainRatios[3];
158  gainRatios[0] = 1.;
159  gainRatios[1] = aGain.gain12Over6();
160  gainRatios[2] = aGain.gain6Over1()*aGain.gain12Over6();
161 
162  if ( detid.subdetId() == EcalBarrel ) {
163  // Define Alpha and Beta either by stored values or by default universal values
164  EBDetId ebDetId( detid );
165  double a, b;
166  if (useAlphaBetaArray_){
167  if ( alphaBetaValues_[ ebDetId.ism()-1 ].size() != 0 ) {
168  a = alphaBetaValues_[ebDetId.ism()-1][ebDetId.ic()-1].first;
169  b = alphaBetaValues_[ebDetId.ism()-1][ebDetId.ic()-1].second;
170  if ( ( a == -1 ) && ( b == -1 ) ) {
171  a = alphaEB_;
172  b = betaEB_;
173  }
174  } else {
175  a = alphaEB_;
176  b = betaEB_;
177  }
178  } else {
179  a = alphaEB_;
180  b = betaEB_;
181  }
182  algoEB_.SetAlphaBeta(a,b);
183  result.push_back( algoEB_.makeRecHit( *itdg, pedVec, gainRatios, 0, 0) );
184  } else {
185  //FIX ME load in a and b from a file
187  result.push_back( algoEE_.makeRecHit(*itdg, pedVec, gainRatios, 0 , 0) );
188  }
189  return true;
190 }
191 
194 
196 
197  psd.addNode(edm::ParameterDescription<double>("alphaEB", 1.138, true) and
198  edm::ParameterDescription<double>("alphaEE", 1.89, true) and
199  edm::ParameterDescription<std::string>("AlphaBetaFilename", "NOFILE", false) and
200  edm::ParameterDescription<double>("betaEB", 1.655, true) and
201  edm::ParameterDescription<double>("MinAmplEndcap", 14.0, true) and
202  edm::ParameterDescription<double>("MinAmplBarrel", 8.0, true) and
203  edm::ParameterDescription<double>("betaEE", 1.4, true) and
204  edm::ParameterDescription<bool>("UseDynamicPedestal", true, true) );
205 
206  return psd;
207 }
208 
#define LogDebug(id)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
tuple ret
prodAgent to be discontinued
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)
ParameterDescriptionNode * addNode(ParameterDescriptionNode const &node)
EcalUncalibRecHitFixedAlphaBetaAlgo< EEDataFrame > algoEE_
int ism() const
get the ECAL/SM id
Definition: EBDetId.h:61
virtual EcalUncalibratedRecHit makeRecHit(const C &dataFrame, const double *pedestals, const double *gainRatios, const EcalWeightSet::EcalWeightMatrix **weights, const EcalWeightSet::EcalChi2WeightMatrix **chi2Matrix)
Compute parameters.
tuple result
Definition: mps_fire.py:83
EcalPedestalsMap::const_iterator EcalPedestalsMapIterator
Definition: EcalPedestals.h:52
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:18
const T & get() const
Definition: EventSetup.h:56
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.