CMS 3D CMS Logo

HiEvtPlaneFlatProducer.cc
Go to the documentation of this file.
1 #include <memory>
4 
7 
9 #include "Math/Vector3D.h"
10 
15 
17 
34 
42 
44 #include "TList.h"
45 #include "TString.h"
46 #include <ctime>
47 #include <cstdlib>
48 
51 
52 using namespace std;
53 using namespace hi;
54 
55 #include <vector>
56 using std::vector;
57 
58 
59 //
60 // class declaration
61 //
62 
64 public:
66  ~HiEvtPlaneFlatProducer() override;
67 
68 private:
69  void produce(edm::Event&, const edm::EventSetup&) override;
70 
71  // ----------member data ---------------------------
72 
76 
79 
82 
85 
88 
92 
95 
96  const int FlatOrder_;
98  double caloCentRef_;
101  int Noffmin_;
102  int Noffmax_;
105  double nCentBins_;
106 };
107 //
108 // constants, enums and typedefs
109 //
110 
111 typedef std::vector<TrackingParticle> TrackingParticleCollection;
113 
114 
115 //
116 // static data member definitions
117 //
118 
119 //
120 // constructors and destructor
121 //
123  centralityVariable_ ( iConfig.getParameter<std::string>("centralityVariable")),
124  centralityBinTag_ ( iConfig.getParameter<edm::InputTag>("centralityBinTag")),
125  centralityTag_ ( iConfig.getParameter<edm::InputTag>("centralityTag")),
126  vertexTag_ ( iConfig.getParameter<edm::InputTag>("vertexTag")),
127  inputPlanesTag_ ( iConfig.getParameter<edm::InputTag>("inputPlanesTag")),
128  trackTag_ ( iConfig.getParameter<edm::InputTag>("trackTag")),
129  FlatOrder_ ( iConfig.getParameter<int>("FlatOrder")),
130  NumFlatBins_ ( iConfig.getParameter<int>("NumFlatBins")),
131  caloCentRef_ ( iConfig.getParameter<double>("caloCentRef")),
132  caloCentRefWidth_ ( iConfig.getParameter<double>("caloCentRefWidth")),
133  CentBinCompression_ ( iConfig.getParameter<int>("CentBinCompression")),
134  Noffmin_ ( iConfig.getParameter<int>("Noffmin")),
135  Noffmax_ ( iConfig.getParameter<int>("Noffmax")),
136  useOffsetPsi_ ( iConfig.getParameter<bool>("useOffsetPsi"))
137 {
138 // UseEtHF = kFALSE;
139  nCentBins_ = 200.;
140 
141  if(iConfig.exists("nonDefaultGlauberModel")){
142  centralityMC_ = iConfig.getParameter<std::string>("nonDefaultGlauberModel");
143  }
145 
146  centralityBinToken = consumes<int>(centralityBinTag_);
147 
148  centralityToken = consumes<reco::Centrality>(centralityTag_);
149 
150  vertexToken = consumes<std::vector<reco::Vertex>>(vertexTag_);
151 
152  trackToken = consumes<reco::TrackCollection>(trackTag_);
153 
154  inputPlanesToken = consumes<reco::EvtPlaneCollection>(inputPlanesTag_);
155 
156  //register your products
157  produces<reco::EvtPlaneCollection>();
158  //now do what ever other initialization is needed
159  for(int i = 0; i<NumEPNames; i++) {
160  flat[i] = new HiEvtPlaneFlatten();
162  }
163 
164 }
165 
166 
168 {
169 
170  // do anything here that needs to be done at desctruction time
171  // (e.g. close files, deallocate resources etc.)
172  for(int i = 0; i<NumEPNames; i++) {
173  delete flat[i];
174  }
175 
176 }
177 
178 
179 //
180 // member functions
181 //
182 
183 // ------------ method called to produce the data ------------
184 void
186 {
187  using namespace edm;
188  using namespace std;
189  using namespace reco;
190 
191  //
192  //Get Flattening Parameters
193  //
194  if( hiWatcher.check(iSetup) ) {
195 
196  //
197  //Get Size of Centrality Table
198  //
200  iSetup.get<HeavyIonRcd>().get(centralityLabel_,centDB_);
201  nCentBins_ = centDB_->m_table.size();
202  for(int i = 0; i<NumEPNames; i++) {
203  flat[i]->setCaloCentRefBins(-1,-1);
204  if(caloCentRef_>0) {
205  int minbin = (caloCentRef_-caloCentRefWidth_/2.)*nCentBins_/100.;
206  int maxbin = (caloCentRef_+caloCentRefWidth_/2.)*nCentBins_/100.;
207  minbin/=CentBinCompression_;
208  maxbin/=CentBinCompression_;
209  if(minbin>0 && maxbin>=minbin) {
210  if(EPDet[i]==HF || EPDet[i]==Castor) flat[i]->setCaloCentRefBins(minbin,maxbin);
211  }
212  }
213  }
214  }
215 
216  if( hirpWatcher.check(iSetup) ) {
217  edm::ESHandle<RPFlatParams> flatparmsDB_;
218  iSetup.get<HeavyIonRPRcd>().get(flatparmsDB_);
219  LoadEPDB db(flatparmsDB_,flat);
220  if(!db.IsSuccess()) return;
221  }
222  //
223  //Get Centrality
224  //
225 
226  int bin = 0;
227  edm::Handle<int> cbin_;
228  iEvent.getByToken(centralityBinToken, cbin_);
229  int cbin = *cbin_;
230  bin = cbin/CentBinCompression_;
231 
232  if(Noffmin_>=0) {
233  edm::Handle<reco::Centrality> centrality_;
234  iEvent.getByToken(centralityToken, centrality_);
235  int Noff = centrality_->Ntracks();
236  if ( (Noff < Noffmin_) or (Noff >= Noffmax_) ) {
237  return;
238  }
239  }
240  //
241  //Get Vertex
242  //
243  int vs_sell; // vertex collection size
244  float vzr_sell;
246  iEvent.getByToken(vertexToken,vertex_);
247  const reco::VertexCollection * vertices3 = vertex_.product();
248  vs_sell = vertices3->size();
249  if(vs_sell>0) {
250  vzr_sell = vertices3->begin()->z();
251  } else
252  vzr_sell = -999.9;
253 
254  //
255  //Get Event Planes
256  //
257 
259  iEvent.getByToken(inputPlanesToken,evtPlanes_);
260 
261  if(!evtPlanes_.isValid()){
262  // cout << "Error! Can't get hiEvtPlane product!" << endl;
263  return ;
264  }
265 
266  auto evtplaneOutput = std::make_unique<EvtPlaneCollection>();
267  EvtPlane * ep[NumEPNames];
268  for(int i = 0; i<NumEPNames; i++) {
269  ep[i]=nullptr;
270  }
271  int indx = 0;
272  for (EvtPlaneCollection::const_iterator rp = evtPlanes_->begin();rp !=evtPlanes_->end(); rp++) {
273  double psiOffset = rp->angle(0);
274  double s = rp->sumSin(0);
275  double c = rp->sumCos(0);
276  uint m = rp->mult();
277 
278  double soff = s;
279  double coff = c;
280  if(useOffsetPsi_) {
281  soff = flat[indx]->getSoffset(s, vzr_sell, bin);
282  coff = flat[indx]->getCoffset(c, vzr_sell, bin);
283  psiOffset = flat[indx]->getOffsetPsi(soff, coff);
284  }
285  double psiFlat = flat[indx]->getFlatPsi(psiOffset,vzr_sell,bin);
286  ep[indx]= new EvtPlane(indx, 2, psiFlat, soff, coff,rp->sumw(), rp->sumw2(), rp->sumPtOrEt(), rp->sumPtOrEt2(), m);
287  ep[indx]->addLevel(0, rp->angle(0), s, c);
288  ep[indx]->addLevel(3,0., rp->sumSin(3), rp->sumCos(3));
289  if(useOffsetPsi_) ep[indx]->addLevel(1, psiOffset, soff, coff);
290  ++indx;
291  }
292 
293  for(int i = 0; i< NumEPNames; i++) {
294  if(ep[i]!=nullptr) evtplaneOutput->push_back(*ep[i]);
295 
296  }
297  iEvent.put(std::move(evtplaneOutput));
298  for(int i = 0; i<indx; i++) delete ep[i];
299 }
300 
301 
302 //define this as a plug-in
void init(int order, int nbins, std::string tag, int vord)
void addLevel(int level, double ang, double sumsin, double sumcos)
Definition: EvtPlane.cc:22
T getParameter(std::string const &) const
const int EPOrder[]
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:136
std::vector< CBin > m_table
const int EPDet[]
double Ntracks() const
Definition: Centrality.h:40
std::vector< TrackingParticle > TrackingParticleCollection
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
bool IsSuccess()
Definition: LoadEPDB.h:109
edm::EDGetTokenT< reco::Centrality > centralityToken
edm::ESWatcher< HeavyIonRcd > hiWatcher
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
double getSoffset(double s, double vtx, int centbin) const
double getOffsetPsi(double s, double c) const
bool exists(std::string const &parameterName) const
checks if a parameter exists
TrackingParticleRefVector::iterator tp_iterator
void setCaloCentRefBins(const int caloCentRefMinBin, const int caloCentRefMaxBin)
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
HiEvtPlaneFlatten * flat[NumEPNames]
const std::string EPNames[]
int iEvent
Definition: GenABIO.cc:230
void produce(edm::Event &, const edm::EventSetup &) override
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
edm::EDGetTokenT< std::vector< reco::Vertex > > vertexToken
edm::EDGetTokenT< reco::TrackCollection > trackToken
double getCoffset(double c, double vtx, int centbin) const
bool isValid() const
Definition: HandleBase.h:74
double getFlatPsi(double psi, double vtx, int centbin) const
bin
set the eta bin as selection string.
float angle(int level=2) const
Definition: EvtPlane.h:25
T const * product() const
Definition: Handle.h:81
HiEvtPlaneFlatProducer(const edm::ParameterSet &)
const T & get() const
Definition: EventSetup.h:58
def uint(string)
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
return(e1-e2)*(e1-e2)+dp *dp
fixed size matrix
edm::Handle< reco::TrackCollection > trackCollection_
HLT enums.
edm::ESWatcher< HeavyIonRPRcd > hirpWatcher
edm::EDGetTokenT< int > centralityBinToken
edm::EDGetTokenT< reco::EvtPlaneCollection > inputPlanesToken
static const int NumEPNames
def move(src, dest)
Definition: eostools.py:510