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