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