Bug #74579. 1. Removal of TPC raw-data viz as it leads to a leak in gEve->FullRedraw3...
[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
f9641c3b 12DA for ZDC standalone CALIBRATION_EMD runs
442e1b18 13
ea628de7 14Contact: Chiara.Oppedisano@to.infn.it
442e1b18 15Link:
8785e578 16Run Type: CALIBRATION_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"
218f916a 25#define MAPDATA_FILE "ZDCChMapping.dat"
92fdeb0e 26#define ENCALIBDATA_FILE "ZDCEnergyCalib.dat"
f9641c3b 27#define TOWCALIBDATA_FILE "ZDCTowerCalib.dat"
f16f149b 28
29#include <stdio.h>
30#include <Riostream.h>
442e1b18 31#include <Riostream.h>
f16f149b 32
33// DATE
34#include <daqDA.h>
35#include <event.h>
36#include <monitor.h>
37
38//ROOT
f9641c3b 39#include <TROOT.h>
40#include <TPluginManager.h>
f16f149b 41#include <TH1F.h>
42#include <TH2F.h>
43#include <TProfile.h>
44#include <TF1.h>
45#include <TFile.h>
442e1b18 46#include <TFitter.h>
f9641c3b 47#include "TMinuitMinimizer.h"
f16f149b 48
49//AliRoot
50#include <AliRawReaderDate.h>
442e1b18 51#include <AliRawEventHeaderBase.h>
f16f149b 52#include <AliZDCRawStream.h>
53
54
55/* Main routine
56 Arguments:
57 1- monitoring data source
58*/
59int main(int argc, char **argv) {
60
f9641c3b 61
62 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
63 "*",
64 "TStreamerInfo",
65 "RIO",
66 "TStreamerInfo()");
67
68 TMinuitMinimizer m;
69 gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer", "Minuit","TMinuitMinimizer",
70 "Minuit", "TMinuitMinimizer(const char *)");
71 TVirtualFitter::SetDefaultFitter("Minuit");
442e1b18 72
73 int status = 0;
f9641c3b 74 // No. of ZDC cabled ch.
198f612a 75 int const kNModules = 10;
f9641c3b 76 int const kNChannels = 24;
27afc0c8 77 int const kNScChannels = 32;
8785e578 78 Int_t kFirstADCGeo=0, kLastADCGeo=1; // NO out-of-time signals!!!
79
198f612a 80
81 Int_t iMod=-1;
82 Int_t modGeo[kNModules], modType[kNModules],modNCh[kNModules];
83 for(Int_t kl=0; kl<kNModules; kl++){
84 modGeo[kl]=modType[kl]=modNCh[kl]=0;
85 }
86
778b6939 87 Int_t ich=0;
88 Int_t adcMod[2*kNChannels], adcCh[2*kNChannels], sigCode[2*kNChannels];
89 Int_t det[2*kNChannels], sec[2*kNChannels];
90 for(Int_t y=0; y<2*kNChannels; y++){
91 adcMod[y]=adcCh[y]=sigCode[y]=det[y]=sec[y]=0;
92 }
198f612a 93
94 Int_t iScCh=0;
95 Int_t scMod[kNScChannels], scCh[kNScChannels], scSigCode[kNScChannels];
96 Int_t scDet[kNScChannels], scSec[kNScChannels];
97 for(Int_t y=0; y<kNScChannels; y++){
98 scMod[y]=scCh[y]=scSigCode[y]=scDet[y]=scSec[y]=0;
99 }
82dffa48 100
101 Int_t itdcCh=0;
102 Int_t tdcMod[kNScChannels], tdcCh[kNScChannels], tdcSigCode[kNScChannels];
103 Int_t tdcDet[kNScChannels], tdcSec[kNScChannels];
104 for(Int_t y=0; y<kNScChannels; y++){
105 tdcMod[y]=tdcCh[y]=tdcSigCode[y]=tdcDet[y]=tdcSec[y]=-1;
106 }
442e1b18 107
108 /* log start of process */
109 printf("ZDC EMD program started\n");
110
111 /* check that we got some arguments = list of files */
112 if (argc<2) {
113 printf("Wrong number of arguments\n");
114 return -1;
115 }
116
f16f149b 117 // --- Preparing histos for EM dissociation spectra
118 //
8785e578 119 //TH1F* histoEMDRaw[4];
f16f149b 120 TH1F* histoEMDCorr[4];
e968a349 121 //
8785e578 122 //char namhistr[50];
123 char namhistc[50];
f16f149b 124 for(Int_t i=0; i<4; i++) {
125 if(i==0){
8785e578 126 //sprintf(namhistr,"ZN%d-EMDRaw",i+1);
f16f149b 127 sprintf(namhistc,"ZN%d-EMDCorr",i+1);
128 }
129 else if(i==1){
8785e578 130 //sprintf(namhistr,"ZP%d-EMDRaw",i);
f16f149b 131 sprintf(namhistc,"ZP%d-EMDCorr",i);
132 }
133 else if(i==2){
8785e578 134 //sprintf(namhistr,"ZN%d-EMDRaw",i);
f16f149b 135 sprintf(namhistc,"ZN%d-EMDCorr",i);
136 }
137 else if(i==3){
8785e578 138 //sprintf(namhistr,"ZP%d-EMDRaw",i-1);
f16f149b 139 sprintf(namhistc,"ZP%d-EMDCorr",i-1);
140 }
8785e578 141 //histoEMDRaw[i] = new TH1F(namhistr,namhistr,100,0.,4000.);
f16f149b 142 histoEMDCorr[i] = new TH1F(namhistc,namhistc,100,0.,4000.);
143 }
144
e968a349 145 // --- Preparing histos for tower inter-calibration
146 //
8785e578 147/* TH1F* histZNCtow[4]; TH1F* histZPCtow[4];
e968a349 148 TH1F* histZNAtow[4]; TH1F* histZPAtow[4];
149 //
150 char namhistznc[50], namhistzpc[50];
151 char namhistzna[50], namhistzpa[50];
152 for(Int_t i=0; i<4; i++) {
153 sprintf(namhistznc,"ZNC-tow%d",i+1);
154 sprintf(namhistzpc,"ZPC-tow%d",i+1);
155 sprintf(namhistzna,"ZNA-tow%d",i+1);
156 sprintf(namhistzpa,"ZPA-tow%d",i+1);
157 //
158 histZNCtow[i] = new TH1F(namhistznc,namhistznc,100,0.,4000.);
159 histZPCtow[i] = new TH1F(namhistzpc,namhistzpc,100,0.,4000.);
160 histZNAtow[i] = new TH1F(namhistzna,namhistzna,100,0.,4000.);
161 histZPAtow[i] = new TH1F(namhistzpa,namhistzpa,100,0.,4000.);
162 }
8785e578 163*/
f16f149b 164 /* open result file */
165 FILE *fp=NULL;
166 fp=fopen("./result.txt","a");
167 if (fp==NULL) {
168 printf("Failed to open file\n");
169 return -1;
170 }
171
442e1b18 172 FILE *mapFile4Shuttle;
218f916a 173
f9641c3b 174 // *** To analyze EMD events you MUST have a pedestal data file!!!
175 // *** -> check if a pedestal run has been analyzed
78beff0d 176 int read = 0;
218f916a 177 read = daqDA_DB_getFile(PEDDATA_FILE,PEDDATA_FILE);
78beff0d 178 if(read){
179 printf("\t ERROR!!! ZDCPedestal.dat file NOT FOUND in DAQ db!!!\n");
f16f149b 180 return -1;
181 }
78beff0d 182 else printf("\t ZDCPedestal.dat file retrieved from DAQ db\n");
183
184 FILE *filePed = fopen(PEDDATA_FILE,"r");
185 if (filePed==NULL) {
186 printf("\t ERROR!!! Can't open ZDCPedestal.dat file!!!\n");
f16f149b 187 return -1;
188 }
189
78beff0d 190 // 144 = 48 in-time + 48 out-of-time + 48 correlations
f9641c3b 191 Float_t readValues[2][3*2*kNChannels];
192 Float_t MeanPed[2*kNChannels];
193 Float_t CorrCoeff0[2*kNChannels], CorrCoeff1[2*kNChannels];
78beff0d 194 // ***************************************************
195 // Unless we have a narrow correlation to fit we
196 // don't fit and store in-time vs. out-of-time
197 // histograms -> mean pedstal subtracted!!!!!!
198 // ***************************************************
78beff0d 199 //
f9641c3b 200 for(int jj=0; jj<6*kNChannels; jj++){
78beff0d 201 for(int ii=0; ii<2; ii++){
202 fscanf(filePed,"%f",&readValues[ii][jj]);
203 }
778b6939 204 if(jj<2*kNChannels){
78beff0d 205 MeanPed[jj] = readValues[0][jj];
8785e578 206 //printf("\t MeanPed[%d] = %1.1f\n",jj, MeanPed[jj]);
78beff0d 207 }
778b6939 208 else if(jj>2*kNChannels){
f9641c3b 209 CorrCoeff0[jj-4*kNChannels] = readValues[0][jj];
210 CorrCoeff1[jj-4*kNChannels] = readValues[1][jj];;
78beff0d 211 }
78beff0d 212 }
f16f149b 213
442e1b18 214 /* report progress */
215 daqDA_progressReport(10);
216
217
f16f149b 218 /* init some counters */
219 int nevents_physics=0;
220 int nevents_total=0;
221
d3f256ca 222 struct eventHeaderStruct *event;
223 eventTypeType eventT;
224
442e1b18 225 /* read the data files */
226 int n;
227 for(n=1;n<argc;n++){
228
229 status=monitorSetDataSource( argv[n] );
f16f149b 230 if (status!=0) {
442e1b18 231 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
232 return -1;
f16f149b 233 }
234
442e1b18 235 /* report progress */
236 /* in this example, indexed on the number of files */
237 daqDA_progressReport(10+80*n/argc);
238
239 /* read the file */
240 for(;;){
f16f149b 241
442e1b18 242 /* get next event */
243 status=monitorGetEventDynamic((void **)&event);
244 if(status==MON_ERR_EOF) break; /* end of monitoring file has been reached */
245 if(status!=0) {
246 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
247 return -1;
248 }
f16f149b 249
442e1b18 250 /* retry if got no event */
251 if(event==NULL) {
252 break;
253 }
254
255 // Initalize raw-data reading and decoding
256 AliRawReader *reader = new AliRawReaderDate((void*)event);
257 reader->Select("ZDC");
258 // --- Reading event header
259 //UInt_t evtype = reader->GetType();
260 //printf("\n\t ZDCEMDda -> ev. type %d\n",evtype);
261 //printf("\t ZDCEMDda -> run # %d\n",reader->GetRunNumber());
262 //
263 AliZDCRawStream *rawStreamZDC = new AliZDCRawStream(reader);
264
265
266 /* use event - here, just write event id to result file */
267 eventT=event->eventType;
268
442e1b18 269 if(eventT==START_OF_DATA){
198f612a 270
27afc0c8 271 rawStreamZDC->SetSODReading(kTRUE);
272
f9641c3b 273 // --------------------------------------------------------
274 // --- Writing ascii data file for the Shuttle preprocessor
275 mapFile4Shuttle = fopen(MAPDATA_FILE,"w");
442e1b18 276 if(!rawStreamZDC->Next()) printf(" \t No raw data found!! \n");
277 else{
27afc0c8 278 while((rawStreamZDC->Next())){
279 if(rawStreamZDC->IsHeaderMapping()){ // mapping header
198f612a 280 iMod++;
281 modGeo[iMod] = rawStreamZDC->GetADCModule();
282 modType[iMod] = rawStreamZDC->GetModType();
283 modNCh[iMod] = rawStreamZDC->GetADCNChannels();
27afc0c8 284 }
285 if(rawStreamZDC->IsChMapping()){
198f612a 286 if(modType[iMod]==1){ // ADC mapping ----------------------
27afc0c8 287 adcMod[ich] = rawStreamZDC->GetADCModFromMap(ich);
288 adcCh[ich] = rawStreamZDC->GetADCChFromMap(ich);
289 sigCode[ich] = rawStreamZDC->GetADCSignFromMap(ich);
290 det[ich] = rawStreamZDC->GetDetectorFromMap(ich);
291 sec[ich] = rawStreamZDC->GetTowerFromMap(ich);
27afc0c8 292 ich++;
293 }
198f612a 294 else if(modType[iMod]==2){ //VME scaler mapping --------------------
27afc0c8 295 scMod[iScCh] = rawStreamZDC->GetScalerModFromMap(iScCh);
296 scCh[iScCh] = rawStreamZDC->GetScalerChFromMap(iScCh);
297 scSigCode[iScCh] = rawStreamZDC->GetScalerSignFromMap(iScCh);
298 scDet[iScCh] = rawStreamZDC->GetScDetectorFromMap(iScCh);
198f612a 299 scSec[iScCh] = rawStreamZDC->GetScTowerFromMap(iScCh);
27afc0c8 300 iScCh++;
301 }
82dffa48 302 else if(modType[iMod]==6 && modGeo[iMod]==4){ // ZDC TDC mapping --------------------
303 tdcMod[itdcCh] = rawStreamZDC->GetTDCModFromMap(itdcCh);
304 tdcCh[itdcCh] = rawStreamZDC->GetTDCChFromMap(itdcCh);
305 tdcSigCode[itdcCh] = rawStreamZDC->GetTDCSignFromMap(itdcCh);
306 itdcCh++;
307 }
442e1b18 308 }
198f612a 309 }
310 // Writing data on output FXS file
198f612a 311 for(Int_t is=0; is<2*kNChannels; is++){
312 fprintf(mapFile4Shuttle,"\t%d\t%d\t%d\t%d\t%d\t%d\n",
313 is,adcMod[is],adcCh[is],sigCode[is],det[is],sec[is]);
314 //printf(" EMD DA -> %d ADC: mod %d ch %d, code %d det %d, sec %d\n",
315 // is,adcMod[is],adcCh[is],sigCode[is],det[is],sec[is]);
316 }
317 for(Int_t is=0; is<kNScChannels; is++){
318 fprintf(mapFile4Shuttle,"\t%d\t%d\t%d\t%d\t%d\t%d\n",
319 is,scMod[is],scCh[is],scSigCode[is],scDet[is],scSec[is]);
320 //printf(" EMD DA -> %d Scaler: mod %d ch %d, code %d det %d, sec %d\n",
321 // is,scMod[is],scCh[is],scSigCode[is],scDet[is],scSec[is]);
442e1b18 322 }
82dffa48 323 for(Int_t is=0; is<kNScChannels; is++){
324 fprintf(mapFile4Shuttle,"\t%d\t%d\t%d\t%d\n",
325 is,tdcMod[is],tdcCh[is],tdcSigCode[is]);
326 //if(tdcMod[is]!=-1) printf(" Mapping DA -> %d TDC: mod %d ch %d, code %d\n",
327 // is,tdcMod[is],tdcCh[is],tdcSigCode[is]);
328 }
e3ddb73e 329 for(Int_t is=0; is<kNModules; is++){
330 fprintf(mapFile4Shuttle,"\t%d\t%d\t%d\n",
331 modGeo[is],modType[is],modNCh[is]);
332 //printf(" EMD DA -> Module mapping: geo %d type %d #ch %d\n",
333 // modGeo[is],modType[is],modNCh[is]);
334 }
198f612a 335
442e1b18 336 }
442e1b18 337 fclose(mapFile4Shuttle);
27afc0c8 338 }// SOD event
f16f149b 339
340 if(eventT==PHYSICS_EVENT){
78beff0d 341 // --- Reading data header
342 reader->ReadHeader();
f16f149b 343 const AliRawDataHeader* header = reader->GetDataHeader();
344 if(header){
ea628de7 345 UChar_t message = header->GetAttributes();
a5747d8f 346 if((message & 0x70) == 0x70){ // DEDICATED EMD RUN
442e1b18 347 //printf("\t STANDALONE_EMD_RUN raw data found\n");
ea628de7 348 continue;
349 }
350 else{
351 printf("\t NO STANDALONE_EMD_RUN raw data found\n");
352 return -1;
353 }
f16f149b 354 }
442e1b18 355 else{
356 printf("\t ATTENTION! No Raw Data Header found!!!\n");
357 return -1;
358 }
7f4bde92 359
360 rawStreamZDC->SetSODReading(kTRUE);
442e1b18 361
f16f149b 362 if (!rawStreamZDC->Next()) printf(" \t No raw data found!! ");
363 //
442e1b18 364 // ----- Setting ch. mapping -----
f9641c3b 365 for(Int_t jk=0; jk<2*kNChannels; jk++){
442e1b18 366 rawStreamZDC->SetMapADCMod(jk, adcMod[jk]);
367 rawStreamZDC->SetMapADCCh(jk, adcCh[jk]);
368 rawStreamZDC->SetMapADCSig(jk, sigCode[jk]);
369 rawStreamZDC->SetMapDet(jk, det[jk]);
370 rawStreamZDC->SetMapTow(jk, sec[jk]);
371 }
372 //
8785e578 373/* Float_t ZDCRawADC[4], ZDCCorrADC[4], ZDCCorrADCSum[4];
f16f149b 374 for(Int_t g=0; g<4; g++){
375 ZDCCorrADCSum[g] = 0.;
376 ZDCRawADC[g] = 0.;
377 }
8785e578 378*/
f16f149b 379 //
380 while(rawStreamZDC->Next()){
8785e578 381 Int_t detID = rawStreamZDC->GetSector(0);
f9641c3b 382 Int_t quad = rawStreamZDC->GetSector(1);
383
384 if(rawStreamZDC->IsADCDataWord() && !(rawStreamZDC->IsUnderflow())
8785e578 385 && !(rawStreamZDC->IsOverflow()) && detID!=-1 && detID!=3
8700404e 386 && (rawStreamZDC->GetADCGain() == 1 && // Selecting LOW RES ch.s
387 rawStreamZDC->GetADCModule()>=kFirstADCGeo && rawStreamZDC->GetADCModule()<=kLastADCGeo)){
f9641c3b 388
e968a349 389 // Taking LOW RES channels -> ch.+kNChannels !!!!
ea628de7 390 Int_t DetIndex=999, PedIndex=999;
778b6939 391 // Not PMRef
392 if(quad!=5){
8785e578 393 if(detID == 1){
394 DetIndex = detID-1;
e968a349 395 PedIndex = quad+kNChannels;
f9641c3b 396 }
8785e578 397 else if(detID==2){
398 DetIndex = detID-1;
f9641c3b 399 PedIndex = quad+5+kNChannels;
400 }
8785e578 401 else if(detID == 4){
402 DetIndex = detID-2;
f9641c3b 403 PedIndex = quad+12+kNChannels;
404 }
8785e578 405 else if(detID == 5){
406 DetIndex = detID-2;
f9641c3b 407 PedIndex = quad+17+kNChannels;
408 }
e968a349 409 // Mean pedestal subtraction
410 Float_t Pedestal = MeanPed[PedIndex];
411 // Pedestal subtraction from correlation with out-of-time signals
412 //Float_t Pedestal = CorrCoeff0[PedIndex]+CorrCoeff1[PedIndex]*MeanPedOOT[PedIndex];
8785e578 413
414 // Run 2010 -> we decide to fit only PMCs
e968a349 415 if(DetIndex!=999 || PedIndex!=999){
8785e578 416 if(quad==0){
417 Float_t corrADCval = (rawStreamZDC->GetADCValue()) - Pedestal;
418 if(detID==1 || detID==2) histoEMDCorr[detID-1]->Fill(corrADCval);
419 else if(detID==4 || detID==5) histoEMDCorr[detID-2]->Fill(corrADCval);
420 }
421 }
422
423/* if(DetIndex!=999 || PedIndex!=999){
f9641c3b 424 //
425 ZDCRawADC[DetIndex] += (Float_t) rawStreamZDC->GetADCValue();
426 //
f9641c3b 427 //
428 ZDCCorrADC[DetIndex] = (rawStreamZDC->GetADCValue()) - Pedestal;
429 ZDCCorrADCSum[DetIndex] += ZDCCorrADC[DetIndex];
430 //
8785e578 431 //printf("\t det %d quad %d res %d pedInd %d "
432 // "Pedestal %1.0f -> ADCCorr = %d ZDCCorrADCSum = %d\n",
433 // detID,quad,rawStreamZDC->GetADCGain(),PedIndex,Pedestal,
434 // (Int_t) ZDCCorrADC[DetIndex],(Int_t) ZDCCorrADCSum[DetIndex]);
778b6939 435
e968a349 436 }
778b6939 437 // Not common PM
438 if(quad!=0){
e968a349 439 Float_t corrADCval = (rawStreamZDC->GetADCValue()) - Pedestal;
8785e578 440 if(detID==1) histZNCtow[quad-1]->Fill(corrADCval);
441 else if(detID==2) histZPCtow[quad-1]->Fill(corrADCval);
442 else if(detID==4) histZNAtow[quad-1]->Fill(corrADCval);
443 else if(detID==5) histZPAtow[quad-1]->Fill(corrADCval);
778b6939 444 //
445 //printf("\t det %d tow %d fill histo w. value %1.0f\n",
8785e578 446 // detID,quad,corrADCval);
f9641c3b 447 }
8785e578 448*/
f9641c3b 449 if(DetIndex==999 || PedIndex==999)
778b6939 450 printf(" WARNING! Detector a/o pedestal index are WRONG!!!\n");
f9641c3b 451
778b6939 452 }//quad!=5
f16f149b 453 }//IsADCDataWord()
e968a349 454
f16f149b 455 }
456 //
457 nevents_physics++;
458 //
778b6939 459 delete reader;
460 delete rawStreamZDC;
461 //
8785e578 462/* for(Int_t j=0; j<4; j++){
463 //histoEMDRaw[j]->Fill(ZDCRawADC[j]);
f16f149b 464 histoEMDCorr[j]->Fill(ZDCCorrADCSum[j]);
465 }
8785e578 466*/
d3f256ca 467 }//(if PHYSICS_EVENT)
778b6939 468
469 /* exit when last event received, no need to wait for TERM signal */
470 else if(eventT==END_OF_RUN) {
471 printf(" -> EOR event detected\n");
472 break;
473 }
f16f149b 474
475 nevents_total++;
476
442e1b18 477 }
d3f256ca 478
479 /* free resources */
480 free(event);
f16f149b 481 }
442e1b18 482
f16f149b 483 /* Analysis of the histograms */
484 //
f9641c3b 485 FILE *fileShuttle1 = fopen(ENCALIBDATA_FILE,"w");
f16f149b 486 //
778b6939 487 Int_t BinMax[4]={0,0,0,0};
488 Float_t YMax[4]={0.,0.,0.,0.};
489 Int_t NBinsx[4]={0,0,0,0};
490 Float_t MeanFitVal[4]={0.,0.,0.,0.};
f16f149b 491 TF1 *fitfun[4];
492 for(Int_t k=0; k<4; k++){
f9641c3b 493 if(histoEMDCorr[k]->GetEntries() == 0){
494 printf("\n WARNING! Empty histos -> ending DA WITHOUT writing output\n\n");
495 return -1;
496 }
778b6939 497 //
f16f149b 498 BinMax[k] = histoEMDCorr[k]->GetMaximumBin();
778b6939 499 if(BinMax[k]<=6){
500 printf("\n WARNING! Something wrong with det %d histo -> ending DA WITHOUT writing output\n\n", k);
501 return -1;
502 }
503 //
f16f149b 504 YMax[k] = (histoEMDCorr[k]->GetXaxis())->GetXmax();
505 NBinsx[k] = (histoEMDCorr[k]->GetXaxis())->GetNbins();
778b6939 506 //printf("\n\t Det%d -> BinMax = %d, ChXMax = %f\n", k+1, BinMax[k], BinMax[k]*YMax[k]/NBinsx[k]);
f16f149b 507 histoEMDCorr[k]->Fit("gaus","Q","",BinMax[k]*YMax[k]/NBinsx[k]*0.7,BinMax[k]*YMax[k]/NBinsx[k]*1.25);
508 fitfun[k] = histoEMDCorr[k]->GetFunction("gaus");
509 MeanFitVal[k] = (Float_t) (fitfun[k]->GetParameter(1));
c38bc7ef 510 //printf("\n\t Mean Value from gaussian fit = %f\n", MeanFitVal[k]);
f16f149b 511 }
512 //
218f916a 513 Float_t CalibCoeff[6];
218f916a 514 //
f9641c3b 515 for(Int_t j=0; j<6; j++){
218f916a 516 if(j<4){
517 CalibCoeff[j] = MeanFitVal[j];
f9641c3b 518 fprintf(fileShuttle1,"\t%f\n",CalibCoeff[j]);
218f916a 519 }
f9641c3b 520 // ZEM energy calib. coeff. = 1
218f916a 521 else if(j==4 || j==5){
522 CalibCoeff[j] = 1.;
f9641c3b 523 fprintf(fileShuttle1,"\t%f\n",CalibCoeff[j]);
218f916a 524 }
f9641c3b 525 }
526 fclose(fileShuttle1);
e968a349 527
f9641c3b 528 FILE *fileShuttle2 = fopen(TOWCALIBDATA_FILE,"w");
778b6939 529 //Float_t meanvalznc[4], meanvalzpc[4], meanvalzna[4], meanvalzpa[4];
f9641c3b 530 for(Int_t j=0; j<4; j++){
778b6939 531 /*if(histZNCtow[j]->GetEntries() == 0){
e968a349 532 printf("\n WARNING! Empty histos -> ending DA WITHOUT writing output\n\n");
533 return -1;
534 }
535 meanvalznc[j] = histZNCtow[j]->GetMean();
536 meanvalzpc[j] = histZPCtow[j]->GetMean();
537 meanvalzna[j] = histZNAtow[j]->GetMean();
778b6939 538 meanvalzpa[j] = histZPAtow[j]->GetMean();*/
e968a349 539
f9641c3b 540 // Note -> For the moment the inter-calibration coeff. are set to 1
144fb00e 541 for(Int_t k=0; k<5; k++){
778b6939 542 Float_t icoeff = 1.;
543 fprintf(fileShuttle2,"\t%f",icoeff);
144fb00e 544 if(k==5) fprintf(fileShuttle2,"\n");
778b6939 545 }
e968a349 546 }
778b6939 547 //
548 /*if(meanvalznc[1]!=0 && meanvalznc[2]!=0 && meanvalznc[3]!=0 &&
e968a349 549 meanvalzpc[1]!=0 && meanvalzpc[2]!=0 && meanvalzpc[3]!=0 &&
550 meanvalzna[1]!=0 && meanvalzna[2]!=0 && meanvalzna[3]!=0 &&
551 meanvalzpa[1]!=0 && meanvalzpa[2]!=0 && meanvalzpa[3]!=0){
552 fprintf(fileShuttle2,"\t%f\t%f\t%f\t%f\n",
553 1.0,meanvalznc[0]/meanvalznc[1],meanvalznc[0]/meanvalznc[2],meanvalznc[0]/meanvalznc[3]);
554 fprintf(fileShuttle2,"\t%f\t%f\t%f\t%f\n",
555 1.0,meanvalzpc[0]/meanvalzpc[1],meanvalzpc[0]/meanvalzpc[2],meanvalzpc[0]/meanvalzpc[3]);
556 fprintf(fileShuttle2,"\t%f\t%f\t%f\t%f\n",
557 1.0,meanvalzna[0]/meanvalzna[1],meanvalzpc[0]/meanvalzna[2],meanvalzpc[0]/meanvalzna[3]);
558 fprintf(fileShuttle2,"\t%f\t%f\t%f\t%f\n",
559 1.0,meanvalzpa[0]/meanvalzpa[1],meanvalzpc[0]/meanvalzpa[2],meanvalzpc[0]/meanvalzpa[3]);
560 }
561 else{
562 printf("\n Tower intercalib. coeff. CAN'T be calculated (some mean values are ZERO)!!!\n\n");
563 return -1;
778b6939 564 }*/
f9641c3b 565 fclose(fileShuttle2);
f16f149b 566
442e1b18 567 for(Int_t ij=0; ij<4; ij++){
8785e578 568 //delete histoEMDRaw[ij];
442e1b18 569 delete histoEMDCorr[ij];
570 }
571
572 //delete minuitFit;
573 TVirtualFitter::SetFitter(0);
f16f149b 574
575 /* write report */
576 fprintf(fp,"Run #%s, received %d physics events out of %d\n",getenv("DATE_RUN_NUMBER"),nevents_physics,nevents_total);
577
578 /* close result file */
579 fclose(fp);
442e1b18 580
581 /* report progress */
582 daqDA_progressReport(90);
583
584 /* store the result file on FES */
a8eaff64 585 status = daqDA_FES_storeFile(MAPDATA_FILE, "MAPPING");
442e1b18 586 if(status){
587 printf("Failed to export file : %d\n",status);
588 return -1;
589 }
590 //
a8eaff64 591 status = daqDA_FES_storeFile(ENCALIBDATA_FILE, "EMDENERGYCALIB");
f9641c3b 592 if(status){
593 printf("Failed to export file : %d\n",status);
594 return -1;
595 }
596 //
a8eaff64 597 status = daqDA_FES_storeFile(TOWCALIBDATA_FILE, "EMDTOWERCALIB");
442e1b18 598 if(status){
599 printf("Failed to export file : %d\n",status);
600 return -1;
601 }
f16f149b 602
442e1b18 603 /* report progress */
604 daqDA_progressReport(100);
f16f149b 605
606 return status;
607}