CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
SumHistoCalibration Class Reference
Inheritance diagram for SumHistoCalibration:
edm::EDAnalyzer

Public Member Functions

 SumHistoCalibration (const edm::ParameterSet &)
 
 ~SumHistoCalibration ()
 
- Public Member Functions inherited from edm::EDAnalyzer
 EDAnalyzer ()
 
std::string workerType () const
 
virtual ~EDAnalyzer ()
 

Private Member Functions

virtual void analyze (const edm::Event &, const edm::EventSetup &)
 
virtual void beginJob ()
 
virtual void endJob ()
 
TrackProbabilityCalibrationfromXml (edm::FileInPath xmlCalibration)
 

Private Attributes

edm::ParameterSet config
 
TrackProbabilityCalibrationm_calibration [2]
 
bool m_sum2D
 
bool m_sum3D
 
std::vector< std::string > m_xmlilelist2d
 
std::vector< std::string > m_xmlilelist3d
 
unsigned int maxLoop
 
unsigned int minLoop
 

Additional Inherited Members

- Public Types inherited from edm::EDAnalyzer
typedef EDAnalyzer ModuleType
 
typedef WorkerT< EDAnalyzerWorkerType
 
- Static Public Member Functions inherited from edm::EDAnalyzer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDAnalyzer
CurrentProcessingContext const * currentContext () const
 

Detailed Description

Definition at line 81 of file SumHistoCalibration.cc.

Constructor & Destructor Documentation

SumHistoCalibration::SumHistoCalibration ( const edm::ParameterSet iConfig)
explicit

Definition at line 107 of file SumHistoCalibration.cc.

References edm::ParameterSet::getParameter(), m_sum2D, m_sum3D, m_xmlilelist2d, and m_xmlilelist3d.

107  :config(iConfig)
108 {
109  m_xmlilelist2d = iConfig.getParameter<std::vector<std::string> >("xmlfiles2d");
110  m_xmlilelist3d = iConfig.getParameter<std::vector<std::string> >("xmlfiles3d");
111  m_sum2D = iConfig.getParameter<bool>("sum2D");
112  m_sum3D = iConfig.getParameter<bool>("sum3D");
113 }
T getParameter(std::string const &) const
std::vector< std::string > m_xmlilelist2d
std::vector< std::string > m_xmlilelist3d
edm::ParameterSet config
SumHistoCalibration::~SumHistoCalibration ( )

Definition at line 116 of file SumHistoCalibration.cc.

117 {
118 }

Member Function Documentation

void SumHistoCalibration::analyze ( const edm::Event iEvent,
const edm::EventSetup iSetup 
)
privatevirtual

Implements edm::EDAnalyzer.

Definition at line 122 of file SumHistoCalibration.cc.

References dt_offlineAnalysis_common_cff::reco.

123 {
124  using namespace edm;
125  using namespace reco;
126  using namespace std;
127 
128 }
void SumHistoCalibration::beginJob ( void  )
privatevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 141 of file SumHistoCalibration.cc.

References TrackProbabilityCalibration::Entry::category, TrackProbabilityCalibration::data, ExpressReco_HICollisions_FallBack::e, fromXml(), TrackProbabilityCalibration::Entry::histogram, i, j, m_calibration, m_sum2D, m_sum3D, m_xmlilelist2d, m_xmlilelist3d, maxLoop, and minLoop.

142 {
143  if(m_sum2D && m_sum3D){minLoop = 0; maxLoop =1;}
144  if(m_sum2D && !m_sum3D){minLoop = 0; maxLoop =0;}
145  if(!m_sum2D && m_sum3D){minLoop = 1; maxLoop =1;}
146  using namespace edm;
149 
150  const TrackProbabilityCalibration * ca[2];
153  ca[0] = fromXml(fip);
154  ca[1] = fromXml(fip2);
155 
156  for(unsigned int i=minLoop;i <=maxLoop ;i++)
157  for(unsigned int j=0;j<ca[i]->data.size() ; j++)
158  {
160  e.category=ca[i]->data[j].category;
161  e.histogram=ca[i]->data[j].histogram;
162  m_calibration[i]->data.push_back(e);
163  }
164 
165  delete ca[0];
166  delete ca[1];
167 
168 
169 
170 
171 
172 
173 
174 
175 
176 
177 
178 
179 
180 }
int i
Definition: DBlmapReader.cc:9
std::vector< std::string > m_xmlilelist2d
std::vector< std::string > m_xmlilelist3d
int j
Definition: DBlmapReader.cc:9
TrackProbabilityCalibration * fromXml(edm::FileInPath xmlCalibration)
PhysicsTools::Calibration::HistogramF histogram
TrackProbabilityCalibration * m_calibration[2]
void SumHistoCalibration::endJob ( void  )
privatevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 217 of file SumHistoCalibration.cc.

