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 TOFdaReadout.root
13 Event types used: PHYSICS_EVENT
17 #define FILE_HITS "TOFdaHits.root"
18 #define FILE_READOUT "TOFdaReadout.root"
20 #define READOUT_INFO_HISTO 1
33 #include "AliTOFRawStream.h"
34 #include "AliRawReaderDate.h"
35 #include "AliRawReader.h"
37 #include "AliTOFHitData.h"
38 #include "AliTOFHitDataBuffer.h"
39 #include "AliTOFDaConfigHandler.h"
40 #include "AliTOFHitField.h"
42 #include "AliTOFGeometry.h"
43 #include "AliTOFDecoderV2.h"
44 #include "AliTOFDecoderSummaryData.h"
45 #include "AliTOFDRMSummaryData.h"
46 #include "AliTOFTRMSummaryData.h"
47 #include "AliTOFChainSummaryData.h"
48 #include "AliTOFTDCHitBuffer.h"
49 #include "AliTOFTDCHit.h"
50 #include "AliTOFTDCErrorBuffer.h"
51 #include "AliTOFTDCError.h"
61 #include "TPluginManager.h"
62 #include "TSAXParser.h"
67 1- monitoring data source
70 main(int argc, char **argv)
73 /* magic line from Rene */
74 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
81 /* log start of process */
82 printf("TOF DA started\n");
84 /* check that we got some arguments = list of files */
86 printf("Wrong number of arguments\n");
94 /* retrieve config file */
95 int getConfigFile = daqDA_DB_getFile("TOFPhysicsConfig.xml","TOFPhysicsConfig.xml");
96 if (getConfigFile != 0){
97 printf("Failed to retrieve config file from DB! returning...\n");
100 /* parse config file */
101 AliTOFDaConfigHandler* tofHandler = new AliTOFDaConfigHandler();
102 TSAXParser *parser = new TSAXParser();
103 parser->ConnectToHandler("AliTOFDaConfigHandler", tofHandler);
104 if (parser->ParseFile("./TOFPhysicsConfig.xml") != 0) {
105 printf("Failed parsing config file! retunring... \n");
108 /* setup config params */
109 Int_t meanMultiplicity = tofHandler->GetMeanMultiplicity(); /* average expected TOF multiplicity */
110 Int_t maxHits = tofHandler->GetMaxHits(); /* max number of hits to be collected */
111 printf("current settings:\n");
112 printf(" - meanMultiplicity = %d\n", meanMultiplicity);
113 printf(" - maxHits = %d\n", maxHits);
115 const Int_t nChannels = 157248;
116 Int_t noiseCheckTrigger = 10; /* first noise check after 10 events */
117 Float_t meanChannelRate = (Float_t)meanMultiplicity / (Float_t)nChannels; /* average expected channel rate (hits/event) */
118 Float_t noiseThreshold = 10. * meanChannelRate; /* noise threshold (hits/event) */
119 Int_t minNoiseHits = 10; /* min number of channel hits to check noise */
120 /* counters and flags */
121 Int_t nPhysicsEvents, nCollectedPhysicsEvents, totHits;
122 Int_t nChHits[nChannels];
123 Bool_t inhibitCollection;
124 Bool_t noiseFlag[nChannels];
126 Int_t ddl, slot, trm, chain, tdc, channel, index, timebin, totbin, deltaBC, l0l1latency, det[5], dummy;
127 Float_t noiseHitThreshold;
133 /* init counters and flags */
135 nCollectedPhysicsEvents = 0;
137 inhibitCollection = kFALSE;
138 for (Int_t ich = 0; ich < nChannels; ich++) {
140 noiseFlag[ich] = kFALSE;
143 /* TOF raw data handling */
144 AliTOFRawStream *rawStream = new AliTOFRawStream();
145 AliTOFDecoderV2 *decoder = rawStream->GetDecoderV2();
146 AliTOFDecoderSummaryData *decodersd;
147 AliTOFDRMSummaryData *drmsd;
148 // AliTOFLTMSummaryData *ltmsd;
149 AliTOFTRMSummaryData *trmsd;
150 AliTOFChainSummaryData *chainsd;
151 AliTOFTDCHitBuffer *hitBuffer;
153 AliTOFTDCErrorBuffer *errorBuffer;
154 AliTOFTDCError *error;
160 const AliRawDataHeader *currentCDH;
161 Int_t currentMiniEventID;
162 Int_t currentEventID1;
163 Int_t currentL0BCID ;
164 Int_t currentBunchID;
165 Bool_t skipTRM, skipChain;
166 Int_t trmIndex, chainIndex, tdcIndex;
169 /* open HITS output file */
170 TFile *fileOutHits = new TFile(FILE_HITS, "RECREATE");
171 /* create hit field data structure */
172 AliTOFHitField *hitField = new AliTOFHitField();
173 /* create temporary tree */
174 TTree *tempTree = new TTree("tempTree", "temporary tree");
175 tempTree->Branch("hit", "AliTOFHitField", &hitField);
176 /* create output tree */
177 TTree *outTree = new TTree("hitTree", "hit tree");
178 outTree->Branch("hit", "AliTOFHitField", &hitField);
180 /* open READOUT output file */
181 TFile *fileOutReadout = new TFile(FILE_READOUT, "RECREATE");
182 /* create chain readout efficiency histo */
183 TH1F *hChainEfficiency = new TH1F("hChainEfficiency", "Chain efficiency;chain;efficiency", 1440, 0., 1440.);
185 #if READOUT_INFO_HISTO
186 /* create TRM data histo */
187 TH1F *hTRMData = new TH1F("hTRMData", "TRM data;TRM;frequency", 720, 0., 720.);
188 /* create TRM empty event frequency histo */
189 TH1F *hTRMEmptyEvent = new TH1F("hTRMEmptyEvent", "TRM empty event error;TRM;frequency", 720, 0., 720.);
190 /* create TRM bad event counter frequency histo */
191 TH1F *hTRMBadEventCounter = new TH1F("hTRMBadEventCounter", "TRM bad event counter;TRM;frequency", 720, 0., 720.);
192 /* create TRM bad CRC frequency histo */
193 TH1F *hTRMBadCRC = new TH1F("hTRMBadCRC", "TRM bad CRC;TRM;frequency", 720, 0., 720.);
195 /* create chain data histo */
196 TH1F *hChainData = new TH1F("hChainData", "Chain data;chain;frequency", 1440, 0., 1440.);
197 /* create chain bad status frequency histo */
198 TH1F *hChainBadStatus = new TH1F("hChainBadStatus", "Chain bad status;chain;frequency", 1440, 0., 1440.);
199 /* create chain bad event counter frequency histo */
200 TH1F *hChainBadEventCounter = new TH1F("hChainBadEventCounter", "Chain bad event counter;chain;status;frequency", 1440, 0., 1440.);
202 /* create TDC error frequency histo */
203 TH1F *hTDCError = new TH1F("hTDCError", "TDC error;TDC;frequency", 21600, 0., 21600.);
204 /* create TDC error flags frequency histo */
205 TH2F *hTDCErrorFlags = new TH2F("hTDCErrorFlags", "TDC error flags;TDC;error flag;frequency", 21600, 0., 21600., 15, 0., 15);
213 AliLog::SetGlobalLogLevel(AliLog::kFatal);
214 struct eventHeaderStruct *event;
216 /* define monitoring table */
217 char *monTable[5] = {
222 ret = monitorDeclareTable(monTable);
224 printf("monitorDeclareTable() failed: %s\n", monitorDecodeError(ret));
227 /* define data source : this is argument 1 */
228 ret = monitorSetDataSource(argv[1]);
230 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(ret));
233 /* declare monitoring program */
234 ret = monitorDeclareMp("TOFdaPhysics");
236 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(ret));
239 /* define wait event timeout - 1s max */
241 monitorSetNoWaitNetworkTimeout(1000);
245 /* loop over events */
248 /* check shutdown condition */
249 if (daqDA_checkShutdown()) break;
255 /* check inhibit collection */
256 if (!inhibitCollection) {
257 /* check number of events and check noise */
258 if (nCollectedPhysicsEvents >= noiseCheckTrigger || totHits >= maxHits) {
259 noiseHitThreshold = noiseThreshold * nCollectedPhysicsEvents;
260 printf("noise check triggered after %d events: threshold is %f hits\n", nCollectedPhysicsEvents, noiseHitThreshold);
261 /* loop over all channels */
262 for (Int_t ich = 0; ich < nChannels; ich++) {
264 if (nChHits[ich] < minNoiseHits || noiseFlag[ich] || nChHits[ich] < noiseHitThreshold) continue;
265 printf("channel %d tagged as noisy (%d hits): disabled\n", ich, nChHits[ich]);
266 noiseFlag[ich] = kTRUE;
267 totHits -= nChHits[ich];
268 } /* end of loop over all channels */
269 /* set new noise check trigger value */
270 noiseCheckTrigger *= 10;
271 } /* end of noise check */
273 /* inhibit hit collection when maximum number of hits exceeded */
274 if (totHits >= maxHits) {
275 printf("maximum number of hits exceeded (%d): inhibit hit collection\n", maxHits);
276 inhibitCollection = kTRUE;
284 /* get next event (blocking call until timeout) */
285 ret = monitorGetEventDynamic((void **)&event);
286 if (ret == MON_ERR_EOF) {
287 printf ("End of File detected\n");
288 break; /* end of monitoring file has been reached */
291 printf("monitorGetEventDynamic() failed (ret=%d errno=%d): %s\n", ret, errno, monitorDecodeError(ret));
294 /* retry if got no event */
295 if (event==NULL) continue;
296 /* check TOF in partecipating detectors */
297 if (!TEST_DETECTOR_IN_PATTERN(event->eventDetectorPattern, EVENT_DETECTOR_TOF)) {
301 /* check event type */
302 if (event->eventType != PHYSICS_EVENT) {
303 printf("not a physics event: %d\n", event->eventType);
307 /* increment number of physics events */
309 if (!inhibitCollection) nCollectedPhysicsEvents++;
315 /* create and setup raw reader */
316 AliRawReader *rawReader = new AliRawReaderDate((void *)event);
318 rawReader->Select("TOF", 0, AliDAQ::NumberOfDdls("TOF") - 1);
319 /* setup raw stream */
320 rawStream->SetRawReader(rawReader);
322 /* loop over DDLs - rawReader->ReadHeader() */
323 while (rawReader->ReadHeader()) {
325 /* read equipment data */
326 dataSize = rawReader->GetDataSize();
327 data = new UChar_t[dataSize];
328 if (!rawReader->ReadNext(data, dataSize)){
334 dataWords = dataSize / 4;
335 decoder->Decode((UInt_t *)data, dataWords);
338 /* read equipment info */
339 currentDDL = rawReader->GetDDLID();
340 currentCDH = rawReader->GetDataHeader();
341 currentMiniEventID = currentCDH->GetMiniEventID();
342 currentEventID1 = currentCDH->GetEventID1();
344 /* read decoder summary data */
345 decodersd = decoder->GetDecoderSummaryData();
347 /* check DRM header/trailer */
348 drmsd = decodersd->GetDRMSummaryData();
349 if (!drmsd->GetHeader() || !drmsd->GetTrailer()) continue;
352 currentL0BCID = drmsd->GetL0BCID();
354 /* loop over TRM to get hits */
355 for (Int_t itrm = 0; itrm < 10; itrm++) {
356 trmsd = drmsd->GetTRMSummaryData(itrm);
357 trmIndex = itrm + 10 * currentDDL;
360 /* check header/trailer */
361 if (!trmsd->GetHeader() || !trmsd->GetTrailer()) continue;
363 #if READOUT_INFO_HISTO
365 hTRMData->Fill(trmIndex);
366 /* fill TRM empty event */
367 if (trmsd->GetEBit() != 0) {
368 hTRMEmptyEvent->Fill(trmIndex);
371 /* fill TRM bad event counter */
372 if (trmsd->GetEventCounter() != drmsd->GetLocalEventCounter()) {
373 hTRMBadEventCounter->Fill(trmIndex);
376 /* fill TRM bad CRC */
377 if (trmsd->GetEventCRC() != trmsd->GetDecoderCRC()) {
378 hTRMBadCRC->Fill(trmIndex);
382 /* check bad condition and skip TRM */
383 if ( trmsd->GetEBit() != 0 ||
384 trmsd->GetEventCounter() != drmsd->GetLocalEventCounter() ||
385 trmsd->GetEventCRC() != trmsd->GetDecoderCRC() ) continue;
388 /* loop over chains */
389 for (Int_t ichain = 0; ichain < 2; ichain++) {
390 chainsd = trmsd->GetChainSummaryData(ichain);
391 chainIndex = ichain + 2 * itrm + 20 * currentDDL;
394 /* check header/trailer */
395 if (!chainsd->GetHeader() || !chainsd->GetTrailer()) continue;
396 currentBunchID = chainsd->GetBunchID();
397 hitBuffer = chainsd->GetTDCPackedHitBuffer();
398 errorBuffer = chainsd->GetTDCErrorBuffer();
400 #if READOUT_INFO_HISTO
401 /* fill chain data */
402 hChainData->Fill(chainIndex);
403 /* check chain bad status */
404 if (chainsd->GetStatus() != 0) {
405 hChainBadStatus->Fill(chainIndex);
408 /* check chain bad event counter */
409 if (chainsd->GetEventCounter() != drmsd->GetLocalEventCounter()) {
410 hChainBadEventCounter->Fill(chainIndex);
413 /* fill TDC error frequency histo */
414 for (Int_t ierr = 0; ierr < errorBuffer->GetEntries(); ierr++) {
415 error = errorBuffer->GetError(ierr);
416 tdc = error->GetTDCID();
417 tdcIndex = tdc + 15 * ichain + 30 * itrm + 300 * currentDDL;
418 hTDCError->Fill(tdcIndex);
419 errorFlags = error->GetErrorFlags();
420 for (Int_t ierflg = 0; ierflg < 15; ierflg++)
421 if (errorFlags & (1 << ierflg))
422 hTDCErrorFlags->Fill(tdcIndex, ierflg);
425 /* check bad condition and skip chain */
426 if ( chainsd->GetStatus() != 0 ||
427 chainsd->GetEventCounter() != drmsd->GetLocalEventCounter() ) continue;
431 * CHAIN READOUT EFFICIENCY
434 /* compute number of available channels removing TDCs in error */
435 chainEff = (120. - 8. * errorBuffer->GetEntries()) / 120.;
436 /* fill chain readout efficiency histo */
437 if (!skipTRM && !skipChain)
438 hChainEfficiency->Fill(chainIndex, chainEff);
444 /* check inhibit collection */
445 if (inhibitCollection) continue;
447 /* loop over hits in buffer */
448 for (Int_t ihit = 0; ihit < hitBuffer->GetEntries(); ihit++) {
451 hit = hitBuffer->GetHit(ihit);
453 /* get channel info */
455 slot = trmsd->GetSlotID();
457 chain = chainsd->GetChain();
458 tdc = hit->GetTDCID();
459 channel = hit->GetChan();
461 rawStream->EquipmentId2VolumeId(ddl, slot, chain, tdc, channel, det);
465 /* check valid index */
466 if (det[0] < 0 || det[0] > 17 ||
467 det[1] < 0 || det[1] > 5 ||
468 det[2] < 0 || det[2] > 18 ||
469 det[3] < 0 || det[3] > 1 ||
470 det[4] < 0 || det[4] > 47) continue;
471 index = AliTOFGeometry::GetIndex(det);
473 /* check noise flag */
474 if (noiseFlag[index]) continue;
475 /* increment number of channel hits and total hits */
478 /* get signal info */
479 timebin = hit->GetHitTime();
480 totbin = hit->GetTOTWidth();
481 deltaBC = currentBunchID - currentEventID1;
482 l0l1latency = currentMiniEventID - currentL0BCID;
483 /* set hit field data */
484 hitField->SetIndex(index);
485 hitField->SetTimeBin(timebin);
486 hitField->SetTOTBin(totbin);
487 hitField->SetDeltaBC(deltaBC);
488 hitField->SetL0L1Latency(l0l1latency);
492 } /* end of loop over hits in buffer */
493 } /* end of loop over chains */
494 } /* end of loop over TRMs */
495 } /* end of loop over DDLs - rawReader->ReadHeader() */
497 /* delete raw reader */
502 } /* end of loop over events */
504 /* final noise check */
505 noiseHitThreshold = noiseThreshold * nCollectedPhysicsEvents;
506 printf("final noise check after collectiong %d events: threshold is %f hits\n", nCollectedPhysicsEvents, noiseHitThreshold);
507 /* loop over all channels */
508 for (Int_t ich = 0; ich < nChannels; ich++) {
510 if (nChHits[ich] < minNoiseHits || noiseFlag[ich] || nChHits[ich] < noiseHitThreshold) continue;
511 printf("channel %d tagged as noisy (%d hits): disabled\n", ich, nChHits[ich]);
512 noiseFlag[ich] = kTRUE;
513 totHits -= nChHits[ich];
514 } /* end of loop over all channels */
516 /* copy hits into output tree from temp tree */
517 printf("copy hits from temporary tree into output tree\n");
518 printf("temporary tree contains %d hits\n", (Int_t)tempTree->GetEntries());
519 for (Int_t ihit = 0; ihit < tempTree->GetEntries(); ihit++) {
521 tempTree->GetEntry(ihit);
522 /* check noise flag */
523 if (noiseFlag[hitField->GetIndex()]) continue;
524 /* fill output tree */
526 } /* end of copy hits into output tree from temp tree */
527 printf("output tree contains %d hits\n", (Int_t)outTree->GetEntries());
529 /* write output tree on HITS file */
532 fileOutHits->Close();
533 /* export file to FXS */
534 if (daqDA_FES_storeFile(FILE_HITS, "HITS"))
537 #if READOUT_INFO_HISTO
539 hTRMEmptyEvent->Sumw2();
540 hTRMBadEventCounter->Sumw2();
544 hChainBadStatus->Sumw2();
545 hChainBadEventCounter->Sumw2();
548 hTDCErrorFlags->Sumw2();
551 if (nPhysicsEvents > 0) {
552 hTRMEmptyEvent->Divide(hTRMData);
553 hTRMBadEventCounter->Divide(hTRMData);
554 hTRMBadCRC->Divide(hTRMData);
555 hTRMData->Scale(1. / nPhysicsEvents);
557 hChainBadStatus->Divide(hChainData);
558 hChainBadEventCounter->Divide(hChainData);
559 hChainData->Scale(1. / nPhysicsEvents);
561 hTDCError->Scale(1. / nPhysicsEvents);
562 hTDCErrorFlags->Scale(1. / nPhysicsEvents);
566 /* scale chain efficiency by number of physics events */
567 printf("found %d physics events\n", nPhysicsEvents);
568 hChainEfficiency->Sumw2();
569 if (nPhysicsEvents > 0) hChainEfficiency->Scale(1. / (nPhysicsEvents));
571 /* write efficiency histo on READOUT file */
572 fileOutReadout->cd();
573 #if READOUT_INFO_HISTO
575 hTRMEmptyEvent->Write();
576 hTRMBadEventCounter->Write();
580 hChainBadStatus->Write();
581 hChainBadEventCounter->Write();
584 hTDCErrorFlags->Write();
586 hChainEfficiency->Write();
587 fileOutReadout->Close();
588 /* export file to FXS */
589 if (daqDA_FES_storeFile(FILE_READOUT, "READOUT"))