Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:34:41

0001 //
0002 // Original Author:  Yetkin Yilmaz
0003 //         Created:  Wed May  2 21:41:30 EDT 2007
0004 //
0005 //
0006 
0007 // system include files
0008 #include <iostream>
0009 #include <fstream>
0010 #include <sstream>
0011 #include <vector>
0012 #include <string>
0013 
0014 // user include files
0015 #include "FWCore/Framework/interface/ESProducer.h"
0016 #include "FWCore/Framework/interface/EventSetup.h"
0017 #include "FWCore/Framework/interface/MakerMacros.h"
0018 #include "FWCore/Framework/interface/SourceFactory.h"
0019 #include "FWCore/Framework/interface/EventSetupRecordIntervalFinder.h"
0020 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0021 #include "CondFormats/DataRecord/interface/HeavyIonRcd.h"
0022 #include "CondFormats/HIObjects/interface/CentralityTable.h"
0023 
0024 using namespace std;
0025 
0026 //
0027 // class decleration
0028 //
0029 
0030 class HiTrivialConditionRetriever : public edm::ESProducer, public edm::EventSetupRecordIntervalFinder {
0031 public:
0032   HiTrivialConditionRetriever(const edm::ParameterSet&);
0033 
0034 protected:
0035   //overriding from ContextRecordIntervalFinder
0036   void setIntervalFor(const edm::eventsetup::EventSetupRecordKey&,
0037                       const edm::IOVSyncValue&,
0038                       edm::ValidityInterval&) override;
0039 
0040 private:
0041   virtual std::unique_ptr<CentralityTable> produceTable(const HeavyIonRcd&);
0042   void printBin(const CentralityTable::CBin*);
0043 
0044   // ----------member data ---------------------------
0045 
0046   int verbose_;
0047   string inputFileName_;
0048 };
0049 
0050 //
0051 // constants, enums and typedefs
0052 //
0053 
0054 //
0055 // static data member definitions
0056 //
0057 
0058 //
0059 // constructors and destructor
0060 //
0061 HiTrivialConditionRetriever::HiTrivialConditionRetriever(const edm::ParameterSet& iConfig) {
0062   setWhatProduced(this, &HiTrivialConditionRetriever::produceTable);
0063   findingRecord<HeavyIonRcd>();
0064 
0065   //now do what ever initialization is needed
0066   verbose_ = iConfig.getUntrackedParameter<int>("verbosity", 1);
0067   inputFileName_ = iConfig.getParameter<string>("inputFile");
0068 }
0069 
0070 std::unique_ptr<CentralityTable> HiTrivialConditionRetriever::produceTable(const HeavyIonRcd&) {
0071   auto CT = std::make_unique<CentralityTable>();
0072 
0073   // Get values from text file
0074   ifstream in(edm::FileInPath(inputFileName_).fullPath().c_str());
0075   string line;
0076 
0077   int i = 0;
0078   while (getline(in, line)) {
0079     if (line.empty() || line[0] == '#') {
0080       continue;
0081     }
0082     CentralityTable::CBin thisBin;
0083     CT->m_table.push_back(thisBin);
0084     istringstream ss(line);
0085     ss >> CT->m_table[i].bin_edge >> CT->m_table[i].n_part.mean >> CT->m_table[i].n_part.var >>
0086         CT->m_table[i].n_coll.mean >> CT->m_table[i].n_coll.var >> CT->m_table[i].n_hard.mean >>
0087         CT->m_table[i].n_hard.var >> CT->m_table[i].b.mean >> CT->m_table[i].b.var;
0088     i++;
0089   }
0090 
0091   return CT;
0092 }
0093 
0094 void HiTrivialConditionRetriever::printBin(const CentralityTable::CBin* thisBin) {
0095   cout << "HF Cut = " << thisBin->bin_edge << endl;
0096   cout << "Npart = " << thisBin->n_part.mean << endl;
0097   cout << "sigma = " << thisBin->n_part.var << endl;
0098   cout << "Ncoll = " << thisBin->n_coll.mean << endl;
0099   cout << "sigma = " << thisBin->n_coll.var << endl;
0100   cout << "B     = " << thisBin->b.mean << endl;
0101   cout << "sigma = " << thisBin->b.var << endl;
0102   cout << "__________________________________________________" << endl;
0103 }
0104 
0105 void HiTrivialConditionRetriever::setIntervalFor(const edm::eventsetup::EventSetupRecordKey& rk,
0106                                                  const edm::IOVSyncValue& iTime,
0107                                                  edm::ValidityInterval& oValidity) {
0108   if (verbose_ >= 1)
0109     std::cout << "HiTrivialConditionRetriever::setIntervalFor(): record key = " << rk.name()
0110               << "\ttime: " << iTime.time().value() << std::endl;
0111   //For right now, we will just use an infinite interval of validity
0112   oValidity = edm::ValidityInterval(edm::IOVSyncValue::beginOfTime(), edm::IOVSyncValue::endOfTime());
0113 }
0114 
0115 //define this as a plug-in
0116 DEFINE_FWK_EVENTSETUP_SOURCE(HiTrivialConditionRetriever);