3 TOF DA for online calibration
7 #define FILE_TOTAL "TOFdaTotal.root"
8 #define FILE_RUN "TOFdaRun.root"
18 #include <AliTOFRawStream.h>
19 #include <AliRawReaderDate.h>
20 #include <AliRawReader.h>
21 #include <AliTOFGeometry.h>
22 #include <AliTOFGeometryV5.h>
23 #include <AliT0RawReader.h>
25 #include <AliTOFHitData.h>
26 #include <AliTOFHitDataBuffer.h>
39 1- monitoring data source
42 int main(int argc, char **argv) {
44 AliTOFGeometry * geomV5 = new AliTOFGeometryV5();
45 AliTOFGeometry * geom = new AliTOFGeometry();
47 static const Int_t size = geomV5->NPadXSector()*geomV5->NSectors();
48 static const Int_t nbins = 500;
49 static const Int_t binmin = -20;
50 const Float_t c = 2.99792458E10; //speed of light
51 TH1F::AddDirectory(0);
52 TH2S * htofPartial = new TH2S("htof","histo with delays", size,-0.5,size*1.-0.5,nbins,binmin-0.5,nbins*1.+binmin-0.5);
54 // decoding the events
58 printf("Wrong number of arguments\n");
62 /* define data source : this is argument 1 */
63 status=monitorSetDataSource( argv[1] );
65 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
69 /* declare monitoring program */
70 status=monitorDeclareMp( __FILE__ );
72 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
76 /* define wait event timeout - 1s max */
78 monitorSetNoWaitNetworkTimeout(1000);
80 /* log start of process */
81 printf("TOF DA started\n");
83 /* init some counters */
84 int nevents_physics=0;
87 struct eventHeaderStruct *event;
91 /* main loop (infinite) */
94 /* check shutdown condition */
95 if (daqDA_checkShutdown()) {break;}
97 /* get next event (blocking call until timeout) */
98 status=monitorGetEventDynamic((void **)&event);
99 if (status==MON_ERR_EOF) {
100 printf ("End of File detected\n");
101 break; /* end of monitoring file has been reached */
105 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
109 /* retry if got no event */
116 /* use event - here, just write event id to result file */
118 eventT=event->eventType;
119 switch (event->eventType){
124 /* END START OF RUN */
132 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
133 //rawReader->RequireHeader(kFALSE);
137 AliT0RawReader *rawReaderT0 = new AliT0RawReader(rawReader);
138 if (!rawReaderT0->Next()) {
139 printf("T0: no raw data found!\n");
141 Int_t allData[110][5];
142 for (Int_t i=0; i<110; i++) {
143 allData[i][0]=rawReaderT0->GetData(i,0);
145 meantime = allData[49][0];
146 //printf("time zero (ns) = %i (%f) \n", meantime, meantime*25*1E-3-200);
156 AliTOFHitData *HitData;
157 AliTOFHitDataBuffer *DataBuffer;
158 AliTOFHitDataBuffer *PackedDataBuffer;
159 AliTOFRawStream *rawStreamTOF = new AliTOFRawStream(rawReader);
160 // rawReader->ReadHeader();
161 rawStreamTOF->ResetBuffers();
162 rawStreamTOF->DecodeDDL(0, AliDAQ::NumberOfDdls("TOF") - 1,0);
163 Int_t nPDBEntriesToT = 0;
164 Int_t nDBEntriesToT = 0;
165 for (Int_t iDDL = 0; iDDL < AliDAQ::NumberOfDdls("TOF"); iDDL++){
167 /* read decoded data */
168 DataBuffer = rawStreamTOF->GetDataBuffer(iDDL);
169 PackedDataBuffer = rawStreamTOF->GetPackedDataBuffer(iDDL);
171 /* get buffer entries */
172 Int_t nDBEntries = DataBuffer->GetEntries();
173 Int_t nPDBEntries = PackedDataBuffer->GetEntries();
174 nPDBEntriesToT+=nPDBEntries;
175 nDBEntriesToT+=nDBEntries;
177 //for (Int_t iHit = 0; iHit < nDBEntries; iHit++){
178 // HitData = DataBuffer->GetHit(iHit);
179 /* store volume information */
180 // rawStreamTOF->EquipmentId2VolumeId(HitData, Volume);
185 /* read data buffer hits */
186 for (Int_t iHit = 0; iHit < nPDBEntries; iHit++){
187 HitData = PackedDataBuffer->GetHit(iHit);
188 /* add volume information */
189 HitData->SetDDLID(iDDL);
190 rawStreamTOF->EquipmentId2VolumeId(HitData, Volume);
195 Volume[4]==-1) continue;
198 Volume[3] = Volume[4];
200 Int_t tof = (Int_t)((Double_t)HitData->GetTime()*1E3/AliTOFGeometry::TdcBinWidth());
201 Int_t index = rawStreamTOF->GetIndex(Volume);
203 geomV5->GetPosPar(Volume,pos);
204 Float_t texp=TMath::Sqrt(pos[0]*pos[0]+pos[1]*pos[1]+pos[2]*pos[2])/c*1E9; //expected time in ns
205 Float_t texpBin=(texp*1E3-32)/AliTOFGeometry::TdcBinWidth(); //expected time in number of TDC bin
206 Int_t deltabin = tof-TMath::Nint(texpBin); //to be used with real data; rounding expected time to Int_t
207 htofPartial->Fill(index,deltabin); //channel index start from 0, bin index from 1
208 //debugging printings
209 //printf("sector %i, plate %i, strip %i, padz %i, padx %i \n",Volume[0],Volume[1],Volume[2],Volume[3],Volume[4]);
210 //printf("pos x = %f, pos y = %f, pos z = %f \n",pos[0],pos[1],pos[2]);
211 //printf ("expected time = %f (ns)\n",texp);
212 //printf ("expected time bin = %f (TDC bin)\n",texpBin);
213 //printf ("measured time bin = %i (TDC bin) with %f (ns) and ACQ bit = %i \n",tof, HitData->GetTime(), HitData->GetACQ());
214 // printf("index = %i, deltabin = %i , filling index = %i, and bin = % i\n",index, deltabin, index, deltabin);
218 PackedDataBuffer->Reset();
221 //printf(" Packed Hit Buffer Entries = %i \n",nPDBEntriesToT);
222 //printf(" Hit Buffer Entries = %i \n",nDBEntriesToT);
234 /* exit when last event received, no need to wait for TERM signal */
235 if (eventT==END_OF_RUN) {
236 printf("EOR event detected\n");
246 //write the Run level file
247 TFile * fileRun = new TFile (FILE_RUN,"RECREATE");
248 htofPartial->Write();
251 //write the Total file
253 TFile * filetot = 0x0;
254 Bool_t isThere=kFALSE;
255 const char *dirname = "./";
256 TString filename = FILE_TOTAL;
257 if((gSystem->FindFile(dirname,filename))!=NULL){
259 printf("%s found \n",FILE_TOTAL);
263 TFile * filetot1 = new TFile (FILE_TOTAL,"READ");
265 if (!filetot1->IsZombie()){
266 printf("updating file %s \n",FILE_TOTAL);
267 TIter next(filetot1->GetListOfKeys());
269 //look for the histogram
270 while ((key=(TKey*)next())){
271 const char * namekey = key->GetName();
272 if (strcmp(namekey,"htoftot")==0){
273 printf(" histo found \n");
274 htoftot = (TH2S*) filetot1->Get("htoftot");
275 htoftot->AddDirectory(0);
276 htoftot->Add(htofPartial);
286 printf(" no %s file found \n",FILE_TOTAL);
287 htoftot = new TH2S(*htofPartial);
288 htoftot->SetName("htoftot");
289 htoftot->AddDirectory(0);
292 filetot = new TFile (FILE_TOTAL,"RECREATE");
308 printf("Run #%s, received %d physics events out of %d\n",getenv("DATE_RUN_NUMBER"),nevents_physics,nevents_total);
312 /* export file to FXS */
313 if (daqDA_FES_storeFile(FILE_RUN, FILE_RUN)) {
316 if (daqDA_FES_storeFile(FILE_TOTAL, FILE_TOTAL)) {