]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PHOS/PHOSLEDda.cxx
increase classdef
[u/mrichter/AliRoot.git] / PHOS / PHOSLEDda.cxx
CommitLineData
68aaec35 1/*
2contact: Boris.Polishchuk@cern.ch
3link: see comments in the $ALICE_ROOT/PHOS/AliPHOSRcuDA1.cxx
567f4fbc 4reference run: /alice/data/2009/LHC09b_PHOS/000075883/raw/09000075883017.20.root
5run type: LED
68aaec35 6DA type: MON
7number of events needed: 1000
567f4fbc 8input files: RCU0.data RCU1.data RCU2.data RCU3.data zs.txt
e57c0b30 9Output files: PHOS_LED.root.
68aaec35 10Trigger types used: CALIBRATION_EVENT
11*/
12
13
14#include "event.h"
15#include "monitor.h"
16extern "C" {
17#include "daqDA.h"
18}
19
20#include <stdio.h>
21#include <stdlib.h>
22
23#include <TSystem.h>
24#include <TROOT.h>
25#include <TPluginManager.h>
26
27#include "AliRawReader.h"
28#include "AliRawReaderDate.h"
29#include "AliPHOSRcuDA1.h"
8083e819 30#include "AliPHOSRawFitterv0.h"
68aaec35 31#include "AliCaloAltroMapping.h"
8083e819 32#include "AliCaloRawStreamV3.h"
567f4fbc 33#include "AliLog.h"
68aaec35 34
35
36/* Main routine
37 Arguments:
38 1- monitoring data source
39*/
40int main(int argc, char **argv) {
41
42 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
43 "*",
44 "TStreamerInfo",
45 "RIO",
46 "TStreamerInfo()");
47
567f4fbc 48 AliLog::SetGlobalDebugLevel(0) ;
49 AliLog::SetGlobalLogLevel(AliLog::kFatal);
50
68aaec35 51 int status;
52
53 if (argc!=2) {
54 printf("Wrong number of arguments\n");
55 return -1;
56 }
57
f4333ce5 58 /* Retrieve ZS parameters from DAQ DB */
59 const char* zsfile = "zs.txt";
60 int failZS = daqDA_DB_getFile(zsfile, zsfile);
61
62 Int_t offset,threshold;
63
64 if(!failZS) {
65 FILE *f = fopen(zsfile,"r");
66 int scan = fscanf(f,"%d %d",&offset,&threshold);
67 }
68
68aaec35 69 /* Retrieve mapping files from DAQ DB */
70 const char* mapFiles[4] = {"RCU0.data","RCU1.data","RCU2.data","RCU3.data"};
71
72 for(Int_t iFile=0; iFile<4; iFile++) {
73 int failed = daqDA_DB_getFile(mapFiles[iFile], mapFiles[iFile]);
74 if(failed) {
75 printf("Cannot retrieve file %s from DAQ DB. Exit.\n",mapFiles[iFile]);
76 return -1;
77 }
78 }
79
80 /* Open mapping files */
81 AliAltroMapping *mapping[4];
82 TString path = "./";
83 path += "RCU";
84 TString path2;
85 for(Int_t i = 0; i < 4; i++) {
86 path2 = path;
87 path2 += i;
88 path2 += ".data";
89 mapping[i] = new AliCaloAltroMapping(path2.Data());
90 }
91
92
93 /* define data source : this is argument 1 */
94 status=monitorSetDataSource( argv[1] );
95 if (status!=0) {
96 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
97 return -1;
98 }
99
100
101 /* declare monitoring program */
102 status=monitorDeclareMp( __FILE__ );
103 if (status!=0) {
104 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
105 return -1;
106 }
107
108
109 /* define wait event timeout - 1s max */
110 monitorSetNowait();
111 monitorSetNoWaitNetworkTimeout(1000);
112
113 /* init some counters */
114 int nevents_physics=0;
115 int nevents_total=0;
d62e649a 116
68aaec35 117 AliRawReader *rawReader = NULL;
d62e649a 118 AliPHOSRcuDA1* dAs[5];
68aaec35 119
d62e649a 120 for(Int_t iMod=0; iMod<5; iMod++) {
121 dAs[iMod] = 0;
122 }
123
68aaec35 124 Float_t e[64][56][2];
125 Float_t t[64][56][2];
2905f08d 126
127 for(Int_t iX=0; iX<64; iX++) {
128 for(Int_t iZ=0; iZ<56; iZ++) {
129 for(Int_t iGain=0; iGain<2; iGain++) {
130 e[iX][iZ][iGain] = 0.;
131 t[iX][iZ][iGain] = 0.;
132 }
133 }
134 }
135
8083e819 136 Int_t cellX = -1;
137 Int_t cellZ = -1;
138 Int_t nBunches = 0;
139 Int_t nFired = -1;
140 Int_t sigStart, sigLength;
d62e649a 141 Int_t caloFlag;
142
7708b003 143
144 TH1I fFiredCells("fFiredCells","Number of fired cells per event",100,0,1000);
68aaec35 145
146 /* main loop (infinite) */
147 for(;;) {
148 struct eventHeaderStruct *event;
149 eventTypeType eventT;
150
151 /* check shutdown condition */
152 if (daqDA_checkShutdown()) {break;}
153
154 /* get next event (blocking call until timeout) */
155 status=monitorGetEventDynamic((void **)&event);
156 if (status==MON_ERR_EOF) {
157 printf ("End of File detected\n");
158 break; /* end of monitoring file has been reached */
159 }
160
161 if (status!=0) {
162 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
163 break;
164 }
165
166 /* retry if got no event */
167 if (event==NULL) {
168 continue;
169 }
170
171
172 /* use event - here, just write event id to result file */
173 eventT=event->eventType;
174
175 if (eventT==PHYSICS_EVENT) {
176
7708b003 177 nFired = 0;
d62e649a 178
68aaec35 179 rawReader = new AliRawReaderDate((void*)event);
8083e819 180 AliCaloRawStreamV3 stream(rawReader,"PHOS",mapping);
d62e649a 181 AliPHOSRawFitterv0 fitter;
8083e819 182 fitter.SubtractPedestals(kTRUE); // assume that data is non-ZS
f4333ce5 183
184 if(!failZS) {
185 fitter.SubtractPedestals(kFALSE);
186 fitter.SetAmpOffset(offset);
187 fitter.SetAmpThreshold(threshold);
188 }
68aaec35 189
8083e819 190 while (stream.NextDDL()) {
191 while (stream.NextChannel()) {
d62e649a 192
8083e819 193 cellX = stream.GetCellX();
194 cellZ = stream.GetCellZ();
195 caloFlag = stream.GetCaloFlag(); // 0=LG, 1=HG, 2=TRU
d62e649a 196
2905f08d 197 if(caloFlag!=0 && caloFlag!=1) continue; //TRU data!
198
8083e819 199 // In case of oscillating signals with ZS, a channel can have several bunches
200 nBunches = 0;
201 while (stream.NextBunch()) {
202 nBunches++;
203 if (nBunches > 1) continue;
d62e649a 204 sigStart = stream.GetStartTimeBin();
205 sigLength = stream.GetBunchLength();
92236b27 206 fitter.SetChannelGeo(stream.GetModule(),cellX,cellZ,caloFlag);
207 fitter.Eval(stream.GetSignals(),sigStart,sigLength);
8083e819 208 } // End of NextBunch()
209
d62e649a 210 if(nBunches>1) continue;
8083e819 211
212 e[cellX][cellZ][caloFlag] = fitter.GetEnergy();
213 t[cellX][cellZ][caloFlag] = fitter.GetTime();
d62e649a 214
8083e819 215 if(caloFlag==1 && fitter.GetEnergy()>40)
216 nFired++;
217 }
d62e649a 218
2905f08d 219 if(stream.GetModule()<0 || stream.GetModule()>4) continue;
220
d62e649a 221 if(dAs[stream.GetModule()])
222 dAs[stream.GetModule()]->FillHistograms(e,t);
2905f08d 223 else {
d62e649a 224 dAs[stream.GetModule()] = new AliPHOSRcuDA1(stream.GetModule(),-1,0);
2905f08d 225 dAs[stream.GetModule()]->FillHistograms(e,t);
226 }
d62e649a 227
228 for(Int_t iX=0; iX<64; iX++) {
229 for(Int_t iZ=0; iZ<56; iZ++) {
230 for(Int_t iGain=0; iGain<2; iGain++) {
231 e[iX][iZ][iGain] = 0.;
232 t[iX][iZ][iGain] = 0.;
233 }
234 }
235 }
236
8083e819 237 }
d62e649a 238
7708b003 239 fFiredCells.Fill(nFired);
d62e649a 240
68aaec35 241 delete rawReader;
242 nevents_physics++;
243 }
244
245 nevents_total++;
246
247 /* free resources */
248 free(event);
249
250 /* exit when last event received, no need to wait for TERM signal */
251 if (eventT==END_OF_RUN) {
252 printf("EOR event detected\n");
253 break;
254 }
255 }
256
257 for(Int_t i = 0; i < 4; i++) delete mapping[i];
258
259 /* Be sure that all histograms are saved */
68aaec35 260
261 const TH2F* h2=0;
262 const TH1F* h1=0;
d62e649a 263 char localfile[128];
68aaec35 264
265 Int_t nGood=0; // >10 entries in peak
266 Int_t nMax=-111; // max. number of entries in peak
267 Int_t iXmax=-1;
268 Int_t iZmax=-1;
d62e649a 269 Int_t iModMax=-1;
270
e57c0b30 271 sprintf(localfile,"PHOS_LED.root");
272 TFile* f = new TFile(localfile,"recreate");
273
d62e649a 274 for(Int_t iMod=0; iMod<5; iMod++) {
275 if(!dAs[iMod]) continue;
276
277 printf("DA1 for module %d detected.\n",iMod);
d62e649a 278
279 for(Int_t iX=0; iX<64; iX++) {
280 for(Int_t iZ=0; iZ<56; iZ++) {
281
282 h1 = dAs[iMod]->GetHgLgRatioHistogram(iX,iZ); // High Gain/Low Gain ratio
283 if(h1) {
284 if(h1->GetMaximum()>10.) nGood++;
285 if(h1->GetMaximum()>nMax) {
286 nMax = (Int_t)h1->GetMaximum(); iXmax=iX; iZmax=iZ; iModMax=iMod;
287 }
288 h1->Write();
289 }
68aaec35 290
d62e649a 291 for(Int_t iGain=0; iGain<2; iGain++) {
292 h2 = dAs[iMod]->GetTimeEnergyHistogram(iX,iZ,iGain); // Time vs Energy
293 if(h2) h2->Write();
294 }
e57c0b30 295
68aaec35 296 }
68aaec35 297 }
d62e649a 298
e57c0b30 299 fFiredCells.Write();
68aaec35 300 }
301
e57c0b30 302 f->Close();
303
304 /* Store output files to the File Exchange Server */
305 daqDA_FES_storeFile(localfile,"LED");
306
68aaec35 307 printf("%d physics events of %d total processed.\n",nevents_physics,nevents_total);
308 printf("%d histograms has >10 entries in maximum, max. is %d entries ",nGood,nMax);
d62e649a 309 printf("(module,iX,iZ)=(%d,%d,%d)",iModMax,iXmax,iZmax);
68aaec35 310 printf("\n");
311
312 return status;
313}