]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ZDC/ZDCEMDda.cxx
DA for EMD events to produce energy calibration data
[u/mrichter/AliRoot.git] / ZDC / ZDCEMDda.cxx
CommitLineData
f16f149b 1/*
2
3DAcase2.c
4
5This program connects to the DAQ data source passed as argument
6and populates local "./result.txt" file with the ids of events received
7during the run.
8
9The program exits when being asked to shut down (daqDA_checkshutdown)
10or End of Run event.
11
12Messages on stdout are exported to DAQ log system.
13
14DA for ZDC standalon pedestal runs
15contact: Chiara.Oppedisano@cern.ch
16
17*/
18
19#include <stdio.h>
20#include <Riostream.h>
21
22// DATE
23#include <daqDA.h>
24#include <event.h>
25#include <monitor.h>
26
27//ROOT
28#include <TRandom.h>
29#include <TH1F.h>
30#include <TH2F.h>
31#include <TProfile.h>
32#include <TF1.h>
33#include <TFile.h>
34
35//AliRoot
36#include <AliRawReaderDate.h>
37#include <AliZDCRawStream.h>
38
39
40/* Main routine
41 Arguments:
42 1- monitoring data source
43*/
44int main(int argc, char **argv) {
45
46 //
47 // --- Preparing histos for EM dissociation spectra
48 //
49 TH1F* histoEMDRaw[4];
50 TH1F* histoEMDCorr[4];
51
52 char namhistr[50], namhistc[50];
53 for(Int_t i=0; i<4; i++) {
54 if(i==0){
55 sprintf(namhistr,"ZN%d-EMDRaw",i+1);
56 sprintf(namhistc,"ZN%d-EMDCorr",i+1);
57 }
58 else if(i==1){
59 sprintf(namhistr,"ZP%d-EMDRaw",i);
60 sprintf(namhistc,"ZP%d-EMDCorr",i);
61 }
62 else if(i==2){
63 sprintf(namhistr,"ZN%d-EMDRaw",i);
64 sprintf(namhistc,"ZN%d-EMDCorr",i);
65 }
66 else if(i==3){
67 sprintf(namhistr,"ZP%d-EMDRaw",i-1);
68 sprintf(namhistc,"ZP%d-EMDCorr",i-1);
69 }
70 histoEMDRaw[i] = new TH1F(namhistr,namhistr,100,0.,4000.);
71 histoEMDCorr[i] = new TH1F(namhistc,namhistc,100,0.,4000.);
72 }
73
74 int status;
75
76 if (argc!=2) {
77 printf("Wrong number of arguments\n");
78 return -1;
79 }
80
81
82 /* open result file */
83 FILE *fp=NULL;
84 fp=fopen("./result.txt","a");
85 if (fp==NULL) {
86 printf("Failed to open file\n");
87 return -1;
88 }
89
90
91 /* define data source : this is argument 1 */
92 status = monitorSetDataSource( argv[1] );
93 if(status!=0) {
94 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
95 return -1;
96 }
97
98
99 /* declare monitoring program */
100 status = monitorDeclareMp( __FILE__ );
101 if (status!=0) {
102 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
103 return -1;
104 }
105
106
107 /* define wait event timeout - 1s max */
108 monitorSetNowait();
109 monitorSetNoWaitNetworkTimeout(1000);
110
111
112 /* log start of process */
113 printf("ZDC PEDESTAL monitoring program started\n");
114
115 /* init some counters */
116 int nevents_physics=0;
117 int nevents_total=0;
118
119 struct equipmentStruct *equipment;
120 int *eventEnd;
121 int *eventData;
122 int *equipmentEnd;
123 int *equipmentData;
124 int *equipmentID;
125 struct eventHeaderStruct *event;
126 eventTypeType eventT;
127 Int_t iev=0;
128
129 /* main loop (infinite) */
130 for(;;) {
131
132 /* check shutdown condition */
133 if (daqDA_checkShutdown()) {break;}
134
135 /* get next event (blocking call until timeout) */
136 status=monitorGetEventDynamic((void **)&event);
137 if (status==MON_ERR_EOF) {
138 printf ("End of File detected\n");
139 break; /* end of monitoring file has been reached */
140 }
141
142 if (status!=0) {
143 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
144 break;
145 }
146
147 /* retry if got no event */
148 if (event==NULL) {
149 continue;
150 }
151
152 iev++;
153
154 /* use event - here, just write event id to result file */
155 eventT=event->eventType;
156
157 if(eventT==PHYSICS_EVENT){
158 //
159 // *** To analyze EMD events you MUST have a pedestal data file!!!
160 // *** -> check if a pedestal run has been analyzied
161 FILE *filePed=NULL;
162 filePed=fopen("./ZDCPedestal.dat","r");
163 if (filePed==NULL) {
164 printf("\t ERROR!!! You MUST have a ZDCPedestal.dat file!!!\n");
165 return -1;
166 }
167 // 132 = 44 in-time + 44 out-of-time + 44 correlations
168 Float_t readValues[2][132], MeanPed[44], MeanPedWidth[44],
169 MeanPedOOT[44], MeanPedWidthOOT[44],
170 CorrCoeff0[44], CorrCoeff1[44];
171 //
172 for(int jj=0; jj<132; jj++){
173 for(int ii=0; ii<2; ii++){
174 fscanf(filePed,"%f",&readValues[ii][jj]);
175 }
176 if(jj<44){
177 MeanPed[jj] = readValues[0][jj];
178 MeanPedWidth[jj] = readValues[1][jj];
179 }
180 else if(jj>44 && jj<88){
181 MeanPedOOT[jj-44] = readValues[0][jj];
182 MeanPedWidthOOT[jj-44] = readValues[1][jj];
183 }
184 else if(jj>88){
185 CorrCoeff0[jj-88] = readValues[0][jj];
186 CorrCoeff1[jj-88] = readValues[1][jj];;
187 }
188 }
189 //
190 //
191 // Initalize raw-data reading and decoding
192 AliRawReader *reader = new AliRawReaderDate((void*)event);
193 const AliRawDataHeader* header = reader->GetDataHeader();
194 if(header){
195 UChar_t message = header->GetL1TriggerMessage();
196 }
197 else{
198 printf("\t ATTENTION! No Raw Data Header found!!!\n");
199 return -1;
200 }
201 //
202 AliZDCRawStream *rawStreamZDC = new AliZDCRawStream(reader);
203 //
204 if (!rawStreamZDC->Next()) printf(" \t No raw data found!! ");
205 //
206 Float_t ZDCRawADC[4], ZDCCorrADC[4], ZDCCorrADCSum[4];
207 for(Int_t g=0; g<4; g++){
208 ZDCCorrADCSum[g] = 0.;
209 ZDCRawADC[g] = 0.;
210 }
211 //
212 while(rawStreamZDC->Next()){
213 if(rawStreamZDC->IsADCDataWord()){
214 Int_t StartIndex[4] = {5,15,29,39};
215 Int_t DetIndex;
216 if(rawStreamZDC->GetSector(0) == 1 || rawStreamZDC->GetSector(0) == 2)
217 DetIndex = rawStreamZDC->GetSector(0)-1;
218 else if(rawStreamZDC->GetSector(0) == 4 || rawStreamZDC->GetSector(0) == 5)
219 DetIndex = rawStreamZDC->GetSector(0)-2;
220
221 if(rawStreamZDC->GetADCGain() == 1){ //EMD -> LR ADC
222 //
223 ZDCRawADC[DetIndex] += (Float_t) rawStreamZDC->GetADCValue();
224 Int_t PedIndex = StartIndex[DetIndex]+rawStreamZDC->GetSector(1);
225 // Mean pedestal subtraction
226 Float_t Pedestal = MeanPed[PedIndex];
227 // Pedestal subtraction from correlation with out-of-time signals
228 //Float_t Pedestal = ;
229 //
230 ZDCCorrADC[DetIndex] = (rawStreamZDC->GetADCValue()) - Pedestal;
231 ZDCCorrADCSum[DetIndex] += ZDCCorrADC[DetIndex];
232 }
233 }//IsADCDataWord()
234 //
235 }
236 //
237 nevents_physics++;
238 //
239 for(Int_t j=0; j<4; j++){
240 histoEMDRaw[j]->Fill(ZDCRawADC[j]);
241 histoEMDCorr[j]->Fill(ZDCCorrADCSum[j]);
242 }
243 }
244
245 nevents_total++;
246
247
248 /* free resources */
249 free(event);
250
251 /* exit when last event received, no need to wait for TERM signal */
252 if (eventT==END_OF_RUN) {
253 printf("EOR event detected\n");
254 break;
255 }
256 }
257
258 /* Analysis of the histograms */
259 //
260 FILE *fileShuttle;
261 fileShuttle = fopen("ZDCEMD.dat","w");
262 //
263 Int_t BinMax[4];
264 Float_t YMax[4];
265 Int_t NBinsx[4];
266 Float_t MeanFitVal[4];
267 TF1 *fitfun[4];
268 for(Int_t k=0; k<4; k++){
269 BinMax[k] = histoEMDCorr[k]->GetMaximumBin();
270 YMax[k] = (histoEMDCorr[k]->GetXaxis())->GetXmax();
271 NBinsx[k] = (histoEMDCorr[k]->GetXaxis())->GetNbins();
272 //printf("\n\t Det%d -> BinMax = %d, ChXMax = %f\n", k+1, BinMax[k], BinMax[k]*YMax[k]/NBinsx[k]);
273 histoEMDCorr[k]->Fit("gaus","Q","",BinMax[k]*YMax[k]/NBinsx[k]*0.7,BinMax[k]*YMax[k]/NBinsx[k]*1.25);
274 fitfun[k] = histoEMDCorr[k]->GetFunction("gaus");
275 MeanFitVal[k] = (Float_t) (fitfun[k]->GetParameter(1));
276 //printf("\n\t Mean Value from gaussian fit = %f\n", MeanFitVal[k]);
277 }
278 //
279 Float_t CalibCoeff[6];
280 /*for(Int_t j=0; j<6; j++){
281 if(j<4) CalibCoeff[j] = 2.76/MeanFitVal[j];
282 else CalibCoeff[j] = 1.;
283 fprintf(fileShuttle,"\t%f\n",CalibCoeff[j]);
284 }
285 */
286 // --- For the moment we have sim data only for ZN1!!!
287 for(Int_t j=0; j<6; j++){
288 if(j==0 || j==1) CalibCoeff[j] = 2.76/MeanFitVal[j];
289 else if(j>0 && j<4) CalibCoeff[j] = CalibCoeff[0];
290 else CalibCoeff[j] = 1.;
291 fprintf(fileShuttle,"\t%f\n",CalibCoeff[j]);
292 }
293 //
294 fclose(fileShuttle);
295
296
297 /* write report */
298 fprintf(fp,"Run #%s, received %d physics events out of %d\n",getenv("DATE_RUN_NUMBER"),nevents_physics,nevents_total);
299
300 /* close result file */
301 fclose(fp);
302
303
304 return status;
305}