FEDRA emulsion software from the OPERA Collaboration
init.C File Reference
#include "hwinit.C"
Include dependency graph for init.C:
This graph shows which files directly or indirectly include this file:

Functions

int finefocus (int clu_thre=300, float fineness=4.)
 
int focus (int clu_thre=300)
 
 genmapext ()
 
void hist ()
 
 homeall ()
 
int imageat (float Z0)
 
int init ()
 
void lightcurve (int INCREMENT)
 
 monitor ()
 
int scanbot ()
 
int scanmarks ()
 
int scantop ()
 
int scanview ()
 
void showgain ()
 
 takebggc (float X0, float Y0, float Z0)
 
 takebggchere ()
 
int tunelight ()
 
 xy (float X, float Y)
 
 xyabs (float X, float Y)
 

Variables

EdbRunrun =0
 
float ThTol =0.5
 

Function Documentation

◆ finefocus()

int finefocus ( int  clu_thre = 300,
float  fineness = 4. 
)
110 {
111 // finds emulsion starting from current values of Z.
112 // fineness defines search depth: DZ=(1+2./fineness)*s->NominalEmLayer
113  int res;
114  int Taken;
115  int FLayers=o->MaxNbGrab;
116  TS->Layers=FLayers;
117  float z0=0,z1=0;
118 
119  o->Threshold=ThrTop;
120  Z0=s->Z->Reference +s->EmBotLayer +s->EmBase -s->EmTopLayer/fineness;
121  if(Z0<=0) Z0=10.;// safety margin
122  DZ=(1+2./fineness)*s->EmTopLayer;
123  res=TS->FindLayer(Z0,DZ,clu_thre,&z0,&z1);
124  if(res<3 ) {printf("res=%d :One or both surfaces not detected!\n",res); return 0;};
125  float z2=0,z3=0;
126  o->Threshold=ThrBot;
127  Z0=s->Z->Reference-s->EmBotLayer/fineness;
128  if(Z0<=0) Z0=10.;// safety margin
129  DZ=(1+2./fineness)*s->NominalEmLayer;
130  res=TS->FindLayer(Z0,DZ,clu_thre,&z2,&z3);
131  if(res<3 ) {printf("res=%d :One or both surfaces not detected!\n",res); return 0;};
132  if( (z0-z1)/s->NominalEmLayer <1-ThTol) { printf("Layer thickness out of tolerance!\n"); return 0;}
133  if( (z0-z1)/s->NominalEmLayer >1+ThTol) { printf("Layer thickness out of tolerance!\n"); return 0;}
134  if( (z2-z3)/s->NominalEmLayer <1-ThTol) { printf("Layer thickness out of tolerance!\n"); return 0;}
135  if( (z2-z3)/s->NominalEmLayer >1+ThTol) { printf("Layer thickness out of tolerance!\n"); return 0;}
136  if( (z1-z2)/s->NominalEmBase <1-ThTol) { printf("Base thickness out of tolerance!\n"); return 0;}
137  if( (z1-z2)/s->NominalEmBase >1+ThTol) { printf("Base thickness out of tolerance!\n"); return 0;}
138  s->Z->Reference=z3;
139  s->EmTopLayer=z0-z1;
140  s->EmBotLayer=z2-z3;
141  s->EmBase=z1-z2;
142  printf("Reference set to %f, Emulsion(Top:Base:Bot) %0.1f : %0.1f : %0.1f \n",s->Z->Reference,s->EmTopLayer,s->EmBase,s->EmBotLayer);
143  return 1;
144 }
brick z0
Definition: RecDispMC.C:106
int MaxNbGrab
Definition: AcqOdyssey.h:181
int Threshold
Definition: AcqOdyssey.h:174
int Layers
Definition: AcqTrackScanner.h:30
int FindLayer(float Z0, float DZ, int ClusterThreshold, float *z0, float *z1)
Definition: AcqTrackScanner.cxx:125
Float_t Z() const
Definition: EdbSegP.h:150
int ThrBot
Definition: hwinit.C:12
AcqOdyssey * o
Definition: hwinit.C:2
int ThrTop
Definition: hwinit.C:11
AcqTrackScanner * TS
Definition: hwinit.C:4
float Z0
Definition: hwinit.C:67
float DZ
Definition: hwinit.C:66
float ThTol
Definition: init.C:75
EdbSegP * s
Definition: tlg2pattern.C:32

