CMS 3D CMS Logo

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:
43  ~CentralityTableProducer() override;
44 
45  private:
46  void analyze(const edm::Event&, const edm::EventSetup&) override;
47  void endJob() override ;
48  void printBin(const CentralityTable::CBin*);
49  // ----------member data ---------------------------
50 
54  bool debug_;
55 
57  TFile* inputTFile_;
58  string inputTFileName_;
60 
61  string rootTag_;
62  ofstream text_;
63 
66 
67  unsigned int runnum_;
68 
69 };
70 
71 //
72 // constants, enums and typedefs
73 //
74 
75 //
76 // static data member definitions
77 //
78 
79 //
80 // constructors and destructor
81 //
83  text_("bins.txt"),
84  runnum_(0)
85 {
86  //now do what ever initialization is needed
87  makeDBFromTFile_ = iConfig.getUntrackedParameter<bool>("makeDBFromTFile",true);
88  makeTFileFromDB_ = iConfig.getUntrackedParameter<bool>("makeTFileFromDB",false);
89  firstRunOnly_ = iConfig.getUntrackedParameter<bool>("isMC",false);
90  debug_ = iConfig.getUntrackedParameter<bool>("debug",false);
91  if(makeDBFromTFile_){
92  inputTFileName_ = iConfig.getParameter<string>("inputTFile");
93  rootTag_ = iConfig.getParameter<string>("rootTag");
94  inputTFile_ = new TFile(inputTFileName_.data(),"read");
95  cout<<inputTFileName_.data()<<endl;
96  }
97 }
98 
100 {
101  // do anything here that needs to be done at desctruction time
102  // (e.g. close files, deallocate resources etc.)
103 }
104 
105 //
106 // member functions
107 //
108 
109 // ------------ method called to for each event ------------
110 void
112 {
113  if(!makeTFileFromDB_) return;
114  if((!firstRunOnly_ && runnum_ != iEvent.id().run()) || (firstRunOnly_ && runnum_ == 0)){
115  runnum_ = iEvent.id().run();
116  cout<<"Adding table for run : "<<runnum_<<endl;
117  TFileDirectory subDir = fs->mkdir(Form("run%d",runnum_));
118  CB = subDir.make<CentralityBins>();
119  }
120 }
121 
122 
123 // ------------ method called once each job just after ending the event loop ------------
124 void
126 
127  if(makeDBFromTFile_){
128  runnum_ = 1;
129  // Get values from root file
130  CB = (CentralityBins*) inputTFile_->Get(Form("%s/run%d",rootTag_.data(),runnum_));
131  cout<<rootTag_.data()<<endl;
132  CT = new CentralityTable();
133  CT->m_table.reserve(CB->getNbins());
134 
135  text_<<"# BinEdge NpartMean NpartVar NcollMean NcollVar NhardMean NhardVar bMean bVar"<<endl;
136  for(int j=0; j<CB->getNbins(); j++){
138  thisBin->bin_edge = CB->lowEdgeOfBin(j);
139  thisBin->n_part.mean = CB->NpartMeanOfBin(j);
140  thisBin->n_part.var = CB->NpartSigmaOfBin(j);
141  thisBin->n_coll.mean = CB->NcollMeanOfBin(j);
142  thisBin->n_coll.var = CB->NcollSigmaOfBin(j);
143  thisBin->n_hard.mean = CB->NhardMeanOfBin(j);
144  thisBin->n_hard.var = CB->NhardSigmaOfBin(j);
145  thisBin->b.mean = CB->bMeanOfBin(j);
146  thisBin->b.var = CB->bSigmaOfBin(j);
147  printBin(thisBin);
148  CT->m_table.push_back(*thisBin);
149  if(thisBin) delete thisBin;
150  }
151 
153  if( pool.isAvailable() ){
154  if( pool->isNewTagRequest( "HeavyIonRcd" ) ){
155  pool->createNewIOV<CentralityTable>( CT, pool->beginOfTime(), pool->endOfTime(), "HeavyIonRcd" );
156  }else{
157  pool->appendSinceTime<CentralityTable>( CT, pool->currentTime(), "HeavyIonRcd" );
158  }
159  }
160  }
161 }
162 
163 
165 
166  cout<<"HF Cut = "<<thisBin->bin_edge<<endl;
167  cout<<"Npart = "<<thisBin->n_part.mean<<endl;
168  cout<<"sigma = "<<thisBin->n_part.var<<endl;
169  cout<<"Ncoll = "<<thisBin->n_coll.mean<<endl;
170  cout<<"sigma = "<<thisBin->n_coll.var<<endl;
171  cout<<"B = "<<thisBin->b.mean<<endl;
172  cout<<"sigma = "<<thisBin->b.var<<endl;
173  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",
174  (Float_t)thisBin->bin_edge,
175  (Float_t)thisBin->n_part.mean,
176  (Float_t)thisBin->n_part.var,
177  (Float_t)thisBin->n_coll.mean,
178  (Float_t)thisBin->n_coll.var,
179  (Float_t)thisBin->n_hard.mean,
180  (Float_t)thisBin->n_hard.var,
181  (Float_t)thisBin->b.mean,
182  (Float_t)thisBin->b.var)
183  <<endl;
184  cout<<"__________________________________________________"<<endl;
185 
186 }
187 
188 
189 
190 //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 example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
void analyze(const edm::Event &, const edm::EventSetup &) override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
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
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:60
float bMeanOfBin(int bin) const
CentralityTableProducer(const edm::ParameterSet &)
float NhardSigmaOfBin(int bin) const
float NcollSigmaOfBin(int bin) const