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 <AliTOFNoiseConfigHandler.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("TOFNoiseConfig.xml","TOFNoiseConfig.xml");
86 if (getConfigFile != 0){
87 printf("Failed to retrieve config file from DB! returning...\n");
91 AliTOFNoiseConfigHandler* tofHandler = new AliTOFNoiseConfigHandler();
92 TSAXParser *parser = new TSAXParser();
93 parser->ConnectToHandler("AliTOFNoiseConfigHandler", tofHandler);
94 if (parser->ParseFile("./TOFNoiseConfig.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);
102 /* init some counters */
103 int nevents_physics=0;
108 Int_t nPDBEntriesToT = 0;
109 Int_t nDBEntriesToT = 0;
110 AliTOFHitData *HitData;
113 for (Int_t i=0;i<5;i++) Volume[i]=-1;
114 AliTOFRawStream *rawStreamTOF = new AliTOFRawStream();
115 AliTOFHitDataBuffer DataBuffer;
116 AliTOFHitDataBuffer PackedDataBuffer;
117 Int_t nDBEntries = 0;
118 Int_t nPDBEntries = 0;
120 struct eventHeaderStruct *event;
121 eventTypeType eventT;
123 /* define data source : this is argument 1 */
124 status=monitorSetDataSource( argv[1] );
126 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
130 /* declare monitoring program */
131 status=monitorDeclareMp( __FILE__ );
133 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
137 /* define wait event timeout - 1s max */
139 monitorSetNoWaitNetworkTimeout(1000);
141 /* main loop (infinite) */
144 /* check shutdown condition */
145 if (daqDA_checkShutdown()) break;
147 /* get next event (blocking call until timeout) */
148 status=monitorGetEventDynamic((void **)&event);
149 if (status==MON_ERR_EOF) {
150 printf ("End of File detected\n");
151 break; /* end of monitoring file has been reached */
155 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
159 /* retry if got no event */
160 if (event==NULL) continue;
164 /* use event - here, just write event id to result file */
166 eventT=event->eventType;
167 switch (event->eventType) {
172 /* END START OF RUN */
181 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
182 //rawReader->RequireHeader(kFALSE);
186 AliT0RawReader *rawReaderT0 = new AliT0RawReader(rawReader,kTRUE);
187 if (!rawReaderT0->Next()) {
188 printf("T0: no raw data found!\n");
192 Int_t allData[105][5];
193 for (Int_t i=0; i<105; i++) {
194 allData[i][0]=rawReaderT0->GetData(i,0);
196 meantime = allData[49][0];
198 //meantime = rawReaderT0->GetData(49,0); //OLD
199 meantime = (Int_t)((rawReaderT0->GetData(51,0)+rawReaderT0->GetData(52,0))/2.); //Alla
200 // printf("time zero (ns) = %i (%f) \n", meantime, (meantime*24.4-200)*1E-3); // debugging purpose
209 for (Int_t ii=0; ii<5; ii++) Volume[ii]=-1;
210 rawStreamTOF->SetRawReader(rawReader);
211 //rawReader->ReadHeader();
212 rawStreamTOF->ResetBuffers();
213 rawStreamTOF->DecodeDDL(0, AliDAQ::NumberOfDdls("TOF") - 1,0);
216 for (Int_t iDDL = 0; iDDL < AliDAQ::NumberOfDdls("TOF"); iDDL++) {
218 /* read decoded data */
219 DataBuffer = rawStreamTOF->GetDataBuffer(iDDL);
220 PackedDataBuffer = rawStreamTOF->GetPackedDataBuffer(iDDL);
222 /* get buffer entries */
223 nDBEntries = DataBuffer.GetEntries();
224 nPDBEntries = PackedDataBuffer.GetEntries();
225 nPDBEntriesToT+=nPDBEntries;
226 nDBEntriesToT+=nDBEntries;
228 //for (Int_t iHit = 0; iHit < nDBEntries; iHit++) {
229 // HitData = DataBuffer->GetHit(iHit);
230 /* store volume information */
231 // rawStreamTOF->EquipmentId2VolumeId(HitData, Volume);
236 /* read data buffer hits */
237 for (Int_t iHit = 0; iHit < nPDBEntries; iHit++) {
238 HitData = PackedDataBuffer.GetHit(iHit);
239 /* add volume information */
240 HitData->SetDDLID(iDDL);
241 rawStreamTOF->EquipmentId2VolumeId(HitData, Volume);
246 Volume[4]==-1) continue;
249 Volume[3] = Volume[4];
251 Int_t tof = (Int_t)((Double_t)HitData->GetTime()*1E3/AliTOFGeometry::TdcBinWidth());
252 Int_t index = geom->GetIndex(Volume);
254 geom->GetPosPar(Volume,pos);
255 Float_t texp = TMath::Sqrt(pos[0]*pos[0]+pos[1]*pos[1]+pos[2]*pos[2])/c*1E9; //expected time in ns
256 Float_t texpBin = texp*1E3/AliTOFGeometry::TdcBinWidth(); //expected time in number of TDC bin
257 Int_t deltabin = tof-TMath::Nint(texpBin); //to be used with real data; rounding expected time to Int_t
258 htofPartial->Fill(index,deltabin); //channel index start from 0, bin index from 1
259 //debugging printings
261 // printf("sector %2d, plate %1d, strip %2d, padz %1d, padx %2d \n",Volume[0],Volume[1],Volume[2],Volume[3],Volume[4]); // too verbose
262 // printf("pos x = %f, pos y = %f, pos z = %f \n",pos[0],pos[1],pos[2]); // too verbose
263 // printf("expected time = %f (ns)\n",texp); // too verbose
264 // printf("expected time bin = %f (TDC bin)\n",texpBin); // too verbose
265 // printf("measured time bin = %i (TDC bin) with %f (ns) and ACQ bit = %i \n",tof, HitData->GetTime(), HitData->GetACQ()); // too verbose
266 // printf("index = %6d, deltabin = %d , filling index = %6d, and bin = %d\n",index, deltabin, index, deltabin); // too verbose
271 PackedDataBuffer.Reset();
275 // printf(" Packed Hit Buffer Entries = %i \n",nPDBEntriesToT); // too verbose
276 // printf(" Hit Buffer Entries = %i \n",nDBEntriesToT); // too verbose
286 /* exit when last event received, no need to wait for TERM signal */
287 if (eventT==END_OF_RUN) {
288 printf("EOR event detected\n");
300 //write the Run level file
301 TFile * fileRun = new TFile (FILE_RUN,"RECREATE");
302 htofPartial->Write();
305 //write the Total file
307 TFile * filetot = 0x0;
308 Bool_t isThere=kFALSE;
309 const char *dirname = "./";
310 TString filename = FILE_TOTAL;
311 if((gSystem->FindFile(dirname,filename))!=NULL){
313 printf("%s found \n",FILE_TOTAL);
317 TFile * filetot1 = new TFile (FILE_TOTAL,"READ");
319 if (!filetot1->IsZombie()){
320 printf("updating file %s \n",FILE_TOTAL);
321 TIter next(filetot1->GetListOfKeys());
323 //look for the histogram
324 while ((key=(TKey*)next())){
325 const char * namekey = key->GetName();
326 if (strcmp(namekey,"htoftot")==0) {
327 printf(" histo found \n");
328 htoftot = (TH2S*) filetot1->Get("htoftot");
329 htoftot->AddDirectory(0);
330 htoftot->Add(htofPartial);
340 printf(" no %s file found \n",FILE_TOTAL);
341 htoftot = new TH2S(*htofPartial);
342 htoftot->SetName("htoftot");
343 htoftot->AddDirectory(0);
346 filetot = new TFile (FILE_TOTAL,"RECREATE");
362 printf("Run #%s, received %d physics events out of %d\n",
363 getenv("DATE_RUN_NUMBER"),nevents_physics,nevents_total);
367 /* export file to FXS */
368 if (daqDA_FES_storeFile(FILE_RUN, "RUNLevel"))
370 if (daqDA_FES_storeFile(FILE_TOTAL, "DELAYS"))