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 const AliRawDataHeader *currentCDH;
130 AliTOFDecoder * decoderTOF = new AliTOFDecoder();
131 AliTOFHitDataBuffer *DataBuffer[72];
132 AliTOFHitDataBuffer *PackedDataBuffer[72];
133 for (Int_t i=0;i<AliDAQ::NumberOfDdls("TOF");i++){
134 DataBuffer[i]=new AliTOFHitDataBuffer();
135 PackedDataBuffer[i]=new AliTOFHitDataBuffer();
137 Int_t currentEquipment;
140 while(rawReader->ReadHeader()){
141 //printf ("ldcId = %i \n",ldcId);
142 ldcId = rawReader->GetLDCId();
144 //memory leak prevention (actually data should be always 0x0 here)
145 if (data != 0x0) delete [] data;
147 //get equipment infos
148 currentEquipment = rawReader->GetEquipmentId();
149 currentDDL = rawReader->GetDDLID();
150 currentCDH = rawReader->GetDataHeader();
152 if (currentDDL%2==0) {
158 Int_t * array = new Int_t[nchDDL];
159 decoderTOF->GetArrayDDL(array, currentDDL);
161 for (Int_t i=0;i<nchDDL;i++){
162 if (htofNoise->GetBinContent(array[i]+1)<0) htofNoise->SetBinContent(array[i]+1,0);
165 //printf(" Equipment = %i, and DDL = %i \n", currentEquipment,currentDDL);
166 const Int_t kDataSize = rawReader->GetDataSize();
167 const Int_t kDataWords = kDataSize / 4;
168 data = new UChar_t[kDataSize];
169 decoderTOF->SetDataBuffer(DataBuffer[currentDDL]);
170 decoderTOF->SetPackedDataBuffer(PackedDataBuffer[currentDDL]);
172 if (!rawReader->ReadNext(data, kDataSize)){
173 rawReader->AddMajorErrorLog(AliTOFRawStream::kDDLdataReading);
174 printf("Error while reading DDL data. Go to next equipment \n");
179 if (decoderTOF->Decode((UInt_t *)data, kDataWords, currentCDH) == kTRUE ){
180 rawReader->AddMajorErrorLog(AliTOFRawStream::kDDLDecoder,Form("DDL # = %d",currentDDL));
181 printf("Error while decoding DDL # %d: decoder returned with errors \n", currentDDL);
184 Int_t nDBEntries = DataBuffer[currentDDL]->GetEntries();
185 Int_t nPDBEntries = PackedDataBuffer[currentDDL]->GetEntries();
186 nPDBEntriesToT+=nPDBEntries;
187 nDBEntriesToT+=nDBEntries;
189 DataBuffer[currentDDL]->Reset();
191 /* read data buffer hits */
192 for (Int_t iHit = 0; iHit < nPDBEntries; iHit++){
193 HitData = PackedDataBuffer[currentDDL]->GetHit(iHit);
194 /* add volume information */
195 HitData->SetDDLID(currentDDL);
196 rawStreamTOF->EquipmentId2VolumeId(HitData, Volume);
201 Volume[4]==-1) continue;
204 Volume[3] = Volume[4];
206 Int_t index = geom->GetIndex(Volume);
207 Bool_t found =kFALSE;
208 // to check array indexes
210 for (Int_t j=0;j<nchDDL;j++){
211 if (index==array[j]) {
216 printf ("index = %i, found = %i\n",index, (Int_t)found);
218 //printf ("index = %i \n",index);
219 htofNoise->Fill(index); //channel index start from 0, bin index from 1
220 //debugging printings
221 //printf("sector %i, plate %i, strip %i, padz %i, padx %i \n",Volume[0],Volume[1],Volume[2],Volume[3],Volume[4]);
225 PackedDataBuffer[currentDDL]->Reset();
231 //printf(" Packed Hit Buffer Entries = %i \n",nPDBEntriesToT);
232 //printf(" Hit Buffer Entries = %i \n",nDBEntriesToT);
237 for (Int_t i=0;i<72;i++){
238 delete DataBuffer[i];
239 delete PackedDataBuffer[i];
259 Float_t time = nevents_physics*200*1E-9; // acquisition time in s
260 //printf(" Noise run lasted %f s \n",time);
261 for (Int_t ibin =1;ibin<=size;ibin++){
262 Float_t cont = htofNoise->GetBinContent(ibin);
264 //printf(" content = %f \n", cont);
265 htofNoise->SetBinContent(ibin,cont/time);
266 //printf(" scaled content = %f \n", cont/time);
270 //write the Run level file
272 sprintf(filename,"TOFoutNoiseLDC_%02i.root",ldcId);
273 TFile * fileRun = new TFile (filename,"RECREATE");
278 fprintf(fp,"Run #%s, received %d physics events out of %d\n",getenv("DATE_RUN_NUMBER"),nevents_physics,nevents_total);
280 /* close result file */
285 /* store the result file on FES */
286 status=daqDA_FES_storeFile(filename,"NOISE");