◆ focus()

int focus ( int  clu_thre = 300)
77 {
78  // finds emulsion starting from nominal values
79  int res;
80  int Taken;
81  float z0=0,z1=0;
82 
84  Z0=s->Z->NominalReference +s->NominalEmBase ;
85  DZ=3*s->NominalEmLayer;
86  res=TS->FindLayer(Z0,DZ,clu_thre,&z0,&z1);
87  if(res<3 ) {printf("res=%d :One or both surfaces not detected!\n",res); return 0;};
88 
89  float z2=0,z3=0;
91  Z0=s->Z->NominalReference-s->NominalEmLayer;
92  DZ=3*s->NominalEmLayer;
93  res=TS->FindLayer(Z0,DZ,clu_thre,&z2,&z3);
94  if(res<3 ) {printf("res=%d :One or both surfaces not detected!\n",res); return 0;};
95  if( (z0-z1)/s->NominalEmLayer <1-ThTol) { printf("Layer thickness out of tolerance!\n"); return 0;}
96  if( (z0-z1)/s->NominalEmLayer >1+ThTol) { printf("Layer thickness out of tolerance!\n"); return 0;}
97  if( (z2-z3)/s->NominalEmLayer <1-ThTol) { printf("Layer thickness out of tolerance!\n"); return 0;}
98  if( (z2-z3)/s->NominalEmLayer >1+ThTol) { printf("Layer thickness out of tolerance!\n"); return 0;}
99  if( (z1-z2)/s->NominalEmBase <1-ThTol) { printf("Base thickness out of tolerance!\n"); return 0;}
100  if( (z1-z2)/s->NominalEmBase >1+ThTol) { printf("Base thickness out of tolerance!\n"); return 0;}
101  s->Z->Reference=z3;
102  s->EmTopLayer=z0-z1;
103  s->EmBotLayer=z2-z3;
104  s->EmBase=z1-z2;
105  printf("Reference set to %f, Emulsion(Top:Base:Bot) %0.1f : %0.1f : %0.1f \n",s->Z->Reference,s->EmTopLayer,s->EmBase,s->EmBotLayer);
106 
107  return 1;
108 }

◆ genmapext()

genmapext ( )
411 {
412 int Nm=FM->eMarksSet->GetN();
413 float Xm,Ym;
414  printf("mapext: 0 0 0 0; %d 0 0 125000 100000; ",Nm);
415  for(int i=0;i<Nm;i++)
416  {
417  Xm=FM->eFoundMarksSet->GetStage()->GetMark(i)->X();
418  Xm=Xm-s->X->NominalReference;
419  Ym=FM->eFoundMarksSet->GetStage()->GetMark(i)->Y();
420  Ym=Ym-s->Y->NominalReference;
421  printf("%d %f %f %f %f 1 1 0; ",i,Xm,Ym,Xm,Ym );
422  }
423 }
EdbMarksSet * eMarksSet
Definition: AcqMarksScanner.h:40
EdbMarksSet * eFoundMarksSet
Definition: AcqMarksScanner.h:41
Float_t Y() const
Definition: EdbFiducial.h:43
Float_t X() const
Definition: EdbFiducial.h:42
EdbMark * GetMark(int i) const
Definition: EdbFiducial.cxx:709
EdbMarksBox * GetStage() const
Definition: EdbFiducial.h:110
Int_t GetN() const
Definition: EdbFiducial.cxx:253
Float_t X() const
Definition: EdbSegP.h:170
Float_t Y() const
Definition: EdbSegP.h:171
AcqMarksScanner * FM
Definition: hwinit.C:3

◆ hist()

