2 TPC DA for online calibration
4 Contact: Haavard.Helstrup@cern.ch
8 Number of events needed: 100
10 Output Files: tpcPedestal.root, to be exported to the DAQ FXS
11 Trigger types used: CALIBRATION_EVENT
18 TPCda_pedestal.cxx - calibration algorithm for TPC pedestal runs
20 10/06/2007 sylvain.chapeland@cern.ch : first version - clean skeleton based on DAQ DA case1
22 contact: marian.ivanov@cern.ch
25 This process reads RAW data from the files provided as command line arguments
26 and save results in a file (named from RESULT_FILE define - see below).
30 #define RESULT_FILE "tpcPedestal.root"
51 #include "AliRawReader.h"
52 #include "AliRawReaderDate.h"
53 #include "AliTPCmapper.h"
54 #include "AliTPCRawStream.h"
55 #include "AliTPCROC.h"
56 #include "AliTPCCalROC.h"
57 #include "AliTPCCalPad.h"
58 #include "AliMathBase.h"
59 #include "TTreeStream.h"
62 // TPC calibration algorithm includes
64 #include "AliTPCCalibPedestal.h"
67 Main routine, TPC pedestal detector algorithm to be run on TPC LDC
68 Arguments: list of DATE raw data files
71 int main(int argc, char **argv) {
73 // Main for TPC pedestal detector algorithm
75 Bool_t timeAnalysis = kTRUE;
78 AliTPCCalibPedestal calibPedestal; // pedestal and noise calibration
79 calibPedestal.SetRangeTime(60,940); // set time bin range
80 calibPedestal.SetTimeAnalysis(timeAnalysis); // pedestal(t) calibration
83 printf("Wrong number of arguments\n");
87 /* log start of process */
88 printf("TPC DA started - %s\n",__FILE__);
90 /* declare monitoring program */
91 status=monitorDeclareMp( __FILE__ );
93 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
97 /* loop over RAW data files */
99 for ( i=1; i<argc; i++ ) {
101 /* define data source : this is argument i */
102 printf("Processing file %s\n", argv[i]);
103 status=monitorSetDataSource( argv[i] );
105 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
111 struct eventHeaderStruct *event;
113 /* check shutdown condition */
114 if (daqDA_checkShutdown()) {break;}
116 /* get next event (blocking call until timeout) */
117 status=monitorGetEventDynamic((void **)&event);
118 if (status==MON_ERR_EOF) {
119 printf ("End of File %d (%s) detected\n", i, argv[i]);
120 break; /* end of monitoring file has been reached */
123 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
127 /* skip start/end of run events */
128 if ( (event->eventType != physicsEvent) && (event->eventType != calibrationEvent) )
131 /* retry if got no event */
138 // Pedestal calibration
139 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
140 calibPedestal.ProcessEvent(rawReader);
148 calibPedestal.Analyse();
149 calibPedestal.AnalyseTime(nevents);
150 printf ("%d physics/calibration events processed\n",nevents);
152 TFile *fileTPC = new TFile(RESULT_FILE, "recreate");
153 calibPedestal.Write("calibPedestal");
155 printf("Wrote %s\n",RESULT_FILE);
157 /* store the result file on FES */
159 status=daqDA_FES_storeFile(RESULT_FILE,RESULT_FILE);
166 // Now prepare ASCII files for local ALTRO configuration through DDL
173 sprintf(filename,"tpcPedestals.data");
174 pedfile.open(filename);
175 sprintf(filename,"tpcNoise.data");
176 noisefile.open(filename);
177 sprintf(filename,"tpcPedestalMem.data");
178 pedmemfile.open(filename);
180 TArrayF **timePed = calibPedestal.GetTimePedestals();
181 AliTPCmapper mapping;
183 Int_t ctr_channel = 0;
185 Int_t ctr_pattern = 0;
187 pedfile << 10 << std::endl; // PEDESTALS per channel
188 noisefile << 11 << std::endl; // NOISE per altro
189 pedmemfile << 12 << std::endl; // PEDESTALs per time bin
191 for ( Int_t roc = 0; roc < 72; roc++ ) {
192 if ( !calibPedestal.GetCalRocPedestal(roc) ) continue;
193 Int_t side = mapping.GetSideFromRoc(roc);
194 Int_t sector = mapping.GetSectorFromRoc(roc);
195 //printf("Analysing ROC %d (side %d, sector %d) ...\n", roc, side, sector);
196 Int_t nru = mapping.IsIROC(roc) ? 2 : 4;
197 for ( int rcu = 0; rcu < nru; rcu++ ) {
198 Int_t patch = mapping.IsIROC(roc) ? rcu : rcu+2;
199 for ( int branch = 0; branch < 2; branch++ ) {
200 for ( int fec = 0; fec < mapping.GetNfec(patch, branch); fec++ ) {
201 for ( int altro = 0; altro < 8; altro++ ) {
204 for ( int channel = 0; channel < 16; channel++ ) {
205 Int_t hwadd = mapping.CodeHWAddress(branch, fec, altro, channel);
206 Int_t row = mapping.GetPadRow(patch, hwadd);
207 Int_t pad = mapping.GetPad(patch, hwadd);
208 Float_t ped = calibPedestal.GetCalRocPedestal(roc)->GetValue(row,pad);
210 if ( ped > 1.e-10 ) {
211 pedfile << ctr_channel << "\t" << side << "\t" << sector << "\t" << patch << "\t" << hwadd << "\t" << ped << std::endl;
215 if ( timePed && fabs(timePed[row][pad].GetSum()) > 1e-10 ) {
216 pedmemfile << ctr_pattern << "\t" << side << "\t" << sector << "\t" << patch << "\t" << hwadd;
217 for ( Int_t timebin = 0; timebin < 1024; timebin++ )
218 pedmemfile << "\t" << timePed[row][pad].At(timebin);
219 pedmemfile << std::endl;
223 Float_t rms2 = calibPedestal.GetCalRocRMS(roc)->GetValue(row,pad);
224 if ( rms2 > 1.e-10 ) { rms += rms2; ctr += 1.; }
225 } // end channel for loop
226 // noise data (rms) averaged over all channels in this ALTRO.
227 Int_t hwadd = mapping.CodeHWAddress(branch, fec, altro, 0);
228 if ( ctr > 1.e-10 ) {
229 noisefile << ctr_altro << "\t" << side << "\t" << sector << "\t" << patch << "\t" << hwadd << "\t" << rms/ctr << std::endl;
232 } // end altro for loop
233 } // end fec for loop
234 } // end branch for loop
235 } // end rcu for loop
242 printf("Wrote ASCII files\n");