3 TOF DA for online calibration
5 Contact: Chiara.Zampolli@bo.infn.it
6 Link: www.bo.infn.it/~zampolli
9 Number of events needed: depending on the run, being run-level
10 Input Files: TOFdaTotal.root, to be updated if existing
11 Output Files: TOFdaRun.root, TOFdaTotal.root, both to be exported to the DAQ FXS
12 Trigger types used: PHYSICS_EVENT
16 #define FILE_TOTAL "TOFdaTotal.root"
17 #define FILE_RUN "TOFdaRun.root"
25 #include <AliTOFRawStream.h>
26 #include <AliRawReaderDate.h>
27 #include <AliRawReader.h>
28 #include <AliTOFGeometry.h>
29 #include <AliT0RawReader.h>
31 #include <AliTOFHitData.h>
32 #include <AliTOFHitDataBuffer.h>
45 1- monitoring data source
48 int main(int argc, char **argv) {
50 AliTOFGeometry * geom = new AliTOFGeometry();
52 static const Int_t size = AliTOFGeometry::NPadXSector()*AliTOFGeometry::NSectors();
53 static const Int_t nbins = 500;
54 static const Int_t binmin = -20;
55 const Float_t c = 2.99792458E10; //speed of light
56 TH1F::AddDirectory(0);
57 TH2S * htofPartial = new TH2S("htof","histo with delays", size,-0.5,size*1.-0.5,nbins,binmin-0.5,nbins*1.+binmin-0.5);
59 // decoding the events
63 printf("Wrong number of arguments\n");
67 /* define data source : this is argument 1 */
68 status=monitorSetDataSource( argv[1] );
70 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
74 /* declare monitoring program */
75 status=monitorDeclareMp( __FILE__ );
77 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
81 /* define wait event timeout - 1s max */
83 monitorSetNoWaitNetworkTimeout(1000);
85 /* log start of process */
86 printf("TOF DA started\n");
88 /* init some counters */
89 int nevents_physics=0;
92 struct eventHeaderStruct *event;
96 /* main loop (infinite) */
99 /* check shutdown condition */
100 if (daqDA_checkShutdown()) {break;}
102 /* get next event (blocking call until timeout) */
103 status=monitorGetEventDynamic((void **)&event);
104 if (status==MON_ERR_EOF) {
105 printf ("End of File detected\n");
106 break; /* end of monitoring file has been reached */
110 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
114 /* retry if got no event */
121 /* use event - here, just write event id to result file */
123 eventT=event->eventType;
124 switch (event->eventType){
129 /* END START OF RUN */
137 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
138 //rawReader->RequireHeader(kFALSE);
142 AliT0RawReader *rawReaderT0 = new AliT0RawReader(rawReader,kTRUE);
143 if (!rawReaderT0->Next()) {
144 printf("T0: no raw data found!\n");
148 Int_t allData[105][5];
149 for (Int_t i=0; i<105; i++) {
150 allData[i][0]=rawReaderT0->GetData(i,0);
152 meantime = allData[49][0];
154 meantime = rawReaderT0->GetData(49,0);
155 // printf("time zero (ns) = %i (%f) \n", meantime, (meantime*24.4-200)*1E-3); // debugging purpose
165 AliTOFHitData *HitData;
166 AliTOFHitDataBuffer *DataBuffer;
167 AliTOFHitDataBuffer *PackedDataBuffer;
168 AliTOFRawStream *rawStreamTOF = new AliTOFRawStream(rawReader);
169 // rawReader->ReadHeader();
170 rawStreamTOF->ResetBuffers();
171 rawStreamTOF->DecodeDDL(0, AliDAQ::NumberOfDdls("TOF") - 1,0);
172 Int_t nPDBEntriesToT = 0;
173 Int_t nDBEntriesToT = 0;
174 for (Int_t iDDL = 0; iDDL < AliDAQ::NumberOfDdls("TOF"); iDDL++){
176 /* read decoded data */
177 DataBuffer = rawStreamTOF->GetDataBuffer(iDDL);
178 PackedDataBuffer = rawStreamTOF->GetPackedDataBuffer(iDDL);
180 /* get buffer entries */
181 Int_t nDBEntries = DataBuffer->GetEntries();
182 Int_t nPDBEntries = PackedDataBuffer->GetEntries();
183 nPDBEntriesToT+=nPDBEntries;
184 nDBEntriesToT+=nDBEntries;
186 //for (Int_t iHit = 0; iHit < nDBEntries; iHit++){
187 // HitData = DataBuffer->GetHit(iHit);
188 /* store volume information */
189 // rawStreamTOF->EquipmentId2VolumeId(HitData, Volume);
194 /* read data buffer hits */
195 for (Int_t iHit = 0; iHit < nPDBEntries; iHit++){
196 HitData = PackedDataBuffer->GetHit(iHit);
197 /* add volume information */
198 HitData->SetDDLID(iDDL);
199 rawStreamTOF->EquipmentId2VolumeId(HitData, Volume);
204 Volume[4]==-1) continue;
207 Volume[3] = Volume[4];
209 Int_t tof = (Int_t)((Double_t)HitData->GetTime()*1E3/AliTOFGeometry::TdcBinWidth());
210 Int_t index = geom->GetIndex(Volume);
212 geom->GetPosPar(Volume,pos);
213 Float_t texp=TMath::Sqrt(pos[0]*pos[0]+pos[1]*pos[1]+pos[2]*pos[2])/c*1E9; //expected time in ns
214 Float_t texpBin=(texp*1E3-32)/AliTOFGeometry::TdcBinWidth(); //expected time in number of TDC bin
215 Int_t deltabin = tof-TMath::Nint(texpBin); //to be used with real data; rounding expected time to Int_t
216 htofPartial->Fill(index,deltabin); //channel index start from 0, bin index from 1
217 //debugging printings
218 //printf("sector %i, plate %i, strip %i, padz %i, padx %i \n",Volume[0],Volume[1],Volume[2],Volume[3],Volume[4]);
219 //printf("pos x = %f, pos y = %f, pos z = %f \n",pos[0],pos[1],pos[2]);
220 //printf ("expected time = %f (ns)\n",texp);
221 //printf ("expected time bin = %f (TDC bin)\n",texpBin);
222 //printf ("measured time bin = %i (TDC bin) with %f (ns) and ACQ bit = %i \n",tof, HitData->GetTime(), HitData->GetACQ());
223 // printf("index = %i, deltabin = %i , filling index = %i, and bin = % i\n",index, deltabin, index, deltabin);
227 PackedDataBuffer->Reset();
230 //printf(" Packed Hit Buffer Entries = %i \n",nPDBEntriesToT);
231 //printf(" Hit Buffer Entries = %i \n",nDBEntriesToT);
243 /* exit when last event received, no need to wait for TERM signal */
244 if (eventT==END_OF_RUN) {
245 printf("EOR event detected\n");
253 //write the Run level file
254 TFile * fileRun = new TFile (FILE_RUN,"RECREATE");
255 htofPartial->Write();
258 //write the Total file
260 TFile * filetot = 0x0;
261 Bool_t isThere=kFALSE;
262 const char *dirname = "./";
263 TString filename = FILE_TOTAL;
264 if((gSystem->FindFile(dirname,filename))!=NULL){
266 printf("%s found \n",FILE_TOTAL);
270 TFile * filetot1 = new TFile (FILE_TOTAL,"READ");
272 if (!filetot1->IsZombie()){
273 printf("updating file %s \n",FILE_TOTAL);
274 TIter next(filetot1->GetListOfKeys());
276 //look for the histogram
277 while ((key=(TKey*)next())){
278 const char * namekey = key->GetName();
279 if (strcmp(namekey,"htoftot")==0){
280 printf(" histo found \n");
281 htoftot = (TH2S*) filetot1->Get("htoftot");
282 htoftot->AddDirectory(0);
283 htoftot->Add(htofPartial);
293 printf(" no %s file found \n",FILE_TOTAL);
294 htoftot = new TH2S(*htofPartial);
295 htoftot->SetName("htoftot");
296 htoftot->AddDirectory(0);
299 filetot = new TFile (FILE_TOTAL,"RECREATE");
315 printf("Run #%s, received %d physics events out of %d\n",getenv("DATE_RUN_NUMBER"),nevents_physics,nevents_total);
319 /* export file to FXS */
320 if (daqDA_FES_storeFile(FILE_RUN, FILE_RUN)) {
323 if (daqDA_FES_storeFile(FILE_TOTAL, FILE_TOTAL)) {