void hist ( )
24 {
25  o->ApplyGainCorr=1;
26  o->ApplyFIRF=0;
27  o->Threshold=0;
28  o->SubtractBG=false;
29  Z0=480;
30  DZ=s->EmTopLayer/4.;
31  TS->Layers=3;
32  TS->FPS=FPS;
33  TH1F* h=new TH1F("PPH","PPH",256,0,256);
34  TCanvas *c=new TCanvas();
35  c->SetLogy();
36  c->Draw();
37  while(1)
38  {
39  TS->ScanView(Z0,DZ);
40  h->Reset();
41  o->PlotImage1D(0,h);
42  o->ShowImage(0);
43  h->Draw();
44  c->Update();
45  }
46 
47 }
bool ApplyFIRF
Definition: AcqOdyssey.h:172
bool SubtractBG
Definition: AcqOdyssey.h:171
bool ApplyGainCorr
Definition: AcqOdyssey.h:173
void ShowImage(int N)
Definition: AcqOdyssey.cxx:263
void PlotImage1D(int N, TH1F *hist=NULL)
Definition: AcqOdyssey.cxx:284
int ScanView(float Z0, float DZ, float GotoX=0, float GotoY=0, bool RawImages=false)
Definition: AcqTrackScanner.cxx:39
int FPS
Definition: AcqTrackScanner.h:31
float FPS
Definition: hwinit.C:10
new TCanvas()

◆ homeall()

homeall ( )
325 {
326  int resx,resy;
327  printf("Homing XY.., \n");
328  s->X->FindHome(-1);
329  s->Y->FindHome(-1);
330  resy=s->Y->WaitForHome(1e4);
331  resx=s->X->WaitForHome(1e4);
332  printf("Reached %f,%f on XY, resx=%d resy=%d\n",s->X->GetPos(),s->Y->GetPos(),resx,resy);
333  if(resx!=1) return 0;
334  if(resy!=1) return 0;
335  printf("resetting X,Y..\n");
336  s->X->Reset();
337  s->Y->Reset();
338  printf("Moving to -79000,20000..\n");
339  s->X->PosMove(-79000,1e6,1e6);
340  s->Y->PosMove(20000,1e6,1e6);
341  resx=s->X->WaitForMoveComplete(1e4);
342  resy=s->Y->WaitForMoveComplete(1e4);
343  printf("Read %f,%f on XY\n",s->X->GetPos(),s->Y->GetPos());
344  printf("Homing Z.., \n");
345  s->Z->FindHome(1);
346  resy=s->Z->WaitForHome(1e4);
347  printf("Reached %f on Z, resy=%d\n",s->Z->GetPos(),resy);
348  if(resy!=1) return 0;
349  printf("resetting Z..\n");
350  s->Z->Reset();
351  printf("Read %f on Z, resy=%d\n",s->Z->GetPos(),resy);
352  s->Z->PosMove(5000,1e4,1e4);
353  s->Z->WaitForMoveComplete(1e4);
354 // s->Y->PosMove(70000,1e6,1e6);
355 // resy=s->Y->WaitForMoveComplete(3e3);
356  printf("homall() complete \n");
357 
358 }

◆ imageat()

int imageat ( float  Z0)
6 {
7  int res;
8  int Taken;
9  float DZ=s->NominalEmLayer; //microns in stage space
10  float Speed=1.*FPS*DZ/(Layers-1);
11  printf("Taking BG: Z Started to %f..\n",Z0-50);
12  s->Z->PosMove(Z0-50,1e4,1e4);
13  res=s->Z->WaitForMoveComplete(1e4);
14  s->Z->ArmBreakpoint(Z0);
15  printf("Taking BG: Grab armed,Z Started to %f..\n",Z0+10);
16  s->Z->PosMove(Z0+10,Speed,50000);
17  Taken=o->GrabImagesONL(1,&Z0,200./Speed); //grab one image with timeout
18  res=s->Z->WaitForMoveComplete(1e4);
19  o->CopyImageToBG(0);
20  return Taken;
21 }
void CopyImageToBG(int N)
Definition: AcqOdyssey.cxx:370
int GrabImagesONL(int N, float *Zs=NULL, double Timeout=0)
Definition: AcqOdyssey.cxx:472
int Layers
Definition: hwinit.C:65
float Speed
Definition: hwinit.C:69

