2 contact: Boris.Polishchuk@cern.ch
3 link: see comments in the $ALICE_ROOT/PHOS/AliPHOSRcuDA1.cxx
4 reference run: /alice/data/2009/LHC09b_PHOS/000075883/raw/09000075883017.20.root
7 number of events needed: 1000
8 input files: RCU0.data RCU1.data RCU2.data RCU3.data zs.txt
9 Output files: PHOS_ModuleN_LED.root, where N is the module number (0-5).
10 Trigger types used: CALIBRATION_EVENT
25 #include <TPluginManager.h>
27 #include "AliRawReader.h"
28 #include "AliRawReaderDate.h"
29 #include "AliPHOSRcuDA1.h"
30 #include "AliPHOSRawFitterv0.h"
31 #include "AliCaloAltroMapping.h"
32 #include "AliCaloRawStreamV3.h"
38 1- monitoring data source
40 int main(int argc, char **argv) {
42 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
48 AliLog::SetGlobalDebugLevel(0) ;
49 AliLog::SetGlobalLogLevel(AliLog::kFatal);
54 printf("Wrong number of arguments\n");
58 /* Retrieve ZS parameters from DAQ DB */
59 const char* zsfile = "zs.txt";
60 int failZS = daqDA_DB_getFile(zsfile, zsfile);
62 Int_t offset,threshold;
65 FILE *f = fopen(zsfile,"r");
66 int scan = fscanf(f,"%d %d",&offset,&threshold);
69 /* Retrieve mapping files from DAQ DB */
70 const char* mapFiles[4] = {"RCU0.data","RCU1.data","RCU2.data","RCU3.data"};
72 for(Int_t iFile=0; iFile<4; iFile++) {
73 int failed = daqDA_DB_getFile(mapFiles[iFile], mapFiles[iFile]);
75 printf("Cannot retrieve file %s from DAQ DB. Exit.\n",mapFiles[iFile]);
80 /* Open mapping files */
81 AliAltroMapping *mapping[4];
85 for(Int_t i = 0; i < 4; i++) {
89 mapping[i] = new AliCaloAltroMapping(path2.Data());
93 /* define data source : this is argument 1 */
94 status=monitorSetDataSource( argv[1] );
96 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
101 /* declare monitoring program */
102 status=monitorDeclareMp( __FILE__ );
104 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
109 /* define wait event timeout - 1s max */
111 monitorSetNoWaitNetworkTimeout(1000);
113 /* init some counters */
114 int nevents_physics=0;
117 AliRawReader *rawReader = NULL;
118 AliPHOSRcuDA1* dAs[5];
120 for(Int_t iMod=0; iMod<5; iMod++) {
124 Float_t e[64][56][2];
125 Float_t t[64][56][2];
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.;
140 Int_t sigStart, sigLength;
144 TH1I fFiredCells("fFiredCells","Number of fired cells per event",100,0,1000);
146 /* main loop (infinite) */
148 struct eventHeaderStruct *event;
149 eventTypeType eventT;
151 /* check shutdown condition */
152 if (daqDA_checkShutdown()) {break;}
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 */
162 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
166 /* retry if got no event */
172 /* use event - here, just write event id to result file */
173 eventT=event->eventType;
175 if (eventT==PHYSICS_EVENT) {
179 rawReader = new AliRawReaderDate((void*)event);
180 AliCaloRawStreamV3 stream(rawReader,"PHOS",mapping);
181 AliPHOSRawFitterv0 fitter;
182 fitter.SubtractPedestals(kTRUE); // assume that data is non-ZS
185 fitter.SubtractPedestals(kFALSE);
186 fitter.SetAmpOffset(offset);
187 fitter.SetAmpThreshold(threshold);
190 while (stream.NextDDL()) {
191 while (stream.NextChannel()) {
193 cellX = stream.GetCellX();
194 cellZ = stream.GetCellZ();
195 caloFlag = stream.GetCaloFlag(); // 0=LG, 1=HG, 2=TRU
197 if(caloFlag!=0 && caloFlag!=1) continue; //TRU data!
199 // In case of oscillating signals with ZS, a channel can have several bunches
201 while (stream.NextBunch()) {
203 if (nBunches > 1) continue;
204 sigStart = stream.GetStartTimeBin();
205 sigLength = stream.GetBunchLength();
206 fitter.SetChannelGeo(stream.GetModule(),cellX,cellZ,caloFlag);
207 fitter.Eval(stream.GetSignals(),sigStart,sigLength);
208 } // End of NextBunch()
210 if(nBunches>1) continue;
212 e[cellX][cellZ][caloFlag] = fitter.GetEnergy();
213 t[cellX][cellZ][caloFlag] = fitter.GetTime();
215 if(caloFlag==1 && fitter.GetEnergy()>40)
219 if(stream.GetModule()<0 || stream.GetModule()>4) continue;
221 if(dAs[stream.GetModule()])
222 dAs[stream.GetModule()]->FillHistograms(e,t);
224 dAs[stream.GetModule()] = new AliPHOSRcuDA1(stream.GetModule(),-1,0);
225 dAs[stream.GetModule()]->FillHistograms(e,t);
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.;
239 fFiredCells.Fill(nFired);
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");
257 for(Int_t i = 0; i < 4; i++) delete mapping[i];
259 /* Be sure that all histograms are saved */
265 Int_t nGood=0; // >10 entries in peak
266 Int_t nMax=-111; // max. number of entries in peak
271 for(Int_t iMod=0; iMod<5; iMod++) {
272 if(!dAs[iMod]) continue;
274 printf("DA1 for module %d detected.\n",iMod);
275 sprintf(localfile,"PHOS_Module%d_LED.root",iMod);
276 TFile* f = new TFile(localfile,"recreate");
278 for(Int_t iX=0; iX<64; iX++) {
279 for(Int_t iZ=0; iZ<56; iZ++) {
281 h1 = dAs[iMod]->GetHgLgRatioHistogram(iX,iZ); // High Gain/Low Gain ratio
283 if(h1->GetMaximum()>10.) nGood++;
284 if(h1->GetMaximum()>nMax) {
285 nMax = (Int_t)h1->GetMaximum(); iXmax=iX; iZmax=iZ; iModMax=iMod;
290 for(Int_t iGain=0; iGain<2; iGain++) {
291 h2 = dAs[iMod]->GetTimeEnergyHistogram(iX,iZ,iGain); // Time vs Energy
301 /* Store output files to the File Exchange Server */
302 daqDA_FES_storeFile(localfile,"LED");
305 printf("%d physics events of %d total processed.\n",nevents_physics,nevents_total);
306 printf("%d histograms has >10 entries in maximum, max. is %d entries ",nGood,nMax);
307 printf("(module,iX,iZ)=(%d,%d,%d)",iModMax,iXmax,iZmax);