]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/PHSGAINda.cxx
Absolute DCA cut in xy-plane.
[u/mrichter/AliRoot.git] / PHOS / PHSGAINda.cxx
1 /*
2 contact: Boris.Polishchuk@cern.ch
3 link: see comments in the $ALICE_ROOT/PHOS/AliPHOSRcuDA1.cxx
4 reference run: /castor/cern.ch/alice/phos/2007/10/04/18/07000008249001.1000.root
5 run type: PHYSICS, STANDALONE
6 DA type: MON 
7 number of events needed: 1000
8 input files: RCU0.data  RCU1.data  RCU2.data  RCU3.data
9 Output files: PHOS_Module2_Calib.root
10 trigger types used: L0
11 */
12
13
14 #include "event.h"
15 #include "monitor.h"
16 extern "C" {
17 #include "daqDA.h"
18 }
19
20 #include <stdio.h>
21 #include <stdlib.h>
22
23 #include <TSystem.h>
24
25 #include "AliRawReader.h"
26 #include "AliRawReaderDate.h"
27 #include "AliPHOSRcuDA1.h"
28 #include "AliPHOSRawDecoder.h"
29 #include "AliCaloAltroMapping.h"
30
31
32 /* Main routine
33       Arguments: 
34       1- monitoring data source
35 */
36 int main(int argc, char **argv) {
37
38   int status;
39   
40   if (argc!=2) {
41     printf("Wrong number of arguments\n");
42     return -1;
43   }
44   
45   /* Open mapping files */
46   AliAltroMapping *mapping[4];
47   TString path = "./";
48   path += "RCU";
49   TString path2;
50   for(Int_t i = 0; i < 4; i++) {
51     path2 = path;
52     path2 += i;
53     path2 += ".data";
54     mapping[i] = new AliCaloAltroMapping(path2.Data());
55   }
56   
57
58   /* define data source : this is argument 1 */  
59   status=monitorSetDataSource( argv[1] );
60   if (status!=0) {
61     printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
62     return -1;
63   }
64
65
66   /* declare monitoring program */
67   status=monitorDeclareMp( __FILE__ );
68   if (status!=0) {
69     printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
70     return -1;
71   }
72
73
74   /* define wait event timeout - 1s max */
75   monitorSetNowait();
76   monitorSetNoWaitNetworkTimeout(1000);
77   
78    /* init some counters */
79   int nevents_physics=0;
80   int nevents_total=0;
81
82   AliRawReader *rawReader = NULL;
83
84   AliPHOSRcuDA1 da1(2,-1); // DA1 (Calibration DA) for module2
85   
86   Float_t e[64][56][2];
87   Float_t t[64][56][2];
88
89   Int_t gain = -1;
90   Int_t X = -1;
91   Int_t Z = -1;
92
93   /* main loop (infinite) */
94   for(;;) {
95     struct eventHeaderStruct *event;
96     eventTypeType eventT;
97   
98     /* check shutdown condition */
99     if (daqDA_checkShutdown()) {break;}
100     
101     /* get next event (blocking call until timeout) */
102     status=monitorGetEventDynamic((void **)&event);
103     if (status==MON_ERR_EOF) {
104       printf ("End of File detected\n");
105       break; /* end of monitoring file has been reached */
106     }
107     
108     if (status!=0) {
109       printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
110       break;
111     }
112
113     /* retry if got no event */
114     if (event==NULL) {
115       continue;
116     }
117
118
119     /* use event - here, just write event id to result file */
120     eventT=event->eventType;
121     
122     if (eventT==PHYSICS_EVENT) {
123       
124       for(Int_t iX=0; iX<64; iX++) {
125         for(Int_t iZ=0; iZ<56; iZ++) {
126           for(Int_t iGain=0; iGain<2; iGain++) {
127             e[iX][iZ][iGain] = 0.;
128             t[iX][iZ][iGain] = 0.;
129           }
130         }
131       }
132
133       rawReader = new AliRawReaderDate((void*)event);
134 //       AliPHOSRawDecoderv1 dc(rawReader,mapping);
135       AliPHOSRawDecoder dc(rawReader,mapping);
136       dc.SubtractPedestals(kTRUE);
137       
138       while(dc.NextDigit()) {
139
140         X = dc.GetRow() - 1;
141         Z = dc.GetColumn() - 1;
142
143         if(dc.IsLowGain()) gain = 0;
144         else
145           gain = 1;
146         
147         e[X][Z][gain] = dc.GetEnergy();
148         t[X][Z][gain] = dc.GetTime();
149         
150       }
151
152       da1.FillHistograms(e,t);
153       //da1.UpdateHistoFile();
154       
155       delete rawReader;     
156       nevents_physics++;
157     }
158     
159     nevents_total++;
160     
161     /* free resources */
162     free(event);
163     
164     /* exit when last event received, no need to wait for TERM signal */
165     if (eventT==END_OF_RUN) {
166       printf("EOR event detected\n");
167       break;
168     }
169   }
170   
171   for(Int_t i = 0; i < 4; i++) delete mapping[i];  
172   
173   return status;
174 }