CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HiEvtPlaneFlatCalib.cc
Go to the documentation of this file.
1 //
2 // Original Author: Stephen Sanders
3 // Created: Sat Jun 26 16:04:04 EDT 2010
4 //
5 //
6 
7 
8 // system include files
9 #include <memory>
10 
11 // user include files
14 
17 
20 
21 #include "Math/Vector3D.h"
22 
26 
29 
35 
42 
44 #include "TFile.h"
45 #include "TH1.h"
46 #include "TH2D.h"
47 #include "TH2F.h"
48 #include "TTree.h"
49 #include "TH1I.h"
50 #include "TF1.h"
51 #include "TList.h"
52 #include "TString.h"
53 #include <time.h>
54 #include <cstdlib>
55 #include <vector>
56 
58 
59 using namespace std;
60 using namespace hi;
61 
62 //
63 // class declaration
64 //
65 
67  public:
68  explicit HiEvtPlaneFlatCalib(const edm::ParameterSet&);
70 
71  private:
72  virtual void beginJob() override ;
73  virtual void analyze(const edm::Event&, const edm::EventSetup&) override;
74  virtual void endJob() override ;
75 
76  // ----------member data ---------------------------
79  // const CentralityBins * cbins_;
81  int vs_sell; // vertex collection size
82  float vzr_sell;
83  float vzErr_sell;
84 
85  static const int NumCentBins=9;
86  double wcent[10];
87 
88  TH1D * hcent;
89  TH1D * hvtx;
90  TH1D * flatXhist[NumEPNames];
91  TH1D * flatYhist[NumEPNames];
92  TH1D * flatCnthist[NumEPNames];
93 
94  TH1D * flatXDBhist[NumEPNames];
95  TH1D * flatYDBhist[NumEPNames];
96  TH1D * hPsi[NumEPNames];
97  TH1D * hPsiFlat[NumEPNames];
98  TH1D * hPsiFlatCent[NumEPNames][NumCentBins];
99  TH1D * hPsiFlatSub1[NumEPNames];
100  TH1D * hPsiFlatSub2[NumEPNames];
101  Double_t epang[NumEPNames];
104  int nRP;
106 
107 };
108 
109 //
110 // constants, enums and typedefs
111 //
112 
113 //
114 // static data member definitions
115 //
116 
117 //
118 // constructors and destructor
119 //
121 {
122  genFlatPsi_ = iConfig.getUntrackedParameter<bool>("genFlatPsi_",true);
123  vtxCollection_ = consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("vtxCollection_"));
124 
125  // NumCentBins=9;
126  wcent[0] = 0;
127  wcent[1] = 5;
128  wcent[2] = 10;
129  wcent[3] = 20;
130  wcent[4] = 30;
131  wcent[5] = 40;
132  wcent[6] = 50;
133  wcent[7] = 60;
134  wcent[8] = 70;
135  wcent[9] = 100;
136 
137  //now do what ever other initialization is needed
138  // cbins_ = 0;
139  centrality_ = 0;
140  hcent = fs->make<TH1D>("cent","cent",41,0,40);
141  hvtx = fs->make<TH1D>("vtx","vtx",1000,-50,50);
142  //setting before 8:35 CDT on 11Jan2011
143  Int_t FlatOrder = 21;
144  for(int i = 0; i<NumEPNames; i++) {
145  TFileDirectory subdir = fs->mkdir(Form("%s",EPNames[i].data()));
146  flat[i] = new HiEvtPlaneFlatten();
147  flat[i]->Init(FlatOrder,11,4,EPNames[i],EPOrder[i]);
148  int nbins = flat[i]->GetHBins();
149  flatXhist[i] = subdir.make<TH1D>(Form("x_%s",EPNames[i].data()),Form("x_%s",EPNames[i].data()),nbins,-0.5,nbins-0.5);
150  flatYhist[i] = subdir.make<TH1D>(Form("y_%s",EPNames[i].data()),Form("y_%s",EPNames[i].data()),nbins,-0.5,nbins-0.5);
151  flatCnthist[i] = subdir.make<TH1D>(Form("cnt_%s",EPNames[i].data()),Form("cnt_%s",EPNames[i].data()),nbins,-0.5,nbins-0.5);
152  Double_t psirange = 4;
153  if(EPOrder[i]==2 ) psirange = 2;
154  if(EPOrder[i]==3 ) psirange = 1.5;
155  if(EPOrder[i]==4 ) psirange = 1;
156  if(EPOrder[i]==5) psirange = 0.8;
157  if(EPOrder[i]==6) psirange = 0.6;
158  hPsi[i] = subdir.make<TH1D>("psi","psi",800,-psirange,psirange);
159  hPsi[i]->SetXTitle("#Psi");
160  hPsi[i]->SetYTitle(Form("Counts (cent<80%c)",'%'));
161  hPsiFlat[i] = subdir.make<TH1D>("psiFlat","psiFlat",800,-psirange,psirange);
162  hPsiFlat[i]->SetXTitle("#Psi");
163  hPsiFlat[i]->SetYTitle(Form("Counts (cent<80%c)",'%'));
164  for(int j = 0; j<NumCentBins; j++) {
165  TString hname = Form("psiFlat_%d_%d",(int) wcent[j],(int) wcent[j+1]);
166  hPsiFlatCent[i][j] = subdir.make<TH1D>(hname.Data(),hname.Data(),800,-psirange,psirange);
167  hPsiFlatCent[i][j]->SetXTitle("#Psi");
168  hPsiFlatCent[i][j]->SetYTitle(Form("Counts (%d<cent#leq%d%c)",(int) wcent[j],(int) wcent[j+1],'%'));
169  }
170 
171  }
172 
173 }
174 
175 
177 {
178 
179  // do anything here that needs to be done at desctruction time
180  // (e.g. close files, deallocate resources etc.)
181 
182 }
183 
184 
185 //
186 // member functions
187 //
188 
189 // ------------ method called to produce the data ------------
190 void
192 {
193  using namespace edm;
194  using namespace reco;
195  //
196  //Get Centrality
197  //
198  if(!centrality_) centrality_ = new CentralityProvider(iSetup);
199 
200  centrality_->newEvent(iEvent,iSetup); // make sure you do this first in every event
201  int bin = centrality_->getBin();
202  double centval = 2.5*bin+1.25;
203  hcent->Fill(bin);
204  //
205  //Get Vertex
206  //
207  edm::Handle<reco::VertexCollection> vertexCollection3;
208  iEvent.getByToken(vtxCollection_,vertexCollection3);
209  const reco::VertexCollection * vertices3 = vertexCollection3.product();
210  vs_sell = vertices3->size();
211  if(vs_sell>0) {
212  vzr_sell = vertices3->begin()->z();
213  vzErr_sell = vertices3->begin()->zError();
214  } else
215  vzr_sell = -999.9;
216  //
217  //Get Flattening Parameters
218  //
219  if(genFlatPsi_) {
220  edm::ESHandle<RPFlatParams> flatparmsDB_;
221  iSetup.get<HeavyIonRPRcd>().get(flatparmsDB_);
222  int flatTableSize = flatparmsDB_->m_table.size();
223  for(int i = 0; i<flatTableSize; i++) {
224  const RPFlatParams::EP* thisBin = &(flatparmsDB_->m_table[i]);
225  for(int j = 0; j<NumEPNames; j++) {
226  int indx = thisBin->RPNameIndx[j];
227  if(indx>=0) {
228  flat[indx]->SetXDB(i, thisBin->x[j]);
229  flat[indx]->SetYDB(i, thisBin->y[j]);
230  }
231  }
232  }
233  }
234 
235  //
236  //Get Event Planes
237  //
238 
240  iEvent.getByLabel("hiEvtPlane","recoLevel",evtPlanes);
241 
242  if(!evtPlanes.isValid()){
243  //cout << "Error! Can't get hiEvtPlane product!" << endl;
244  return ;
245  }
246 
247  for (EvtPlaneCollection::const_iterator rp = evtPlanes->begin();rp !=evtPlanes->end(); rp++) {
248  if(rp->angle() > -5) {
249  string baseName = rp->label();
250  for(int i = 0; i< NumEPNames; i++) {
251  if(EPNames[i].compare(baseName)==0) {
252  double psiFlat = flat[i]->GetFlatPsi(rp->angle(),vzr_sell,bin);
253  epang[i]=psiFlat;
254  if(EPNames[i].compare(rp->label())==0) {
255  flat[i]->Fill(rp->angle(),vzr_sell,bin);
256  if(i==0) hvtx->Fill(vzr_sell);
257 
258  if(centval<=80) hPsi[i]->Fill(rp->angle());
259  if(genFlatPsi_) {
260  if(centval<=80) hPsiFlat[i]->Fill(psiFlat);
261  for(int j = 0; j<NumCentBins; j++) {
262  if(centval>wcent[j]&&centval<=wcent[j+1]) hPsiFlatCent[i][j]->Fill(psiFlat);
263  }
264  }
265  }
266  }
267  }
268  }
269  }
270 
271 }
272 
273 // ------------ method called once each job just before starting event loop ------------
274 void
276 {
277 }
278 
279 // ------------ method called once each job just after ending the event loop ------------
280 void
282  for(int i = 0; i<NumEPNames; i++) {
283  for(int j = 0; j<flat[i]->GetHBins();j++) {
284  flatXhist[i]->SetBinContent(j+1,flat[i]->GetX(j));
285  flatYhist[i]->SetBinContent(j+1,flat[i]->GetY(j));
286  flatCnthist[i]->SetBinContent(j+1,flat[i]->GetCnt(j));
287  }
288  }
289 }
290 
291 //define this as a plug-in
virtual void beginJob() override
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
const int EPOrder[]
int i
Definition: DBlmapReader.cc:9
virtual void endJob() override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:446
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
const std::string EPNames[]
void beginJob()
Definition: Breakpoints.cc:15
return((rh^lh)&mask)
int iEvent
Definition: GenABIO.cc:230
virtual void analyze(const edm::Event &, const edm::EventSetup &) override
int j
Definition: DBlmapReader.cc:9
T * make(const Args &...args) const
make new ROOT object
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:402
TFileDirectory mkdir(const std::string &dir, const std::string &descr="")
create a new subdirectory
const T & get() const
Definition: EventSetup.h:55
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
int RPNameIndx[50]
Definition: RPFlatParams.h:16
static const int NumEPNames
edm::EDGetTokenT< reco::VertexCollection > vtxCollection_
HiEvtPlaneFlatCalib(const edm::ParameterSet &)
CentralityProvider * centrality_
edm::Service< TFileService > fs