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