CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PhotonRegressionValueMapProducer.cc
Go to the documentation of this file.
3 
6 
8 
11 
14 
16 
18 
19 #include <memory>
20 #include <vector>
21 
22 namespace {
23  // Cluster shapes
24  constexpr char sigmaIPhiIPhi_[] = "sigmaIPhiIPhi";
25  constexpr char sigmaIEtaIPhi_[] = "sigmaIEtaIPhi";
26  constexpr char e2x5Max_[] = "e2x5Max";
27  constexpr char e2x5Left_[] = "e2x5Left";
28  constexpr char e2x5Right_[] = "e2x5Right";
29  constexpr char e2x5Top_[] = "e2x5Top";
30  constexpr char e2x5Bottom_[] = "e2x5Bottom";
31 }
32 
34 
35  public:
36 
39 
40  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
41 
42  private:
43 
44  virtual void produce(edm::Event&, const edm::EventSetup&) override;
45 
48  const std::vector<float> & values,
49  const std::string & label) const ;
50 
51  // The object that will compute 5x5 quantities
52  std::unique_ptr<EcalClusterLazyToolsBase> lazyTools;
53 
54  // for AOD case
59 
60  // for miniAOD case
65 
66  const bool use_full5x5_;
67 };
68 
70  use_full5x5_(iConfig.getParameter<bool>("useFull5x5")) {
71 
72  //
73  // Declare consummables, handle both AOD and miniAOD case
74  //
75  ebReducedRecHitCollection_ = mayConsume<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>
76  ("ebReducedRecHitCollection"));
77  ebReducedRecHitCollectionMiniAOD_ = mayConsume<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>
78  ("ebReducedRecHitCollectionMiniAOD"));
79 
80  eeReducedRecHitCollection_ = mayConsume<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>
81  ("eeReducedRecHitCollection"));
82  eeReducedRecHitCollectionMiniAOD_ = mayConsume<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>
83  ("eeReducedRecHitCollectionMiniAOD"));
84 
85  esReducedRecHitCollection_ = mayConsume<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>
86  ("esReducedRecHitCollection"));
87  esReducedRecHitCollectionMiniAOD_ = mayConsume<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>
88  ("esReducedRecHitCollectionMiniAOD"));
89 
90  // reco photons are castable into pat photons, so no need to handle reco/pat seprately
91  src_ = mayConsume<edm::View<reco::Photon> >(iConfig.getParameter<edm::InputTag>("src"));
92  srcMiniAOD_ = mayConsume<edm::View<reco::Photon> >(iConfig.getParameter<edm::InputTag>("srcMiniAOD"));
93 
94  //
95  // Declare producibles
96  //
97  // Cluster shapes
98  produces<edm::ValueMap<float> >(sigmaIPhiIPhi_);
99  produces<edm::ValueMap<float> >(sigmaIEtaIPhi_);
100  produces<edm::ValueMap<float> >(e2x5Max_);
101  produces<edm::ValueMap<float> >(e2x5Left_);
102  produces<edm::ValueMap<float> >(e2x5Right_);
103  produces<edm::ValueMap<float> >(e2x5Top_);
104  produces<edm::ValueMap<float> >(e2x5Bottom_);
105 }
106 
108 {}
109 
110 template<typename LazyTools,typename SeedType>
111 inline void calculateValues(EcalClusterLazyToolsBase* tools_tocast,
112  const SeedType& the_seed,
113  std::vector<float>& sigmaIPhiIPhi,
114  std::vector<float>& sigmaIEtaIPhi,
115  std::vector<float>& e2x5Max,
116  std::vector<float>& e2x5Left,
117  std::vector<float>& e2x5Right,
118  std::vector<float>& e2x5Top,
119  std::vector<float>& e2x5Bottom) {
120  LazyTools* tools = static_cast<LazyTools*>(tools_tocast);
121 
122  float spp = -999;
123  std::vector<float> vCov = tools->localCovariances( the_seed );
124  spp = (isnan(vCov[2]) ? 0. : sqrt(vCov[2]));
125  float sep = vCov[1];
126  sigmaIPhiIPhi.push_back(spp);
127  sigmaIEtaIPhi.push_back(sep);
128  e2x5Max .push_back(tools->e2x5Max(the_seed) );
129  e2x5Left .push_back(tools->e2x5Left(the_seed) );
130  e2x5Right .push_back(tools->e2x5Right(the_seed) );
131  e2x5Top .push_back(tools->e2x5Top(the_seed) );
132  e2x5Bottom.push_back(tools->e2x5Bottom(the_seed) );
133 }
134 
136 
137  using namespace edm;
138 
140 
141  bool isAOD = true;
142  iEvent.getByToken(src_, src);
143  if(!src.isValid() ){
144  isAOD = false;
145  iEvent.getByToken(srcMiniAOD_, src);
146  }
147 
148  if( !src.isValid() ) {
149  throw cms::Exception("IllDefinedDataTier")
150  << "DataFormat does not contain a photon source!";
151  }
152 
153  // configure lazy tools
155 
156  if( isAOD ) {
160  } else {
164  }
165 
166  if( use_full5x5_ ) {
167  lazyTools.reset( new noZS::EcalClusterLazyTools(iEvent, iSetup,
168  ebrh, eerh, esrh ) );
169  } else {
170  lazyTools.reset( new EcalClusterLazyTools(iEvent, iSetup,
171  ebrh, eerh, esrh ) );
172  }
173 
174  if( !isAOD && src->size() ) {
175  edm::Ptr<pat::Photon> test(src->ptrAt(0));
176  if( test.isNull() || !test.isAvailable() ) {
177  throw cms::Exception("InvalidConfiguration")
178  <<"DataFormat is detected as miniAOD but cannot cast to pat::Photon!";
179  }
180  }
181 
182  // Cluster shapes
183  std::vector<float> sigmaIPhiIPhi;
184  std::vector<float> sigmaIEtaIPhi;
185  std::vector<float> e2x5Max;
186  std::vector<float> e2x5Left;
187  std::vector<float> e2x5Right;
188  std::vector<float> e2x5Top;
189  std::vector<float> e2x5Bottom;
190 
191  // reco::Photon::superCluster() is virtual so we can exploit polymorphism
192  for (unsigned idxpho = 0; idxpho < src->size(); ++idxpho) {
193  const auto& iPho = src->ptrAt(idxpho);
194 
195  //
196  // Compute full 5x5 quantities
197  //
198  const auto& theseed = *(iPho->superCluster()->seed());
199 
200  if( use_full5x5_ ) {
201  calculateValues<noZS::EcalClusterLazyTools>(lazyTools.get(),
202  theseed,
203  sigmaIPhiIPhi,
204  sigmaIEtaIPhi,
205  e2x5Max,
206  e2x5Left,
207  e2x5Right,
208  e2x5Top,
209  e2x5Bottom);
210  } else {
211  calculateValues<EcalClusterLazyTools>(lazyTools.get(),
212  theseed,
213  sigmaIPhiIPhi,
214  sigmaIEtaIPhi,
215  e2x5Max,
216  e2x5Left,
217  e2x5Right,
218  e2x5Top,
219  e2x5Bottom);
220  }
221  }
222 
223  // Cluster shapes
224  writeValueMap(iEvent, src, sigmaIPhiIPhi, sigmaIPhiIPhi_);
225  writeValueMap(iEvent, src, sigmaIEtaIPhi, sigmaIEtaIPhi_);
226  writeValueMap(iEvent, src, e2x5Max, e2x5Max_);
227  writeValueMap(iEvent, src, e2x5Left, e2x5Left_);
228  writeValueMap(iEvent, src, e2x5Right, e2x5Right_);
229  writeValueMap(iEvent, src, e2x5Top, e2x5Top_);
230  writeValueMap(iEvent, src, e2x5Bottom, e2x5Bottom_);
231 
232  lazyTools.reset(nullptr);
233 }
234 
237  const std::vector<float> & values,
238  const std::string & label) const
239 {
240  using namespace edm;
241  using namespace std;
242  auto_ptr<ValueMap<float> > valMap(new ValueMap<float>());
243  edm::ValueMap<float>::Filler filler(*valMap);
244  filler.insert(handle, values.begin(), values.end());
245  filler.fill();
246  iEvent.put(valMap, label);
247 }
248 
250  //The following says we do not know what parameters are allowed so do no validation
251  // Please change this to state exactly what you do use, even if it is no parameters
253  desc.setUnknown();
254  descriptions.addDefault(desc);
255 }
256 
T getParameter(std::string const &) const
EcalClusterLazyToolsT<::EcalClusterTools > EcalClusterLazyTools
std::unique_ptr< EcalClusterLazyToolsBase > lazyTools
edm::EDGetTokenT< EcalRecHitCollection > ebReducedRecHitCollectionMiniAOD_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:449
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
edm::EDGetTokenT< EcalRecHitCollection > esReducedRecHitCollectionMiniAOD_
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:52
edm::EDGetTokenT< EcalRecHitCollection > eeReducedRecHitCollection_
edm::EDGetTokenT< EcalRecHitCollection > ebReducedRecHitCollection_
#define constexpr
int iEvent
Definition: GenABIO.cc:230
void addDefault(ParameterSetDescription const &psetDescription)
PhotonRegressionValueMapProducer(const edm::ParameterSet &)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
bool isnan(float x)
Definition: math.h:13
T sqrt(T t)
Definition: SSEVec.h:48
tuple handle
Definition: patZpeak.py:22
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void writeValueMap(edm::Event &iEvent, const edm::Handle< edm::View< reco::Photon > > &handle, const std::vector< float > &values, const std::string &label) const
void calculateValues(EcalClusterLazyToolsBase *tools_tocast, const edm::Ptr< reco::GsfElectron > &iEle, const edm::EventSetup &iSetup, std::vector< float > &vsigmaIEtaIPhi, std::vector< float > &veMax, std::vector< float > &ve2nd, std::vector< float > &veTop, std::vector< float > &veBottom, std::vector< float > &veLeft, std::vector< float > &veRight, std::vector< float > &vclusterMaxDR, std::vector< float > &vclusterMaxDRDPhi, std::vector< float > &vclusterMaxDRDEta, std::vector< float > &vclusterMaxDRRawEnergy, std::vector< float > &vclusterRawEnergy0, std::vector< float > &vclusterRawEnergy1, std::vector< float > &vclusterRawEnergy2, std::vector< float > &vclusterDPhiToSeed0, std::vector< float > &vclusterDPhiToSeed1, std::vector< float > &vclusterDPhiToSeed2, std::vector< float > &vclusterDEtaToSeed0, std::vector< float > &vclusterDEtaToSeed1, std::vector< float > &vclusterDEtaToSeed2, std::vector< int > &veleIPhi, std::vector< int > &veleIEta, std::vector< float > &veleCryPhi, std::vector< float > &veleCryEta)
edm::EDGetTokenT< EcalRecHitCollection > esReducedRecHitCollection_
edm::EDGetTokenT< EcalRecHitCollection > eeReducedRecHitCollectionMiniAOD_
virtual void produce(edm::Event &, const edm::EventSetup &) override