3 TOF DA for online calibration from pulser data
5 Contact: Chiara.Zampolli@bo.infn.it
6 Link: www.bo.infn.it/~zampolli
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>
42 #include "TPluginManager.h"
45 Arguments: list of DATE raw data files
47 int main(int argc, char **argv) {
49 /* magic line from Rene */
50 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
56 AliTOFGeometry * geom = new AliTOFGeometry();
58 static const Int_t size = AliTOFGeometry::NPadXSector()*AliTOFGeometry::NSectors();
59 TH1F::AddDirectory(0);
60 TH1F * htofNoise = new TH1F("hTOFnoise","histo with signals on TOF during noise", size,-0.5,size-0.5);
61 for (Int_t ibin =1;ibin<=size;ibin++){
62 htofNoise->SetBinContent(ibin,-1);
68 /* log start of process */
69 printf("TOF DA started\n");
71 /* check that we got some arguments = list of files */
73 printf("Wrong number of arguments\n");
77 /* open result file */
79 fp=fopen("./result.txt","a");
81 printf("Failed to open file\n");
85 /* init some counters */
86 int nevents_physics=0;
89 /* read the data files */
91 for (n=1;n<argc;n++) {
93 status=monitorSetDataSource( argv[n] );
95 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
101 struct eventHeaderStruct *event;
102 eventTypeType eventT;
105 status=monitorGetEventDynamic((void **)&event);
106 if (status==MON_ERR_EOF) break; /* end of monitoring file has been reached */
108 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
112 /* retry if got no event */
117 /* use event - here, just write event id to result file */
118 eventT=event->eventType;
120 if (eventT==PHYSICS_EVENT) {
121 //printf ("event %i \n", nevents_physics);
122 Int_t nPDBEntriesToT = 0;
123 Int_t nDBEntriesToT = 0;
124 AliTOFHitData *HitData;
127 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
128 AliTOFRawStream *rawStreamTOF = new AliTOFRawStream(rawReader);
129 AliTOFDecoder * decoderTOF = new AliTOFDecoder();
130 AliTOFHitDataBuffer *DataBuffer[72];
131 AliTOFHitDataBuffer *PackedDataBuffer[72];
132 for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){
133 DataBuffer[i]=new AliTOFHitDataBuffer();
134 PackedDataBuffer[i]=new AliTOFHitDataBuffer();
136 Int_t currentEquipment;
139 while(rawReader->ReadHeader()){
140 //printf ("ldcId = %i \n",ldcId);
141 ldcId = rawReader->GetLDCId();
143 //memory leak prevention (actually data should be always 0x0 here)
144 if (data != 0x0) delete [] data;
146 //get equipment infos
147 currentEquipment = rawReader->GetEquipmentId();
148 currentDDL = rawReader->GetDDLID();
150 if (currentDDL%2==0) {
156 Int_t * array = new Int_t[nchDDL];
157 decoderTOF->GetArrayDDL(array, currentDDL);
159 for (Int_t i=0;i<nchDDL;i++){
160 if (htofNoise->GetBinContent(array[i]+1)<0) htofNoise->SetBinContent(array[i]+1,0);
163 //printf(" Equipment = %i, and DDL = %i \n", currentEquipment,currentDDL);
164 const Int_t kDataSize = rawReader->GetDataSize();
165 const Int_t kDataWords = kDataSize / 4;
166 data = new UChar_t[kDataSize];
167 decoderTOF->SetDataBuffer(DataBuffer[currentDDL]);
168 decoderTOF->SetPackedDataBuffer(PackedDataBuffer[currentDDL]);
170 if (!rawReader->ReadNext(data, kDataSize)){
171 rawReader->AddMajorErrorLog(AliTOFRawStream::kDDLdataReading);
172 printf("Error while reading DDL data. Go to next equipment \n");
177 if (decoderTOF->Decode((UInt_t *)data, kDataWords) == kTRUE) {
178 rawReader->AddMajorErrorLog(AliTOFRawStream::kDDLDecoder,Form("DDL # = %d",currentDDL));
179 printf("Error while decoding DDL # %d: decoder returned with errors \n", currentDDL);
182 Int_t nDBEntries = DataBuffer[currentDDL]->GetEntries();
183 Int_t nPDBEntries = PackedDataBuffer[currentDDL]->GetEntries();
184 nPDBEntriesToT+=nPDBEntries;
185 nDBEntriesToT+=nDBEntries;
187 DataBuffer[currentDDL]->Reset();
189 /* read data buffer hits */
190 for (Int_t iHit = 0; iHit < nPDBEntries; iHit++){
191 HitData = PackedDataBuffer[currentDDL]->GetHit(iHit);
192 /* add volume information */
193 HitData->SetDDLID(currentDDL);
194 rawStreamTOF->EquipmentId2VolumeId(HitData, Volume);
199 Volume[4]==-1) continue;
202 Volume[3] = Volume[4];
204 Int_t index = geom->GetIndex(Volume);
205 Bool_t found =kFALSE;
206 // to check array indexes
208 for (Int_t j=0;j<nchDDL;j++){
209 if (index==array[j]) {
214 printf ("index = %i, found = %i\n",index, (Int_t)found);
216 //printf ("index = %i \n",index);
217 htofNoise->Fill(index); //channel index start from 0, bin index from 1
218 //debugging printings
219 //printf("sector %i, plate %i, strip %i, padz %i, padx %i \n",Volume[0],Volume[1],Volume[2],Volume[3],Volume[4]);
223 PackedDataBuffer[currentDDL]->Reset();
229 //printf(" Packed Hit Buffer Entries = %i \n",nPDBEntriesToT);
230 //printf(" Hit Buffer Entries = %i \n",nDBEntriesToT);
235 for (Int_t i=0;i<72;i++){
236 delete DataBuffer[i];
237 delete PackedDataBuffer[i];
257 Float_t time = nevents_physics*200*1E-9; // acquisition time in s
258 //printf(" Noise run lasted %f s \n",time);
259 for (Int_t ibin =1;ibin<=size;ibin++){
260 Float_t cont = htofNoise->GetBinContent(ibin);
262 //printf(" content = %f \n", cont);
263 htofNoise->SetBinContent(ibin,cont/time);
264 //printf(" scaled content = %f \n", cont/time);
268 //write the Run level file
270 sprintf(filename,"TOFoutNoiseLDC_%02i.root",ldcId);
271 TFile * fileRun = new TFile (filename,"RECREATE");
276 fprintf(fp,"Run #%s, received %d physics events out of %d\n",getenv("DATE_RUN_NUMBER"),nevents_physics,nevents_total);
278 /* close result file */
283 /* store the result file on FES */
284 status=daqDA_FES_storeFile(filename,"NOISE");