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