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