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