◆ init()

int init ( )

Configure Odyssey for taking image with processing

284 {
285  int res;
286  hwinit();
287  printf("Please set the focus to the middle of the base, then type 'q'..\n");
288  monitor();
289  tunelight();
290  takebggchere(); //take background and equalization map
292 
293  o->ApplyGainCorr=true;
294 // o->ApplyGainCorr=false;
295  o->ApplyFIRF=true;
296  o->Threshold=ThrTop;
297  o->SubtractBG=true;
298  return 1;
299 
300 }
int hwinit()
Definition: hwinit.C:72
int tunelight()
Definition: init.C:244
takebggchere()
Definition: init.C:178
monitor()
Definition: init.C:360

◆ lightcurve()

void lightcurve ( int  INCREMENT)
200 {
201  int L0=s->L->LightLevel;
202  TCanvas *c=new TCanvas();
203  TH1F* h=new TH1F("PPH","PPH",256,0,256);
204 
205  TH1F* Uh=new TH1F("Uh","",(LLMAX-LLMIN)/INCREMENT,LLMIN,LLMAX);
206  Uh->SetLineColor(kBlue); //Underflows
207  TH1F* Oh=new TH1F("Oh","",(LLMAX-LLMIN)/INCREMENT,LLMIN,LLMAX);
208  Oh->SetLineColor(kRed); //Overflows
209  TH1F* Mh=new TH1F("Mh","",(LLMAX-LLMIN)/INCREMENT,LLMIN,LLMAX);
210  Mh->SetLineColor(kGreen); //Mean
211  TH1F* Rh=new TH1F("Rh","",(LLMAX-LLMIN)/INCREMENT,LLMIN,LLMAX);
212  Rh->SetLineColor(kBlack); //RMS
213 
214  for(int LL=LLMIN; LL<LLMAX; LL+=INCREMENT)
215  {
216  s->L->LightLevel=LL;
217  s->L->ON();
218  gSystem->Sleep(LDelay);
220  o->ApplyGainCorr=false;
221  o->ApplyFIRF=false;
222  o->Threshold=0;
223  o->SubtractBG=false;
224  o->GrabOneImage(s->Z->GetPos(),5);
225 // Try to figure out what the image looks like...
226  h->Reset();
227  o->PlotImage1D(0, h);
228 // h->Draw(); c->Update();
229  float Underflows=h->GetBinContent(0)+h->GetBinContent(1)+h->GetBinContent(2);
230  float Overflows=h->GetBinContent(257)+h->GetBinContent(256)+h->GetBinContent(255);
231  float Mean=h->GetMean();
232  float RMS=h->GetRMS();
233  Uh->Fill(LL,TMath::Log(Underflows+1)/TMath::Log(10.)*20.);
234  Oh->Fill(LL,TMath::Log(Overflows+1)/TMath::Log(10.)*20.);
235  Mh->Fill(LL,Mean);
236  Rh->Fill(LL,RMS);
237  Mh->Draw(); Rh->Draw("same"); Oh->Draw("same"); Uh->Draw("same");
238  c->Update();
239  }
240  s->L->LightLevel=L0; s->L->ON();
241 
242 }
bool Log(int level, const char *location, const char *fmt,...)
Definition: EdbLog.cxx:75
int GrabOneImage(float Z, double Timeout=0)
Definition: AcqOdyssey.cxx:1084
int LLMAX
Definition: hwinit.C:7
int LDelay
Definition: hwinit.C:8
int LLMIN
Definition: hwinit.C:6

◆ monitor()

monitor ( )
361 {
362  o->StartLiveGrab();
363  s->Monitor();
364  o->StopLiveGrab();
365 }
void StartLiveGrab()
Definition: AcqOdyssey.cxx:1100
void StopLiveGrab()
Definition: AcqOdyssey.cxx:1110

◆ scanbot()

int scanbot ( )
59 {
60  Z0=s->Z->Reference;
61  DZ=s->EmBotLayer;
62  return scanview();
63 }
int scanview()
Definition: init.C:64

