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 <AliT0RawReader.h>
22 #include <AliTOFHitData.h>
23 #include <AliTOFHitDataBuffer.h>
36 1- monitoring data source
39 int main(int argc, char **argv) {
41 AliTOFGeometry * geom = new AliTOFGeometry();
43 static const Int_t size = AliTOFgeometry::NPadXSector()*AliTOFGeometry::NSectors();
44 static const Int_t nbins = 500;
45 static const Int_t binmin = -20;
46 const Float_t c = 2.99792458E10; //speed of light
47 TH1F::AddDirectory(0);
48 TH2S * htofPartial = new TH2S("htof","histo with delays", size,-0.5,size*1.-0.5,nbins,binmin-0.5,nbins*1.+binmin-0.5);
50 // decoding the events
54 printf("Wrong number of arguments\n");
58 /* define data source : this is argument 1 */
59 status=monitorSetDataSource( argv[1] );
61 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
65 /* declare monitoring program */
66 status=monitorDeclareMp( __FILE__ );
68 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
72 /* define wait event timeout - 1s max */
74 monitorSetNoWaitNetworkTimeout(1000);
76 /* log start of process */
77 printf("TOF DA started\n");
79 /* init some counters */
80 int nevents_physics=0;
83 struct eventHeaderStruct *event;
87 /* main loop (infinite) */
90 /* check shutdown condition */
91 if (daqDA_checkShutdown()) {break;}
93 /* get next event (blocking call until timeout) */
94 status=monitorGetEventDynamic((void **)&event);
95 if (status==MON_ERR_EOF) {
96 printf ("End of File detected\n");
97 break; /* end of monitoring file has been reached */
101 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
105 /* retry if got no event */
112 /* use event - here, just write event id to result file */
114 eventT=event->eventType;
115 switch (event->eventType){
120 /* END START OF RUN */
128 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
129 //rawReader->RequireHeader(kFALSE);
133 AliT0RawReader *rawReaderT0 = new AliT0RawReader(rawReader,kTRUE);
134 if (!rawReaderT0->Next()) {
135 printf("T0: no raw data found!\n");
137 Int_t allData[110][5];
138 for (Int_t i=0; i<110; i++) {
139 allData[i][0]=rawReaderT0->GetData(i,0);
141 meantime = allData[49][0];
142 //printf("time zero (ns) = %i (%f) \n", meantime, meantime*25*1E-3-200);
152 AliTOFHitData *HitData;
153 AliTOFHitDataBuffer *DataBuffer;
154 AliTOFHitDataBuffer *PackedDataBuffer;
155 AliTOFRawStream *rawStreamTOF = new AliTOFRawStream(rawReader);
156 // rawReader->ReadHeader();
157 rawStreamTOF->ResetBuffers();
158 rawStreamTOF->DecodeDDL(0, AliDAQ::NumberOfDdls("TOF") - 1,0);
159 Int_t nPDBEntriesToT = 0;
160 Int_t nDBEntriesToT = 0;
161 for (Int_t iDDL = 0; iDDL < AliDAQ::NumberOfDdls("TOF"); iDDL++){
163 /* read decoded data */
164 DataBuffer = rawStreamTOF->GetDataBuffer(iDDL);
165 PackedDataBuffer = rawStreamTOF->GetPackedDataBuffer(iDDL);
167 /* get buffer entries */
168 Int_t nDBEntries = DataBuffer->GetEntries();
169 Int_t nPDBEntries = PackedDataBuffer->GetEntries();
170 nPDBEntriesToT+=nPDBEntries;
171 nDBEntriesToT+=nDBEntries;
173 //for (Int_t iHit = 0; iHit < nDBEntries; iHit++){
174 // HitData = DataBuffer->GetHit(iHit);
175 /* store volume information */
176 // rawStreamTOF->EquipmentId2VolumeId(HitData, Volume);
181 /* read data buffer hits */
182 for (Int_t iHit = 0; iHit < nPDBEntries; iHit++){
183 HitData = PackedDataBuffer->GetHit(iHit);
184 /* add volume information */
185 HitData->SetDDLID(iDDL);
186 rawStreamTOF->EquipmentId2VolumeId(HitData, Volume);
191 Volume[4]==-1) continue;
194 Volume[3] = Volume[4];
196 Int_t tof = (Int_t)((Double_t)HitData->GetTime()*1E3/AliTOFGeometry::TdcBinWidth());
197 Int_t index = geom->GetIndex(Volume);
199 geom->GetPosPar(Volume,pos);
200 Float_t texp=TMath::Sqrt(pos[0]*pos[0]+pos[1]*pos[1]+pos[2]*pos[2])/c*1E9; //expected time in ns
201 Float_t texpBin=(texp*1E3-32)/AliTOFGeometry::TdcBinWidth(); //expected time in number of TDC bin
202 Int_t deltabin = tof-TMath::Nint(texpBin); //to be used with real data; rounding expected time to Int_t
203 htofPartial->Fill(index,deltabin); //channel index start from 0, bin index from 1
204 //debugging printings
205 //printf("sector %i, plate %i, strip %i, padz %i, padx %i \n",Volume[0],Volume[1],Volume[2],Volume[3],Volume[4]);
206 //printf("pos x = %f, pos y = %f, pos z = %f \n",pos[0],pos[1],pos[2]);
207 //printf ("expected time = %f (ns)\n",texp);
208 //printf ("expected time bin = %f (TDC bin)\n",texpBin);
209 //printf ("measured time bin = %i (TDC bin) with %f (ns) and ACQ bit = %i \n",tof, HitData->GetTime(), HitData->GetACQ());
210 // printf("index = %i, deltabin = %i , filling index = %i, and bin = % i\n",index, deltabin, index, deltabin);
214 PackedDataBuffer->Reset();
217 //printf(" Packed Hit Buffer Entries = %i \n",nPDBEntriesToT);
218 //printf(" Hit Buffer Entries = %i \n",nDBEntriesToT);
230 /* exit when last event received, no need to wait for TERM signal */
231 if (eventT==END_OF_RUN) {
232 printf("EOR event detected\n");
240 //write the Run level file
241 TFile * fileRun = new TFile (FILE_RUN,"RECREATE");
242 htofPartial->Write();
245 //write the Total file
247 TFile * filetot = 0x0;
248 Bool_t isThere=kFALSE;
249 const char *dirname = "./";
250 TString filename = FILE_TOTAL;
251 if((gSystem->FindFile(dirname,filename))!=NULL){
253 printf("%s found \n",FILE_TOTAL);
257 TFile * filetot1 = new TFile (FILE_TOTAL,"READ");
259 if (!filetot1->IsZombie()){
260 printf("updating file %s \n",FILE_TOTAL);
261 TIter next(filetot1->GetListOfKeys());
263 //look for the histogram
264 while ((key=(TKey*)next())){
265 const char * namekey = key->GetName();
266 if (strcmp(namekey,"htoftot")==0){
267 printf(" histo found \n");
268 htoftot = (TH2S*) filetot1->Get("htoftot");
269 htoftot->AddDirectory(0);
270 htoftot->Add(htofPartial);
280 printf(" no %s file found \n",FILE_TOTAL);
281 htoftot = new TH2S(*htofPartial);
282 htoftot->SetName("htoftot");
283 htoftot->AddDirectory(0);
286 filetot = new TFile (FILE_TOTAL,"RECREATE");
302 printf("Run #%s, received %d physics events out of %d\n",getenv("DATE_RUN_NUMBER"),nevents_physics,nevents_total);
306 /* export file to FXS */
307 if (daqDA_FES_storeFile(FILE_RUN, FILE_RUN)) {
310 if (daqDA_FES_storeFile(FILE_TOTAL, FILE_TOTAL)) {