Error in DARC data reading corrected + message bit masking
[u/mrichter/AliRoot.git] / ZDC / ZDCPEDESTALda.cxx
CommitLineData
f3ca8792 1/*
2
039a08c3 3This program reads the DAQ data files passed as argument using the monitoring library.
4
039a08c3 5The program reports about its processing progress.
f3ca8792 6
7Messages on stdout are exported to DAQ log system.
8
b3b2b9dd 9DA for ZDC standalone pedestal runs
ea628de7 10
b3b2b9dd 11Contact: Chiara.Oppedisano@to.infn.it
442e1b18 12Link:
b3b2b9dd 13Run Type: STANDALONE_PEDESTAL_RUN
442e1b18 14DA Type: LDC
b3b2b9dd 15Number of events needed: no constraint (tipically ~10^3)
27afc0c8 16Input Files: none
442e1b18 17Output Files: ZDCPedestal.dat, ZDCChMapping.dat
b3b2b9dd 18Trigger Types Used: Standalone Trigger
f3ca8792 19
20*/
218f916a 21#define PEDDATA_FILE "ZDCPedestal.dat"
65448375 22#define PEDHISTO_FILE "ZDCPedHisto.root"
218f916a 23#define MAPDATA_FILE "ZDCChMapping.dat"
f3ca8792 24
25#include <stdio.h>
039a08c3 26#include <stdlib.h>
f3ca8792 27#include <Riostream.h>
28
29// DATE
f3ca8792 30#include <event.h>
31#include <monitor.h>
039a08c3 32#include <daqDA.h>
f3ca8792 33
34//ROOT
65448375 35#include <TROOT.h>
36#include <TPluginManager.h>
f3ca8792 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>
65448375 43#include "TMinuitMinimizer.h"
f3ca8792 44
45//AliRoot
46#include <AliRawReaderDate.h>
442e1b18 47#include <AliRawEventHeaderBase.h>
f3ca8792 48#include <AliZDCRawStream.h>
49
50
51/* Main routine
039a08c3 52 Arguments: list of DATE raw data files
f3ca8792 53*/
54int main(int argc, char **argv) {
442e1b18 55
65448375 56
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");
f3ca8792 67
039a08c3 68 int status = 0;
9d0b658a 69 int const kNChannels = 24;
c3986754 70 int const kNScChannels = 32;
71
72 Int_t ich=0;
73 Int_t adcMod[2*kNChannels], adcCh[2*kNChannels], sigCode[2*kNChannels];
74 Int_t det[2*kNChannels], sec[2*kNChannels];
75 for(Int_t y=0; y<2*kNChannels; y++){
76 adcMod[y]=adcCh[y]=sigCode[y]=det[y]=sec[y]=0;
77 }
039a08c3 78
79 /* log start of process */
63604324 80 printf("\n ZDC PEDESTAL program started\n");
039a08c3 81
82 /* check that we got some arguments = list of files */
65448375 83 if (argc<2){
039a08c3 84 printf("Wrong number of arguments\n");
85 return -1;
86 }
87
f3ca8792 88 // --- Histograms for ADC pedestals
b3b2b9dd 89 // [22 signal channels + 2 reference PTMs] x 2 gain chains
f3ca8792 90 //
039a08c3 91 TH1F::AddDirectory(0);
9d0b658a 92 //
b3b2b9dd 93 TH1F *hPedhg[kNChannels], *hPedOutOfTimehg[kNChannels];
94 TH2F *hPedCorrhg[kNChannels];
95 TH1F *hPedlg[kNChannels], *hPedOutOfTimelg[kNChannels];
96 TH2F *hPedCorrlg[kNChannels];
f3ca8792 97 //
b3b2b9dd 98 char namhist1hg[50], namhist2hg[50], namhist3hg[50];
99 char namhist1lg[50], namhist2lg[50], namhist3lg[50];
100 for(Int_t j=0; j<kNChannels; j++){
7f4bde92 101 if(j<=4){ // ZNC
102 sprintf(namhist1hg,"PedZNChg_%d",j);
103 sprintf(namhist2hg,"PedZNChgOutOfTime_%d",j);
104 sprintf(namhist3hg,"PedCorrZNChg_%d",j);
b3b2b9dd 105 //
7f4bde92 106 sprintf(namhist1lg,"PedZNClg_%d",j);
107 sprintf(namhist2lg,"PedZNClgOutOfTime_%d",j);
108 sprintf(namhist3lg,"PedCorrZNClg_%d",j);
b3b2b9dd 109 }
7f4bde92 110 else if(j>=5 && j<=9){ // ZPC
111 sprintf(namhist1hg,"PedZPChg_%d",j-5);
112 sprintf(namhist2hg,"PedZPChgOutOfTime_%d",j-5);
113 sprintf(namhist3hg,"PedCorrZPChg_%d",j-5);
b3b2b9dd 114 //
7f4bde92 115 sprintf(namhist1lg,"PedZPClg_%d",j-5);
116 sprintf(namhist2lg,"PedZPClgOutOfTime_%d",j-5);
117 sprintf(namhist3lg,"PedCorrZPClg_%d",j-5);
f3ca8792 118 }
7f4bde92 119 else if(j==10 || j==11){ // ZEM
b3b2b9dd 120 sprintf(namhist1hg,"PedZEMhg_%d",j-10);
121 sprintf(namhist2hg,"PedZEMhgOutOfTime_%d",j-10);
122 sprintf(namhist3hg,"PedCorrZEMhg_%d",j-10);
123 //
124 sprintf(namhist1lg,"PedZEMlg_%d",j-10);
125 sprintf(namhist2lg,"PedZEMlgOutOfTime_%d",j-10);
126 sprintf(namhist3lg,"PedCorrZEMlg_%d",j-10);
f3ca8792 127 }
7f4bde92 128 else if(j>=12 && j<=16){ // ZNA
129 sprintf(namhist1hg,"PedZNAhg_%d",j-12);
130 sprintf(namhist2hg,"PedZNAhgOutOfTime_%d",j-12);
131 sprintf(namhist3hg,"PedCorrZNAhg_%d",j-12);
b3b2b9dd 132 //
7f4bde92 133 sprintf(namhist1lg,"PedZNAlg_%d",j-12);
134 sprintf(namhist2lg,"PedZNAlgOutOfTime_%d",j-12);
135 sprintf(namhist3lg,"PedCorrZNAlg_%d",j-12);
f3ca8792 136 }
7f4bde92 137 else if(j>=17 && j<=21){ // ZPA
138 sprintf(namhist1hg,"PedZPAhg_%d",j-17);
139 sprintf(namhist2hg,"PedZPAhgOutOfTime_%d",j-17);
140 sprintf(namhist3hg,"PedCorrZPAhg_%d",j-17);
b3b2b9dd 141 //
7f4bde92 142 sprintf(namhist1lg,"PedZPAlg_%d",j-17);
143 sprintf(namhist2lg,"PedZPAlgOutOfTime_%d",j-17);
144 sprintf(namhist3lg,"PedCorrZPAlg_%d",j-17);
f3ca8792 145 }
7f4bde92 146 else if(j==22 || j==24){ //Reference PMs
b3b2b9dd 147 sprintf(namhist1hg,"PedRefhg_%d",j-22);
148 sprintf(namhist2hg,"PedRefhgOutOfTime_%d",j-22);
149 sprintf(namhist3hg,"PedCorrRefhg_%d",j-22);
150 //
151 sprintf(namhist1lg,"PedReflg_%d",j-22);
152 sprintf(namhist2lg,"PedReflgOutOfTime_%d",j-22);
153 sprintf(namhist3lg,"PedCorrReflg_%d",j-22);
f3ca8792 154 }
b3b2b9dd 155 // --- High gain chain histos
057ed567 156 hPedhg[j] = new TH1F(namhist1hg, namhist1hg, 200, 0., 200.);
157 hPedOutOfTimehg[j] = new TH1F(namhist2hg, namhist2hg, 200, 0., 200.);
b3b2b9dd 158 hPedCorrhg[j] = new TH2F(namhist3hg,namhist3hg,100,0.,200.,100,0.,200.);
159 // --- Low gain chain histos
057ed567 160 hPedlg[j] = new TH1F(namhist1lg, namhist1lg, 100, 0., 1000.);
161 hPedOutOfTimelg[j] = new TH1F(namhist2lg, namhist2lg, 100, 0., 1000.);
162 hPedCorrlg[j] = new TH2F(namhist3lg,namhist3lg,100,0.,1000.,100,0.,1000.);
f3ca8792 163 }
164
f3ca8792 165
166 /* open result file */
167 FILE *fp=NULL;
9d0b658a 168 fp=fopen("./result.txt","w");
f3ca8792 169 if (fp==NULL) {
170 printf("Failed to open file\n");
171 return -1;
172 }
173
442e1b18 174 FILE *mapFile4Shuttle;
f3ca8792 175
039a08c3 176 /* report progress */
177 daqDA_progressReport(10);
f3ca8792 178
f3ca8792 179
f3ca8792 180 /* init some counters */
181 int nevents_physics=0;
182 int nevents_total=0;
183
27afc0c8 184 struct eventHeaderStruct *event;
185 eventTypeType eventT;
186
039a08c3 187 /* read the data files */
188 int n;
442e1b18 189 for(n=1;n<argc;n++){
039a08c3 190
191 status=monitorSetDataSource( argv[n] );
f3ca8792 192 if (status!=0) {
039a08c3 193 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
194 return -1;
f3ca8792 195 }
196
039a08c3 197 /* report progress */
198 /* in this example, indexed on the number of files */
199 daqDA_progressReport(10+80*n/argc);
200
201 /* read the file */
202 for(;;) {
039a08c3 203
204 /* get next event */
205 status=monitorGetEventDynamic((void **)&event);
442e1b18 206 if(status==MON_ERR_EOF) break; /* end of monitoring file has been reached */
207 if(status!=0) {
039a08c3 208 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
209 return -1;
210 }
211
212 /* retry if got no event */
442e1b18 213 if(event==NULL) {
039a08c3 214 break;
215 }
442e1b18 216
217 // Initalize raw-data reading and decoding
218 AliRawReader *reader = new AliRawReaderDate((void*)event);
219 reader->Select("ZDC");
220 // --- Reading event header
221 //UInt_t evtype = reader->GetType();
222 //printf("\n\t ZDCPEDESTALda -> ev. type %d\n",evtype);
223 //printf("\t ZDCPEDESTALda -> run # %d\n",reader->GetRunNumber());
224 //
225 AliZDCRawStream *rawStreamZDC = new AliZDCRawStream(reader);
226
f3ca8792 227
039a08c3 228 /* use event - here, just write event id to result file */
229 eventT=event->eventType;
442e1b18 230
c3986754 231 Int_t iScCh=0;
27afc0c8 232 Int_t scMod[kNScChannels], scCh[kNScChannels], scSigCode[kNScChannels];
233 Int_t scDet[kNScChannels], scSec[kNScChannels];
234 for(Int_t y=0; y<kNScChannels; y++){
c3986754 235 scMod[y]=scCh[y]=scSigCode[y]=scDet[y]=scSec[y]=0;
236 }
237 //
238 Int_t modNum=-1, modType=-1;
7f4bde92 239
442e1b18 240 if(eventT==START_OF_DATA){
241
7f4bde92 242 rawStreamZDC->SetSODReading(kTRUE);
243
9d0b658a 244 // --------------------------------------------------------
245 // --- Writing ascii data file for the Shuttle preprocessor
246 mapFile4Shuttle = fopen(MAPDATA_FILE,"w");
442e1b18 247 if(!rawStreamZDC->Next()) printf(" \t No raw data found!! \n");
248 else{
c3986754 249 while((rawStreamZDC->Next())){
250 if(rawStreamZDC->IsHeaderMapping()){ // mapping header
251 modNum = rawStreamZDC->GetADCModule();
252 modType = rawStreamZDC->GetModType();
253 }
254 if(rawStreamZDC->IsChMapping()){
255 if(modType==1){ // ADC mapping ----------------------
256 adcMod[ich] = rawStreamZDC->GetADCModFromMap(ich);
257 adcCh[ich] = rawStreamZDC->GetADCChFromMap(ich);
258 sigCode[ich] = rawStreamZDC->GetADCSignFromMap(ich);
259 det[ich] = rawStreamZDC->GetDetectorFromMap(ich);
260 sec[ich] = rawStreamZDC->GetTowerFromMap(ich);
261 //
262 fprintf(mapFile4Shuttle,"\t%d\t%d\t%d\t%d\t%d\t%d\n",
263 ich,adcMod[ich],adcCh[ich],sigCode[ich],det[ich],sec[ich]);
264 //
265 //printf(" Mapping in DA -> %d ADC: mod %d ch %d, code %d det %d, sec %d\n",
266 // ich,adcMod[ich],adcCh[ich],sigCode[ich],det[ich],sec[ich]);
267 //
268 ich++;
269 }
270 else if(modType==2){ //VME scaler mapping --------------------
271 scMod[iScCh] = rawStreamZDC->GetScalerModFromMap(iScCh);
272 scCh[iScCh] = rawStreamZDC->GetScalerChFromMap(iScCh);
273 scSigCode[iScCh] = rawStreamZDC->GetScalerSignFromMap(iScCh);
274 scDet[iScCh] = rawStreamZDC->GetScDetectorFromMap(iScCh);
275 scSec[iScCh] = rawStreamZDC->GetScTowerFromMap(iScCh);
276 //
277 fprintf(mapFile4Shuttle,"\t%d\t%d\t%d\t%d\t%d\t%d\n",
278 iScCh,scMod[iScCh],scCh[iScCh],scSigCode[iScCh],scDet[iScCh],scSec[iScCh]);
279 //
280 //printf(" Mapping in DA -> %d Scaler: mod %d ch %d, code %d det %d, sec %d\n",
281 // iScCh,scMod[iScCh],scCh[iScCh],scSigCode[iScCh],scDet[iScCh],scSec[iScCh]);
282 //
283 iScCh++;
284 }
442e1b18 285 }
286 }
287 }
442e1b18 288 fclose(mapFile4Shuttle);
9d0b658a 289 }// SOD event
442e1b18 290
d3f256ca 291 else if(eventT==PHYSICS_EVENT){
442e1b18 292 // --- Reading data header
293 reader->ReadHeader();
039a08c3 294 const AliRawDataHeader* header = reader->GetDataHeader();
442e1b18 295 if(header){
b3b2b9dd 296 UChar_t message = header->GetAttributes();
a5747d8f 297 if((message & 0x20) == 0x20){ // PEDESTAL RUN
442e1b18 298 //printf("\t STANDALONE_PEDESTAL RUN raw data found\n");
299 }
300 else{
27afc0c8 301 printf("ZDCPEDESTALda.cxx -> NO STANDALONE_PEDESTAL RUN raw data found\n");
a5747d8f 302 printf(" Attributes: %x\n", message);
27afc0c8 303 return -1;
442e1b18 304 }
305 }
306 else{
307 printf("\t ATTENTION! No Raw Data Header found!!!\n");
308 return -1;
309 }
7f4bde92 310
311 rawStreamZDC->SetSODReading(kTRUE);
442e1b18 312
313 if(!rawStreamZDC->Next()) printf(" \t No raw data found!! \n");
314 //
315 // ----- Setting ch. mapping -----
9d0b658a 316 for(Int_t jk=0; jk<2*kNChannels; jk++){
7f4bde92 317 //printf("ZDCPEDESTALDA.cxx -> ch.%d mod %d, ch %d, code %d det %d, sec %d\n",
318 // jk,adcMod[jk],adcCh[jk],sigCode[jk],det[jk],sec[jk]);
442e1b18 319 rawStreamZDC->SetMapADCMod(jk, adcMod[jk]);
320 rawStreamZDC->SetMapADCCh(jk, adcCh[jk]);
321 rawStreamZDC->SetMapADCSig(jk, sigCode[jk]);
322 rawStreamZDC->SetMapDet(jk, det[jk]);
323 rawStreamZDC->SetMapTow(jk, sec[jk]);
324 }
325 //
326 Int_t iraw=0;
039a08c3 327 Int_t RawADChg[kNChannels], RawADCoothg[kNChannels];
328 Int_t RawADClg[kNChannels], RawADCootlg[kNChannels];
329 for(Int_t j=0; j<kNChannels; j++){
330 RawADChg[j]=0; RawADCoothg[j]=0;
331 RawADClg[j]=0; RawADCootlg[j]=0;
332 }
442e1b18 333 //
039a08c3 334 while(rawStreamZDC->Next()){
442e1b18 335 Int_t index=-1;
7f4bde92 336 Int_t detector = rawStreamZDC->GetSector(0);
9d0b658a 337 Int_t sector = rawStreamZDC->GetSector(1);
a5747d8f 338 //
339 //printf(" rawData: det %d sec %d value %d\n",
340 // detector, sector,rawStreamZDC->GetADCGain(),rawStreamZDC->GetADCValue() );
9d0b658a 341
7f4bde92 342 if(rawStreamZDC->IsADCDataWord() && (detector!=-1)){
9d0b658a 343 if(sector!=5){ // Physics signals
344 if(detector==1) index = sector; // *** ZNC
345 else if(detector==2) index = sector+5; // *** ZPC
346 else if(detector==3) index = sector+9; // *** ZEM
347 else if(detector==4) index = sector+12; // *** ZNA
348 else if(detector==5) index = sector+17; // *** ZPA
f3ca8792 349 }
b3b2b9dd 350 else{ // Reference PMs
7f4bde92 351 index = (detector-1)/3+22;
f3ca8792 352 }
b3b2b9dd 353 //
c3986754 354 if(index==-1) printf("ERROR in ZDCPEDESTALda.cxx -> det %d quad %d index %d \n",
355 detector,sector,index);
7f4bde92 356
442e1b18 357 //
358 if(iraw<2*kNChannels){ // --- In-time pedestals (1st 48 raw data)
b3b2b9dd 359 if(rawStreamZDC->GetADCGain()==0){
360 hPedhg[index]->Fill(rawStreamZDC->GetADCValue());
361 RawADChg[index] = rawStreamZDC->GetADCValue();
442e1b18 362 //
363 //printf("\t filling histo hPedhg[%d]\n",index);
b3b2b9dd 364 }
365 else{
366 hPedlg[index]->Fill(rawStreamZDC->GetADCValue());
367 RawADClg[index] = rawStreamZDC->GetADCValue();
442e1b18 368 //
369 //printf("\t filling histo hPedlg[%d]\n",index);
b3b2b9dd 370 }
442e1b18 371 }
372 else{ // --- Out-of-time pedestals
373 if(rawStreamZDC->GetADCGain()==0){
374 hPedOutOfTimehg[index]->Fill(rawStreamZDC->GetADCValue());
375 RawADCoothg[index] = rawStreamZDC->GetADCValue();
376 //
377 //printf("\t filling histo hPedOutOfTimehg[%d]\n",index);
039a08c3 378 }
442e1b18 379 else{
380 hPedOutOfTimelg[index]->Fill(rawStreamZDC->GetADCValue());
381 RawADCootlg[index] = rawStreamZDC->GetADCValue();
382 //
383 //printf("\t filling histo hPedOutOfTimelg[%d]\n",index);
039a08c3 384 }
442e1b18 385 }
386 iraw++;
387 }//IsADCDataWord()
388 //
389 if(iraw == 4*kNChannels){ // Last ADC channel -> Filling correlation histos
390 for(Int_t k=0; k<kNChannels; k++){
039a08c3 391 hPedCorrhg[k]->Fill(RawADCoothg[k], RawADChg[k]);
392 hPedCorrlg[k]->Fill(RawADCootlg[k], RawADClg[k]);
442e1b18 393 }
394 }
d3f256ca 395 }
396 nevents_physics++;
397 //
398 delete reader;
399 delete rawStreamZDC;
039a08c3 400
401 }//(if PHYSICS_EVENT)
d3f256ca 402
403 /* exit when last event received, no need to wait for TERM signal */
404 else if(eventT==END_OF_RUN) {
405 printf(" -> EOR event detected\n");
406 break;
407 }
408
039a08c3 409 nevents_total++;
f3ca8792 410
f3ca8792 411 }
d3f256ca 412
413 /* free resources */
414 free(event);
039a08c3 415 }
f3ca8792 416
417 /* Analysis of the histograms */
418 //
419 FILE *fileShuttle;
218f916a 420 fileShuttle = fopen(PEDDATA_FILE,"w");
f3ca8792 421 //
b3b2b9dd 422 Float_t MeanPed[2*kNChannels], MeanPedWidth[2*kNChannels],
63604324 423 MeanPedOOT[2*kNChannels], MeanPedWidthOOT[2*kNChannels];
b3b2b9dd 424 // --- In-time pedestals
425 TF1 *ADCfunchg[kNChannels];
426 for(Int_t i=0; i<kNChannels; i++){
f9641c3b 427 if(hPedhg[i]->GetEntries() == 0){
428 printf("\n WARNING! Empty histos -> ending DA WITHOUT writing output\n\n");
429 return -1;
430 }
b3b2b9dd 431 hPedhg[i]->Fit("gaus","Q");
432 ADCfunchg[i] = hPedhg[i]->GetFunction("gaus");
442e1b18 433 MeanPed[i] = (Double_t) ADCfunchg[i]->GetParameter(1);
434 MeanPedWidth[i] = (Double_t) ADCfunchg[i]->GetParameter(2);
218f916a 435 fprintf(fileShuttle,"\t%f\t%f\n",MeanPed[i],MeanPedWidth[i]);
057ed567 436 //printf("\t MeanPedhg[%d] = %f\n",i, MeanPed[i]);
b3b2b9dd 437 }
438 TF1 *ADCfunclg[kNChannels];
439 for(Int_t i=0; i<kNChannels; i++){
440 hPedlg[i]->Fit("gaus","Q");
441 ADCfunclg[i] = hPedlg[i]->GetFunction("gaus");
442e1b18 442 MeanPed[i+kNChannels] = (Double_t) ADCfunclg[i]->GetParameter(1);
443 MeanPedWidth[i+kNChannels] = (Double_t) ADCfunclg[i]->GetParameter(2);
218f916a 444 fprintf(fileShuttle,"\t%f\t%f\n",MeanPed[i+kNChannels],MeanPedWidth[i+kNChannels]);
057ed567 445 //printf("\t MeanPedlg[%d] = %f\n",i+kNChannels, MeanPed[i+kNChannels]);
f3ca8792 446 }
447 // --- Out-of-time pedestals
b3b2b9dd 448 TF1 *ADCootfunchg[kNChannels];
449 for(Int_t i=0; i<kNChannels; i++){
3d155339 450 if(hPedOutOfTimehg[i]->GetEntries() == 0){
a5747d8f 451 printf("\n WARNING! Empty histos for out-of-time channels!!!\n\n");
3d155339 452 return -1;
453 }
b3b2b9dd 454 hPedOutOfTimehg[i]->Fit("gaus","Q");
455 ADCootfunchg[i] = hPedOutOfTimehg[i]->GetFunction("gaus");
442e1b18 456 MeanPedOOT[i] = (Double_t) ADCootfunchg[i]->GetParameter(1);
457 MeanPedWidthOOT[i] = (Double_t) ADCootfunchg[i]->GetParameter(2);
218f916a 458 fprintf(fileShuttle,"\t%f\t%f\n",MeanPedOOT[i],MeanPedWidthOOT[i]);
057ed567 459 //printf("\t MeanPedOOThg[%d] = %f\n",i, MeanPedOOT[i]);
b3b2b9dd 460 }
461 TF1 *ADCootfunclg[kNChannels];
462 for(Int_t i=0; i<kNChannels; i++){
463 hPedOutOfTimelg[i]->Fit("gaus","Q");
464 ADCootfunclg[i] = hPedOutOfTimelg[i]->GetFunction("gaus");
442e1b18 465 MeanPedOOT[i+kNChannels] = (Double_t) ADCootfunclg[i]->GetParameter(1);
466 MeanPedWidthOOT[i+kNChannels] = (Double_t) ADCootfunclg[i]->GetParameter(2);
218f916a 467 fprintf(fileShuttle,"\t%f\t%f\n",MeanPedOOT[i+kNChannels],MeanPedWidthOOT[i+kNChannels]);
057ed567 468 //printf("\t MeanPedOOTlg[%d] = %f\n",i+kNChannels, MeanPedOOT[i+kNChannels]);
f3ca8792 469 }
63604324 470
b3b2b9dd 471 // --- Correlations
9d0b658a 472
27afc0c8 473 Float_t CorrCoeff0[2*kNChannels], CorrCoeff1[2*kNChannels];
b3b2b9dd 474 TProfile *hPedCorrProfhg[kNChannels], *hPedCorrProflg[kNChannels];
475 TF1 *ffunchg[kNChannels], *ffunclg[kNChannels];
f3ca8792 476 char namhist4[50];
b3b2b9dd 477 for(int i=0;i<kNChannels;i++) {
478 sprintf(namhist4,"ADCHRvsOOT%d_Prof",i);
479 hPedCorrProfhg[i] = hPedCorrhg[i]->ProfileX(namhist4,-1,-1,"S");
480 hPedCorrProfhg[i]->SetName(namhist4);
481 hPedCorrProfhg[i]->Fit("pol1","Q");
482 ffunchg[i] = hPedCorrProfhg[i]->GetFunction("pol1");
442e1b18 483 CorrCoeff0[i] = (Double_t) ffunchg[i]->GetParameter(0);
484 CorrCoeff1[i] = (Double_t) ffunchg[i]->GetParameter(1);
9d0b658a 485 fprintf(fileShuttle,"\t%f\t%f\n",CorrCoeff0[i],CorrCoeff1[i]);
ea628de7 486 //printf("\t CorrCoeff0[%d] = %f, CorrCoeff1[%d] = %f\n",i, CorrCoeff0[i], i, CorrCoeff1[i]);
b3b2b9dd 487 }
488 for(int i=0;i<kNChannels;i++) {
489 sprintf(namhist4,"ADCLRvsOOT%d_Prof",i);
490 hPedCorrProflg[i] = hPedCorrlg[i]->ProfileX(namhist4,-1,-1,"S");
491 hPedCorrProflg[i]->SetName(namhist4);
492 hPedCorrProflg[i]->Fit("pol1","Q");
493 ffunclg[i] = hPedCorrProflg[i]->GetFunction("pol1");
442e1b18 494 CorrCoeff0[i+kNChannels] = (Double_t) ffunclg[i]->GetParameter(0);
495 CorrCoeff1[i+kNChannels] = (Double_t) ffunclg[i]->GetParameter(1);
9d0b658a 496 fprintf(fileShuttle,"\t%f\t%f\n",CorrCoeff0[i+kNChannels],CorrCoeff1[i+kNChannels]);
ea628de7 497 //printf("\t CorrCoeff0[%d] = %f, CorrCoeff1[%d] = %f\n",
498 // i+kNChannels, CorrCoeff0[i+kNChannels], i+kNChannels, CorrCoeff1[i+kNChannels]);
f3ca8792 499 }
27afc0c8 500
f3ca8792 501 //
502 fclose(fileShuttle);
b3b2b9dd 503 //
65448375 504 /* report progress */
505 daqDA_progressReport(80);
506 //
507 TFile *histofile = new TFile(PEDHISTO_FILE,"RECREATE");
508 histofile->cd();
509 for(int k=0; k<kNChannels; k++){
510 hPedhg[k]->Write();
511 hPedOutOfTimehg[k]->Write();
512 hPedCorrhg[k]->Write();
513 hPedlg[k]->Write();
514 hPedOutOfTimelg[k]->Write();
515 hPedCorrlg[k]->Write();
516 }
517 //
518 histofile->Close();
519 //
039a08c3 520 for(Int_t j=0; j<kNChannels; j++){
521 delete hPedhg[j];
522 delete hPedOutOfTimehg[j];
523 delete hPedCorrhg[j];
524 delete hPedlg[j];
525 delete hPedOutOfTimelg[j];
526 delete hPedCorrlg[j];
527 }
f3ca8792 528
529 /* write report */
530 fprintf(fp,"Run #%s, received %d physics events out of %d\n",getenv("DATE_RUN_NUMBER"),nevents_physics,nevents_total);
531
532 /* close result file */
533 fclose(fp);
039a08c3 534
535 /* report progress */
536 daqDA_progressReport(90);
537
442e1b18 538 /* store the result files on FES */
63604324 539 // [1] File with mapping
a8eaff64 540 status = daqDA_FES_storeFile(MAPDATA_FILE, "MAPPING");
442e1b18 541 if(status){
65448375 542 printf("Failed to export mapping data file to DAQ FES\n");
442e1b18 543 return -1;
544 }
63604324 545 // [2] File with pedestal data
a8eaff64 546 status = daqDA_FES_storeFile(PEDDATA_FILE, "PEDESTALDATA");
039a08c3 547 if(status){
65448375 548 printf("Failed to export pedestal data file to DAQ FES\n");
549 return -1;
550 }
551 // [3] File with pedestal histos
a8eaff64 552 status = daqDA_FES_storeFile(PEDHISTO_FILE, "PEDESTALHISTOS");
65448375 553 if(status){
554 printf("Failed to export pedestal histos file to DAQ FES\n");
63604324 555 return -1;
556 }
557
558 /* store the result files on DB */
a8eaff64 559 status = daqDA_DB_storeFile(PEDDATA_FILE, PEDDATA_FILE);
63604324 560 if(status){
65448375 561 printf("Failed to store pedestal data file to DAQ DB\n");
039a08c3 562 return -1;
563 }
564
565 /* report progress */
566 daqDA_progressReport(100);
f3ca8792 567
f3ca8792 568 return status;
569}