◆ scanmarks()

int scanmarks ( )
369 {
370  printf("Point1\n");
371  if(FM->eFoundMarksSet) { /*delete FM->eFoundMarksSet;*/}
372  printf("Point2\n");
374  printf("Point3\n");
375  for(int m=0;m<FM->eMarksSet->GetN();m++)
376  {
377  printf("Point m=%d\n",m);
378  float X,Y,Z;
379  float Xn,Yn;
380  FM->GotoMark(m);
381  if(!focus(300)) continue;
382  if(!FM->ScanMark(&X,&Y,&Z)) { o->StopLiveGrab(); continue; }
383  o->StopLiveGrab();
384  Xn=FM->eMarksSet->GetAbsolute()->GetMark(m)->X();
385  Yn=FM->eMarksSet->GetAbsolute()->GetMark(m)->Y();
388  }
389  FM->eFoundMarksSet->Print();
390  if(FM->eFoundMarksSet->GetN()<3) {printf("Less than 3 marks found! Aborting.\n"); s->eAffine=0; return 0;}
391  printf("Affine transformation from stage to nominal :\n");
393  s->eAffine=FM->eFoundMarksSet->Stage2Abs();
394  return 1;
395 }
float Xn[5]
Definition: RecDispMC_Profiles.C:859
bool ScanMark(float *X=NULL, float *Y=NULL, float *Z=NULL)
Definition: AcqMarksScanner.cxx:280
bool GotoMark(int Id)
Definition: AcqMarksScanner.cxx:77
void Print(Option_t *opt="") const
Definition: EdbAffine.cxx:52
void AddMark(int id, float x, float y, int flag=0)
Definition: EdbFiducial.cxx:716
Definition: EdbFiducial.h:88
EdbMarksBox * GetAbsolute() const
Definition: EdbFiducial.h:109
EdbAffine2D * Stage2Abs() const
Definition: EdbFiducial.cxx:279
void Print(Option_t *opt="") const
Definition: EdbFiducial.cxx:593
struct @8 Z
int focus(int clu_thre=300)
Definition: init.C:76
Double_t X
Definition: tlg2pattern.C:77
Double_t Y
Definition: tlg2pattern.C:77

◆ scantop()

int scantop ( )
49 {
50 // o->ApplyGainCorr=false;
51 // o->ApplyFIRF=false;
52 // o->Threshold=0;
53 // o->SubtractBG=false;
54  Z0=s->Z->Reference+s->EmBotLayer+s->EmBase;
55  DZ=s->EmTopLayer;
56  return scanview();
57 }

◆ scanview()

int scanview ( )
65 {
66 
67  TS->Layers=Layers;
68  TS->FPS=FPS;
69  return TS->ScanView(Z0,DZ);
70 }

◆ showgain()

void showgain ( )
398 {
399  short aa[1280*1024];
400  o->GetGCImage(aa);
401  TH2S *hg = new TH2S("hg","hg",1280,0,1280,1024,0,1024);
402  for(int iy=10; iy<1014; iy++)
403  for(int ix=10; ix<1270; ix++) hg->Fill(ix,iy,aa[iy*1280+ix]);
404 
405  gStyle->SetPalette(1);
406  hg->Draw("colZ");
407  c1->SaveAs("c1.gif");
408 }
void GetGCImage(short *buf)
Definition: AcqOdyssey.cxx:442
TCanvas * c1
Definition: energy.C:13

◆ takebggc()

