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"
28 #include <AliTOFRawStream.h>
29 #include <AliRawReaderDate.h>
30 #include <AliRawReader.h>
31 #include <AliTOFGeometry.h>
32 #include <AliT0RawReader.h>
34 #include <AliTOFHitData.h>
35 #include <AliTOFHitDataBuffer.h>
36 #include <AliTOFDaConfigHandler.h>
46 #include "TPluginManager.h"
47 #include "TSAXParser.h"
51 1- monitoring data source
53 int main(int argc, char **argv) {
55 /* magic line from Rene */
56 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
62 AliTOFGeometry * geom = new AliTOFGeometry();
64 static const Int_t size = AliTOFGeometry::NPadXSector()*AliTOFGeometry::NSectors();
65 static const Int_t nbins = 500;
66 static const Int_t binmin = -20;
67 const Float_t c = 2.99792458E10; //speed of light [cm/s]
68 TH1F::AddDirectory(0);
69 TH2S * htofPartial = new TH2S("htof","histo with delays",
70 size,-0.5,size*1.-0.5,
71 nbins,binmin-0.5,nbins*1.+binmin-0.5);
75 /* log start of process */
76 printf("TOF DA started\n");
78 /* check that we got some arguments = list of files */
80 printf("Wrong number of arguments\n");
84 /* retrieve config file */
85 int getConfigFile = daqDA_DB_getFile("TOFPhysicsConfig.xml","TOFPhysicsConfig.xml");
86 if (getConfigFile != 0){
87 printf("Failed to retrieve config file from DB! returning...\n");
91 AliTOFDaConfigHandler* tofHandler = new AliTOFDaConfigHandler();
92 TSAXParser *parser = new TSAXParser();
93 parser->ConnectToHandler("AliTOFDaConfigHandler", tofHandler);
94 if (parser->ParseFile("./TOFPhysicsConfig.xml") != 0) {
95 printf("Failed parsing config file! retunring... \n");
99 Int_t debugFlag = tofHandler->GetDebugFlag();
100 printf("The debug flag is %i\n",debugFlag);
101 Int_t t0Flag = tofHandler->GetT0Flag();
102 printf("The T0 flag is %i\n\n",t0Flag);
104 printf("The T0 time will be subtracted from the measured TOF time. So, in TDC bins: \n");
105 printf("tof = tofRaw - (rawReaderT0->GetData(51,0)+rawReaderT0->GetData(52,0))/2) \n\n");
108 printf("The T0 time will not be used.\n");
109 printf("tof = tofRaw \n\n");
112 /* init some counters */
113 int nevents_physics=0;
118 Int_t nPDBEntriesToT = 0;
119 Int_t nDBEntriesToT = 0;
120 AliTOFHitData *HitData;
123 for (Int_t i=0;i<5;i++) Volume[i]=-1;
124 AliTOFRawStream *rawStreamTOF = new AliTOFRawStream();
125 AliTOFHitDataBuffer *DataBuffer;
126 AliTOFHitDataBuffer *PackedDataBuffer;
127 Int_t nDBEntries = 0;
128 Int_t nPDBEntries = 0;
130 struct eventHeaderStruct *event;
131 eventTypeType eventT;
133 /* define data source : this is argument 1 */
134 status=monitorSetDataSource( argv[1] );
136 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
140 /* declare monitoring program */
141 status=monitorDeclareMp( __FILE__ );
143 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
147 /* define wait event timeout - 1s max */
149 monitorSetNoWaitNetworkTimeout(1000);
151 /* main loop (infinite) */
154 /* check shutdown condition */
155 if (daqDA_checkShutdown()) break;
157 /* get next event (blocking call until timeout) */
158 status=monitorGetEventDynamic((void **)&event);
159 if (status==MON_ERR_EOF) {
160 printf ("End of File detected\n");
161 break; /* end of monitoring file has been reached */
165 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
169 /* retry if got no event */
170 if (event==NULL) continue;
174 /* use event - here, just write event id to result file */
176 eventT=event->eventType;
177 switch (event->eventType) {
182 /* END START OF RUN */
191 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
192 //rawReader->RequireHeader(kFALSE);
196 AliT0RawReader *rawReaderT0 = new AliT0RawReader(rawReader,kTRUE);
197 if (!rawReaderT0->Next()) {
198 printf("T0: no raw data found!\n");
202 Int_t allData[105][5];
203 for (Int_t i=0; i<105; i++) {
204 allData[i][0]=rawReaderT0->GetData(i,0);
206 meantime = allData[49][0];
208 //meantime = rawReaderT0->GetData(49,0); //OLD
209 meantime = (Int_t)((rawReaderT0->GetData(51,0)+rawReaderT0->GetData(52,0))/2.); //Alla
211 printf("\nT0 for the current event:\n"); // debugging purpose
212 printf("time zero = %i (TDC bin)\n", meantime); // debugging purpose
213 printf("time zero = %f (ns)\n\n", (Float_t)(meantime)*24.4*1E-3); // debugging purpose
223 for (Int_t ii=0; ii<5; ii++) Volume[ii]=-1;
224 rawStreamTOF->SetRawReader(rawReader);
225 //rawReader->ReadHeader();
226 rawStreamTOF->ResetBuffers();
227 rawStreamTOF->DecodeDDL(0, AliDAQ::NumberOfDdls("TOF") - 1,0);
230 for (Int_t iDDL = 0; iDDL < AliDAQ::NumberOfDdls("TOF"); iDDL++) {
232 /* read decoded data */
233 DataBuffer = rawStreamTOF->GetDataBuffer(iDDL);
234 PackedDataBuffer = rawStreamTOF->GetPackedDataBuffer(iDDL);
236 /* get buffer entries */
237 nDBEntries = DataBuffer->GetEntries();
238 nPDBEntries = PackedDataBuffer->GetEntries();
239 nPDBEntriesToT+=nPDBEntries;
240 nDBEntriesToT+=nDBEntries;
242 //for (Int_t iHit = 0; iHit < nDBEntries; iHit++) {
243 // HitData = DataBuffer->GetHit(iHit);
244 /* store volume information */
245 // rawStreamTOF->EquipmentId2VolumeId(HitData, Volume);
250 /* read data buffer hits */
251 for (Int_t iHit = 0; iHit < nPDBEntries; iHit++) {
252 HitData = PackedDataBuffer->GetHit(iHit);
253 /* add volume information */
254 HitData->SetDDLID(iDDL);
255 rawStreamTOF->EquipmentId2VolumeId(HitData, Volume);
260 Volume[4]==-1) continue;
263 Volume[3] = Volume[4];
265 Int_t tofRaw = (Int_t)((Double_t)HitData->GetTime()*1E3/AliTOFGeometry::TdcBinWidth());
267 if (!t0Flag) tof = tofRaw;
268 else tof = tofRaw - meantime;
269 Int_t index = geom->GetIndex(Volume);
271 geom->GetPosPar(Volume,pos);
272 Float_t texp = TMath::Sqrt(pos[0]*pos[0]+pos[1]*pos[1]+pos[2]*pos[2])/c*1E9; //expected time in ns
273 Float_t texpBin = texp*1E3/AliTOFGeometry::TdcBinWidth(); //expected time in number of TDC bin
274 Int_t deltabin = tof-TMath::Nint(texpBin); //to be used with real data; rounding expected time to Int_t
275 htofPartial->Fill(index,deltabin); //channel index start from 0, bin index from 1
276 //debugging printings
278 printf("tofRaw = %i, tof = %i \n",tofRaw,tof);
281 printf("sector %2d, plate %1d, strip %2d, padz %1d, padx %2d \n",Volume[0],Volume[1],Volume[2],Volume[3],Volume[4]); // too verbose
282 printf("pos x = %f, pos y = %f, pos z = %f \n",pos[0],pos[1],pos[2]); // too verbose
283 printf("expected time = %f (ns)\n",texp); // too verbose
284 printf("expected time bin = %f (TDC bin)\n",texpBin); // too verbose
285 printf("measured time bin = %i (TDC bin) with %f (ns) and ACQ bit = %i \n",tof, HitData->GetTime(), HitData->GetACQ()); // too verbose
286 printf("index = %6d, deltabin = %d , filling index = %6d, and bin = %d\n",index, deltabin, index, deltabin); // too verbose
291 PackedDataBuffer->Reset();
295 // printf(" Packed Hit Buffer Entries = %i \n",nPDBEntriesToT); // too verbose
296 // printf(" Hit Buffer Entries = %i \n",nDBEntriesToT); // too verbose
306 /* exit when last event received, no need to wait for TERM signal */
307 if (eventT==END_OF_RUN) {
308 printf("EOR event detected\n");
320 //write the Run level file
321 TFile * fileRun = new TFile (FILE_RUN,"RECREATE");
322 htofPartial->Write();
325 //write the Total file
327 TFile * filetot = 0x0;
328 Bool_t isThere=kFALSE;
329 const char *dirname = "./";
330 TString filename = FILE_TOTAL;
331 if((gSystem->FindFile(dirname,filename))!=NULL){
333 printf("%s found \n",FILE_TOTAL);
337 TFile * filetot1 = new TFile (FILE_TOTAL,"READ");
339 if (!filetot1->IsZombie()){
340 printf("updating file %s \n",FILE_TOTAL);
341 TIter next(filetot1->GetListOfKeys());
343 //look for the histogram
344 while ((key=(TKey*)next())){
345 const char * namekey = key->GetName();
346 if (strcmp(namekey,"htoftot")==0) {
347 printf(" histo found \n");
348 htoftot = (TH2S*) filetot1->Get("htoftot");
349 htoftot->AddDirectory(0);
350 htoftot->Add(htofPartial);
360 printf(" no %s file found \n",FILE_TOTAL);
361 htoftot = new TH2S(*htofPartial);
362 htoftot->SetName("htoftot");
363 htoftot->AddDirectory(0);
366 filetot = new TFile (FILE_TOTAL,"RECREATE");
382 printf("Run #%s, received %d physics events out of %d\n",
383 getenv("DATE_RUN_NUMBER"),nevents_physics,nevents_total);
387 /* export file to FXS */
388 if (daqDA_FES_storeFile(FILE_RUN, "RUNLevel"))
390 if (daqDA_FES_storeFile(FILE_TOTAL, "DELAYS"))