FEDRA emulsion software from the OPERA Collaboration
EdbDistortionMap Class Reference

#include <EdbDistortion.h>

Inheritance diagram for EdbDistortionMap:
Collaboration diagram for EdbDistortionMap:

Public Member Functions

void Add (const EdbDistortionMap &map, float k=1.)
 
void AddDX (int j, double dx)
 
void AddDY (int j, double dy)
 
void ApplyCorr (EdbClDist &c)
 
int Bin (int j) const
 
void DrawCorrMap (TFile *file=0, const char *name=0)
 
double DX (int j) const
 
double DY (int j) const
 
 EdbDistortionMap ()
 
void Fill (float x, float y, float dx, float dy)
 
void GenerateCorrectionMatrix (const char *file)
 
TH2F * GetH2dX (const char *name="hdx")
 
TH2F * GetH2dY (const char *name="hdy")
 
void InitMap (int nxpix, int nypix, float xpix, float ypix, float stepX, float stepY)
 
int Jcell (float x, float y) const
 
void Norm ()
 
void PutH2dX (const TH2F &h2)
 
void PutH2dY (const TH2F &h2)
 
void ReadMatrix2Map (const char *file)
 
void Save (TFile *f, const char *suffix="")
 
void Scale (const float k)
 
void SetDX (int j, double dx)
 
void SetDY (int j, double dy)
 
void Smooth (int n=1, Option_t *opt="k5a")
 
float StepX ()
 
float StepY ()
 
void Substract (const EdbDistortionMap &map)
 
virtual ~EdbDistortionMap ()
 

Private Attributes

EdbCell2 eMap
 
int eNXpix
 
int eNYpix
 
float eXpix
 
float eYpix
 

Constructor & Destructor Documentation

◆ EdbDistortionMap()

EdbDistortionMap::EdbDistortionMap ( )
inline
41 {}

◆ ~EdbDistortionMap()

virtual EdbDistortionMap::~EdbDistortionMap ( )
inlinevirtual
42 {}

Member Function Documentation

◆ Add()

void EdbDistortionMap::Add ( const EdbDistortionMap map,
float  k = 1. 
)
615 {
616  int nc=eMap.Ncell();
617  for( int j=0; j<nc; j++ ) {
618  int jm = map.Jcell( eMap.Xj(j), eMap.Yj(j) );
619  TArrayD *dxy = (TArrayD *)eMap.GetObject(j,0);
620  (*dxy)[0] += k*map.DX(jm);
621  (*dxy)[1] += k*map.DY(jm);
622  eMap.Fill(j);
623  }
624 }
TObject * GetObject(float x, float y, int ientr) const
Definition: EdbCell2.h:199
int Jcell(float x, float y) const
Definition: EdbDistortion.h:54
EdbCell2 eMap
Definition: EdbDistortion.h:38
double DY(int j) const
Definition: EdbDistortion.cxx:540
double DX(int j) const
Definition: EdbDistortion.cxx:534
int Ncell() const
Definition: EdbCell2.h:49
float Xj(int j) const
Definition: EdbCell2.h:62
float Yj(int j) const
Definition: EdbCell2.h:63
int Fill(float x, float y)
Definition: EdbCell2.h:88

◆ AddDX()

void EdbDistortionMap::AddDX ( int  j,
double  dx 
)
523 {
524  TArrayD *dxy = (TArrayD*)( eMap.GetObject(j, 0 ) );
525  if(dxy) (*dxy)[0] += dx;
526 }

◆ AddDY()

void EdbDistortionMap::AddDY ( int  j,
double  dy 
)
529 {
530  TArrayD *dxy = (TArrayD*)( eMap.GetObject(j, 0 ) );
531  if(dxy) (*dxy)[1] += dy;
532 }

◆ ApplyCorr()

void EdbDistortionMap::ApplyCorr ( EdbClDist c)
356 {
357  int j=Jcell(c.eX,c.eY);
358  if(j>-1) {
359  TArrayD *dxy = (TArrayD*)( eMap.GetObject(j, 0 ) );
360  if(dxy) {
361  c.eX -= (*dxy)[0];
362  c.eY -= (*dxy)[1];
363  }
364  }
365 }
Float_t eY
Definition: EdbDistortion.h:18
Float_t eX
Definition: EdbDistortion.h:18

◆ Bin()

