]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ZDC/ZDCEMDda.cxx
Remove High Voltage STATus values from preprocessor configuration
[u/mrichter/AliRoot.git] / ZDC / ZDCEMDda.cxx
CommitLineData
f16f149b 1/*
2
442e1b18 3This program reads the DAQ data files passed as argument using the monitoring library.
f16f149b 4
442e1b18 5It computes the average event size and populates local "./result.txt" file with the
6result.
f16f149b 7
442e1b18 8The program reports about its processing progress.
f16f149b 9
10Messages on stdout are exported to DAQ log system.
11
442e1b18 12DA for ZDC standalone pedestal runs
13
ea628de7 14Contact: Chiara.Oppedisano@to.infn.it
442e1b18 15Link:
ea628de7 16Run Type: STANDALONE_EMD_RUN
442e1b18 17DA Type: LDC
18Number of events needed: at least ~5*10^3
ea628de7 19Input Files: ZDCPedestal.dat
442e1b18 20Output Files: ZDCEMDCalib.dat, ZDCChMapping.dat
ea628de7 21Trigger Types Used: Standalone Trigger
f16f149b 22
23*/
24
25#include <stdio.h>
26#include <Riostream.h>
442e1b18 27#include <Riostream.h>
f16f149b 28
29// DATE
30#include <daqDA.h>
31#include <event.h>
32#include <monitor.h>
33
34//ROOT
35#include <TRandom.h>
36#include <TH1F.h>
37#include <TH2F.h>
38#include <TProfile.h>
39#include <TF1.h>
40#include <TFile.h>
442e1b18 41#include <TFitter.h>
f16f149b 42
43//AliRoot
44#include <AliRawReaderDate.h>
442e1b18 45#include <AliRawEventHeaderBase.h>
f16f149b 46#include <AliZDCRawStream.h>
47
48
49/* Main routine
50 Arguments:
51 1- monitoring data source
52*/
53int main(int argc, char **argv) {
54
442e1b18 55 TFitter *minuitFit = new TFitter(4);
56 TVirtualFitter::SetFitter(minuitFit);
57
58 int status = 0;
59
60 /* log start of process */
61 printf("ZDC EMD program started\n");
62
63 /* check that we got some arguments = list of files */
64 if (argc<2) {
65 printf("Wrong number of arguments\n");
66 return -1;
67 }
68
f16f149b 69 //
70 // --- Preparing histos for EM dissociation spectra
71 //
72 TH1F* histoEMDRaw[4];
73 TH1F* histoEMDCorr[4];
74
75 char namhistr[50], namhistc[50];
76 for(Int_t i=0; i<4; i++) {
77 if(i==0){
78 sprintf(namhistr,"ZN%d-EMDRaw",i+1);
79 sprintf(namhistc,"ZN%d-EMDCorr",i+1);
80 }
81 else if(i==1){
82 sprintf(namhistr,"ZP%d-EMDRaw",i);
83 sprintf(namhistc,"ZP%d-EMDCorr",i);
84 }
85 else if(i==2){
86 sprintf(namhistr,"ZN%d-EMDRaw",i);
87 sprintf(namhistc,"ZN%d-EMDCorr",i);
88 }
89 else if(i==3){
90 sprintf(namhistr,"ZP%d-EMDRaw",i-1);
91 sprintf(namhistc,"ZP%d-EMDCorr",i-1);
92 }
93 histoEMDRaw[i] = new TH1F(namhistr,namhistr,100,0.,4000.);
94 histoEMDCorr[i] = new TH1F(namhistc,namhistc,100,0.,4000.);
95 }
96
f16f149b 97 /* open result file */
98 FILE *fp=NULL;
99 fp=fopen("./result.txt","a");
100 if (fp==NULL) {
101 printf("Failed to open file\n");
102 return -1;
103 }
104
442e1b18 105 FILE *mapFile4Shuttle;
106 const char *mapfName = "ZDCChMapping.dat";
f16f149b 107
108 /* define data source : this is argument 1 */
109 status = monitorSetDataSource( argv[1] );
110 if(status!=0) {
111 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
112 return -1;
113 }
114
115
116 /* declare monitoring program */
117 status = monitorDeclareMp( __FILE__ );
118 if (status!=0) {
119 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
120 return -1;
121 }
122
123
124 /* define wait event timeout - 1s max */
125 monitorSetNowait();
126 monitorSetNoWaitNetworkTimeout(1000);
127
128
129 /* log start of process */
442e1b18 130 printf("ZDC EMD monitoring program started\n");
f16f149b 131
442e1b18 132 /* report progress */
133 daqDA_progressReport(10);
134
135
f16f149b 136 /* init some counters */
137 int nevents_physics=0;
138 int nevents_total=0;
139
442e1b18 140 /* read the data files */
141 int n;
142 for(n=1;n<argc;n++){
143
144 status=monitorSetDataSource( argv[n] );
f16f149b 145 if (status!=0) {
442e1b18 146 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
147 return -1;
f16f149b 148 }
149
442e1b18 150 /* report progress */
151 /* in this example, indexed on the number of files */
152 daqDA_progressReport(10+80*n/argc);
153
154 /* read the file */
155 for(;;){
156 struct eventHeaderStruct *event;
157 eventTypeType eventT;
f16f149b 158
442e1b18 159 /* get next event */
160 status=monitorGetEventDynamic((void **)&event);
161 if(status==MON_ERR_EOF) break; /* end of monitoring file has been reached */
162 if(status!=0) {
163 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
164 return -1;
165 }
f16f149b 166
442e1b18 167 /* retry if got no event */
168 if(event==NULL) {
169 break;
170 }
171
172 // Initalize raw-data reading and decoding
173 AliRawReader *reader = new AliRawReaderDate((void*)event);
174 reader->Select("ZDC");
175 // --- Reading event header
176 //UInt_t evtype = reader->GetType();
177 //printf("\n\t ZDCEMDda -> ev. type %d\n",evtype);
178 //printf("\t ZDCEMDda -> run # %d\n",reader->GetRunNumber());
179 //
180 AliZDCRawStream *rawStreamZDC = new AliZDCRawStream(reader);
181
182
183 /* use event - here, just write event id to result file */
184 eventT=event->eventType;
185
186 Int_t ich=0, adcMod[48], adcCh[48], sigCode[48], det[48], sec[48];
187 if(eventT==START_OF_DATA){
188
189 if(!rawStreamZDC->Next()) printf(" \t No raw data found!! \n");
190 else{
191 while(rawStreamZDC->Next()){
192 if(rawStreamZDC->IsChMapping()){
193 adcMod[ich] = rawStreamZDC->GetADCModFromMap(ich);
194 adcCh[ich] = rawStreamZDC->GetADCChFromMap(ich);
195 sigCode[ich] = rawStreamZDC->GetADCSignFromMap(ich);
196 det[ich] = rawStreamZDC->GetDetectorFromMap(ich);
197 sec[ich] = rawStreamZDC->GetTowerFromMap(ich);
198 ich++;
199 }
200 }
201 }
202 // --------------------------------------------------------
203 // --- Writing ascii data file for the Shuttle preprocessor
204 mapFile4Shuttle = fopen(mapfName,"w");
205 for(Int_t i=0; i<ich; i++){
206 fprintf(mapFile4Shuttle,"\t%d\t%d\t%d\t%d\t%d\t%d\n",i,
207 adcMod[i],adcCh[i],sigCode[i],det[i],sec[i]);
208 //
209 //printf("ZDCPEDESTALDA.cxx -> ch.%d mod %d, ch %d, code %d det %d, sec %d\n",
210 // i,adcMod[i],adcCh[i],sigCode[i],det[i],sec[i]);
211 }
212 fclose(mapFile4Shuttle);
213 }
f16f149b 214
215 if(eventT==PHYSICS_EVENT){
216 //
217 // *** To analyze EMD events you MUST have a pedestal data file!!!
218 // *** -> check if a pedestal run has been analyzied
219 FILE *filePed=NULL;
220 filePed=fopen("./ZDCPedestal.dat","r");
221 if (filePed==NULL) {
222 printf("\t ERROR!!! You MUST have a ZDCPedestal.dat file!!!\n");
223 return -1;
224 }
ea628de7 225 // 144 = 48 in-time + 48 out-of-time + 48 correlations
226 Float_t readValues[2][144], MeanPed[44], MeanPedWidth[44],
f16f149b 227 MeanPedOOT[44], MeanPedWidthOOT[44],
228 CorrCoeff0[44], CorrCoeff1[44];
229 //
ea628de7 230 for(int jj=0; jj<144; jj++){
f16f149b 231 for(int ii=0; ii<2; ii++){
232 fscanf(filePed,"%f",&readValues[ii][jj]);
233 }
ea628de7 234 if(jj<48){
f16f149b 235 MeanPed[jj] = readValues[0][jj];
236 MeanPedWidth[jj] = readValues[1][jj];
237 }
ea628de7 238 else if(jj>48 && jj<96){
239 MeanPedOOT[jj-48] = readValues[0][jj];
240 MeanPedWidthOOT[jj-48] = readValues[1][jj];
f16f149b 241 }
ea628de7 242 else if(jj>144){
243 CorrCoeff0[jj-96] = readValues[0][jj];
244 CorrCoeff1[jj-96] = readValues[1][jj];;
f16f149b 245 }
246 }
247 //
442e1b18 248
249 // --- Reading data header
250 reader->ReadHeader();
f16f149b 251 const AliRawDataHeader* header = reader->GetDataHeader();
252 if(header){
ea628de7 253 UChar_t message = header->GetAttributes();
254 if(message & 0x70){ // DEDICATED EMD RUN
442e1b18 255 //printf("\t STANDALONE_EMD_RUN raw data found\n");
ea628de7 256 continue;
257 }
258 else{
259 printf("\t NO STANDALONE_EMD_RUN raw data found\n");
260 return -1;
261 }
f16f149b 262 }
442e1b18 263 else{
264 printf("\t ATTENTION! No Raw Data Header found!!!\n");
265 return -1;
266 }
267
f16f149b 268 if (!rawStreamZDC->Next()) printf(" \t No raw data found!! ");
269 //
442e1b18 270 // ----- Setting ch. mapping -----
271 for(Int_t jk=0; jk<48; jk++){
272 rawStreamZDC->SetMapADCMod(jk, adcMod[jk]);
273 rawStreamZDC->SetMapADCCh(jk, adcCh[jk]);
274 rawStreamZDC->SetMapADCSig(jk, sigCode[jk]);
275 rawStreamZDC->SetMapDet(jk, det[jk]);
276 rawStreamZDC->SetMapTow(jk, sec[jk]);
277 }
278 //
f16f149b 279 Float_t ZDCRawADC[4], ZDCCorrADC[4], ZDCCorrADCSum[4];
280 for(Int_t g=0; g<4; g++){
281 ZDCCorrADCSum[g] = 0.;
282 ZDCRawADC[g] = 0.;
283 }
284 //
285 while(rawStreamZDC->Next()){
286 if(rawStreamZDC->IsADCDataWord()){
ea628de7 287 Int_t DetIndex=999, PedIndex=999;
288 if(rawStreamZDC->GetSector(0) == 1 || rawStreamZDC->GetSector(0) == 2){
f16f149b 289 DetIndex = rawStreamZDC->GetSector(0)-1;
ea628de7 290 PedIndex = (rawStreamZDC->GetSector(0)+1)+4*rawStreamZDC->GetSector(1);
291 }
292 else if(rawStreamZDC->GetSector(0) == 4 || rawStreamZDC->GetSector(0) == 5){
f16f149b 293 DetIndex = rawStreamZDC->GetSector(0)-2;
ea628de7 294 PedIndex = (rawStreamZDC->GetSector(0)-2)+4*rawStreamZDC->GetSector(1)+24;
295 }
296 //
f16f149b 297 if(rawStreamZDC->GetADCGain() == 1){ //EMD -> LR ADC
298 //
299 ZDCRawADC[DetIndex] += (Float_t) rawStreamZDC->GetADCValue();
f16f149b 300 // Mean pedestal subtraction
301 Float_t Pedestal = MeanPed[PedIndex];
302 // Pedestal subtraction from correlation with out-of-time signals
ea628de7 303 //Float_t Pedestal = CorrCoeff0[PedIndex]+CorrCoeff1[PedIndex]*MeanPedOOT[PedIndex];
f16f149b 304 //
305 ZDCCorrADC[DetIndex] = (rawStreamZDC->GetADCValue()) - Pedestal;
306 ZDCCorrADCSum[DetIndex] += ZDCCorrADC[DetIndex];
ea628de7 307 //
308 /*printf("\t det %d quad %d res %d pedInd %d ADCCorr %d ZDCCorrADCSum[%d] = %d\n",
309 rawStreamZDC->GetSector(0),rawStreamZDC->GetSector(1),
310 rawStreamZDC->GetADCGain(),PedIndex,
311 (Int_t) (rawStreamZDC->GetADCValue() - Pedestal), DetIndex,
312 (Int_t) ZDCCorrADCSum[DetIndex]);
313 */
314 }
f16f149b 315 }//IsADCDataWord()
316 //
317 }
318 //
319 nevents_physics++;
320 //
321 for(Int_t j=0; j<4; j++){
322 histoEMDRaw[j]->Fill(ZDCRawADC[j]);
323 histoEMDCorr[j]->Fill(ZDCCorrADCSum[j]);
324 }
325 }
326
327 nevents_total++;
328
f16f149b 329 /* free resources */
330 free(event);
331
332 /* exit when last event received, no need to wait for TERM signal */
333 if (eventT==END_OF_RUN) {
334 printf("EOR event detected\n");
335 break;
336 }
442e1b18 337
338 }
f16f149b 339 }
442e1b18 340
f16f149b 341 /* Analysis of the histograms */
342 //
343 FILE *fileShuttle;
442e1b18 344 const char *fName = "ZDCPedestal.dat";
345 fileShuttle = fopen(fName,"w");
f16f149b 346 //
347 Int_t BinMax[4];
348 Float_t YMax[4];
349 Int_t NBinsx[4];
350 Float_t MeanFitVal[4];
351 TF1 *fitfun[4];
352 for(Int_t k=0; k<4; k++){
353 BinMax[k] = histoEMDCorr[k]->GetMaximumBin();
354 YMax[k] = (histoEMDCorr[k]->GetXaxis())->GetXmax();
355 NBinsx[k] = (histoEMDCorr[k]->GetXaxis())->GetNbins();
ea628de7 356// printf("\n\t Det%d -> BinMax = %d, ChXMax = %f\n", k+1, BinMax[k], BinMax[k]*YMax[k]/NBinsx[k]);
f16f149b 357 histoEMDCorr[k]->Fit("gaus","Q","",BinMax[k]*YMax[k]/NBinsx[k]*0.7,BinMax[k]*YMax[k]/NBinsx[k]*1.25);
358 fitfun[k] = histoEMDCorr[k]->GetFunction("gaus");
359 MeanFitVal[k] = (Float_t) (fitfun[k]->GetParameter(1));
c38bc7ef 360 //printf("\n\t Mean Value from gaussian fit = %f\n", MeanFitVal[k]);
f16f149b 361 }
362 //
363 Float_t CalibCoeff[6];
364 /*for(Int_t j=0; j<6; j++){
4ef37af5 365 if(j<4) CalibCoeff[j] = MeanFitVal[j];
f16f149b 366 else CalibCoeff[j] = 1.;
367 fprintf(fileShuttle,"\t%f\n",CalibCoeff[j]);
368 }
369 */
370 // --- For the moment we have sim data only for ZN1!!!
371 for(Int_t j=0; j<6; j++){
4ef37af5 372 if(j==0) CalibCoeff[j] = MeanFitVal[j];
f16f149b 373 else if(j>0 && j<4) CalibCoeff[j] = CalibCoeff[0];
374 else CalibCoeff[j] = 1.;
375 fprintf(fileShuttle,"\t%f\n",CalibCoeff[j]);
376 }
377 //
378 fclose(fileShuttle);
379
442e1b18 380 for(Int_t ij=0; ij<4; ij++){
381 delete histoEMDRaw[ij];
382 delete histoEMDCorr[ij];
383 }
384
385 //delete minuitFit;
386 TVirtualFitter::SetFitter(0);
f16f149b 387
388 /* write report */
389 fprintf(fp,"Run #%s, received %d physics events out of %d\n",getenv("DATE_RUN_NUMBER"),nevents_physics,nevents_total);
390
391 /* close result file */
392 fclose(fp);
442e1b18 393
394 /* report progress */
395 daqDA_progressReport(90);
396
397 /* store the result file on FES */
398 status = daqDA_FES_storeFile(mapfName,"ZDCCHMAPPING_data");
399 if(status){
400 printf("Failed to export file : %d\n",status);
401 return -1;
402 }
403 //
404 status = daqDA_FES_storeFile(fName,"ZDCEMD_data");
405 if(status){
406 printf("Failed to export file : %d\n",status);
407 return -1;
408 }
f16f149b 409
442e1b18 410 /* report progress */
411 daqDA_progressReport(100);
f16f149b 412
413 return status;
414}