References cond::service::PoolDBOutputService::beginOfTime(), config, cond::service::PoolDBOutputService::createNewIOV(), TrackProbabilityCalibration::data, cond::service::PoolDBOutputService::endOfTime(), fromXml(), edm::ParameterSet::getParameter(), edm::Service< T >::isAvailable(), j, gen::k, m_calibration, m_sum2D, m_sum3D, m_xmlilelist2d, m_xmlilelist3d, indexGen::ofile, dt_offlineAnalysis_common_cff::reco, and findQualityFiles::size.

217  {
218 
219 
220  using namespace edm;
221  using namespace reco;
222  using namespace std;
223 
224 
225 
226 
227  if(m_sum3D){
228  for(unsigned int itFile =1; itFile< m_xmlilelist3d.size(); itFile++){
229  edm::FileInPath fip(m_xmlilelist3d[itFile]);
230  const TrackProbabilityCalibration *ca = fromXml(fip);
231  for(unsigned int j=0;j<ca->data.size() ; j++)
232  {
233  for(int k = 0; k< m_calibration[0]->data[j].histogram.numberOfBins(); k++){
234  m_calibration[0]->data[j].histogram.setBinContent(k, ca->data[j].histogram.binContent(k)
235  + m_calibration[0]->data[j].histogram.binContent(k));
236  }
237  }
238  delete ca;
239  }
240  }
241  if(m_sum2D){
242  for(unsigned int itFile =1; itFile< m_xmlilelist2d.size(); itFile++){
243  edm::FileInPath fip(m_xmlilelist2d[itFile]);
245  for(unsigned int j=0;j<ca->data.size() ; j++)
246  {
247  for(int k = 0; k< m_calibration[1]->data[j].histogram.numberOfBins(); k++){
248  m_calibration[1]->data[j].histogram.setBinContent(k,ca->data[j].histogram.binContent(k)
249  + m_calibration[1]->data[j].histogram.binContent(k));
250  }
251  }
252  delete ca;
253  }
254  }
255 
256 
257 
258 
259 
260 
261 
262 
263 
264 
265 
266 
267 
268 
269  if(config.getParameter<bool>("writeToDB"))
270  {
272  if( !mydbservice.isAvailable() ) return;
273  //mydbservice->createNewIOV<TrackProbabilityCalibration>(m_calibration[0], mydbservice->endOfTime(),"BTagTrackProbability3DRcd");
274  //mydbservice->createNewIOV<TrackProbabilityCalibration>(m_calibration[1], mydbservice->endOfTime(),"BTagTrackProbability2DRcd");
275  mydbservice->createNewIOV<TrackProbabilityCalibration>(m_calibration[0], mydbservice->beginOfTime(), mydbservice->endOfTime(),"BTagTrackProbability3DRcd");
276  mydbservice->createNewIOV<TrackProbabilityCalibration>(m_calibration[1], mydbservice->beginOfTime(), mydbservice->endOfTime(),"BTagTrackProbability2DRcd");
277 
278  }
279 
280 
281  if(config.getParameter<bool>("writeToRootXML"))
282  {
283  std::ofstream of2("2d.xml");
284  TBufferXML b2(TBuffer::kWrite);
285  of2 << b2.ConvertToXML(const_cast<void*>(static_cast<const void*>(m_calibration[1])),
286  TClass::GetClass("TrackProbabilityCalibration"),
287  kTRUE, kFALSE);
288  of2.close();
289  std::ofstream of3("3d.xml");
290  TBufferXML b3(TBuffer::kWrite);
291  of3 << b3.ConvertToXML(const_cast<void*>(static_cast<const void*>(m_calibration[0])),
292  TClass::GetClass("TrackProbabilityCalibration"),
293  kTRUE, kFALSE);
294  of3.close();
295  }
296 
297 
298  if(config.getParameter<bool>("writeToBinary"))
299  {
300  std::ofstream ofile("2d.dat");
301  MyTBuffer buffer(TBuffer::kWrite);
302  buffer.StreamObject(const_cast<void*>(static_cast<const void*>(m_calibration[1])),
303  TClass::GetClass("TrackProbabilityCalibration"));
304  Int_t size = buffer.Length();
305  ofile.write(buffer.Buffer(),size);
306  ofile.close();
307 
308  std::ofstream ofile3("3d.dat");
309  MyTBuffer buffer3(TBuffer::kWrite);
310  buffer3.StreamObject(const_cast<void*>(static_cast<const void*>(m_calibration[0])),
311  TClass::GetClass("TrackProbabilityCalibration"));
312  Int_t size3 = buffer3.Length();
313  ofile3.write(buffer3.Buffer(),size3);
314  ofile3.close();
315  }
316 
317 
318 
319 
320 
321 }
T getParameter(std::string const &) const
std::vector< std::string > m_xmlilelist2d
TBufferFile MyTBuffer
std::vector< std::string > m_xmlilelist3d
bool isAvailable() const
Definition: Service.h:47
int j
Definition: DBlmapReader.cc:9
edm::ParameterSet config
TrackProbabilityCalibration * fromXml(edm::FileInPath xmlCalibration)
void createNewIOV(T *firstPayloadObj, cond::Time_t firstSinceTime, cond::Time_t firstTillTime, const std::string &recordName, bool withlogging=false)
int k[5][pyjets_maxn]
tuple ofile
Definition: indexGen.py:101
TrackProbabilityCalibration * m_calibration[2]
tuple size
Write out results.
TrackProbabilityCalibration * SumHistoCalibration::fromXml ( edm::FileInPath  xmlCalibration)
private

