/[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.7 - (hide annotations) (download)
Fri Dec 17 12:46:21 2004 UTC (20 years ago) by kusanagi
Branch: MAIN
Changes since 2.6: +38 -5 lines
*** empty log message ***

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

  ViewVC Help
Powered by ViewVC 1.1.23