nano config for LHC10hx
[u/mrichter/AliRoot.git] / ZDC / ZDCLASERda.cxx
CommitLineData
ead118d8 1/*
2
3This program reads the DAQ data files passed as argument using the monitoring library.
4
ead118d8 5The program reports about its processing progress.
6
7Messages on stdout are exported to DAQ log system.
8
9DA for ZDC standalone pedestal runs
10
11Contact: Chiara.Oppedisano@to.infn.it
12Link:
13Run Type: STANDALONE_LASER_RUN
442e1b18 14DA Type: LDC
ead118d8 15Number of events needed: no constraint (tipically ~10^3)
19419b67 16Input Files: ZDCPedestal.dat
ead118d8 17Output Files: ZDCLaser.dat
18Trigger Types Used: Standalone Trigger
19
20*/
78beff0d 21#define PEDDATA_FILE "ZDCPedestal.dat"
218f916a 22#define MAPDATA_FILE "ZDCChMapping.dat"
65448375 23#define LASHISTO_FILE "ZDCLaserHisto.root"
218f916a 24#define LASDATA_FILE "ZDCLaserCalib.dat"
ead118d8 25
26#include <stdio.h>
27#include <stdlib.h>
28#include <Riostream.h>
29
30// DATE
31#include <event.h>
32#include <monitor.h>
33#include <daqDA.h>
34
35//ROOT
65448375 36#include <TROOT.h>
37#include <TPluginManager.h>
ead118d8 38#include <TH1F.h>
39#include <TF1.h>
40#include <TFile.h>
442e1b18 41#include <TFitter.h>
65448375 42#include "TMinuitMinimizer.h"
ead118d8 43
44//AliRoot
45#include <AliRawReaderDate.h>
442e1b18 46#include <AliRawEventHeaderBase.h>
ead118d8 47#include <AliZDCRawStream.h>
48
49
50/* Main routine
51 Arguments: list of DATE raw data files
52*/
53int main(int argc, char **argv) {
442e1b18 54
65448375 55 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
56 "*",
57 "TStreamerInfo",
58 "RIO",
59 "TStreamerInfo()");
60
61 TMinuitMinimizer m;
62 gROOT->GetPluginManager()->AddHandler("ROOT::Math::Minimizer", "Minuit","TMinuitMinimizer",
63 "Minuit", "TMinuitMinimizer(const char *)");
64 TVirtualFitter::SetDefaultFitter("Minuit");
ead118d8 65
198f612a 66
ead118d8 67 int status = 0;
ed8a15fd 68 int const kNModules = 9;
9d0b658a 69 int const kNChannels = 24;
27afc0c8 70 int const kNScChannels = 32;
b0b160e3 71 Int_t kFirstADCGeo=0, kLastADCGeo=1; // NO out-of-time signals!!!
198f612a 72
73 Int_t iMod=-1;
74 Int_t modGeo[kNModules], modType[kNModules],modNCh[kNModules];
75 for(Int_t kl=0; kl<kNModules; kl++){
76 modGeo[kl]=modType[kl]=modNCh[kl]=0;
77 }
19419b67 78
79 Int_t ich=0;
80 Int_t adcMod[2*kNChannels], adcCh[2*kNChannels], sigCode[2*kNChannels];
81 Int_t det[2*kNChannels], sec[2*kNChannels];
82 for(Int_t y=0; y<2*kNChannels; y++){
83 adcMod[y]=adcCh[y]=sigCode[y]=det[y]=sec[y]=0;
84 }
198f612a 85
86 Int_t iScCh=0;
87 Int_t scMod[kNScChannels], scCh[kNScChannels], scSigCode[kNScChannels];
88 Int_t scDet[kNScChannels], scSec[kNScChannels];
89 for(Int_t y=0; y<kNScChannels; y++){
90 scMod[y]=scCh[y]=scSigCode[y]=scDet[y]=scSec[y]=0;
91 }
82dffa48 92
93 Int_t itdcCh=0;
94 Int_t tdcMod[kNScChannels], tdcCh[kNScChannels], tdcSigCode[kNScChannels];
95 Int_t tdcDet[kNScChannels], tdcSec[kNScChannels];
96 for(Int_t y=0; y<kNScChannels; y++){
97 tdcMod[y]=tdcCh[y]=tdcSigCode[y]=tdcDet[y]=tdcSec[y]=-1;
98 }
99
ead118d8 100 /* log start of process */
9d0b658a 101 printf("\n ZDC LASER program started\n");
ead118d8 102
103 /* check that we got some arguments = list of files */
104 if (argc<2) {
105 printf("Wrong number of arguments\n");
106 return -1;
107 }
108
109 // --- Histograms for LASER runs
110 // 20 signal channels + 2 reference PTMs
111 //
112 TH1F::AddDirectory(0);
bd94dbdd 113 // --- Histos for reference PMTs (high gain chains)
b0b160e3 114 TH1F *hPMRefChg = new TH1F("hPMRefChg","hPMRefChg", 100,-100.5,1100.5);
115 TH1F *hPMRefAhg = new TH1F("hPMRefAhg","hPMRefAhg", 100,-100.5,1100.5);
116 TH1F *hPMRefClg = new TH1F("hPMRefClg","hPMRefClg", 100,-100.5,4900.5);
117 TH1F *hPMRefAlg = new TH1F("hPMRefAlg","hPMRefAlg", 100,-100.5,4900.5);
78beff0d 118 //
9d0b658a 119 // --- Histos for detector PMTs
120 TH1F *hZNChg[5], *hZPChg[5], *hZNAhg[5], *hZPAhg[5], *hZEMhg[2];
121 TH1F *hZNClg[5], *hZPClg[5], *hZNAlg[5], *hZPAlg[5], *hZEMlg[2];
122 char hnamZNChg[20], hnamZPChg[20], hnamZNAhg[20], hnamZPAhg[20];
123 char hnamZNClg[20], hnamZPClg[20], hnamZNAlg[20], hnamZPAlg[20];
124 char hnamZEMhg[20], hnamZEMlg[20];
bd94dbdd 125 for(Int_t j=0; j<5; j++){
9d0b658a 126 sprintf(hnamZNChg,"ZNChg-tow%d",j);
127 sprintf(hnamZPChg,"ZPChg-tow%d",j);
128 sprintf(hnamZNAhg,"ZNAhg-tow%d",j);
129 sprintf(hnamZPAhg,"ZPAhg-tow%d",j);
130 //
b0b160e3 131 hZNChg[j] = new TH1F(hnamZNChg, hnamZNChg, 100,-100.5,1100.5);
132 hZPChg[j] = new TH1F(hnamZPChg, hnamZPChg, 100,-100.5,1100.5);
133 hZNAhg[j] = new TH1F(hnamZNAhg, hnamZNAhg, 100,-100.5,1100.5);
134 hZPAhg[j] = new TH1F(hnamZPAhg, hnamZPAhg, 100,-100.5,1100.5);
9d0b658a 135 //
136 sprintf(hnamZNClg,"ZNClg-tow%d",j);
137 sprintf(hnamZPClg,"ZPClg-tow%d",j);
138 sprintf(hnamZNAlg,"ZNAlg-tow%d",j);
139 sprintf(hnamZPAlg,"ZPAlg-tow%d",j);
bd94dbdd 140 //
b0b160e3 141 hZNClg[j] = new TH1F(hnamZNClg, hnamZNClg, 100,-100.5,4900.5);
142 hZPClg[j] = new TH1F(hnamZPClg, hnamZPClg, 100,-100.5,4900.5);
143 hZNAlg[j] = new TH1F(hnamZNAlg, hnamZNAlg, 100,-100.5,4900.5);
144 hZPAlg[j] = new TH1F(hnamZPAlg, hnamZPAlg, 100,-100.5,4900.5);
9d0b658a 145 //
146 if(j<2){
147 sprintf(hnamZEMhg,"ZEM%dhg",j);
148 sprintf(hnamZEMlg,"ZEM%dlg",j);
149 //
b0b160e3 150 hZEMhg[j] = new TH1F(hnamZEMhg, hnamZEMhg, 100,-100.5,1100.5);
151 hZEMlg[j] = new TH1F(hnamZEMlg, hnamZEMlg, 100,-100.5,4900.5);
9d0b658a 152 }
bd94dbdd 153 }
ead118d8 154
155 /* open result file */
156 FILE *fp=NULL;
157 fp=fopen("./result.txt","a");
158 if (fp==NULL) {
159 printf("Failed to open file\n");
160 return -1;
161 }
9d0b658a 162 /* report progress */
163 daqDA_progressReport(10);
78beff0d 164
165 // *** To analyze LASER events you MUST have a pedestal data file!!!
9d0b658a 166 // *** -> check if a pedestal run has been analyzed
78beff0d 167 int read = 0;
9d0b658a 168 read = daqDA_DB_getFile(PEDDATA_FILE, PEDDATA_FILE);
78beff0d 169 if(read){
170 printf("\t ERROR!!! ZDCPedestal.dat file NOT FOUND in DAQ db!!!\n");
171 return -1;
172 }
173 else printf("\t ZDCPedestal.dat file retrieved from DAQ db\n");
174
175 FILE *filePed = fopen(PEDDATA_FILE,"r");
176 if (filePed==NULL) {
177 printf("\t ERROR!!! Can't open ZDCPedestal.dat file!!!\n");
178 return -1;
179 }
180
181 // 144 = 48 in-time + 48 out-of-time + 48 correlations
9d0b658a 182 Float_t readValues[2][6*kNChannels];
183 Float_t MeanPedhg[kNChannels], MeanPedlg[kNChannels];
184 Float_t CorrCoeff0[2*kNChannels], CorrCoeff1[2*kNChannels];
78beff0d 185 // ***************************************************
186 // Unless we have a narrow correlation to fit we
187 // don't fit and store in-time vs. out-of-time
188 // histograms -> mean pedstal subtracted!!!!!!
189 // ***************************************************
78beff0d 190 //
9d0b658a 191 for(int jj=0; jj<6*kNChannels; jj++){
78beff0d 192 for(int ii=0; ii<2; ii++){
193 fscanf(filePed,"%f",&readValues[ii][jj]);
194 }
9d0b658a 195 if(jj<kNChannels){
196 MeanPedhg[jj] = readValues[0][jj];
197 //printf("\t MeanPedhg[%d] = %1.1f\n",jj, MeanPedhg[jj]);
78beff0d 198 }
9d0b658a 199 else if(jj>=kNChannels && jj<2*kNChannels){
200 MeanPedlg[jj-kNChannels] = readValues[0][jj];
201 //printf("\t MeanPedlg[%d] = %1.1f\n",jj-kNChannels, MeanPedlg[jj-kNChannels]);
78beff0d 202 }
9d0b658a 203 else if(jj>4*kNChannels){
204 CorrCoeff0[jj-4*kNChannels] = readValues[0][jj];
205 CorrCoeff1[jj-4*kNChannels] = readValues[1][jj];;
78beff0d 206 }
78beff0d 207 }
9d0b658a 208
209 FILE *mapFile4Shuttle;
ead118d8 210
211 /* report progress */
9d0b658a 212 daqDA_progressReport(20);
ead118d8 213
214
215 /* init some counters */
216 int nevents_physics=0;
217 int nevents_total=0;
218
d3f256ca 219 struct eventHeaderStruct *event;
220 eventTypeType eventT;
221
ead118d8 222 /* read the data files */
223 int n;
9d0b658a 224 for(n=1;n<argc;n++) {
ead118d8 225
226 status=monitorSetDataSource( argv[n] );
227 if (status!=0) {
228 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
229 return -1;
230 }
231
232 /* report progress */
233 /* in this example, indexed on the number of files */
9d0b658a 234 daqDA_progressReport(20+70*n/argc);
ead118d8 235
236 /* read the file */
237 for(;;) {
ead118d8 238
239 /* get next event */
240 status=monitorGetEventDynamic((void **)&event);
241 if (status==MON_ERR_EOF) break; /* end of monitoring file has been reached */
242 if (status!=0) {
243 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
244 return -1;
245 }
246
247 /* retry if got no event */
248 if (event==NULL) {
249 break;
250 }
251
442e1b18 252 // Initalize raw-data reading and decoding
253 AliRawReader *reader = new AliRawReaderDate((void*)event);
254 reader->Select("ZDC");
255 // --- Reading event header
78beff0d 256 //UInt_t evtype = reader->GetType();
257 //printf("\n\t ZDCLASERda -> ev. type %d\n",evtype);
258 //printf("\t ZDCLASERda -> run # %d\n",reader->GetRunNumber());
442e1b18 259 //
260 AliZDCRawStream *rawStreamZDC = new AliZDCRawStream(reader);
261
262
263 /* use event - here, just write event id to result file */
264 eventT=event->eventType;
27afc0c8 265
442e1b18 266 if(eventT==START_OF_DATA){
198f612a 267
268 iMod=-1; ich=0; iScCh=0;
269
27afc0c8 270 rawStreamZDC->SetSODReading(kTRUE);
271
9d0b658a 272 // --------------------------------------------------------
273 // --- Writing ascii data file for the Shuttle preprocessor
274 mapFile4Shuttle = fopen(MAPDATA_FILE,"w");
442e1b18 275 if(!rawStreamZDC->Next()) printf(" \t No raw data found!! \n");
276 else{
27afc0c8 277 while((rawStreamZDC->Next())){
278 if(rawStreamZDC->IsHeaderMapping()){ // mapping header
198f612a 279 iMod++;
280 modGeo[iMod] = rawStreamZDC->GetADCModule();
281 modType[iMod] = rawStreamZDC->GetModType();
282 modNCh[iMod] = rawStreamZDC->GetADCNChannels();
27afc0c8 283 }
284 if(rawStreamZDC->IsChMapping()){
198f612a 285 if(modType[iMod]==1){ // ADC mapping ----------------------
27afc0c8 286 adcMod[ich] = rawStreamZDC->GetADCModFromMap(ich);
287 adcCh[ich] = rawStreamZDC->GetADCChFromMap(ich);
288 sigCode[ich] = rawStreamZDC->GetADCSignFromMap(ich);
289 det[ich] = rawStreamZDC->GetDetectorFromMap(ich);
290 sec[ich] = rawStreamZDC->GetTowerFromMap(ich);
27afc0c8 291 ich++;
292 }
198f612a 293 else if(modType[iMod]==2){ //VME scaler mapping --------------------
27afc0c8 294 scMod[iScCh] = rawStreamZDC->GetScalerModFromMap(iScCh);
295 scCh[iScCh] = rawStreamZDC->GetScalerChFromMap(iScCh);
296 scSigCode[iScCh] = rawStreamZDC->GetScalerSignFromMap(iScCh);
297 scDet[iScCh] = rawStreamZDC->GetScDetectorFromMap(iScCh);
198f612a 298 scSec[iScCh] = rawStreamZDC->GetScTowerFromMap(iScCh);
27afc0c8 299 iScCh++;
300 }
82dffa48 301 else if(modType[iMod]==6 && modGeo[iMod]==4){ // ZDC TDC mapping --------------------
302 tdcMod[itdcCh] = rawStreamZDC->GetTDCModFromMap(itdcCh);
303 tdcCh[itdcCh] = rawStreamZDC->GetTDCChFromMap(itdcCh);
304 tdcSigCode[itdcCh] = rawStreamZDC->GetTDCSignFromMap(itdcCh);
305 itdcCh++;
306 }
442e1b18 307 }
198f612a 308 }
309 // Writing data on output FXS file
198f612a 310 for(Int_t is=0; is<2*kNChannels; is++){
311 fprintf(mapFile4Shuttle,"\t%d\t%d\t%d\t%d\t%d\t%d\n",
312 is,adcMod[is],adcCh[is],sigCode[is],det[is],sec[is]);
313 //printf(" Laser DA -> %d ADC: mod %d ch %d, code %d det %d, sec %d\n",
314 // is,adcMod[is],adcCh[is],sigCode[is],det[is],sec[is]);
315 }
316 for(Int_t is=0; is<kNScChannels; is++){
317 fprintf(mapFile4Shuttle,"\t%d\t%d\t%d\t%d\t%d\t%d\n",
318 is,scMod[is],scCh[is],scSigCode[is],scDet[is],scSec[is]);
319 //printf(" Laser DA -> %d Scaler: mod %d ch %d, code %d det %d, sec %d\n",
320 // is,scMod[is],scCh[is],scSigCode[is],scDet[is],scSec[is]);
442e1b18 321 }
82dffa48 322 for(Int_t is=0; is<kNScChannels; is++){
323 fprintf(mapFile4Shuttle,"\t%d\t%d\t%d\t%d\n",
324 is,tdcMod[is],tdcCh[is],tdcSigCode[is]);
325 //if(tdcMod[is]!=-1) printf(" Mapping DA -> %d TDC: mod %d ch %d, code %d\n",
326 // is,tdcMod[is],tdcCh[is],tdcSigCode[is]);
327 }
608444fb 328 for(Int_t is=0; is<kNModules; is++){
329 fprintf(mapFile4Shuttle,"\t%d\t%d\t%d\n",
330 modGeo[is],modType[is],modNCh[is]);
331 //printf(" Laser DA -> Module mapping: geo %d type %d #ch %d\n",
332 // modGeo[is],modType[is],modNCh[is]);
333 }
198f612a 334
442e1b18 335 }
442e1b18 336 fclose(mapFile4Shuttle);
9d0b658a 337 }// SOD event
ead118d8 338
d3f256ca 339 else if(eventT==PHYSICS_EVENT){
9d0b658a 340 // --- Reading data header
442e1b18 341 reader->ReadHeader();
ead118d8 342 const AliRawDataHeader* header = reader->GetDataHeader();
343 if(header) {
344 UChar_t message = header->GetAttributes();
a5747d8f 345 if((message & 0x30) == 0x30){ // DEDICATED LASER RUN
442e1b18 346 //printf("\t STANDALONE_LASER_RUN raw data found\n");
ead118d8 347 }
348 else{
9d0b658a 349 printf("ZDCLASERda.cxx -> NO STANDALONE_LASER_RUN raw data found\n");
ead118d8 350 return -1;
351 }
352 }
442e1b18 353 else{
354 printf("\t ATTENTION! No Raw Data Header found!!!\n");
355 return -1;
356 }
357
7f4bde92 358 rawStreamZDC->SetSODReading(kTRUE);
359
ead118d8 360 if (!rawStreamZDC->Next()) printf(" \t No raw data found!! \n");
442e1b18 361 //
362 // ----- Setting ch. mapping -----
9d0b658a 363 for(Int_t jk=0; jk<2*kNChannels; jk++){
442e1b18 364 rawStreamZDC->SetMapADCMod(jk, adcMod[jk]);
365 rawStreamZDC->SetMapADCCh(jk, adcCh[jk]);
366 rawStreamZDC->SetMapADCSig(jk, sigCode[jk]);
367 rawStreamZDC->SetMapDet(jk, det[jk]);
368 rawStreamZDC->SetMapTow(jk, sec[jk]);
369 }
ead118d8 370 //
371 while(rawStreamZDC->Next()){
372 Int_t index=-1;
bd94dbdd 373 Int_t detector = rawStreamZDC->GetSector(0);
9d0b658a 374 Int_t sector = rawStreamZDC->GetSector(1);
bd94dbdd 375
8700404e 376 if(rawStreamZDC->IsADCDataWord() && !(rawStreamZDC->IsUnderflow()) &&
377 !(rawStreamZDC->IsOverflow()) && detector!=-1 &&
378 rawStreamZDC->GetADCModule()>=kFirstADCGeo && rawStreamZDC->GetADCModule()<=kLastADCGeo){
bd94dbdd 379
9d0b658a 380 if(sector!=5){ // Physics signals
19419b67 381 if(detector==1) index = sector; // *** ZNC
9d0b658a 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
bd94dbdd 386 }
387 else{ // Reference PMs
388 index = (detector-1)/3+22;
389 }
9d0b658a 390 //
391 if(index==-1) printf("ERROR in ZDCLASERda.cxx -> det %d quad %d res %d index %d ADC %d\n",
392 detector, sector, rawStreamZDC->GetADCGain(), index, rawStreamZDC->GetADCValue());
bd94dbdd 393
9d0b658a 394 Float_t Pedestal=0.;
19419b67 395 if(rawStreamZDC->GetADCGain()==0) Pedestal = MeanPedhg[index];
9d0b658a 396 else if(rawStreamZDC->GetADCGain()==1) Pedestal = MeanPedlg[index];
397 //
ead118d8 398 Float_t CorrADC = rawStreamZDC->GetADCValue() - Pedestal;
9d0b658a 399 //
400 //printf("\tdet %d sec %d res %d index %d ped %1.0f ADCcorr %1.0f\n",
401 // detector, sector, rawStreamZDC->GetADCGain(), index, Pedestal,CorrADC);
78beff0d 402
bd94dbdd 403 // **** Detector PMs
9d0b658a 404 if(sector!=5){
405 if(rawStreamZDC->GetADCGain()==0){ // --- High gain chain ---
406 // ---- side C
19419b67 407 if(detector==1) hZNChg[sector]->Fill(CorrADC);
9d0b658a 408 else if(detector==2) hZPChg[sector]->Fill(CorrADC);
409 // ---- side A
410 else if(detector==4) hZNAhg[sector]->Fill(CorrADC);
411 else if(detector==5) hZPAhg[sector]->Fill(CorrADC);
412 // ---- ZEM
9b1ed75c 413 /*else if(detector==3){
b144b750 414 hZEMhg[sector-1]->Fill(CorrADC);
9b1ed75c 415 }*/
9d0b658a 416 }
417 else if(rawStreamZDC->GetADCGain()==1){ // --- Low gain chain ---
418 // ---- side C
19419b67 419 if(detector==1) hZNClg[sector]->Fill(CorrADC);
9d0b658a 420 else if(detector==2) hZPClg[sector]->Fill(CorrADC);
421 // ---- side A
422 else if(detector==4) hZNAlg[sector]->Fill(CorrADC);
423 else if(detector==5) hZPAlg[sector]->Fill(CorrADC);
424 // ---- ZEM
9b1ed75c 425 //else if(detector==3) hZEMlg[sector-1]->Fill(CorrADC);
9d0b658a 426 }
ead118d8 427 }
bd94dbdd 428 // **** Reference PMs
9d0b658a 429 else if(sector==5){
430 if(rawStreamZDC->GetADCGain()==0){ // --- High gain chain ---
431 // ---- PMRef chain side C
432 if(detector==1) hPMRefChg->Fill(CorrADC);
433 // ---- PMRef side A
434 else if(detector==4) hPMRefAhg->Fill(CorrADC);
435 }
436 else if(rawStreamZDC->GetADCGain()==1){ // --- Low gain chain ---
437 // ---- PMRef chain side C
438 if(detector==1) hPMRefClg->Fill(CorrADC);
439 // ---- PMRef side A
440 else if(detector==4) hPMRefAlg->Fill(CorrADC);
441 }
442 }
bd94dbdd 443 }//IsADCDataWord()+NOunderflow+NOoverflow
ead118d8 444 //
445 }
446 //
447 nevents_physics++;
448 //
449 delete reader;
450 delete rawStreamZDC;
451
452 }//(if PHYSICS_EVENT)
ead118d8 453
d3f256ca 454 /* exit when last event received, no need to wait for TERM signal */
455 else if(eventT==END_OF_RUN) {
456 printf(" -> EOR event detected\n");
457 break;
458 }
459
460
461 nevents_total++;
ead118d8 462
463 }
d3f256ca 464
465 /* free resources */
466 free(event);
ead118d8 467 }
468
469 /* Analysis of the histograms */
470 //
19419b67 471 Int_t detector[2*kNChannels], quad[2*kNChannels];
9d0b658a 472 Int_t maxBin[2*kNChannels], nBin[2*kNChannels];
473 Float_t xMax[2*kNChannels], maxXval[2*kNChannels], xlow[2*kNChannels];
474 Float_t mean[2*kNChannels], sigma[2*kNChannels];
19419b67 475 for(Int_t t=0; t<2*kNChannels; t++){
476 detector[t] = quad[t] = 0;
477 maxBin[t] = nBin[t] = 0;
478 xMax[t] = maxXval[t] = xlow[t] = 0.;
479 mean[t] = sigma[t] = 0.;
480 }
9d0b658a 481 TF1 *fun[2*kNChannels];
19419b67 482 Int_t atLeastOneHisto=0;
6f427255 483
9d0b658a 484 // ******** High gain chain ********
bd94dbdd 485 for(Int_t k=0; k<5; k++){
486 // --- ZNC
19419b67 487 detector[k] = 1;
9d0b658a 488 quad[k] = k;
489 maxBin[k] = hZNChg[k]->GetMaximumBin();
490 nBin[k] = (hZNChg[k]->GetXaxis())->GetNbins();
491 xMax[k] = (hZNChg[k]->GetXaxis())->GetXmax();
bd94dbdd 492 if(nBin[k]!=0) maxXval[k] = maxBin[k]*xMax[k]/nBin[k];
bd94dbdd 493 if(maxXval[k]-150.<0.) xlow[k]=0.;
494 else xlow[k] = maxXval[k]-150.;
19419b67 495 // checking if at least one histo is fitted
3bd4bc9d 496 if(hZNChg[k]->GetEntries()!=0 || hZNChg[k]->GetMean()>0){
19419b67 497 atLeastOneHisto=1;
498 //
499 hZNChg[k]->Fit("gaus","Q","",xlow[k],maxXval[k]+150.);
500 fun[k] = hZNChg[k]->GetFunction("gaus");
501 mean[k] = (Float_t) (fun[k]->GetParameter(1));
502 sigma[k] = (Float_t) (fun[k]->GetParameter(2));
503 }
bd94dbdd 504 // --- ZPC
19419b67 505 detector[k+5] = 2;
9d0b658a 506 quad[k+5] = k;
507 maxBin[k+5] = hZPChg[k]->GetMaximumBin();
508 nBin[k+5] = (hZPChg[k]->GetXaxis())->GetNbins();
509 xMax[k+5] = (hZPChg[k]->GetXaxis())->GetXmax();
bd94dbdd 510 if(nBin[k+5]!=0) maxXval[k+5] = maxBin[k+5]*xMax[k+5]/nBin[k+5];
bd94dbdd 511 if(maxXval[k+5]-150.<0.) xlow[k+5]=0.;
512 else xlow[k+5] = maxXval[k+5]-150.;
3bd4bc9d 513 if(hZPChg[k]->GetEntries()!=0 || hZPChg[k]->GetMean()>0){
19419b67 514 atLeastOneHisto=1;
515 //
516 hZPChg[k]->Fit("gaus","Q","",xlow[k+5],maxXval[k+5]+150.);
517 fun[k+5] = hZPChg[k]->GetFunction("gaus");
518 mean[k+5] = (Float_t) (fun[k+5]->GetParameter(1));
519 sigma[k+5] = (Float_t) (fun[k+5]->GetParameter(2));
520 }
9b1ed75c 521 // --- ZEM
522/* if(k<2){
19419b67 523 detector[k+10] = 3;
9d0b658a 524 quad[k+10] = k+1;
525 maxBin[k+10] = hZEMhg[k]->GetMaximumBin();
526 nBin[k+10] = (hZEMhg[k]->GetXaxis())->GetNbins();
527 xMax[k+10] = (hZEMhg[k]->GetXaxis())->GetXmax();
528 if(nBin[k+10]!=0) maxXval[k+10] = maxBin[k+10]*xMax[k+10]/nBin[k+10];
529 if(maxXval[k+10]-150.<0.) xlow[k+10]=0.;
530 else xlow[k+10] = maxXval[k+10]-150.;
9b1ed75c 531 printf("ZEM%d: entries %1.0f mean %1.0f\n",k+1,hZEMhg[k]->GetEntries(),hZEMhg[k]->GetMean());
3bd4bc9d 532 if(hZEMhg[k]->GetEntries()!=0 || hZEMhg[k]->GetMean()>0){
19419b67 533 atLeastOneHisto=1;
b144b750 534 //
19419b67 535 hZEMhg[k]->Fit("gaus","Q","",xlow[k+10],maxXval[k+10]+150.);
536 fun[k+10] = hZEMhg[k]->GetFunction("gaus");
537 mean[k+10] = (Float_t) (fun[k+10]->GetParameter(1));
538 sigma[k+10] = (Float_t) (fun[k+10]->GetParameter(2));
539 }
9d0b658a 540 }
9b1ed75c 541*/
bd94dbdd 542 // --- ZNA
19419b67 543 detector[k+12] = 4;
9d0b658a 544 quad[k+12] = k;
545 maxBin[k+12] = hZNAhg[k]->GetMaximumBin();
546 nBin[k+12] = (hZNAhg[k]->GetXaxis())->GetNbins();
547 xMax[k+12] = (hZNAhg[k]->GetXaxis())->GetXmax();
548 if(nBin[k+12]!=0) maxXval[k+12] = maxBin[k+12]*xMax[k+12]/nBin[k+12];
549 if(maxXval[k+12]-150.<0.) xlow[k+12]=0.;
550 else xlow[k+12] = maxXval[k+12]-150.;
3bd4bc9d 551 if(hZNAhg[k]->GetEntries()!=0 || hZNAhg[k]->GetMean()>0){
19419b67 552 atLeastOneHisto=1;
553 //
554 hZNAhg[k]->Fit("gaus","Q","",xlow[k+12],maxXval[k+12]+150.);
555 fun[k+12] = hZNAhg[k]->GetFunction("gaus");
556 mean[k+12] = (Float_t) (fun[k+12]->GetParameter(1));
557 sigma[k+12] = (Float_t) (fun[k+12]->GetParameter(2));
558 }
bd94dbdd 559 // --- ZPA
19419b67 560 detector[k+17] = 4;
9d0b658a 561 quad[k+17] = 5;
562 maxBin[k+17] = hZPAhg[k]->GetMaximumBin();
563 nBin[k+17] = (hZPAhg[k]->GetXaxis())->GetNbins();
564 xMax[k+17] = (hZPAhg[k]->GetXaxis())->GetXmax();
565 if(nBin[k+17]!=0) maxXval[k+17] = maxBin[k+17]*xMax[k+17]/nBin[k+17];
566 if(maxXval[k+17]-150.<0.) xlow[k+17]=0.;
567 else xlow[k+17] = maxXval[k+17]-150.;
3bd4bc9d 568 if(hZPAhg[k]->GetEntries()!=0 || hZPAhg[k]->GetMean()>0){
19419b67 569 atLeastOneHisto=1;
570 //
571 hZPAhg[k]->Fit("gaus","Q","",xlow[k+17],maxXval[k+17]+150.);
572 fun[k+17] = hZPAhg[k]->GetFunction("gaus");
573 mean[k+17] = (Float_t) (fun[k+17]->GetParameter(1));
574 sigma[k+17] = (Float_t) (fun[k+17]->GetParameter(2));
575 }
bd94dbdd 576 }
bd94dbdd 577 // ~~~~~~~~ PM Ref side C ~~~~~~~~
19419b67 578 detector[22] = 1;
9d0b658a 579 quad[22] = 5;
580 maxBin[22] = hPMRefChg->GetMaximumBin();
581 nBin[22] = (hPMRefChg->GetXaxis())->GetNbins();
582 xMax[22] = (hPMRefChg->GetXaxis())->GetXmax();
583 if(nBin[22]!=0) maxXval[22] = maxBin[22]*xMax[22]/nBin[22];
584 if(maxXval[22]-150.<0.) xlow[22]=0.;
19419b67 585 else xlow[22] = maxXval[22]-150.;
b0b160e3 586 if(hPMRefChg->GetEntries()!=0){
19419b67 587 atLeastOneHisto=1;
588 //
589 hPMRefChg->Fit("gaus","Q","",xlow[22],maxXval[22]+150.);
590 fun[22] = hPMRefChg->GetFunction("gaus");
591 mean[22] = (Float_t) (fun[22]->GetParameter(1));
592 sigma[22] = (Float_t) (fun[22]->GetParameter(2));
593 }
9d0b658a 594 // ~~~~~~~~ PM Ref side A ~~~~~~~~
19419b67 595 detector[23] = 4;
9d0b658a 596 quad[23] = 5;
597 maxBin[23] = hPMRefAhg->GetMaximumBin();
598 nBin[23] = (hPMRefAhg->GetXaxis())->GetNbins();
599 xMax[23] = (hPMRefAhg->GetXaxis())->GetXmax();
600 if(nBin[23]!=0) maxXval[23] = maxBin[23]*xMax[23]/nBin[23];
601 if(maxXval[23]-100.<0.) xlow[23]=0.;
19419b67 602 else xlow[23] = maxXval[23]-150.;
b0b160e3 603 if(hPMRefAhg->GetEntries()!=0){
19419b67 604 atLeastOneHisto=1;
605 //
606 hPMRefAhg->Fit("gaus","Q","",xlow[23],maxXval[23]+100.);
607 fun[23] = hPMRefAhg->GetFunction("gaus");
608 mean[23] = (Float_t) (fun[23]->GetParameter(1));
609 sigma[23] = (Float_t) (fun[23]->GetParameter(2));
610 }
6f427255 611
9d0b658a 612 // ******** Low gain chain ********
b0b160e3 613/* Int_t kOffset = 24;
9d0b658a 614 for(Int_t k=0; k<5; k++){
615 // --- ZNC
19419b67 616 detector[k+kOffset] = 1;
9d0b658a 617 quad[k+kOffset] = k;
618 maxBin[k+kOffset] = hZNClg[k]->GetMaximumBin();
619 nBin[k+kOffset] = (hZNClg[k]->GetXaxis())->GetNbins();
620 xMax[k+kOffset] = (hZNClg[k]->GetXaxis())->GetXmax();
621 if(nBin[k+kOffset]!=0) maxXval[k+kOffset] = maxBin[k+kOffset]*xMax[k+kOffset]/nBin[k+kOffset];
622 if(maxXval[k+kOffset]-150.<0.) xlow[k+kOffset]=0.;
623 else xlow[k+kOffset] = maxXval[k+kOffset]-150.;
b0b160e3 624 if(hZNClg[k]->GetEntries()!=0){
19419b67 625 atLeastOneHisto=1;
626 //
627 hZNClg[k]->Fit("gaus","Q","",xlow[k+kOffset],maxXval[k+kOffset]+150.);
628 fun[k+kOffset] = hZNClg[k]->GetFunction("gaus");
629 mean[k+kOffset] = (Float_t) (fun[k+kOffset]->GetParameter(1));
630 sigma[k+kOffset] = (Float_t) (fun[k+kOffset]->GetParameter(2));
631 }
9d0b658a 632 // --- ZPC
19419b67 633 detector[k+kOffset+5] = 2;
9d0b658a 634 quad[k+kOffset+5] = k;
635 maxBin[k+kOffset+5] = hZPClg[k]->GetMaximumBin();
636 nBin[k+kOffset+5] = (hZPClg[k]->GetXaxis())->GetNbins();
637 xMax[k+kOffset+5] = (hZPClg[k]->GetXaxis())->GetXmax();
638 if(nBin[k+kOffset+5]!=0) maxXval[k+kOffset+5] = maxBin[k+kOffset+5]*xMax[k+kOffset+5]/nBin[k+kOffset+5];
639 if(maxXval[k+kOffset+5]-150.<0.) xlow[k+kOffset+5]=0.;
640 else xlow[k+kOffset+5] = maxXval[k+kOffset+5]-150.;
b0b160e3 641 if(hZPClg[k]->GetEntries()!=0){
19419b67 642 atLeastOneHisto=1;
643 //
644 hZPClg[k]->Fit("gaus","Q","",xlow[k+kOffset+5],maxXval[k+kOffset+5]+150.);
645 fun[k+kOffset+5] = hZPClg[k]->GetFunction("gaus");
646 mean[k+kOffset+5] = (Float_t) (fun[k+kOffset+5]->GetParameter(1));
647 sigma[k+kOffset+5] = (Float_t) (fun[k+kOffset+5]->GetParameter(2));
648 }
9d0b658a 649 // --- ZEM1
650 if(k+kOffset<2){
19419b67 651 detector[k+kOffset+10] = 3;
9d0b658a 652 quad[k+kOffset+10] = k+1;
653 maxBin[k+kOffset+10] = hZEMlg[k]->GetMaximumBin();
654 nBin[k+kOffset+10] = (hZEMlg[k]->GetXaxis())->GetNbins();
655 xMax[k+kOffset+10] = (hZEMlg[k]->GetXaxis())->GetXmax();
656 if(nBin[k+kOffset+10]!=0) maxXval[k+kOffset+10] = maxBin[k+kOffset+10]*xMax[k+kOffset+10]/nBin[k+kOffset+10];
657 if(maxXval[k+kOffset+10]-150.<0.) xlow[k+kOffset+10]=0.;
658 else xlow[k+kOffset+10] = maxXval[k+kOffset+10]-150.;
b0b160e3 659 if(hZEMlg[k]->GetEntries()!=0){
19419b67 660 atLeastOneHisto=1;
661 //
662 hZEMlg[k]->Fit("gaus","Q","",xlow[k+kOffset+10],maxXval[k+kOffset+10]+150.);
663 fun[k+kOffset+10] = hZEMlg[k]->GetFunction("gaus");
664 mean[k+kOffset+10] = (Float_t) (fun[k+kOffset+10]->GetParameter(1));
665 sigma[k+kOffset+10] = (Float_t) (fun[k+kOffset+10]->GetParameter(2));
666 }
9d0b658a 667 }
668 // --- ZNA
19419b67 669 detector[k+kOffset+12] = 4;
9d0b658a 670 quad[k+kOffset+12] = k;
671 maxBin[k+kOffset+12] = hZNAlg[k]->GetMaximumBin();
672 nBin[k+kOffset+12] = (hZNAlg[k]->GetXaxis())->GetNbins();
673 xMax[k+kOffset+12] = (hZNAlg[k]->GetXaxis())->GetXmax();
674 if(nBin[k+kOffset+12]!=0) maxXval[k+kOffset+12] = maxBin[k+kOffset+12]*xMax[k+kOffset+12]/nBin[k+kOffset+12];
675 if(maxXval[k+kOffset+12]-150.<0.) xlow[k+kOffset+12]=0.;
676 else xlow[k+kOffset+12] = maxXval[k+kOffset+12]-150.;
b0b160e3 677 if(hZNAlg[k]->GetEntries()!=0){
19419b67 678 atLeastOneHisto=1;
679 //
680 hZNAlg[k]->Fit("gaus","Q","",xlow[k+kOffset+12],maxXval[k+kOffset+12]+150.);
681 fun[k+kOffset+12] = hZNAlg[k]->GetFunction("gaus");
682 mean[k+kOffset+12] = (Float_t) (fun[k+kOffset+12]->GetParameter(1));
683 sigma[k+kOffset+12] = (Float_t) (fun[k+kOffset+12]->GetParameter(2));
684 }
9d0b658a 685 // --- ZPA
19419b67 686 detector[k+kOffset+17] = 5;
9d0b658a 687 quad[k+kOffset+17] = k;
688 maxBin[k+kOffset+17] = hZPAlg[k]->GetMaximumBin();
689 nBin[k+kOffset+17] = (hZPAlg[k]->GetXaxis())->GetNbins();
690 xMax[k+kOffset+17] = (hZPAlg[k]->GetXaxis())->GetXmax();
691 if(nBin[k+kOffset+17]!=0) maxXval[k+kOffset+17] = maxBin[k+kOffset+17]*xMax[k+kOffset+17]/nBin[k+kOffset+17];
692 if(maxXval[k+kOffset+17]-150.<0.) xlow[k+kOffset+17]=0.;
693 else xlow[k+kOffset+17] = maxXval[k+kOffset+17]-150.;
b0b160e3 694 if(hZPAlg[k]->GetEntries()!=0){
19419b67 695 atLeastOneHisto=1;
696 //
697 hZPAlg[k]->Fit("gaus","Q","",xlow[k+kOffset+17],maxXval[k+kOffset+17]+150.);
698 fun[k+kOffset+17] = hZPAlg[k]->GetFunction("gaus");
699 mean[k+kOffset+17] = (Float_t) (fun[k+kOffset+17]->GetParameter(1));
700 sigma[k+kOffset+17] = (Float_t) (fun[k+kOffset+17]->GetParameter(2));
701 }
9d0b658a 702 }
703 // ~~~~~~~~ PM Ref side C ~~~~~~~~
19419b67 704 detector[46] = 1;
9d0b658a 705 quad[46] = 5;
706 maxBin[46] = hPMRefClg->GetMaximumBin();
707 nBin[46] = (hPMRefClg->GetXaxis())->GetNbins();
708 xMax[46] = (hPMRefClg->GetXaxis())->GetXmax();
709 if(nBin[46]!=0) maxXval[46] = maxBin[46]*xMax[46]/nBin[46];
710 if(maxXval[46]-150.<0.) xlow[46]=0.;
19419b67 711 else xlow[46] = maxXval[46]-150.;
b0b160e3 712 if(hPMRefClg->GetEntries()!=0){
19419b67 713 atLeastOneHisto=1;
714 //
715 hPMRefClg->Fit("gaus","Q","",xlow[46],maxXval[46]+150.);
716 fun[46] = hPMRefClg->GetFunction("gaus");
717 mean[46] = (Float_t) (fun[46]->GetParameter(1));
718 sigma[46] = (Float_t) (fun[46]->GetParameter(2));
719 }
bd94dbdd 720 // ~~~~~~~~ PM Ref side A ~~~~~~~~
19419b67 721 detector[47] = 4;
9d0b658a 722 quad[47] = 5;
723 maxBin[47] = hPMRefAlg->GetMaximumBin();
724 nBin[47] = (hPMRefAlg->GetXaxis())->GetNbins();
725 xMax[47] = (hPMRefAlg->GetXaxis())->GetXmax();
726 if(nBin[47]!=0) maxXval[47] = maxBin[47]*xMax[47]/nBin[47];
727 if(maxXval[47]-100.<0.) xlow[47]=0.;
19419b67 728 else xlow[47] = maxXval[47]-150.;
b0b160e3 729 if(hPMRefAlg->GetEntries()!=0){
19419b67 730 atLeastOneHisto=1;
731 //
732 hPMRefAlg->Fit("gaus","Q","",xlow[47],maxXval[47]+100.);
733 fun[47] = hPMRefAlg->GetFunction("gaus");
734 mean[47] = (Float_t) (fun[47]->GetParameter(1));
735 sigma[47] = (Float_t) (fun[47]->GetParameter(2));
736 }
b0b160e3 737*/
19419b67 738 if(atLeastOneHisto==0){
739 printf("\n WARNING! Empty LASER histos -> ending DA WITHOUT writing output\n\n");
740 return -1;
741 }
ead118d8 742 FILE *fileShuttle;
218f916a 743 fileShuttle = fopen(LASDATA_FILE,"w");
9d0b658a 744 for(Int_t i=0; i<2*kNChannels; i++){
19419b67 745 fprintf(fileShuttle,"\t%d\t%d\t%f\t%f\n",detector[i],quad[i],mean[i], sigma[i]);
bd94dbdd 746 }
ead118d8 747 //
748 fclose(fileShuttle);
b0b160e3 749
65448375 750 /* report progress */
751 daqDA_progressReport(80);
752 //
753 TFile *histofile = new TFile(LASHISTO_FILE,"RECREATE");
754 histofile->cd();
755 for(int j=0; j<5; j++){
756 hZNChg[j]->Write();
757 hZPChg[j]->Write();
758 hZNAhg[j]->Write();
759 hZPAhg[j]->Write();
760 hZNClg[j]->Write();
761 hZPClg[j]->Write();
762 hZNAlg[j]->Write();
763 hZPAlg[j]->Write();
9b1ed75c 764 /*if(j<2){
65448375 765 hZEMhg[j]->Write();
766 hZEMlg[j]->Write();
9b1ed75c 767 }*/
65448375 768 }
769 hPMRefChg->Write();
770 hPMRefAhg->Write();
771 hPMRefClg->Write();
772 hPMRefAlg->Write();
773 //
774 histofile->Close();
ead118d8 775 //
bd94dbdd 776 for(Int_t j=0; j<5; j++){
9d0b658a 777 delete hZNChg[j];
778 delete hZPChg[j];
779 delete hZNAhg[j];
780 delete hZPAhg[j];
781 delete hZNClg[j];
782 delete hZPClg[j];
783 delete hZNAlg[j];
784 delete hZPAlg[j];
9b1ed75c 785 /*if(j<2){
9d0b658a 786 delete hZEMhg[j];
787 delete hZEMlg[j];
9b1ed75c 788 }*/
bd94dbdd 789 }
9d0b658a 790 delete hPMRefChg;
791 delete hPMRefAhg;
792 delete hPMRefClg;
793 delete hPMRefAlg;
442e1b18 794
ead118d8 795 /* write report */
796 fprintf(fp,"Run #%s, received %d physics events out of %d\n",getenv("DATE_RUN_NUMBER"),nevents_physics,nevents_total);
797
798 /* close result file */
799 fclose(fp);
800
801 /* report progress */
802 daqDA_progressReport(90);
9d0b658a 803
ead118d8 804 /* store the result file on FES */
65448375 805 // [1] File with mapping
a8eaff64 806 status = daqDA_FES_storeFile(MAPDATA_FILE, "MAPPING");
442e1b18 807 if(status){
808 printf("Failed to export file : %d\n",status);
809 return -1;
810 }
811 //
65448375 812 // [2] File with laser data
a8eaff64 813 status = daqDA_FES_storeFile(LASDATA_FILE, "LASERDATA");
ead118d8 814 if(status){
815 printf("Failed to export file : %d\n",status);
816 return -1;
817 }
65448375 818 // [3] File with laser histos
a8eaff64 819 status = daqDA_FES_storeFile(LASHISTO_FILE, "LASERHISTOS");
65448375 820 if(status){
821 printf("Failed to export pedestal histos file to DAQ FES\n");
822 return -1;
823 }
ead118d8 824
825 /* report progress */
826 daqDA_progressReport(100);
827
ead118d8 828 return status;
829}