Definition at line 182 of file SumHistoCalibration.cc.

References edm::hlt::Exception, edm::FileInPath::fullPath(), and xmlFile().

Referenced by beginJob(), and endJob().

183 {
184  std::ifstream xmlFile(xmlCalibration.fullPath().c_str());
185  if (!xmlFile.good())
186  throw cms::Exception("BTauFakeMVAJetTagConditions")
187  << "File \"" << xmlCalibration.fullPath()
188  << "\" could not be opened for reading."
189  << std::endl;
190  std::ostringstream ss;
191  ss << xmlFile.rdbuf();
192  xmlFile.close();
193  TClass *classType = 0;
194  void *ptr = TBufferXML(TBuffer::kRead).ConvertFromXMLAny(
195  ss.str().c_str(), &classType, kTRUE, kFALSE);
196  if (!ptr)
197  throw cms::Exception("SumHistoCalibration")
198  << "Unknown error parsing XML serialization"
199  << std::endl;
200 
201  if (std::strcmp(classType->GetName(),
202  "TrackProbabilityCalibration")) {
203  classType->Destructor(ptr);
204  throw cms::Exception("SumHistoCalibration")
205  << "Serialized object has wrong C++ type."
206  << std::endl;
207  }
208 
209  return static_cast<TrackProbabilityCalibration*>(ptr);
210 }
bool xmlFile(const std::string fParam)
std::string fullPath() const
Definition: FileInPath.cc:170

Member Data Documentation

edm::ParameterSet SumHistoCalibration::config
private

Definition at line 91 of file SumHistoCalibration.cc.

Referenced by endJob().

TrackProbabilityCalibration* SumHistoCalibration::m_calibration[2]
private

Definition at line 101 of file SumHistoCalibration.cc.

Referenced by beginJob(), and endJob().

bool SumHistoCalibration::m_sum2D
private

Definition at line 98 of file SumHistoCalibration.cc.

Referenced by beginJob(), endJob(), and SumHistoCalibration().

bool SumHistoCalibration::m_sum3D
private

Definition at line 99 of file SumHistoCalibration.cc.

Referenced by beginJob(), endJob(), and SumHistoCalibration().

std::vector<std::string> SumHistoCalibration::m_xmlilelist2d
private

Definition at line 96 of file SumHistoCalibration.cc.

Referenced by beginJob(), endJob(), and SumHistoCalibration().

std::vector<std::string> SumHistoCalibration::m_xmlilelist3d
private

Definition at line 97 of file SumHistoCalibration.cc.

Referenced by beginJob(), endJob(), and SumHistoCalibration().

unsigned int SumHistoCalibration::maxLoop
private

Definition at line 100 of file SumHistoCalibration.cc.

Referenced by beginJob().

unsigned int SumHistoCalibration::minLoop
private

Definition at line 100 of file SumHistoCalibration.cc.

Referenced by beginJob().