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.13 2011/05/20 17:17:29 wmtan 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 
44 
48 
50 
51 #include <TFile.h>
52 
53 using namespace std;
54 //
55 // class decleration
56 //
57 
59  public:
62 
63  private:
64  virtual void beginRun(const edm::EventSetup&) ;
65  virtual void analyze(const edm::Event&, const edm::EventSetup&);
66  virtual void endJob() ;
67  void printBin(const CentralityTable::CBin*);
68  // ----------member data ---------------------------
69 
73  bool debug_;
74 
76  TFile* inputTFile_;
77  string inputTFileName_;
79 
80  string rootTag_;
81  ofstream text_;
82 
85 
86  unsigned int runnum_;
87 
88 };
89 
90 //
91 // constants, enums and typedefs
92 //
93 
94 //
95 // static data member definitions
96 //
97 
98 //
99 // constructors and destructor
100 //
102  text_("bins.txt"),
103  runnum_(0)
104 {
105  //now do what ever initialization is needed
106  makeDBFromTFile_ = iConfig.getUntrackedParameter<bool>("makeDBFromTFile",1);
107  makeTFileFromDB_ = iConfig.getUntrackedParameter<bool>("makeTFileFromDB",0);
108  firstRunOnly_ = iConfig.getUntrackedParameter<bool>("isMC",false);
109  debug_ = iConfig.getUntrackedParameter<bool>("debug",false);
110  if(makeDBFromTFile_){
111  inputTFileName_ = iConfig.getParameter<string>("inputTFile");
112  rootTag_ = iConfig.getParameter<string>("rootTag");
113  inputTFile_ = new TFile(inputTFileName_.data(),"read");
114  cout<<inputTFileName_.data()<<endl;
115  }
116 }
117 
119 {
120  // do anything here that needs to be done at desctruction time
121  // (e.g. close files, deallocate resources etc.)
122 }
123 
124 //
125 // member functions
126 //
127 
128 // ------------ method called to for each event ------------
129 void
131 {
132  if(!makeTFileFromDB_) return;
133  if((!firstRunOnly_ && runnum_ != iEvent.id().run()) || (firstRunOnly_ && runnum_ == 0)){
134  runnum_ = iEvent.id().run();
135  cout<<"Adding table for run : "<<runnum_<<endl;
136  CentralityProvider cent(iSetup);
137  if(debug_) cent.print();
138  TFileDirectory subDir = fs->mkdir(Form("run%d",runnum_));
139  CB = subDir.make<CentralityBins>((CentralityBins)cent);
140  }
141 }
142 
143 // ------------ method called once each job just before starting event loop ------------
144 void
146 {
147 }
148 
149 // ------------ method called once each job just after ending the event loop ------------
150 void
152 
153  if(makeDBFromTFile_){
154  runnum_ = 1;
155  // Get values from root file
156  CB = (CentralityBins*) inputTFile_->Get(Form("%s/run%d",rootTag_.data(),runnum_));
157  cout<<rootTag_.data()<<endl;
158  CT = new CentralityTable();
159  CT->m_table.reserve(CB->getNbins());
160 
161  text_<<"# BinEdge NpartMean NpartVar NcollMean NcollVar NhardMean NhardVar bMean bVar"<<endl;
162  for(int j=0; j<CB->getNbins(); j++){
164  thisBin->bin_edge = CB->lowEdgeOfBin(j);
165  thisBin->n_part.mean = CB->NpartMeanOfBin(j);
166  thisBin->n_part.var = CB->NpartSigmaOfBin(j);
167  thisBin->n_coll.mean = CB->NcollMeanOfBin(j);
168  thisBin->n_coll.var = CB->NcollSigmaOfBin(j);
169  thisBin->n_hard.mean = CB->NhardMeanOfBin(j);
170  thisBin->n_hard.var = CB->NhardSigmaOfBin(j);
171  thisBin->b.mean = CB->bMeanOfBin(j);
172  thisBin->b.var = CB->bSigmaOfBin(j);
173  printBin(thisBin);
174  CT->m_table.push_back(*thisBin);
175  if(thisBin) delete thisBin;
176  }
177 
179  if( pool.isAvailable() ){
180  if( pool->isNewTagRequest( "HeavyIonRcd" ) ){
181  pool->createNewIOV<CentralityTable>( CT, pool->beginOfTime(), pool->endOfTime(), "HeavyIonRcd" );
182  }else{
183  pool->appendSinceTime<CentralityTable>( CT, pool->currentTime(), "HeavyIonRcd" );
184  }
185  }
186  }
187 }
188 
189 
191 
192  cout<<"HF Cut = "<<thisBin->bin_edge<<endl;
193  cout<<"Npart = "<<thisBin->n_part.mean<<endl;
194  cout<<"sigma = "<<thisBin->n_part.var<<endl;
195  cout<<"Ncoll = "<<thisBin->n_coll.mean<<endl;
196  cout<<"sigma = "<<thisBin->n_coll.var<<endl;
197  cout<<"B = "<<thisBin->b.mean<<endl;
198  cout<<"sigma = "<<thisBin->b.var<<endl;
199  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",
200  (Float_t)thisBin->bin_edge,
201  (Float_t)thisBin->n_part.mean,
202  (Float_t)thisBin->n_part.var,
203  (Float_t)thisBin->n_coll.mean,
204  (Float_t)thisBin->n_coll.var,
205  (Float_t)thisBin->n_hard.mean,
206  (Float_t)thisBin->n_hard.var,
207  (Float_t)thisBin->b.mean,
208  (Float_t)thisBin->b.var)
209  <<endl;
210  cout<<"__________________________________________________"<<endl;
211 
212 }
213 
214 
215 
216 //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