CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MoveFlatParamsToDB.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: MoveFlatParamsToDB
4 // Class: MoveFlatParamsToDB
5 //
13 //
14 // Original Author: Stephen Sanders
15 // Created: Fri Jun 11 12:56:15 EDT 2010
16 //
17 //
18 
19 
20 // system include files
21 #include <memory>
22 #include <iostream>
23 #include <fstream>
24 #include <vector>
25 #include <string>
26 // user include files
29 
35 
38 
43 
48 
50 #include "TFile.h"
51 #include "TH1.h"
52 #include "TH2D.h"
53 #include "TH2F.h"
54 #include "TTree.h"
55 #include "TH1I.h"
56 #include "TF1.h"
57 #include "TList.h"
58 #include "TString.h"
59 #include <time.h>
60 #include <cstdlib>
61 #include <iostream>
62 #include <vector>
63 using namespace std;
64 using namespace hi;
65 
66 //
67 // class declaration
68 //
69 
71 public:
72  explicit MoveFlatParamsToDB(const edm::ParameterSet&);
74 
75 
76 private:
77  virtual void beginJob() override ;
78  virtual void analyze(const edm::Event&, const edm::EventSetup&) override;
79  virtual void endJob() override ;
80 // edm::Service<TFileService> fs;
81  TFile * inFile;
82  //Hard coded limit of 100 different reaction planes
83  TH1D * x[NumEPNames];
84  TH1D * y[NumEPNames];
85  TH1D * xycnt[NumEPNames];
86  string rpname[NumEPNames];
87  int RPNameIndx[NumEPNames];
88  int RPSubEvnt[NumEPNames];
90  int nRP;
91 
92  // ----------member data ---------------------------
93 };
94 
95 //
96 // constants, enums and typedefs
97 //
98 
99 //
100 // static data member definitions
101 //
102 
103 //
104 // constructors and destructor
105 //
107 
108 {
109  cout<<"Enter MoveFlatParamsToDB"<<endl;
110  //now do what ever initialization is needed
111  inFile = new TFile("data/rpflat_combined.root");
112  if(inFile->IsZombie()) {
113  cout<<"file not found"<<endl;
114  }
115  TList * list = ((TDirectory *)inFile->Get("hiEvtPlaneFlatCalib"))->GetListOfKeys();
116  int indx =0;
117  int cnt = 0;
118  for(int i = 0; i<NumEPNames; i++) {
119  x[i]=0;
120  y[i]=0;
121  xycnt[i]=0;
122  }
123  while(indx >=0 && indx<NumEPNames) {
124  int EPNameIndx = -1;
125  TString name = list->At(indx)->GetName();
126  if(!name.Contains("cent")&&!name.Contains("vtx")&&!name.Contains("MidEtaTrackRescor")) {
127  for(int i = 0; i<NumEPNames; i++) {
128  if(name.CompareTo(EPNames[i])==0) {
129  EPNameIndx = i;
130  break;
131  }
132  }
133  if(EPNameIndx <0) cout<<"A bad reaction plane name has been encountered: "<<name.Data()<<endl;
134  RPNameIndx[cnt]=EPNameIndx;
135  TString sname = name;
136  x[cnt] = (TH1D *) inFile->Get(Form("hiEvtPlaneFlatCalib/%s/x_%s",name.Data(),name.Data()));
137  y[cnt] = (TH1D *) inFile->Get(Form("hiEvtPlaneFlatCalib/%s/y_%s",name.Data(),name.Data()));
138  xycnt[cnt] = (TH1D *) inFile->Get(Form("hiEvtPlaneFlatCalib/%s/cnt_%s",name.Data(),name.Data()));
139  rpname[cnt]=sname;
140  if(!x[cnt]) cout<<"bad x"<<endl;
141  if(!y[cnt]) cout<<"bad y"<<endl;
142  if(!xycnt[cnt]) cout<<"bad cnt"<<endl;
143  if(x[cnt] && xycnt[cnt] && y[cnt]) {
144  x[cnt]->Divide(xycnt[cnt]);
145  y[cnt]->Divide(xycnt[cnt]);
146  }
147  ++cnt;
148  if(cnt>NumEPNames||cnt>50) {
149  cout<<"Maximum number of reaction planes exceeded!"<<endl;
150  break;
151  }
152  }
153 
154  if(list->At(indx)==list->Last())
155  indx = -1;
156  else
157  ++indx;
158  }
159  nRP = cnt;
160  cout<<"nRP = "<<nRP<<endl;
161 }
162 
163 
165 {
166 
167  // do anything here that needs to be done at desctruction time
168  // (e.g. close files, deallocate resources etc.)
169 
170 }
171 
172 
173 //
174 // member functions
175 //
176 
177 // ------------ method called to for each event ------------
178 void
180 {
181  using namespace edm;
182  rpFlat = new RPFlatParams();
183  rpFlat->m_table.reserve(x[0]->GetNbinsX());
184  cout<<"Size of table: "<<x[0]->GetNbinsX()<<endl;
185  for(int j = 0; j<x[0]->GetNbinsX();j++) {
186  RPFlatParams::EP * thisBin = new RPFlatParams::EP();
187  for(int i = 0; i<nRP; i++) {
188  thisBin->x[i] = x[i]->GetBinContent(j+1);
189  thisBin->y[i] = y[i]->GetBinContent(j+1);
190  thisBin->RPNameIndx[i]=RPNameIndx[i];
191  }
192  rpFlat->m_table.push_back(*thisBin);
193  if(thisBin) delete thisBin;
194  }
195  cout<<"Number of RP: "<<nRP<<endl;
197  if(poolDbService.isAvailable())
198  poolDbService->writeOne( rpFlat,poolDbService->beginOfTime(),"HeavyIonRPRcd");
199  cout<<"DONE"<<endl;
200 }
201 
202 
203 // ------------ method called once each job just before starting event loop ------------
204 void
206 {
207 }
208 
209 // ------------ method called once each job just after ending the event loop ------------
210 void
212 }
213 
214 //define this as a plug-in
int i
Definition: DBlmapReader.cc:9
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
const std::string EPNames[]
virtual void beginJob() override
MoveFlatParamsToDB(const edm::ParameterSet &)
virtual void analyze(const edm::Event &, const edm::EventSetup &) override
void beginJob()
Definition: Breakpoints.cc:15
int iEvent
Definition: GenABIO.cc:230
int j
Definition: DBlmapReader.cc:9
void writeOne(T *payload, Time_t time, const std::string &recordName, bool withlogging=false)
virtual void endJob() override
int RPNameIndx[50]
Definition: RPFlatParams.h:16
tuple cout
Definition: gather_cfg.py:121
static const int NumEPNames
Definition: DDAxes.h:10
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger list("!*","!HLTx*"if it matches 2 triggers or more) will accept the event if all the matching triggers are FAIL.It will reject the event if any of the triggers are PASS or EXCEPTION(this matches the behavior of"!*"before the partial wildcard feature was incorporated).Triggers which are in the READY state are completely ignored.(READY should never be returned since the trigger paths have been run