int EdbDistortionMap::Bin ( int  j) const
inline
53 {return eMap.Bin(j);}
int Bin(float x, float y) const
Definition: EdbCell2.h:80

◆ DrawCorrMap()

void EdbDistortionMap::DrawCorrMap ( TFile *  file = 0,
const char *  name = 0 
)
380 {
381  bool batch = gROOT->IsBatch();
382  if(file) {
383  Log(2,"EdbDistortionMap::DrawCorrMap","Save to file %s", file->GetName());
384  gROOT->SetBatch();
385  }
386 
387  TCanvas *cc = new TCanvas(Form("c_%s",name),"Corrections map",1200,900);
388 
389  gStyle->SetPalette(1);
390  gStyle->SetOptStat(0);
391  gPad->SetGridx(1);
392  gPad->SetGridy(1);
393 
394  float margin=10;
395  double minXborder = eMap.Xmin() - margin;
396  double maxXborder = eMap.Xmax() + margin;
397  double minYborder = eMap.Ymin() - margin;
398  double maxYborder = eMap.Ymax() + margin;
399 
400  TH2F *hh = new TH2F(Form("hh_%s",name),"Corrections map",100,minXborder,maxXborder,100,minYborder,maxYborder);
401  hh->GetXaxis()->SetTitle("X (#mum)");
402  hh->GetYaxis()->SetTitle("Y (#mum)");
403  hh->Draw();
404 
405  TBox *plate = new TBox(eMap.Xmin(),eMap.Ymin(),eMap.Xmax(),eMap.Ymax());
406  plate->SetFillColor(16);
407  plate->SetFillStyle(3001);
408  plate->Draw();
409 
410  Double_t meanx=0, meany=0, meanr=0, wtot=0;
411  float scale = 15.;
412  int nc=eMap.Ncell();
413  for( int i=0; i<nc; i++ ) {
414  int w = eMap.Bin(i); if(!w) continue;
415  TArrayD *dxy = (TArrayD*)( eMap.GetObject(i, 0 ) );
416  float x = eMap.Xj(i);
417  float y = eMap.Yj(i);
418  float dx = (*dxy)[0];
419  float dy = (*dxy)[1];
420 
421  TArrow *arrow = new TArrow(x,y,x+scale*dx,y+scale*dy,0.01);
422  arrow->SetLineWidth(1);
423  arrow->Draw();
424 
425  meanx += dx;
426  meany += dy;
427  meanr += sqrt(dx*dx+dy*dy);
428  wtot += w;
429  }
430 
431  meanx /= wtot;
432  meany /= wtot;
433  meanr /= wtot;
434  printf("\nmeanR = %g meanx = %g meany = %g wtot = %f\n", meanr, meanx, meany, wtot);
435 
436  if(file) {
437  const char *mapname = "corr_map";
438  if(name) mapname = name;
439  eMap.DrawH2(Form("eMap_%s",name),"entries/bin")->Write();
440  cc->Write(name);
441  }
442  gROOT->SetBatch(batch);
443 }
bool Log(int level, const char *location, const char *fmt,...)
Definition: EdbLog.cxx:75
float Xmax() const
Definition: EdbCell2.h:65
float Ymin() const
Definition: EdbCell2.h:66
TH2F * DrawH2(const char *name="plot2d", const char *title="EdbH2plot2D")
Definition: EdbCell2.cpp:197
float Xmin() const
Definition: EdbCell2.h:64
float Ymax() const
Definition: EdbCell2.h:67
Int_t plate
Definition: merge_Energy_SytematicSources_Electron.C:1
const char * name
Definition: merge_Energy_SytematicSources_Electron.C:24
new TCanvas()
void w(int rid=2, int nviews=2)
Definition: test.C:27
TFile * file
Definition: write_pvr.C:3

◆ DX()

double EdbDistortionMap::DX ( int  j) const
535 {
536  TArrayD *dxy = (TArrayD*)( eMap.GetObject(j, 0 ) );
537  if(dxy) return (*dxy)[0]; else return 0;
538 }

◆ DY()

double EdbDistortionMap::DY ( int  j) const
541 {
542  TArrayD *dxy = (TArrayD*)( eMap.GetObject(j, 0 ) );
543  if(dxy) return (*dxy)[1]; else return 0;
544 }

◆ Fill()

