/[PAMELA software]/yoda/techmodel/forroutines/calorimeter/calunpack.for
ViewVC logotype

Annotation of /yoda/techmodel/forroutines/calorimeter/calunpack.for

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2.9 - (hide annotations) (download)
Fri Jan 7 11:26:02 2005 UTC (19 years, 11 months ago) by kusanagi
Branch: MAIN
Changes since 2.8: +9 -7 lines
New  version 3.5.05

1 kusanagi 1.8 C
2 kusanagi 2.2 C Written by Emiliano Mocchiutti and Mirko Boezio
3 kusanagi 1.8 C
4 kusanagi 2.9 C * Version: 3.4.05 *
5 kusanagi 1.9 C
6 kusanagi 2.2 C Changelog:
7     C
8 kusanagi 2.9 C 3.4.04 - 3.4.05: (2005-01-05) XE is section y odd not even, fixed.
9     C
10 kusanagi 2.8 C 3.4.03 - 3.4.04: (2004-12-21) bug in recognising decoding errors, fixed.
11     C
12 kusanagi 2.7 C 3.4.02 - 3.4.03: (2004-12-17) forget to clear esci/stwerr and vector vect
13     C plus problems with lleng (truncated vect!). Fixed the
14     C clearing, workaround for lleng (to be further investigated)
15     C
16 kusanagi 2.6 C 3.4.01 - 3.4.02: (2004-12-10) cleanup of the code and changed sections order.
17     C
18 kusanagi 2.5 C 3.4.00 - 3.4.01: (2004-11-26) CA50 comes after Strips Hit, fixed.
19     C
20     C 3.3.03 - 3.4.00: (2004-11-08) changed the DSP program hence changed calunpack
21     C to better find the calorimeter sections.
22     C
23     C 3.3.02 - 3.3.03: (2004-11-08) changes in the commons (one more common for
24     C calpulse and from calstripshit to calstriphit).
25     C
26     C 3.3.01 - 3.3.02: (2004-10-19) italian name of subroutines translated to
27     C english. Forgot to clear vector in case of CRC errors,
28     C fixed. stwerr is integer not real! fixed
29     C
30 kusanagi 2.4 C 3.3.00 - 3.3.01: (2004-10-18) forgot to clear stwerr if no sections are found
31     C fixed.
32     C
33 kusanagi 2.2 C 3.2.00 - 3.3.00: (2004-10-15) enanched search of sections in case of one or
34     C more missing sections.
35     C Switched to c function "fillin" to create calorimeter words
36     C instead of fortran function "riempi": great improvement in
37     C time processing!!
38     C
39     C 3.1.00 - 3.2.00: (2004-10-13) forget to clean some variables, fixed.
40     C Reprocess event in the case we have CRC errors and a high
41     C number of error trying to understand the kind of event
42     C we are processing (raw, compress, full mode) in order to
43 kusanagi 2.4 C distinguish better the four section.The reprocessing happens
44 kusanagi 2.2 C on about the 30% of events with CRC errors (in the case of
45     C file 040827_005 the reprocessing is done on about 2% of all
46     C the events).
47     C
48     C 3.0.00 - 3.1.00: (2004-10-12) cleanup and speedup of the code, less loops
49     C same strength in finding the calorimeter sections.
50     C
51     C 2.18.4 - 3.0.00: (2004-10-07) major changes in the procedure to find the
52     C calorimeter sections and enhanced search in the case of
53     c CRC errors (to fix a bug which made the misunderstanding
54     C some kind of CRC errors with missing sections).
55     C Clean up unused variables, speeded up some loops.
56     C Zero length input vector error added.
57     C Enhanced search of the first section recorded since the
58     C starting point is very important to correctly find and
59     C interpret all the other sections.
60     C If section length is absurd and the CRC header bit = 0
61     C then search again for that section (needed to make a
62     C better search of section when in presence of CRC errors)
63     C Search all the sections and if you reach the end of vector
64     C (EOV) continue searching if you haven't find all the four
65     C section (and go out without looping if no section is
66     C present).
67 kusanagi 2.1 C
68     C 2.18.3 - 2.18.4: consider a bad thing if you find a section in the wrong
69     C position of the vector and try again to
70     C find the real data (if they exist).
71     C
72     C 2.18.2 - 2.18.3: vectors belonging to common must be cleared if the calo
73     C isn't found. Fixed.
74 kusanagi 1.8 C
75 kusanagi 2.1 C 2.18.1 - 2.18.2: fixed unclearing error codes if the program doesn't find
76     C the calorimeter where it should be but shifted somewhere
77 kusanagi 2.2 C else forgotten to clear st2c variable: fixed
78 kusanagi 2.1 C exit error code wrong in some cases: fixed
79 kusanagi 2.2 C self trigger data not saved: fixed.
80 kusanagi 2.1 C
81     C 2.18.0 - 2.18.1: small changes in the common varie to fix a memory leak;
82 kusanagi 2.2 C fixed an error in reporting error codes (stwerr,pwerror).
83 kusanagi 2.1 C
84 kusanagi 2.2 C 2.17.0 - 2.18.0: corrected bug which made unable the program to find CRC
85     C errors in the last section of the calorimeter;
86     C added a "debugging" option to dump to standard output
87     C the whole packet in hexadecimal format and other
88     C useful informations. To activate it the dump variable
89     C in the common varie must be passed with the value
90     C of iev you want to check. Do nothing if you don't want
91     C any output.
92 kusanagi 1.9 C
93 kusanagi 1.3 C------------------------------------------------
94 kusanagi 1.7 SUBROUTINE CALUNPACK(vecta,lung,me)
95 kusanagi 1.3 C------------------------------------------------
96    
97     IMPLICIT NONE
98     C
99 kusanagi 2.2 C PARAMETERS DEFINITION
100     C
101     C START = WHERE TO START TO LOOK FOR THE CALORIMETER, IN WORDS
102     C 1STSEC = MAXIMUM POSITION, IN BYTES, WHERE WE SUPPOSE TO FIND THE
103     C HEADER OF THE FIRST SECTION
104 kusanagi 1.3 C
105 kusanagi 2.2 INTEGER START, SEC1ST
106 kusanagi 1.3 INTEGER NPLA, NCHA, LENSEV
107 kusanagi 2.2 INTEGER*2 ival
108     C
109     PARAMETER (START=50,SEC1ST=1200)
110 kusanagi 1.3 PARAMETER (NPLA=22,NCHA=96,LENSEV=NPLA*NCHA)
111 kusanagi 2.2 PARAMETER (ival='FFFF'x)
112 kusanagi 1.3 C
113 kusanagi 2.2 C Normal variables definition
114 kusanagi 1.3 C
115 kusanagi 2.2 integer lung, SOGLIA0, SEC2ND
116 kusanagi 1.7 INTEGER*1 VECTA(lung)
117 kusanagi 1.9 INTEGER*2 vect(60000), test
118 kusanagi 1.6 integer*2 check, crc, e2(4)
119 kusanagi 2.2 INTEGER*2 length, length2
120     integer me, m, dumpo, finoa
121     INTEGER merror(4), headcor, ichc, coco
122 kusanagi 2.6 INTEGER i, j, iev, min, st2c, bit, bi, lleng
123 kusanagi 2.2 INTEGER ic, k,l, ke, ic0, icsave, chi
124     INTEGER hcchi(1000), hcic(1000),hcco
125     INTEGER contr, isfull, israw, iscomp
126     INTEGER inf, sup, em, icb
127 kusanagi 2.6 INTEGER XO, YO, XE, YE, icold
128 kusanagi 2.2 integer st1b, st2b, lunga, pari
129     integer stwerr(4),yescbra, chis, esci, icprima
130     integer seemcomp, seemfull, cberaw, yesisco, yesisfu,yesisra
131 kusanagi 2.5 integer ca50, ca50a, ca50b
132 kusanagi 2.2 C
133 kusanagi 1.3 real dedx1(11,96),dedx2(11,96),dedx3(11,96),dedx4(11,96)
134     real dedx1c(11,96),dedx2c(11,96),dedx3c(11,96),dedx4c(11,96)
135     real base1(11,6),base2(11,6),base3(11,6),base4(11,6)
136 kusanagi 2.2 REAL DEXY(2,NPLA,NCHA), dexyc(2,npla,ncha), base(2,npla,6)
137 kusanagi 1.3 real auto(7)
138 kusanagi 2.5 real calselftrig(4,7), calIItrig(4), calstriphit(4),
139 kusanagi 1.3 & calDSPtaberr(4), calevnum(4)
140 kusanagi 2.2 real perror(4)
141     C
142 kusanagi 2.5 DATA YE/246/ ! CODE_EV_R YE = 111 10110
143 kusanagi 1.3 DATA YO/237/ ! CODE_EV_R YO = 111 01101
144     DATA XE/234/ ! CODE_EV_R XE = 111 01010
145 kusanagi 2.5 DATA XO/241/ ! CODE_EV_R XO = 111 10001
146 kusanagi 2.2 C
147 kusanagi 2.6 COMMON / evento / iev, stwerr, perror,
148 kusanagi 1.3 & dexy,dexyc,base,
149     & calselftrig,calIItrig,
150 kusanagi 2.5 & calstriphit,calDSPtaberr,calevnum
151 kusanagi 1.3 save / evento /
152 kusanagi 2.2 C
153 kusanagi 2.8 COMMON / VARIE / dumpo, CONTR, merror
154 kusanagi 2.2 SAVE / VARIE /
155 kusanagi 1.3 C
156     C Begin !
157     C
158 kusanagi 2.2 SOGLIA0 = 70
159     C
160     C input length must be > 0, if not go out with error code 142
161     C
162 kusanagi 2.5 if (lung.le.0) then
163 kusanagi 2.2 if (dumpo.eq.iev) print *,'lung = ',lung
164     do i=1,4
165     merror(i)=142
166     enddo
167     goto 999
168     endif
169     C
170     C no debug informations
171     C
172 kusanagi 2.1 if (dumpo.eq.0) dumpo=-1
173 kusanagi 2.2 C
174     C DEBUG: PRINT OUT THE INPUT VECTOR
175     C
176 kusanagi 2.1 if (iev.eq.dumpo) then
177 kusanagi 1.9 do l=1,lung
178     write(*,17)l,vecta(l)
179     enddo
180     endif
181 kusanagi 2.2 C
182     C DETERMINE LENGTH IN WORDS FROM LENGTH IN BYTES
183     C
184 kusanagi 1.7 IF (MOD(LUNG,2).EQ.0) THEN
185     lunga = lung / 2
186     pari = 1
187     else
188     lunga = int(lung/2) + 1
189     endif
190 kusanagi 2.2 SEC2ND = LUNGA
191     C
192     C IS LENGTH IS TOO LONG?
193     C
194 kusanagi 2.1 if (lunga.gt.60000.and.dumpo.gt.0) then
195 kusanagi 1.9 print *,'Calorimeter WARNING: more than 60000 words!'
196     lunga = 60000
197 kusanagi 1.6 endif
198 kusanagi 2.2 C
199     C PRE-CLEAR VARIABLES
200     C
201     yesisco = 0
202     yesisfu = 0
203     yesisra = 0
204     yescbra = 0
205     C
206     1 CONTINUE
207 kusanagi 1.5 c
208 kusanagi 2.2 C CLEAR VARIABLES
209     C
210     if (iev.lt.0.or.iev.gt.90000000) iev = 0
211     esci = 0
212     chi = 0
213     chis = 0
214     min = 0
215     lleng = 0
216     m = 0
217     pari = 0
218     icb = 0
219     em = 0
220     coco = 0
221     me = 1
222     contr = 1
223     ic = 1
224     icsave = 0
225     C
226 kusanagi 2.5 call clearall
227 kusanagi 1.6 call azero(dedx1,11*96)
228     call azero(dedx2,11*96)
229     call azero(dedx3,11*96)
230     call azero(dedx4,11*96)
231     call azero(dedx1c,11*96)
232     call azero(dedx2c,11*96)
233     call azero(dedx3c,11*96)
234     call azero(dedx4c,11*96)
235     call azero(base1,11*6)
236     call azero(base2,11*6)
237     call azero(base3,11*6)
238     call azero(base4,11*6)
239     C
240 kusanagi 1.5 do l = 1,4
241 kusanagi 2.1 e2(l) = 0
242 kusanagi 1.8 perror(l) = 0.
243     stwerr(l) = 0
244 kusanagi 1.5 merror(l) = 0
245     enddo
246 kusanagi 2.2 C
247     C DETERMINE WHERE TO START TO FIND THE CALORIMETER IN THE INBUT BUFFER
248     C
249     length2 = start
250 kusanagi 1.3 c
251     20 continue
252 kusanagi 2.2 C
253 kusanagi 1.5 if (length2.ge.-2) then
254     ic = ic + (2 * (length2 + 2))
255     else
256 kusanagi 2.1 if (dumpo.gt.0)
257 kusanagi 2.2 & print *,'Calorimeter WARNING: length errors ',ic,length2
258 kusanagi 1.5 endif
259 kusanagi 2.2 C
260     headcor = 0
261     ichc = ic
262     icprima = ic
263     hcco = 0
264     do i=1,1000
265     hcchi(i) = 0
266     hcic(i) = 0
267     enddo
268 kusanagi 1.5 c
269     32 continue
270 kusanagi 2.2 C
271 kusanagi 1.3 ke = 0
272 kusanagi 2.2 chis = chi
273 kusanagi 2.1 icold = ic
274 kusanagi 2.7 DO i = 1, 60000
275     vect(i) = 0
276     enddo
277 kusanagi 1.3 do while (ke.eq.0)
278     C
279 kusanagi 2.2 C if (iev.eq.dumpo) print *,'parto da ',ic,contr
280     C
281 kusanagi 1.3 C Check consistency of header.
282     C it is composed by CODE+D# (8 bits) and by SATUS WORD (8 bits)
283     c so we must split vect into the two components:
284     C
285 kusanagi 1.5 st1b = 0
286     st2b = 0
287 kusanagi 2.2 C
288     C A CALORIMETER SECTION IS MADE OF AT LEAST 4 BYTES
289     C IF WE HAVE NO ROOM FOR A SECTION GO OUT
290     C
291     if ((ic+4).gt.lung.or.esci.eq.1) then
292     if (headcor.eq.1.and.contr.lt.5) then
293     headcor=-1
294     ic=ichc
295     goto 32
296     else
297     if (headcor.eq.0.or.headcor.eq.2) then
298     chi = chi + 8 * (5 - contr)
299     endif
300     merror(contr) = 129
301 kusanagi 2.7 stwerr(contr) = 0
302 kusanagi 2.6 if (iev.eq.dumpo) print *,'put to zero here ',headcor
303 kusanagi 2.2 if (esci.eq.0) then
304     ic = icsave
305     else
306     ic = icprima
307     endif
308     if (headcor.eq.2) then
309     chi = chis
310     endif
311     esci = 0
312     headcor = 0
313     hcco = 0
314     ichc = 0
315     do i=1,1000
316     hcchi(i) = 0
317     hcic(i) = 0
318     enddo
319     length2 = -2
320     lleng = 0
321     length = 0
322     goto 150
323     endif
324 kusanagi 1.7 endif
325 kusanagi 2.2 C
326     C ST1B IS "CODE", ST2B IS "D#"
327     C
328 kusanagi 1.5 do bit = 0, 7
329     bi = ibits(vecta(ic),bit,1)
330     if (bi.eq.1) st1b = ibset(st1b,bit)
331     bi = ibits(vecta(ic+1),bit,1)
332     if (bi.eq.1) st2b = ibset(st2b,bit)
333     enddo
334 kusanagi 1.6 c
335 kusanagi 2.2 C IC+2 AND IC+3 CONTAINS THE LENGTH OF THE CALORIMETER SECTION
336 kusanagi 1.6 c
337 kusanagi 1.5 length2 = 0
338     do bit=0, 7
339     bi = ibits(vecta(ic+3),bit,1)
340     if (bi.eq.1) length2 = ibset(length2,bit)
341     bi = ibits(vecta(ic+2),bit,1)
342     if (bi.eq.1) length2 = ibset(length2,bit+8)
343 kusanagi 2.5 enddo
344     C
345     C calorimeter signature in DSP mode (CA50 CA50):
346     C
347     ca50 = 0
348     if (ic+24.lt.lung) then
349     ca50a = 0
350     do bit=0, 7
351     bi = ibits(vecta(ic+23),bit,1)
352     if (bi.eq.1) ca50a = ibset(ca50a,bit)
353     bi = ibits(vecta(ic+22),bit,1)
354     if (bi.eq.1) ca50a = ibset(ca50a,bit+8)
355     enddo
356     ca50b = 0
357     do bit=0, 7
358     bi = ibits(vecta(ic+25),bit,1)
359     if (bi.eq.1) ca50b = ibset(ca50b,bit)
360     bi = ibits(vecta(ic+24),bit,1)
361     if (bi.eq.1) ca50b = ibset(ca50b,bit+8)
362     enddo
363     if (ca50a.eq.ca50b.and.ca50a.eq.51792) ca50 = 1
364     endif
365    
366 kusanagi 2.2 C
367 kusanagi 1.3 c the crc should be at vect(length) with
368 kusanagi 2.2 C
369 kusanagi 1.5 length = length2 + 1
370 kusanagi 1.3 C
371 kusanagi 2.2 c some checks to be sure we have found the calorimeter data:
372 kusanagi 1.3 c status word is always less then 129
373     c
374 kusanagi 1.5 if (st2b.gt.128) then
375     length = 0
376 kusanagi 2.2 length2 = 0
377 kusanagi 1.5 goto 100
378     endif
379 kusanagi 1.3 c
380 kusanagi 2.2 c length of the packet IN WORDS must be less then HALF OF THE
381     C LENGTH IN BYTES if noT THERE ARE SOME errors
382 kusanagi 1.3 c
383 kusanagi 2.2 bi = ibits(st2b,0,1)
384     if (length2.gt.lunga.OR.LENGTH2.LE.0) then
385     if (headcor.eq.2) then
386     chi = chi + 4
387     endif
388 kusanagi 1.5 length = 0
389 kusanagi 2.2 length2 = 0
390 kusanagi 1.5 goto 100
391     endif
392     c
393 kusanagi 1.3 e2(contr) = 0
394     C
395 kusanagi 2.2 if (CONTR.eq.1) then
396 kusanagi 1.3 c
397     c is it the first section?
398     c
399 kusanagi 2.5 if (st1b.eq.XE.and.(ca50.eq.1.or.length2.eq.1064)) then
400 kusanagi 1.3 c if so go out of this loop and go on recording data
401     ke = 1
402 kusanagi 2.2 icsave = ic
403     m = ic
404 kusanagi 2.7 if (iev.eq.dumpo) then
405     print *,'1m,lunga,lleng,lung,pari',m,lunga,lleng,lung,
406     & pari
407     endif
408 kusanagi 2.2 call fillin(m,lunga,lleng,lung,pari,vect,vecta)
409     C
410 kusanagi 1.5 icb = 1
411 kusanagi 2.2 E2(contr) = vect(icb)
412 kusanagi 2.7 if (iev.eq.dumpo) then
413     print *,'headcor ',headcor
414     write(*,22)vect(icb)
415     print *,'1m,lunga,lleng,lung,pari',m,lunga,lleng,lung,
416     & pari
417     endif
418 kusanagi 2.2 if (headcor.eq.2) then
419     if (coco.ne.1) then
420     coco = 1
421     else
422     coco = -1
423     endif
424     if (st2b.ne.0) then
425 kusanagi 2.5 call counter(e2(contr),chi)
426 kusanagi 2.2 endif
427 kusanagi 1.3 endif
428 kusanagi 2.2 goto 100
429 kusanagi 1.3 endif
430     ENDIF
431     C
432     c the same for the second section, ...
433     c
434     if (CONTR.eq.2) then
435 kusanagi 2.5 if (st1b.eq.XO.and.(ca50.eq.1.or.length2.eq.1064)) then
436 kusanagi 2.2 ke = 2
437     icsave = ic
438 kusanagi 1.5 m = ic
439 kusanagi 2.7 if (iev.eq.dumpo) then
440     print *,'2m,lunga,lleng,lung,pari',m,lunga,lleng,lung,
441     & pari
442     endif
443 kusanagi 2.2 call fillin(m,lunga,lleng,lung,pari,vect,vecta)
444 kusanagi 1.5 icb = 1
445 kusanagi 2.2 E2(contr) = vect(icb)
446 kusanagi 2.7 if (iev.eq.dumpo) then
447     print *,'headcor ',headcor
448     write(*,22)vect(icb)
449     print *,'2m,lunga,lleng,lung,pari',m,lunga,lleng,lung,
450     & pari
451     endif
452 kusanagi 2.2 if (headcor.eq.2) then
453     if (coco.ne.2) then
454     coco = 2
455     else
456     coco = -1
457     endif
458     if ((ic-icold).ne.0) chi=chi+abs(ic-icold)
459     if (st2b.ne.0) then
460 kusanagi 2.5 call counter(e2(contr),chi)
461 kusanagi 1.3 endif
462     endif
463 kusanagi 2.2 goto 100
464 kusanagi 1.3 endif
465     ENDIF
466     c
467     C ... for the third,...
468     c
469     if (CONTR.eq.3) then
470 kusanagi 2.5 if (st1b.eq.YE.and.(ca50.eq.1.or.length2.eq.1064)) then
471 kusanagi 2.2 ke = 3
472     icsave = ic
473     m = ic
474     if (iev.eq.dumpo) then
475 kusanagi 2.7 print *,'3m,lunga,lleng,lung,pari',m,lunga,lleng,lung,
476 kusanagi 2.2 & pari
477 kusanagi 1.3 endif
478 kusanagi 2.2 call fillin(m,lunga,lleng,lung,pari,vect,vecta)
479 kusanagi 1.5 icb = 1
480 kusanagi 2.2 E2(contr) = vect(icb)
481     if (iev.eq.dumpo) then
482     print *,'headcor ',headcor
483     write(*,22)vect(icb)
484 kusanagi 2.7 print *,'3m,lunga,lleng,lung,pari',m,lunga,lleng,lung,
485 kusanagi 2.2 & pari
486 kusanagi 1.3 endif
487 kusanagi 2.2 if (headcor.eq.2) then
488     if (coco.eq.3) then
489     coco = 3
490     else
491     coco = -1
492     endif
493     if (ic-icold.ne.0) chi = chi + abs(ic-icold)
494     if (st2b.ne.0) then
495 kusanagi 2.5 call counter(e2(contr),chi)
496 kusanagi 1.3 endif
497     endif
498 kusanagi 2.2 goto 100
499 kusanagi 1.3 endif
500     ENDIF
501     C
502     c ...and for the last section.
503     c
504     if (CONTR.eq.4) then
505 kusanagi 2.5 if (st1b.eq.YO.and.(ca50.eq.1.or.length2.eq.1064)) then
506 kusanagi 2.2 ke = 4
507     icsave = ic
508 kusanagi 1.5 m = ic
509 kusanagi 2.2 call fillin(m,lunga,lleng,lung,pari,vect,vecta)
510 kusanagi 1.5 icb = 1
511 kusanagi 2.2 E2(contr) = vect(icb)
512     if (headcor.eq.2) then
513     if (coco.eq.4) then
514     coco = 4
515     else
516     coco = -1
517     endif
518     if ((ic-icold).ne.0) chi = chi + abs(ic-icold)
519     if (st2b.ne.0) then
520 kusanagi 2.5 call counter(e2(contr),chi)
521 kusanagi 2.2 endif
522 kusanagi 1.3 endif
523 kusanagi 1.5 goto 100
524 kusanagi 1.3 endif
525     endif
526 kusanagi 2.2 C
527     if (contr.gt.4) then
528 kusanagi 2.6 if (iev.eq.dumpo) print *,'go out here'
529 kusanagi 2.2 headcor = 0
530     hcco = 0
531     ichc = 0
532     do i=1,1000
533     hcchi(i) = 0
534     hcic(i) = 0
535     enddo
536     goto 200
537     endif
538 kusanagi 1.3 C
539     100 CONTINUE
540     c
541     c increment vector of one searching for the next section
542     c
543     ic = ic + 1
544     c
545     enddo
546     C
547     c format not used
548     c
549 kusanagi 1.7 10 FORMAT(2X,'Error for view:',2X,I1,2X,'Status word:',2X,Z4)
550     11 FORMAT(2X,'View or command not recognized for view:',2X,I1,2X,
551     & 'Status word:',2X,Z4)
552     12 FORMAT(2X,'Error - did NOT find view:',2X,I1)
553     13 FORMAT(2X,'Error - eof reached, exiting')
554     14 FORMAT(2X,I8,2X,I10)
555     15 FORMAT(2X,I8,2X,Z8)
556 kusanagi 2.5 17 FORMAT(2X,'Element:',2X,I6,2X,' word:',2X,Z8)
557     18 FORMAT(2X,'Element:',2X,I6,2X,' word:',2X,Z2,Z2)
558 kusanagi 1.9 21 FORMAT(2X,'CRC: ',2X,Z8)
559 kusanagi 2.2 22 FORMAT(2X,'vect(icb): ',2X,Z8)
560 kusanagi 1.9 C
561 kusanagi 1.3 c go on recording data
562 kusanagi 1.7 ic = ic - 1
563 kusanagi 2.2 c
564 kusanagi 1.7 c
565     K = CONTR
566     ic0 = icb
567     icb = icb + 1
568     length = vect(icb) + 2
569     length2 = vect(icb)
570 kusanagi 1.8 lleng = (length*2) - 1
571 kusanagi 1.3 C
572 kusanagi 2.2 C Check consistency of CRCs.
573     C
574     C
575     C IF THE STATUS WORD HAS THE CRC BIT ON AND WE ARE NOT IN THE
576     C HEADCOR CASE 0 (WE WERE BELIEVING THE SECTION FOUND WAS FINE)
577     C
578     if ((ibits(e2(contr),0,1).ne.0.or.
579     & (ibits(e2(contr),3,1).eq.1.and.length2.ne.1064))
580     & .and.headcor.EQ.0) then
581     headcor = 1
582     ichc = ic - 1
583     if (iev.eq.dumpo) print *,'crc st word wrong',ic,ichc,headcor
584     endif
585     C
586     C HEADOCR = 1 MEANS SEARCH AGAIN FOR THAT SECTION
587 kusanagi 1.3 C
588 kusanagi 2.2 if (headcor.eq.1) then
589     hcco = hcco + 1
590     if (st2b.ne.0) then
591 kusanagi 2.5 call counter(e2(contr),hcchi(hcco))
592 kusanagi 2.2 endif
593     C
594     if (contr.gt.1.or.yesisco.ne.0.or.yesisfu.ne.0
595     & .or.yesisra.ne.0.or.yescbra.ne.0) then
596     iscomp = 0
597     isfull = 0
598     israw = 0
599     if (yesisco.ne.0.or.yesisfu.ne.0
600     & .or.yesisra.ne.0.or.yescbra.ne.0) then
601     if (yesisra.ne.0.or.yescbra.ne.0) israw = 2
602     if (yesisco.ne.0) iscomp = 2
603     if (yesisfu.ne.0) isfull = 2
604     else
605     i = 1
606     do while(iscomp.eq.0.and.isfull.eq.0.and.israw.eq.0.and.
607     & i.lt.(contr-1))
608     if (ibits(stwerr(i),16,1).eq.1) iscomp = iscomp + 1
609     if (ibits(stwerr(i),17,1).eq.1) isfull = isfull + 1
610     if (ibits(e2(i),3,1).eq.1.and.merror(i).eq.0)
611     & israw = israw + 1
612     i = i + 1
613     enddo
614     endif
615     c
616     c how does this section look like? (note that in case of crc errors
617     c this test has no value...)
618     c
619 kusanagi 2.5 test = vect(icb+12)
620 kusanagi 2.2 seemcomp = 0
621     seemfull = 0
622     if (test.eq.ival) then
623     seemcomp = 1
624     elseif (test.eq.0) then
625     seemfull = 1
626     endif
627     c
628     c if a previous good section was raw and this header we are analyzing
629     c is not raw something strange is happening, add a weight.
630     c
631     if ((israw.ne.0.and.ibits(e2(contr),3,1).ne.1)
632     & .or.(israw.ne.0.and.length2.ne.1064)) then
633     hcco = hcco - 1
634     length=0
635     length2=0
636     lleng=0
637     ic = ic + 1
638     if (iev.eq.dumpo)
639     & print *,'not raw, search again ',ic,ichc,headcor
640     goto 32
641     endif
642     c
643     c the same with compress and full mode
644     c
645     if ((iscomp.ne.0.or.isfull.ne.0)
646     & .and.ibits(e2(contr),3,1).eq.1) then
647     hcco = hcco - 1
648     length=0
649     length2=0
650     lleng=0
651     ic = ic + 1
652     if (iev.eq.dumpo)
653     & print *,'raw in full or compress mode, search again ',ic,ichc,
654     & headcor
655     goto 32
656     endif
657    
658     if (iscomp.ne.0.and.(ibits(e2(contr),3,1).eq.1.or.
659     & seemcomp.eq.0)) hcchi(hcco) = hcchi(hcco) + 2
660     if (isfull.ne.0.and.(ibits(e2(contr),3,1).eq.1.or.
661     & seemfull.eq.0)) hcchi(hcco) = hcchi(hcco) + 2
662     endif
663     C
664     if (ibits(e2(contr),3,1).eq.1.and.length2.eq.1064) then
665     hcchi(hcco) = hcchi(hcco) - 2
666     elseif ((ibits(e2(contr),3,1).eq.1.or.israw.ne.0)
667     & .and.length2.ne.1064) then
668     hcco = hcco - 1
669     length=0
670     length2=0
671     lleng=0
672     ic = ic + 1
673     if (iev.eq.dumpo)
674     & print *,'raw bit not raw length, search again ',ic,ichc,headcor
675     goto 32
676     endif
677     C
678     hcic(hcco) = ic
679     ic = ic + 1
680     length=0
681     length2=0
682     lleng=0
683     if (iev.eq.dumpo) print *,'search again ',ic,ichc,headcor
684     goto 32
685     endif
686     C
687     C HEADCOR = - 1 MEANS STOP SEARCHING FOR THAT SECTION, SELECT
688     C THE CASE WITH LESS ERRORS, FOUND THAT SECTION AND GIVE
689     C HEADCOR = 2 (I.E. GO OUT OF THE LOOP)
690     C
691     if (headcor.eq.-1) then
692 kusanagi 2.6 if (iev.eq.dumpo) print *,'enter -1, ',hcco,ke
693 kusanagi 2.2 headcor = 2
694     if (ke.le.2.and.hcco.ge.1) then
695     finoa = 0
696     do i = 1, hcco
697     if (ke.eq.1.and.hcic(i).lt.SEC1ST) finoa = i
698     if (ke.eq.2.and.hcic(i).lt.SEC2ND) finoa = i
699     enddo
700     if (finoa.eq.0) then
701     esci = 1
702     if (iev.eq.dumpo)
703     & print *,'finoa=0! no possible solutions '
704     else
705     if (iev.eq.dumpo) print *,'ke = ',ke,' and hcco>1 ',finoa
706     call minerr(ic,hcic,hcchi,min,finoa)
707     endif
708     else
709     if (hcco.eq.0) then
710     esci = 1
711     if (iev.eq.dumpo)
712     & print *,'hcco=0! no possible solutions'
713     else
714     call minerr(ic,hcic,hcchi,min,hcco)
715     endif
716     endif
717     e2(contr) = 0
718     if (iev.eq.dumpo) then
719     print *,'stop searching'
720     print *,'ic,hcic(min),min,... ',ic,hcic(min),min,
721     & hcchi(min),hcco,coco
722     do i=1,hcco
723     print *,'i, hcchi ',i,hcchi(i)
724     enddo
725     endif
726     c
727     length=0
728     length2=0
729     lleng=0
730 kusanagi 2.7 esci = 0
731     MERROR(contr) = 0
732 kusanagi 2.2 goto 32
733     endif
734     C
735     C determine the type of data if not raw (compress or full)
736     C
737     if (headcor.eq.0.or.headcor.eq.2
738     & .and.ibits(e2(contr),3,1).ne.1) then
739 kusanagi 2.5 test = vect(icb+12)
740 kusanagi 2.2 seemcomp = 0
741     seemfull = 0
742     if (test.eq.ival) then
743 kusanagi 2.5 C
744 kusanagi 2.2 C compress mode
745 kusanagi 2.5 C
746 kusanagi 2.2 stwerr(contr) = ibset(stwerr(contr),16)
747     elseif (test.eq.0) then
748     C
749 kusanagi 2.5 C full mode
750     C
751 kusanagi 2.2 stwerr(contr) = ibset(stwerr(contr),17)
752     endif
753     endif
754     C
755     hcco = 0
756     ichc = 0
757 kusanagi 2.1 check = 0
758 kusanagi 2.2 do i=1,1000
759     hcchi(i) = 0
760     hcic(i) = 0
761     enddo
762 kusanagi 1.7 inf = ic0
763     sup = length - 1
764     do i = inf,sup
765     check=crc(check,vect(i))
766     enddo
767 kusanagi 2.2 C
768 kusanagi 2.7 if (iev.eq.dumpo) then
769     write(*,21)vect(length)
770     print *,' CRC position ',length
771     write(*,21)check
772     endif
773 kusanagi 2.2 C
774 kusanagi 1.7 if (check.ne.vect(length)) then
775     merror(contr) = 132
776 kusanagi 2.2 chi = chi + 4
777 kusanagi 1.7 lleng = 0
778 kusanagi 2.2 length2 = 0
779     length = 0
780 kusanagi 2.5 C
781     C clear vectors of that section in the common
782     C
783     call clearsec
784     C
785 kusanagi 2.2 if (ke.eq.1.and.headcor.ne.2) then
786     ic = 10
787     elseif (headcor.eq.2) then
788     contr = contr + 1
789 kusanagi 1.8 endif
790 kusanagi 2.2 headcor = 1
791     ichc = ic - 1
792     if (iev.eq.dumpo)
793 kusanagi 2.6 & print *,'crc is wrong ',ic,
794     & ' search section ',contr,' coco = ',coco
795 kusanagi 2.2 goto 32
796     else
797     chi = chi - 4
798     if (chi.lt.0) chi = 0
799 kusanagi 1.7 endif
800 kusanagi 2.2 C
801     headcor = 0
802 kusanagi 1.3 C
803 kusanagi 1.8 19 CONTINUE
804 kusanagi 2.2 C
805     C Process data.
806     C
807 kusanagi 2.5 call clearsec
808 kusanagi 2.2 do i = 1, 7
809     icb = icb + 1
810     auto(i) = vect(icb)
811     enddo
812     C
813     st2c = 0
814     if (st2b.ne.0) then
815     do bit=0, 6
816     bi = ibits(st2b,bit,1)
817     if (bit.eq.3.and.bi.ne.0) st2c = 8
818 kusanagi 1.3 enddo
819 kusanagi 2.2 endif
820 kusanagi 1.7 C
821 kusanagi 2.2 if (st2c.eq.8) then
822     if (length2.ne.1064) then
823     merror(contr) = 133
824     chi = chi + 4
825     if (iev.eq.dumpo)
826     & print *,'raw lung 4'
827     lleng = 0
828     goto 150
829     else
830 kusanagi 2.5 if (k.eq.1) call CALRAW(vect,icb+1,length-1,dedx1)
831 kusanagi 2.2 if (k.eq.2) call CALRAW(vect,icb+1,length-1,dedx2)
832     if (k.eq.3) call CALRAW(vect,icb+1,length-1,dedx3)
833     if (k.eq.4) call CALRAW(vect,icb+1,length-1,dedx4)
834 kusanagi 1.5 endif
835 kusanagi 2.2 goto 50
836     endif
837 kusanagi 1.7 C
838 kusanagi 2.2 41 FORMAT(2X,I2,2X,'word :',1x,z4)
839 kusanagi 2.5 test = vect(icb+5)
840 kusanagi 2.2 c
841     if (test.eq.ival) then
842     if (length2.gt.1201) then
843     merror(contr) = 134
844     chi = chi + 4
845     if (iev.eq.dumpo)
846     & print *,'compr lung 4'
847     lleng = 0
848     goto 150
849     else
850     icb = icb + 1
851     calIItrig(k) = vect(icb)
852     icb = icb + 1
853 kusanagi 2.5 calstriphit(k) = vect(icb)
854     icb = icb + 1
855     C FIRST CALORIMETER SIGNATURE: CA50
856 kusanagi 2.2 icb = icb + 1
857 kusanagi 2.5 C SECOND CALORIMETER SIGNATURE: CA50
858     icb = icb + 1
859     C test is here!
860 kusanagi 2.2 icb = icb + 1
861     calDSPtaberr(k) = vect(icb)
862     icb = icb + 1
863     calevnum(k) = vect(icb)
864 kusanagi 2.5 if (k.eq.1) call CALCOMPRESS(vect,icb+1,length-1,dedx1c,
865     & base1)
866 kusanagi 2.2 if (k.eq.2) call CALCOMPRESS(vect,icb+1,length-1,dedx2c,
867     & base2)
868     if (k.eq.3) call CALCOMPRESS(vect,icb+1,length-1,dedx3c,
869     & base3)
870     if (k.eq.4) call CALCOMPRESS(vect,icb+1,length-1,dedx4c,
871     & base4)
872 kusanagi 1.5 goto 50
873 kusanagi 1.3 endif
874 kusanagi 2.2 else if (test.eq.0) then
875     if (length2.gt.2257) then
876     merror(contr) = 135
877     chi = chi + 4
878     if (iev.eq.dumpo)
879     & print *,'full lung 4'
880     lleng = 0
881     goto 150
882     else
883     icb = icb + 1
884     calIItrig(k) = vect(icb)
885     icb = icb + 1
886 kusanagi 2.5 calstriphit(k) = vect(icb)
887     icb = icb + 1
888     C FIRST CALORIMETER SIGNATURE: CA50
889 kusanagi 2.2 icb = icb + 1
890 kusanagi 2.5 C SECOND CALORIMETER SIGNATURE: CA50
891     icb = icb + 1
892     C test is here!
893 kusanagi 2.2 icb = icb + 1
894     calDSPtaberr(k) = vect(icb)
895     icb = icb + 1
896     calevnum(k) = vect(icb)
897 kusanagi 2.5 if (k.eq.1) call CALFULL(vect,icb+1,length-1,dedx1,
898     & dedx1c,base1)
899 kusanagi 2.2 if (k.eq.2) call CALFULL(vect,icb+1,length-1,dedx2,
900     & dedx2c,base2)
901     if (k.eq.3) call CALFULL(vect,icb+1,length-1,dedx3,
902     & dedx3c,base3)
903     if (k.eq.4) call CALFULL(vect,icb+1,length-1,dedx4,
904     & dedx4c,base4)
905     goto 50
906 kusanagi 1.3 endif
907 kusanagi 2.2 else
908     merror(contr) = 136
909     chi = chi + 4
910     if (iev.eq.dumpo)
911     & print *,'decoding problems 4'
912     lleng = 0
913     goto 150
914     endif
915 kusanagi 2.1 c
916 kusanagi 2.2 50 continue
917 kusanagi 2.1 c
918 kusanagi 1.7 C
919 kusanagi 2.2 do i = 1,7
920     calselftrig(k,i) = auto(i)
921     enddo
922     C
923     DO I = 1,11
924     DO J = 1,96
925 kusanagi 2.9 DEXY(2,2*I,J) = DEDX2(I,J)
926 kusanagi 2.5 DEXY(1,2*I-1,J) = DEDX4(I,J)
927 kusanagi 2.9 DEXY(2,2*I-1,97-J) = DEDX1(I,J)
928 kusanagi 2.5 DEXY(1,2*I,J) = DEDX3(I,J)
929 kusanagi 2.9 DEXYC(2,2*I,J) = DEDX2C(I,J)
930 kusanagi 2.5 DEXYC(1,2*I-1,J) = DEDX4C(I,J)
931 kusanagi 2.9 DEXYC(2,2*I-1,97-J) = DEDX1C(I,J)
932 kusanagi 2.5 DEXYC(1,2*I,J) = DEDX3C(I,J)
933 kusanagi 1.3 enddo
934 kusanagi 2.2 do j = 1,6
935 kusanagi 2.9 base(2,2*i,j) = base2(i,j)
936 kusanagi 2.5 base(1,2*i-1,j) = base4(i,j)
937 kusanagi 2.9 base(2,2*i-1,7-j) = base1(i,j)
938 kusanagi 2.5 base(1,2*i,j) = base3(i,j)
939 kusanagi 1.3 enddo
940 kusanagi 2.2 enddo
941 kusanagi 1.3 C
942     150 continue
943     C
944     contr = contr + 1
945     C
946     c go on till we have found all the four sections
947     c
948 kusanagi 1.5 if (contr.lt.5) goto 20
949 kusanagi 1.3 c
950 kusanagi 1.8 200 continue
951     C
952 kusanagi 2.2 iscomp = 0
953     isfull = 0
954     israw = 0
955     do i = 1, 4
956     if (ibits(stwerr(i),16,1).eq.1) iscomp = iscomp + 1
957     if (ibits(stwerr(i),17,1).eq.1) isfull = isfull + 1
958     if (ibits(e2(i),3,1).eq.1) israw = israw + 1
959     enddo
960     if (iscomp.ne.0) chi = chi + 8 * (4 - iscomp)
961     if (israw.ne.0) chi = chi + 8 * (4 - israw)
962     if (isfull.ne.0) chi = chi + 8 * (4 - isfull)
963     C
964     C if chi>10 and we have information enough to understand the physic event
965     C was acquired in a certain mode (RAW, FULL or COMPRESS) then reprocess
966     C the event using this information, sometimes we miss a section due to
967     C CRC errors in the previous one but if we know what we are looking for
968     C then it is possible to save this kind of events.
969     C
970     if (chi.gt.5.and.yesisco.eq.0.and.yesisfu.eq.0
971     & .and.yesisra.eq.0.and.yescbra.eq.0) then
972     israw = 0
973     cberaw = 0
974     do i = 1, 4
975     if (ibits(e2(i),3,1).eq.1.and.merror(i).eq.0)
976     & israw = israw + 1
977     if (ibits(e2(i),3,1).eq.1.and.merror(i).eq.132)
978     & cberaw = cberaw + 1
979     enddo
980     yesisco = 0
981     yesisfu = 0
982     yesisra = 0
983     yescbra = 0
984     if (iscomp.ne.0) yesisco = 1
985     if (isfull.ne.0) yesisfu = 1
986     if (israw.ne.0) yesisra = 1
987     if (cberaw.ne.0) yescbra = 1
988     if ((yesisco+yesisfu+yesisra).eq.1.or.
989     & ((yesisco+yesisfu+yesisra).eq.0.and.yescbra.eq.1)) then
990     if (iev.eq.dumpo) then
991     print *,'************************'
992     if (iscomp.ne.0) print *,'is a compress acq.'
993     if (isfull.ne.0) print *,'is a full acq.'
994     if (israw.ne.0) print *,'is a raw acq.'
995     if (israw.eq.0.and.cberaw.ne.0)
996     & print *,'could be a raw acq.'
997     print *,'so, SGARBUF, do it again! ',chi
998     print *,'************************'
999 kusanagi 1.8 endif
1000 kusanagi 2.2 SOGLIA0 = SOGLIA0 - ISCOMP - ISFULL - ISRAW
1001     goto 1
1002 kusanagi 1.8 endif
1003 kusanagi 2.2 if ((yesisco+yesisfu+yesisra+yescbra).eq.0) chi = 1000
1004 kusanagi 1.8 endif
1005 kusanagi 2.2 C
1006     if (iev.eq.dumpo)
1007     & print *,'chi <= soglia0 ?',chi,soglia0
1008     if (chi.lt.soglia0) then
1009     me = 0
1010     else
1011     me = 1
1012     do i = 1, 4
1013     merror(i) = 129
1014     e2(i) = 0
1015 kusanagi 2.5 stwerr(i) = 0
1016 kusanagi 2.1 enddo
1017 kusanagi 2.5 call clearall
1018 kusanagi 2.2 goto 999
1019 kusanagi 1.8 endif
1020 kusanagi 1.3 C
1021     C if all section are missing clear vectors and go out
1022     C
1023     if (merror(1).eq.129.and.merror(2).eq.129
1024 kusanagi 2.2 & .and.merror(3).eq.129.and.merror(4).eq.129) then
1025 kusanagi 1.3 do l = 1,4
1026     e2(l) = 0
1027 kusanagi 2.4 stwerr(l) = 0
1028 kusanagi 1.3 enddo
1029 kusanagi 2.5 call clearall
1030 kusanagi 1.3 endif
1031     c
1032     999 continue
1033 kusanagi 2.1 c
1034 kusanagi 1.8 do l = 1, 4
1035     do bit=0, 31
1036     if (bit.lt.16) then
1037     bi = ibits(E2(L),bit,1)
1038 kusanagi 2.2 elseif (bit.gt.17) then
1039 kusanagi 1.8 bi = 0
1040 kusanagi 2.2 elseif (bit.ge.16.and.bit.le.17) then
1041     bi = 2
1042 kusanagi 1.8 endif
1043 kusanagi 2.1 if (bi.eq.1) then
1044     stwerr(l) = ibset(stwerr(l),bit)
1045 kusanagi 2.2 elseif (bi.eq.0) then
1046 kusanagi 2.1 stwerr(l) = ibclr(stwerr(l),bit)
1047     endif
1048 kusanagi 1.8 enddo
1049     perror(l) = float(merror(l))
1050 kusanagi 1.7 enddo
1051 kusanagi 2.1 c
1052 kusanagi 1.8 iev = iev + 1
1053 kusanagi 1.3 RETURN
1054     END
1055    
1056    
1057     C------------------------------------------------
1058     SUBROUTINE CALRAW(vect,inf,sup,dedx)
1059     C------------------------------------------------
1060    
1061     IMPLICIT NONE
1062 kusanagi 2.2 C
1063     INTEGER NPLA, NCHA, LENSEV
1064     PARAMETER (NPLA=22,NCHA=96,LENSEV=NPLA*NCHA)
1065     C
1066 kusanagi 1.7 INTEGER*2 VECT(30000)
1067 kusanagi 1.3 INTEGER inf, sup
1068 kusanagi 2.6 INTEGER i,j,k, iev
1069 kusanagi 2.2 INTEGER contr
1070 kusanagi 2.8 integer stwerr(4), dumpo, merror(4)
1071 kusanagi 1.3 C
1072 kusanagi 2.2 REAL DEXY(2,NPLA,NCHA), dexyc(2,npla,ncha), base(2,npla,6)
1073 kusanagi 2.5 real calselftrig(4,7), calIItrig(4), calstriphit(4),
1074 kusanagi 1.3 & calDSPtaberr(4), calevnum(4)
1075     REAL dedx(11,96)
1076 kusanagi 2.6 real perror(4)
1077 kusanagi 2.2 C
1078 kusanagi 2.6 COMMON / evento / iev, stwerr, perror,
1079 kusanagi 1.3 & dexy,dexyc,base,
1080     & calselftrig,calIItrig,
1081 kusanagi 2.5 & calstriphit,calDSPtaberr,calevnum
1082 kusanagi 1.3
1083     save / evento /
1084     c
1085 kusanagi 2.8 COMMON / VARIE / dumpo, CONTR, merror
1086 kusanagi 1.3 SAVE / VARIE /
1087 kusanagi 2.2 c
1088 kusanagi 1.3 k = inf
1089     do j = 1,96
1090     do i = 1,11
1091 kusanagi 2.2 DEDX(I,J) = 0.
1092 kusanagi 1.3 dedx(i,j) = vect(k)
1093     k = k + 1
1094     enddo
1095     enddo
1096     c
1097     RETURN
1098     END
1099    
1100     C------------------------------------------------
1101     SUBROUTINE CALCOMPRESS(vect,inf,sup,dedx,basse)
1102     C------------------------------------------------
1103    
1104     IMPLICIT NONE
1105    
1106 kusanagi 2.2 INTEGER NPLA, NCHA, LENSEV
1107     PARAMETER (NPLA=22,NCHA=96,LENSEV=NPLA*NCHA)
1108 kusanagi 1.3 C
1109 kusanagi 2.2 INTEGER*2 VECT(30000)
1110     INTEGER*2 st, st1, st2
1111 kusanagi 1.3 INTEGER inf, sup
1112 kusanagi 2.6 INTEGER i,j, iev
1113 kusanagi 1.3 INTEGER ib
1114     INTEGER ipl, ipr, ist
1115     INTEGER merror(4)
1116     INTEGER contr
1117 kusanagi 2.2 integer stwerr(4),dumpo
1118 kusanagi 2.8 integer bit,bi
1119 kusanagi 2.2 C
1120     REAL DEXY(2,NPLA,NCHA), dexyc(2,npla,ncha), base(2,npla,6)
1121 kusanagi 2.5 real calselftrig(4,7), calIItrig(4), calstriphit(4),
1122 kusanagi 1.3 & calDSPtaberr(4), calevnum(4)
1123     REAL dedx(11,96), basse(11,6)
1124 kusanagi 2.6 real perror(4)
1125 kusanagi 1.3 C
1126 kusanagi 1.8 COMMON / evento / IEV, stwerr,perror,
1127 kusanagi 1.3 & dexy,dexyc,base,
1128     & calselftrig,calIItrig,
1129 kusanagi 2.5 & calstriphit,calDSPtaberr,calevnum
1130 kusanagi 1.3
1131     save / evento /
1132     c
1133 kusanagi 2.8 COMMON / VARIE / dumpo, CONTR, merror
1134 kusanagi 1.3 SAVE / VARIE /
1135    
1136     C
1137     DO I = 1,11
1138     DO J = 1,96
1139 kusanagi 2.2 if (j.le.6) basse(i,j) = 0.
1140 kusanagi 1.3 DEDX(I,J) = 0.
1141     ENDDO
1142     ENDDO
1143     C
1144 kusanagi 1.5 i = inf
1145     c
1146 kusanagi 1.3 10 continue
1147 kusanagi 1.6 if (i.gt.sup) then
1148     RETURN
1149     endif
1150 kusanagi 1.3 C
1151     40 format(2x,i5,2x,'status :',1x,Z4)
1152 kusanagi 1.5 C
1153     c
1154     st1 = 0
1155 kusanagi 2.8 c st1 = IAND(vect(i),'0800'x)
1156     c st1 = ISHFT(st1,-11)
1157     do bit=0, 7
1158     bi = ibits(vect(i),bit+8,1)
1159     if (bi.eq.1) st1 = ibset(st1,bit)
1160     enddo
1161     43 format(2x,'vect(i) = ',Z8)
1162     if (st1.eq.8) then
1163 kusanagi 1.3 ib = 1
1164     else
1165 kusanagi 2.8 c st2 = IAND(vect(i),'1000'x)
1166     c st2 = ISHFT(st2,-12)
1167     if (st1.eq.16) then
1168 kusanagi 1.3 ib = 0
1169     else
1170 kusanagi 2.1 if (iev.eq.dumpo) then
1171 kusanagi 1.9 print *,'i ',i
1172     write(*,43)vect(i)
1173     endif
1174 kusanagi 1.5 merror(contr) = 139
1175 kusanagi 1.3 RETURN
1176     endif
1177     endif
1178     C
1179     if (ib.eq.1) then
1180 kusanagi 1.6 C
1181 kusanagi 1.3 st = IAND(vect(i),'00FF'x)
1182 kusanagi 1.5 c
1183 kusanagi 1.3 ipl = int(st/6) + 1
1184 kusanagi 1.5 ipr = st - (ipl - 1) * 6 + 1
1185 kusanagi 1.3 i = i + 1
1186 kusanagi 1.6 if (i.gt.sup) RETURN
1187 kusanagi 1.3 basse(ipl,ipr) = vect(i)
1188 kusanagi 1.6 c
1189 kusanagi 1.3 20 continue
1190     if (i.gt.sup) RETURN
1191     C
1192     i = i + 1
1193 kusanagi 1.6 if (i.gt.sup) RETURN
1194     if ((vect(i)+1).gt.16.or.(vect(i)+1).lt.1) then
1195 kusanagi 2.8
1196 kusanagi 1.6 goto 10
1197     endif
1198     ist = vect(i) + 1 + 16 * (ipr - 1)
1199 kusanagi 1.3 i = i + 1
1200 kusanagi 1.6 if (i.gt.sup) RETURN
1201 kusanagi 1.5 dedx(ipl,ist) = vect(i)
1202 kusanagi 1.6 goto 20
1203 kusanagi 1.3 else
1204     C
1205     st = IAND(vect(i),'00FF'x)
1206 kusanagi 1.6 ipl = int(st/6) + 1
1207 kusanagi 1.5 ipr = st - (ipl - 1) * 6 + 1
1208 kusanagi 1.3 do j = 1,16
1209     i = i + 1
1210 kusanagi 1.6 if (i.gt.sup) RETURN
1211     ist = j + 16 * (ipr - 1)
1212     dedx(ipl,ist) = vect(i)
1213 kusanagi 1.3 enddo
1214 kusanagi 1.6 i = i + 1
1215     if (i.gt.sup) RETURN
1216 kusanagi 1.3 goto 10
1217     C
1218     endif
1219    
1220    
1221     RETURN
1222     END
1223    
1224    
1225 kusanagi 1.5 C----------------------------------------------------------
1226 kusanagi 1.3 SUBROUTINE CALFULL(vect,inf,sup,dedx,dedxc,basse)
1227 kusanagi 1.5 C--------------------------------------------------------------
1228 kusanagi 1.3
1229     IMPLICIT NONE
1230    
1231 kusanagi 2.2 INTEGER NPLA, NCHA, LENSEV
1232     PARAMETER (NPLA=22,NCHA=96,LENSEV=NPLA*NCHA)
1233     C
1234 kusanagi 1.7 INTEGER*2 VECT(30000)
1235 kusanagi 1.3 INTEGER inf, sup
1236 kusanagi 2.6 INTEGER i,j,k, iev
1237 kusanagi 2.2 INTEGER contr
1238 kusanagi 2.8 integer stwerr(4),dumpo,merror(4)
1239 kusanagi 1.3 C
1240 kusanagi 2.2 REAL DEXY(2,NPLA,NCHA), dexyc(2,npla,ncha), base(2,npla,6)
1241 kusanagi 2.5 real calselftrig(4,7), calIItrig(4), calstriphit(4),
1242 kusanagi 1.3 & calDSPtaberr(4), calevnum(4)
1243     REAL dedx(11,96), basse(11,6), dedxc(11,96)
1244 kusanagi 2.6 real perror(4)
1245 kusanagi 2.2 C
1246 kusanagi 2.6 COMMON / evento / iev, stwerr,perror,
1247 kusanagi 1.3 & dexy,dexyc,base,
1248     & calselftrig,calIItrig,
1249 kusanagi 2.5 & calstriphit,calDSPtaberr,calevnum
1250 kusanagi 1.3
1251     save / evento /
1252     c
1253 kusanagi 2.8 COMMON / VARIE / dumpo, CONTR, merror
1254 kusanagi 1.3 SAVE / VARIE /
1255     C
1256 kusanagi 1.6 k = inf
1257 kusanagi 1.3 do i = 1,11
1258     do j = 1,96
1259 kusanagi 2.2 DEDX(I,J) = 0.
1260 kusanagi 1.3 dedx(i,j) = vect(k)
1261     k = k + 1
1262     enddo
1263     enddo
1264     C
1265     call CALCOMPRESS(vect,k,sup,dedxc,basse)
1266 kusanagi 1.6 C
1267     10 FORMAT(2X,'Status word:',2X,Z8)
1268 kusanagi 1.3
1269     RETURN
1270     END
1271    
1272    
1273     C------------------------------------------------
1274 kusanagi 2.5 SUBROUTINE COUNTER(ve,er)
1275 kusanagi 1.3 C------------------------------------------------
1276    
1277     IMPLICIT NONE
1278    
1279     INTEGER NPLA, NCHA, LENSEV
1280     PARAMETER (NPLA=22,NCHA=96,LENSEV=NPLA*NCHA)
1281 kusanagi 2.2 C
1282     INTEGER*2 VE, st4
1283 kusanagi 2.6 INTEGER er, bit, bi, iev
1284 kusanagi 1.3 INTEGER contr
1285 kusanagi 2.8 integer stwerr(4),dumpo, merror(4)
1286 kusanagi 2.2 C
1287     REAL DEXY(2,NPLA,NCHA), dexyc(2,npla,ncha), base(2,npla,6)
1288 kusanagi 2.5 real calselftrig(4,7), calIItrig(4), calstriphit(4),
1289 kusanagi 2.2 & calDSPtaberr(4), calevnum(4)
1290 kusanagi 2.6 real perror(4)
1291 kusanagi 2.2 C
1292 kusanagi 1.8 COMMON / evento / IEV, stwerr,perror,
1293 kusanagi 1.3 & dexy,dexyc,base,
1294     & calselftrig,calIItrig,
1295 kusanagi 2.5 & calstriphit,calDSPtaberr,calevnum
1296 kusanagi 1.3
1297     save / evento /
1298    
1299 kusanagi 2.8 COMMON / VARIE / dumpo, CONTR, merror
1300 kusanagi 1.3 SAVE / VARIE /
1301    
1302    
1303     st4 = 0
1304     st4 = IAND(ve,'00FF'x)
1305     if (st4.ne.0) then
1306     do bit=0, 6
1307     bi = ibits(st4,bit,1)
1308     if (bi.ne.0) then
1309 kusanagi 2.2 er = er + 2
1310 kusanagi 1.3 endif
1311     enddo
1312     endif
1313    
1314     10 FORMAT(2X,'Status word:',2X,Z4)
1315     return
1316     end
1317    
1318    
1319     C------------------------------------------------
1320     SUBROUTINE MINERR(ic,icsave,chi,min,co)
1321     C------------------------------------------------
1322    
1323     IMPLICIT NONE
1324     C
1325 kusanagi 2.2 INTEGER NPLA, NCHA, LENSEV
1326     PARAMETER (NPLA=22,NCHA=96,LENSEV=NPLA*NCHA)
1327     C
1328 kusanagi 1.3 INTEGER ic, icsave(1000), chi(1000)
1329     integer l, st, min,co
1330 kusanagi 2.6 INTEGER iev
1331 kusanagi 2.2 INTEGER contr
1332 kusanagi 2.8 integer stwerr(4),dumpo, merror(4)
1333 kusanagi 1.3 C
1334 kusanagi 2.2 REAL DEXY(2,NPLA,NCHA), dexyc(2,npla,ncha), base(2,npla,6)
1335 kusanagi 2.5 real calselftrig(4,7), calIItrig(4), calstriphit(4),
1336 kusanagi 2.2 & calDSPtaberr(4), calevnum(4)
1337 kusanagi 2.6 real perror(4)
1338 kusanagi 2.2 C
1339 kusanagi 2.6 COMMON / evento / iev, stwerr,perror,
1340 kusanagi 1.3 & dexy,dexyc,base,
1341     & calselftrig,calIItrig,
1342 kusanagi 2.5 & calstriphit,calDSPtaberr,calevnum
1343 kusanagi 1.3
1344     save / evento /
1345 kusanagi 2.6 C
1346 kusanagi 2.8 COMMON / VARIE / dumpo, CONTR, merror
1347 kusanagi 1.3 SAVE / VARIE /
1348    
1349     st = chi(1)
1350     min = 1
1351     if (co.gt.1) then
1352     do l = 2, co
1353     if (chi(l).lt.st) then
1354     st = chi(l)
1355     min = l
1356     endif
1357     enddo
1358     endif
1359     ic = icsave(min)
1360    
1361     return
1362     end
1363 kusanagi 1.7
1364     C-----------------------------------------------------
1365 kusanagi 2.5 SUBROUTINE CLEARSEC
1366 kusanagi 1.7 C-----------------------------------------------------
1367    
1368     IMPLICIT NONE
1369     C
1370     INTEGER NPLA, NCHA, LENSEV
1371     PARAMETER (NPLA=22,NCHA=96,LENSEV=NPLA*NCHA)
1372 kusanagi 2.2 C
1373 kusanagi 2.6 INTEGER iev
1374 kusanagi 2.5 INTEGER contr, i,j
1375 kusanagi 2.8 integer stwerr(4),dumpo, merror(4)
1376 kusanagi 2.2 C
1377     REAL DEXY(2,NPLA,NCHA), dexyc(2,npla,ncha), base(2,npla,6)
1378 kusanagi 2.5 real calselftrig(4,7), calIItrig(4), calstriphit(4),
1379 kusanagi 1.7 & calDSPtaberr(4), calevnum(4)
1380 kusanagi 2.6 real perror(4)
1381 kusanagi 2.2 C
1382 kusanagi 2.6 COMMON / evento / iev, stwerr,perror,
1383 kusanagi 1.7 & dexy,dexyc,base,
1384     & calselftrig,calIItrig,
1385 kusanagi 2.5 & calstriphit,calDSPtaberr,calevnum
1386 kusanagi 1.7
1387     save / evento /
1388     c
1389 kusanagi 2.8 COMMON / VARIE / dumpo, CONTR, merror
1390 kusanagi 2.5 SAVE / VARIE /
1391 kusanagi 1.7 C
1392 kusanagi 2.5 DO I = 1,11
1393     DO J = 1,96
1394     if (contr.eq.1) then
1395     DEXY(1,2*I,J) = 0.
1396     DEXYC(1,2*I,J) = 0.
1397     endif
1398     if (contr.eq.2) then
1399     DEXY(1,2*I-1,J) = 0.
1400     DEXYC(1,2*I-1,J) = 0.
1401     endif
1402     if (contr.eq.3) then
1403     DEXY(2,2*I-1,97-J) = 0.
1404     DEXYC(2,2*I-1,97-J) = 0.
1405     endif
1406     if (contr.eq.4) then
1407     DEXY(2,2*I,J) = 0.
1408     DEXYC(2,2*I,J) = 0.
1409     endif
1410     enddo
1411     do j = 1,6
1412     if (contr.eq.3) base(2,2*i-1,7-j) = 0.
1413     if (contr.eq.2) base(1,2*i-1,j) = 0.
1414     if (contr.eq.4) base(2,2*i,j) = 0.
1415     if (contr.eq.1) base(1,2*i,j) = 0.
1416     enddo
1417     if (i.le.7) calselftrig(contr,i) = 0.
1418     enddo
1419     calIItrig(contr) = 0.
1420     calstriphit(contr) = 0.
1421     calDSPtaberr(contr) = 0.
1422     calevnum(contr) = 0.
1423     return
1424 kusanagi 1.7 end
1425 kusanagi 2.5 C

  ViewVC Help
Powered by ViewVC 1.1.23