CMS 3D CMS Logo

EvtPlaneProducer.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    EvtPlaneProducer
00004 // Class:      EvtPlaneProducer
00005 // 
00013 //
00014 // Original Author:  Sergey Petrushanko
00015 //         Created:  Fri Jul 11 10:05:00 2008
00016 // $Id: EvtPlaneProducer.cc,v 1.1 2008/07/20 19:19:35 yilmaz Exp $
00017 //
00018 //
00019 
00020 
00021 // system include files
00022 #include <memory>
00023 #include <iostream>
00024 
00025 // user include files
00026 #include "FWCore/Framework/interface/Frameworkfwd.h"
00027 #include "FWCore/Framework/interface/EDProducer.h"
00028 #include "FWCore/Framework/interface/Event.h"
00029 #include "FWCore/Framework/interface/EventSetup.h"
00030 
00031 #include "FWCore/Framework/interface/MakerMacros.h"
00032 #include "FWCore/Framework/interface/ESHandle.h"
00033 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00034 
00035 #include "DataFormats/Candidate/interface/Candidate.h"
00036 #include "DataFormats/HeavyIonEvent/interface/EvtPlane.h"
00037 
00038 #include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h"
00039 #include "DataFormats/Common/interface/EDProduct.h"
00040 #include "DataFormats/Common/interface/Ref.h"
00041 
00042 #include "SimDataFormats/HepMCProduct/interface/HepMCProduct.h"
00043 #include "HepMC/GenEvent.h"
00044 #include "HepMC/GenParticle.h"
00045 
00046 #include "DataFormats/Common/interface/Handle.h"
00047 #include "DataFormats/CaloTowers/interface/CaloTowerCollection.h"
00048 #include <iostream>
00049 
00050 using namespace std;
00051 
00052 //
00053 // class decleration
00054 //
00055 
00056 class EvtPlaneProducer : public edm::EDProducer {
00057    public:
00058       explicit EvtPlaneProducer(const edm::ParameterSet&);
00059       ~EvtPlaneProducer();
00060 
00061    private:
00062       virtual void beginJob(const edm::EventSetup&) ;
00063       virtual void produce(edm::Event&, const edm::EventSetup&);
00064       virtual void endJob() ;
00065       
00066       // ----------member data ---------------------------
00067 
00068   bool useECAL_;
00069   bool useHCAL_;
00070 
00071 };
00072 
00073 //
00074 // constants, enums and typedefs
00075 //
00076 
00077 
00078 //
00079 // static data member definitions
00080 //
00081 
00082 //
00083 // constructors and destructor
00084 //
00085 EvtPlaneProducer::EvtPlaneProducer(const edm::ParameterSet& iConfig)
00086 {
00087    //register your products
00088   
00089   useECAL_ = iConfig.getUntrackedParameter<bool>("useECAL",true);
00090   useHCAL_ = iConfig.getUntrackedParameter<bool>("useHCAL",true);
00091 
00092   produces<reco::EvtPlane>("caloLevel");
00093 
00094 }
00095 
00096 
00097 EvtPlaneProducer::~EvtPlaneProducer()
00098 {
00099   
00100   // do anything here that needs to be done at desctruction time
00101   // (e.g. close files, deallocate resources etc.)
00102 
00103 }
00104 
00105 
00106 //
00107 // member functions
00108 //
00109 
00110 // ------------ method called to produce the data  ------------
00111 void
00112 EvtPlaneProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00113 {
00114   using namespace edm;
00115   using namespace reco;
00116   using namespace HepMC;
00117 
00118       double ugol[9], ugol2[9];
00119       double tower_eta, tower_phi, tower_energy, tower_energy_e, tower_energy_h;
00120       double s1t, s2t, s1e, s2e, s1h, s2h;
00121       double s1[9], s2[9], TEnergy[144], TPhi[144];
00122       double pi = 3.14159;
00123       int numb; 
00124 
00125       double planeA     =  0.;
00126 
00127 //       cout << endl << "  Start of the event plane determination." << endl;
00128 
00129        for(int j=0;j<9;j++) {
00130         s1[j]  = 0.;
00131         s2[j]  = 0.;
00132        }
00133       
00134        for(int l=0;l<144;l++) {
00135         TEnergy[l]  = 0.;
00136         TPhi[l]  = 0.;
00137        }
00138 
00139       Handle<CaloTowerCollection> calotower;
00140       iEvent.getByLabel("towerMaker",calotower);
00141       
00142       if(!calotower.isValid()){
00143         cout << "Error! Can't get calotower product!" << endl;
00144        return ;
00145       }
00146 
00147         for (CaloTowerCollection::const_iterator j = calotower->begin();j !=calotower->end(); j++) {
00148 
00149 //        cout << *j << std::endl;
00150 //        cout << "ENERGY HAD " << j->hadEnergy()<< " ENERGY EM " <<j->emEnergy() 
00151 //        << " ETA " <<j->eta() << " PHI " <<j->phi() << std::endl;
00152              
00153         tower_eta        = j->eta();
00154         tower_phi        = j->phi();
00155         tower_energy_e   = j->emEnergy();
00156         tower_energy_h   = j->hadEnergy();
00157         tower_energy     = tower_energy_e + tower_energy_h;
00158         
00159         s1t = tower_energy*sin(2.*tower_phi-pi);
00160         s2t = tower_energy*cos(2.*tower_phi-pi);
00161         s1e = tower_energy_e*sin(2.*tower_phi-pi);
00162         s2e = tower_energy_e*cos(2.*tower_phi-pi);
00163         s1h = tower_energy_h*sin(2.*tower_phi-pi);
00164         s2h = tower_energy_h*cos(2.*tower_phi-pi);
00165 
00166          if (fabs(tower_eta)<3.){
00167 
00168           numb = static_cast< int >(72.*(tower_phi/pi + 1.) - 0.5);
00169           TEnergy[numb] += tower_energy;
00170           TPhi[numb]     = tower_phi;
00171 
00172 // barrel + endcap
00173           s1[0] +=  s1t;
00174           s2[0] +=  s2t;
00175           s1[3] +=  s1h;
00176           s2[3] +=  s2h;
00177           s1[6] +=  s1e;
00178           s2[6] +=  s2e;
00179           
00180 // endcap
00181          if (fabs(tower_eta)>1.5) {
00182           s1[2] +=  s1t;
00183           s2[2] +=  s2t;
00184           s1[5] +=  s1h;
00185           s2[5] +=  s2h;
00186           s1[8] +=  s1e;
00187           s2[8] +=  s2e;
00188          }
00189          }
00190          
00191 // barrel
00192          if (fabs(tower_eta)<1.5){
00193           s1[1] +=  s1t;
00194           s2[1] +=  s2t;
00195           s1[4] +=  s1h;
00196           s2[4] +=  s2h;
00197           s1[7] +=  s1e;
00198           s2[7] +=  s2e;
00199          }
00200         }
00201         
00202       for(int j1=0;j1<9;j1++) {
00203  
00204        if (s2[j1]==0.) {ugol[j1]=0.;}
00205        else {ugol[j1] = 0.5*atan(s1[j1]/s2[j1]);}
00206        
00207        if ( s2[j1] < 0 && s1[j1] <  0) ugol[j1] = ugol[j1] - pi/2.;
00208        if ( s2[j1] < 0 && s1[j1] >= 0) ugol[j1] = ugol[j1] + pi/2.;
00209        
00210        ugol2[j1] = ugol[j1] + pi/2.;
00211        if (ugol2[j1]>pi/2.) ugol2[j1] = ugol2[j1] - pi;
00212        
00213       }
00214 
00215 /*       
00216        cout <<  endl << "   Azimuthal angle of reaction plane (with minimum)" << endl
00217        << "HCAL+ECAL (b+e)   " << ugol[0] << endl
00218        << "HCAL+ECAL (b)     " << ugol[1] << endl
00219        << "HCAL+ECAL (e)     " << ugol[2] << endl
00220        << "HCAL      (b+e)   " << ugol[3] << endl
00221        << "HCAL      (b)     " << ugol[4] << endl
00222        << "HCAL      (e)     " << ugol[5] << endl
00223        << "ECAL      (b+e)   " << ugol[6] << endl
00224        << "ECAL      (b)     " << ugol[7] << endl
00225        << "ECAL      (e)     " << ugol[8] << endl;
00226 
00227        cout <<  endl << "   Azimuthal angle of reaction plane (with maximum)" << endl
00228        << "HCAL+ECAL (b+e)   " << ugol2[0] << endl
00229        << "HCAL+ECAL (b)     " << ugol2[1] << endl
00230        << "HCAL+ECAL (e)     " << ugol2[2] << endl
00231        << "HCAL      (b+e)   " << ugol2[3] << endl
00232        << "HCAL      (b)     " << ugol2[4] << endl
00233        << "HCAL      (e)     " << ugol2[5] << endl
00234        << "ECAL      (b+e)   " << ugol2[6] << endl
00235        << "ECAL      (b)     " << ugol2[7] << endl
00236        << "ECAL      (e)     " << ugol2[8] << endl  << endl;
00237 
00238 */
00239 
00240    if(useECAL_ && !useHCAL_){
00241      planeA=ugol2[6];
00242      std::auto_ptr<EvtPlane> evtplaneOutput(new EvtPlane(planeA));
00243      iEvent.put(evtplaneOutput, "caloLevel");   
00244    }
00245 
00246    if(useHCAL_ && !useECAL_){
00247      planeA=ugol2[3];
00248      std::auto_ptr<EvtPlane> evtplaneOutput(new EvtPlane(planeA));
00249      iEvent.put(evtplaneOutput, "caloLevel");   
00250    }   
00251 
00252    if(useECAL_ && useHCAL_){
00253      planeA=ugol2[0];
00254      std::auto_ptr<EvtPlane> evtplaneOutput(new EvtPlane(planeA));
00255      iEvent.put(evtplaneOutput,"caloLevel");   
00256    }    
00257 
00258 // cout << "  "<< planeA << endl;
00259  
00260 }
00261 
00262 // ------------ method called once each job just before starting event loop  ------------
00263 void 
00264 EvtPlaneProducer::beginJob(const edm::EventSetup&)
00265 {
00266 }
00267 
00268 // ------------ method called once each job just after ending the event loop  ------------
00269 void 
00270 EvtPlaneProducer::endJob() {
00271 }
00272 
00273 //define this as a plug-in
00274 DEFINE_FWK_MODULE(EvtPlaneProducer);

Generated on Tue Jun 9 17:43:35 2009 for CMSSW by  doxygen 1.5.4