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"
29 #include "AliTOFRawStream.h"
30 #include "AliRawReaderDate.h"
31 #include "AliRawReader.h"
33 #include "AliTOFHitData.h"
34 #include "AliTOFHitDataBuffer.h"
35 #include "AliTOFDaConfigHandler.h"
36 #include "AliTOFHitField.h"
38 #include "AliTOFGeometry.h"
48 #include "TPluginManager.h"
49 #include "TSAXParser.h"
54 1- monitoring data source
57 main(int argc, char **argv)
60 /* magic line from Rene */
61 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
68 /* log start of process */
69 printf("TOF DA started\n");
71 /* check that we got some arguments = list of files */
73 printf("Wrong number of arguments\n");
81 /* retrieve config file */
82 int getConfigFile = daqDA_DB_getFile("TOFPhysicsConfig.xml","TOFPhysicsConfig.xml");
83 if (getConfigFile != 0){
84 printf("Failed to retrieve config file from DB! returning...\n");
87 /* parse config file */
88 AliTOFDaConfigHandler* tofHandler = new AliTOFDaConfigHandler();
89 TSAXParser *parser = new TSAXParser();
90 parser->ConnectToHandler("AliTOFDaConfigHandler", tofHandler);
91 if (parser->ParseFile("./TOFPhysicsConfig.xml") != 0) {
92 printf("Failed parsing config file! retunring... \n");
95 /* setup config params */
96 Int_t meanMultiplicity = tofHandler->GetMeanMultiplicity(); /* average expected TOF multiplicity */
97 Int_t maxHits = tofHandler->GetMaxHits(); /* max number of hits to be collected */
98 printf("current settings:\n");
99 printf(" - meanMultiplicity = %d\n", meanMultiplicity);
100 printf(" - maxHits = %d\n", maxHits);
102 const Int_t nChannels = 157248;
103 Int_t noiseCheckTrigger = 10; /* first noise check after 10 events */
104 Float_t meanChannelRate = (Float_t)meanMultiplicity / (Float_t)nChannels; /* average expected channel rate (hits/event) */
105 Float_t noiseThreshold = 10. * meanChannelRate; /* noise threshold (hits/event) */
106 Int_t minNoiseHits = 10; /* min number of channel hits to check noise */
107 /* counters and flags */
108 Int_t nEvents, totHits;
109 Int_t nChHits[nChannels];
110 Bool_t noiseFlag[nChannels];
112 Int_t nhits, ddl, slot, trm, chain, tdc, channel, index, timebin, totbin, deltaBC, l0l1latency, det[5], dummy;
113 Float_t noiseHitThreshold;
119 /* init counters and flags */
122 for (Int_t ich = 0; ich < nChannels; ich++) {
127 /* TOF raw data handling */
128 AliTOFRawStream *rawStream = new AliTOFRawStream();
129 AliTOFHitDataBuffer *pdb = NULL;
130 AliTOFHitData *hit = NULL;
132 /* open output file */
133 TFile *fileOut = new TFile(FILE_HITS, "RECREATE");
134 /* create hit field data structure */
135 AliTOFHitField *hitField = new AliTOFHitField();
136 /* create temporary tree */
137 TTree *tempTree = new TTree("tempTree", "temporary tree");
138 tempTree->Branch("hit", "AliTOFHitField", &hitField);
139 /* create output tree */
140 TTree *outTree = new TTree("hitTree", "hit tree");
141 outTree->Branch("hit", "AliTOFHitField", &hitField);
147 AliLog::SetGlobalLogLevel(AliLog::kFatal);
148 struct eventHeaderStruct *event;
150 /* define data source : this is argument 1 */
151 ret = monitorSetDataSource(argv[1]);
153 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(ret));
156 /* declare monitoring program */
157 ret = monitorDeclareMp("tofDA");
159 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(ret));
162 /* define wait event timeout - 1s max */
164 monitorSetNoWaitNetworkTimeout(1000);
166 /* loop over events */
169 /* check shutdown condition */
170 if (daqDA_checkShutdown()) break;
176 /* check number of events and check noise */
177 if (nEvents >= noiseCheckTrigger || totHits >= maxHits) {
178 noiseHitThreshold = noiseThreshold * nEvents;
179 printf("noise check triggered after %d events: threshold is %f hits\n", nEvents, noiseHitThreshold);
180 /* loop over all channels */
181 for (Int_t ich = 0; ich < nChannels; ich++) {
183 if (nChHits[ich] < minNoiseHits || noiseFlag[ich] || nChHits[ich] < noiseHitThreshold) continue;
184 printf("channel %d tagged as noisy (%d hits): disabled\n", ich, nChHits[ich]);
185 noiseFlag[ich] = kTRUE;
186 totHits -= nChHits[ich];
187 } /* end of loop over all channels */
188 /* set new noise check trigger value */
189 noiseCheckTrigger *= 10;
190 } /* end of noise check */
192 /* break loop when maximum number of hits exceeded */
193 if (totHits >= maxHits) {
194 printf("maximum number of hits exceeded (%d): stop hit collection\n", maxHits);
202 /* get next event (blocking call until timeout) */
203 ret = monitorGetEventDynamic((void **)&event);
204 if (ret == MON_ERR_EOF) {
205 printf ("End of File detected\n");
206 break; /* end of monitoring file has been reached */
209 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(ret));
212 /* retry if got no event */
213 if (event==NULL) continue;
214 /* check event type */
215 if (event->eventType != PHYSICS_EVENT) continue;
216 /* increment number of events */
223 /* create raw reader */
224 AliRawReader *rawReader = new AliRawReaderDate((void *)event);
225 /* setup raw stream */
226 rawStream->SetRawReader(rawReader);
228 rawStream->ResetBuffers();
230 rawStream->DecodeDDL(0, AliDAQ::NumberOfDdls("TOF") - 1, 0);
237 for (Int_t iddl = 0; iddl < AliDAQ::NumberOfDdls("TOF"); iddl++) {
238 /* get packed-data buffer */
239 pdb = rawStream->GetPackedDataBuffer(iddl);
240 nhits = pdb->GetEntries();
241 /* loop over hits in buffer */
242 for (Int_t ihit = 0; ihit < nhits; ihit++) {
244 hit = pdb->GetHit(ihit);
245 /* get channel info */
247 slot = hit->GetSlotID();
249 chain = hit->GetChain();
251 channel = hit->GetChan();
253 rawStream->EquipmentId2VolumeId(ddl, slot, chain, tdc, channel, det);
257 /* check valid index */
258 if (det[0] < 0 || det[0] > 17 ||
259 det[1] < 0 || det[1] > 5 ||
260 det[2] < 0 || det[2] > 18 ||
261 det[3] < 0 || det[3] > 1 ||
262 det[4] < 0 || det[4] > 47) continue;
263 index = AliTOFGeometry::GetIndex(det);
264 /* check noise flag */
265 if (noiseFlag[index]) continue;
266 /* increment number of channel hits and total hits */
269 /* get signal info */
270 timebin = hit->GetTimeBin();
271 totbin = hit->GetTOTBin();
272 deltaBC = hit->GetDeltaBunchID();
273 l0l1latency = hit->GetL0L1Latency();
274 /* set hit field data */
275 hitField->SetIndex(index);
276 hitField->SetTimeBin(timebin);
277 hitField->SetTOTBin(totbin);
278 hitField->SetDeltaBC(deltaBC);
279 hitField->SetL0L1Latency(l0l1latency);
282 } /* end of loop over hits in buffer */
283 } /* end of loop over DDLs */
285 /* delete raw reader */
288 } /* end of loop over events */
290 /* final noise check */
291 noiseHitThreshold = noiseThreshold * nEvents;
292 printf("final noise check after %d events: threshold is %f hits\n", nEvents, noiseHitThreshold);
293 /* loop over all channels */
294 for (Int_t ich = 0; ich < nChannels; ich++) {
296 if (nChHits[ich] < minNoiseHits || noiseFlag[ich] || nChHits[ich] < noiseHitThreshold) continue;
297 printf("channel %d tagged as noisy (%d hits): disabled\n", ich, nChHits[ich]);
298 noiseFlag[ich] = kTRUE;
299 totHits -= nChHits[ich];
300 } /* end of loop over all channels */
302 /* copy hits into output tree from temp tree */
303 printf("copy hits from temporary tree into output tree\n");
304 printf("temporary tree contains %d hits\n", (Int_t)tempTree->GetEntries());
305 for (Int_t ihit = 0; ihit < tempTree->GetEntries(); ihit++) {
307 tempTree->GetEntry(ihit);
308 /* check noise flag */
309 if (noiseFlag[hitField->GetIndex()]) continue;
310 /* fill output tree */
312 } /* end of copy hits into output tree from temp tree */
313 printf("output tree contains %d hits\n", (Int_t)outTree->GetEntries());
315 /* write output tree on file */
320 /* export file to FXS */
321 if (daqDA_FES_storeFile(FILE_HITS, "HITS"))