CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Protected Attributes
PhotonMIPHaloTagger Class Reference

#include <PhotonMIPHaloTagger.h>

Public Member Functions

std::vector< double > GetMipTrailFit (const reco::Photon *photon, const edm::Event &iEvent, const edm::EventSetup &iSetup, edm::Handle< EcalRecHitCollection > ecalhitsCollEB, double inputRangeY, double inputRangeX, double inputResWidth, double inputHaloDiscCut, int &NhitCone_, bool &ismipHalo_)
 
void GetSeedHighestE (const reco::Photon *photon, const edm::Event &iEvent, const edm::EventSetup &iSetup, edm::Handle< EcalRecHitCollection > Brechit, int &seedIEta, int &seedIPhi, double &seedE)
 
void MIPcalculate (const reco::Photon *, const edm::Event &, const edm::EventSetup &es, reco::Photon::MIPVariables &mipId)
 
 PhotonMIPHaloTagger ()
 
void setup (const edm::ParameterSet &conf, edm::ConsumesCollector &&iC)
 
virtual ~PhotonMIPHaloTagger ()
 

Protected Attributes

edm::EDGetToken EBecalCollection_
 
edm::EDGetToken EEecalCollection_
 
double haloDiscThreshold_
 
double inputHaloDiscCut
 
double inputRangeX
 
double inputRangeY
 
double inputResWidth
 
bool ismipHalo_
 
std::vector< double > mipFitResults_
 
int nhitCone_
 
double residualWidthEnergy_
 
double xRangeFit_
 
double yRangeFit_
 

Detailed Description

Definition at line 17 of file PhotonMIPHaloTagger.h.

Constructor & Destructor Documentation

PhotonMIPHaloTagger::PhotonMIPHaloTagger ( )
inline

Definition at line 21 of file PhotonMIPHaloTagger.h.

21 {};
virtual PhotonMIPHaloTagger::~PhotonMIPHaloTagger ( )
inlinevirtual

Definition at line 23 of file PhotonMIPHaloTagger.h.

23 {};

Member Function Documentation

std::vector< double > PhotonMIPHaloTagger::GetMipTrailFit ( const reco::Photon photon,
const edm::Event iEvent,
const edm::EventSetup iSetup,
edm::Handle< EcalRecHitCollection ecalhitsCollEB,
double  inputRangeY,
double  inputRangeX,
double  inputResWidth,
double  inputHaloDiscCut,
int &  NhitCone_,
bool &  ismipHalo_ 
)

Now Filll the FitResults vector

Definition at line 136 of file PhotonMIPHaloTagger.cc.

References Abs(), gather_cfg::cout, GetSeedHighestE(), EBDetId::ieta(), inputHaloDiscCut, inputRangeX, inputRangeY, inputResWidth, EBDetId::iphi(), j, visualization-live-secondInstance_cfg::m, edm::Handle< T >::product(), contentValuesCheck::ss, and reco::Photon::superCluster().

Referenced by MIPcalculate().

