]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/PHOSGAINda.cxx
In MUONRecoCheck.C:
[u/mrichter/AliRoot.git] / PHOS / PHOSGAINda.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: PHYSICS
6 DA type: MON 
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_Calib_Total.root contains cumulative statistics for a number of runs. 
10 Trigger types used: PHYSICS
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 /* Main routine
36       Arguments: 
37       1- monitoring data source
38 */
39 int main(int argc, char **argv) {
40
41   gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
42                                         "*",
43                                         "TStreamerInfo",
44                                         "RIO",
45                                         "TStreamerInfo()");
46
47   AliLog::SetGlobalDebugLevel(0) ;
48   AliLog::SetGlobalLogLevel(AliLog::kFatal);
49   
50   int status;
51   
52   if (argc!=2) {
53     printf("Wrong number of arguments\n");
54     return -1;
55   }
56   
57   /* Retrieve ZS parameters from DAQ DB */
58   const char* zsfile = "zs.txt";
59   int failZS = daqDA_DB_getFile(zsfile, zsfile);
60   
61   Int_t offset,threshold;
62   
63   if(!failZS) {
64     FILE *f = fopen(zsfile,"r");
65     int scan = fscanf(f,"%d %d",&offset,&threshold);
66   }
67   
68   /* Retrieve mapping files from DAQ DB */ 
69   const char* mapFiles[20] = {
70     "Mod0RCU0.data",
71     "Mod0RCU1.data",
72     "Mod0RCU2.data",
73     "Mod0RCU3.data",
74     "Mod1RCU0.data",
75     "Mod1RCU1.data",
76     "Mod1RCU2.data",
77     "Mod1RCU3.data",
78     "Mod2RCU0.data",
79     "Mod2RCU1.data",
80     "Mod2RCU2.data",
81     "Mod2RCU3.data",
82     "Mod3RCU0.data",
83     "Mod3RCU1.data",
84     "Mod3RCU2.data",
85     "Mod3RCU3.data",
86     "Mod4RCU0.data",
87     "Mod4RCU1.data",
88     "Mod4RCU2.data",
89     "Mod4RCU3.data"
90   };
91   
92   for(Int_t iFile=0; iFile<20; iFile++) {
93     int failed = daqDA_DB_getFile(mapFiles[iFile], mapFiles[iFile]);
94     if(failed) { 
95       printf("Cannot retrieve file %s from DAQ DB. Exit.\n",mapFiles[iFile]);
96       return -1;
97     }
98   }
99   
100   /* Open mapping files */
101   AliAltroMapping *mapping[20];
102   TString path = "./";
103   
104   path += "Mod";
105   TString path2;
106   TString path3;
107   Int_t iMap = 0;
108   
109   for(Int_t iMod = 0; iMod < 5; iMod++) {
110     path2 = path;
111     path2 += iMod;
112     path2 += "RCU";
113     
114     for(Int_t iRCU=0; iRCU<4; iRCU++) {
115       path3 = path2;
116       path3 += iRCU;
117       path3 += ".data";
118       mapping[iMap] = new AliCaloAltroMapping(path3.Data());
119       iMap++;
120     }
121   }
122   
123   /* define data source : this is argument 1 */  
124   status=monitorSetDataSource( argv[1] );
125   if (status!=0) {
126     printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
127     return -1;
128   }
129
130
131   /* declare monitoring program */
132   status=monitorDeclareMp( __FILE__ );
133   if (status!=0) {
134     printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
135     return -1;
136   }
137
138
139   /* define wait event timeout - 1s max */
140   monitorSetNowait();
141   monitorSetNoWaitNetworkTimeout(1000);
142   
143    /* init some counters */
144   int nevents_physics=0;
145   int nevents_total=0;
146
147   AliRawReader *rawReader = NULL;
148   AliPHOSRcuDA1* dAs[5];
149
150   for(Int_t iMod=0; iMod<5; iMod++) {
151     dAs[iMod] = 0;
152   }
153   
154   Float_t e[64][56][2];
155   Float_t t[64][56][2];
156
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.;
162       }
163     }
164   }
165   
166   Int_t cellX    = -1;
167   Int_t cellZ    = -1;
168   Int_t nBunches =  0;
169   Int_t sigStart, sigLength;
170   Int_t caloFlag;
171
172   /* main loop (infinite) */
173   for(;;) {
174     struct eventHeaderStruct *event;
175     eventTypeType eventT;
176   
177     /* check shutdown condition */
178     if (daqDA_checkShutdown()) {break;}
179     
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 */
185     }
186     
187     if (status!=0) {
188       printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
189       break;
190     }
191
192     /* retry if got no event */
193     if (event==NULL) {
194       continue;
195     }
196
197
198     /* use event - here, just write event id to result file */
199     eventT=event->eventType;
200     
201     if (eventT==PHYSICS_EVENT) {
202       
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
207       
208       if(!failZS) {
209         fitter.SubtractPedestals(kFALSE);
210         fitter.SetAmpOffset(offset);
211         fitter.SetAmpThreshold(threshold);
212       }
213       
214       while (stream.NextDDL()) {
215         while (stream.NextChannel()) {
216           
217           /* Retrieve ZS parameters from data*/
218           if(failZS) {
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);
228             }
229           }
230           
231           cellX    = stream.GetCellX();
232           cellZ    = stream.GetCellZ();
233           caloFlag = stream.GetCaloFlag();  // 0=LG, 1=HG, 2=TRU
234           
235           if(caloFlag!=0 && caloFlag!=1) continue; //TRU data!
236           
237           // In case of oscillating signals with ZS, 
238           //a channel can have several bunches.
239           
240           nBunches = 0;
241           while (stream.NextBunch()) {
242             nBunches++;
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()
249           
250           if (nBunches != 1) continue;
251           
252           e[cellX][cellZ][caloFlag] = fitter.GetEnergy();
253           t[cellX][cellZ][caloFlag] = fitter.GetTime();
254         }
255         
256         if(stream.GetModule()<0 || stream.GetModule()>4) continue;
257         
258         if(dAs[stream.GetModule()])
259           dAs[stream.GetModule()]->FillHistograms(e,t);
260         else {
261           dAs[stream.GetModule()] = new AliPHOSRcuDA1(stream.GetModule(),-1,0);
262           dAs[stream.GetModule()]->FillHistograms(e,t);
263         }
264         
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.;
270             }
271           }
272         }
273
274       }
275
276 //       da1.FillHistograms(e,t);
277 //     //da1.UpdateHistoFile();
278       
279         delete rawReader;     
280         nevents_physics++;
281     }
282     
283     nevents_total++;
284     
285     /* free resources */
286     free(event);
287     
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");
291       break;
292     }
293   }
294   
295   for(Int_t i = 0; i < 20; i++) delete mapping[i];  
296   
297   /* Be sure that all histograms are saved */
298
299   char h2name[80];
300   char totfile[80];
301   
302   //Write the Total file (accumulated statistics for number of runs)
303   sprintf(totfile,"PHOS_Calib_Total.root");
304   TFile * ftot = new TFile(totfile,"recreate");
305   
306 //   if (!ftot->IsZombie()){
307 //     printf("Updating file %s.\n",ftot->GetName());
308
309 //     for(Int_t iMod=0; iMod<5; iMod++) {
310 //       if(!dAs[iMod]) continue;
311     
312 //       printf("DA1 for module %d detected.\n",iMod);
313     
314 //       for(Int_t iX=0; iX<64; iX++) {
315 //      for(Int_t iZ=0; iZ<56; iZ++) {
316         
317 //        for(Int_t iGain=0; iGain<2; iGain++) {
318 //          sprintf(h2name,"%d_%d_%d_%d",iMod,iX,iZ,iGain);
319 //          TH2F* h2tot = (TH2F*)ftot->Get(h2name);
320 //          const TH2F* h2run = dAs[iMod]->GetTimeEnergyHistogram(iX,iZ,iGain); // Time vs Energy
321 //          if(!h2tot && h2run) h2run->Write();
322 //          if(h2tot && h2run) { h2tot->Add(h2run); h2tot->Write(h2tot->GetName(),TObject::kWriteDelete); }
323 //        }
324 //      }
325 //       }
326 //     }
327 //   }
328   
329   ftot->Close();
330   
331   /* Store output files to the File Exchange Server */
332   daqDA_FES_storeFile(totfile,"AMPLITUDES");
333   
334   return status;
335 }