3 TPCda_pedestal.cxx - calibration algorithm for TPC pedestal runs
5 10/06/2007 sylvain.chapeland@cern.ch : first version - clean skeleton based on DAQ DA case1
7 contact: marian.ivanov@cern.ch
10 This process reads RAW data from the files provided as command line arguments
11 and save results in a file (named from RESULT_FILE define - see below).
15 #define RESULT_FILE "tpcPedestal.root"
36 #include "AliRawReader.h"
37 #include "AliRawReaderDate.h"
38 #include "AliTPCmapper.h"
39 #include "AliTPCRawStream.h"
40 #include "AliTPCROC.h"
41 #include "AliTPCCalROC.h"
42 #include "AliTPCCalPad.h"
43 #include "AliMathBase.h"
44 #include "TTreeStream.h"
47 // TPC calibration algorithm includes
49 #include "AliTPCCalibPedestal.h"
52 Main routine, TPC pedestal detector algorithm to be run on TPC LDC
53 Arguments: list of DATE raw data files
56 int main(int argc, char **argv) {
58 // Main for TPC pedestal detector algorithm
60 Bool_t timeAnalysis = kTRUE;
63 AliTPCCalibPedestal calibPedestal; // pedestal and noise calibration
64 calibPedestal.SetTimeAnalysis(timeAnalysis); // pedestal(t) calibration
67 printf("Wrong number of arguments\n");
71 /* log start of process */
72 printf("TPC DA started - %s\n",__FILE__);
74 /* declare monitoring program */
75 status=monitorDeclareMp( __FILE__ );
77 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
81 /* loop over RAW data files */
83 for ( i=1; i<argc; i++ ) {
85 /* define data source : this is argument i */
86 printf("Processing file %s\n", argv[i]);
87 status=monitorSetDataSource( argv[i] );
89 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
95 struct eventHeaderStruct *event;
97 /* check shutdown condition */
98 if (daqDA_checkShutdown()) {break;}
100 /* get next event (blocking call until timeout) */
101 status=monitorGetEventDynamic((void **)&event);
102 if (status==MON_ERR_EOF) {
103 printf ("End of File %d (%s) detected\n", i, argv[i]);
104 break; /* end of monitoring file has been reached */
107 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
111 /* skip start/end of run events */
112 if ( (event->eventType != physicsEvent) && (event->eventType != calibrationEvent) )
115 /* retry if got no event */
122 // Pedestal calibration
123 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
124 calibPedestal.ProcessEvent(rawReader);
132 calibPedestal.Analyse();
133 calibPedestal.AnalyseTime(nevents);
134 printf ("%d physics/calibration events processed\n",nevents);
136 TFile *fileTPC = new TFile(RESULT_FILE, "recreate");
137 calibPedestal.Write("calibPedestal");
139 printf("Wrote %s\n",RESULT_FILE);
142 // Now prepare ASCII files for local ALTRO configuration through DDL
149 sprintf(filename,"tpcPedestals.data");
150 pedfile.open(filename);
151 sprintf(filename,"tpcNoise.data");
152 noisefile.open(filename);
153 sprintf(filename,"tpcPedestalMem.data");
154 pedmemfile.open(filename);
156 TArrayF **timePed = calibPedestal.GetTimePedestals();
157 AliTPCmapper mapping;
159 Int_t ctr_channel = 0;
161 Int_t ctr_pattern = 0;
163 pedfile << 10 << std::endl; // PEDESTALS per channel
164 noisefile << 11 << std::endl; // NOISE per altro
165 pedmemfile << 12 << std::endl; // PEDESTALs per time bin
167 for ( Int_t roc = 0; roc < 72; roc++ ) {
168 if ( !calibPedestal.GetCalRocPedestal(roc) ) continue;
169 Int_t side = mapping.GetSideFromRoc(roc);
170 Int_t sector = mapping.GetSectorFromRoc(roc);
171 //printf("Analysing ROC %d (side %d, sector %d) ...\n", roc, side, sector);
172 Int_t nru = mapping.IsIROC(roc) ? 2 : 4;
173 for ( int rcu = 0; rcu < nru; rcu++ ) {
174 Int_t patch = mapping.IsIROC(roc) ? rcu : rcu+2;
175 for ( int branch = 0; branch < 2; branch++ ) {
176 for ( int fec = 0; fec < mapping.GetNfec(patch, branch); fec++ ) {
177 for ( int altro = 0; altro < 8; altro++ ) {
180 for ( int channel = 0; channel < 16; channel++ ) {
181 Int_t hwadd = mapping.CodeHWAddress(branch, fec, altro, channel);
182 Int_t row = mapping.GetPadRow(patch, hwadd);
183 Int_t pad = mapping.GetPad(patch, hwadd);
184 Float_t ped = calibPedestal.GetCalRocPedestal(roc)->GetValue(row,pad);
186 if ( ped > 1.e-10 ) {
187 pedfile << ctr_channel << "\t" << side << "\t" << sector << "\t" << patch << "\t" << hwadd << "\t" << ped << std::endl;
191 if ( timePed && fabs(timePed[row][pad].GetSum()) > 1e-10 ) {
192 pedmemfile << ctr_pattern << "\t" << side << "\t" << sector << "\t" << patch << "\t" << hwadd;
193 for ( Int_t timebin = 0; timebin < 1024; timebin++ )
194 pedmemfile << "\t" << timePed[row][pad].At(timebin);
195 pedmemfile << std::endl;
199 Float_t rms2 = calibPedestal.GetCalRocRMS(roc)->GetValue(row,pad);
200 if ( rms2 > 1.e-10 ) { rms += rms2; ctr += 1.; }
201 } // end channel for loop
202 // noise data (rms) averaged over all channels in this ALTRO.
203 Int_t hwadd = mapping.CodeHWAddress(branch, fec, altro, 0);
204 if ( ctr > 1.e-10 ) {
205 noisefile << ctr_altro << "\t" << side << "\t" << sector << "\t" << patch << "\t" << hwadd << "\t" << rms/ctr << std::endl;
208 } // end altro for loop
209 } // end fec for loop
210 } // end branch for loop
211 } // end rcu for loop
218 printf("Wrote ASCII files\n");