146 {
147  bool debug_= false;
148 
149  if(debug_)std::cout<<" inside MipFitTrail "<<std::endl;
150  //getting them from cfi config
151  double yrange = inputRangeY;
152  double xrange = inputRangeX;
153  double res_width = inputResWidth; //width of the residual distribution
154  double halo_disc_cut = inputHaloDiscCut; //cut based on Shower,Angle and MIP
155 
156 
157  //initilize them here
158  double m = 0.;
159  m = yrange/xrange; //slope of the lines which form the cone around the trail
160 
161 
162 
163 
164  //first get the seed cell index
165  int seedIEta = -999;
166  int seedIPhi = -999;
167  double seedE = -999.;
168 
169 
170  //get seed propert.
171  GetSeedHighestE(photon,
172  iEvent,
173  iSetup,
174  ecalhitsCollEB,
175  seedIEta,
176  seedIPhi,
177  seedE);
178 
179  if(debug_)std::cout<<"Seed E ="<<seedE<<" Seed ieta = "<<seedIEta<<" Seed iphi ="<< seedIPhi<<std::endl;
180 
181  //to store results
182  std::vector<double> FitResults_;
183  FitResults_.clear();
184 
185 
186  //create some vector and clear them
187  std::vector<int> ieta_cell;
188  std::vector<int> iphi_cell;
189  std::vector<double> energy_cell;
190 
191  ieta_cell.clear();
192  iphi_cell.clear();
193  energy_cell.clear();
194 
195 
196  int ietacell = 0;
197  int iphicell = 0;
198  int kArray = 0;
199 
200  double energy_total = 0.;
201  int delt_ieta =0;
202  int delt_iphi =0;
203 
204 
205  for(EcalRecHitCollection::const_iterator it = ecalhitsCollEB->begin();it!=ecalhitsCollEB->end();++it)
206  {
207  EBDetId dit = it->detid();
208 
209 
210  iphicell = dit.iphi();
211  ietacell = dit.ieta();
212 
213  if(ietacell < 0)ietacell++;
214 
215  //Exclude all cells within +/- 5 ieta of seed cell
216  if(TMath::Abs(ietacell - seedIEta) >= 5 && it->energy() > 0.)
217  {
218 
219  delt_ieta = ietacell - seedIEta;
220  delt_iphi = iphicell - seedIPhi;
221 
222  //Phi wrapping inclusion
223  if(delt_iphi > 180){ delt_iphi = delt_iphi - 360; }
224  if(delt_iphi < -180){ delt_iphi = delt_iphi + 360; }
225 
226  //Condition to be within the cones
227  if( ( (delt_iphi >= (m*delt_ieta)) && (delt_iphi <= (-m*delt_ieta)) ) ||
228  ( (delt_iphi <= (m*delt_ieta)) && (delt_iphi >= (-m*delt_ieta)) )
229  )
230  {
231  ieta_cell.push_back(delt_ieta);
232  iphi_cell.push_back(delt_iphi);
233  energy_cell.push_back(it->energy());
234  energy_total += it->energy();
235  kArray++;
236  }
237 
238  }//within cerntain range of seed cell
239 
240  }//loop voer hits
241 
242 
243 
244 //Iterations for imporovements
245 
246  int Npoints = 0;
247  int throwaway_index = -1;
248  double chi2;
249  double eT = 0.;
250  double hres = 99999.;
251 
252  //some tmp local variale
253  double Roundness_ =999.;
254  double Angle_ =999.;
255  double halo_disc_ =0.;
256 
257  Npoints = kArray;
258 
259  if(debug_)std::cout<<" starting npoing = "<<Npoints<<std::endl;
260 
261  //defined some variable for iterative fitting the mip trail line
262  double res = 0.0;
263  double res_sq = 0.0;
264  double wt = 0.0;
265  double sx = 0.0;
266  double sy = 0.0;
267  double ss = 0.0;
268  double sxx = 0.0;
269  double sxy = 0.0;
270  double delt = 0.0;
271  double a1 = 0.0;
272  double b1 = 0.0;
273  double m_chi2 = 0.0;
274  double etot_cell=0.0;
275 
276 
277  //start Iterations
278  for(int it=0; it < 200 && hres >(5.0*res_width); it++)
279  { //Max iter. is 200
280 
281 
282  //Throw away previous highest residual, if not first loop
283  if (throwaway_index!=-1)
284  {
285  ieta_cell.erase(ieta_cell.begin()+throwaway_index);
286  iphi_cell.erase(iphi_cell.begin()+throwaway_index);
287  energy_cell.erase(energy_cell.begin()+throwaway_index);
288  Npoints--;
289  }
290 
291 
292  //Lets Initialize them first for each iteration
293  res = 0.0;
294  res_sq = 0.0;
295  wt = 0.0;
296  sx = 0.0;
297  sy = 0.0;
298  ss = 0.0;
299  sxx = 0.0;
300  sxy = 0.0;
301  delt = 0.0;
302  a1 = 0.0;
303  b1 = 0.0;
304  m_chi2 = 0.0;
305  etot_cell=0.0;
306 
307 
308  //Fit the line to trail
309  for(int j=0; j<Npoints; j++)
310  {
311  wt = 1.0;
312  ss += wt;
313  sx += ieta_cell[j]*wt;
314  sy += iphi_cell[j];
315  sxx += ieta_cell[j]*ieta_cell[j]*wt;
316  sxy += ieta_cell[j]*iphi_cell[j]*wt;
317  }
318 
319  delt = ss*sxx - (sx*sx);
320  a1 = ((sxx*sy)-(sx*sxy))/delt; // INTERCEPT
321  b1 = ((ss*sxy)-(sx*sy))/delt; // SLOPE
322 
323 
324  double highest_res = 0.;
325  int highres_index = 0;
326 
327 
328  for(int j=0; j<Npoints; j++)
329  {
330  res = 1.0*iphi_cell[j] - a1 - b1*ieta_cell[j];
331  res_sq = res*res;
332 
333  if(TMath::Abs(res) > highest_res)
334  {
335  highest_res = TMath::Abs(res);
336  highres_index = j;
337  }
338 
339  m_chi2 += res_sq;
340  etot_cell += energy_cell[j];
341 
342  }
343 
344 
345  throwaway_index = highres_index;
346  hres = highest_res;
347 
348  chi2 = m_chi2 /((Npoints-2));
349  chi2 = chi2/(res_width*res_width);
350  eT = etot_cell;
351 
352  }//for loop for iterations
353 
354  if(debug_)std::cout<<"hres = "<<hres<<std::endl;
355 
356  //get roundness and angle for this photon candidate form EcalClusterTool
357  std::vector<float> showershapes_barrel = EcalClusterTools::roundnessBarrelSuperClusters(*(photon->superCluster()), (*ecalhitsCollEB.product()));
358 
359  Roundness_ = showershapes_barrel[0];
360  Angle_ = showershapes_barrel[1];
361 
362  if(debug_)std::cout<<" eTot ="<<eT<<" Rounness = "<<Roundness_<<" Angle_ "<<Angle_ <<std::endl;
363 
364  //get the halo disc variable
365  halo_disc_ = 0.;
366  halo_disc_ = eT/(Roundness_* Angle_);
367 
368 
370  FitResults_.push_back(chi2); //chi2
371  FitResults_.push_back(eT); //total energy
372  FitResults_.push_back(b1); //slope
373  FitResults_.push_back(a1); //intercept
374  NhitCone_ = Npoints; //nhit in cone
375  if(halo_disc_ > halo_disc_cut)ismipHalo_ = true; //is halo?, yes if halo_disc > 70 by default
376  // based on 2010 study
377 
378 
379  if(debug_)std::cout<<"Endof MIP Trail: halo_dic= "<<halo_disc_<<" nhitcone ="<<NhitCone_<<" isHalo= "<<ismipHalo_<<std::endl;
380  if(debug_)std::cout<<"Endof MIP Trail: Chi2 = "<<chi2<<" eT= "<<eT<<" slope = "<<b1<<" Intercept ="<<a1<<std::endl;
381 
382  return FitResults_;
383 
384 }
reco::SuperClusterRef superCluster() const
Ref to SuperCluster.
std::vector< EcalRecHit >::const_iterator const_iterator
void GetSeedHighestE(const reco::Photon *photon, const edm::Event &iEvent, const edm::EventSetup &iSetup, edm::Handle< EcalRecHitCollection > Brechit, int &seedIEta, int &seedIPhi, double &seedE)
int iphi() const
get the crystal iphi
Definition: EBDetId.h:53
T Abs(T a)
Definition: MathUtil.h:49
int j
Definition: DBlmapReader.cc:9
int ieta() const
get the crystal ieta
Definition: EBDetId.h:51
T const * product() const
Definition: Handle.h:81
tuple cout
Definition: gather_cfg.py:121
void PhotonMIPHaloTagger::GetSeedHighestE ( const reco::Photon photon,
const edm::Event iEvent,
const edm::EventSetup iSetup,
edm::Handle< EcalRecHitCollection Brechit,
int &  seedIEta,
int &  seedIPhi,
double &  seedE 
)

