CMS 3D CMS Logo

EcalRawToRecHitRoI.h

Go to the documentation of this file.
00001 #ifndef EventFilter_EcalRawToRecHitRoI_H
00002 #define EventFilter_EcalRawToRecHitRoI_H
00003 
00004 #include <FWCore/Framework/interface/EDProducer.h>
00005                                                                                              
00006 #include <DataFormats/Common/interface/Handle.h>
00007 #include <FWCore/Framework/interface/ESHandle.h>
00008 #include <FWCore/Framework/interface/Event.h>
00009 #include <FWCore/Framework/interface/EDProducer.h>
00010 #include <FWCore/MessageLogger/interface/MessageLogger.h>
00011 #include <FWCore/ParameterSet/interface/ParameterSet.h>
00012 
00013 #include "Geometry/EcalMapping/interface/EcalElectronicsMapping.h"
00014 
00015 #include "CondFormats/L1TObjects/interface/L1CaloGeometry.h"
00016 #include "DataFormats/L1Trigger/interface/L1EmParticleFwd.h"
00017 #include "DataFormats/L1Trigger/interface/L1JetParticleFwd.h"
00018 #include "DataFormats/Candidate/interface/Candidate.h"
00019 #include "DataFormats/Common/interface/View.h"
00020                                                                                              
00021 #include <iostream>
00022 #include <string>
00023 #include <vector>
00024 
00025 #include "DataFormats/Common/interface/LazyGetter.h"
00026 #include "DataFormats/Common/interface/RefGetter.h"
00027 #include "DataFormats/EcalRecHit/interface/EcalRecHit.h"
00028 
00029 //additionnal stuff to be more precise with candidates
00030 //#include "MagneticField/Engine/interface/MagneticField.h"
00031 #include "TrackingTools/Records/interface/TrackingComponentsRecord.h"
00032 #include "TrackingTools/GeomPropagators/interface/Propagator.h"
00033 #include "TrackingTools/GeomPropagators/interface/StateOnTrackerBound.h"
00034 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
00035 #include "TrackingTools/TrajectoryState/interface/FreeTrajectoryState.h"
00036 #include <FWCore/Framework/interface/EventSetup.h>
00037 
00038 class EcalRawToRecHitRoI : public edm::EDProducer {
00039 
00040   typedef edm::LazyGetter<EcalRecHit> EcalRecHitLazyGetter;
00041   typedef edm::RefGetter<EcalRecHit> EcalRecHitRefGetter;
00042 
00043 public:
00044 
00045         EcalRawToRecHitRoI(const edm::ParameterSet& pset);
00046         virtual ~EcalRawToRecHitRoI();
00047         void produce(edm::Event & e, const edm::EventSetup& c);
00048         void beginJob(const edm::EventSetup& c);
00049         void endJob(void);
00050 
00051  private:
00052 
00053         void Egamma(edm::Event& e, const edm::EventSetup& es, std::vector<int>& FEDs);
00054         void Muon(edm::Event& e, const edm::EventSetup& es, std::vector<int>& FEDs);
00055         void Jet(edm::Event& e, const edm::EventSetup& es, std::vector<int>& FEDs);
00056         void Cand(edm::Event& e, const edm::EventSetup& es, std::vector<int>& FEDs);
00057 
00058 
00060         edm::InputTag sourceTag_;
00061    
00063         const EcalElectronicsMapping* TheMapping;
00064      
00066         class CalUnpackJobPSet {
00067         public:
00068           CalUnpackJobPSet(){}
00069           CalUnpackJobPSet(edm::ParameterSet &cfg){
00070             Source = cfg.getParameter<edm::InputTag>("Source");
00071             Ptmin = cfg.getParameter<double>("Ptmin");
00072             regionEtaMargin = cfg.getParameter<double>("regionEtaMargin");
00073             regionPhiMargin = cfg.getParameter<double>("regionPhiMargin");
00074           }
00075           edm::InputTag Source;
00076           double Ptmin;
00077           double regionEtaMargin;
00078           double regionPhiMargin;
00079         };
00080 
00082         bool EGamma_;
00084         class EmJobPSet : public CalUnpackJobPSet {
00085         public:
00086           EmJobPSet(edm::ParameterSet &cfg) : CalUnpackJobPSet(cfg){}
00087             ~EmJobPSet(){}
00088         };
00090         void Egamma_OneL1EmCollection(const edm::Handle< l1extra::L1EmParticleCollection > emColl,
00091                                       const EmJobPSet & ejpset,
00092                                       const edm::ESHandle< L1CaloGeometry > & l1CaloGeom,
00093                                       std::vector<int> & FEDs);
00095         std::vector< EmJobPSet > EmSource_;
00096         
00098         bool Muon_ ;
00100         class MuJobPSet : public CalUnpackJobPSet {
00101         public:
00102           MuJobPSet(){}
00103           MuJobPSet(edm::ParameterSet &cfg) : CalUnpackJobPSet(cfg), epsilon(0.01) {}
00104             ~MuJobPSet(){}
00105             double epsilon;
00106         };
00108         MuJobPSet MuonSource_;
00109 
00111         bool Jet_ ;
00113         class JetJobPSet :public CalUnpackJobPSet {
00114         public:
00115           JetJobPSet(edm::ParameterSet &cfg) : CalUnpackJobPSet(cfg), epsilon(0.01) {}
00116             ~JetJobPSet(){}
00117             double epsilon;
00118         };
00120         void Jet_OneL1JetCollection(const edm::Handle< l1extra::L1JetParticleCollection > jetColl,
00121                                     const JetJobPSet & jjpset,
00122                                     std::vector<int> & feds);
00124         std::vector< JetJobPSet > JetSource_;
00125 
00127         bool Candidate_;
00129         class CandJobPSet : public CalUnpackJobPSet {
00130         public:
00131           enum CTYPE { view, candidate, chargedcandidate, l1muon, l1jet };
00132           CandJobPSet(edm::ParameterSet &cfg);
00133           ~CandJobPSet(){}
00134           double epsilon;
00135           bool bePrecise;
00136           std::string propagatorNameToBePrecise;
00137           CTYPE cType;
00138         };
00140         template <typename CollectionType> void OneCandCollection(const edm::Event& e,
00141                                                                   const edm::EventSetup& es,
00142                                                                   const CandJobPSet & cjpset,
00143                                                                   std::vector<int> & feds);
00144 
00146         std::vector< CandJobPSet > CandSource_;
00147 
00149         bool All_;
00150 
00152         void ListOfFEDS(double etaLow, double etaHigh, double phiLow,
00153                         double phiHigh, double etamargin, double phimargin,
00154                         std::vector<int>& FEDs);
00155         
00157         void unique(std::vector<int>& FEDs){
00158           std::sort(FEDs.begin(),FEDs.end());
00159           std::vector<int>::iterator n_end = std::unique(FEDs.begin(),FEDs.end());
00160           FEDs.erase(n_end,FEDs.end());}
00161         std::string dumpFEDs(const std::vector<int>& FEDs);
00162 };
00163 
00164 template <typename CollectionType> void EcalRawToRecHitRoI::OneCandCollection(const edm::Event& e,
00165                                                                               const edm::EventSetup& es,
00166                                                                               const CandJobPSet & cjpset,
00167                                                                               std::vector<int> & feds){
00168   const std::string category ="EcalRawToRecHit|Cand";
00169   
00170   edm::Handle<CollectionType> candColl;
00171   e.getByLabel(cjpset.Source, candColl);
00172   if (candColl.failedToGet()) {edm::LogError(category)<<"could not get: "<<cjpset.Source<<" of type: "<<cjpset.cType; return;}
00173 
00174   typename CollectionType::const_iterator it = candColl->begin();
00175   typename CollectionType::const_iterator end= candColl->end();
00176 
00177   StateOnTrackerBound * onBounds=0;
00178   edm::ESHandle<Propagator> propH;
00179   if (cjpset.bePrecise){
00180     //      grab a propagator from ES
00181     es.get<TrackingComponentsRecord>().get(cjpset.propagatorNameToBePrecise, propH);
00182     //      make the extrapolator object
00183     onBounds = new StateOnTrackerBound(propH.product());
00184   }
00185   
00186   for (; it!=end;++it){
00187     double pt    =  it->pt();
00188     double eta   =  it->eta();
00189     double phi   =  it->phi();
00190     if (cjpset.bePrecise){
00191       //      starting FTS
00192       GlobalPoint point(it->vx(),it->vy(),it->vz());
00193       GlobalVector vector(it->px(),it->py(),it->pz());
00194 
00195       if (point.mag()==0 && vector.mag()==0){
00196         edm::LogWarning(category)<<" state of candidate is not valid. skipping.";
00197         continue;
00198       }
00199 
00200       FreeTrajectoryState fts(point, vector, it->charge(), propH->magneticField());
00201       //      final TSOS
00202       TrajectoryStateOnSurface out = (*onBounds)(fts);
00203       if (out.isValid()){
00204         vector=out.globalMomentum();
00205         point=out.globalPosition();
00206         //      be more precise
00207         pt= vector.perp();
00208         eta= point.eta();
00209         phi= point.phi();
00210       }
00211       else{edm::LogError(category)<<"I tried to be precise, but propagation failed. from:\n"<<fts;
00212         continue;}
00213     }
00214     
00215     LogDebug(category)<<" here is a candidate Seed  with (eta,phi) = " 
00216                       <<eta << " " << phi << " and pt " << pt;
00217     if (pt < cjpset.Ptmin) continue;
00218     
00219     ListOfFEDS(eta, eta, phi-cjpset.epsilon, phi+cjpset.epsilon, cjpset.regionEtaMargin, cjpset.regionPhiMargin,feds);
00220   }
00221   if(cjpset.bePrecise){delete onBounds;}
00222 }
00223 
00224 #endif
00225 
00226 

Generated on Tue Jun 9 17:34:32 2009 for CMSSW by  doxygen 1.5.4