void EdbDistortionMap::Fill ( float  x,
float  y,
float  dx,
float  dy 
)
490 {
491  TArrayD *dxy = (TArrayD *)eMap.GetObject(x,y,0);
492  if(dxy) {
493  (*dxy)[0]+=dx;
494  (*dxy)[1]+=dy;
495  eMap.Fill(x, y);
496  }
497 }

◆ GenerateCorrectionMatrix()

void EdbDistortionMap::GenerateCorrectionMatrix ( const char *  file)
666 {
667  int nentries = eMap.Ncell();
668  Double_t *vx = new Double_t[nentries];
669  Double_t *vy = new Double_t[nentries];
670  Double_t *vdx = new Double_t[nentries];
671  Double_t *vdy = new Double_t[nentries];
672 
673  for(int i=0; i<nentries; i++) {
674  int w = eMap.Bin(i); if(!w) continue;
675  TArrayD *arr = (TArrayD*)eMap.GetObject(i,0);
676  if(!arr) { Log(1,"EdbDistortionMap::GenerateCorrectionMatrix","ERROR: missed bin"); break; }
677  vx[i] = eMap.Xj(i);
678  vy[i] = eMap.Yj(i);
679  vdx[i] = arr->At(0);
680  vdy[i] = arr->At(1);
681  }
682 
683  TGraph2D *gdx = new TGraph2D("graphDX","graphDX",nentries,vx,vy,vdx);
684  TGraph2D *gdy = new TGraph2D("graphDY","graphDY",nentries,vx,vy,vdy);
685 
686  FILE *fmatr = fopen(file,"w");
687  fprintf(fmatr,"%d %d %f %f\n", eNXpix, eNYpix, eXpix, eYpix);
688 
689  for(int i=0; i<eNXpix; i++) {
690  for(int j=0; j<eNYpix; j++) {
691  float x = (i - 0.5*(eNXpix-1))*eXpix;
692  float y = (j - 0.5*(eNYpix-1))*eYpix;
693  //float dx = gdx->Interpolate(x,y);
694  //float dy = gdy->Interpolate(x,y);
695  float dx = ((TArrayD *)eMap.GetObject(x,y,0))->At(0);
696  float dy = ((TArrayD *)eMap.GetObject(x,y,0))->At(1);
697  fprintf(fmatr,"%5d %5d %12.6f %12.6f %11.6f %11.6f\n", i, j, x,y,dx,dy);
698  }
699  }
700  fclose(fmatr);
701 }
int nentries
Definition: check_shower.C:40
int eNXpix
Definition: EdbDistortion.h:37
float eXpix
Definition: EdbDistortion.h:36
int eNYpix
Definition: EdbDistortion.h:37
float eYpix
Definition: EdbDistortion.h:36
fclose(pFile)

◆ GetH2dX()

TH2F * EdbDistortionMap::GetH2dX ( const char *  name = "hdx")
593 {
594  TH2F *hd = eMap.DrawH2(name,"CorrectionMatrix dX");
595  hd->Reset();
596  int nc=eMap.Ncell();
597  for( int j=0; j<nc; j++ )
598  hd->Fill( eMap.Xj(j), eMap.Yj(j), DX(j) );
599  return hd;
600 }

◆ GetH2dY()

TH2F * EdbDistortionMap::GetH2dY ( const char *  name = "hdy")
604 {
605  TH2F *hd = eMap.DrawH2(name,"CorrectionMatrix dY");
606  hd->Reset();
607  int nc=eMap.Ncell();
608  for( int j=0; j<nc; j++ )
609  hd->Fill( eMap.Xj(j), eMap.Yj(j), DY(j) );
610  return hd;
611 }

◆ InitMap()

