3 TOF DA for online calibration from pulser data
5 Contact: Chiara.Zampolli@bo.infn.it
6 Link: www.bo.infn.it/~zampolli
7 Run Type: CALIBRATION, PULSER - to be properly defined
9 Number of events needed: 10000
10 Input Files: TOF<nrun>.raw, where <nrun> is the run number
11 Output Files: TOFoutPulserLDC_<LDCid>.root, where <LDCid> is the id of the LDC which is read (2 characters field, e.g. TOFoutPulserLDC_03.root),to be exported to the DAQ FXS
12 Trigger types used: PHYSICS_EVENT (for the time being)
25 #include <AliTOFRawStream.h>
26 #include <AliRawReaderDate.h>
27 #include <AliRawReader.h>
28 #include <AliTOFGeometry.h>
30 #include <AliTOFHitData.h>
31 #include <AliTOFHitDataBuffer.h>
32 #include <AliTOFDecoder.h>
43 Arguments: list of DATE raw data files
45 int main(int argc, char **argv) {
47 AliTOFGeometry * geom = new AliTOFGeometry();
49 static const Int_t size = AliTOFGeometry::NPadXSector()*AliTOFGeometry::NSectors();
50 TH1F::AddDirectory(0);
51 TH1F * htofNoise = new TH1F("hTOFnoise","histo with signals on TOF during noise", size,-0.5,size-0.5);
52 for (Int_t ibin =1;ibin<=size;ibin++){
53 htofNoise->SetBinContent(ibin,-1);
59 /* log start of process */
60 printf("TOF DA started\n");
62 /* check that we got some arguments = list of files */
64 printf("Wrong number of arguments\n");
68 /* open result file */
70 fp=fopen("./result.txt","a");
72 printf("Failed to open file\n");
76 /* init some counters */
77 int nevents_physics=0;
80 /* read the data files */
82 for (n=1;n<argc;n++) {
84 status=monitorSetDataSource( argv[n] );
86 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
92 struct eventHeaderStruct *event;
96 status=monitorGetEventDynamic((void **)&event);
97 if (status==MON_ERR_EOF) break; /* end of monitoring file has been reached */
99 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
103 /* retry if got no event */
108 /* use event - here, just write event id to result file */
109 eventT=event->eventType;
111 if (eventT==PHYSICS_EVENT) {
112 //printf ("event %i \n", nevents_physics);
113 Int_t nPDBEntriesToT = 0;
114 Int_t nDBEntriesToT = 0;
115 AliTOFHitData *HitData;
118 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
119 AliTOFRawStream *rawStreamTOF = new AliTOFRawStream(rawReader);
120 AliTOFDecoder * decoderTOF = new AliTOFDecoder();
121 AliTOFHitDataBuffer *DataBuffer[72];
122 AliTOFHitDataBuffer *PackedDataBuffer[72];
123 for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){
124 DataBuffer[i]=new AliTOFHitDataBuffer();
125 PackedDataBuffer[i]=new AliTOFHitDataBuffer();
127 Int_t currentEquipment;
130 while(rawReader->ReadHeader()){
131 //printf ("ldcId = %i \n",ldcId);
132 ldcId = rawReader->GetLDCId();
134 //memory leak prevention (actually data should be always 0x0 here)
135 if (data != 0x0) delete [] data;
137 //get equipment infos
138 currentEquipment = rawReader->GetEquipmentId();
139 currentDDL = rawReader->GetDDLID();
141 if (currentDDL%2==0) {
147 Int_t * array = new Int_t[nchDDL];
148 decoderTOF->GetArrayDDL(array, currentDDL);
150 for (Int_t i=0;i<nchDDL;i++){
151 if (htofNoise->GetBinContent(array[i]+1)<0) htofNoise->SetBinContent(array[i]+1,0);
154 //printf(" Equipment = %i, and DDL = %i \n", currentEquipment,currentDDL);
155 const Int_t kDataSize = rawReader->GetDataSize();
156 const Int_t kDataWords = kDataSize / 4;
157 data = new UChar_t[kDataSize];
158 decoderTOF->SetDataBuffer(DataBuffer[currentDDL]);
159 decoderTOF->SetPackedDataBuffer(PackedDataBuffer[currentDDL]);
161 if (!rawReader->ReadNext(data, kDataSize)){
162 rawReader->AddMajorErrorLog(AliTOFRawStream::kDDLdataReading);
163 printf("Error while reading DDL data. Go to next equipment \n");
168 if (decoderTOF->Decode((UInt_t *)data, kDataWords) == kTRUE) {
169 rawReader->AddMajorErrorLog(AliTOFRawStream::kDDLDecoder,Form("DDL # = %d",currentDDL));
170 printf("Error while decoding DDL # %d: decoder returned with errors \n", currentDDL);
173 Int_t nDBEntries = DataBuffer[currentDDL]->GetEntries();
174 Int_t nPDBEntries = PackedDataBuffer[currentDDL]->GetEntries();
175 nPDBEntriesToT+=nPDBEntries;
176 nDBEntriesToT+=nDBEntries;
178 DataBuffer[currentDDL]->Reset();
180 /* read data buffer hits */
181 for (Int_t iHit = 0; iHit < nPDBEntries; iHit++){
182 HitData = PackedDataBuffer[currentDDL]->GetHit(iHit);
183 /* add volume information */
184 HitData->SetDDLID(currentDDL);
185 rawStreamTOF->EquipmentId2VolumeId(HitData, Volume);
190 Volume[4]==-1) continue;
193 Volume[3] = Volume[4];
195 Int_t index = geom->GetIndex(Volume);
196 Bool_t found =kFALSE;
197 // to check array indexes
199 for (Int_t j=0;j<nchDDL;j++){
200 if (index==array[j]) {
205 printf ("index = %i, found = %i\n",index, (Int_t)found);
207 //printf ("index = %i \n",index);
208 htofNoise->Fill(index); //channel index start from 0, bin index from 1
209 //debugging printings
210 //printf("sector %i, plate %i, strip %i, padz %i, padx %i \n",Volume[0],Volume[1],Volume[2],Volume[3],Volume[4]);
214 PackedDataBuffer[currentDDL]->Reset();
220 //printf(" Packed Hit Buffer Entries = %i \n",nPDBEntriesToT);
221 //printf(" Hit Buffer Entries = %i \n",nDBEntriesToT);
226 for (Int_t i=0;i<72;i++){
227 delete DataBuffer[i];
228 delete PackedDataBuffer[i];
248 Float_t time = nevents_physics*200*1E-9; // acquisition time in s
249 //printf(" Noise run lasted %f s \n",time);
250 for (Int_t ibin =1;ibin<=size;ibin++){
251 Float_t cont = htofNoise->GetBinContent(ibin);
253 //printf(" content = %f \n", cont);
254 htofNoise->SetBinContent(ibin,cont/time);
255 //printf(" scaled content = %f \n", cont/time);
259 //write the Run level file
261 sprintf(filename,"TOFoutNoiseLDC_%02i.root",ldcId);
262 TFile * fileRun = new TFile (filename,"RECREATE");
267 fprintf(fp,"Run #%s, received %d physics events out of %d\n",getenv("DATE_RUN_NUMBER"),nevents_physics,nevents_total);
269 /* close result file */
274 /* store the result file on FES */
275 status=daqDA_FES_storeFile(filename,filename);