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
17 TPCda_pedestal.cxx - calibration algorithm for TPC pedestal runs
19 10/06/2007 sylvain.chapeland@cern.ch : first version - clean skeleton based on DAQ DA case1
20 19/10/2007 christian.lippmann@cern.ch : Possibility to write output to ASCII file
21 24/10/2007 christian.lippmann@cern.ch : Including pedestal calibration for time bins
22 23/11/2007 christian.lippmann@cern.ch : Fix in order to avoid streamer problems in case of
23 invalid ROOTSTYS. The famous magic line provided by Rene.
24 28/11/2007 christian.lippmann@cern.ch : TPC mapping file is read from DaqDetDB
26 contact: marian.ivanov@cern.ch
28 This process reads RAW data from the files provided as command line arguments
29 and save results in a file (named from RESULT_FILE define - see below).
33 #define RESULT_FILE "tpcPedestal.root"
34 #define MAPPING_FILE "tpcMapping.root"
35 #define AliDebugLevel() -1
53 #include "TPluginManager.h"
58 #include "AliRawReader.h"
59 #include "AliRawReaderDate.h"
60 #include "AliTPCmapper.h"
61 #include "AliTPCRawStream.h"
62 #include "AliTPCROC.h"
63 #include "AliTPCCalROC.h"
64 #include "AliTPCCalPad.h"
65 #include "AliMathBase.h"
66 #include "TTreeStream.h"
71 // TPC calibration algorithm includes
73 #include "AliTPCCalibPedestal.h"
76 Main routine, TPC pedestal detector algorithm to be run on TPC LDC
77 Arguments: list of DATE raw data files
80 int main(int argc, char **argv) {
82 // Main for TPC pedestal detector algorithm
85 AliLog::SetClassDebugLevel("AliTPCRawStream",AliLog::kFatal);
86 AliLog::SetClassDebugLevel("AliRawReaderDate",AliLog::kFatal);
87 AliLog::SetClassDebugLevel("AliTPCAltroMapping",AliLog::kFatal);
88 AliLog::SetModuleDebugLevel("TPC",AliLog::kFatal);
89 AliLog::SetModuleDebugLevel("RAW",AliLog::kFatal);
91 Bool_t timeAnalysis = kTRUE;
94 printf("Wrong number of arguments\n");
99 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
106 /* log start of process */
107 printf("TPC DA started - %s\n",__FILE__);
109 /* declare monitoring program */
110 status=monitorDeclareMp( __FILE__ );
112 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
116 AliTPCmapper *mapping = 0; // The TPC mapping
119 /* copy locally the mapping file from daq detector config db */
120 status = daqDA_DB_getFile(MAPPING_FILE,"./tpcMapping.root");
122 printf("Failed to get mapping file (%s) from DAQdetDB, status=%d\n", MAPPING_FILE, status);
123 printf("Continue anyway ... maybe it works?\n"); // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
124 return -1; // temporarily uncommented for testing on pcald47 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
127 /* open the mapping file and retrieve mapping object */
128 TFile *fileMapping = new TFile(MAPPING_FILE, "read");
129 mapping = (AliTPCmapper*) fileMapping->Get("tpcMapping");
134 printf("Failed to get mapping object from %s. ...\n", MAPPING_FILE);
137 printf("Got mapping object from %s\n", MAPPING_FILE);
140 AliTPCCalibPedestal calibPedestal; // pedestal and noise calibration
141 calibPedestal.SetRangeTime(60,940); // set time bin range
142 calibPedestal.SetTimeAnalysis(timeAnalysis); // pedestal(t) calibration
144 calibPedestal.SetAltroMapping(mapping->GetAltroMapping()); // Use altro mapping we got from daqDetDb
146 /* loop over RAW data files */
148 for ( i=1; i<argc; i++ ) {
150 /* define data source : this is argument i */
151 printf("Processing file %s\n", argv[i]);
152 status=monitorSetDataSource( argv[i] );
154 printf("monitorSetDataSource() failed. Error=%s. Exiting ...\n", monitorDecodeError(status));
160 struct eventHeaderStruct *event;
162 /* check shutdown condition */
163 if (daqDA_checkShutdown()) {break;}
165 /* get next event (blocking call until timeout) */
166 status=monitorGetEventDynamic((void **)&event);
167 if (status==MON_ERR_EOF) {
168 printf ("End of File %d (%s) detected\n", i, argv[i]);
169 break; /* end of monitoring file has been reached */
172 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
176 /* skip start/end of run events */
177 if ( (event->eventType != physicsEvent) && (event->eventType != calibrationEvent) )
180 /* retry if got no event */
186 // Pedestal calibration
187 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
188 calibPedestal.ProcessEvent(rawReader);
189 //calibPedestal.ProcessEventFast(rawReader); // fast data reader
198 // Analyse pedestals and write them to rootfile
201 calibPedestal.Analyse();
202 calibPedestal.AnalyseTime(nevents);
203 printf ("%d physics/calibration events processed.\n",nevents);
205 TFile *fileTPC = new TFile(RESULT_FILE, "recreate");
206 calibPedestal.Write("calibPedestal");
208 printf("Wrote %s.\n",RESULT_FILE);
210 /* store the result file on FES */
212 status=daqDA_FES_storeFile(RESULT_FILE,RESULT_FILE);
219 // Now prepare ASCII files for local ALTRO configuration through DDL.
226 sprintf(filename,"tpcPedestals.data");
227 pedfile.open(filename);
228 sprintf(filename,"tpcNoise.data");
229 noisefile.open(filename);
230 sprintf(filename,"tpcPedestalMem.data");
231 pedmemfile.open(filename);
233 TArrayF **timePed = calibPedestal.GetTimePedestals(); // pedestal values for each time bin
235 Int_t ctr_channel = 0;
237 Int_t ctr_pattern = 0;
239 pedfile << 10 << std::endl; // mark file to contain PEDESTALS per channel
240 noisefile << 11 << std::endl; // mark file to contain NOISE per altro
241 pedmemfile << 12 << std::endl; // mark file to contain PEDESTALs per time bin
243 for ( Int_t roc = 0; roc < 72; roc++ ) {
244 if ( !calibPedestal.GetCalRocPedestal(roc) ) continue;
245 Int_t side = mapping->GetSideFromRoc(roc);
246 Int_t sector = mapping->GetSectorFromRoc(roc);
247 //printf("Analysing ROC %d (side %d, sector %d) ...\n", roc, side, sector);
248 Int_t nru = mapping->IsIROC(roc) ? 2 : 4;
249 for ( int rcu = 0; rcu < nru; rcu++ ) {
250 Int_t patch = mapping->IsIROC(roc) ? rcu : rcu+2;
251 for ( int branch = 0; branch < 2; branch++ ) {
252 for ( int fec = 0; fec < mapping->GetNfec(patch, branch); fec++ ) {
253 for ( int altro = 0; altro < 8; altro++ ) {
256 for ( int channel = 0; channel < 16; channel++ ) {
257 Int_t hwadd = mapping->CodeHWAddress(branch, fec, altro, channel);
258 Int_t row = mapping->GetPadRow(patch, hwadd); // row in a ROC
259 Int_t globalrow = mapping->GetGlobalPadRow(patch, hwadd); // row in full sector
260 Int_t pad = mapping->GetPad(patch, hwadd);
261 Float_t ped = calibPedestal.GetCalRocPedestal(roc)->GetValue(row,pad);
263 if ( ped > 1.e-10 ) {
264 pedfile << ctr_channel << "\t" << side << "\t" << sector << "\t" << patch << "\t"
265 << hwadd << "\t" << ped << std::endl;
269 if ( timePed && fabs(timePed[globalrow][pad].GetSum()) > 1e-10 ) {
270 pedmemfile << ctr_pattern << "\t" << side << "\t" << sector << "\t" << patch
272 for ( Int_t timebin = 0; timebin < 1024; timebin++ )
273 pedmemfile << "\t" << timePed[globalrow][pad].At(timebin);
274 pedmemfile << std::endl;
278 Float_t rms2 = calibPedestal.GetCalRocRMS(roc)->GetValue(row,pad);
279 if ( rms2 > 1.e-10 ) { rms += rms2; ctr += 1.; }
280 } // end channel for loop
281 // noise data (rms) averaged over all channels in this ALTRO.
282 Int_t hwadd = mapping->CodeHWAddress(branch, fec, altro, 0);
283 if ( ctr > 1.e-10 ) {
284 noisefile << ctr_altro << "\t" << side << "\t" << sector << "\t" << patch << "\t"
285 << hwadd << "\t" << rms/ctr << std::endl;
288 } // end altro for loop
289 } // end fec for loop
290 } // end branch for loop
291 } // end rcu for loop
297 printf("Wrote ASCII files.\n");