]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ZDC/ZDCPEDESTALda.cxx
Fixing problem in QA checker for 2011 RUN
[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;
198f612a 69 int const kNModules = 10;
9d0b658a 70 int const kNChannels = 24;
c3986754 71 int const kNScChannels = 32;
8700404e 72 Int_t kFirstADCGeo=0, kLastADCGeo=3;
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 }
c3986754 79
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 }
100
039a08c3 101
102 /* log start of process */
63604324 103 printf("\n ZDC PEDESTAL program started\n");
039a08c3 104
105 /* check that we got some arguments = list of files */
65448375 106 if (argc<2){
039a08c3 107 printf("Wrong number of arguments\n");
108 return -1;
109 }
110
f3ca8792 111 // --- Histograms for ADC pedestals
b3b2b9dd 112 // [22 signal channels + 2 reference PTMs] x 2 gain chains
f3ca8792 113 //
039a08c3 114 TH1F::AddDirectory(0);
9d0b658a 115 //
b3b2b9dd 116 TH1F *hPedhg[kNChannels], *hPedOutOfTimehg[kNChannels];
117 TH2F *hPedCorrhg[kNChannels];
118 TH1F *hPedlg[kNChannels], *hPedOutOfTimelg[kNChannels];
119 TH2F *hPedCorrlg[kNChannels];
f3ca8792 120 //
b3b2b9dd 121 char namhist1hg[50], namhist2hg[50], namhist3hg[50];
122 char namhist1lg[50], namhist2lg[50], namhist3lg[50];
123 for(Int_t j=0; j<kNChannels; j++){
7f4bde92 124 if(j<=4){ // ZNC
125 sprintf(namhist1hg,"PedZNChg_%d",j);
126 sprintf(namhist2hg,"PedZNChgOutOfTime_%d",j);
127 sprintf(namhist3hg,"PedCorrZNChg_%d",j);
b3b2b9dd 128 //
7f4bde92 129 sprintf(namhist1lg,"PedZNClg_%d",j);
130 sprintf(namhist2lg,"PedZNClgOutOfTime_%d",j);
131 sprintf(namhist3lg,"PedCorrZNClg_%d",j);
b3b2b9dd 132 }
7f4bde92 133 else if(j>=5 && j<=9){ // ZPC
134 sprintf(namhist1hg,"PedZPChg_%d",j-5);
135 sprintf(namhist2hg,"PedZPChgOutOfTime_%d",j-5);
136 sprintf(namhist3hg,"PedCorrZPChg_%d",j-5);
b3b2b9dd 137 //
7f4bde92 138 sprintf(namhist1lg,"PedZPClg_%d",j-5);
139 sprintf(namhist2lg,"PedZPClgOutOfTime_%d",j-5);
140 sprintf(namhist3lg,"PedCorrZPClg_%d",j-5);
f3ca8792 141 }
7f4bde92 142 else if(j==10 || j==11){ // ZEM
3018cd7f 143 sprintf(namhist1hg,"PedZEMhg_%d",j-9);
144 sprintf(namhist2hg,"PedZEMhgOutOfTime_%d",j-9);
145 sprintf(namhist3hg,"PedCorrZEMhg_%d",j-9);
b3b2b9dd 146 //
3018cd7f 147 sprintf(namhist1lg,"PedZEMlg_%d",j-9);
148 sprintf(namhist2lg,"PedZEMlgOutOfTime_%d",j-9);
149 sprintf(namhist3lg,"PedCorrZEMlg_%d",j-9);
f3ca8792 150 }
7f4bde92 151 else if(j>=12 && j<=16){ // ZNA
152 sprintf(namhist1hg,"PedZNAhg_%d",j-12);
153 sprintf(namhist2hg,"PedZNAhgOutOfTime_%d",j-12);
154 sprintf(namhist3hg,"PedCorrZNAhg_%d",j-12);
b3b2b9dd 155 //
7f4bde92 156 sprintf(namhist1lg,"PedZNAlg_%d",j-12);
157 sprintf(namhist2lg,"PedZNAlgOutOfTime_%d",j-12);
158 sprintf(namhist3lg,"PedCorrZNAlg_%d",j-12);
f3ca8792 159 }
7f4bde92 160 else if(j>=17 && j<=21){ // ZPA
161 sprintf(namhist1hg,"PedZPAhg_%d",j-17);
162 sprintf(namhist2hg,"PedZPAhgOutOfTime_%d",j-17);
163 sprintf(namhist3hg,"PedCorrZPAhg_%d",j-17);
b3b2b9dd 164 //
7f4bde92 165 sprintf(namhist1lg,"PedZPAlg_%d",j-17);
166 sprintf(namhist2lg,"PedZPAlgOutOfTime_%d",j-17);
167 sprintf(namhist3lg,"PedCorrZPAlg_%d",j-17);
f3ca8792 168 }
07b2ecec 169 else if(j==22 || j==23){ //Reference PMs
b3b2b9dd 170 sprintf(namhist1hg,"PedRefhg_%d",j-22);
171 sprintf(namhist2hg,"PedRefhgOutOfTime_%d",j-22);
172 sprintf(namhist3hg,"PedCorrRefhg_%d",j-22);
173 //
174 sprintf(namhist1lg,"PedReflg_%d",j-22);
175 sprintf(namhist2lg,"PedReflgOutOfTime_%d",j-22);
176 sprintf(namhist3lg,"PedCorrReflg_%d",j-22);
f3ca8792 177 }
b3b2b9dd 178 // --- High gain chain histos
057ed567 179 hPedhg[j] = new TH1F(namhist1hg, namhist1hg, 200, 0., 200.);
180 hPedOutOfTimehg[j] = new TH1F(namhist2hg, namhist2hg, 200, 0., 200.);
b3b2b9dd 181 hPedCorrhg[j] = new TH2F(namhist3hg,namhist3hg,100,0.,200.,100,0.,200.);
182 // --- Low gain chain histos
02ef9013 183 hPedlg[j] = new TH1F(namhist1lg, namhist1lg, 100, 0., 1500.);
184 hPedOutOfTimelg[j] = new TH1F(namhist2lg, namhist2lg, 100, 0., 1500.);
185 hPedCorrlg[j] = new TH2F(namhist3lg,namhist3lg,100,0.,1500.,100,0.,1500.);
f3ca8792 186 }
187
f3ca8792 188
189 /* open result file */
190 FILE *fp=NULL;
9d0b658a 191 fp=fopen("./result.txt","w");
f3ca8792 192 if (fp==NULL) {
193 printf("Failed to open file\n");
194 return -1;
195 }
196
442e1b18 197 FILE *mapFile4Shuttle;
f3ca8792 198
039a08c3 199 /* report progress */
200 daqDA_progressReport(10);
f3ca8792 201
f3ca8792 202
f3ca8792 203 /* init some counters */
204 int nevents_physics=0;
205 int nevents_total=0;
206
27afc0c8 207 struct eventHeaderStruct *event;
208 eventTypeType eventT;
209
039a08c3 210 /* read the data files */
211 int n;
442e1b18 212 for(n=1;n<argc;n++){
039a08c3 213
214 status=monitorSetDataSource( argv[n] );
f3ca8792 215 if (status!=0) {
039a08c3 216 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
217 return -1;
f3ca8792 218 }
219
039a08c3 220 /* report progress */
221 /* in this example, indexed on the number of files */
222 daqDA_progressReport(10+80*n/argc);
223
224 /* read the file */
225 for(;;) {
039a08c3 226
227 /* get next event */
228 status=monitorGetEventDynamic((void **)&event);
442e1b18 229 if(status==MON_ERR_EOF) break; /* end of monitoring file has been reached */
230 if(status!=0) {
039a08c3 231 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
232 return -1;
233 }
234
235 /* retry if got no event */
442e1b18 236 if(event==NULL) {
039a08c3 237 break;
238 }
442e1b18 239
240 // Initalize raw-data reading and decoding
241 AliRawReader *reader = new AliRawReaderDate((void*)event);
242 reader->Select("ZDC");
243 // --- Reading event header
244 //UInt_t evtype = reader->GetType();
245 //printf("\n\t ZDCPEDESTALda -> ev. type %d\n",evtype);
246 //printf("\t ZDCPEDESTALda -> run # %d\n",reader->GetRunNumber());
247 //
248 AliZDCRawStream *rawStreamZDC = new AliZDCRawStream(reader);
249
f3ca8792 250
039a08c3 251 /* use event - here, just write event id to result file */
252 eventT=event->eventType;
442e1b18 253
442e1b18 254 if(eventT==START_OF_DATA){
198f612a 255
82dffa48 256 iMod=-1; ich=0; iScCh=0; itdcCh=0;
198f612a 257
7f4bde92 258 rawStreamZDC->SetSODReading(kTRUE);
259
9d0b658a 260 // --------------------------------------------------------
261 // --- Writing ascii data file for the Shuttle preprocessor
262 mapFile4Shuttle = fopen(MAPDATA_FILE,"w");
442e1b18 263 if(!rawStreamZDC->Next()) printf(" \t No raw data found!! \n");
264 else{
c3986754 265 while((rawStreamZDC->Next())){
266 if(rawStreamZDC->IsHeaderMapping()){ // mapping header
198f612a 267 iMod++;
268 modGeo[iMod] = rawStreamZDC->GetADCModule();
269 modType[iMod] = rawStreamZDC->GetModType();
270 modNCh[iMod] = rawStreamZDC->GetADCNChannels();
c3986754 271 }
272 if(rawStreamZDC->IsChMapping()){
198f612a 273 if(modType[iMod]==1){ // ADC mapping ----------------------
c3986754 274 adcMod[ich] = rawStreamZDC->GetADCModFromMap(ich);
275 adcCh[ich] = rawStreamZDC->GetADCChFromMap(ich);
276 sigCode[ich] = rawStreamZDC->GetADCSignFromMap(ich);
277 det[ich] = rawStreamZDC->GetDetectorFromMap(ich);
278 sec[ich] = rawStreamZDC->GetTowerFromMap(ich);
c3986754 279 ich++;
280 }
198f612a 281 else if(modType[iMod]==2){ //VME scaler mapping --------------------
c3986754 282 scMod[iScCh] = rawStreamZDC->GetScalerModFromMap(iScCh);
283 scCh[iScCh] = rawStreamZDC->GetScalerChFromMap(iScCh);
284 scSigCode[iScCh] = rawStreamZDC->GetScalerSignFromMap(iScCh);
285 scDet[iScCh] = rawStreamZDC->GetScDetectorFromMap(iScCh);
198f612a 286 scSec[iScCh] = rawStreamZDC->GetScTowerFromMap(iScCh);
c3986754 287 iScCh++;
288 }
82dffa48 289 else if(modType[iMod]==6 && modGeo[iMod]==4){ // ZDC TDC mapping --------------------
290 tdcMod[itdcCh] = rawStreamZDC->GetTDCModFromMap(itdcCh);
291 tdcCh[itdcCh] = rawStreamZDC->GetTDCChFromMap(itdcCh);
292 tdcSigCode[itdcCh] = rawStreamZDC->GetTDCSignFromMap(itdcCh);
293 itdcCh++;
294 }
442e1b18 295 }
198f612a 296 }
297 // Writing data on output FXS file
198f612a 298 for(Int_t is=0; is<2*kNChannels; is++){
299 fprintf(mapFile4Shuttle,"\t%d\t%d\t%d\t%d\t%d\t%d\n",
300 is,adcMod[is],adcCh[is],sigCode[is],det[is],sec[is]);
301 //printf(" Pedestal DA -> %d ADC: mod %d ch %d, code %d det %d, sec %d\n",
302 // is,adcMod[is],adcCh[is],sigCode[is],det[is],sec[is]);
303 }
304 for(Int_t is=0; is<kNScChannels; is++){
305 fprintf(mapFile4Shuttle,"\t%d\t%d\t%d\t%d\t%d\t%d\n",
306 is,scMod[is],scCh[is],scSigCode[is],scDet[is],scSec[is]);
307 //printf(" Pedestal DA -> %d Scaler: mod %d ch %d, code %d det %d, sec %d\n",
308 // is,scMod[is],scCh[is],scSigCode[is],scDet[is],scSec[is]);
442e1b18 309 }
82dffa48 310 for(Int_t is=0; is<kNScChannels; is++){
311 fprintf(mapFile4Shuttle,"\t%d\t%d\t%d\t%d\n",
312 is,tdcMod[is],tdcCh[is],tdcSigCode[is]);
313 //if(tdcMod[is]!=-1) printf(" Mapping DA -> %d TDC: mod %d ch %d, code %d\n",
314 // is,tdcMod[is],tdcCh[is],tdcSigCode[is]);
315 }
608444fb 316 for(Int_t is=0; is<kNModules; is++){
317 fprintf(mapFile4Shuttle,"\t%d\t%d\t%d\n",
318 modGeo[is],modType[is],modNCh[is]);
319 //printf(" Pedestal DA -> Module mapping: geo %d type %d #ch %d\n",
320 // modGeo[is],modType[is],modNCh[is]);
321 }
198f612a 322
442e1b18 323 }
442e1b18 324 fclose(mapFile4Shuttle);
9d0b658a 325 }// SOD event
442e1b18 326
d3f256ca 327 else if(eventT==PHYSICS_EVENT){
442e1b18 328 // --- Reading data header
329 reader->ReadHeader();
039a08c3 330 const AliRawDataHeader* header = reader->GetDataHeader();
442e1b18 331 if(header){
b3b2b9dd 332 UChar_t message = header->GetAttributes();
a5747d8f 333 if((message & 0x20) == 0x20){ // PEDESTAL RUN
442e1b18 334 //printf("\t STANDALONE_PEDESTAL RUN raw data found\n");
335 }
336 else{
27afc0c8 337 printf("ZDCPEDESTALda.cxx -> NO STANDALONE_PEDESTAL RUN raw data found\n");
8700404e 338 printf(" CDH attributes: %x\n", message);
27afc0c8 339 return -1;
442e1b18 340 }
341 }
342 else{
343 printf("\t ATTENTION! No Raw Data Header found!!!\n");
344 return -1;
345 }
7f4bde92 346
347 rawStreamZDC->SetSODReading(kTRUE);
442e1b18 348
349 if(!rawStreamZDC->Next()) printf(" \t No raw data found!! \n");
350 //
351 // ----- Setting ch. mapping -----
9d0b658a 352 for(Int_t jk=0; jk<2*kNChannels; jk++){
7f4bde92 353 //printf("ZDCPEDESTALDA.cxx -> ch.%d mod %d, ch %d, code %d det %d, sec %d\n",
354 // jk,adcMod[jk],adcCh[jk],sigCode[jk],det[jk],sec[jk]);
442e1b18 355 rawStreamZDC->SetMapADCMod(jk, adcMod[jk]);
356 rawStreamZDC->SetMapADCCh(jk, adcCh[jk]);
357 rawStreamZDC->SetMapADCSig(jk, sigCode[jk]);
358 rawStreamZDC->SetMapDet(jk, det[jk]);
359 rawStreamZDC->SetMapTow(jk, sec[jk]);
360 }
361 //
362 Int_t iraw=0;
039a08c3 363 Int_t RawADChg[kNChannels], RawADCoothg[kNChannels];
364 Int_t RawADClg[kNChannels], RawADCootlg[kNChannels];
365 for(Int_t j=0; j<kNChannels; j++){
366 RawADChg[j]=0; RawADCoothg[j]=0;
367 RawADClg[j]=0; RawADCootlg[j]=0;
368 }
442e1b18 369 //
039a08c3 370 while(rawStreamZDC->Next()){
442e1b18 371 Int_t index=-1;
7f4bde92 372 Int_t detector = rawStreamZDC->GetSector(0);
9d0b658a 373 Int_t sector = rawStreamZDC->GetSector(1);
a5747d8f 374 //
375 //printf(" rawData: det %d sec %d value %d\n",
376 // detector, sector,rawStreamZDC->GetADCGain(),rawStreamZDC->GetADCValue() );
9d0b658a 377
8700404e 378 if((rawStreamZDC->IsADCDataWord()) && (detector!=-1) &&
379 (rawStreamZDC->GetADCModule()>=kFirstADCGeo && rawStreamZDC->GetADCModule()<=kLastADCGeo)){
9d0b658a 380 if(sector!=5){ // Physics signals
381 if(detector==1) index = sector; // *** ZNC
382 else if(detector==2) index = sector+5; // *** ZPC
383 else if(detector==3) index = sector+9; // *** ZEM
384 else if(detector==4) index = sector+12; // *** ZNA
385 else if(detector==5) index = sector+17; // *** ZPA
f3ca8792 386 }
b3b2b9dd 387 else{ // Reference PMs
7f4bde92 388 index = (detector-1)/3+22;
f3ca8792 389 }
b3b2b9dd 390 //
c3986754 391 if(index==-1) printf("ERROR in ZDCPEDESTALda.cxx -> det %d quad %d index %d \n",
392 detector,sector,index);
7f4bde92 393
442e1b18 394 //
395 if(iraw<2*kNChannels){ // --- In-time pedestals (1st 48 raw data)
b3b2b9dd 396 if(rawStreamZDC->GetADCGain()==0){
397 hPedhg[index]->Fill(rawStreamZDC->GetADCValue());
398 RawADChg[index] = rawStreamZDC->GetADCValue();
442e1b18 399 //
400 //printf("\t filling histo hPedhg[%d]\n",index);
b3b2b9dd 401 }
402 else{
403 hPedlg[index]->Fill(rawStreamZDC->GetADCValue());
404 RawADClg[index] = rawStreamZDC->GetADCValue();
442e1b18 405 //
406 //printf("\t filling histo hPedlg[%d]\n",index);
b3b2b9dd 407 }
442e1b18 408 }
409 else{ // --- Out-of-time pedestals
410 if(rawStreamZDC->GetADCGain()==0){
411 hPedOutOfTimehg[index]->Fill(rawStreamZDC->GetADCValue());
412 RawADCoothg[index] = rawStreamZDC->GetADCValue();
413 //
414 //printf("\t filling histo hPedOutOfTimehg[%d]\n",index);
039a08c3 415 }
442e1b18 416 else{
417 hPedOutOfTimelg[index]->Fill(rawStreamZDC->GetADCValue());
418 RawADCootlg[index] = rawStreamZDC->GetADCValue();
419 //
420 //printf("\t filling histo hPedOutOfTimelg[%d]\n",index);
039a08c3 421 }
442e1b18 422 }
423 iraw++;
424 }//IsADCDataWord()
d3f256ca 425 }
5aa49948 426 //
427 if(iraw==4*kNChannels ){ // Last ADC channel -> Filling correlation histos
428 for(Int_t k=0; k<kNChannels; k++){
429 hPedCorrhg[k]->Fill(RawADCoothg[k], RawADChg[k]);
430 hPedCorrlg[k]->Fill(RawADCootlg[k], RawADClg[k]);
431 }
432 //printf(" ev. %d -> Filling correlation histo %d\n",nevents_physics, kNChannels);
433 }
d3f256ca 434 nevents_physics++;
435 //
436 delete reader;
437 delete rawStreamZDC;
039a08c3 438
439 }//(if PHYSICS_EVENT)
d3f256ca 440
441 /* exit when last event received, no need to wait for TERM signal */
442 else if(eventT==END_OF_RUN) {
443 printf(" -> EOR event detected\n");
444 break;
445 }
446
039a08c3 447 nevents_total++;
f3ca8792 448
f3ca8792 449 }
d3f256ca 450
451 /* free resources */
452 free(event);
039a08c3 453 }
f3ca8792 454
455 /* Analysis of the histograms */
456 //
457 FILE *fileShuttle;
218f916a 458 fileShuttle = fopen(PEDDATA_FILE,"w");
f3ca8792 459 //
b3b2b9dd 460 Float_t MeanPed[2*kNChannels], MeanPedWidth[2*kNChannels],
63604324 461 MeanPedOOT[2*kNChannels], MeanPedWidthOOT[2*kNChannels];
b3b2b9dd 462 // --- In-time pedestals
463 TF1 *ADCfunchg[kNChannels];
464 for(Int_t i=0; i<kNChannels; i++){
f9641c3b 465 if(hPedhg[i]->GetEntries() == 0){
466 printf("\n WARNING! Empty histos -> ending DA WITHOUT writing output\n\n");
467 return -1;
468 }
b3b2b9dd 469 hPedhg[i]->Fit("gaus","Q");
470 ADCfunchg[i] = hPedhg[i]->GetFunction("gaus");
442e1b18 471 MeanPed[i] = (Double_t) ADCfunchg[i]->GetParameter(1);
472 MeanPedWidth[i] = (Double_t) ADCfunchg[i]->GetParameter(2);
218f916a 473 fprintf(fileShuttle,"\t%f\t%f\n",MeanPed[i],MeanPedWidth[i]);
057ed567 474 //printf("\t MeanPedhg[%d] = %f\n",i, MeanPed[i]);
b3b2b9dd 475 }
476 TF1 *ADCfunclg[kNChannels];
477 for(Int_t i=0; i<kNChannels; i++){
478 hPedlg[i]->Fit("gaus","Q");
479 ADCfunclg[i] = hPedlg[i]->GetFunction("gaus");
442e1b18 480 MeanPed[i+kNChannels] = (Double_t) ADCfunclg[i]->GetParameter(1);
481 MeanPedWidth[i+kNChannels] = (Double_t) ADCfunclg[i]->GetParameter(2);
218f916a 482 fprintf(fileShuttle,"\t%f\t%f\n",MeanPed[i+kNChannels],MeanPedWidth[i+kNChannels]);
057ed567 483 //printf("\t MeanPedlg[%d] = %f\n",i+kNChannels, MeanPed[i+kNChannels]);
f3ca8792 484 }
485 // --- Out-of-time pedestals
b3b2b9dd 486 TF1 *ADCootfunchg[kNChannels];
487 for(Int_t i=0; i<kNChannels; i++){
3d155339 488 if(hPedOutOfTimehg[i]->GetEntries() == 0){
a5747d8f 489 printf("\n WARNING! Empty histos for out-of-time channels!!!\n\n");
3d155339 490 return -1;
491 }
b3b2b9dd 492 hPedOutOfTimehg[i]->Fit("gaus","Q");
493 ADCootfunchg[i] = hPedOutOfTimehg[i]->GetFunction("gaus");
442e1b18 494 MeanPedOOT[i] = (Double_t) ADCootfunchg[i]->GetParameter(1);
495 MeanPedWidthOOT[i] = (Double_t) ADCootfunchg[i]->GetParameter(2);
218f916a 496 fprintf(fileShuttle,"\t%f\t%f\n",MeanPedOOT[i],MeanPedWidthOOT[i]);
057ed567 497 //printf("\t MeanPedOOThg[%d] = %f\n",i, MeanPedOOT[i]);
b3b2b9dd 498 }
499 TF1 *ADCootfunclg[kNChannels];
500 for(Int_t i=0; i<kNChannels; i++){
501 hPedOutOfTimelg[i]->Fit("gaus","Q");
502 ADCootfunclg[i] = hPedOutOfTimelg[i]->GetFunction("gaus");
442e1b18 503 MeanPedOOT[i+kNChannels] = (Double_t) ADCootfunclg[i]->GetParameter(1);
504 MeanPedWidthOOT[i+kNChannels] = (Double_t) ADCootfunclg[i]->GetParameter(2);
218f916a 505 fprintf(fileShuttle,"\t%f\t%f\n",MeanPedOOT[i+kNChannels],MeanPedWidthOOT[i+kNChannels]);
057ed567 506 //printf("\t MeanPedOOTlg[%d] = %f\n",i+kNChannels, MeanPedOOT[i+kNChannels]);
f3ca8792 507 }
63604324 508
b3b2b9dd 509 // --- Correlations
02ef9013 510 Float_t CorrCoeff0[2*kNChannels], CorrCoeff1[2*kNChannels];
b3b2b9dd 511 TProfile *hPedCorrProfhg[kNChannels], *hPedCorrProflg[kNChannels];
512 TF1 *ffunchg[kNChannels], *ffunclg[kNChannels];
f3ca8792 513 char namhist4[50];
b3b2b9dd 514 for(int i=0;i<kNChannels;i++) {
02ef9013 515 if(i==0 || i==7 || i== 10 || i==11){
b3b2b9dd 516 sprintf(namhist4,"ADCHRvsOOT%d_Prof",i);
517 hPedCorrProfhg[i] = hPedCorrhg[i]->ProfileX(namhist4,-1,-1,"S");
518 hPedCorrProfhg[i]->SetName(namhist4);
02ef9013 519 if(hPedCorrProfhg[i]->GetEntries()!=0){
520 hPedCorrProfhg[i]->Fit("pol1","Q");
521 ffunchg[i] = hPedCorrProfhg[i]->GetFunction("pol1");
522 CorrCoeff0[i] = (Double_t) ffunchg[i]->GetParameter(0);
523 CorrCoeff1[i] = (Double_t) ffunchg[i]->GetParameter(1);
524 //printf("\t CorrCoeff0[%d] = %f, CorrCoeff1[%d] = %f\n",i, CorrCoeff0[i], i, CorrCoeff1[i]);
525 }
526 else{
527 printf(" Warning -> Correlation for high range ch. %d has no entry and can't be fitted!\n",i);
528 }
529 }
530 else{
531 CorrCoeff0[i] = 0.;
532 CorrCoeff1[i] = 0.;
533 }
534 fprintf(fileShuttle,"\t%f\t%f\n",CorrCoeff0[i],CorrCoeff1[i]);
535
b3b2b9dd 536 }
537 for(int i=0;i<kNChannels;i++) {
02ef9013 538 if(i==0 || i==7 || i== 10 || i==11){
b3b2b9dd 539 sprintf(namhist4,"ADCLRvsOOT%d_Prof",i);
540 hPedCorrProflg[i] = hPedCorrlg[i]->ProfileX(namhist4,-1,-1,"S");
541 hPedCorrProflg[i]->SetName(namhist4);
02ef9013 542 if(hPedCorrProflg[i]->GetEntries()!=0){
543 hPedCorrProflg[i]->Fit("pol1","Q");
544 ffunclg[i] = hPedCorrProflg[i]->GetFunction("pol1");
545 CorrCoeff0[i+kNChannels] = (Double_t) ffunclg[i]->GetParameter(0);
546 CorrCoeff1[i+kNChannels] = (Double_t) ffunclg[i]->GetParameter(1);
547 //printf("\t CorrCoeff0[%d] = %f, CorrCoeff1[%d] = %f\n",
548 // i+kNChannels, CorrCoeff0[i+kNChannels], i+kNChannels, CorrCoeff1[i+kNChannels]);
549 }
550 else{
551 printf(" Warning -> Correlation for low range ch. %d has no entry and can't be fitted!\n",i);
552 }
553 }
554 else{
555 CorrCoeff0[i+kNChannels] = 0.;
556 CorrCoeff1[i+kNChannels] = 0.;
557 }
558 fprintf(fileShuttle,"\t%f\t%f\n",CorrCoeff0[i+kNChannels],CorrCoeff1[i+kNChannels]);
f3ca8792 559 }
02ef9013 560
f3ca8792 561 //
562 fclose(fileShuttle);
b3b2b9dd 563 //
65448375 564 /* report progress */
565 daqDA_progressReport(80);
566 //
567 TFile *histofile = new TFile(PEDHISTO_FILE,"RECREATE");
568 histofile->cd();
569 for(int k=0; k<kNChannels; k++){
570 hPedhg[k]->Write();
571 hPedOutOfTimehg[k]->Write();
572 hPedCorrhg[k]->Write();
573 hPedlg[k]->Write();
574 hPedOutOfTimelg[k]->Write();
575 hPedCorrlg[k]->Write();
576 }
577 //
578 histofile->Close();
579 //
039a08c3 580 for(Int_t j=0; j<kNChannels; j++){
581 delete hPedhg[j];
582 delete hPedOutOfTimehg[j];
583 delete hPedCorrhg[j];
584 delete hPedlg[j];
585 delete hPedOutOfTimelg[j];
586 delete hPedCorrlg[j];
587 }
f3ca8792 588
589 /* write report */
590 fprintf(fp,"Run #%s, received %d physics events out of %d\n",getenv("DATE_RUN_NUMBER"),nevents_physics,nevents_total);
591
592 /* close result file */
593 fclose(fp);
039a08c3 594
595 /* report progress */
596 daqDA_progressReport(90);
597
442e1b18 598 /* store the result files on FES */
63604324 599 // [1] File with mapping
a8eaff64 600 status = daqDA_FES_storeFile(MAPDATA_FILE, "MAPPING");
442e1b18 601 if(status){
65448375 602 printf("Failed to export mapping data file to DAQ FES\n");
442e1b18 603 return -1;
604 }
63604324 605 // [2] File with pedestal data
a8eaff64 606 status = daqDA_FES_storeFile(PEDDATA_FILE, "PEDESTALDATA");
039a08c3 607 if(status){
65448375 608 printf("Failed to export pedestal data file to DAQ FES\n");
609 return -1;
610 }
611 // [3] File with pedestal histos
a8eaff64 612 status = daqDA_FES_storeFile(PEDHISTO_FILE, "PEDESTALHISTOS");
65448375 613 if(status){
614 printf("Failed to export pedestal histos file to DAQ FES\n");
63604324 615 return -1;
616 }
617
618 /* store the result files on DB */
a8eaff64 619 status = daqDA_DB_storeFile(PEDDATA_FILE, PEDDATA_FILE);
63604324 620 if(status){
65448375 621 printf("Failed to store pedestal data file to DAQ DB\n");
039a08c3 622 return -1;
623 }
624
625 /* report progress */
626 daqDA_progressReport(100);
f3ca8792 627
f3ca8792 628 return status;
629}