void EdbDistortionMap::InitMap ( int  nxpix,
int  nypix,
float  xpix,
float  ypix,
float  stepX,
float  stepY 
)
637 {
638  // matrix of the corrections in each entry is TArrayD with 2 entries:(dx,dy)
639  eNXpix = nxpix;
640  eNYpix = nypix;
641  eXpix = xpix;
642  eYpix = ypix;
643 
644  float mi[2] = { -eNXpix*Abs(eXpix)/2., -eNYpix*Abs(eYpix)/2. };
645  float ma[2] = { eNXpix*Abs(eXpix)/2., eNYpix*Abs(eYpix)/2. };
646  int n[2] = { int((ma[0]-mi[0])/stepX), int((ma[1]-mi[1])/stepY) };
647 
648  stepX = (ma[0]-mi[0])/n[0];
649  stepY = (ma[1]-mi[1])/n[1];
650  n[0] = int((ma[0]-mi[0]+1.)/stepX);
651  n[1] = int((ma[1]-mi[1]+1.)/stepY);
652 
653  eMap.InitCell(2, n, mi, ma);
654  //eMap.PrintStat();
655 
656  int nc=eMap.Ncell();
657  for( int i=0; i<nc; i++ ) {
658  TArrayD *a = new TArrayD(2);
659  eMap.AddObject(i, (TObject*)a );
660  eMap.SetBin(i,0);
661  }
662 }
void a()
Definition: check_aligned.C:59
int InitCell(EdbCell2 &c)
Definition: EdbCell2.h:170
bool AddObject(float v[2], TObject *obj)
Definition: EdbCell2.h:176
void SetBin(int ix, int iy, int n)
Definition: EdbCell2.h:91

◆ Jcell()

int EdbDistortionMap::Jcell ( float  x,
float  y 
) const
inline
54 {return eMap.Jcell(x,y);}
int Jcell(int ix, int iy) const
Definition: EdbCell2.h:57

◆ Norm()

void EdbDistortionMap::Norm ( )
500 {
501  int nc=eMap.Ncell();
502  for( int i=0; i<nc; i++ ) {
503  TArrayD *dxy = (TArrayD*)( eMap.GetObject(i, 0 ) ); if(!dxy) continue;
504  int w = eMap.Bin(i); if(!w) continue;
505  (*dxy)[0] /= w;
506  (*dxy)[1] /= w;
507  }
508 }

◆ PutH2dX()

void EdbDistortionMap::PutH2dX ( const TH2F &  h2)
561 {
562  // TODO: no any checks yet
563  int nc = h2.GetNcells();
564  int ix,iy,iz;
565  for( int j=0; j<nc; j++ ) {
566  double dx = h2.GetBinContent(j);
567  h2.GetBinXYZ(j,ix,iy,iz);
568  float x = ((TAxis*)h2.GetXaxis())->GetBinCenter(ix);
569  float y = ((TAxis*)h2.GetYaxis())->GetBinCenter(iy);
570  int jm = eMap.Jcell(x,y);
571  SetDX( jm, dx );
572  }
573 }
void SetDX(int j, double dx)
Definition: EdbDistortion.cxx:510
TH1F * h2
Definition: energy.C:19

◆ PutH2dY()

void EdbDistortionMap::PutH2dY ( const TH2F &  h2)
577 {
578  // TODO: no any checks yet
579  int nc = h2.GetNcells();
580  int ix,iy,iz;
581  for( int j=0; j<nc; j++ ) {
582  double dy = h2.GetBinContent(j);
583  h2.GetBinXYZ(j,ix,iy,iz);
584  float x = ((TAxis*)h2.GetXaxis())->GetBinCenter(ix);
585  float y = ((TAxis*)h2.GetYaxis())->GetBinCenter(iy);
586  int jm = eMap.Jcell(x,y);
587  SetDY( jm, dy );
588  }
589 }
void SetDY(int j, double dy)
Definition: EdbDistortion.cxx:516

◆ ReadMatrix2Map()

void EdbDistortionMap::ReadMatrix2Map ( const char *  file)
448 {
449  Log(1,"EdbDistortionMap::ReadMatrix2Map","%s ",file);
450  FILE *f = fopen(file,"r");
451  if(!f) { Log(1,"ReadMatrix2Map","file %s not found!",file); return; }
452  char str[256];
453  fgets(str, 256, f);
454  int nxpix, nypix;
455  float xpix, ypix;
456  sscanf(str,"%d %d %f %f", &nxpix, &nypix, &xpix, &ypix);
457  if( nxpix!=eNXpix||nypix!=eNYpix||abs(xpix-eXpix)>0.000001||abs(ypix-eYpix)>0.000001 )
458  { Log(1,"ReadMatrix2Map","ERROR: matrix definition is different!",file);
459  printf("%d %d %f %f\n", nxpix, nypix, xpix, ypix);
460  return;
461  }
462 
463  int i0,j0;
464  float x0,y0,dx0,dy0;
465  for(int i=0; i<eNXpix; i++) {
466  for(int j=0; j<eNYpix; j++) {
467  if(fgets(str, 256, f)==NULL) Log(1,"GenerateCorrectionMatrix","ERROR: input file is not correct");
468  if( sscanf(str, "%d %d %f %f %f %f", &i0, &j0, &x0, &y0, &dx0, &dy0) == 6 )
469  {
470  TArrayD *dxy = (TArrayD *)eMap.GetObject(x0,y0,0);
471  (*dxy)[0]+=dx0;
472  (*dxy)[1]+=dy0;
473  eMap.Fill(x0, y0);
474  }
475  }
476  }
477  fclose(f);
478 
479  int nc=eMap.Ncell();
480  for( int i=0; i<nc; i++ ) {
481  TArrayD *dxy = (TArrayD*)( eMap.GetObject(i, 0 ) ); if(!dxy) continue;
482  int w = eMap.Bin(i); if(!w) continue;
483  (*dxy)[0] /= w;
484  (*dxy)[1] /= w;
485  }
486 }
FILE * f
Definition: RecDispMC.C:150
#define NULL
Definition: nidaqmx.h:84

