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 //
2 // Original Author: Stephen Sanders
3 // Created: Fri Jun 11 12:56:15 EDT 2010
4 //
5 //
6 
7 
8 // system include files
9 #include <memory>
10 #include <iostream>
11 #include <fstream>
12 #include <vector>
13 #include <string>
14 // user include files
17 
23 
26 
31 
36 
38 #include "TFile.h"
39 #include "TH1.h"
40 #include "TH2D.h"
41 #include "TH2F.h"
42 #include "TTree.h"
43 #include "TH1I.h"
44 #include "TF1.h"
45 #include "TList.h"
46 #include "TString.h"
47 #include <time.h>
48 #include <cstdlib>
49 #include <iostream>
50 #include <vector>
51 using namespace std;
52 using namespace hi;
53 
54 //
55 // class declaration
56 //
57 
59 public:
60  explicit MoveFlatParamsToDB(const edm::ParameterSet&);
62 
63 
64 private:
65  virtual void beginJob() override ;
66  virtual void analyze(const edm::Event&, const edm::EventSetup&) override;
67  virtual void endJob() override ;
68 // edm::Service<TFileService> fs;
69  TFile * inFile;
70  //Hard coded limit of 100 different reaction planes
71  TH1D * x[NumEPNames];
72  TH1D * y[NumEPNames];
73  TH1D * xycnt[NumEPNames];
74  string rpname[NumEPNames];
75  int RPNameIndx[NumEPNames];
76  int RPSubEvnt[NumEPNames];
78  int nRP;
79 
80  // ----------member data ---------------------------
81 };
82 
83 //
84 // constants, enums and typedefs
85 //
86 
87 //
88 // static data member definitions
89 //
90 
91 //
92 // constructors and destructor
93 //
95 
96 {
97  cout<<"Enter MoveFlatParamsToDB"<<endl;
98  //now do what ever initialization is needed
99  inFile = new TFile("data/rpflat_combined.root");
100  if(inFile->IsZombie()) {
101  cout<<"file not found"<<endl;
102  }
103  TList * list = ((TDirectory *)inFile->Get("hiEvtPlaneFlatCalib"))->GetListOfKeys();
104  int indx =0;
105  int cnt = 0;
106  for(int i = 0; i<NumEPNames; i++) {
107  x[i]=0;
108  y[i]=0;
109  xycnt[i]=0;
110  }
111  while(indx >=0 && indx<NumEPNames) {
112  int EPNameIndx = -1;
113  TString name = list->At(indx)->GetName();
114  if(!name.Contains("cent")&&!name.Contains("vtx")&&!name.Contains("MidEtaTrackRescor")) {
115  for(int i = 0; i<NumEPNames; i++) {
116  if(name.CompareTo(EPNames[i])==0) {
117  EPNameIndx = i;
118  break;
119  }
120  }
121  if(EPNameIndx <0) cout<<"A bad reaction plane name has been encountered: "<<name.Data()<<endl;
122  RPNameIndx[cnt]=EPNameIndx;
123  TString sname = name;
124  x[cnt] = (TH1D *) inFile->Get(Form("hiEvtPlaneFlatCalib/%s/x_%s",name.Data(),name.Data()));
125  y[cnt] = (TH1D *) inFile->Get(Form("hiEvtPlaneFlatCalib/%s/y_%s",name.Data(),name.Data()));
126  xycnt[cnt] = (TH1D *) inFile->Get(Form("hiEvtPlaneFlatCalib/%s/cnt_%s",name.Data(),name.Data()));
127  rpname[cnt]=sname;
128  if(!x[cnt]) cout<<"bad x"<<endl;
129  if(!y[cnt]) cout<<"bad y"<<endl;
130  if(!xycnt[cnt]) cout<<"bad cnt"<<endl;
131  if(x[cnt] && xycnt[cnt] && y[cnt]) {
132  x[cnt]->Divide(xycnt[cnt]);
133  y[cnt]->Divide(xycnt[cnt]);
134  }
135  ++cnt;
136  if(cnt>NumEPNames||cnt>50) {
137  cout<<"Maximum number of reaction planes exceeded!"<<endl;
138  break;
139  }
140  }
141 
142  if(list->At(indx)==list->Last())
143  indx = -1;
144  else
145  ++indx;
146  }
147  nRP = cnt;
148  cout<<"nRP = "<<nRP<<endl;
149 }
150 
151 
153 {
154 
155  // do anything here that needs to be done at desctruction time
156  // (e.g. close files, deallocate resources etc.)
157 
158 }
159 
160 
161 //
162 // member functions
163 //
164 
165 // ------------ method called to for each event ------------
166 void
168 {
169  using namespace edm;
170  rpFlat = new RPFlatParams();
171  rpFlat->m_table.reserve(x[0]->GetNbinsX());
172  cout<<"Size of table: "<<x[0]->GetNbinsX()<<endl;
173  for(int j = 0; j<x[0]->GetNbinsX();j++) {
174  RPFlatParams::EP * thisBin = new RPFlatParams::EP();
175  for(int i = 0; i<nRP; i++) {
176  thisBin->x[i] = x[i]->GetBinContent(j+1);
177  thisBin->y[i] = y[i]->GetBinContent(j+1);
178  thisBin->RPNameIndx[i]=RPNameIndx[i];
179  }
180  rpFlat->m_table.push_back(*thisBin);
181  if(thisBin) delete thisBin;
182  }
183  cout<<"Number of RP: "<<nRP<<endl;
185  if(poolDbService.isAvailable())
186  poolDbService->writeOne( rpFlat,poolDbService->beginOfTime(),"HeavyIonRPRcd");
187  cout<<"DONE"<<endl;
188 }
189 
190 
191 // ------------ method called once each job just before starting event loop ------------
192 void
194 {
195 }
196 
197 // ------------ method called once each job just after ending the event loop ------------
198 void
200 }
201 
202 //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