3 TOF DA for online calibration
5 Contact: Chiara.Zampolli@bo.infn.it
6 Roberto.Preghenella@bo.infn.it
10 Number of events needed:
12 Output Files: TOFdaHits.root
13 Event types used: PHYSICS_EVENT
17 #define FILE_HITS "TOFdaHits.root"
18 #define FILE_CALIB "TOFdaCalib.root"
30 #include "AliTOFRawStream.h"
31 #include "AliRawReaderDate.h"
32 #include "AliRawReader.h"
34 #include "AliTOFHitData.h"
35 #include "AliTOFHitDataBuffer.h"
36 #include "AliTOFDaConfigHandler.h"
37 #include "AliTOFHitField.h"
39 #include "AliTOFGeometry.h"
49 #include "TPluginManager.h"
50 #include "TSAXParser.h"
55 1- monitoring data source
58 main(int argc, char **argv)
61 /* magic line from Rene */
62 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
69 /* log start of process */
70 printf("TOF DA started\n");
72 /* check that we got some arguments = list of files */
74 printf("Wrong number of arguments\n");
82 /* retrieve config file */
83 int getConfigFile = daqDA_DB_getFile("TOFPhysicsConfig.xml","TOFPhysicsConfig.xml");
84 if (getConfigFile != 0){
85 printf("Failed to retrieve config file from DB! returning...\n");
88 /* parse config file */
89 AliTOFDaConfigHandler* tofHandler = new AliTOFDaConfigHandler();
90 TSAXParser *parser = new TSAXParser();
91 parser->ConnectToHandler("AliTOFDaConfigHandler", tofHandler);
92 if (parser->ParseFile("./TOFPhysicsConfig.xml") != 0) {
93 printf("Failed parsing config file! retunring... \n");
96 /* setup config params */
97 Int_t meanMultiplicity = tofHandler->GetMeanMultiplicity(); /* average expected TOF multiplicity */
98 Int_t maxHits = tofHandler->GetMaxHits(); /* max number of hits to be collected */
99 printf("current settings:\n");
100 printf(" - meanMultiplicity = %d\n", meanMultiplicity);
101 printf(" - maxHits = %d\n", maxHits);
103 const Int_t nChannels = 157248;
104 Int_t noiseCheckTrigger = 10; /* first noise check after 10 events */
105 Float_t meanChannelRate = (Float_t)meanMultiplicity / (Float_t)nChannels; /* average expected channel rate (hits/event) */
106 Float_t noiseThreshold = 10. * meanChannelRate; /* noise threshold (hits/event) */
107 Int_t minNoiseHits = 10; /* min number of channel hits to check noise */
108 /* counters and flags */
109 Int_t nPhysicsEvents, nCalibEvents, totHits;
110 Int_t nChHits[nChannels];
111 Bool_t inhibitCollection;
112 Bool_t noiseFlag[nChannels];
114 Int_t nhits, ddl, slot, trm, chain, tdc, channel, index, timebin, totbin, deltaBC, l0l1latency, det[5], dummy;
115 Float_t noiseHitThreshold;
121 /* init counters and flags */
125 inhibitCollection = kFALSE;
126 for (Int_t ich = 0; ich < nChannels; ich++) {
128 noiseFlag[ich] = kFALSE;
131 /* TOF raw data handling */
132 AliTOFRawStream *rawStream = new AliTOFRawStream();
133 AliTOFHitDataBuffer *pdb = NULL;
134 AliTOFHitData *hit = NULL;
136 /* open HITS output file */
137 TFile *fileOutHits = new TFile(FILE_HITS, "RECREATE");
138 /* create hit field data structure */
139 AliTOFHitField *hitField = new AliTOFHitField();
140 /* create temporary tree */
141 TTree *tempTree = new TTree("tempTree", "temporary tree");
142 tempTree->Branch("hit", "AliTOFHitField", &hitField);
143 /* create output tree */
144 TTree *outTree = new TTree("hitTree", "hit tree");
145 outTree->Branch("hit", "AliTOFHitField", &hitField);
147 /* open CALIB output file */
148 TFile *fileOutCalib = new TFile(FILE_CALIB, "RECREATE");
149 /* create calib hit histo */
150 TH1F *hCalibHit = new TH1F("hCalibHit", "Calibration events;index;N_{hits}/N_{events}", nChannels, 0., nChannels);
156 AliLog::SetGlobalLogLevel(AliLog::kFatal);
157 struct eventHeaderStruct *event;
159 /* define data source : this is argument 1 */
160 ret = monitorSetDataSource(argv[1]);
162 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(ret));
165 /* declare monitoring program */
166 ret = monitorDeclareMp("tofDA");
168 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(ret));
171 /* define wait event timeout - 1s max */
173 monitorSetNoWaitNetworkTimeout(1000);
175 /* loop over events */
178 /* check shutdown condition */
179 if (daqDA_checkShutdown()) break;
185 /* check inhibit collection */
186 if (!inhibitCollection) {
187 /* check number of events and check noise */
188 if (nPhysicsEvents >= noiseCheckTrigger || totHits >= maxHits) {
189 noiseHitThreshold = noiseThreshold * nPhysicsEvents;
190 printf("noise check triggered after %d events: threshold is %f hits\n", nPhysicsEvents, noiseHitThreshold);
191 /* loop over all channels */
192 for (Int_t ich = 0; ich < nChannels; ich++) {
194 if (nChHits[ich] < minNoiseHits || noiseFlag[ich] || nChHits[ich] < noiseHitThreshold) continue;
195 printf("channel %d tagged as noisy (%d hits): disabled\n", ich, nChHits[ich]);
196 noiseFlag[ich] = kTRUE;
197 totHits -= nChHits[ich];
198 } /* end of loop over all channels */
199 /* set new noise check trigger value */
200 noiseCheckTrigger *= 10;
201 } /* end of noise check */
203 /* inhibit hit collection when maximum number of hits exceeded */
204 if (totHits >= maxHits) {
205 printf("maximum number of hits exceeded (%d): inhibit hit collection\n", maxHits);
206 inhibitCollection = kTRUE;
214 /* get next event (blocking call until timeout) */
215 ret = monitorGetEventDynamic((void **)&event);
216 if (ret == MON_ERR_EOF) {
217 printf ("End of File detected\n");
218 break; /* end of monitoring file has been reached */
221 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(ret));
224 /* retry if got no event */
225 if (event==NULL) continue;
226 /* check event type */
227 if (event->eventType != PHYSICS_EVENT && event->eventType != CALIBRATION_EVENT) continue;
228 /* check inhibit collection */
229 if (event->eventType == PHYSICS_EVENT && inhibitCollection) continue;
230 /* increment number of physics events */
231 if (event->eventType == PHYSICS_EVENT) nPhysicsEvents++;
232 /* increment number of calib events */
233 if (event->eventType == CALIBRATION_EVENT) nCalibEvents++;
239 /* create raw reader */
240 AliRawReader *rawReader = new AliRawReaderDate((void *)event);
241 /* setup raw stream */
242 rawStream->SetRawReader(rawReader);
244 rawStream->ResetBuffers();
246 rawStream->DecodeDDL(0, AliDAQ::NumberOfDdls("TOF") - 1, 0);
253 for (Int_t iddl = 0; iddl < AliDAQ::NumberOfDdls("TOF"); iddl++) {
254 /* get packed-data buffer */
255 pdb = rawStream->GetPackedDataBuffer(iddl);
256 nhits = pdb->GetEntries();
257 /* loop over hits in buffer */
258 for (Int_t ihit = 0; ihit < nhits; ihit++) {
260 hit = pdb->GetHit(ihit);
261 /* get channel info */
263 slot = hit->GetSlotID();
265 chain = hit->GetChain();
267 channel = hit->GetChan();
269 rawStream->EquipmentId2VolumeId(ddl, slot, chain, tdc, channel, det);
273 /* check valid index */
274 if (det[0] < 0 || det[0] > 17 ||
275 det[1] < 0 || det[1] > 5 ||
276 det[2] < 0 || det[2] > 18 ||
277 det[3] < 0 || det[3] > 1 ||
278 det[4] < 0 || det[4] > 47) continue;
279 index = AliTOFGeometry::GetIndex(det);
281 /* switch event type */
282 switch (event->eventType) {
289 /* check noise flag */
290 if (noiseFlag[index]) continue;
291 /* increment number of channel hits and total hits */
294 /* get signal info */
295 timebin = hit->GetTimeBin();
296 totbin = hit->GetTOTBin();
297 deltaBC = hit->GetDeltaBunchID();
298 l0l1latency = hit->GetL0L1Latency();
299 /* set hit field data */
300 hitField->SetIndex(index);
301 hitField->SetTimeBin(timebin);
302 hitField->SetTOTBin(totbin);
303 hitField->SetDeltaBC(deltaBC);
304 hitField->SetL0L1Latency(l0l1latency);
313 case CALIBRATION_EVENT:
314 /* fill calib hit histo */
315 hCalibHit->Fill(index);
318 } /* end of switch event type */
319 } /* end of loop over hits in buffer */
320 } /* end of loop over DDLs */
322 /* delete raw reader */
325 } /* end of loop over events */
327 /* final noise check */
328 noiseHitThreshold = noiseThreshold * nPhysicsEvents;
329 printf("final noise check after %d events: threshold is %f hits\n", nPhysicsEvents, noiseHitThreshold);
330 /* loop over all channels */
331 for (Int_t ich = 0; ich < nChannels; ich++) {
333 if (nChHits[ich] < minNoiseHits || noiseFlag[ich] || nChHits[ich] < noiseHitThreshold) continue;
334 printf("channel %d tagged as noisy (%d hits): disabled\n", ich, nChHits[ich]);
335 noiseFlag[ich] = kTRUE;
336 totHits -= nChHits[ich];
337 } /* end of loop over all channels */
339 /* copy hits into output tree from temp tree */
340 printf("copy hits from temporary tree into output tree\n");
341 printf("temporary tree contains %d hits\n", (Int_t)tempTree->GetEntries());
342 for (Int_t ihit = 0; ihit < tempTree->GetEntries(); ihit++) {
344 tempTree->GetEntry(ihit);
345 /* check noise flag */
346 if (noiseFlag[hitField->GetIndex()]) continue;
347 /* fill output tree */
349 } /* end of copy hits into output tree from temp tree */
350 printf("output tree contains %d hits\n", (Int_t)outTree->GetEntries());
352 /* write output tree on HITS file */
355 fileOutHits->Close();
356 /* export file to FXS */
357 if (daqDA_FES_storeFile(FILE_HITS, "HITS"))
360 /* scale calib hit histo by number of calib events */
362 hCalibHit->Scale(1. / nCalibEvents);
364 /* write calib hit histo on CALIB file */
367 fileOutCalib->Close();
368 /* export file to FXS */
369 if (daqDA_FES_storeFile(FILE_CALIB, "CALIB"))