CMS 3D CMS Logo

FWECALCaloDataDetailViewBuilder.cc
Go to the documentation of this file.
1 // FIXME - needed to set fixed eta-phi limits. Without the
2 // visible area may change widely depending on energy
3 // deposition availability
4 
5 #include "TEveCaloData.h"
6 #include "TEveViewer.h"
7 #include "TEveCalo.h"
8 #include "TAxis.h"
9 #include "TMath.h"
10 #include "THLimitsFinder.h"
11 #include "TLatex.h"
12 
18 
22 
23 #include "TGeoMatrix.h"
24 #include "TEveTrans.h"
25 
26 #include <utility>
27 
29 {
30  // get the hits from the event
31 
33  const EcalRecHitCollection *hits = 0;
34 
35  if (fabs(m_eta) < 1.5)
36  {
37  try
38  {
39  edm::InputTag tag("ecalRecHit", "EcalRecHitsEB");
40  m_event->getByLabel(tag, handle_hits);
41  if (handle_hits.isValid())
42  {
43  hits = &*handle_hits;
44  }
45  }
46  catch (...)
47  {
48  fwLog(fwlog::kWarning) <<"FWECALCaloDataDetailViewBuilder::build():: Failed to access EcalRecHitsEB collection." << std::endl;
49  }
50  if ( ! handle_hits.isValid()) {
51  try{
52  edm::InputTag tag("reducedEcalRecHitsEB");
53  m_event->getByLabel(tag, handle_hits);
54  if (handle_hits.isValid())
55  {
56  hits = &*handle_hits;
57  }
58 
59  }
60  catch (...)
61  {
62  fwLog(fwlog::kWarning) <<"FWECALCaloDataDetailViewBuilder::build():: Failed to access reducedEcalRecHitsEB collection." << std::endl;
63  }
64  }
65  }
66  else
67  {
68  try
69  {
70  edm::InputTag tag("ecalRecHit", "EcalRecHitsEE");
71  m_event->getByLabel(tag, handle_hits);
72  if (handle_hits.isValid())
73  hits = &*handle_hits;
74  }
75  catch (...)
76  {
77  fwLog(fwlog::kWarning) <<"FWECALCaloDataDetailViewBuilder::build():: Failed to access ecalRecHitsEE collection." << std::endl;
78  }
79 
80  if ( ! handle_hits.isValid()) {
81  try {
82  edm::InputTag tag("reducedEcalRecHitsEE");
83  m_event->getByLabel(tag, handle_hits);
84  if (handle_hits.isValid())
85  {
86  hits = &*handle_hits;
87  }
88 
89  }
90  catch (...)
91  {
92  fwLog(fwlog::kWarning) <<"FWECALCaloDataDetailViewBuilder::build():: Failed to access reducedEcalRecHitsEE collection." << std::endl;
93  }
94  }
95  }
96 
97  // data
98  TEveCaloDataVec* data = new TEveCaloDataVec( 1 + m_colors.size() );
99  data->RefSliceInfo(0).Setup("hits (not clustered)", 0.0, m_defaultColor );
100  for( size_t i = 0; i < m_colors.size(); ++i )
101  {
102  data->RefSliceInfo(i + 1).Setup( "hits (clustered)", 0.0, m_colors[i] );
103  }
104 
105  if( handle_hits.isValid() )
106  {
107  fillData( hits, data, xyEE );
108  }
109 
110  // axis
111  Double_t etaMin(0), etaMax(0), phiMin(0), phiMax(0);
112  if (data->Empty())
113  {
114  fwLog(fwlog::kWarning) <<"FWECALCaloDataDetailViewBuilder::build():: No hits found in " << Form("FWECALCaloDataDetailViewBuilder::build():: No hits found in eta[%f] phi[%f] region", m_eta, m_phi)<<".\n";
115 
116  // add dummy background
117  float x = m_size*TMath::DegToRad();
118  if (fabs(m_eta) < 1.5 || xyEE == false) {
119  etaMin = m_eta -x;
120  etaMax = m_eta +x;
121  phiMin = m_phi -x;
122  phiMax = m_phi +x;
123  data->AddTower(etaMin, etaMax, phiMin, phiMax);
124  }
125  else
126  {
127  float theta = TEveCaloData::EtaToTheta(m_eta);
128  float r = TMath::Tan(theta) * 290;
129  phiMin = r * TMath::Cos(m_phi - x) -300;
130  phiMax = r * TMath::Cos(m_phi + x) + 300;
131  etaMin = r * TMath::Sin(m_phi - x) - 300;
132  etaMax = r * TMath::Sin(m_phi + x) + 300;
133  data->AddTower(TMath::Min(etaMin, etaMax), TMath::Max(etaMin, etaMax),
134  TMath::Min(phiMin, phiMax), TMath::Max(phiMin, phiMax));
135 
136  }
137  data->FillSlice(0, 0.1);
138  }
139 
140 
141  TAxis* eta_axis = 0;
142  TAxis* phi_axis = 0;
143  data->GetEtaLimits(etaMin, etaMax);
144  data->GetPhiLimits(phiMin, phiMax);
145  // printf("data rng %f %f %f %f\n",etaMin, etaMax, phiMin, phiMax );
146 
147  if (fabs(m_eta) > 1.5 && xyEE ) {
148  eta_axis = new TAxis(10, etaMin, etaMax);
149  phi_axis = new TAxis(10, phiMin, phiMax);
150  eta_axis->SetTitle("X[cm]");
151  phi_axis->SetTitle("Y[cm]");
152  phi_axis->SetTitleSize(0.05);
153  eta_axis->SetTitleSize(0.05);
154  } else {
155  std::vector<double> etaBinsWithinLimits;
156  etaBinsWithinLimits.push_back(etaMin);
157  for (unsigned int i=0; i<83; ++i)
159  etaBinsWithinLimits.push_back(fw3dlego::xbins[i]);
160  etaBinsWithinLimits.push_back(etaMax);
161 
162  std::vector<double> phiBinsWithinLimits;
163  phiBinsWithinLimits.push_back(phiMin);
164  for ( double phi = -M_PI; phi < M_PI; phi += M_PI/36 )
165  if ( phi > phiMin && phi < phiMax )
166  phiBinsWithinLimits.push_back(phi);
167  phiBinsWithinLimits.push_back(phiMax);
168 
169  eta_axis = new TAxis((int)etaBinsWithinLimits.size() -1, &etaBinsWithinLimits[0]);
170  phi_axis = new TAxis((int)phiBinsWithinLimits.size() -1, &phiBinsWithinLimits[0]);
171 
172  eta_axis->SetTitleFont(122);
173  eta_axis->SetTitle("h");
174  eta_axis->SetTitleSize(0.07);
175  phi_axis->SetTitleFont(122);
176  phi_axis->SetTitle("f");
177  phi_axis->SetTitleSize(0.07);
178  }
179  eta_axis->SetNdivisions(510);
180  phi_axis->SetNdivisions(510);
181  data->SetEtaBins(eta_axis);
182  data->SetPhiBins(phi_axis);
183  return data;
184 }
185 
186 //_______________________________________________________________
188 {
189  TEveCaloData* data = buildCaloData(true);
190 
191  double etaMin, etaMax, phiMin, phiMax;
192  data->GetEtaLimits(etaMin, etaMax);
193  data->GetPhiLimits(phiMin, phiMax);
194 
195  // lego
196  TEveCaloLego *lego = new TEveCaloLego(data);
197  lego->SetDrawNumberCellPixels(100);
198  // scale and translate to real world coordinates
199  lego->SetEta(etaMin, etaMax);
200  lego->SetPhiWithRng((phiMin+phiMax)*0.5, (phiMax-phiMin)*0.5); // phi range = 2* phiOffset
201  Double_t legoScale = ((etaMax - etaMin) < (phiMax - phiMin)) ? (etaMax - etaMin) : (phiMax - phiMin);
202  lego->InitMainTrans();
203  lego->RefMainTrans().SetScale(legoScale, legoScale, legoScale*0.5);
204  lego->RefMainTrans().SetPos((etaMax+etaMin)*0.5, (phiMax+phiMin)*0.5, 0);
205  lego->SetAutoRebin(kFALSE);
206  lego->Set2DMode(TEveCaloLego::kValSizeOutline);
207  lego->SetName("ECALDetail Lego");
208  return lego;
209 
210 }
211 
212 void FWECALCaloDataDetailViewBuilder::setColor(Color_t color, const std::vector<DetId> &detIds)
213 {
214 
215  m_colors.push_back(color);
216 
217  // get the slice for this group of detIds
218  // note that the zeroth slice is the default one (all else)
219  int slice = m_colors.size();
220  // take a note of which slice these detids are going to go into
221  for (size_t i = 0; i < detIds.size(); ++i)
222  m_detIdsToColor[detIds[i]] = slice;
223 }
224 
225 void
227 {
228  std::vector<DetId> clusterDetIds;
229  const std::vector<std::pair<DetId, float> > &hitsAndFractions = cluster.hitsAndFractions();
230  for (size_t j = 0; j < hitsAndFractions.size(); ++j)
231  {
232  clusterDetIds.push_back(hitsAndFractions[j].first);
233  }
234 
235  setColor( color, clusterDetIds );
236 }
237 
238 void
239 FWECALCaloDataDetailViewBuilder::showSuperClusters( Color_t color1, Color_t color2 )
240 {
241  // get the superclusters from the event
243 
244  if( fabs( m_eta ) < 1.5 ) {
245  try {
246  m_event->getByLabel(edm::InputTag("correctedHybridSuperClusters"), collection);
247  }
248  catch (...)
249  {
250  fwLog(fwlog::kWarning) <<"no barrel superclusters are available" << std::endl;
251  }
252  } else {
253  try {
254  m_event->getByLabel(edm::InputTag("correctedMulti5x5SuperClustersWithPreshower"), collection);
255  }
256  catch (...)
257  {
258  fwLog(fwlog::kWarning) <<"no endcap superclusters are available" << std::endl;
259  }
260  }
261  if( collection.isValid() )
262  {
263  unsigned int colorIndex = 0;
264  // sort clusters in eta so neighboring clusters have distinct colors
265  reco::SuperClusterCollection sorted = *collection.product();
266  std::sort( sorted.begin(), sorted.end(), superClusterEtaLess );
267  for( size_t i = 0; i < sorted.size(); ++i )
268  {
269  if( !(fabs(sorted[i].eta() - m_eta) < (m_size*0.0172)
270  && fabs(sorted[i].phi() - m_phi) < (m_size*0.0172)) )
271  continue;
272 
273  if( colorIndex %2 == 0 )
274  showSuperCluster( sorted[i], color1 );
275  else
276  showSuperCluster( sorted[i], color2 );
277  ++colorIndex;
278  }
279  }
280 }
281 
282 void
284  TEveCaloDataVec *data, bool xyEE )
285 {
286  const float barrelCR = m_size*0.0172; // barrel cell range
287 
288  // loop on all the detids
289  for( EcalRecHitCollection::const_iterator k = hits->begin(), kEnd = hits->end();
290  k != kEnd; ++k )
291  {
292  // get reco geometry
293  double centerEta = 0;
294  double centerPhi = 0;
295  const float* points = m_geom->getCorners( k->id().rawId());
296  if( points != 0 )
297  {
298  TEveVector v;
299  int j = 0;
300  for( int i = 0; i < 8; ++i )
301  {
302  v += TEveVector( points[j], points[j + 1], points[j + 2] );
303  j +=3;
304  }
305  centerEta = v.Eta();
306  centerPhi = v.Phi();
307  }
308  else
309  fwLog( fwlog::kInfo ) << "cannot get geometry for DetId: "<< k->id().rawId() << ". Ignored.\n";
310 
311  double size = k->energy() / cosh( centerEta );
312 
313  // check what slice to put in
314  int slice = 0;
315  std::map<DetId, int>::const_iterator itr = m_detIdsToColor.find(k->id());
316  if (itr != m_detIdsToColor.end()) slice = itr->second;
317 
318  // if in the EB
319  if( k->id().subdetId() == EcalBarrel || xyEE == false )
320  {
321  // do phi wrapping
322  if( centerPhi > m_phi + M_PI) centerPhi -= 2 * M_PI;
323  if( centerPhi < m_phi - M_PI) centerPhi += 2 * M_PI;
324 
325  // check if the hit is in the window to be drawn
326  if( !( fabs( centerEta - m_eta ) < barrelCR
327  && fabs( centerPhi - m_phi ) < barrelCR )) continue;
328 
329  double minEta(10), maxEta(-10), minPhi(4), maxPhi(-4);
330  if( points != 0 )
331  {
332  // calorimeter crystalls have slightly non-symetrical form in eta-phi projection
333  // so if we simply get the largest eta and phi, cells will overlap
334  // therefore we get a smaller eta-phi range representing the inner square
335  // we also should use only points from the inner face of the crystal, since
336  // non-projecting direction of crystals leads to large shift in eta on outter
337  // face.
338  int j = 0;
339  float eps = 0.005;
340  for( unsigned int i = 0; i < 8; ++i )
341  {
342  TEveVector crystal( points[j], points[j + 1], points[j + 2] );
343  j += 3;
344  double eta = crystal.Eta();
345  double phi = crystal.Phi();
346  if ( ((k->id().subdetId() == EcalBarrel) && (crystal.Perp() > 135) )|| ((k->id().subdetId() == EcalEndcap) && (crystal.Perp() > 155))) continue;
347  if ( minEta - eta > eps) minEta = eta;
348  if ( eta - minEta > 0 && eta - minEta < eps ) minEta = eta;
349  if ( eta - maxEta > eps) maxEta = eta;
350  if ( maxEta - eta > 0 && maxEta - eta < eps ) maxEta = eta;
351  if ( minPhi - phi > eps) minPhi = phi;
352  if ( phi - minPhi > 0 && phi - minPhi < eps ) minPhi = phi;
353  if ( phi - maxPhi > eps) maxPhi = phi;
354  if ( maxPhi - phi > 0 && maxPhi - phi < eps ) maxPhi = phi;
355  }
356  }
357  else
358  {
359  double delta = 0.0172 * 0.5;
360  minEta = centerEta - delta;
361  maxEta = centerEta + delta;
362  minPhi = centerPhi - delta;
363  maxPhi = centerPhi + delta;
364  }
365  if( minPhi >= ( m_phi - barrelCR ) && maxPhi <= ( m_phi + barrelCR ) &&
366  minEta >= ( m_eta - barrelCR ) && maxEta <= ( m_eta + barrelCR ))
367  {
368  // printf("add %f %f %f %f \n",minEta, maxEta, minPhi, maxPhi );
369  data->AddTower( minEta, maxEta, minPhi, maxPhi );
370  data->FillSlice( slice, size );
371  }
372  // otherwise in the EE
373  }
374  else if( k->id().subdetId() == EcalEndcap )
375  {
376  // check if the hit is in the window to be drawn
377  double crystalSize = m_size * 0.0172;
378  if( !( fabs( centerEta - m_eta ) < ( crystalSize )
379  && fabs( centerPhi - m_phi ) < ( crystalSize )))
380  continue;
381 
382  if( points != 0 )
383  {
384  double minX(9999), maxX(-9999), minY(9999), maxY(-9999);
385  int j = 0;
386  for( unsigned int i = 0; i < 8; ++i )
387  {
388  TEveVector crystal( points[j], points[j + 1], points[j + 2] );
389  j += 3;
390  double x = crystal.fX;
391  double y = crystal.fY;
392  if( fabs( crystal.fZ ) > 330 ) continue;
393  if( minX - x > 0.01 ) minX = x;
394  if( x - maxX > 0.01 ) maxX = x;
395  if( minY - y > 0.01 ) minY = y;
396  if( y - maxY > 0.01 ) maxY = y;
397  }
398  data->AddTower( minX, maxX, minY, maxY );
399  // printf("EE add %f %f %f %f \n",minX, maxX, minY, maxY );
400  }
401  data->FillSlice( slice, size );
402  }
403  } // end loop on hits
404 
405  data->DataChanged();
406 }
407 
408 double
410  Color_t clustered1, Color_t clustered2,
411  Color_t supercluster
412  )
413 {
414  Double_t fontsize = 0.07;
415  TLatex* latex = new TLatex();
416  Double_t x = x0;
417  Double_t y = y0;
418  Double_t boxH = 0.25*fontsize;
419  Double_t yStep = 0.04;
420 
421  y -= yStep;
422  latex->DrawLatex(x, y, "Energy types:");
423  y -= yStep;
424 
425  Double_t pos[4];
426  pos[0] = x+0.05;
427  pos[2] = x+0.20;
428 
429  pos[1] = y; pos[3] = pos[1] + boxH;
431  latex->DrawLatex(x+0.25, y, "unclustered");
432  y -= yStep;
433  if (clustered1<0) return y;
434 
435  pos[1] = y; pos[3] = pos[1] + boxH;
436  FWDetailViewBase::drawCanvasBox(pos, clustered1);
437  latex->DrawLatex(x+0.25, y, "clustered");
438  y -= yStep;
439  if (clustered2<0) return y;
440 
441  pos[1] = y; pos[3] = pos[1] + boxH;
442  FWDetailViewBase::drawCanvasBox(pos, clustered2);
443  latex->DrawLatex(x+0.25, y, "clustered");
444  y -= yStep;
445  if (supercluster<0) return y;
446 
447  pos[1] = y; pos[3] = pos[1] + boxH;
448  FWDetailViewBase::drawCanvasBox(pos, supercluster);
449  latex->DrawLatex(x+0.25, y, "super-cluster");
450  y -= yStep;
451 
452  return y;
453 }
size
Write out results.
dbl * delta
Definition: mlp_gen.cc:36
int i
Definition: DBlmapReader.cc:9
const double xbins[]
void showSuperCluster(const reco::SuperCluster &cluster, Color_t color=kYellow)
std::vector< EcalRecHit >::const_iterator const_iterator
Geom::Theta< T > theta() const
const std::vector< std::pair< DetId, float > > & hitsAndFractions() const
Definition: CaloCluster.h:192
double maxEta
T Min(T a, T b)
Definition: MathUtil.h:39
std::vector< SuperCluster > SuperClusterCollection
collection of SuperCluser objectr
static bool superClusterEtaLess(const reco::CaloCluster &lhs, const reco::CaloCluster &rhs)
int j
Definition: DBlmapReader.cc:9
double makeLegend(double x0=0.02, double y0=0.95, Color_t clustered1=kGreen+1, Color_t clustered2=kTeal, Color_t supercluster=kYellow)
bool isValid() const
Definition: HandleBase.h:75
void setColor(Color_t color, const std::vector< DetId > &detIds)
#define M_PI
int k[5][pyjets_maxn]
const_iterator end() const
T Max(T a, T b)
Definition: MathUtil.h:44
void fillData(const EcalRecHitCollection *hits, TEveCaloDataVec *data, bool xyEE)
const float * getCorners(unsigned int id) const
Definition: FWGeometry.cc:286
T const * product() const
Definition: Handle.h:81
#define fwLog(_level_)
Definition: fwLog.h:50
bool getByLabel(InputTag const &, Handle< T > &) const
Definition: EventBase.h:89
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
void showSuperClusters(Color_t color1=kGreen+2, Color_t color2=kTeal)
minPhi
set NPt=0 and the vector of double for variable size binning
const_iterator begin() const
static void drawCanvasBox(Double_t *pos, Color_t fillCol, Int_t fillType=0, bool bg=kTRUE)