CMS 3D CMS Logo

CentralityTableProducer.cc
Go to the documentation of this file.
1 
2 // system include files
3 #include <iostream>
4 #include <fstream>
5 #include <vector>
6 #include <string>
7 
8 // user include files
11 
17 
20 
24 
26 
28 
32 
33 #include <TFile.h>
34 
35 using namespace std;
36 //
37 // class decleration
38 //
39 
41 public:
43  ~CentralityTableProducer() override;
44 
45 private:
46  void analyze(const edm::Event&, const edm::EventSetup&) override;
47  void endJob() override;
48  void printBin(const CentralityTable::CBin*);
49  // ----------member data ---------------------------
50 
54  bool debug_;
55 
57  TFile* inputTFile_;
60 
61  string rootTag_;
62  ofstream text_;
63 
66 
67  unsigned int runnum_;
68 };
69 
70 //
71 // constants, enums and typedefs
72 //
73 
74 //
75 // static data member definitions
76 //
77 
78 //
79 // constructors and destructor
80 //
81 CentralityTableProducer::CentralityTableProducer(const edm::ParameterSet& iConfig) : text_("bins.txt"), runnum_(0) {
82  //now do what ever initialization is needed
83  makeDBFromTFile_ = iConfig.getUntrackedParameter<bool>("makeDBFromTFile", true);
84  makeTFileFromDB_ = iConfig.getUntrackedParameter<bool>("makeTFileFromDB", false);
85  firstRunOnly_ = iConfig.getUntrackedParameter<bool>("isMC", false);
86  debug_ = iConfig.getUntrackedParameter<bool>("debug", false);
87  if (makeDBFromTFile_) {
88  inputTFileName_ = iConfig.getParameter<string>("inputTFile");
89  rootTag_ = iConfig.getParameter<string>("rootTag");
90  inputTFile_ = new TFile(inputTFileName_.data(), "read");
91  cout << inputTFileName_.data() << endl;
92  }
93 }
94 
96  // do anything here that needs to be done at desctruction time
97  // (e.g. close files, deallocate resources etc.)
98 }
99 
100 //
101 // member functions
102 //
103 
104 // ------------ method called to for each event ------------
106  if (!makeTFileFromDB_)
107  return;
108  if ((!firstRunOnly_ && runnum_ != iEvent.id().run()) || (firstRunOnly_ && runnum_ == 0)) {
109  runnum_ = iEvent.id().run();
110  cout << "Adding table for run : " << runnum_ << endl;
111  TFileDirectory subDir = fs->mkdir(Form("run%d", runnum_));
112  CB = subDir.make<CentralityBins>();
113  }
114 }
115 
116 // ------------ method called once each job just after ending the event loop ------------
118  if (makeDBFromTFile_) {
119  runnum_ = 1;
120  // Get values from root file
121  CB = (CentralityBins*)inputTFile_->Get(Form("%s/run%d", rootTag_.data(), runnum_));
122  cout << rootTag_.data() << endl;
123  CT = new CentralityTable();
124  CT->m_table.reserve(CB->getNbins());
125 
126  text_ << "# BinEdge NpartMean NpartVar NcollMean NcollVar NhardMean NhardVar bMean bVar" << endl;
127  for (int j = 0; j < CB->getNbins(); j++) {
129  thisBin->bin_edge = CB->lowEdgeOfBin(j);
130  thisBin->n_part.mean = CB->NpartMeanOfBin(j);
131  thisBin->n_part.var = CB->NpartSigmaOfBin(j);
132  thisBin->n_coll.mean = CB->NcollMeanOfBin(j);
133  thisBin->n_coll.var = CB->NcollSigmaOfBin(j);
134  thisBin->n_hard.mean = CB->NhardMeanOfBin(j);
135  thisBin->n_hard.var = CB->NhardSigmaOfBin(j);
136  thisBin->b.mean = CB->bMeanOfBin(j);
137  thisBin->b.var = CB->bSigmaOfBin(j);
138  printBin(thisBin);
139  CT->m_table.push_back(*thisBin);
140  if (thisBin)
141  delete thisBin;
142  }
143 
145  if (pool.isAvailable()) {
146  if (pool->isNewTagRequest("HeavyIonRcd")) {
147  pool->createNewIOV<CentralityTable>(CT, pool->beginOfTime(), pool->endOfTime(), "HeavyIonRcd");
148  } else {
149  pool->appendSinceTime<CentralityTable>(CT, pool->currentTime(), "HeavyIonRcd");
150  }
151  }
152  }
153 }
154 
156  cout << "HF Cut = " << thisBin->bin_edge << endl;
157  cout << "Npart = " << thisBin->n_part.mean << endl;
158  cout << "sigma = " << thisBin->n_part.var << endl;
159  cout << "Ncoll = " << thisBin->n_coll.mean << endl;
160  cout << "sigma = " << thisBin->n_coll.var << endl;
161  cout << "B = " << thisBin->b.mean << endl;
162  cout << "sigma = " << thisBin->b.var << endl;
163  text_ << Form("%0.2f\t%0.2f\t%0.2f\t%0.2f\t%0.2f\t%0.2f\t%0.2f\t%0.2f\t%0.2f",
164  (Float_t)thisBin->bin_edge,
165  (Float_t)thisBin->n_part.mean,
166  (Float_t)thisBin->n_part.var,
167  (Float_t)thisBin->n_coll.mean,
168  (Float_t)thisBin->n_coll.var,
169  (Float_t)thisBin->n_hard.mean,
170  (Float_t)thisBin->n_hard.var,
171  (Float_t)thisBin->b.mean,
172  (Float_t)thisBin->b.var)
173  << endl;
174  cout << "__________________________________________________" << endl;
175 }
176 
177 //define this as a plug-in
CentralityTableProducer::CB
const CentralityBins * CB
Definition: CentralityTableProducer.cc:65
CentralityTable::CBin
Definition: CentralityTable.h:16
CentralityTable
Definition: CentralityTable.h:7
CentralityTableProducer::printBin
void printBin(const CentralityTable::CBin *)
Definition: CentralityTableProducer.cc:155
CentralityBins.h
dqmiodatasetharvest.pool
pool
Definition: dqmiodatasetharvest.py:190
ESHandle.h
CentralityTableProducer::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: CentralityTableProducer.cc:105
CentralityTable::CBin::n_coll
BinValues n_coll
Definition: CentralityTable.h:19
CentralityTable::CBin::n_part
BinValues n_part
Definition: CentralityTable.h:18
CentralityTable.h
gather_cfg.cout
cout
Definition: gather_cfg.py:144
CentralityTable::CBin::bin_edge
float bin_edge
Definition: CentralityTable.h:17
CentralityTableProducer::debug_
bool debug_
Definition: CentralityTableProducer.cc:54
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
CentralityTableProducer::endJob
void endJob() override
Definition: CentralityTableProducer.cc:117
EDAnalyzer.h
TFileDirectory
Definition: TFileDirectory.h:24
CentralityBins::NcollSigmaOfBin
float NcollSigmaOfBin(int bin) const
Definition: CentralityBins.h:61
CentralityTableProducer::rootTag_
string rootTag_
Definition: CentralityTableProducer.cc:61
edm::EDAnalyzer
Definition: EDAnalyzer.h:29
CentralityTableProducer::inputTFileName_
string inputTFileName_
Definition: CentralityTableProducer.cc:58
HeavyIonRcd.h
MakerMacros.h
PoolDBOutputService.h
PostProcessorHcalIsoTrack_cfi.subDir
subDir
Definition: PostProcessorHcalIsoTrack_cfi.py:5
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
CentralityTableProducer::text_
ofstream text_
Definition: CentralityTableProducer.cc:62
Service.h
CentralityBins
Definition: CentralityBins.h:37
CentralityTable::m_table
std::vector< CBin > m_table
Definition: CentralityTable.h:39
CentralityTableProducer::inputTFile_
TFile * inputTFile_
Definition: CentralityTableProducer.cc:57
edm::ESHandle< CentralityTable >
CentralityBins::bMeanOfBin
float bMeanOfBin(int bin) const
Definition: CentralityBins.h:67
CentralityTable::BinValues::var
float var
Definition: CentralityTable.h:11
CentralityBins::NhardMeanOfBin
float NhardMeanOfBin(int bin) const
Definition: CentralityBins.h:63
CentralityTableProducer::firstRunOnly_
bool firstRunOnly_
Definition: CentralityTableProducer.cc:53
CentralityBins::NhardSigmaOfBin
float NhardSigmaOfBin(int bin) const
Definition: CentralityBins.h:65
CentralityBins::lowEdgeOfBin
float lowEdgeOfBin(int bin) const
Definition: CentralityBins.h:53
TFileService.h
TFileService::mkdir
TFileDirectory mkdir(const std::string &dir, const std::string &descr="")
create a new subdirectory
Definition: TFileService.h:69
edm::ParameterSet
Definition: ParameterSet.h:36
Event.h
CentralityBins::NcollMeanOfBin
float NcollMeanOfBin(int bin) const
Definition: CentralityBins.h:59
edm::Service< TFileService >
iEvent
int iEvent
Definition: GenABIO.cc:224
CentralityTableProducer::makeDBFromTFile_
bool makeDBFromTFile_
Definition: CentralityTableProducer.cc:51
analyze
example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
edm::EventSetup
Definition: EventSetup.h:57
CentralityTableProducer
Definition: CentralityTableProducer.cc:40
CentralityTableProducer::~CentralityTableProducer
~CentralityTableProducer() override
Definition: CentralityTableProducer.cc:95
CentralityTable::BinValues::mean
float mean
Definition: CentralityTable.h:10
CentralityTableProducer::fs
edm::Service< TFileService > fs
Definition: CentralityTableProducer.cc:59
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
CentralityTableProducer::CentralityTableProducer
CentralityTableProducer(const edm::ParameterSet &)
Definition: CentralityTableProducer.cc:81
CentralityTableProducer::CT
CentralityTable * CT
Definition: CentralityTableProducer.cc:64
CentralityBins::bSigmaOfBin
float bSigmaOfBin(int bin) const
Definition: CentralityBins.h:69
std
Definition: JetResolutionObject.h:76
Ref.h
CentralityTableProducer::runnum_
unsigned int runnum_
Definition: CentralityTableProducer.cc:67
Frameworkfwd.h
CentralityTable::CBin::b
BinValues b
Definition: CentralityTable.h:21
CentralityTableProducer::inputDB_
edm::ESHandle< CentralityTable > inputDB_
Definition: CentralityTableProducer.cc:56
EventSetup.h
CentralityTable::CBin::n_hard
BinValues n_hard
Definition: CentralityTable.h:20
HcalRecHitCollections.h
Candidate.h
CentralityTableProducer::makeTFileFromDB_
bool makeTFileFromDB_
Definition: CentralityTableProducer.cc:52
ParameterSet.h
RecoCaloTowerCandidate.h
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
edm::Event
Definition: Event.h:73
CentralityBins::getNbins
int getNbins() const
Definition: CentralityBins.h:51
CentralityBins::NpartMeanOfBin
float NpartMeanOfBin(int bin) const
Definition: CentralityBins.h:55
CentralityBins::NpartSigmaOfBin
float NpartSigmaOfBin(int bin) const
Definition: CentralityBins.h:57