takebggc ( float  X0,
float  Y0,
float  Z0 
)
148 {
149  s->L->ON();
150  float ZC=s->Z->GetPos();
151  s->Z->PosMove(ZC+10000,1e6,1e6);
152  s->Z->WaitForMoveComplete(1e4);
153 
154  s->X->PosMove(X0,1e6,1e6);
155  s->Y->PosMove(Y0,1e6,1e6);
156  s->X->WaitForMoveComplete(1e4);
157  s->Y->WaitForMoveComplete(1e4);
158  s->Z->PosMove(Z0,1e6,1e6);
159  s->Z->WaitForMoveComplete(1e4);
160 
162  o->ApplyGainCorr=false;
163  o->ApplyFIRF=false;
164  o->Threshold=0;
165  o->SubtractBG=false;
166  if(imageat(Z0)<1) {printf("Can't take image! Abort.\n"); return 0 ;};
167  o->CopyImageToGC(0,0xC8);
168 
170  o->ApplyGainCorr=true;
171  o->ApplyFIRF=true;
172  o->Threshold=0;
173  o->SubtractBG=false;
174  if(imageat(Z0)<1) {printf("Can't take image! Abort.\n"); return 0 ;};
175  return 1;
176 }
void CopyImageToGC(int N, long ConstBG=0)
Definition: AcqOdyssey.cxx:377
float X0
Definition: emthickness.cpp:69
float Y0
Definition: emthickness.cpp:70
int imageat(float Z0)
Definition: init.C:5

◆ takebggchere()

takebggchere ( )
179 {
180  float Z0=s->Z->GetPos();
182  o->ApplyGainCorr=false;
183  o->ApplyFIRF=false;
184  o->Threshold=0;
185  o->SubtractBG=false;
186  if(imageat(Z0)<1) {printf("Can't take image! Abort.\n"); return 0 ;};
187  o->CopyImageToGC(0,0xC8);
188 
190  o->ApplyGainCorr=true;
191  o->ApplyFIRF=true;
192  o->Threshold=0;
193  o->SubtractBG=false;
194  if(imageat(Z0)<1) {printf("Can't take image! Abort.\n"); return 0 ;};
195  return 1;
196 }

◆ tunelight()

int tunelight ( )
245 {
246  TH1F* h=new TH1F("PPH","PPH",256,0,256);
247  bool Stop=false;
248  int LL;
249  LL=LLMAX;
250  int Dir=-1; // start to decrease light
251  TCanvas *c=new TCanvas();
252 while(!Stop)
253  {
254  s->L->LightLevel=LL;
255  s->L->ON();
256  gSystem->Sleep(LDelay);
258  o->ApplyGainCorr=false;
259  o->ApplyFIRF=false;
260  o->Threshold=0;
261  o->SubtractBG=false;
262  o->GrabOneImage(s->Z->GetPos(),5);
263 // Try to figure out what the image looks like...
264  h->Reset();
265  o->PlotImage1D(0, h);
266  h->Draw(); c->Update();
267  float Underflows=h->GetBinContent(0)+h->GetBinContent(1)+h->GetBinContent(2);
268  float Overflows=h->GetBinContent(257)+h->GetBinContent(256)+h->GetBinContent(255);
269  float Mean=h->GetMean();
270  float RMS=h->GetRMS();
271 
272  if(Underflows>10000) { LL+=Dir*500; continue; }
273  if(Underflows>100) { LL+=Dir*200; continue; }
274  if(Underflows>10) { LL+=Dir*20; continue; }
275  if(Overflows>100) { printf("Image profile saturates from both sides! Can't set up light..\n"); return 0; }
276  Stop=1;
277  }
278  printf("Light is set to : %d\n",LL);
279  return 1;
280 }

◆ xy()

xy ( float  X,
float  Y 
)
304 {
305  s->X->PosMove(X,1e9,1e9);
306  s->Y->PosMove(Y,1e9,1e9);
307 }

◆ xyabs()

xyabs ( float  X,
float  Y 
)
310 {
311  EdbMark *p=new EdbMark();
312  p->SetX(X);
313  p->SetY(Y);
314  if(FM->eFoundMarksSet)
315  {
316  p->Transform(FM->eFoundMarksSet->Abs2Stage());
317  }
318 
319  s->X->PosMove(p->X(),1e9,1e9);
320  s->Y->PosMove(p->Y(),1e9,1e9);
321  delete p;
322 }
Definition: EdbFiducial.h:21
EdbAffine2D * Abs2Stage() const
Definition: EdbFiducial.cxx:271
p
Definition: testBGReduction_AllMethods.C:8

Variable Documentation

◆ run

EdbRun* run =0

◆ ThTol

float ThTol =0.5