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