CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10/src/RecoHI/HiEvtPlaneAlgos/src/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.21 2012/02/15 11:04:09 eulisse Exp $
00017 //
00018 //
00019 #define TRACKCOLLECTION 1
00020 //#define RECOCHARGEDCANDIDATECOLLECTION 1
00021 
00022 
00023 // system include files
00024 #include <memory>
00025 #include <iostream>
00026 #include <time.h>
00027 #include "TMath.h"
00028 
00029 // user include files
00030 #include "FWCore/Framework/interface/Frameworkfwd.h"
00031 #include "FWCore/Framework/interface/EDProducer.h"
00032 #include "FWCore/Framework/interface/Event.h"
00033 #include "FWCore/Framework/interface/EventSetup.h"
00034 
00035 #include "FWCore/Framework/interface/MakerMacros.h"
00036 #include "FWCore/Framework/interface/ESHandle.h"
00037 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00038 
00039 #include "DataFormats/Candidate/interface/Candidate.h"
00040 #include "DataFormats/HeavyIonEvent/interface/EvtPlane.h"
00041 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidate.h"
00042 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidateFwd.h"
00043 
00044 #include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h"
00045 #include "DataFormats/Common/interface/EDProduct.h"
00046 #include "DataFormats/Common/interface/Ref.h"
00047 
00048 #include "DataFormats/Common/interface/Handle.h"
00049 #include "DataFormats/CaloTowers/interface/CaloTowerCollection.h"
00050 
00051 #include "FWCore/ServiceRegistry/interface/Service.h"
00052 #include "CommonTools/UtilAlgos/interface/TFileService.h"
00053 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00054 #include "DataFormats/TrackReco/interface/Track.h"
00055 #include "DataFormats/VertexReco/interface/Vertex.h"
00056 #include "DataFormats/VertexReco/interface/VertexFwd.h"
00057 
00058 #include <cstdlib>
00059 #include "RecoHI/HiEvtPlaneAlgos/interface/HiEvtPlaneList.h"
00060 
00061 using namespace std;
00062 using namespace hi;
00063 
00064 //
00065 // class decleration
00066 //
00067 
00068 class EvtPlaneProducer : public edm::EDProducer {
00069 public:
00070   explicit EvtPlaneProducer(const edm::ParameterSet&);
00071   ~EvtPlaneProducer();
00072   
00073 private:
00074   //edm::Service<TFileService> fs;
00075   class GenPlane {
00076   public: 
00077     GenPlane(string name,double etaminval1,double etamaxval1,double etaminval2,double etamaxval2,int orderval){
00078       epname=name;
00079       etamin1=etaminval1;
00080       etamax1=etamaxval1;
00081       etamin2=etaminval2;
00082       etamax2=etamaxval2;
00083       sumsin=0;
00084       sumcos=0;
00085       order = (double) orderval;
00086     }
00087     ~GenPlane(){;}
00088     void addParticle(double w, double s, double c, double eta) {
00089       if(w < 0.001) return;
00090       if((eta>=etamin1 && eta<etamax1) || 
00091          (etamin2!= etamax2 && eta>=etamin2 && eta<etamax2 )) {
00092         sumsin+=w*s;
00093         sumcos+=w*c;
00094         //For tracking, w=1 and mult is the track multiplicity.  
00095         //For calorimetors, w is an energy that needs to be subsequently 
00096         //converted if an  multiplicity if needed
00097         mult+=w;
00098       }
00099     }
00100     
00101     double getAngle(double &ang, double &sv, double &cv){
00102       ang = -10;
00103       sv = 0;
00104       cv = 0;
00105       sv = sumsin;
00106       cv = sumcos;
00107       double q = sv*sv+cv*cv;
00108       if(q>0) ang = atan2(sv,cv)/order;
00109       return ang;
00110     }
00111     void reset() {
00112       sumsin=0;
00113       sumcos=0;
00114       mult = 0;
00115     }
00116   private:
00117     string epname;
00118     double etamin1;
00119     double etamax1;
00120 
00121     double etamin2;
00122     double etamax2;
00123     double sumsin;
00124     double sumcos;
00125     int mult;
00126     double order;
00127   };
00128   
00129 
00130   GenPlane *rp[NumEPNames];
00131 
00132   virtual void beginJob() ;
00133   virtual void produce(edm::Event&, const edm::EventSetup&);
00134   virtual void endJob() ;
00135   
00136   // ----------member data ---------------------------
00137   edm::InputTag vtxCollection_;
00138   edm::InputTag caloCollection_;
00139   edm::InputTag trackCollection_;
00140   bool useECAL_;
00141   bool useHCAL_;
00142   bool useTrack_;
00143   bool useTrackPtWeight_;
00144   double minet_;
00145   double maxet_;
00146   double minpt_;
00147   double maxpt_;
00148   double minvtx_;
00149   double maxvtx_;
00150   double dzerr_;
00151   double chi2_;
00152 
00153   bool storeNames_;
00154 };
00155 
00156 //
00157 // constants, enums and typedefs
00158 //
00159 
00160 
00161 //
00162 // static data member definitions
00163 //
00164 
00165 //
00166 // constructors and destructor
00167 //
00168 EvtPlaneProducer::EvtPlaneProducer(const edm::ParameterSet& iConfig)
00169 {
00170   
00171   
00172   //register your products
00173   vtxCollection_  = iConfig.getParameter<edm::InputTag>("vtxCollection_");
00174   caloCollection_  = iConfig.getParameter<edm::InputTag>("caloCollection_");
00175   trackCollection_  = iConfig.getParameter<edm::InputTag>("trackCollection_");
00176   useECAL_ = iConfig.getUntrackedParameter<bool>("useECAL_",true);
00177   useHCAL_ = iConfig.getUntrackedParameter<bool>("useHCAL_",true);
00178   useTrack_ = iConfig.getUntrackedParameter<bool>("useTrack",true);
00179   useTrackPtWeight_ = iConfig.getUntrackedParameter<bool>("useTrackPtWeight_",true);
00180   minet_ = iConfig.getUntrackedParameter<double>("minet_",0.2);
00181   maxet_ = iConfig.getUntrackedParameter<double>("maxet_",500.);
00182   minpt_ = iConfig.getUntrackedParameter<double>("minpt_",0.3);
00183   maxpt_ = iConfig.getUntrackedParameter<double>("maxpt_",2.5);
00184   minvtx_ = iConfig.getUntrackedParameter<double>("minvtx_",-50.);
00185   maxvtx_ = iConfig.getUntrackedParameter<double>("maxvtx_",50.);
00186   dzerr_ = iConfig.getUntrackedParameter<double>("dzerr_",10.);
00187   chi2_  = iConfig.getUntrackedParameter<double>("chi2_",40.);
00188 
00189   storeNames_ = 1;
00190   produces<reco::EvtPlaneCollection>("recoLevel");
00191   for(int i = 0; i<NumEPNames; i++ ) {
00192     rp[i] = new GenPlane(EPNames[i].data(),EPEtaMin1[i],EPEtaMax1[i],EPEtaMin2[i],EPEtaMax2[i],EPOrder[i]);
00193   }
00194 }
00195 
00196 
00197 EvtPlaneProducer::~EvtPlaneProducer()
00198 {
00199   
00200   // do anything here that needs to be done at desctruction time
00201   // (e.g. close files, deallocate resources etc.)
00202   
00203 }
00204 
00205 
00206 //
00207 // member functions
00208 //
00209 
00210 // ------------ method called to produce the data  ------------
00211 void
00212 EvtPlaneProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00213 {
00214   using namespace edm;
00215   using namespace reco;
00216 
00217   int vs_sell;
00218   float vzr_sell;
00219   //
00220   //Get Vertex
00221   //
00222   edm::Handle<reco::VertexCollection> vertexCollection3;
00223   iEvent.getByLabel(vtxCollection_,vertexCollection3);
00224   const reco::VertexCollection * vertices3 = vertexCollection3.product();
00225   vs_sell = vertices3->size();
00226   if(vs_sell>0) {
00227     vzr_sell = vertices3->begin()->z();
00228   } else
00229     vzr_sell = -999.9;
00230   //
00231   for(int i = 0; i<NumEPNames; i++) rp[i]->reset();
00232   if(vzr_sell>minvtx_ && vzr_sell<maxvtx_) {
00233     //calorimetry part
00234     
00235     double tower_eta, tower_phi;
00236     double tower_energyet, tower_energyet_e, tower_energyet_h;
00237     double s1, s2, s13,s23,s14,s24,s15,s25,s16,s26;
00238     Handle<CaloTowerCollection> calotower;
00239     iEvent.getByLabel(caloCollection_,calotower);
00240     
00241     if(calotower.isValid()){
00242       
00243       for (CaloTowerCollection::const_iterator j = calotower->begin();j !=calotower->end(); j++) {   
00244         tower_eta        = j->eta();
00245         tower_phi        = j->phi();
00246         tower_energyet_e   = j->emEt();
00247         tower_energyet_h   = j->hadEt();
00248         tower_energyet     = tower_energyet_e + tower_energyet_h;
00249         
00250         s1 = sin(2.*tower_phi);
00251         s2 = cos(2.*tower_phi);    
00252         s13 = sin(3.*tower_phi);
00253         s23 = cos(3.*tower_phi);
00254         s14 = sin(4.*tower_phi);
00255         s24 = cos(4.*tower_phi);
00256         s15 = sin(5.*tower_phi);
00257         s25 = cos(5.*tower_phi);
00258         s16 = sin(6.*tower_phi);
00259         s26 = cos(6.*tower_phi);
00260         
00261         if(tower_energyet<minet_) continue;
00262         if(tower_energyet>maxet_) continue;;
00263 
00264         rp[etEcal    ]->addParticle (tower_energyet_e, s1,    s2,    tower_eta);
00265         rp[etEcalP   ]->addParticle (tower_energyet_e, s1,    s2,    tower_eta);
00266         rp[etEcalM   ]->addParticle (tower_energyet_e, s1,    s2,    tower_eta);
00267         rp[etHcal    ]->addParticle (tower_energyet_h, s1,    s2,    tower_eta);
00268         rp[etHcalP   ]->addParticle (tower_energyet_h, s1,    s2,    tower_eta);
00269         rp[etHcalM   ]->addParticle (tower_energyet_h, s1,    s2,    tower_eta);
00270         rp[etHF      ]->addParticle (tower_energyet,   s1,    s2,    tower_eta);
00271         rp[etHFp     ]->addParticle (tower_energyet,   s1,    s2,    tower_eta);
00272         rp[etHFm     ]->addParticle (tower_energyet,   s1,    s2,    tower_eta);
00273         rp[etCaloHFP ]->addParticle (tower_energyet,   s1,    s2,    tower_eta);
00274         rp[etCaloHFM ]->addParticle (tower_energyet,   s1,    s2,    tower_eta);
00275 
00276         rp[etHF3     ]->addParticle (tower_energyet,   s13,   s23,   tower_eta);
00277         rp[etHFp3    ]->addParticle (tower_energyet,   s13,   s23,   tower_eta);    
00278         rp[etHFm3    ]->addParticle (tower_energyet,   s13,   s23,   tower_eta);
00279 
00280         rp[etHF4     ]->addParticle (tower_energyet,   s14,   s24,   tower_eta);
00281         rp[etHFp4    ]->addParticle (tower_energyet,   s14,   s24,   tower_eta);    
00282         rp[etHFm4    ]->addParticle (tower_energyet,   s14,   s24,   tower_eta);
00283 
00284         rp[etHF5     ]->addParticle (tower_energyet,   s15,   s25,   tower_eta);
00285         rp[etHFp5    ]->addParticle (tower_energyet,   s15,   s25,   tower_eta);    
00286         rp[etHFm5    ]->addParticle (tower_energyet,   s15,   s25,   tower_eta);
00287 
00288         rp[etHF6     ]->addParticle (tower_energyet,   s16,   s26,   tower_eta);
00289         rp[etHFp6    ]->addParticle (tower_energyet,   s16,   s26,   tower_eta);    
00290         rp[etHFm6    ]->addParticle (tower_energyet,   s16,   s26,   tower_eta);
00291       } 
00292     }
00293     //Tracking part
00294     
00295     double track_eta;
00296     double track_phi;
00297     double track_pt;
00298 #ifdef TRACKCOLLECTION  
00299     Handle<reco::TrackCollection> tracks;
00300     iEvent.getByLabel(trackCollection_, tracks);
00301     
00302     if(tracks.isValid()){
00303       for(reco::TrackCollection::const_iterator j = tracks->begin(); j != tracks->end(); j++){
00304         
00305         //Find possible collections with command line: edmDumpEventContent *.root
00306 #endif
00307 #ifdef RECOCHARGEDCANDIDATECOLLECTION
00308         edm::Handle<reco::RecoChargedCandidateCollection> trackCollection;
00309         iEvent.getByLabel("allMergedPtSplit12Tracks",trackCollection);
00310         //      iEvent.getByLabel("hiGoodMergedTracks",trackCollection);
00311         if(trackCollection.isValid()){
00312           
00313           const reco::RecoChargedCandidateCollection * tracks = trackCollection.product();
00314           for(reco::RecoChargedCandidateCollection::const_iterator j = tracks->begin(); j != tracks->end(); j++){
00315 #endif  
00316         edm::Handle<reco::VertexCollection> vertex;
00317         iEvent.getByLabel(vtxCollection_, vertex);
00318         
00319 // find the vertex point and error
00320 
00321         math::XYZPoint vtxPoint(0.0,0.0,0.0);
00322         double vzErr =0.0, vxErr=0.0, vyErr=0.0;
00323         if(vertex->size()>0) {
00324           vtxPoint=vertex->begin()->position();
00325           vzErr=vertex->begin()->zError();
00326           vxErr=vertex->begin()->xError();
00327           vyErr=vertex->begin()->yError();
00328         }
00329         bool accepted = true;
00330         bool isPixel = false;
00331         // determine if the track is a pixel track
00332         if ( j->numberOfValidHits() < 7 ) isPixel = true;
00333         
00334         // determine the vertex significance 
00335         double d0=0.0, dz=0.0, d0sigma=0.0, dzsigma=0.0;
00336         d0 = -1.*j->dxy(vtxPoint);
00337         dz = j->dz(vtxPoint);
00338         d0sigma = sqrt(j->d0Error()*j->d0Error()+vxErr*vyErr);
00339         dzsigma = sqrt(j->dzError()*j->dzError()+vzErr*vzErr);
00340         
00341         // cuts for pixel tracks
00342         if( isPixel )
00343           {
00344             // dz significance cut 
00345             if ( fabs(dz/dzsigma) > dzerr_ ) accepted = false;
00346             
00347             // chi2/ndof cut 
00348             if ( j->normalizedChi2() > chi2_ ) accepted = false;
00349           }
00350         
00351         // cuts for full tracks
00352         if ( ! isPixel)
00353           {
00354             // dz and d0 significance cuts 
00355             if ( fabs(dz/dzsigma) > 3 ) accepted = false;
00356             if ( fabs(d0/d0sigma) > 3 ) accepted = false;
00357             
00358             // pt resolution cut
00359             if ( j->ptError()/j->pt() > 0.05 ) accepted = false;
00360             
00361             // number of valid hits cut
00362             if ( j->numberOfValidHits() < 12 ) accepted = false;
00363           }
00364         if( accepted ) {
00365           track_eta = j->eta();
00366           track_phi = j->phi();
00367           track_pt = j->pt();
00368           double s =sin(2*track_phi);
00369           double c =cos(2*track_phi);
00370           double s3 =sin(3*track_phi);
00371           double c3 =cos(3*track_phi);
00372           double s4 =sin(4*track_phi);
00373           double c4 =cos(4*track_phi);
00374           double s5 =sin(5*track_phi);
00375           double c5 =cos(5*track_phi);
00376           double s6 =sin(6*track_phi);
00377           double c6 =cos(6*track_phi);
00378           double w = 1;
00379           if(useTrackPtWeight_) {
00380             w = track_pt;
00381             if(w>2.5) w=2.0;   //v2 starts decreasing above ~2.5 GeV/c
00382           }
00383           if(track_pt<minpt_) continue;
00384           if(track_pt>maxpt_) continue;
00385           rp[EvtPlaneFromTracksMidEta]->addParticle(w,s,c,track_eta);
00386           rp[EvtPTracksPosEtaGap]->addParticle(w,s,c,track_eta);
00387           rp[EvtPTracksNegEtaGap]->addParticle(w,s,c,track_eta);
00388           rp[EPTracksMid3]->addParticle(w,s3,c3,track_eta);
00389           rp[EPTracksPos3]->addParticle(w,s3,c3,track_eta);
00390           rp[EPTracksNeg3]->addParticle(w,s3,c3,track_eta);
00391           rp[EPTracksMid4]->addParticle(w,s4,c4,track_eta);
00392           rp[EPTracksPos4]->addParticle(w,s4,c4,track_eta);
00393           rp[EPTracksNeg4]->addParticle(w,s4,c4,track_eta);
00394           rp[EPTracksMid5]->addParticle(w,s5,c5,track_eta);
00395           rp[EPTracksPos5]->addParticle(w,s5,c5,track_eta);
00396           rp[EPTracksNeg5]->addParticle(w,s5,c5,track_eta);
00397           rp[EPTracksMid6]->addParticle(w,s6,c6,track_eta);
00398           rp[EPTracksPos6]->addParticle(w,s6,c6,track_eta);
00399           rp[EPTracksNeg6]->addParticle(w,s6,c6,track_eta);
00400           
00401         }
00402         
00403       }
00404     }
00405       }
00406       std::auto_ptr<EvtPlaneCollection> evtplaneOutput(new EvtPlaneCollection);
00407       
00408   EvtPlane *ep[NumEPNames];
00409   
00410   double ang=-10;
00411   double sv = 0;
00412   double cv = 0;
00413 
00414   for(int i = 0; i<NumEPNames; i++) {
00415     rp[i]->getAngle(ang,sv,cv);
00416     if(storeNames_) ep[i] = new EvtPlane(ang,sv,cv,EPNames[i]);
00417     else ep[i] = new EvtPlane(ang,sv,cv,"");
00418   }
00419   if(useTrack_) {
00420     for(int i = 0; i<9; i++) {
00421       evtplaneOutput->push_back(*ep[i]);
00422     }  
00423   }
00424   for(int i = 9; i<NumEPNames; i++) {
00425     if(useECAL_ && !useHCAL_) {
00426       if(EPNames[i].rfind("Ecal")!=string::npos) {
00427         evtplaneOutput->push_back(*ep[i]);
00428       }
00429     } else if (useHCAL_ && !useECAL_) {
00430       if(EPNames[i].rfind("Hcal")!=string::npos) {
00431         evtplaneOutput->push_back(*ep[i]);
00432       }
00433     }else if (useECAL_ && useHCAL_) {
00434       evtplaneOutput->push_back(*ep[i]);
00435     }
00436   }
00437   
00438   iEvent.put(evtplaneOutput, "recoLevel");
00439   //  storeNames_ = 0;
00440 }
00441   
00442   // ------------ method called once each job just before starting event loop  ------------
00443 void 
00444 EvtPlaneProducer::beginJob()
00445 {
00446 }
00447 
00448 // ------------ method called once each job just after ending the event loop  ------------
00449 void 
00450 EvtPlaneProducer::endJob() {
00451 }
00452 
00453 //define this as a plug-in
00454 DEFINE_FWK_MODULE(EvtPlaneProducer);