Definition at line 391 of file PhotonMIPHaloTagger.cc.

References gather_cfg::cout, DetId::Ecal, EcalBarrel, EBDetId::ieta(), EBDetId::iphi(), j, and reco::Photon::superCluster().

Referenced by GetMipTrailFit().

398 {
399 
400  bool debug_= false;
401 
402  if(debug_)std::cout<<"Inside GetSeed"<<std::endl;
403  //Get the Seed
404  double SeedE = -999.;
405 
406  //initilaze them here
407  seedIeta = -999;
408  seedIphi = -999;
409  seedEnergy = -999.;
410 
411 
412 
413 
414  std::vector< std::pair<DetId, float> > PhotonHit_DetIds = photon->superCluster()->hitsAndFractions();
415  int ncrys = 0;
416 
417  std::vector< std::pair<DetId, float> >::const_iterator detitr;
418  for(detitr = PhotonHit_DetIds.begin(); detitr != PhotonHit_DetIds.end(); ++detitr)
419  {
420 
421  if (((*detitr).first).det() == DetId::Ecal && ((*detitr).first).subdetId() == EcalBarrel)
422  {
423  EcalRecHitCollection::const_iterator j= Brechit->find(((*detitr).first));
425 
426  if ( j!= Brechit->end()) thishit = j;
427  if ( j== Brechit->end()){ continue;}
428 
429 
430  EBDetId detId = (EBDetId)((*detitr).first);
431 
432  double crysE = thishit->energy();
433 
434  if (crysE > SeedE)
435  {SeedE = crysE;
436  seedIeta = detId.ieta();
437  seedIphi = (detId.iphi());
438  seedEnergy = SeedE;
439 
440  if(debug_)std::cout<<"Current max Seed = "<<SeedE<<" seedIphi = "<<seedIphi<<" ieta= "<<seedIeta<<std::endl;
441 
442  }
443 
444  ncrys++;
445 
446 
447  }//check if in Barrel
448 
449  }//loop over EBrechits cells
450 
451 
452 
453  if(debug_)std::cout<<"End of GetSeed"<<std::endl;
454 
455 }
reco::SuperClusterRef superCluster() const
Ref to SuperCluster.
std::vector< EcalRecHit >::const_iterator const_iterator
int iphi() const
get the crystal iphi
Definition: EBDetId.h:53
int j
Definition: DBlmapReader.cc:9
int ieta() const
get the crystal ieta
Definition: EBDetId.h:51
tuple cout
Definition: gather_cfg.py:121
void PhotonMIPHaloTagger::MIPcalculate ( const reco::Photon pho,
const edm::Event e,
const edm::EventSetup es,
reco::Photon::MIPVariables mipId 
)

