3 TOF DA for online calibration
7 #define FILE_TOTAL "TOFdaTotal.root"
8 #define FILE_RUN "TOFdaRun.root"
16 #include <AliTOFRawStream.h>
17 #include <AliRawReaderDate.h>
18 #include <AliRawReader.h>
19 #include <AliTOFGeometry.h>
20 #include <AliTOFGeometryV5.h>
21 #include <AliT0RawReader.h>
23 #include <AliTOFHitData.h>
24 #include <AliTOFHitDataBuffer.h>
37 1- monitoring data source
40 int main(int argc, char **argv) {
42 AliTOFGeometry * geomV5 = new AliTOFGeometryV5();
43 AliTOFGeometry * geom = new AliTOFGeometry();
45 static const Int_t size = geomV5->NPadXSector()*geomV5->NSectors();
46 static const Int_t nbins = 500;
47 static const Int_t binmin = -20;
48 const Float_t c = 2.99792458E10; //speed of light
49 TH1F::AddDirectory(0);
50 TH2S * htofPartial = new TH2S("htof","histo with delays", size,-0.5,size*1.-0.5,nbins,binmin-0.5,nbins*1.+binmin-0.5);
52 // decoding the events
56 printf("Wrong number of arguments\n");
60 /* define data source : this is argument 1 */
61 status=monitorSetDataSource( argv[1] );
63 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
67 /* declare monitoring program */
68 status=monitorDeclareMp( __FILE__ );
70 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
74 /* define wait event timeout - 1s max */
76 monitorSetNoWaitNetworkTimeout(1000);
78 /* log start of process */
79 printf("TOF DA started\n");
81 /* init some counters */
82 int nevents_physics=0;
85 struct eventHeaderStruct *event;
89 /* main loop (infinite) */
92 /* check shutdown condition */
93 if (daqDA_checkShutdown()) {break;}
95 /* get next event (blocking call until timeout) */
96 status=monitorGetEventDynamic((void **)&event);
97 if (status==MON_ERR_EOF) {
98 printf ("End of File detected\n");
99 break; /* end of monitoring file has been reached */
103 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
107 /* retry if got no event */
114 /* use event - here, just write event id to result file */
116 eventT=event->eventType;
117 switch (event->eventType){
122 /* END START OF RUN */
130 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
131 //rawReader->RequireHeader(kFALSE);
135 AliT0RawReader *rawReaderT0 = new AliT0RawReader(rawReader,kTRUE);
136 if (!rawReaderT0->Next()) {
137 printf("T0: no raw data found!\n");
139 Int_t allData[110][5];
140 for (Int_t i=0; i<110; i++) {
141 allData[i][0]=rawReaderT0->GetData(i,0);
143 meantime = allData[49][0];
144 //printf("time zero (ns) = %i (%f) \n", meantime, meantime*25*1E-3-200);
154 AliTOFHitData *HitData;
155 AliTOFHitDataBuffer *DataBuffer;
156 AliTOFHitDataBuffer *PackedDataBuffer;
157 AliTOFRawStream *rawStreamTOF = new AliTOFRawStream(rawReader);
158 // rawReader->ReadHeader();
159 rawStreamTOF->ResetBuffers();
160 rawStreamTOF->DecodeDDL(0, AliDAQ::NumberOfDdls("TOF") - 1,0);
161 Int_t nPDBEntriesToT = 0;
162 Int_t nDBEntriesToT = 0;
163 for (Int_t iDDL = 0; iDDL < AliDAQ::NumberOfDdls("TOF"); iDDL++){
165 /* read decoded data */
166 DataBuffer = rawStreamTOF->GetDataBuffer(iDDL);
167 PackedDataBuffer = rawStreamTOF->GetPackedDataBuffer(iDDL);
169 /* get buffer entries */
170 Int_t nDBEntries = DataBuffer->GetEntries();
171 Int_t nPDBEntries = PackedDataBuffer->GetEntries();
172 nPDBEntriesToT+=nPDBEntries;
173 nDBEntriesToT+=nDBEntries;
175 //for (Int_t iHit = 0; iHit < nDBEntries; iHit++){
176 // HitData = DataBuffer->GetHit(iHit);
177 /* store volume information */
178 // rawStreamTOF->EquipmentId2VolumeId(HitData, Volume);
183 /* read data buffer hits */
184 for (Int_t iHit = 0; iHit < nPDBEntries; iHit++){
185 HitData = PackedDataBuffer->GetHit(iHit);
186 /* add volume information */
187 HitData->SetDDLID(iDDL);
188 rawStreamTOF->EquipmentId2VolumeId(HitData, Volume);
193 Volume[4]==-1) continue;
196 Volume[3] = Volume[4];
198 Int_t tof = (Int_t)((Double_t)HitData->GetTime()*1E3/AliTOFGeometry::TdcBinWidth());
199 Int_t index = rawStreamTOF->GetIndex(Volume);
201 geomV5->GetPosPar(Volume,pos);
202 Float_t texp=TMath::Sqrt(pos[0]*pos[0]+pos[1]*pos[1]+pos[2]*pos[2])/c*1E9; //expected time in ns
203 Float_t texpBin=(texp*1E3-32)/AliTOFGeometry::TdcBinWidth(); //expected time in number of TDC bin
204 Int_t deltabin = tof-TMath::Nint(texpBin); //to be used with real data; rounding expected time to Int_t
205 htofPartial->Fill(index,deltabin); //channel index start from 0, bin index from 1
206 //debugging printings
207 //printf("sector %i, plate %i, strip %i, padz %i, padx %i \n",Volume[0],Volume[1],Volume[2],Volume[3],Volume[4]);
208 //printf("pos x = %f, pos y = %f, pos z = %f \n",pos[0],pos[1],pos[2]);
209 //printf ("expected time = %f (ns)\n",texp);
210 //printf ("expected time bin = %f (TDC bin)\n",texpBin);
211 //printf ("measured time bin = %i (TDC bin) with %f (ns) and ACQ bit = %i \n",tof, HitData->GetTime(), HitData->GetACQ());
212 // printf("index = %i, deltabin = %i , filling index = %i, and bin = % i\n",index, deltabin, index, deltabin);
216 PackedDataBuffer->Reset();
219 //printf(" Packed Hit Buffer Entries = %i \n",nPDBEntriesToT);
220 //printf(" Hit Buffer Entries = %i \n",nDBEntriesToT);
232 /* exit when last event received, no need to wait for TERM signal */
233 if (eventT==END_OF_RUN) {
234 printf("EOR event detected\n");
244 //write the Run level file
245 TFile * fileRun = new TFile (FILE_RUN,"RECREATE");
246 htofPartial->Write();
249 //write the Total file
251 TFile * filetot = 0x0;
252 Bool_t isThere=kFALSE;
253 const char *dirname = "./";
254 TString filename = FILE_TOTAL;
255 if((gSystem->FindFile(dirname,filename))!=NULL){
257 printf("%s found \n",FILE_TOTAL);
261 TFile * filetot1 = new TFile (FILE_TOTAL,"READ");
263 if (!filetot1->IsZombie()){
264 printf("updating file %s \n",FILE_TOTAL);
265 TIter next(filetot1->GetListOfKeys());
267 //look for the histogram
268 while ((key=(TKey*)next())){
269 const char * namekey = key->GetName();
270 if (strcmp(namekey,"htoftot")==0){
271 printf(" histo found \n");
272 htoftot = (TH2S*) filetot1->Get("htoftot");
273 htoftot->AddDirectory(0);
274 htoftot->Add(htofPartial);
284 printf(" no %s file found \n",FILE_TOTAL);
285 htoftot = new TH2S(*htofPartial);
286 htoftot->SetName("htoftot");
287 htoftot->AddDirectory(0);
290 filetot = new TFile (FILE_TOTAL,"RECREATE");
306 printf("Run #%s, received %d physics events out of %d\n",getenv("DATE_RUN_NUMBER"),nevents_physics,nevents_total);
310 /* export file to FXS */
311 if (daqDA_FES_storeFile(FILE_RUN, FILE_RUN)) {
314 if (daqDA_FES_storeFile(FILE_TOTAL, FILE_TOTAL)) {