]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/PHOSLEDda.cxx
All histograms now written in one file, no matter how much modules processed.
[u/mrichter/AliRoot.git] / PHOS / PHOSLEDda.cxx
1 /*
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
5 run type: LED
6 DA type: MON 
7 number of events needed: 1000
8 input files: RCU0.data  RCU1.data  RCU2.data  RCU3.data  zs.txt
9 Output files: PHOS_LED.root.
10 Trigger types used: CALIBRATION_EVENT
11 */
12
13
14 #include "event.h"
15 #include "monitor.h"
16 extern "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"
30 #include "AliPHOSRawFitterv0.h"
31 #include "AliCaloAltroMapping.h"
32 #include "AliCaloRawStreamV3.h"
33 #include "AliLog.h"
34
35
36 /* Main routine
37       Arguments: 
38       1- monitoring data source
39 */
40 int main(int argc, char **argv) {
41
42   gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
43                                         "*",
44                                         "TStreamerInfo",
45                                         "RIO",
46                                         "TStreamerInfo()");
47
48   AliLog::SetGlobalDebugLevel(0) ;
49   AliLog::SetGlobalLogLevel(AliLog::kFatal);
50   
51   int status;
52   
53   if (argc!=2) {
54     printf("Wrong number of arguments\n");
55     return -1;
56   }
57
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
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;
116   
117   AliRawReader *rawReader = NULL;
118   AliPHOSRcuDA1* dAs[5];
119   
120   for(Int_t iMod=0; iMod<5; iMod++) {
121     dAs[iMod] = 0;
122   }
123
124   Float_t e[64][56][2];
125   Float_t t[64][56][2];
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   
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;
141   Int_t caloFlag;
142   
143
144   TH1I fFiredCells("fFiredCells","Number of fired cells per event",100,0,1000);
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       
177       nFired = 0;
178       
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
183
184       if(!failZS) {
185         fitter.SubtractPedestals(kFALSE);
186         fitter.SetAmpOffset(offset);
187         fitter.SetAmpThreshold(threshold);
188       }
189       
190       while (stream.NextDDL()) {
191         while (stream.NextChannel()) {
192           
193           cellX    = stream.GetCellX();
194           cellZ    = stream.GetCellZ();
195           caloFlag = stream.GetCaloFlag();  // 0=LG, 1=HG, 2=TRU
196           
197           if(caloFlag!=0 && caloFlag!=1) continue; //TRU data!
198           
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;
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()
209           
210           if(nBunches>1) continue;
211           
212           e[cellX][cellZ][caloFlag] = fitter.GetEnergy();
213           t[cellX][cellZ][caloFlag] = fitter.GetTime();
214           
215           if(caloFlag==1 && fitter.GetEnergy()>40)
216             nFired++;
217         }
218         
219         if(stream.GetModule()<0 || stream.GetModule()>4) continue;
220         
221         if(dAs[stream.GetModule()])
222           dAs[stream.GetModule()]->FillHistograms(e,t);
223         else {
224           dAs[stream.GetModule()] = new AliPHOSRcuDA1(stream.GetModule(),-1,0);
225           dAs[stream.GetModule()]->FillHistograms(e,t);
226         } 
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         
237       }
238       
239       fFiredCells.Fill(nFired);
240       
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 */
260   
261   const TH2F* h2=0;
262   const TH1F* h1=0;
263   char localfile[128];
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;
269   Int_t iModMax=-1;
270   
271   sprintf(localfile,"PHOS_LED.root");
272   TFile* f = new TFile(localfile,"recreate");
273
274   for(Int_t iMod=0; iMod<5; iMod++) {
275     if(!dAs[iMod]) continue;
276   
277     printf("DA1 for module %d detected.\n",iMod);
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         }
290       
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         }
295         
296       }
297     }
298     
299     fFiredCells.Write();    
300   }
301   
302   f->Close();
303   
304   /* Store output files to the File Exchange Server */
305   daqDA_FES_storeFile(localfile,"LED");
306   
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);
309   printf("(module,iX,iZ)=(%d,%d,%d)",iModMax,iXmax,iZmax);
310   printf("\n");
311
312   return status;
313 }