1 | function [FileName eps_x eps_z rms_x_source rms_z_source rms_x_convavantdec rms_z_convavantdec] = getpinhole(varargin) |
---|
2 | % GETPINHOLE enregistre les images de la caméra pinhole avec les paramÚtres |
---|
3 | % environnants. |
---|
4 | % ATTENTION les devices emittance et Image Analyser doivent etre opérationnels |
---|
5 | % et la "Region Of Interest" de l'image analyser optimisée |
---|
6 | % INPUTS |
---|
7 | % 'Display' affiche l'image enregistrée (par défaut) |
---|
8 | % 'NoDisplay' le contraire.. |
---|
9 | % 'Archive' sauvegarde la structure matlab (par défaut) |
---|
10 | % 'NoArchive' le contraire.. |
---|
11 | % |
---|
12 | % OUTPUTS |
---|
13 | % 1. eps_x - Horizontal emittance |
---|
14 | % 2. eps_z - Vertical emittance |
---|
15 | % 3. rms_x_source - Horizontal beam size at the source point |
---|
16 | % 4. rms_z_source - Horizontal beam size at the source point |
---|
17 | |
---|
18 | % |
---|
19 | % Written By Marie-Agnes Tordeux and Laurent S. Nadolski |
---|
20 | % Modification Laurent S. Nadolski, May 25th, 2007 |
---|
21 | % output variable to be used in scripts with no graphical interface. |
---|
22 | % Update new Tango interface for PHC-IMAGEANALYZER |
---|
23 | |
---|
24 | % update 26 avril 2012 : rétro calcul des tailles aux points source |
---|
25 | |
---|
26 | DisplayFlag = 1; |
---|
27 | ScriptFlag = 0; % no message to be used within script |
---|
28 | |
---|
29 | ArchiveFlag = 1; |
---|
30 | |
---|
31 | for i = length(varargin):-1:1 |
---|
32 | if strcmpi(varargin{i},'Display') |
---|
33 | DisplayFlag = 1; |
---|
34 | varargin(i) = []; |
---|
35 | elseif strcmpi(varargin{i},'NoDisplay') |
---|
36 | DisplayFlag = 0; |
---|
37 | varargin(i) = []; |
---|
38 | elseif strcmpi(varargin{i},'NoArchive') |
---|
39 | ArchiveFlag = 0; |
---|
40 | varargin(i) = []; |
---|
41 | elseif strcmpi(varargin{i},'NoDisplay') |
---|
42 | DisplayFlag = 0; |
---|
43 | varargin(i) = []; |
---|
44 | elseif strcmpi(varargin{i},'Script') |
---|
45 | ScriptFlag = 1; |
---|
46 | varargin(i) = []; |
---|
47 | elseif strcmpi(varargin{i},'NoScript') |
---|
48 | ScriptFlag = 0; |
---|
49 | varargin(i) = []; |
---|
50 | elseif strcmpi(varargin{i},'Archive') |
---|
51 | ArchiveFlag = 1; |
---|
52 | varargin(i) = []; |
---|
53 | end |
---|
54 | end |
---|
55 | |
---|
56 | % Starting time |
---|
57 | t0 = clock; |
---|
58 | FileName = ''; |
---|
59 | dev = 'ANS-C02/DG/PHC-VG'; |
---|
60 | devAna = 'ANS-C02/DG/PHC-IMAGEANALYZER'; |
---|
61 | devatt = 'ANS-C02/DG/PHC-M.ATT'; |
---|
62 | devpoint = 'ANS-C02/DG/PHC-M.CAM1.VERT'; |
---|
63 | devposH = 'ANS-C02/DG/PHC-M.CAM2_HORZ'; |
---|
64 | devposV = 'ANS-C02/DG/PHC-M.CAM2_HORZ2'; |
---|
65 | devpinholeH = 'ANS-C02/DG/PHC-M.PH_HORZ'; |
---|
66 | devpinholeV = 'ANS-C02/DG/PHC-M.PH_VERT'; |
---|
67 | devpinholegonio = 'ANS-C02/DG/PHC-M.PH_GONIO'; |
---|
68 | devpinholerot = 'ANS-C02/DG/PHC-M.PH_ROT'; |
---|
69 | devemit = 'ANS-C02/DG/PHC-EMIT'; |
---|
70 | |
---|
71 | temp=tango_read_attribute2(dev,'Image'); |
---|
72 | ImagePHC = temp.value'; |
---|
73 | rep.image = ImagePHC; |
---|
74 | rep.current = getdcct; |
---|
75 | |
---|
76 | rep.growth = readattribute([devAna '/OpticalMagnification']); |
---|
77 | a=tango_get_property(devemit,'DistPinholeH2Convert') ; rep.DistPinholeH2Convert = str2num(a.value{:}) ; |
---|
78 | a=tango_get_property(devemit,'DistPinholeV2Convert') ; rep.DistPinholeV2Convert = str2num(a.value{:}) ; |
---|
79 | a=tango_get_property(devemit,'DistSource2PinholeH') ; rep.DistSource2PinholeH = str2num(a.value{:}); |
---|
80 | a=tango_get_property(devemit,'DistSource2PinholeV') ; rep.DistSource2PinholeV = str2num(a.value{:}); |
---|
81 | |
---|
82 | rep.pixelsizex = readattribute([devAna '/PixelSizeX']); |
---|
83 | rep.pixelsizez = readattribute([devAna '/PixelSizeY']); |
---|
84 | rep.betaX = readattribute([devemit '/BetaX']); |
---|
85 | rep.betaZ = readattribute([devemit '/BetaZ']); |
---|
86 | rep.etaX = readattribute([devemit '/EtaX']); |
---|
87 | rep.etaZ = readattribute([devemit '/EtaZ']); |
---|
88 | rep.gamma = readattribute([devAna '/GammaCorrection']); |
---|
89 | rep.sigmax = readattribute([devAna '/XProjFitSigma']); |
---|
90 | rep.magnitudex = readattribute([devAna '/XProjFitMag']); |
---|
91 | rep.sigmaz = readattribute([devAna '/YProjFitSigma']); |
---|
92 | rep.magnitudez = readattribute([devAna '/YProjFitMag']); |
---|
93 | rep.attenuateur = readattribute([devatt '/position']); |
---|
94 | rep.pos_H_pinhole = readattribute([devpinholeH '/position']); % position H de la pinhole |
---|
95 | rep.pos_V_pinhole = readattribute([devpinholeV '/position']); % position V de la pinhole |
---|
96 | rep.pos_gonio_pinhole = readattribute([devpinholegonio '/position']); % position gonio de la pinhole |
---|
97 | rep.pos_rot_pinhole = readattribute([devpinholerot '/position']); % position rotation de la pinhole |
---|
98 | rep.point = readattribute([devpoint '/position']); % mise au point camera 2 |
---|
99 | rep.posH = readattribute([devposH '/position']); % position horizontale camera 2 |
---|
100 | rep.posV = readattribute([devposV '/position']); % position verticale (vis à vis du convertisseur) camera 2 |
---|
101 | rep.X = tango_read_attribute2(devAna,'XProj'); |
---|
102 | rep.Z = tango_read_attribute2(devAna,'YProj'); |
---|
103 | rep.fitX = tango_read_attribute2(devAna,'XProjFitted'); |
---|
104 | rep.fitZ = tango_read_attribute2(devAna,'YProjFitted'); |
---|
105 | rep.GaussianFitTilt = readattribute([devAna '/GaussianFitTilt']); |
---|
106 | rep.pinholesizeV = readattribute([devemit '/PinholeSizeV']); |
---|
107 | rep.pinholesizeH = readattribute([devemit '/PinholeSizeH']); |
---|
108 | rep.emittanceX = readattribute([devemit '/EmittanceH']); |
---|
109 | rep.emittanceZ = readattribute([devemit '/EmittanceV']); |
---|
110 | %rep.QT1 = getam('QT', [1 1]) |
---|
111 | |
---|
112 | if DisplayFlag |
---|
113 | %figure(101); |
---|
114 | figure |
---|
115 | image(ImagePHC,'CDataMapping','scaled','Parent',gca) |
---|
116 | %figure(105); |
---|
117 | figure |
---|
118 | plot(rep.fitX.value,'k') ; hold on ; plot(rep.X.value,'r') ; |
---|
119 | xlabel('numero de pixel') |
---|
120 | plot(rep.fitZ.value,'p') ; hold on ; plot(rep.Z.value,'b') ; legend('fit H de l''ImageAnalyser','Données brutes H','fit V de l''ImageAnalyser','Données brutes V') |
---|
121 | xlabel('numero de pixel') |
---|
122 | title('Profils H et V projetés dans la région d''interet (ROI)'); |
---|
123 | hold off |
---|
124 | %%%%%%%%%%%%%%% WARNING |
---|
125 | |
---|
126 | end |
---|
127 | |
---|
128 | %%% test du gamma |
---|
129 | if rep.gamma ~= 1 |
---|
130 | disp('gamma caméra n''est pas à sa valeur correcte') % test sur la valeur de gamma |
---|
131 | return |
---|
132 | end |
---|
133 | |
---|
134 | %%% pixel intensité max |
---|
135 | Max_image_brute = max(max(ImagePHC)); |
---|
136 | warning_intensite = 0; |
---|
137 | if Max_image_brute>4000 |
---|
138 | disp('l''image est saturée - modifier l''atténuateur') % test sur la saturation de l'image |
---|
139 | RES = [double(Max_image_brute)]; |
---|
140 | fprintf('max pixel = %13.2f \n',RES ) |
---|
141 | %return |
---|
142 | elseif Max_image_brute<300 |
---|
143 | warning_intensite = 1; |
---|
144 | end |
---|
145 | |
---|
146 | |
---|
147 | if ArchiveFlag |
---|
148 | toto = 0; |
---|
149 | if isempty(FileName) |
---|
150 | FileName = appendtimestamp(getfamilydata('Default', 'PINHOLEArchiveFile')); |
---|
151 | DirectoryName = getfamilydata('Directory', 'PINHOLE'); |
---|
152 | if isempty(DirectoryName) |
---|
153 | DirectoryName = [getfamilydata('Directory','DataRoot'), 'Response', filesep, 'BPM', filesep]; |
---|
154 | else |
---|
155 | % Make sure default directory e('l''image est saturée - modifier l''atténuateur')xists |
---|
156 | DirStart = pwd; |
---|
157 | [DirectoryName, ErrorFlag] = gotodirectory(DirectoryName); |
---|
158 | cd(DirStart); |
---|
159 | end |
---|
160 | [FileName, DirectoryName] = uiputfile('*.mat', 'Select a Pinhole File ("Save" starts measurement)', [DirectoryName FileName]); |
---|
161 | if FileName == 0 |
---|
162 | ArchiveFlag = 0; |
---|
163 | disp(' Pinhole registration canceled.'); |
---|
164 | toto = 1; |
---|
165 | %return |
---|
166 | else |
---|
167 | FileName = [DirectoryName, FileName]; |
---|
168 | end |
---|
169 | |
---|
170 | elseif FileName == -1 |
---|
171 | FileName = appendtimestamp(getfamilydata('Default', 'QUADArchiveFile')); |
---|
172 | DirectoryName = getfamilydata('Directory', 'QUAD'); |
---|
173 | FileName = [DirectoryName, FileName]; |
---|
174 | end |
---|
175 | |
---|
176 | rep.CreatedBy = 'getpinhole'; |
---|
177 | rep.t = t0; |
---|
178 | rep.tout = etime(clock,t0); |
---|
179 | rep.TimeStamp = datestr(clock); |
---|
180 | if toto == 0 |
---|
181 | save(FileName,'rep'); |
---|
182 | end |
---|
183 | fprintf('Data save in filename %s \n', FileName); |
---|
184 | %fprintf('***************************************************************** \n'); |
---|
185 | |
---|
186 | end |
---|
187 | |
---|
188 | if ~ScriptFlag |
---|
189 | |
---|
190 | fprintf('*********** paramÚtres instrumentation pinhole **************** \n'); |
---|
191 | fprintf('atténuateur (nb pas) %22.2f \n',rep.attenuateur); |
---|
192 | fprintf('position H de la pinhole %18.2f \n',rep.pos_H_pinhole); |
---|
193 | fprintf('position V de la pinhole %18.2f \n',rep.pos_V_pinhole); |
---|
194 | fprintf('position gonio de la pinhole %14.2f \n',rep.pos_gonio_pinhole); |
---|
195 | fprintf('position rotation de la pinhole %11.2f \n',rep.pos_rot_pinhole); |
---|
196 | fprintf('position H de la camera %12.2f \n',rep.posH); |
---|
197 | fprintf('position V de la camera %12.2f \n',rep.posV); |
---|
198 | fprintf('mise au point de la camera %9.2f \n',rep.point); |
---|
199 | fprintf('Grandissement de la partie visible %12.2f \n',rep.growth); |
---|
200 | fprintf('Distance Pinhole - Convertisseur plan H :%10.4f \n', rep.DistPinholeH2Convert); |
---|
201 | fprintf('Distance Pinhole - Convertisseur plan V :%10.4f \n', rep.DistPinholeV2Convert); |
---|
202 | fprintf('Distance source - Pinhole plan H :%10.4f \n', rep.DistSource2PinholeH); |
---|
203 | fprintf('Distance source - Pinhole plan V :%10.4f \n', rep.DistSource2PinholeV); |
---|
204 | fprintf('Taille des pinholes en microns: %12.2f H et %5.2f V\n',rep.pinholesizeH,rep.pinholesizeV); |
---|
205 | |
---|
206 | |
---|
207 | fprintf('*********** paramÚtres faisceau généraux ********************** \n'); |
---|
208 | fprintf('courant dcct %20.2f \n', rep.current); |
---|
209 | fprintf('Intensité maximale sur la CCD %20.2f \n',Max_image_brute); |
---|
210 | |
---|
211 | fprintf('***** paramÚtres faisceau sur convertisseur X-> visible ******* \n'); |
---|
212 | fprintf('sigmax au convertisseur en µm %14.2f \n', rep.sigmax); |
---|
213 | fprintf('sigmaz au convertisseur en µm %14.2f \n', rep.sigmaz); |
---|
214 | |
---|
215 | fprintf('********* paramÚtres faisceau au point source ***************** \n'); |
---|
216 | % fprintf('sigmax au point source en µm %14.2f \n', rep.sigmax/(rep.DistPinholeH2Convert/rep.DistSource2PinholeH)); |
---|
217 | % fprintf('sigmaz au point source en µm %14.2f \n', rep.sigmaz/(rep.DistPinholeV2Convert/rep.DistSource2PinholeV)); |
---|
218 | sigmax_point_source = 1e6*sqrt(rep.emittanceX*1e-9*rep.betaX + rep.etaX*rep.etaX*1.01e-3*1.01e-3); |
---|
219 | sigmaz_point_source = 1e6*sqrt(rep.emittanceZ*1e-12*rep.betaZ + rep.etaZ*rep.etaZ*1.01e-3*1.01e-3); |
---|
220 | |
---|
221 | fprintf('sigmax au point source en µm %14.2f \n', sigmax_point_source); |
---|
222 | fprintf('sigmaz au point source en µm %14.2f \n', sigmaz_point_source); |
---|
223 | fprintf('tilt de l''ellipse %15.1f \n', rep.GaussianFitTilt); |
---|
224 | |
---|
225 | fprintf('******************************************************************************************************* \n'); |
---|
226 | fprintf('---I dcct (mA)-----Emittance X(nm)---Emittance Z(pm)----Couplage (10-2) \n') |
---|
227 | RES = [rep.current rep.emittanceX rep.emittanceZ (rep.emittanceZ/rep.emittanceX)/10]; % modif 7 sept 2008 -> == DSERVER EMITTANCE |
---|
228 | fprintf(' %8.2f %8.2f %8.2f %8.2f \n',RES) |
---|
229 | fprintf('******************************************************************************************************* \n'); |
---|
230 | |
---|
231 | end |
---|
232 | |
---|
233 | if warning_intensite == 1 |
---|
234 | disp(' Attention l''illumination de la camera est faible '); |
---|
235 | disp(' veillez à recommencer en diminuant l''atténuateur '); |
---|
236 | end |
---|
237 | |
---|
238 | |
---|