CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CentralityTableProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: CentralityTableProducer
4 // Class: CentralityTableProducer
5 //
13 //
14 // Original Author: Yetkin Yilmaz
15 // Created: Wed May 2 21:41:30 EDT 2007
16 //
17 //
18 
19 
20 // system include files
21 #include <iostream>
22 #include <fstream>
23 #include <vector>
24 #include <string>
25 
26 // user include files
29 
35 
38 
43 
47 
49 
50 #include <TFile.h>
51 
52 using namespace std;
53 //
54 // class decleration
55 //
56 
58  public:
61 
62  private:
63  virtual void beginRun(const edm::EventSetup&) ;
64  virtual void analyze(const edm::Event&, const edm::EventSetup&) override;
65  virtual void endJob() override ;
66  void printBin(const CentralityTable::CBin*);
67  // ----------member data ---------------------------
68 
72  bool debug_;
73 
75  TFile* inputTFile_;
76  string inputTFileName_;
78 
79  string rootTag_;
80  ofstream text_;
81 
84 
85  unsigned int runnum_;
86 
87 };
88 
89 //
90 // constants, enums and typedefs
91 //
92 
93 //
94 // static data member definitions
95 //
96 
97 //
98 // constructors and destructor
99 //
101  text_("bins.txt"),
102  runnum_(0)
103 {
104  //now do what ever initialization is needed
105  makeDBFromTFile_ = iConfig.getUntrackedParameter<bool>("makeDBFromTFile",1);
106  makeTFileFromDB_ = iConfig.getUntrackedParameter<bool>("makeTFileFromDB",0);
107  firstRunOnly_ = iConfig.getUntrackedParameter<bool>("isMC",false);
108  debug_ = iConfig.getUntrackedParameter<bool>("debug",false);
109  if(makeDBFromTFile_){
110  inputTFileName_ = iConfig.getParameter<string>("inputTFile");
111  rootTag_ = iConfig.getParameter<string>("rootTag");
112  inputTFile_ = new TFile(inputTFileName_.data(),"read");
113  cout<<inputTFileName_.data()<<endl;
114  }
115 }
116 
118 {
119  // do anything here that needs to be done at desctruction time
120  // (e.g. close files, deallocate resources etc.)
121 }
122 
123 //
124 // member functions
125 //
126 
127 // ------------ method called to for each event ------------
128 void
130 {
131  if(!makeTFileFromDB_) return;
132  if((!firstRunOnly_ && runnum_ != iEvent.id().run()) || (firstRunOnly_ && runnum_ == 0)){
133  runnum_ = iEvent.id().run();
134  cout<<"Adding table for run : "<<runnum_<<endl;
135  CentralityProvider cent(iSetup);
136  if(debug_) cent.print();
137  TFileDirectory subDir = fs->mkdir(Form("run%d",runnum_));
138  CB = subDir.make<CentralityBins>((CentralityBins)cent);
139  }
140 }
141 
142 // ------------ method called once each job just before starting event loop ------------
143 void
145 {
146 }
147 
148 // ------------ method called once each job just after ending the event loop ------------
149 void
151 
152  if(makeDBFromTFile_){
153  runnum_ = 1;
154  // Get values from root file
155  CB = (CentralityBins*) inputTFile_->Get(Form("%s/run%d",rootTag_.data(),runnum_));
156  cout<<rootTag_.data()<<endl;
157  CT = new CentralityTable();
158  CT->m_table.reserve(CB->getNbins());
159 
160  text_<<"# BinEdge NpartMean NpartVar NcollMean NcollVar NhardMean NhardVar bMean bVar"<<endl;
161  for(int j=0; j<CB->getNbins(); j++){
163  thisBin->bin_edge = CB->lowEdgeOfBin(j);
164  thisBin->n_part.mean = CB->NpartMeanOfBin(j);
165  thisBin->n_part.var = CB->NpartSigmaOfBin(j);
166  thisBin->n_coll.mean = CB->NcollMeanOfBin(j);
167  thisBin->n_coll.var = CB->NcollSigmaOfBin(j);
168  thisBin->n_hard.mean = CB->NhardMeanOfBin(j);
169  thisBin->n_hard.var = CB->NhardSigmaOfBin(j);
170  thisBin->b.mean = CB->bMeanOfBin(j);
171  thisBin->b.var = CB->bSigmaOfBin(j);
172  printBin(thisBin);
173  CT->m_table.push_back(*thisBin);
174  if(thisBin) delete thisBin;
175  }
176 
178  if( pool.isAvailable() ){
179  if( pool->isNewTagRequest( "HeavyIonRcd" ) ){
180  pool->createNewIOV<CentralityTable>( CT, pool->beginOfTime(), pool->endOfTime(), "HeavyIonRcd" );
181  }else{
182  pool->appendSinceTime<CentralityTable>( CT, pool->currentTime(), "HeavyIonRcd" );
183  }
184  }
185  }
186 }
187 
188 
190 
191  cout<<"HF Cut = "<<thisBin->bin_edge<<endl;
192  cout<<"Npart = "<<thisBin->n_part.mean<<endl;
193  cout<<"sigma = "<<thisBin->n_part.var<<endl;
194  cout<<"Ncoll = "<<thisBin->n_coll.mean<<endl;
195  cout<<"sigma = "<<thisBin->n_coll.var<<endl;
196  cout<<"B = "<<thisBin->b.mean<<endl;
197  cout<<"sigma = "<<thisBin->b.var<<endl;
198  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",
199  (Float_t)thisBin->bin_edge,
200  (Float_t)thisBin->n_part.mean,
201  (Float_t)thisBin->n_part.var,
202  (Float_t)thisBin->n_coll.mean,
203  (Float_t)thisBin->n_coll.var,
204  (Float_t)thisBin->n_hard.mean,
205  (Float_t)thisBin->n_hard.var,
206  (Float_t)thisBin->b.mean,
207  (Float_t)thisBin->b.var)
208  <<endl;
209  cout<<"__________________________________________________"<<endl;
210 
211 }
212 
213 
214 
215 //define this as a plug-in
RunNumber_t run() const
Definition: EventID.h:42
T getParameter(std::string const &) const
void printBin(const CentralityTable::CBin *)
T getUntrackedParameter(std::string const &, T const &) const
std::vector< CBin > m_table
float NpartSigmaOfBin(int bin) const
virtual void analyze(const edm::Event &, const edm::EventSetup &) override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual void endJob() override
float lowEdgeOfBin(int bin) const
void appendSinceTime(T *payloadObj, cond::Time_t sinceTime, const std::string &recordName, bool withlogging=false)
int iEvent
Definition: GenABIO.cc:230
float NcollMeanOfBin(int bin) const
bool isNewTagRequest(const std::string &recordName)
bool isAvailable() const
Definition: Service.h:46
int j
Definition: DBlmapReader.cc:9
float bSigmaOfBin(int bin) const
float NhardMeanOfBin(int bin) const
T * make(const Args &...args) const
make new ROOT object
void createNewIOV(T *firstPayloadObj, cond::Time_t firstSinceTime, cond::Time_t firstTillTime, const std::string &recordName, bool withlogging=false)
TFileDirectory mkdir(const std::string &dir, const std::string &descr="")
create a new subdirectory
Definition: TFileService.h:69
float NpartMeanOfBin(int bin) const
int getNbins() const
edm::ESHandle< CentralityTable > inputDB_
edm::Service< TFileService > fs
edm::EventID id() const
Definition: EventBase.h:56
float bMeanOfBin(int bin) const
tuple cout
Definition: gather_cfg.py:121
CentralityTableProducer(const edm::ParameterSet &)
float NhardSigmaOfBin(int bin) const
virtual void beginRun(const edm::EventSetup &)
float NcollSigmaOfBin(int bin) const