◆ Save()

void EdbDistortionMap::Save ( TFile *  f,
const char *  suffix = "" 
)
368 {
369  if(file) {
370  bool batch = gROOT->IsBatch();
371  gROOT->SetBatch();
372  DrawCorrMap( file, Form("corrmap_%s",suffix) );
373  GetH2dX()->Write( Form("hdx_%s",suffix) );
374  GetH2dY()->Write( Form("hdy_%s",suffix) );
375  gROOT->SetBatch(batch);
376  }
377 }
void DrawCorrMap(TFile *file=0, const char *name=0)
Definition: EdbDistortion.cxx:379
TH2F * GetH2dY(const char *name="hdy")
Definition: EdbDistortion.cxx:603
TH2F * GetH2dX(const char *name="hdx")
Definition: EdbDistortion.cxx:592

◆ Scale()

void EdbDistortionMap::Scale ( const float  k)
628 {
629  int nc=eMap.Ncell();
630  for( int j=0; j<nc; j++ ) {
631  SetDX( j, DX(j)*k );
632  SetDY( j, DY(j)*k );
633  }
634 }

◆ SetDX()

void EdbDistortionMap::SetDX ( int  j,
double  dx 
)
511 {
512  TArrayD *dxy = (TArrayD*)( eMap.GetObject(j, 0 ) );
513  if(dxy) (*dxy)[0] = dx;
514 }

◆ SetDY()

void EdbDistortionMap::SetDY ( int  j,
double  dy 
)
517 {
518  TArrayD *dxy = (TArrayD*)( eMap.GetObject(j, 0 ) );
519  if(dxy) (*dxy)[1] = dy;
520 }

◆ Smooth()

void EdbDistortionMap::Smooth ( int  n = 1,
Option_t *  opt = "k5a" 
)
548 {
549  TH2F *h2x = GetH2dX();
550  TH2F *h2y = GetH2dY();
551  for(int i=0; i<n; i++) {
552  h2x->Smooth(1,opt);
553  h2y->Smooth(1,opt);
554  }
555  PutH2dX(*h2x);
556  PutH2dY(*h2y);
557 }
void PutH2dY(const TH2F &h2)
Definition: EdbDistortion.cxx:576
void PutH2dX(const TH2F &h2)
Definition: EdbDistortion.cxx:560
const char * opt
Definition: mc2raw.cxx:42

◆ StepX()

float EdbDistortionMap::StepX ( )
inline
56 {return eMap.Xbin();}
float Xbin() const
Definition: EdbCell2.h:77

◆ StepY()

float EdbDistortionMap::StepY ( )
inline
57 {return eMap.Ybin();}
float Ybin() const
Definition: EdbCell2.h:78

◆ Substract()

void EdbDistortionMap::Substract ( const EdbDistortionMap map)
inline
60 { Add(map,-1.); }
void Add(const EdbDistortionMap &map, float k=1.)
Definition: EdbDistortion.cxx:614

Member Data Documentation

◆ eMap

EdbCell2 EdbDistortionMap::eMap
private

◆ eNXpix

int EdbDistortionMap::eNXpix
private

◆ eNYpix

int EdbDistortionMap::eNYpix
private

◆ eXpix

float EdbDistortionMap::eXpix
private

◆ eYpix

float EdbDistortionMap::eYpix
private

The documentation for this class was generated from the following files: