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: Mod0RCU0.data Mod0RCU1.data Mod0RCU2.data Mod0RCU3.data Mod1RCU0.data Mod1RCU1.data Mod1RCU2.data Mod1RCU3.data Mod2RCU0.data Mod2RCU1.data Mod2RCU2.data Mod2RCU3.data Mod3RCU0.data Mod3RCU1.data Mod3RCU2.data Mod3RCU3.data Mod4RCU0.data Mod4RCU1.data Mod4RCU2.data Mod4RCU3.data zs.txt
9 Output files: PHOS_ModuleN_Calib.root, where N is the module number (0-5), PHOS_Calib.root
10 Trigger types used: PHYSICS
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"
37 1- monitoring data source
39 int main(int argc, char **argv) {
41 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
47 AliLog::SetGlobalDebugLevel(0) ;
48 AliLog::SetGlobalLogLevel(AliLog::kFatal);
53 printf("Wrong number of arguments\n");
57 /* Retrieve ZS parameters from DAQ DB */
58 const char* zsfile = "zs.txt";
59 int failZS = daqDA_DB_getFile(zsfile, zsfile);
61 Int_t offset,threshold;
64 FILE *f = fopen(zsfile,"r");
65 int scan = fscanf(f,"%d %d",&offset,&threshold);
68 /* Retrieve mapping files from DAQ DB */
69 const char* mapFiles[20] = {
92 for(Int_t iFile=0; iFile<20; iFile++) {
93 int failed = daqDA_DB_getFile(mapFiles[iFile], mapFiles[iFile]);
95 printf("Cannot retrieve file %s from DAQ DB. Exit.\n",mapFiles[iFile]);
100 /* Open mapping files */
101 AliAltroMapping *mapping[20];
109 for(Int_t iMod = 0; iMod < 5; iMod++) {
114 for(Int_t iRCU=0; iRCU<4; iRCU++) {
118 mapping[iMap] = new AliCaloAltroMapping(path3.Data());
123 /* define data source : this is argument 1 */
124 status=monitorSetDataSource( argv[1] );
126 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
131 /* declare monitoring program */
132 status=monitorDeclareMp( __FILE__ );
134 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
139 /* define wait event timeout - 1s max */
141 monitorSetNoWaitNetworkTimeout(1000);
143 /* init some counters */
144 int nevents_physics=0;
147 AliRawReader *rawReader = NULL;
148 AliPHOSRcuDA1* dAs[5];
150 for(Int_t iMod=0; iMod<5; iMod++) {
154 Float_t e[64][56][2];
155 Float_t t[64][56][2];
157 for(Int_t iX=0; iX<64; iX++) {
158 for(Int_t iZ=0; iZ<56; iZ++) {
159 for(Int_t iGain=0; iGain<2; iGain++) {
160 e[iX][iZ][iGain] = 0.;
161 t[iX][iZ][iGain] = 0.;
169 Int_t sigStart, sigLength;
172 /* main loop (infinite) */
174 struct eventHeaderStruct *event;
175 eventTypeType eventT;
177 /* check shutdown condition */
178 if (daqDA_checkShutdown()) {break;}
180 /* get next event (blocking call until timeout) */
181 status=monitorGetEventDynamic((void **)&event);
182 if (status==MON_ERR_EOF) {
183 printf ("End of File detected\n");
184 break; /* end of monitoring file has been reached */
188 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
192 /* retry if got no event */
198 /* use event - here, just write event id to result file */
199 eventT=event->eventType;
201 if (eventT==PHYSICS_EVENT) {
203 rawReader = new AliRawReaderDate((void*)event);
204 AliCaloRawStreamV3 stream(rawReader,"PHOS",mapping);
205 AliPHOSRawFitterv0 fitter;
206 fitter.SubtractPedestals(kTRUE); // assume that data is non-ZS
209 fitter.SubtractPedestals(kFALSE);
210 fitter.SetAmpOffset(offset);
211 fitter.SetAmpThreshold(threshold);
214 while (stream.NextDDL()) {
215 while (stream.NextChannel()) {
217 /* Retrieve ZS parameters from data*/
219 short value = stream.GetAltroCFG1();
220 bool ZeroSuppressionEnabled = (value >> 15) & 0x1;
221 bool AutomaticBaselineSubtraction = (value >> 14) & 0x1;
222 if(ZeroSuppressionEnabled) {
223 offset = (value >> 10) & 0xf;
224 threshold = value & 0x3ff;
225 fitter.SubtractPedestals(kFALSE);
226 fitter.SetAmpOffset(offset);
227 fitter.SetAmpThreshold(threshold);
231 cellX = stream.GetCellX();
232 cellZ = stream.GetCellZ();
233 caloFlag = stream.GetCaloFlag(); // 0=LG, 1=HG, 2=TRU
235 if(caloFlag!=0 && caloFlag!=1) continue; //TRU data!
237 // In case of oscillating signals with ZS,
238 //a channel can have several bunches.
241 while (stream.NextBunch()) {
243 if (nBunches > 1) continue;
244 sigStart = stream.GetStartTimeBin();
245 sigLength = stream.GetBunchLength();
246 fitter.SetChannelGeo(stream.GetModule(),cellX,cellZ,caloFlag);
247 fitter.Eval(stream.GetSignals(),sigStart,sigLength);
248 } // End of NextBunch()
250 if (nBunches>1) continue;
252 e[cellX][cellZ][caloFlag] = fitter.GetEnergy();
253 t[cellX][cellZ][caloFlag] = fitter.GetTime();
256 if(stream.GetModule()<0 || stream.GetModule()>4) continue;
258 if(dAs[stream.GetModule()])
259 dAs[stream.GetModule()]->FillHistograms(e,t);
261 dAs[stream.GetModule()] = new AliPHOSRcuDA1(stream.GetModule(),-1);
262 dAs[stream.GetModule()]->FillHistograms(e,t);
265 for(Int_t iX=0; iX<64; iX++) {
266 for(Int_t iZ=0; iZ<56; iZ++) {
267 for(Int_t iGain=0; iGain<2; iGain++) {
268 e[iX][iZ][iGain] = 0.;
269 t[iX][iZ][iGain] = 0.;
276 // da1.FillHistograms(e,t);
277 // //da1.UpdateHistoFile();
288 /* exit when last event received, no need to wait for TERM signal */
289 if (eventT==END_OF_RUN) {
290 printf("EOR event detected\n");
295 for(Int_t i = 0; i < 20; i++) delete mapping[i];
297 /* Be sure that all histograms are saved */
299 for(Int_t iMod=0; iMod<5; iMod++) {
300 if(!dAs[iMod]) continue;
302 printf("DA1 for module %d detected.\n",iMod);
304 dAs[iMod]->UpdateHistoFile();
305 dAs[iMod]->SetWriteToFile(kFALSE);
312 sprintf(localfile,"PHOS_Calib.root");
313 TFile* f = new TFile(localfile,"recreate");
315 for(Int_t iMod=0; iMod<5; iMod++) {
316 if(!dAs[iMod]) continue;
318 for(Int_t iX=0; iX<64; iX++) {
319 for(Int_t iZ=0; iZ<56; iZ++) {
321 h1 = dAs[iMod]->GetHgLgRatioHistogram(iX,iZ); // High Gain/Low Gain ratio
324 for(Int_t iGain=0; iGain<2; iGain++) {
325 h2 = dAs[iMod]->GetTimeEnergyHistogram(iX,iZ,iGain); // Time vs Energy
334 /* Store output files to the File Exchange Server */
335 daqDA_FES_storeFile(localfile,"AMPLITUDES");