CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch2/src/RecoHI/HiEvtPlaneAlgos/src/HiEvtPlaneFlatProducer.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    HiEvtPlaneFlatProducer
00004 // Class:      HiEvtPlaneFlatProducer
00005 // 
00014 //
00015 // Original Author:  Stephen Sanders
00016 //         Created:  Sat Jun 26 16:04:04 EDT 2010
00017 // $Id: HiEvtPlaneFlatProducer.cc,v 1.14 2012/02/15 11:04:09 eulisse Exp $
00018 //
00019 //
00020 
00021 
00022 // system include files
00023 #include <memory>
00024 
00025 // user include files
00026 #include "FWCore/Framework/interface/Frameworkfwd.h"
00027 #include "FWCore/Framework/interface/EDProducer.h"
00028 
00029 #include "FWCore/Framework/interface/Event.h"
00030 #include "FWCore/Framework/interface/MakerMacros.h"
00031 
00032 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00033 #include "Math/Vector3D.h"
00034 
00035 #include "DataFormats/Common/interface/Handle.h"
00036 #include "FWCore/Framework/interface/ESHandle.h"
00037 #include "DataFormats/CaloTowers/interface/CaloTowerCollection.h"
00038 
00039 #include "DataFormats/HeavyIonEvent/interface/Centrality.h"
00040 #include "DataFormats/HeavyIonEvent/interface/CentralityBins.h"
00041 
00042 #include "DataFormats/HeavyIonEvent/interface/EvtPlane.h"
00043 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00044 #include "DataFormats/TrackReco/interface/Track.h"
00045 #include "DataFormats/VertexReco/interface/Vertex.h"
00046 #include "DataFormats/VertexReco/interface/VertexFwd.h"
00047 #include "SimDataFormats/Track/interface/SimTrack.h"
00048 #include "SimDataFormats/Track/interface/SimTrackContainer.h"
00049 #include "SimDataFormats/Track/interface/CoreSimTrack.h"
00050 #include "SimDataFormats/EncodedEventId/interface/EncodedEventId.h"
00051 #include "SimDataFormats/Vertex/interface/SimVertex.h"
00052 #include "SimDataFormats/Vertex/interface/SimVertexContainer.h"
00053 #include "SimDataFormats/TrackingHit/interface/PSimHit.h"
00054 #include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
00055 #include "SimDataFormats/TrackingHit/interface/UpdatablePSimHit.h"
00056 #include "SimDataFormats/TrackingAnalysis/interface/TrackingParticleFwd.h"
00057 #include "SimDataFormats/TrackingAnalysis/interface/TrackingVertexContainer.h"
00058 
00059 #include "FWCore/ServiceRegistry/interface/Service.h"
00060 #include "CommonTools/UtilAlgos/interface/TFileService.h"
00061 #include "CondFormats/DataRecord/interface/HeavyIonRPRcd.h"
00062 #include "CondFormats/HIObjects/interface/CentralityTable.h"
00063 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
00064 #include "CondFormats/HIObjects/interface/RPFlatParams.h"
00065 
00066 #include "RecoHI/HiEvtPlaneAlgos/interface/HiEvtPlaneFlatten.h"
00067 #include "TList.h"
00068 #include "TString.h"
00069 #include <time.h>
00070 #include <cstdlib>
00071 
00072 #include "RecoHI/HiEvtPlaneAlgos/interface/HiEvtPlaneList.h"
00073 
00074 using namespace std;
00075 using namespace hi;
00076 
00077 #include <vector>
00078 using std::vector;
00079 
00080 
00081 //
00082 // class declaration
00083 //
00084 
00085 class HiEvtPlaneFlatProducer : public edm::EDProducer {
00086    public:
00087       explicit HiEvtPlaneFlatProducer(const edm::ParameterSet&);
00088       ~HiEvtPlaneFlatProducer();
00089 
00090    private:
00091       virtual void beginJob() ;
00092       virtual void produce(edm::Event&, const edm::EventSetup&);
00093       virtual void endJob() ;
00094       
00095       // ----------member data ---------------------------
00096 
00097   edm::InputTag vtxCollection_;
00098   edm::InputTag inputPlanes_;
00099   edm::InputTag centrality_;
00100 
00101   int vs_sell;   // vertex collection size
00102   float vzr_sell;
00103   float vzErr_sell;
00104 
00105   Double_t epang[NumEPNames];
00106   HiEvtPlaneFlatten * flat[NumEPNames];
00107   RPFlatParams * rpFlat;
00108   int nRP;
00109   bool storeNames_;
00110 
00111 };
00112 
00113 //
00114 // constants, enums and typedefs
00115 //
00116 typedef std::vector<TrackingParticle>                   TrackingParticleCollection;
00117 typedef TrackingParticleRefVector::iterator               tp_iterator;
00118 
00119 
00120 //
00121 // static data member definitions
00122 //
00123 
00124 //
00125 // constructors and destructor
00126 //
00127 HiEvtPlaneFlatProducer::HiEvtPlaneFlatProducer(const edm::ParameterSet& iConfig)
00128 {
00129 
00130   vtxCollection_  = iConfig.getParameter<edm::InputTag>("vtxCollection_");
00131   inputPlanes_ = iConfig.getParameter<edm::InputTag>("inputPlanes_");
00132   centrality_ = iConfig.getParameter<edm::InputTag>("centrality_");
00133   storeNames_ = 1;
00134    //register your products
00135   produces<reco::EvtPlaneCollection>();
00136    //now do what ever other initialization is needed
00137   Int_t FlatOrder = 21;
00138   for(int i = 0; i<NumEPNames; i++) {
00139     flat[i] = new HiEvtPlaneFlatten();
00140     flat[i]->Init(FlatOrder,11,4,EPNames[i],EPOrder[i]);
00141   }
00142   
00143 }
00144 
00145 
00146 HiEvtPlaneFlatProducer::~HiEvtPlaneFlatProducer()
00147 {
00148  
00149    // do anything here that needs to be done at desctruction time
00150    // (e.g. close files, deallocate resources etc.)
00151 
00152 }
00153 
00154 
00155 //
00156 // member functions
00157 //
00158 
00159 // ------------ method called to produce the data  ------------
00160 void
00161 HiEvtPlaneFlatProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00162 {
00163   using namespace edm;
00164   using namespace std;
00165   using namespace reco;
00166 
00167   //
00168   //Get Centrality
00169   //
00170 
00171   edm::Handle<int> ch;
00172   iEvent.getByLabel(centrality_,ch);
00173   int bin = *(ch.product());
00174 
00175   //  double centval = 2.5*bin+1.25;
00176   //
00177   //Get Vertex
00178   //
00179   edm::Handle<reco::VertexCollection> vertexCollection3;
00180   iEvent.getByLabel(vtxCollection_,vertexCollection3);
00181   const reco::VertexCollection * vertices3 = vertexCollection3.product();
00182   vs_sell = vertices3->size();
00183   if(vs_sell>0) {
00184     vzr_sell = vertices3->begin()->z();
00185     vzErr_sell = vertices3->begin()->zError();
00186   } else
00187     vzr_sell = -999.9;
00188   //
00189   //Get Flattening Parameters
00190   //
00191   edm::ESHandle<RPFlatParams> flatparmsDB_;
00192   iSetup.get<HeavyIonRPRcd>().get(flatparmsDB_);
00193   int flatTableSize = flatparmsDB_->m_table.size();
00194   for(int i = 0; i<flatTableSize; i++) {
00195     const RPFlatParams::EP* thisBin = &(flatparmsDB_->m_table[i]);
00196     for(int j = 0; j<NumEPNames; j++) {
00197       int indx = thisBin->RPNameIndx[j];
00198       if(indx>=0) {
00199         flat[indx]->SetXDB(i, thisBin->x[j]);
00200         flat[indx]->SetYDB(i, thisBin->y[j]);
00201       }
00202     }
00203   }
00204   
00205   //
00206   //Get Event Planes
00207   //
00208   
00209   Handle<reco::EvtPlaneCollection> evtPlanes;
00210   iEvent.getByLabel(inputPlanes_,evtPlanes);
00211   
00212   if(!evtPlanes.isValid()){
00213     //    cout << "Error! Can't get hiEvtPlane product!" << endl;
00214     return ;
00215   }
00216 
00217   std::auto_ptr<EvtPlaneCollection> evtplaneOutput(new EvtPlaneCollection);
00218   EvtPlane * ep[NumEPNames];
00219   for(int i = 0; i<NumEPNames; i++) {
00220     ep[i]=0;
00221   }
00222   for (EvtPlaneCollection::const_iterator rp = evtPlanes->begin();rp !=evtPlanes->end(); rp++) {
00223     if(rp->angle() > -5) {
00224       string baseName = rp->label();
00225       for(int i = 0; i< NumEPNames; i++) {
00226         if(EPNames[i].compare(baseName)==0) {
00227           double psiFlat = flat[i]->GetFlatPsi(rp->angle(),vzr_sell,bin);
00228           epang[i]=psiFlat;
00229           if(EPNames[i].compare(rp->label())==0) {          
00230             if(storeNames_) ep[i]= new EvtPlane(psiFlat, rp->sumSin(), rp->sumCos(),rp->label().data());
00231             else ep[i]= new EvtPlane(psiFlat, rp->sumSin(), rp->sumCos(),"");
00232           } 
00233         }
00234       }
00235     }    
00236   }
00237   
00238   for(int i = 0; i< NumEPNames; i++) {
00239     if(ep[i]!=0) evtplaneOutput->push_back(*ep[i]);
00240   }
00241   iEvent.put(evtplaneOutput);
00242   storeNames_ = 0;  
00243 }
00244 
00245 // ------------ method called once each job just before starting event loop  ------------
00246 void 
00247 HiEvtPlaneFlatProducer::beginJob()
00248 {
00249 }
00250 
00251 // ------------ method called once each job just after ending the event loop  ------------
00252 void 
00253 HiEvtPlaneFlatProducer::endJob() {
00254 }
00255 
00256 //define this as a plug-in
00257 DEFINE_FWK_MODULE(HiEvtPlaneFlatProducer);