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
12 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
21 19/10/2007 christian.lippmann@cern.ch : Possibility to write output to ASCII file
22 24/10/2007 christian.lippmann@cern.ch : Including pedestal calibration for time bins
23 23/11/2007 christian.lippmann@cern.ch : Fix in order to avoid streamer problems in case of
24 invalid ROOTSTYS. The famous magic line provided by Rene.
25 28/11/2007 christian.lippmann@cern.ch : TPC mapping file is read from DaqDetDB
27 contact: marian.ivanov@cern.ch
29 This process reads RAW data from the files provided as command line arguments
30 and save results in a file (named from RESULT_FILE define - see below).
34 #define RESULT_FILE "tpcPedestal.root"
35 #define FILE_ID "pedestals"
36 #define MAPPING_FILE "tpcMapping.root"
37 #define AliDebugLevel() -1
55 #include "TPluginManager.h"
60 #include "AliRawReader.h"
61 #include "AliRawReaderDate.h"
62 #include "AliTPCmapper.h"
63 #include "AliTPCRawStream.h"
64 #include "AliTPCROC.h"
65 #include "AliTPCCalROC.h"
66 #include "AliTPCCalPad.h"
67 #include "AliMathBase.h"
68 #include "TTreeStream.h"
73 // TPC calibration algorithm includes
75 #include "AliTPCCalibPedestal.h"
78 Main routine, TPC pedestal detector algorithm to be run on TPC LDC
79 Arguments: list of DATE raw data files
82 int main(int argc, char **argv) {
84 // Main for TPC pedestal detector algorithm
87 AliLog::SetClassDebugLevel("AliTPCRawStream",-5);
88 AliLog::SetClassDebugLevel("AliRawReaderDate",-5);
89 AliLog::SetClassDebugLevel("AliTPCAltroMapping",-5);
90 AliLog::SetModuleDebugLevel("RAW",-5);
92 Bool_t timeAnalysis = kTRUE;
95 printf("Wrong number of arguments\n");
100 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
107 /* log start of process */
108 printf("TPC DA started - %s\n",__FILE__);
110 /* declare monitoring program */
111 status=monitorDeclareMp( __FILE__ );
113 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
117 AliTPCmapper *mapping = 0; // The TPC mapping
120 /* copy locally the mapping file from daq detector config db */
121 status = daqDA_DB_getFile(MAPPING_FILE,"./tpcMapping.root");
123 printf("Failed to get mapping file (%s) from DAQdetDB, status=%d\n", MAPPING_FILE, status);
124 printf("Continue anyway ... maybe it works?\n"); // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
125 return -1; // temporarily uncommented for testing on pcald47 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
128 /* open the mapping file and retrieve mapping object */
129 TFile *fileMapping = new TFile(MAPPING_FILE, "read");
130 mapping = (AliTPCmapper*) fileMapping->Get("tpcMapping");
135 printf("Failed to get mapping object from %s. ...\n", MAPPING_FILE);
138 printf("Got mapping object from %s\n", MAPPING_FILE);
141 AliTPCCalibPedestal calibPedestal; // pedestal and noise calibration
142 calibPedestal.SetRangeTime(60,940); // set time bin range
143 calibPedestal.SetTimeAnalysis(timeAnalysis); // pedestal(t) calibration
145 calibPedestal.SetAltroMapping(mapping->GetAltroMapping()); // Use altro mapping we got from daqDetDb
147 /* loop over RAW data files */
149 for ( i=1; i<argc; i++ ) {
151 /* define data source : this is argument i */
152 printf("Processing file %s\n", argv[i]);
153 status=monitorSetDataSource( argv[i] );
155 printf("monitorSetDataSource() failed. Error=%s. Exiting ...\n", monitorDecodeError(status));
161 struct eventHeaderStruct *event;
163 /* check shutdown condition */
164 if (daqDA_checkShutdown()) {break;}
166 /* get next event (blocking call until timeout) */
167 status=monitorGetEventDynamic((void **)&event);
168 if (status==MON_ERR_EOF) {
169 printf ("End of File %d (%s) detected\n", i, argv[i]);
170 break; /* end of monitoring file has been reached */
173 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
177 /* skip start/end of run events */
178 if ( (event->eventType != physicsEvent) && (event->eventType != calibrationEvent) )
181 /* retry if got no event */
187 // Pedestal calibration
188 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
189 calibPedestal.ProcessEvent(rawReader);
190 //calibPedestal.ProcessEventFast(rawReader); // fast data reader
199 // Analyse pedestals and write them to rootfile
202 calibPedestal.Analyse();
203 calibPedestal.AnalyseTime(nevents);
204 printf ("%d physics/calibration events processed.\n",nevents);
206 TFile *fileTPC = new TFile(RESULT_FILE, "recreate");
207 calibPedestal.Write("tpcCalibPedestal");
209 printf("Wrote %s.\n",RESULT_FILE);
211 /* store the result file on FES */
213 status=daqDA_FES_storeFile(RESULT_FILE,FILE_ID);
220 // Now prepare ASCII files for local ALTRO configuration through DDL.
227 sprintf(filename,"tpcPedestals.data");
228 pedfile.open(filename);
229 sprintf(filename,"tpcNoise.data");
230 noisefile.open(filename);
231 sprintf(filename,"tpcPedestalMem.data");
232 pedmemfile.open(filename);
234 TArrayF **timePed = calibPedestal.GetTimePedestals(); // pedestal values for each time bin
236 Int_t ctr_channel = 0;
238 Int_t ctr_pattern = 0;
240 pedfile << 10 << std::endl; // mark file to contain PEDESTALS per channel
241 noisefile << 11 << std::endl; // mark file to contain NOISE per altro
242 pedmemfile << 12 << std::endl; // mark file to contain PEDESTALs per time bin
244 for ( Int_t roc = 0; roc < 72; roc++ ) {
245 if ( !calibPedestal.GetCalRocPedestal(roc) ) continue;
246 Int_t side = mapping->GetSideFromRoc(roc);
247 Int_t sector = mapping->GetSectorFromRoc(roc);
248 //printf("Analysing ROC %d (side %d, sector %d) ...\n", roc, side, sector);
249 Int_t nru = mapping->IsIROC(roc) ? 2 : 4;
250 for ( int rcu = 0; rcu < nru; rcu++ ) {
251 Int_t patch = mapping->IsIROC(roc) ? rcu : rcu+2;
252 for ( int branch = 0; branch < 2; branch++ ) {
253 for ( int fec = 0; fec < mapping->GetNfec(patch, branch); fec++ ) {
254 for ( int altro = 0; altro < 8; altro++ ) {
257 for ( int channel = 0; channel < 16; channel++ ) {
258 Int_t hwadd = mapping->CodeHWAddress(branch, fec, altro, channel);
259 Int_t row = mapping->GetPadRow(patch, hwadd); // row in a ROC
260 Int_t globalrow = mapping->GetGlobalPadRow(patch, hwadd); // row in full sector
261 Int_t pad = mapping->GetPad(patch, hwadd);
262 Float_t ped = calibPedestal.GetCalRocPedestal(roc)->GetValue(row,pad);
264 if ( ped > 1.e-10 ) {
265 pedfile << ctr_channel << "\t" << side << "\t" << sector << "\t" << patch << "\t"
266 << hwadd << "\t" << ped << std::endl;
270 if ( timePed && fabs(timePed[globalrow][pad].GetSum()) > 1e-10 ) {
271 pedmemfile << ctr_pattern << "\t" << side << "\t" << sector << "\t" << patch
273 for ( Int_t timebin = 0; timebin < 1024; timebin++ )
274 pedmemfile << "\t" << timePed[globalrow][pad].At(timebin);
275 pedmemfile << std::endl;
279 Float_t rms2 = calibPedestal.GetCalRocRMS(roc)->GetValue(row,pad);
280 if ( rms2 > 1.e-10 ) { rms += rms2; ctr += 1.; }
281 } // end channel for loop
282 // noise data (rms) averaged over all channels in this ALTRO.
283 Int_t hwadd = mapping->CodeHWAddress(branch, fec, altro, 0);
284 if ( ctr > 1.e-10 ) {
285 noisefile << ctr_altro << "\t" << side << "\t" << sector << "\t" << patch << "\t"
286 << hwadd << "\t" << rms/ctr << std::endl;
289 } // end altro for loop
290 } // end fec for loop
291 } // end branch for loop
292 } // end rcu for loop
298 printf("Wrote ASCII files.\n");