/[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.4 - (hide annotations) (download)
Mon Oct 18 13:58:57 2004 UTC (20 years, 1 month ago) by kusanagi
Branch: MAIN
Changes since 2.3: +8 -7 lines
update by Emiliano

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

  ViewVC Help
Powered by ViewVC 1.1.23