Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
326 | f9daq | 1 | #include "vme.h" |
2 | #include <userint.h> |
||
3 | #include "minirich.h" |
||
4 | #include "toolbox.h" |
||
5 | #include "icfa.h" |
||
6 | #include "H1D.h" |
||
7 | #include "H2D.h" |
||
8 | #include "H3D.h" |
||
9 | #include "HDraw.h" |
||
10 | |||
11 | |||
12 | |||
13 | int p6h; |
||
14 | int hxy=200; |
||
15 | int minirichplothandle=0; |
||
16 | |||
17 | int sa02Printf(const char *format, ...); |
||
18 | |||
19 | typedef struct { |
||
20 | int feb; |
||
21 | int chip; |
||
22 | int ch; |
||
23 | int chx; |
||
24 | int chy; |
||
25 | int pmtx; |
||
26 | int pmty; |
||
27 | int pmtid |
||
28 | } EID2MAPMT; |
||
29 | |||
30 | EID2MAPMT eid2mapmt[144*4]; |
||
31 | |||
32 | |||
33 | int icfa_LoadElectronicMap(const char *fname) { |
||
34 | |||
35 | FILE *fp = fopen(fname,"r"); |
||
36 | int febidx, feb,chip,ch,chx,chy,pmtx,pmty,pmt; |
||
37 | int nread=0; |
||
38 | int ndim=400; |
||
39 | char line[400]; |
||
40 | int nr=0; |
||
41 | // file should be sorted feb [0..3], chip[0..3], ch [0.. 35] |
||
42 | while (fgets(line,ndim,fp)!=NULL) { |
||
43 | // FEBCH PMTCH X Y PMTX PMTY PMTID |
||
44 | |||
45 | nr = sscanf(line,"%d%d%d%d%d",&febidx,&ch,&chx,&chy,&pmt); |
||
46 | if (nr) { |
||
47 | chip = febidx / 36; |
||
48 | ch = febidx % 36; |
||
49 | pmtx = pmt / 3; |
||
50 | pmty = pmt % 3; |
||
51 | for (feb = 0; feb<4; feb++){ |
||
52 | // 4 febs |
||
53 | // 0 2 |
||
54 | // 1 3 |
||
55 | int fx = feb %2; |
||
56 | int fy = feb /2; |
||
57 | eid2mapmt[nread+feb*144].feb = feb; |
||
58 | eid2mapmt[nread+feb*144].chip = chip; |
||
59 | eid2mapmt[nread+feb*144].ch = ch ; |
||
60 | eid2mapmt[nread+feb*144].chx = chx + fx * 18; |
||
61 | eid2mapmt[nread+feb*144].chy = chy + fy * 18; |
||
62 | eid2mapmt[nread+feb*144].pmtx = pmtx ; |
||
63 | eid2mapmt[nread+feb*144].pmty = pmty ; |
||
64 | } |
||
65 | } |
||
66 | nread++; |
||
67 | } |
||
68 | sa02Printf("eid2pmtxy %d records read.\n",nread); |
||
69 | fclose(fp); |
||
70 | return 0; |
||
71 | |||
72 | } |
||
73 | |||
74 | |||
75 | int icfa_GetPosition(unsigned int febchid, int *chx, int *chy) { |
||
76 | |||
77 | if (febchid>=144*4) return -1; |
||
78 | *chx = eid2mapmt[febchid].chx; |
||
79 | *chy = eid2mapmt[febchid].chy ; |
||
80 | return 0; |
||
81 | } |
||
82 | |||
83 | int icfa_Fill(int febchid, double weight){ |
||
84 | int x; |
||
85 | int y; |
||
86 | icfa_GetPosition(febchid, &x, &y); |
||
87 | H2DFillBin(hxy, x,y,weight); |
||
88 | return 0; |
||
89 | } |
||
90 | |||
91 | |||
92 | |||
93 | int icfa_Init(){ // read mapmt mapping |
||
94 | |||
95 | icfa_LoadElectronicMap("eid2pmtxy.map"); |
||
96 | //short VMUSB_VME_DGG(unsigned short channel, unsigned short trigger,unsigned short output, |
||
97 | // long delay, unsigned short gate, unsigned short invert, unsigned short latch); |
||
98 | // set DGG 1 to create ADC gate, I1 -> O1 delay:0, gate 0x400 = 12us |
||
99 | WIENER_VMUSB_VME_DGG(0,1,0,0x0,0x100,0,0); |
||
100 | /* |
||
101 | channel |
||
102 | [in] The DGG channel you wish to modify. Valid values are: |
||
103 | |||
104 | 1 – For DGG channel B |
||
105 | trigger |
||
106 | [in] Determines the start of the DGG. Valid Values are: |
||
107 | |||
108 | 1 – NIM input 1 |
||
109 | 2 – NIM input 2 |
||
110 | 3 – Event Trigger |
||
111 | 4 - End of Event |
||
112 | 5 - USB Trigger |
||
113 | 6 - Pulser |
||
114 | output |
||
115 | [in] Determines the NIM ouput used for the DGG channel. Valid values are: |
||
116 | |||
117 | 1 – NIM O2 |
||
118 | delay |
||
119 | [in] 32 bit word in steps of 12.5ns between trigger and start of gate consisting of |
||
120 | lower 16 bits: Delay_fine |
||
121 | upper 16 bits: Delay_coarse |
||
122 | gate |
||
123 | [in] Sets the length of the gate in units of 12.5ns |
||
124 | invert |
||
125 | [in] Determines whether or not the DGG is inverted. Valid values are: |
||
126 | |||
127 | 1 – Is inverted |
||
128 | latch |
||
129 | [in] Determines whether or not the DGG is latched. Valid values are: |
||
130 | |||
131 | 1 – Is latched |
||
132 | */ |
||
133 | // User Devices Source Selector - Read/Write Offset = 16 0x10 |
||
134 | // xxusb_register_write(udev, XXUSB_ACTION_REGISTER, 0x2); // USB Trigger |
||
135 | WIENER_VMUSB_VME_DGG(0,5,0,0xF,0xF,0,0); |
||
136 | //WIENER_VMUSB_VME_Output_settings(0,7,0,0); // nekaj od tega bi moralo delat |
||
137 | WIENER_VMUSB_register_write(10,0x2); // USB Trigger |
||
138 | |||
139 | |||
140 | return 0; |
||
141 | } |
||
142 | |||
143 | int icfa_Histo(){ // read mapmt mapping |
||
144 | |||
145 | H2DInit(hxy,"minirich","MiniRICH hit map",36,0, 1,36,0, 1); |
||
146 | H2DSetTitleX(hxy,"x (channels)"); |
||
147 | H2DSetTitleY(hxy,"y (channels)"); |
||
148 | return 0; |
||
149 | } |
||
150 | |||
151 | |||
152 | int icfa_Draw(){ |
||
153 | |||
154 | if (minirichplothandle > 0 ) { |
||
155 | DeleteGraphPlot (p6h, MINIRICH_GRAPH, minirichplothandle, VAL_IMMEDIATE_DRAW); |
||
156 | minirichplothandle=0; |
||
157 | } |
||
158 | H2DDraw(hxy,p6h, MINIRICH_GRAPH, &minirichplothandle); |
||
159 | |||
160 | return 0; |
||
161 | } |
||
162 | |||
163 | int icfa_Event(uint32_t *d, int mode){ |
||
164 | if (!mode) H2DClear(hxy); |
||
165 | for (int i=0;i<144*4;i++){ |
||
166 | if (d[i]>0) icfa_Fill(i,d[i]); |
||
167 | } |
||
168 | return 0; |
||
169 | } |
||
170 | |||
171 | int CVICALLBACK daq_icfa(void *functionData) { |
||
172 | |||
173 | int neve; |
||
174 | int threshold; |
||
175 | icfa_Init(); |
||
176 | GetCtrlVal(p6h,MINIRICH_NEVE, &neve); |
||
177 | GetCtrlVal(p6h,MINIRICH_THR, &threshold); |
||
178 | |||
179 | icfa_Histo(); |
||
180 | |||
181 | for (int k=0;k<144*4;k++){ |
||
182 | int i = Random(0,144*4); |
||
183 | icfa_Fill(k,1); |
||
184 | } |
||
185 | icfa_Draw(hxy); |
||
186 | return 0; |
||
187 | } |
||
188 | |||
189 | |||
190 | int CVICALLBACK rich_Draw_RingCB (int panel, int control, int event, |
||
191 | void *callbackData, int eventData1, int eventData2) { |
||
192 | static int oh1=0; |
||
193 | static int oh2=0; |
||
194 | switch (event) { |
||
195 | case EVENT_COMMIT: { |
||
196 | double min_r; |
||
197 | double max_r; |
||
198 | double x,y; |
||
199 | GetCtrlVal (p6h, MINIRICH_R_MIN, &min_r ) ; |
||
200 | GetCtrlVal (p6h, MINIRICH_R_MAX, &max_r ) ; |
||
201 | double r1=min_r*2.0 ; |
||
202 | double r2=max_r*2.0 ; |
||
203 | GetGraphCursor (p6h, MINIRICH_GRAPH, 1, &x, &y); |
||
204 | sa02Printf ( "x:%5.2f\ty:%5.2f OH1=%d OH2=%d\n", x, y, oh1, oh2 ) ; |
||
205 | |||
206 | if (oh1 > 0 ) { |
||
207 | DeleteGraphPlot (p6h, MINIRICH_GRAPH, oh1, VAL_IMMEDIATE_DRAW); |
||
208 | oh1=0; |
||
209 | } |
||
210 | if (oh2 > 0 ) { |
||
211 | DeleteGraphPlot (p6h, MINIRICH_GRAPH, oh2, VAL_IMMEDIATE_DRAW); |
||
212 | oh2=0; |
||
213 | } |
||
214 | oh1 = PlotOval (p6h, MINIRICH_GRAPH, x-r1, y-r1, x+r1, y+r1, VAL_RED, VAL_TRANSPARENT); |
||
215 | oh2 = PlotOval (p6h, MINIRICH_GRAPH, x-r2, y-r2, x+r2, y+r2, VAL_RED, VAL_TRANSPARENT); |
||
216 | break; |
||
217 | } |
||
218 | } |
||
219 | return 0; |
||
220 | } |
||
221 | |||
222 | int CVICALLBACK rich_Histo_ClearCB (int panel, int control, int event, |
||
223 | void *callbackData, int eventData1, int eventData2) { |
||
224 | switch (event) { |
||
225 | case EVENT_COMMIT: |
||
226 | H2DClear(hxy); |
||
227 | icfa_Draw(); |
||
228 | break; |
||
229 | } |
||
230 | return 0; |
||
231 | } |
||
232 | |||
233 | int CVICALLBACK icfa_StartCB (int panel, int control, int event, |
||
234 | void *callbackData, int eventData1, int eventData2) { |
||
235 | switch (event) { |
||
236 | case EVENT_COMMIT: |
||
237 | daq_icfa(NULL); |
||
238 | break; |
||
239 | } |
||
240 | return 0; |
||
241 | } |
||
242 | |||
243 | extern HColorMap *colormap; |
||
244 | int CVICALLBACK SetMaximum (int panel, int control, int event, |
||
245 | void *callbackData, int eventData1, int eventData2) { |
||
246 | switch (event) { |
||
247 | case EVENT_COMMIT: |
||
248 | if (minirichplothandle> 0 ) DeleteGraphPlot (panel, MINIRICH_GRAPH, minirichplothandle, VAL_IMMEDIATE_DRAW); |
||
249 | |||
250 | int histogram=hxy; |
||
251 | double min = H2DGetMin(histogram); |
||
252 | |||
253 | |||
254 | double fx=0; |
||
255 | GetCtrlVal(p6h,MINIRICH_MAXZ, &fx); |
||
256 | double max = H2DGetMax(histogram)*fx/100.; |
||
257 | RangeColors(min,max); |
||
258 | minirichplothandle = PlotScaledIntensity (panel, MINIRICH_GRAPH, |
||
259 | H2DGetData(histogram), |
||
260 | H2DGetNbinsX(histogram), |
||
261 | H2DGetNbinsY(histogram), |
||
262 | VAL_DOUBLE, |
||
263 | H2DGetStepY(histogram), |
||
264 | H2DGetMinY(histogram), |
||
265 | H2DGetStepX(histogram), |
||
266 | H2DGetMinX(histogram), |
||
267 | colormap->array, |
||
268 | colormap->HiColor, |
||
269 | colormap->numberofColors, 1, 0); |
||
270 | break; |
||
271 | } |
||
272 | return 0; |
||
273 | } |