]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PHOS/PHOSLEDda.cxx
Added protection, for missing pileup vertices when reading older data, avoid segfault...
[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
4reference run: /castor/cern.ch/alice/phos/2007/10/04/18/07000008249001.1000.root
5run type: STANDALONE
6DA type: MON
7number of events needed: 1000
8input files: RCU0.data RCU1.data RCU2.data RCU3.data
9Output files: PHOS_Module2_LED.root
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"
68aaec35 33
34
35/* Main routine
36 Arguments:
37 1- monitoring data source
38*/
39int main(int argc, char **argv) {
40
41 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
42 "*",
43 "TStreamerInfo",
44 "RIO",
45 "TStreamerInfo()");
46
47 int status;
48
49 if (argc!=2) {
50 printf("Wrong number of arguments\n");
51 return -1;
52 }
53
54 /* Retrieve mapping files from DAQ DB */
55 const char* mapFiles[4] = {"RCU0.data","RCU1.data","RCU2.data","RCU3.data"};
56
57 for(Int_t iFile=0; iFile<4; iFile++) {
58 int failed = daqDA_DB_getFile(mapFiles[iFile], mapFiles[iFile]);
59 if(failed) {
60 printf("Cannot retrieve file %s from DAQ DB. Exit.\n",mapFiles[iFile]);
61 return -1;
62 }
63 }
64
65 /* Open mapping files */
66 AliAltroMapping *mapping[4];
67 TString path = "./";
68 path += "RCU";
69 TString path2;
70 for(Int_t i = 0; i < 4; i++) {
71 path2 = path;
72 path2 += i;
73 path2 += ".data";
74 mapping[i] = new AliCaloAltroMapping(path2.Data());
75 }
76
77
78 /* define data source : this is argument 1 */
79 status=monitorSetDataSource( argv[1] );
80 if (status!=0) {
81 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
82 return -1;
83 }
84
85
86 /* declare monitoring program */
87 status=monitorDeclareMp( __FILE__ );
88 if (status!=0) {
89 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
90 return -1;
91 }
92
93
94 /* define wait event timeout - 1s max */
95 monitorSetNowait();
96 monitorSetNoWaitNetworkTimeout(1000);
97
98 /* init some counters */
99 int nevents_physics=0;
100 int nevents_total=0;
101
102 Int_t fMod = 2; // module 2!
103 AliRawReader *rawReader = NULL;
104
105 AliPHOSRcuDA1 da1(fMod,-1,0); // DA1 for module2, no input/output file
106
107 Float_t e[64][56][2];
108 Float_t t[64][56][2];
109
8083e819 110 Int_t gain = -1;
111 Int_t cellX = -1;
112 Int_t cellZ = -1;
113 Int_t nBunches = 0;
114 Int_t nFired = -1;
115 Int_t sigStart, sigLength;
7708b003 116
117 TH1I fFiredCells("fFiredCells","Number of fired cells per event",100,0,1000);
68aaec35 118
119 /* main loop (infinite) */
120 for(;;) {
121 struct eventHeaderStruct *event;
122 eventTypeType eventT;
123
124 /* check shutdown condition */
125 if (daqDA_checkShutdown()) {break;}
126
127 /* get next event (blocking call until timeout) */
128 status=monitorGetEventDynamic((void **)&event);
129 if (status==MON_ERR_EOF) {
130 printf ("End of File detected\n");
131 break; /* end of monitoring file has been reached */
132 }
133
134 if (status!=0) {
135 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
136 break;
137 }
138
139 /* retry if got no event */
140 if (event==NULL) {
141 continue;
142 }
143
144
145 /* use event - here, just write event id to result file */
146 eventT=event->eventType;
147
148 if (eventT==PHYSICS_EVENT) {
149
150 for(Int_t iX=0; iX<64; iX++) {
151 for(Int_t iZ=0; iZ<56; iZ++) {
152 for(Int_t iGain=0; iGain<2; iGain++) {
153 e[iX][iZ][iGain] = 0.;
154 t[iX][iZ][iGain] = 0.;
155 }
156 }
157 }
158
7708b003 159 nFired = 0;
160
68aaec35 161 rawReader = new AliRawReaderDate((void*)event);
8083e819 162 AliCaloRawStreamV3 stream(rawReader,"PHOS",mapping);
163 AliPHOSRawFitterv0 fitter();
164 fitter.SubtractPedestals(kTRUE); // assume that data is non-ZS
68aaec35 165
8083e819 166 while (stream.NextDDL()) {
167 while (stream.NextChannel()) {
168
169 cellX = stream.GetCellX();
170 cellZ = stream.GetCellZ();
171 caloFlag = stream.GetCaloFlag(); // 0=LG, 1=HG, 2=TRU
172
173 // In case of oscillating signals with ZS, a channel can have several bunches
174 nBunches = 0;
175 while (stream.NextBunch()) {
176 nBunches++;
177 if (nBunches > 1) continue;
178 sigStart = fRawStream.GetStartTimeBin();
179 sigLength = fRawStream.GetBunchLength();
180 fitter.SetSamples(fRawStream->GetSignals(),sigStart,sigLength);
181 } // End of NextBunch()
182
183 fitter.SetNBunches(nBunches);
184 fitter.SetChannelGeo(module,cellX,cellZ,caloFlag);
185 fitter.Eval();
186
187 if (nBunches>1 || caloFlag!=0 || caloFlag!=1 || fitter.GetSignalQuality()>1) continue;
188
189 e[cellX][cellZ][caloFlag] = fitter.GetEnergy();
190 t[cellX][cellZ][caloFlag] = fitter.GetTime();
191
192 if(caloFlag==1 && fitter.GetEnergy()>40)
193 nFired++;
194 }
195 }
68aaec35 196
7708b003 197
68aaec35 198 da1.FillHistograms(e,t);
7708b003 199 fFiredCells.Fill(nFired);
200
68aaec35 201 delete rawReader;
202 nevents_physics++;
203 }
204
205 nevents_total++;
206
207 /* free resources */
208 free(event);
209
210 /* exit when last event received, no need to wait for TERM signal */
211 if (eventT==END_OF_RUN) {
212 printf("EOR event detected\n");
213 break;
214 }
215 }
216
217 for(Int_t i = 0; i < 4; i++) delete mapping[i];
218
219 /* Be sure that all histograms are saved */
220
221 char localfile[128];
222 sprintf(localfile,"PHOS_Module%d_LED.root",fMod);
223 TFile* f = new TFile(localfile,"recreate");
224
225 const TH2F* h2=0;
226 const TH1F* h1=0;
227
228 Int_t nGood=0; // >10 entries in peak
229 Int_t nMax=-111; // max. number of entries in peak
230 Int_t iXmax=-1;
231 Int_t iZmax=-1;
232
233 for(Int_t iX=0; iX<64; iX++) {
234 for(Int_t iZ=0; iZ<56; iZ++) {
235
236 h1 = da1.GetHgLgRatioHistogram(iX,iZ); // High Gain/Low Gain ratio
237 if(h1) {
238 if(h1->GetMaximum()>10.) nGood++;
239 if(h1->GetMaximum()>nMax) {nMax = (Int_t)h1->GetMaximum(); iXmax=iX; iZmax=iZ;}
240 h1->Write();
241 }
242
243 for(Int_t iGain=0; iGain<2; iGain++) {
244 h2 = da1.GetTimeEnergyHistogram(iX,iZ,iGain); // Time vs Energy
245 if(h2) h2->Write();
246 }
247
248 }
249 }
250
7708b003 251 fFiredCells.Write();
68aaec35 252 f->Close();
253
254 /* Store output files to the File Exchange Server */
7708b003 255 daqDA_FES_storeFile("PHOS_Module2_LED.root","LED");
68aaec35 256
257 printf("%d physics events of %d total processed.\n",nevents_physics,nevents_total);
258 printf("%d histograms has >10 entries in maximum, max. is %d entries ",nGood,nMax);
259 printf("(module,iX,iZ)=(%d,%d,%d)",fMod,iXmax,iZmax);
260 printf("\n");
261
262 return status;
263}