Definition at line 67 of file PhotonMIPHaloTagger.cc.

References gather_cfg::cout, EBecalCollection_, edm::Event::getByToken(), GetMipTrailFit(), haloDiscThreshold_, inputHaloDiscCut, inputRangeX, inputRangeY, inputResWidth, ismipHalo_, edm::HandleBase::isValid(), reco::Photon::MIPVariables::mipChi2, mipFitResults_, reco::Photon::MIPVariables::mipIntercept, reco::Photon::MIPVariables::mipIsHalo, reco::Photon::MIPVariables::mipNhitCone, reco::Photon::MIPVariables::mipSlope, reco::Photon::MIPVariables::mipTotEnergy, nhitCone_, residualWidthEnergy_, xRangeFit_, and yRangeFit_.

70  {
71 
72  //get the predefined variables
77 
78 
79 
80  //First store in local variables
81  mipFitResults_.clear();
82 
83  nhitCone_ = -99; //hit inside the cone
84  ismipHalo_ = false; // halo?
85 
86 
87 
88  // Get EcalRecHits
89  bool validEcalRecHits=true;
90 
91  edm::Handle<EcalRecHitCollection> barrelHitHandle;
92  e.getByToken(EBecalCollection_, barrelHitHandle);
93 
94  if (!barrelHitHandle.isValid()) {
95  edm::LogError("MIPcalculate") << "Error! Can't get the barrel hits product ";//<<EBecalCollection_.label(); (cant be bothered tracking the input tag just for this error message)
96  validEcalRecHits=false;
97  }
98 
99 
100  if(validEcalRecHits){
101  // GetMIPTrailFit
102  mipFitResults_ = GetMipTrailFit(pho, e, es,
103  barrelHitHandle,
105  nhitCone_,
106  ismipHalo_ );
107 
108 
109 
110  //Now set the variable in "MIPVaraible"
111  mipId.mipChi2 = mipFitResults_[0];
112  mipId.mipTotEnergy = mipFitResults_[1];
113  mipId.mipSlope = mipFitResults_[2];
114  mipId.mipIntercept = mipFitResults_[3];
115  mipId.mipNhitCone = nhitCone_;
116  mipId.mipIsHalo = ismipHalo_;
117  }
118  else{ std::cout<<"MIPCalculate::Ecal Collection is not there hence set some default values"<<std::endl;
119  mipId.mipChi2 = -999.;
120  mipId.mipTotEnergy = -999.;
121  mipId.mipSlope = -999.;
122  mipId.mipIntercept = -999.;
123  mipId.mipNhitCone = 0;
124  mipId.mipIsHalo = false;
125  }
126 
127  // std::cout<<"Setting: isHalo = "<<ismipHalo_<<" nhitcone= "<<nhitCone_<<std::endl;
128  // std::cout<<"Setting: Chi2 = "<<mipFitResults_[0]<<" eT= "<<mipFitResults_[1]<<" slope = "<<mipFitResults_[2]<<" Intercept ="<<mipFitResults_[3]<<std::endl;
129 }
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
edm::EDGetToken EBecalCollection_
std::vector< double > mipFitResults_
bool isValid() const
Definition: HandleBase.h:75
std::vector< double > GetMipTrailFit(const reco::Photon *photon, const edm::Event &iEvent, const edm::EventSetup &iSetup, edm::Handle< EcalRecHitCollection > ecalhitsCollEB, double inputRangeY, double inputRangeX, double inputResWidth, double inputHaloDiscCut, int &NhitCone_, bool &ismipHalo_)
tuple cout
Definition: gather_cfg.py:121
void PhotonMIPHaloTagger::setup ( const edm::ParameterSet conf,
edm::ConsumesCollector &&  iC 
)

