CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PFSuperClusterTreeMaker.cc
Go to the documentation of this file.
1 //
2 // Class: PFSuperClusterTreeMaker.cc
3 //
4 // Info: Processes a track into histograms of delta-phis and such
5 //
6 // Author: L. Gray (FNAL)
7 //
8 
9 #include <memory>
10 #include <map>
11 
17 
22 
25 
28 #include "TTree.h"
29 #include "TVector2.h"
30 
32 
35 
37 namespace MK = reco::MustacheKernel;
38 
40 
41 #include <algorithm>
42 #include <memory>
43 
45 
46 namespace {
47  template<typename T>
48  struct array_deleter{
49  void operator () (T* arr) { delete [] arr; }
50  };
51 
52  typedef std::unary_function<const edm::Ptr<reco::PFCluster>&,
53  double> ClusUnaryFunction;
54 
55  struct GetSharedRecHitFraction : public ClusUnaryFunction {
56  const edm::Ptr<reco::PFCluster> the_seed;
57  double x_rechits_tot, x_rechits_match;
58  GetSharedRecHitFraction(const edm::Ptr<reco::PFCluster>& s) :
59  the_seed(s) {}
60  double operator()(const edm::Ptr<reco::PFCluster>& x) {
61  // now see if the clusters overlap in rechits
62  const auto& seedHitsAndFractions =
63  the_seed->hitsAndFractions();
64  const auto& xHitsAndFractions =
65  x->hitsAndFractions();
66  x_rechits_tot = xHitsAndFractions.size();
67  x_rechits_match = 0.0;
68  for( const std::pair<DetId, float>& seedHit : seedHitsAndFractions ) {
69  for( const std::pair<DetId, float>& xHit : xHitsAndFractions ) {
70  if( seedHit.first == xHit.first ) {
71  x_rechits_match += 1.0;
72  }
73  }
74  }
75  return x_rechits_match/x_rechits_tot;
76  }
77  };
78 }
79 
81  typedef TTree* treeptr;
82 public:
85 
86  void analyze(const edm::Event&, const edm::EventSetup&);
87 private:
89  bool _dogen;
93  std::shared_ptr<PFEnergyCalibration> _calib;
95  const reco::SuperCluster&);
96  // the tree
97  void setTreeArraysForSize(const size_t N_ECAL,const size_t N_PS);
99  Int_t nVtx;
105  std::shared_ptr<Float_t> clusterRawEnergy, clusterCalibEnergy,
109  std::shared_ptr<Int_t> clusterInMustache, clusterInDynDPhi;
111  std::shared_ptr<Float_t> psClusterRawEnergy, psClusterEta, psClusterPhi;
112 };
113 
115  const edm::EventSetup& es) {
117  e.getByLabel(_vtxsrc,vtcs);
118  if( vtcs.isValid() ) nVtx = vtcs->size();
119  else nVtx = -1;
120 
122  e.getByLabel(_scInputEB, ebSCs);
123  e.getByLabel(_scInputEE, eeSCs);
124 
125  if( ebSCs.isValid() ) {
126  for( const auto& sc : *ebSCs ) processSuperClusterFillTree(e,sc);
127  } else {
128  throw cms::Exception("PFSuperClusterTreeMaker")
129  << "Product ID for the EB SuperCluster collection was invalid!"
130  << std::endl;
131  }
132 
133  if( eeSCs.isValid() ) {
134  for( const auto& sc : *eeSCs ) processSuperClusterFillTree(e,sc);
135  } else {
136  throw cms::Exception("PFSuperClusterTreeMaker")
137  << "Product ID for the EE SuperCluster collection was invalid!"
138  << std::endl;
139  }
140 }
141 
144  const reco::SuperCluster& sc) {
145  const int N_ECAL = sc.clustersEnd() - sc.clustersBegin();
146  const int N_PS = ( sc.preshowerClustersEnd() -
147  sc.preshowerClustersBegin() );
148  if( sc.rawEnergy()/std::cosh(sc.position().Eta()) < 4.0 ) return;
149  N_ECALClusters = std::max(0,N_ECAL - 1); // minus 1 because of seed
150  N_PSClusters = N_PS;
151  reco::GenParticleRef genmatch;
152  // gen information (if needed)
153  if( _dogen ) {
155  e.getByLabel(_geninput,genp);
156  if( genp.isValid() ) {
157  double minDr = 1e6, this_dr;
158  reco::GenParticleRef bestmatch;
159  for(size_t i = 0; i < genp->size(); ++i) {
160  this_dr = reco::deltaR(genp->at(i),sc);
161  // oh hai, this is hard coded to photons for the time being
162  if( this_dr < minDr && genp->at(i).pdgId() == 22) {
163  minDr = this_dr;
164  bestmatch = reco::GenParticleRef(genp,i);
165  }
166  }
167  if( bestmatch.isNonnull() ) {
168  genmatch = bestmatch;
169  genEnergy = bestmatch->energy();
170  genEta = bestmatch->eta();
171  genPhi = bestmatch->phi();
172  genDRToCentroid = minDr;
173  genDRToSeed = reco::deltaR(*bestmatch,*(sc.seed()));
174  } else {
175  genEnergy = -1.0;
176  genEta = 999.0;
177  genPhi = 999.0;
178  genDRToCentroid = 999.0;
179  genDRToSeed = 999.0;
180  }
181  } else {
182  throw cms::Exception("PFSuperClusterTreeMaker")
183  << "Requested generator level information was not available!"
184  << std::endl;
185  }
186  }
187  // supercluster information
189  scRawEnergy = sc.rawEnergy();
190  scCalibratedEnergy = sc.energy();
192  scEta = sc.position().Eta();
193  scPhi = sc.position().Phi();
194  scR = sc.position().R();
195  scPhiWidth = sc.phiWidth();
196  scEtaWidth = sc.etaWidth();
197  // sc seed information
199  GetSharedRecHitFraction fractionOfSeed(theseed);
200  scSeedRawEnergy = theseed->energy();
201  scSeedCalibratedEnergy = _calib->energyEm(*theseed,0.0,0.0,false);
202  scSeedEta = theseed->eta();
203  scSeedPhi = theseed->phi();
204  // loop over all clusters that aren't the seed
205  auto clusend = sc.clustersEnd();
206  size_t iclus = 0;
208  for( auto clus = sc.clustersBegin(); clus != clusend; ++clus ) {
209  pclus = edm::Ptr<reco::PFCluster>(*clus);
210  if( theseed == pclus ) continue;
211  clusterRawEnergy.get()[iclus] = pclus->energy();
212  clusterCalibEnergy.get()[iclus] = _calib->energyEm(*pclus,0.0,0.0,false);
213  clusterEta.get()[iclus] = pclus->eta();
214  clusterPhi.get()[iclus] = pclus->phi();
215  clusterDPhiToSeed.get()[iclus] =
216  TVector2::Phi_mpi_pi(pclus->phi() - theseed->phi());
217  clusterDEtaToSeed.get()[iclus] = pclus->eta() - theseed->eta();
218  clusterDPhiToCentroid.get()[iclus] =
219  TVector2::Phi_mpi_pi(pclus->phi() - sc.phi());
220  clusterDEtaToCentroid.get()[iclus] = pclus->eta() - sc.eta();
221  clusterDPhiToCentroid.get()[iclus] =
222  TVector2::Phi_mpi_pi(pclus->phi() - sc.phi());
223  clusterDEtaToCentroid.get()[iclus] = pclus->eta() - sc.eta();
224  clusterHitFractionSharedWithSeed.get()[iclus] = fractionOfSeed(pclus);
225  if( _dogen && genmatch.isNonnull() ) {
226  clusterDPhiToGen.get()[iclus] =
227  TVector2::Phi_mpi_pi(pclus->phi() - genmatch->phi());
228  clusterDEtaToGen.get()[iclus] = pclus->eta() - genmatch->eta();
229  }
230  clusterInMustache.get()[iclus] = (Int_t) MK::inMustache(theseed->eta(),
231  theseed->phi(),
232  pclus->energy(),
233  pclus->eta(),
234  pclus->phi());
235  clusterInDynDPhi.get()[iclus] = (Int_t)
237  theseed->phi(),
238  pclus->energy(),
239  pclus->eta(),
240  pclus->phi());
241  ++iclus;
242  }
243  // loop over all preshower clusters
244  auto psclusend = sc.preshowerClustersEnd();
245  size_t ipsclus = 0;
247  for( auto psclus = sc.preshowerClustersBegin(); psclus != psclusend;
248  ++psclus ) {
249  ppsclus = edm::Ptr<reco::PFCluster>(*psclus);
250  psClusterRawEnergy.get()[ipsclus] = ppsclus->energy();
251  psClusterEta.get()[ipsclus] = ppsclus->eta();
252  psClusterPhi.get()[ipsclus] = ppsclus->phi();
253  ++ipsclus;
254  }
255  _tree->Fill();
256 }
257 
259  _calib.reset(new PFEnergyCalibration());
260  N_ECALClusters = 1;
261  N_PSClusters = 1;
262  _tree = _fs->make<TTree>("SuperClusterTree","Dump of all available SC info");
263  _tree->Branch("N_ECALClusters",&N_ECALClusters,"N_ECALClusters/I");
264  _tree->Branch("N_PSClusters",&N_PSClusters,"N_PSClusters/I");
265  _tree->Branch("nVtx",&nVtx,"nVtx/I");
266  _tree->Branch("scRawEnergy",&scRawEnergy,"scRawEnergy/F");
267  _tree->Branch("scCalibratedEnergy",&scCalibratedEnergy,
268  "scCalibratedEnergy/F");
269  _tree->Branch("scPreshowerEnergy",&scPreshowerEnergy,"scPreshowerEnergy/F");
270  _tree->Branch("scEta",&scEta,"scEta/F");
271  _tree->Branch("scPhi",&scPhi,"scPhi/F");
272  _tree->Branch("scR",&scR,"scR/F");
273  _tree->Branch("scPhiWidth",&scPhiWidth,"scPhiWidth/F");
274  _tree->Branch("scEtaWidth",&scEtaWidth,"scEtaWidth/F");
275  _tree->Branch("scSeedRawEnergy",&scSeedRawEnergy,"scSeedRawEnergy/F");
276  _tree->Branch("scSeedCalibratedEnergy",&scSeedCalibratedEnergy,
277  "scSeedCalibratedEnergy/F");
278  _tree->Branch("scSeedEta",&scSeedEta,"scSeedEta/F");
279  _tree->Branch("scSeedPhi",&scSeedPhi,"scSeedPhi/F");
280  // ecal cluster information
281  clusterRawEnergy.reset(new Float_t[1],array_deleter<Float_t>());
282  _tree->Branch("clusterRawEnergy",clusterRawEnergy.get(),
283  "clusterRawEnergy[N_ECALClusters]/F");
284  clusterCalibEnergy.reset(new Float_t[1],array_deleter<Float_t>());
285  _tree->Branch("clusterCalibEnergy",clusterCalibEnergy.get(),
286  "clusterCalibEnergy[N_ECALClusters]/F");
287  clusterEta.reset(new Float_t[1],array_deleter<Float_t>());
288  _tree->Branch("clusterEta",clusterEta.get(),
289  "clusterEta[N_ECALClusters]/F");
290  clusterPhi.reset(new Float_t[1],array_deleter<Float_t>());
291  _tree->Branch("clusterPhi",clusterPhi.get(),
292  "clusterPhi[N_ECALClusters]/F");
293  clusterDPhiToSeed.reset(new Float_t[1],array_deleter<Float_t>());
294  _tree->Branch("clusterDPhiToSeed",clusterDPhiToSeed.get(),
295  "clusterDPhiToSeed[N_ECALClusters]/F");
296  clusterDEtaToSeed.reset(new Float_t[1],array_deleter<Float_t>());
297  _tree->Branch("clusterDEtaToSeed",clusterDEtaToSeed.get(),
298  "clusterDEtaToSeed[N_ECALClusters]/F");
299  clusterDPhiToCentroid.reset(new Float_t[1],array_deleter<Float_t>());
300  _tree->Branch("clusterDPhiToCentroid",clusterDPhiToCentroid.get(),
301  "clusterDPhiToCentroid[N_ECALClusters]/F");
302  clusterDEtaToCentroid.reset(new Float_t[1],array_deleter<Float_t>());
303  _tree->Branch("clusterDEtaToCentroid",clusterDEtaToCentroid.get(),
304  "clusterDEtaToCentroid[N_ECALClusters]/F");
305  clusterHitFractionSharedWithSeed.reset(new Float_t[1],
306  array_deleter<Float_t>());
307  _tree->Branch("clusterHitFractionSharedWithSeed",
309  "clusterHitFractionSharedWithSeed[N_ECALClusters]/F");
310  clusterInMustache.reset(new Int_t[1],array_deleter<Int_t>());
311  _tree->Branch("clusterInMustache",clusterInMustache.get(),
312  "clusterInMustache[N_ECALClusters]/I");
313  clusterInDynDPhi.reset(new Int_t[1],array_deleter<Int_t>());
314  _tree->Branch("clusterInDynDPhi",clusterInDynDPhi.get(),
315  "clusterInDynDPhi[N_ECALClusters]/I");
316  // preshower information
317  psClusterRawEnergy.reset(new Float_t[1],array_deleter<Float_t>());
318  _tree->Branch("psClusterRawEnergy",psClusterRawEnergy.get(),
319  "psClusterRawEnergy[N_PSClusters]/F");
320  psClusterEta.reset(new Float_t[1],array_deleter<Float_t>());
321  _tree->Branch("psClusterEta",psClusterEta.get(),
322  "psClusterEta[N_PSClusters]/F");
323  psClusterPhi.reset(new Float_t[1],array_deleter<Float_t>());
324  _tree->Branch("psClusterPhi",psClusterPhi.get(),
325  "psClusterPhi[N_PSClusters]/F");
326 
327 
328  if( (_dogen = p.getUntrackedParameter<bool>("doGen",false)) ) {
329  _geninput = p.getParameter<edm::InputTag>("genSrc");
330  _tree->Branch("genEta",&genEta,"genEta/F");
331  _tree->Branch("genPhi",&genPhi,"genPhi/F");
332  _tree->Branch("genEnergy",&genEnergy,"genEnergy/F");
333  _tree->Branch("genDRToCentroid",&genDRToCentroid,"genDRToCentroid/F");
334  _tree->Branch("genDRToSeed",&genDRToSeed,"genDRToSeed/F");
335 
336  clusterDPhiToGen.reset(new Float_t[1],array_deleter<Float_t>());
337  _tree->Branch("clusterDPhiToGen",clusterDPhiToGen.get(),
338  "clusterDPhiToGen[N_ECALClusters]/F");
339  clusterDEtaToGen.reset(new Float_t[1],array_deleter<Float_t>());
340  _tree->Branch("clusterDEtaToGen",clusterDEtaToGen.get(),
341  "clusterDPhiToGen[N_ECALClusters]/F");
342  }
343  _vtxsrc = p.getParameter<edm::InputTag>("primaryVertices");
344  _scInputEB = p.getParameter<edm::InputTag>("superClusterSrcEB");
345  _scInputEE = p.getParameter<edm::InputTag>("superClusterSrcEE");
346 }
347 
348 
350  const size_t N_PS) {
351  Float_t* cRE_new = new Float_t[N_ECAL];
352  clusterRawEnergy.reset(cRE_new,array_deleter<Float_t>());
353  _tree->GetBranch("clusterRawEnergy")->SetAddress(clusterRawEnergy.get());
354  Float_t* cCE_new = new Float_t[N_ECAL];
355  clusterCalibEnergy.reset(cCE_new,array_deleter<Float_t>());
356  _tree->GetBranch("clusterCalibEnergy")->SetAddress(clusterCalibEnergy.get());
357  Float_t* cEta_new = new Float_t[N_ECAL];
358  clusterEta.reset(cEta_new,array_deleter<Float_t>());
359  _tree->GetBranch("clusterEta")->SetAddress(clusterEta.get());
360  Float_t* cPhi_new = new Float_t[N_ECAL];
361  clusterPhi.reset(cPhi_new,array_deleter<Float_t>());
362  _tree->GetBranch("clusterPhi")->SetAddress(clusterPhi.get());
363  Float_t* cDPhiSeed_new = new Float_t[N_ECAL];
364  clusterDPhiToSeed.reset(cDPhiSeed_new,array_deleter<Float_t>());
365  _tree->GetBranch("clusterDPhiToSeed")->SetAddress(clusterDPhiToSeed.get());
366  Float_t* cDEtaSeed_new = new Float_t[N_ECAL];
367  clusterDEtaToSeed.reset(cDEtaSeed_new,array_deleter<Float_t>());
368  _tree->GetBranch("clusterDEtaToSeed")->SetAddress(clusterDEtaToSeed.get());
369  Float_t* cDPhiCntr_new = new Float_t[N_ECAL];
370  clusterDPhiToCentroid.reset(cDPhiCntr_new,array_deleter<Float_t>());
371  _tree->GetBranch("clusterDPhiToCentroid")->SetAddress(clusterDPhiToCentroid.get());
372  Float_t* cDEtaCntr_new = new Float_t[N_ECAL];
373  clusterDEtaToCentroid.reset(cDEtaCntr_new,array_deleter<Float_t>());
374  _tree->GetBranch("clusterDEtaToCentroid")->SetAddress(clusterDEtaToCentroid.get());
375  Float_t* cHitFracShared_new = new Float_t[N_ECAL];
376  clusterHitFractionSharedWithSeed.reset(cHitFracShared_new,
377  array_deleter<Float_t>());
378  _tree->GetBranch("clusterHitFractionSharedWithSeed")->SetAddress(clusterHitFractionSharedWithSeed.get());
379 
380  if( _dogen ) {
381  Float_t* cDPhiGen_new = new Float_t[N_ECAL];
382  clusterDPhiToGen.reset(cDPhiGen_new,array_deleter<Float_t>());
383  _tree->GetBranch("clusterDPhiToGen")->SetAddress(clusterDPhiToGen.get());
384  Float_t* cDEtaGen_new = new Float_t[N_ECAL];
385  clusterDEtaToGen.reset(cDEtaGen_new,array_deleter<Float_t>());
386  _tree->GetBranch("clusterDEtaToGen")->SetAddress(clusterDEtaToGen.get());
387  }
388  Int_t* cInMust_new = new Int_t[N_ECAL];
389  clusterInMustache.reset(cInMust_new,array_deleter<Int_t>());
390  _tree->GetBranch("clusterInMustache")->SetAddress(clusterInMustache.get());
391  Int_t* cInDynDPhi_new = new Int_t[N_ECAL];
392  clusterInDynDPhi.reset(cInDynDPhi_new,array_deleter<Int_t>());
393  _tree->GetBranch("clusterInDynDPhi")->SetAddress(clusterInDynDPhi.get());
394  Float_t* psRE_new = new Float_t[N_PS];
395  psClusterRawEnergy.reset(psRE_new,array_deleter<Float_t>());
396  _tree->GetBranch("psClusterRawEnergy")->SetAddress(psClusterRawEnergy.get());
397  Float_t* psEta_new = new Float_t[N_PS];
398  psClusterEta.reset(psEta_new,array_deleter<Float_t>());
399  _tree->GetBranch("psClusterEta")->SetAddress(psClusterEta.get());
400  Float_t* psPhi_new = new Float_t[N_PS];
401  psClusterPhi.reset(psPhi_new,array_deleter<Float_t>());
402  _tree->GetBranch("psClusterPhi")->SetAddress(psClusterPhi.get());
403 }
404 
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
const math::XYZPoint & position() const
cluster centroid position
Definition: CaloCluster.h:123
CaloCluster_iterator preshowerClustersBegin() const
fist iterator over PreshowerCluster constituents
Definition: SuperCluster.h:77
int i
Definition: DBlmapReader.cc:9
std::shared_ptr< Float_t > psClusterRawEnergy
double phiWidth() const
obtain phi and eta width of the Super Cluster
Definition: SuperCluster.h:57
bool inDynamicDPhiWindow(const bool isEE, const float seedPhi, const float ClustE, const float ClusEta, const float clusPhi)
Definition: Mustache.cc:74
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::shared_ptr< Float_t > clusterPhi
edm::Ref< GenParticleCollection > GenParticleRef
persistent reference to a GenParticle
std::shared_ptr< Float_t > clusterCalibEnergy
void setTreeArraysForSize(const size_t N_ECAL, const size_t N_PS)
double Phi_mpi_pi(double x)
Definition: JetUtil.h:24
std::shared_ptr< PFEnergyCalibration > _calib
std::shared_ptr< Float_t > clusterDEtaToCentroid
std::shared_ptr< Float_t > clusterHitFractionSharedWithSeed
double eta() const
pseudorapidity of cluster centroid
Definition: CaloCluster.h:160
edm::Service< TFileService > _fs
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:250
double etaWidth() const
Definition: SuperCluster.h:58
const T & max(const T &a, const T &b)
auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:30
double energy() const
cluster energy
Definition: CaloCluster.h:120
std::shared_ptr< Float_t > psClusterPhi
std::shared_ptr< Float_t > clusterDPhiToSeed
bool isValid() const
Definition: HandleBase.h:76
tuple genp
produce generated paricles in acceptance #
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
edm::ParameterSet PSet
double rawEnergy() const
raw uncorrected energy (sum of energies of component BasicClusters)
Definition: SuperCluster.h:49
std::shared_ptr< Float_t > clusterDPhiToGen
void analyze(const edm::Event &, const edm::EventSetup &)
std::shared_ptr< Float_t > psClusterEta
std::shared_ptr< Int_t > clusterInMustache
std::shared_ptr< Float_t > clusterEta
std::shared_ptr< Float_t > clusterDEtaToSeed
CaloCluster_iterator clustersBegin() const
fist iterator over BasicCluster constituents
Definition: SuperCluster.h:71
T * make() const
make new ROOT object
const CaloClusterPtr & seed() const
seed BasicCluster
Definition: SuperCluster.h:68
double preshowerEnergy() const
energy deposited in preshower
Definition: SuperCluster.h:52
Definition: DDAxes.h:10
std::shared_ptr< Int_t > clusterInDynDPhi
std::shared_ptr< Float_t > clusterRawEnergy
double phi() const
azimuthal angle of cluster centroid
Definition: CaloCluster.h:163
long double T
std::shared_ptr< Float_t > clusterDEtaToGen
std::shared_ptr< Float_t > clusterDPhiToCentroid
bool inMustache(const float maxEta, const float maxPhi, const float ClustE, const float ClusEta, const float ClusPhi)
Definition: Mustache.cc:9
CaloCluster_iterator preshowerClustersEnd() const
last iterator over PreshowerCluster constituents
Definition: SuperCluster.h:80
list at
Definition: asciidump.py:428
CaloCluster_iterator clustersEnd() const
last iterator over BasicCluster constituents
Definition: SuperCluster.h:74
void processSuperClusterFillTree(const edm::Event &, const reco::SuperCluster &)