]> git.uio.no Git - u/mrichter/AliRoot.git/blame - VZERO/VZEROda.cxx
fixing backward incompatible operator=, check for existence of fEventPlaneP
[u/mrichter/AliRoot.git] / VZERO / VZEROda.cxx
CommitLineData
bb80ae5b 1/*********************************************************************************
2- Contact: Brigitte Cheynis b.cheynis@ipnl.in2p3.fr
f30630cb 3- Link: http
03e924d7 4- Raw data test file :
5- Reference run number :
bb80ae5b 6- Run Type: PHYSICS
03e924d7 7- DA Type: MON
8- Number of events needed: >=500
f30630cb 9- Input Files: argument list
aafd3c0d 10- Output Files: local files VZERO_Histos.root, V0_Pedestals.dat (Online mapping)
11 FXS file V0_Ped_Width_Gain.dat (Offline mapping)
f30630cb 12- Trigger types used: PHYSICS_EVENT
bb80ae5b 13**********************************************************************************/
14
bb80ae5b 15/**********************************************************************************
16* *
17* VZERO Detector Algorithm used for extracting calibration parameters *
18* *
03e924d7 19* This program connects to the DAQ data source passed as argument. *
bb80ae5b 20* It computes calibration parameters, populates local "./V0_Ped_Width_Gain.dat" *
d154146a 21* file, exports it to the FES, and stores it into DAQ DB *
03e924d7 22* The program exits when being asked to shut down (daqDA_checkshutdown) *
c2d54b4c 23* or on End of Run event. *
bb80ae5b 24* We have 128 channels instead of 64 as expected for V0 due to the two sets of *
25* charge integrators which are used by the FEE ... *
bb80ae5b 26* *
27***********************************************************************************/
f52220c5 28
29// DATE
30#include "event.h"
31#include "monitor.h"
32#include "daqDA.h"
33
34//AliRoot
35#include <AliVZERORawStream.h>
36#include <AliRawReaderDate.h>
37#include <AliRawReader.h>
38#include <AliDAQ.h>
39
40// standard
41#include <stdio.h>
42#include <stdlib.h>
43
44//ROOT
bb80ae5b 45#include "TROOT.h"
46#include "TPluginManager.h"
f52220c5 47#include <TFile.h>
48#include <TH1F.h>
49#include <TMath.h>
50
26206101 51Int_t GetOfflineChannel(Int_t channel);
52
03e924d7 53/* Main routine --- Arguments: monitoring data source */
f52220c5 54
55int main(int argc, char **argv) {
56
6ee2e288 57/* magic line from Cvetan */
58 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
59 "*",
60 "TStreamerInfo",
61 "RIO",
62 "TStreamerInfo()");
f52220c5 63 int status;
03e924d7 64 if (argc!=2) {
65 printf("Wrong number of arguments\n");
66 return -1;
67 }
c2d54b4c 68
aafd3c0d 69 // Online values (using FEE channel numbering),
70 // stored into local V0_Pedestals.dat:
56396b71 71 Double_t adcMean[128];
72 Double_t adcSigma[128];
73 Double_t pedMean[128];
74 Double_t pedSigma[128];
aafd3c0d 75 // Offline values(same but ordered as in aliroot for offliners)
76 // stored into V0_Ped_Width_Gain.dat:
56396b71 77 Double_t adcMeanOff[128];
78 Double_t adcSigmaOff[128];
79 Double_t pedMeanOff[128];
80 Double_t pedSigmaOff[128];
26206101 81
c2d54b4c 82//___________________________________________________
83// Get cuts from V00DA.config file
84
421f5e67 85 Int_t kClockMin; // = 16; LHC Clock Min for pedestal calculation
86 Int_t kClockMax; // = 19; LHC Clock Max for pedestal calculation
5a8e0a88 87 Int_t kLowCut; // = 60; low cut on signal distribution - to be tuned
88 Int_t kHighCut; // = 50; high cut on pedestal distribution - to be tuned
89
c2d54b4c 90 status = daqDA_DB_getFile("V00DA.config","./V00DA.config");
91 if (status) {
421f5e67 92 printf("Failed to get Config file (V00DA.config) from DAQ DB, status=%d\n", status);
93 printf("Take default values of parameters for pedestal calculation \n");
94 kClockMin = 16;
95 kClockMax = 19;
96 kLowCut = 60;
97 kHighCut = 50;
98 } else {
99 /* open the config file and retrieve cuts */
100 FILE *fpConfig = fopen("V00DA.config","r");
101 int res = fscanf(fpConfig,"%d %d %d %d ",&kClockMin,&kClockMax,&kLowCut,&kHighCut);
102 if(res!=4) {
103 printf("Failed to get values from Config file (V00DA.config): wrong file format - 4 integers are expected - \n");
104 kClockMin = 16;
105 kClockMax = 19;
106 kLowCut = 60;
107 kHighCut = 50;
108 }
109 fclose(fpConfig);
c2d54b4c 110 }
f52220c5 111
421f5e67 112 printf("LHC Clock Min for pedestal calculation = %d; LHC Clock Max for pedestal calculation = %d; LowCut on signal = %d ; HighCut on pedestal = %d\n",
113 kClockMin, kClockMax, kLowCut, kHighCut);
c2d54b4c 114
f52220c5 115//___________________________________________________
116// Book HISTOGRAMS - dynamics of p-p collisions -
117
56396b71 118 char adcName[6];
119 char pedName[6];
df6d42e7 120 TH1F *hADCname[128];
121 TH1F *hPEDname[128];
f52220c5 122
123 char texte[12];
df6d42e7 124 for (Int_t i=0; i<128; i++) {
56396b71 125 sprintf(adcName,"hADC%d",i);
f52220c5 126 sprintf(texte,"ADC cell%d",i);
56396b71 127 hADCname[i] = new TH1F(adcName,texte,1024,-0.5, 1023.5);
128 sprintf(pedName,"hPED%d",i);
f52220c5 129 sprintf(texte,"PED cell%d",i);
56396b71 130 hPEDname[i] = new TH1F(pedName,texte,1024,-0.5, 1023.5);
03e924d7 131 }
f52220c5 132//___________________________________________________
aafd3c0d 133
134 /* open result file to be exported to FES */
135 FILE *fpLocal=NULL;
136 fpLocal=fopen("./V0_Pedestals.dat","w");
137 if (fpLocal==NULL) {
138 printf("Failed to open local result file\n");
139 return -1;}
d154146a 140
f52220c5 141 /* open result file to be exported to FES */
142 FILE *fp=NULL;
b68c91e6 143 fp=fopen("./V0_Ped_Width_Gain.dat","w");
f52220c5 144 if (fp==NULL) {
145 printf("Failed to open result file\n");
146 return -1;}
147
03e924d7 148 /* define data source : this is argument 1 */
149 status=monitorSetDataSource( argv[1] );
150 if (status!=0) {
151 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
152 return -1;
153 }
154
155 /* declare monitoring program */
156 status=monitorDeclareMp( __FILE__ );
157 if (status!=0) {
158 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
159 return -1;
160 }
161
162 /* define wait event timeout - 1s max */
163 monitorSetNowait();
164 monitorSetNoWaitNetworkTimeout(1000);
165
f52220c5 166 /* init counters on events */
56396b71 167 int neventsPhysics=0;
168 int neventsTotal=0;
f52220c5 169
03e924d7 170 /* loop on events (infinite) */
171 for(;;) {
172 struct eventHeaderStruct *event;
173 eventTypeType eventT;
174
175 /* check shutdown condition */
176 if (daqDA_checkShutdown()) {break;}
177
178 /* get next event (blocking call until timeout) */
179 status=monitorGetEventDynamic((void **)&event);
180 if (status==MON_ERR_EOF) {
181 printf ("End of File detected\n");
182 break; /* end of monitoring file has been reached */
183 }
184
185 if (status!=0) {
186 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
187 break;
188 }
189
190 /* retry if got no event */
191 if (event==NULL) continue;
192
193 /* decode event */
194 eventT=event->eventType;
f52220c5 195
03e924d7 196 switch (event->eventType){
f52220c5 197
03e924d7 198 case START_OF_RUN:
199 break;
f52220c5 200
03e924d7 201 case END_OF_RUN:
202 printf("End Of Run detected\n");
203 break;
f52220c5 204
03e924d7 205 case PHYSICS_EVENT:
56396b71 206 neventsPhysics++;
c2d54b4c 207
03e924d7 208 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
df6d42e7 209
03e924d7 210 AliVZERORawStream* rawStream = new AliVZERORawStream(rawReader);
cbc184a3 211 if (rawStream->Next()) {
212 for(Int_t i=0; i<64; i++) {
5a8e0a88 213 Int_t nFlag = 0;
39ea43db 214 for(Int_t j=kClockMin; j <= kClockMax; j++) { // Check flags on clock range used for pedestal calculation
5a8e0a88 215 if((rawStream->GetBBFlag(i,j)) || (rawStream->GetBGFlag(i,j))) nFlag++;
216 }
421f5e67 217 if(nFlag == 0){ // Fill 64*2 pedestal histograms - 2 integrators -
218 for(Int_t j=kClockMin;j <= kClockMax;j++){
56396b71 219 Int_t integrator = rawStream->GetIntegratorFlag(i,j);
5a8e0a88 220 Float_t pedestal = (float)(rawStream->GetPedestal(i,j));
56396b71 221 hPEDname[i + 64 * integrator]->Fill(pedestal);
5a8e0a88 222 }
223 }
224 if((rawStream->GetBBFlag(i,10)) || (rawStream->GetBGFlag(i,10))){ // Charge
56396b71 225 Int_t integrator = rawStream->GetIntegratorFlag(i,10);
421f5e67 226 Float_t charge = (float)(rawStream->GetADC(i)); // Fill 64*2 ADCmax histograms
56396b71 227 hADCname[i + 64 * integrator]->Fill(charge);
5a8e0a88 228 }
d61b4baa 229 }
230 }
03e924d7 231 delete rawStream;
232 rawStream = 0x0;
233 delete rawReader;
234 rawReader = 0x0;
235 } // end of switch on event type
236
56396b71 237 neventsTotal++;
03e924d7 238 /* free resources */
239 free(event);
f52220c5 240
03e924d7 241 /* exit when last event received, no need to wait for TERM signal */
242 if (eventT==END_OF_RUN) {
243 printf("End Of Run event detected\n");
244 break;
245 }
f52220c5 246
03e924d7 247 } // loop over events
c2d54b4c 248
56396b71 249 printf("%d physics events processed\n",neventsPhysics);
f52220c5 250
26206101 251//___________________________________________________________________________
252// Computes mean values, converts FEE channels into Offline AliRoot channels
253// and dumps the ordered values into the output text file for SHUTTLE
f52220c5 254
df6d42e7 255 for(Int_t i=0; i<128; i++) {
f52220c5 256 hPEDname[i]->GetXaxis()->SetRange(0,kHighCut);
56396b71 257 pedMean[i] = hPEDname[i]->GetMean();
258 pedSigma[i] = hPEDname[i]->GetRMS();
5a8e0a88 259 hADCname[i]->GetXaxis()->SetRange(kLowCut,1024);
56396b71 260 adcMean[i] = hADCname[i]->GetMean();
261 adcSigma[i] = hADCname[i]->GetRMS();
262// printf(" i = %d, %.3f %.3f %.3f %.3f\n",i,pedMean[i],pedSigma[i],adcMean[i],adcSigma[i]);
263 fprintf(fpLocal," %.3f %.3f %.3f %.3f\n",pedMean[i],pedSigma[i],
264 adcMean[i],adcSigma[i]);
26206101 265 if (i < 64) {
266 Int_t j = GetOfflineChannel(i);
56396b71 267 pedMeanOff[j] = pedMean[i];
268 pedSigmaOff[j] = pedSigma[i];
269 adcMeanOff[j] = adcMean[i];
270 adcSigmaOff[j] = adcSigma[i]; }
26206101 271 else{
272 Int_t j = GetOfflineChannel(i-64);
56396b71 273 pedMeanOff[j+64] = pedMean[i];
274 pedSigmaOff[j+64] = pedSigma[i];
275 adcMeanOff[j+64] = adcMean[i];
276 adcSigmaOff[j+64] = adcSigma[i];
26206101 277 }
278 }
279
280 for(Int_t j=0; j<128; j++) {
56396b71 281// printf(" j = %d, %.3f %.3f %.3f %.3f\n",j,pedMeanOff[j],pedSigmaOff[j],
282// adcMeanOff[j],adcSigmaOff[j]);
283 fprintf(fp," %.3f %.3f %.3f %.3f\n",pedMeanOff[j],pedSigmaOff[j],
284 adcMeanOff[j],adcSigmaOff[j]);
c2d54b4c 285 }
286
f52220c5 287//________________________________________________________________________
288// Write root file with histos for users further check - just in case -
289
290 TFile *histoFile = new TFile("VZERO_histos.root","RECREATE");
291
df6d42e7 292 for (Int_t i=0; i<128; i++) {
5a8e0a88 293 hADCname[i]->GetXaxis()->SetRange(0,1024);
f52220c5 294 hADCname[i]->Write();
295 hPEDname[i]->Write(); }
296
297 histoFile->Close();
df6d42e7 298 delete histoFile;
f52220c5 299
300//________________________________________________________________________
301
aafd3c0d 302 /* close local result file and FXS result file*/
303 fclose(fpLocal);
03e924d7 304 fclose(fp);
305
f52220c5 306 /* export result file to FES */
307 status=daqDA_FES_storeFile("./V0_Ped_Width_Gain.dat","V00da_results");
308 if (status) {
309 printf("Failed to export file : %d\n",status);
310 return -1; }
311
d154146a 312 /* store result file into Online DB */
aafd3c0d 313 status=daqDA_DB_storeFile("./V0_Pedestals.dat","V00da_results");
d154146a 314 if (status) {
315 printf("Failed to store file into Online DB: %d\n",status);
316 return -1; }
317
f52220c5 318 return status;
319}
26206101 320
321 Int_t GetOfflineChannel(Int_t channel) {
322
323// Channel mapping Online - Offline:
324
325 Int_t fOfflineChannel[64] = {39, 38, 37, 36, 35, 34, 33, 32,
326 47, 46, 45, 44, 43, 42, 41, 40,
327 55, 54, 53, 52, 51, 50, 49, 48,
328 63, 62, 61, 60, 59, 58, 57, 56,
329 7, 6, 5, 4, 3, 2, 1, 0,
330 15, 14, 13, 12, 11, 10, 9, 8,
331 23, 22, 21, 20, 19, 18, 17, 16,
332 31, 30, 29, 28, 27, 26, 25, 24};
333 return fOfflineChannel[channel];
334}