CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/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.9 2011/10/07 09:41:29 yilmaz 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     Double_t psirange = 4;
00142     if(EPOrder[i]==2 ) psirange = 2;
00143     if(EPOrder[i]==3 ) psirange = 1.5;
00144     if(EPOrder[i]==4 ) psirange = 1;
00145     if(EPOrder[i]==5) psirange = 0.8;
00146     if(EPOrder[i]==6) psirange = 0.6;
00147   }
00148   
00149 }
00150 
00151 
00152 HiEvtPlaneFlatProducer::~HiEvtPlaneFlatProducer()
00153 {
00154  
00155    // do anything here that needs to be done at desctruction time
00156    // (e.g. close files, deallocate resources etc.)
00157 
00158 }
00159 
00160 
00161 //
00162 // member functions
00163 //
00164 
00165 // ------------ method called to produce the data  ------------
00166 void
00167 HiEvtPlaneFlatProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00168 {
00169   using namespace edm;
00170   using namespace std;
00171   using namespace reco;
00172 
00173   //
00174   //Get Centrality
00175   //
00176 
00177   edm::Handle<int> ch;
00178   iEvent.getByLabel(centrality_,ch);
00179   int bin = *(ch.product());
00180 
00181   //  double centval = 2.5*bin+1.25;
00182   //
00183   //Get Vertex
00184   //
00185   edm::Handle<reco::VertexCollection> vertexCollection3;
00186   iEvent.getByLabel(vtxCollection_,vertexCollection3);
00187   const reco::VertexCollection * vertices3 = vertexCollection3.product();
00188   vs_sell = vertices3->size();
00189   if(vs_sell>0) {
00190     vzr_sell = vertices3->begin()->z();
00191     vzErr_sell = vertices3->begin()->zError();
00192   } else
00193     vzr_sell = -999.9;
00194   //
00195   //Get Flattening Parameters
00196   //
00197   edm::ESHandle<RPFlatParams> flatparmsDB_;
00198   iSetup.get<HeavyIonRPRcd>().get(flatparmsDB_);
00199   int flatTableSize = flatparmsDB_->m_table.size();
00200   for(int i = 0; i<flatTableSize; i++) {
00201     const RPFlatParams::EP* thisBin = &(flatparmsDB_->m_table[i]);
00202     for(int j = 0; j<NumEPNames; j++) {
00203       int indx = thisBin->RPNameIndx[j];
00204       if(indx>=0) {
00205         flat[indx]->SetXDB(i, thisBin->x[j]);
00206         flat[indx]->SetYDB(i, thisBin->y[j]);
00207       }
00208     }
00209   }
00210   
00211   //
00212   //Get Event Planes
00213   //
00214   
00215   Handle<reco::EvtPlaneCollection> evtPlanes;
00216   iEvent.getByLabel(inputPlanes_,evtPlanes);
00217   
00218   if(!evtPlanes.isValid()){
00219     //    cout << "Error! Can't get hiEvtPlane product!" << endl;
00220     return ;
00221   }
00222   double psiFull[NumEPNames];
00223   for(int i = 0; i<NumEPNames; i++) {
00224     psiFull[i] = -10;
00225   }
00226 
00227   std::auto_ptr<EvtPlaneCollection> evtplaneOutput(new EvtPlaneCollection);
00228   EvtPlane * ep[NumEPNames];
00229   for(int i = 0; i<NumEPNames; i++) {
00230     ep[i]=0;
00231   }
00232   for (EvtPlaneCollection::const_iterator rp = evtPlanes->begin();rp !=evtPlanes->end(); rp++) {
00233     if(rp->angle() > -5) {
00234       string baseName = rp->label();
00235       for(int i = 0; i< NumEPNames; i++) {
00236         if(EPNames[i].compare(baseName)==0) {
00237           double psiFlat = flat[i]->GetFlatPsi(rp->angle(),vzr_sell,bin);
00238           epang[i]=psiFlat;
00239           if(EPNames[i].compare(rp->label())==0) {          
00240             psiFull[i] = psiFlat;
00241             if(storeNames_) ep[i]= new EvtPlane(psiFlat, rp->sumSin(), rp->sumCos(),rp->label().data());
00242             else ep[i]= new EvtPlane(psiFlat, rp->sumSin(), rp->sumCos(),"");
00243           } 
00244         }
00245       }
00246     }    
00247   }
00248   
00249   for(int i = 0; i< NumEPNames; i++) {
00250     if(ep[i]!=0) evtplaneOutput->push_back(*ep[i]);
00251   }
00252   iEvent.put(evtplaneOutput);
00253   storeNames_ = 0;  
00254 }
00255 
00256 // ------------ method called once each job just before starting event loop  ------------
00257 void 
00258 HiEvtPlaneFlatProducer::beginJob()
00259 {
00260 }
00261 
00262 // ------------ method called once each job just after ending the event loop  ------------
00263 void 
00264 HiEvtPlaneFlatProducer::endJob() {
00265 }
00266 
00267 //define this as a plug-in
00268 DEFINE_FWK_MODULE(HiEvtPlaneFlatProducer);