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 // $Id: CentralityTableProducer.cc,v 1.12 2010/11/03 14:53:05 yilmaz Exp $
17 //
18 //
19 
20 
21 // system include files
22 #include <iostream>
23 #include <fstream>
24 #include <vector>
25 #include <string>
26 
27 // user include files
30 
36 
39 
45 
49 
51 
52 #include <TFile.h>
53 
54 using namespace std;
55 //
56 // class decleration
57 //
58 
60  public:
63 
64  private:
65  virtual void beginRun(const edm::EventSetup&) ;
66  virtual void analyze(const edm::Event&, const edm::EventSetup&);
67  virtual void endJob() ;
68  void printBin(const CentralityTable::CBin*);
69  // ----------member data ---------------------------
70 
74  bool debug_;
75 
77  TFile* inputTFile_;
78  string inputTFileName_;
80 
81  string rootTag_;
82  ofstream text_;
83 
86 
87  unsigned int runnum_;
88 
89 };
90 
91 //
92 // constants, enums and typedefs
93 //
94 
95 //
96 // static data member definitions
97 //
98 
99 //
100 // constructors and destructor
101 //
103  text_("bins.txt"),
104  runnum_(0)
105 {
106  //now do what ever initialization is needed
107  makeDBFromTFile_ = iConfig.getUntrackedParameter<bool>("makeDBFromTFile",1);
108  makeTFileFromDB_ = iConfig.getUntrackedParameter<bool>("makeTFileFromDB",0);
109  firstRunOnly_ = iConfig.getUntrackedParameter<bool>("isMC",false);
110  debug_ = iConfig.getUntrackedParameter<bool>("debug",false);
111  if(makeDBFromTFile_){
112  inputTFileName_ = iConfig.getParameter<string>("inputTFile");
113  rootTag_ = iConfig.getParameter<string>("rootTag");
114  inputTFile_ = new TFile(inputTFileName_.data(),"read");
115  cout<<inputTFileName_.data()<<endl;
116  }
117 }
118 
120 {
121  // do anything here that needs to be done at desctruction time
122  // (e.g. close files, deallocate resources etc.)
123 }
124 
125 //
126 // member functions
127 //
128 
129 // ------------ method called to for each event ------------
130 void
132 {
133  if(!makeTFileFromDB_) return;
134  if((!firstRunOnly_ && runnum_ != iEvent.id().run()) || (firstRunOnly_ && runnum_ == 0)){
135  runnum_ = iEvent.id().run();
136  cout<<"Adding table for run : "<<runnum_<<endl;
137  CentralityProvider cent(iSetup);
138  if(debug_) cent.print();
139  TFileDirectory subDir = fs->mkdir(Form("run%d",runnum_));
140  CB = subDir.make<CentralityBins>((CentralityBins)cent);
141  }
142 }
143 
144 // ------------ method called once each job just before starting event loop ------------
145 void
147 {
148 }
149 
150 // ------------ method called once each job just after ending the event loop ------------
151 void
153 
154  if(makeDBFromTFile_){
155  runnum_ = 1;
156  // Get values from root file
157  CB = (CentralityBins*) inputTFile_->Get(Form("%s/run%d",rootTag_.data(),runnum_));
158  cout<<rootTag_.data()<<endl;
159  CT = new CentralityTable();
160  CT->m_table.reserve(CB->getNbins());
161 
162  text_<<"# BinEdge NpartMean NpartVar NcollMean NcollVar NhardMean NhardVar bMean bVar"<<endl;
163  for(int j=0; j<CB->getNbins(); j++){
165  thisBin->bin_edge = CB->lowEdgeOfBin(j);
166  thisBin->n_part.mean = CB->NpartMeanOfBin(j);
167  thisBin->n_part.var = CB->NpartSigmaOfBin(j);
168  thisBin->n_coll.mean = CB->NcollMeanOfBin(j);
169  thisBin->n_coll.var = CB->NcollSigmaOfBin(j);
170  thisBin->n_hard.mean = CB->NhardMeanOfBin(j);
171  thisBin->n_hard.var = CB->NhardSigmaOfBin(j);
172  thisBin->b.mean = CB->bMeanOfBin(j);
173  thisBin->b.var = CB->bSigmaOfBin(j);
174  printBin(thisBin);
175  CT->m_table.push_back(*thisBin);
176  if(thisBin) delete thisBin;
177  }
178 
180  if( pool.isAvailable() ){
181  if( pool->isNewTagRequest( "HeavyIonRcd" ) ){
182  pool->createNewIOV<CentralityTable>( CT, pool->beginOfTime(), pool->endOfTime(), "HeavyIonRcd" );
183  }else{
184  pool->appendSinceTime<CentralityTable>( CT, pool->currentTime(), "HeavyIonRcd" );
185  }
186  }
187  }
188 }
189 
190 
192 
193  cout<<"HF Cut = "<<thisBin->bin_edge<<endl;
194  cout<<"Npart = "<<thisBin->n_part.mean<<endl;
195  cout<<"sigma = "<<thisBin->n_part.var<<endl;
196  cout<<"Ncoll = "<<thisBin->n_coll.mean<<endl;
197  cout<<"sigma = "<<thisBin->n_coll.var<<endl;
198  cout<<"B = "<<thisBin->b.mean<<endl;
199  cout<<"sigma = "<<thisBin->b.var<<endl;
200  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",
201  (Float_t)thisBin->bin_edge,
202  (Float_t)thisBin->n_part.mean,
203  (Float_t)thisBin->n_part.var,
204  (Float_t)thisBin->n_coll.mean,
205  (Float_t)thisBin->n_coll.var,
206  (Float_t)thisBin->n_hard.mean,
207  (Float_t)thisBin->n_hard.var,
208  (Float_t)thisBin->b.mean,
209  (Float_t)thisBin->b.var)
210  <<endl;
211  cout<<"__________________________________________________"<<endl;
212 
213 }
214 
215 
216 
217 //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
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
float lowEdgeOfBin(int bin) const
virtual void analyze(const edm::Event &, const edm::EventSetup &)
void appendSinceTime(T *payloadObj, cond::Time_t sinceTime, const std::string &recordName, bool withlogging=false)
int iEvent
Definition: GenABIO.cc:243
float NcollMeanOfBin(int bin) const
bool isNewTagRequest(const std::string &recordName)
bool isAvailable() const
Definition: Service.h:47
int j
Definition: DBlmapReader.cc:9
float bSigmaOfBin(int bin) const
float NhardMeanOfBin(int bin) const
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
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
T * make() const
make new ROOT object
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