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