Definition at line 48 of file PhotonMIPHaloTagger.cc.

References EBecalCollection_, EEecalCollection_, edm::ParameterSet::getParameter(), haloDiscThreshold_, residualWidthEnergy_, xRangeFit_, and yRangeFit_.

Referenced by GEDPhotonProducer::GEDPhotonProducer(), and PhotonProducer::PhotonProducer().

48  {
49 
50 
51  EBecalCollection_ = iC.consumes<EcalRecHitCollection>(conf.getParameter<edm::InputTag>("barrelEcalRecHitCollection"));
52  EEecalCollection_ = iC.consumes<EcalRecHitCollection>(conf.getParameter<edm::InputTag>("endcapEcalRecHitCollection"));
53 
54 
55  yRangeFit_ = conf.getParameter<double>("YRangeFit");
56  xRangeFit_ = conf.getParameter<double>("XRangeFit");
57  residualWidthEnergy_ = conf.getParameter<double>("ResidualWidth");
58  haloDiscThreshold_ = conf.getParameter<double>("HaloDiscThreshold");
59 
60 
61 }
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
edm::EDGetToken EBecalCollection_
edm::EDGetToken EEecalCollection_

Member Data Documentation

edm::EDGetToken PhotonMIPHaloTagger::EBecalCollection_
protected

Definition at line 62 of file PhotonMIPHaloTagger.h.

Referenced by MIPcalculate(), and setup().

edm::EDGetToken PhotonMIPHaloTagger::EEecalCollection_
protected

Definition at line 63 of file PhotonMIPHaloTagger.h.

Referenced by setup().

double PhotonMIPHaloTagger::haloDiscThreshold_
protected

Definition at line 78 of file PhotonMIPHaloTagger.h.

Referenced by MIPcalculate(), and setup().

double PhotonMIPHaloTagger::inputHaloDiscCut
protected

Definition at line 71 of file PhotonMIPHaloTagger.h.

Referenced by GetMipTrailFit(), and MIPcalculate().

double PhotonMIPHaloTagger::inputRangeX
protected

Definition at line 69 of file PhotonMIPHaloTagger.h.

Referenced by GetMipTrailFit(), and MIPcalculate().

double PhotonMIPHaloTagger::inputRangeY
protected

Definition at line 68 of file PhotonMIPHaloTagger.h.

Referenced by GetMipTrailFit(), and MIPcalculate().

double PhotonMIPHaloTagger::inputResWidth
protected

Definition at line 70 of file PhotonMIPHaloTagger.h.

Referenced by GetMipTrailFit(), and MIPcalculate().

bool PhotonMIPHaloTagger::ismipHalo_
protected

Definition at line 83 of file PhotonMIPHaloTagger.h.

Referenced by MIPcalculate().

std::vector<double> PhotonMIPHaloTagger::mipFitResults_
protected

Definition at line 81 of file PhotonMIPHaloTagger.h.

Referenced by MIPcalculate().

int PhotonMIPHaloTagger::nhitCone_
protected

Definition at line 82 of file PhotonMIPHaloTagger.h.

Referenced by MIPcalculate().

double PhotonMIPHaloTagger::residualWidthEnergy_
protected

Definition at line 77 of file PhotonMIPHaloTagger.h.

Referenced by MIPcalculate(), and setup().

double PhotonMIPHaloTagger::xRangeFit_
protected

Definition at line 76 of file PhotonMIPHaloTagger.h.

Referenced by MIPcalculate(), and setup().

double PhotonMIPHaloTagger::yRangeFit_
protected

Definition at line 75 of file PhotonMIPHaloTagger.h.

Referenced by MIPcalculate(), and setup().