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 
28 
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&) override;
48  virtual void endJob() override ;
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  TFileDirectory subDir = fs->mkdir(Form("run%d",runnum_));
119  CB = subDir.make<CentralityBins>();
120  }
121 }
122 
123 // ------------ method called once each job just before starting event loop ------------
124 void
126 {
127 }
128 
129 // ------------ method called once each job just after ending the event loop ------------
130 void
132 
133  if(makeDBFromTFile_){
134  runnum_ = 1;
135  // Get values from root file
136  CB = (CentralityBins*) inputTFile_->Get(Form("%s/run%d",rootTag_.data(),runnum_));
137  cout<<rootTag_.data()<<endl;
138  CT = new CentralityTable();
139  CT->m_table.reserve(CB->getNbins());
140 
141  text_<<"# BinEdge NpartMean NpartVar NcollMean NcollVar NhardMean NhardVar bMean bVar"<<endl;
142  for(int j=0; j<CB->getNbins(); j++){
144  thisBin->bin_edge = CB->lowEdgeOfBin(j);
145  thisBin->n_part.mean = CB->NpartMeanOfBin(j);
146  thisBin->n_part.var = CB->NpartSigmaOfBin(j);
147  thisBin->n_coll.mean = CB->NcollMeanOfBin(j);
148  thisBin->n_coll.var = CB->NcollSigmaOfBin(j);
149  thisBin->n_hard.mean = CB->NhardMeanOfBin(j);
150  thisBin->n_hard.var = CB->NhardSigmaOfBin(j);
151  thisBin->b.mean = CB->bMeanOfBin(j);
152  thisBin->b.var = CB->bSigmaOfBin(j);
153  printBin(thisBin);
154  CT->m_table.push_back(*thisBin);
155  if(thisBin) delete thisBin;
156  }
157 
159  if( pool.isAvailable() ){
160  if( pool->isNewTagRequest( "HeavyIonRcd" ) ){
161  pool->createNewIOV<CentralityTable>( CT, pool->beginOfTime(), pool->endOfTime(), "HeavyIonRcd" );
162  }else{
163  pool->appendSinceTime<CentralityTable>( CT, pool->currentTime(), "HeavyIonRcd" );
164  }
165  }
166  }
167 }
168 
169 
171 
172  cout<<"HF Cut = "<<thisBin->bin_edge<<endl;
173  cout<<"Npart = "<<thisBin->n_part.mean<<endl;
174  cout<<"sigma = "<<thisBin->n_part.var<<endl;
175  cout<<"Ncoll = "<<thisBin->n_coll.mean<<endl;
176  cout<<"sigma = "<<thisBin->n_coll.var<<endl;
177  cout<<"B = "<<thisBin->b.mean<<endl;
178  cout<<"sigma = "<<thisBin->b.var<<endl;
179  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",
180  (Float_t)thisBin->bin_edge,
181  (Float_t)thisBin->n_part.mean,
182  (Float_t)thisBin->n_part.var,
183  (Float_t)thisBin->n_coll.mean,
184  (Float_t)thisBin->n_coll.var,
185  (Float_t)thisBin->n_hard.mean,
186  (Float_t)thisBin->n_hard.var,
187  (Float_t)thisBin->b.mean,
188  (Float_t)thisBin->b.var)
189  <<endl;
190  cout<<"__________________________________________________"<<endl;
191 
192 }
193 
194 
195 
196 //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
int getNbins() const
edm::ESHandle< CentralityTable > inputDB_
edm::Service< TFileService > fs
edm::EventID id() const
Definition: EventBase.h:59
float bMeanOfBin(int bin) const
tuple cout
Definition: gather_cfg.py:145
CentralityTableProducer(const edm::ParameterSet &)
float NhardSigmaOfBin(int bin) const
virtual void beginRun(const edm::EventSetup &)
float NcollSigmaOfBin(int bin) const