2 PMD DA for online calibration
4 contact: basanta@phy.iitb.ac.in
6 Reference run:/afs/cern.ch/user/b/bnandi/public/gaindata/pythia100evts.date
9 Number of events needed: 1 million for PB+PB, 200 milion for p+p
10 Input Files: PMD_PED.root, PMD_GAIN_CONFIGFILE, pmd_gain_tempfile.dat
11 Output Files: PMDGAINS.root, to be exported to the DAQ FES
12 Trigger types used: PHYSICS_EVENT
22 #include <Riostream.h>
27 #include "AliRawReaderDate.h"
28 #include "AliPMDCalibPedestal.h"
29 #include "AliPMDCalibGain.h"
34 #include "TBenchmark.h"
37 #include "TPluginManager.h"
43 1- monitoring data source
45 int main(int argc, char **argv) {
47 /* magic line from Rene */
48 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
58 Int_t filestatus = -1, xvar = 5;
59 Int_t totevt = -1, maxevt = -1;
60 Int_t hotevtsize = -1;
61 Bool_t hotfilestatus = false;
63 // Reads the pedestal file and keep the values in memory for subtraction
65 AliPMDCalibGain calibgain;
67 // Fetch the pedestal file - PMD_PED.root
69 status = daqDA_DB_getFile("PMD_PED.root","PMD_PED.root");
73 printf("*** Pedestal file retrieved from DB *** \n");
77 printf("*** Pedestal file NOT retrieved from DB *** \n");
81 Int_t pstatus = calibgain.ExtractPedestal("PMD_PED.root");
83 if(pstatus == -3) return -3;
88 // Retrieve the PMD_GAIN_CONFIGFILE
89 status = daqDA_DB_getFile("PMD_GAIN_CONFIGFILE","PMD_GAIN_CONFIGFILE");
93 fp1 = fopen("PMD_GAIN_CONFIGFILE","r");
97 printf("*** PMD GAIN Configfile doesn't exist,Provide one ***\n");
102 fscanf(fp1,"%d %d %d %d %d\n",&filestatus, &xvar, &totevt, &maxevt, &hotevtsize);
103 //printf("%d %d %d %d %d\n",filestatus, xvar, totevt, maxevt, hotevtsize);
110 // Retrieve the Temporray ascii file from DB
111 status = daqDA_DB_getFile("pmd_gain_tempfile.dat","pmd_gain_tempfile.dat");
114 calibgain.ReadTempFile("pmd_gain_tempfile.dat");
118 printf("--- pmd_gain_tempfile.dat: not retrieved from DB ---\n");
120 // Retrieve the hot cell file from DB - PMD_HOT.root
121 status = daqDA_DB_getFile("PMD_HOT.root","PMD_HOT.root");
124 calibgain.ExtractHotChannel("PMD_HOT.root");
128 printf("--- pmd_gain_tempfile.dat: not retrieved from DB ---\n");
133 // decoding the events
137 printf("Wrong number of arguments\n");
142 /* define data source : this is argument 1 */
143 status=monitorSetDataSource( argv[1] );
145 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
149 /* declare monitoring program */
150 status=monitorDeclareMp( __FILE__ );
152 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
156 /* define wait event timeout - 1s max */
158 monitorSetNoWaitNetworkTimeout(1000);
160 /* log start of process */
161 printf("PMD GAIN DA - strted generating the gain of a cell\n");
163 /* init some counters */
164 int nevents_physics=0;
167 struct eventHeaderStruct *event;
168 eventTypeType eventT = 0;
172 /* main loop (infinite) */
175 /* check shutdown condition */
176 if (daqDA_checkShutdown()) {break;}
178 /* get next event (blocking call until timeout) */
179 status=monitorGetEventDynamic((void **)&event);
180 if (status==MON_ERR_EOF) {
181 printf ("End of File detected\n");
182 break; /* end of monitoring file has been reached */
186 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
190 /* retry if got no event */
197 /* use event - here, just write event id to result file */
199 eventT=event->eventType;
200 switch (event->eventType){
205 /* END START OF RUN */
214 //if(nevents_physics%100 == 0)printf("Physis Events = %d\n",nevents_physics);
215 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
216 TObjArray *pmdddlcont = new TObjArray();
217 calibgain.ProcessEvent(rawReader, pmdddlcont);
219 if (totevt%hotevtsize == 0) hotfilestatus = true;
232 /* exit when last event received, no need to wait for TERM signal */
235 ic = new TTree("ic","PMD Gain tree");
236 meanc = new TTree("meanc","PMD Module mean tree");
240 TFile *hotRun = new TFile ("PMD_HOT.root","RECREATE");
242 TTree *hot = new TTree("hot","PMD Hot cell tree");
244 calibgain.FindHotCell(hot,xvar);
249 // store the hot cell root file in the DB
251 status = daqDA_DB_storeFile("PMD_HOT.root","PMD_HOT.root");
253 // store the hot cell root file in the file exchange server
255 printf("root file for hot cell is created and getting exported\n");
256 status = daqDA_FES_storeFile("PMD_HOT.root","PMD_HOT.root");
261 TFile *hotRun = new TFile ("PMD_HOT.root","RECREATE");
263 TTree *hot = new TTree("hot","PMD Hot cell tree");
265 calibgain.FindHotCell(hot,xvar);
270 // store the hot cell root file in the DB
272 status = daqDA_DB_storeFile("PMD_HOT.root","PMD_HOT.root");
274 // store the hot cell root file in the file exchange server
276 printf("root file for hot cell is created and getting exported\n");
277 status = daqDA_FES_storeFile("PMD_HOT.root","PMD_HOT.root");
281 fp1 = fopen("PMD_GAIN_CONFIGFILE","w+");
285 printf("-----------------------------------------------\n");
286 printf("*** Required Number of Events not reached ***\n");
287 printf("*** Number of Events processed = %d ***\n",totevt);
288 printf("*** Writing the intermediate ASCII file ***\n");
289 printf("-----------------------------------------------\n");
291 calibgain.WriteTempFile("pmd_gain_tempfile.dat");
293 // Store the Intermediate ascii file in the DB
294 status = daqDA_DB_storeFile("pmd_gain_tempfile.dat","pmd_gain_tempfile.dat");
297 fprintf(fp1,"%d %d %d %d %d\n",filestatus,xvar,totevt,maxevt,hotevtsize);
300 // Store the configfile in the DB
301 status = daqDA_DB_storeFile("PMD_GAIN_CONFIGFILE","PMD_GAIN_CONFIGFILE");
304 else if (totevt >= maxevt)
306 printf("-----------------------------------------------\n");
307 printf("*** Required Number of Events reached = %d ***\n",totevt);
308 printf("*** Writing the PMDGAINS.root file ***\n");
309 printf("-----------------------------------------------\n");
311 calibgain.Analyse(ic, meanc);
313 TFile * gainRun = new TFile ("PMDGAINS.root","RECREATE");
317 TFile * meanRun = new TFile ("PMD_MEAN_SM.root","RECREATE");
324 fprintf(fp1,"%d %d %d %d %d\n",filestatus,xvar,totevt,maxevt,hotevtsize);
327 // Store the configfile in the DB
328 status = daqDA_DB_storeFile("PMD_GAIN_CONFIGFILE","PMD_GAIN_CONFIGFILE");
338 /* store the result file on FES */
342 printf("root file for cell gain is created and getting exported\n");
343 status = daqDA_FES_storeFile("PMDGAINS.root","PMDGAINS.root");
344 printf("root file for normalised means of different modules\n");
345 status = daqDA_FES_storeFile("PMD_MEAN_SM.root","PMD_MEAN_SM.root");