]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TPC/TPCPEDESTALda.cxx
Adding AliTPCcalibTracksCuts (Marian)
[u/mrichter/AliRoot.git] / TPC / TPCPEDESTALda.cxx
CommitLineData
c12208b8 1/*
2
3TPCda_pedestal.cxx - calibration algorithm for TPC pedestal runs
4
510/06/2007 sylvain.chapeland@cern.ch : first version - clean skeleton based on DAQ DA case1
6
7contact: marian.ivanov@cern.ch
8
9
10This process reads RAW data from the files provided as command line arguments
11and save results in a file (named from RESULT_FILE define - see below).
12
13*/
14
15#define RESULT_FILE "tpcPedestal.root"
16
17
18extern "C" {
19#include <daqDA.h>
20}
21#include "event.h"
22#include "monitor.h"
23#include <stdio.h>
24#include <stdlib.h>
87d57858 25#include <fstream.h>
c12208b8 26
27//
28//Root includes
29//
30#include <TFile.h>
bdf99a93 31#include <TArrayF.h>
8b1405a7 32#include "TROOT.h"
33#include "TPluginManager.h"
c12208b8 34
35//
36//AliRoot includes
37//
38#include "AliRawReader.h"
39#include "AliRawReaderDate.h"
87d57858 40#include "AliTPCmapper.h"
c12208b8 41#include "AliTPCRawStream.h"
42#include "AliTPCROC.h"
43#include "AliTPCCalROC.h"
44#include "AliTPCCalPad.h"
45#include "AliMathBase.h"
46#include "TTreeStream.h"
47
48//
49// TPC calibration algorithm includes
50//
51#include "AliTPCCalibPedestal.h"
52
bdf99a93 53/*
54 Main routine, TPC pedestal detector algorithm to be run on TPC LDC
55 Arguments: list of DATE raw data files
c12208b8 56*/
bdf99a93 57
c12208b8 58int main(int argc, char **argv) {
bdf99a93 59 //
60 // Main for TPC pedestal detector algorithm
61 //
8b1405a7 62
63 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
64 "*",
65 "TStreamerInfo",
66 "RIO",
67 "TStreamerInfo()");
bdf99a93 68 Bool_t timeAnalysis = kTRUE;
c12208b8 69
70 int i,status;
bdf99a93 71 AliTPCCalibPedestal calibPedestal; // pedestal and noise calibration
72 calibPedestal.SetTimeAnalysis(timeAnalysis); // pedestal(t) calibration
c12208b8 73
74 if (argc<2) {
75 printf("Wrong number of arguments\n");
76 return -1;
77 }
78
c12208b8 79 /* log start of process */
80 printf("TPC DA started - %s\n",__FILE__);
81
c12208b8 82 /* declare monitoring program */
83 status=monitorDeclareMp( __FILE__ );
84 if (status!=0) {
85 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
86 return -1;
87 }
88
c12208b8 89 /* loop over RAW data files */
90 int nevents=0;
bdf99a93 91 for ( i=1; i<argc; i++ ) {
c12208b8 92
93 /* define data source : this is argument i */
94 printf("Processing file %s\n", argv[i]);
95 status=monitorSetDataSource( argv[i] );
96 if (status!=0) {
97 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
98 return -1;
99 }
100
101 /* read until EOF */
bdf99a93 102 for ( ; ; ) {
c12208b8 103 struct eventHeaderStruct *event;
104
105 /* check shutdown condition */
106 if (daqDA_checkShutdown()) {break;}
107
108 /* get next event (blocking call until timeout) */
109 status=monitorGetEventDynamic((void **)&event);
110 if (status==MON_ERR_EOF) {
bdf99a93 111 printf ("End of File %d (%s) detected\n", i, argv[i]);
112 break; /* end of monitoring file has been reached */
c12208b8 113 }
c12208b8 114 if (status!=0) {
bdf99a93 115 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
116 break;
c12208b8 117 }
118
bdf99a93 119 /* skip start/end of run events */
120 if ( (event->eventType != physicsEvent) && (event->eventType != calibrationEvent) )
121 continue;
122
c12208b8 123 /* retry if got no event */
124 if (event==NULL) {
bdf99a93 125 continue;
c12208b8 126 }
bdf99a93 127
c12208b8 128 nevents++;
129
130 // Pedestal calibration
131 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
132 calibPedestal.ProcessEvent(rawReader);
133 delete rawReader;
134
135 /* free resources */
136 free(event);
137 }
138 }
139
140 calibPedestal.Analyse();
bdf99a93 141 calibPedestal.AnalyseTime(nevents);
142 printf ("%d physics/calibration events processed\n",nevents);
c12208b8 143
bdf99a93 144 TFile *fileTPC = new TFile(RESULT_FILE, "recreate");
c12208b8 145 calibPedestal.Write("calibPedestal");
146 delete fileTPC;
147 printf("Wrote %s\n",RESULT_FILE);
148
bdf99a93 149 //
150 // Now prepare ASCII files for local ALTRO configuration through DDL
151 //
87d57858 152
bdf99a93 153 ofstream pedfile;
154 ofstream noisefile;
155 ofstream pedmemfile;
87d57858 156 char filename[255];
bdf99a93 157 sprintf(filename,"tpcPedestals.data");
158 pedfile.open(filename);
159 sprintf(filename,"tpcNoise.data");
160 noisefile.open(filename);
161 sprintf(filename,"tpcPedestalMem.data");
162 pedmemfile.open(filename);
163
164 TArrayF **timePed = calibPedestal.GetTimePedestals();
165 AliTPCmapper mapping;
87d57858 166
bdf99a93 167 Int_t ctr_channel = 0;
168 Int_t ctr_altro = 0;
169 Int_t ctr_pattern = 0;
87d57858 170
bdf99a93 171 pedfile << 10 << std::endl; // PEDESTALS per channel
172 noisefile << 11 << std::endl; // NOISE per altro
173 pedmemfile << 12 << std::endl; // PEDESTALs per time bin
87d57858 174
bdf99a93 175 for ( Int_t roc = 0; roc < 72; roc++ ) {
176 if ( !calibPedestal.GetCalRocPedestal(roc) ) continue;
177 Int_t side = mapping.GetSideFromRoc(roc);
178 Int_t sector = mapping.GetSectorFromRoc(roc);
179 //printf("Analysing ROC %d (side %d, sector %d) ...\n", roc, side, sector);
180 Int_t nru = mapping.IsIROC(roc) ? 2 : 4;
181 for ( int rcu = 0; rcu < nru; rcu++ ) {
182 Int_t patch = mapping.IsIROC(roc) ? rcu : rcu+2;
183 for ( int branch = 0; branch < 2; branch++ ) {
184 for ( int fec = 0; fec < mapping.GetNfec(patch, branch); fec++ ) {
185 for ( int altro = 0; altro < 8; altro++ ) {
186 Float_t rms = 0.;
187 Float_t ctr = 0.;
188 for ( int channel = 0; channel < 16; channel++ ) {
189 Int_t hwadd = mapping.CodeHWAddress(branch, fec, altro, channel);
190 Int_t row = mapping.GetPadRow(patch, hwadd);
191 Int_t pad = mapping.GetPad(patch, hwadd);
192 Float_t ped = calibPedestal.GetCalRocPedestal(roc)->GetValue(row,pad);
193 // fixed pedestal
194 if ( ped > 1.e-10 ) {
195 pedfile << ctr_channel << "\t" << side << "\t" << sector << "\t" << patch << "\t" << hwadd << "\t" << ped << std::endl;
196 ctr_channel++;
197 }
198 // pedestal(t)
199 if ( timePed && fabs(timePed[row][pad].GetSum()) > 1e-10 ) {
200 pedmemfile << ctr_pattern << "\t" << side << "\t" << sector << "\t" << patch << "\t" << hwadd;
201 for ( Int_t timebin = 0; timebin < 1024; timebin++ )
202 pedmemfile << "\t" << timePed[row][pad].At(timebin);
203 pedmemfile << std::endl;
204 ctr_pattern++;
205 }
206 // rms=noise
207 Float_t rms2 = calibPedestal.GetCalRocRMS(roc)->GetValue(row,pad);
208 if ( rms2 > 1.e-10 ) { rms += rms2; ctr += 1.; }
209 } // end channel for loop
210 // noise data (rms) averaged over all channels in this ALTRO.
211 Int_t hwadd = mapping.CodeHWAddress(branch, fec, altro, 0);
212 if ( ctr > 1.e-10 ) {
213 noisefile << ctr_altro << "\t" << side << "\t" << sector << "\t" << patch << "\t" << hwadd << "\t" << rms/ctr << std::endl;
214 ctr_altro++;
215 }
216 } // end altro for loop
217 } // end fec for loop
218 } // end branch for loop
219 } // end rcu for loop
220 } // end roc loop
221
222 pedfile.close();
223 noisefile.close();
224 pedmemfile.close();
225
226 printf("Wrote ASCII files\n");
87d57858 227
c12208b8 228 return status;
229}