NCFS-Pack
A generic (astro)particle physics analysis framework
 
Loading...
Searching...
No Matches
NcDataStreamStats.cxx
Go to the documentation of this file.
1
31
33
193
194#include "NcDataStreamStats.h"
195#include "Riostream.h"
196
197ClassImp(NcDataStreamStats); // Class implementation to enable ROOT I/O
198
200NcDataStreamStats::NcDataStreamStats(const char* name,const char* title) : NcTaggingBase(name,title)
201{
207
208 fData=0;
209 fBranchname="none";
210 fMaxevt=0;
211 fPfreq=0;
212}
213
215{
221
222 if (fData)
223 {
224 delete fData;
225 fData=0;
226 }
227}
228
230{
236
237 fData=0;
238 if (q.fData) fData=(TChain*)(q.fData->Clone());
241 fPfreq=q.fPfreq;
242}
243
244void NcDataStreamStats::Exec(Option_t* opt)
245{
252
253 if (!fData)
254 {
255 cout << endl;
256 cout << " *NcDataStreamStats::Exec* No input data provided." << endl;
257 return;
258 }
259
260 if (fDevname=="")
261 {
262 cout << endl;
263 cout << " *NcDataStreamStats::Exec* No device name for the event tags provided." << endl;
264 return;
265 }
266
267 cout << endl;
268 cout << " *** Device and indicator identifiers ***" << endl;
269 cout << " Tag device name : " << fDevname << endl;
270 cout << " Pass indicator : " << fPassname << endl;
271 cout << " Write indicator : " << fWritename << endl;
272
273 // Branch in the tree for the event input
274 fData->SetBranchAddress(fBranchname.Data(),&fEvt);
275
276 Int_t nen=(int)fData->GetEntries();
277 cout << endl;
278 cout << " Number of entries available : " << nen << endl;
279 cout << endl;
280
281 if (fMaxevt && fMaxevt<nen) nen=fMaxevt;
282 cout << " *** Number of entries to be processed : " << nen << endl;
283
284 Int_t nact=0;
285 Int_t ndeact=0;
286 if (fAct) nact=fAct->GetEntries();
287 if (fDeact) ndeact=fDeact->GetEntries();
288 for (Int_t i=0; i<nact; i++)
289 {
290 if (!i)
291 {
292 cout << endl;
293 cout << " === Tag names (*=wildcard) that are activated by the user for re-tagged event sample studies ===" << endl;
294 cout << " The non-activated tags are flagged as \"dead\" in the combined \"Passing*Writing\" listing." << endl;
295 cout << " However, they are still shown in the corresponding tag matrix to identify the missed tags." << endl;
296 cout << endl;
297 }
298 TObjString* tagx=(TObjString*)fAct->At(i);
299 if (!tagx) continue;
300
301 cout << " ... *" << tagx->GetString() << "*" << endl;
302 }
303 for (Int_t i=0; i<ndeact; i++)
304 {
305 if (!i)
306 {
307 cout << endl;
308 cout << " === Tag names (*=wildcard) that are de-activated by the user for re-tagged background reduction studies ===" << endl;
309 cout << " The de-activated tags are flagged as \"dead\" in the combined \"Passing*Writing\" listing." << endl;
310 cout << " However, they are still shown in the corresponding tag matrix to identify the missed tags." << endl;
311 cout << endl;
312 }
313 TObjString* tagx=(TObjString*)fDeact->At(i);
314 if (!tagx) continue;
315
316 cout << " ... *" << tagx->GetString() << "*" << endl;
317 }
318 cout << endl;
319
320 fNevt=0; // Number of events that were tagged
321 fNevtComb=0; // Number of user reduced events via selected re-tagging
322
323 TString title;
324 title=fPassname;
325 if (title=="*") title="Passing";
326 title+=" statistics";
327 fPass.SetNameTitle(fDevname.Data(),title.Data());
328 fApass.Set(fMaxtag);
329 fMpass.ResizeTo(fMaxtag,fMaxtag);
330 fMpass.Zero();
331 title=fWritename;
332 if (title=="*") title="Writing";
333 title+=" statistics";
334 fWrites.SetNameTitle(fDevname.Data(),title.Data());
335 fAwrites.Set(fMaxtag);
336 fMwrites.ResizeTo(fMaxtag,fMaxtag);
337 fMwrites.Zero();
338 title="Combined ";
339 if (nact || ndeact) title="User reduced combined ";
340 if (fPassname!="*" && fWritename!="*")
341 {
342 title+=fPassname;
343 title+="*";
344 title+=fWritename;
345 }
346 else
347 {
348 title+="Passing*Writing";
349 }
350 title+=" statistics";
351 fCombis.SetNameTitle(fDevname.Data(),title.Data());
352 fAcombis.Set(fMaxtag);
353 fMcombis.ResizeTo(fMaxtag,fMaxtag);
354 fMcombis.Zero();
355
356 Int_t select=0;
357 Int_t ntags=0;
358 Int_t jrun=0;
359 Int_t jevt=0;
360 Int_t perc=0;
361 TString name;
362 Int_t ipass=0;
363 Int_t iwrite=0;
364 Int_t combflag=0;
365 Int_t idx=0;
366 Int_t ival1=0;
367 Int_t ival2=0;
368 Int_t ival3=0;
369 Int_t ival4=0;
370
371 TString namex;
372 Int_t jdeact=0;
373
374 for (Int_t ient=0; ient<nen; ient++)
375 {
376 fData->GetEntry(ient);
377 if (!fEvt) continue;
378
379 // Do not process rejected events
380 select=fEvt->GetSelectLevel();
381 if (select<0) continue;
382
383 ntags=0;
384 NcDevice* tagdev=(NcDevice*)fEvt->GetDevice(fDevname);
385 if (!tagdev) continue;
386
387 ntags=tagdev->GetNhits();
388 if (ntags>fMaxtag) ntags=fMaxtag;
389
390 fApass.Reset();
391 fAwrites.Reset();
392 fAcombis.Reset();
393
394 jrun=fEvt->GetRunNumber();
395 jevt=fEvt->GetEventNumber();
396
397 // Determine the first and last recorded event
398 if (!fEvtFirst) fEvtFirst=new NcEvent(*fEvt);
399 if (!fEvtLast) fEvtLast=new NcEvent(*fEvt);
400 if (fEvtFirst->GetDifference(fEvt,"s")<0)
401 {
402 delete fEvtFirst;
403 fEvtFirst=new NcEvent(*fEvt);
404 }
405 if (fEvtLast->GetDifference(fEvt,"s")>0)
406 {
407 delete fEvtLast;
408 fEvtLast=new NcEvent(*fEvt);
409 }
410
411 fNevt++;
412
413 combflag=0;
414 for (Int_t itag=1; itag<=ntags; itag++)
415 {
416 NcSignal* sx=tagdev->GetHit(itag);
417 if (!sx) continue;
418 name=sx->GetName();
419 if (sx->GetSlotIndex(fPassname))
420 {
421 ipass=int(sx->GetSignal(fPassname)+0.1); // Flag to indicate if the tag passing criteria are satisfied (1) or not (0)
422 }
423 else
424 {
425 ipass=1;
426 }
427 if (sx->GetSlotIndex(fWritename))
428 {
429 iwrite=int(sx->GetSignal(fWritename)+0.1); // Flag to indicate if this tag would write the event (1) or not (0)
430 }
431 else
432 {
433 iwrite=1;
434 }
435
436 // Update stats for this tag name
437 fPass.AddNamedSlot(name);
438 fWrites.AddNamedSlot(name);
439 fCombis.AddNamedSlot(name);
440 fPass.AddSignal(ipass,name);
441 idx=fPass.GetSlotIndex(name);
442 if (idx && idx<=fMaxtag) fApass.AddAt(ipass,idx-1);
443 fWrites.AddSignal(iwrite,name);
444 idx=fWrites.GetSlotIndex(name);
445 if (idx && idx<=fMaxtag) fAwrites.AddAt(iwrite,idx-1);
446 fCombis.AddSignal(ipass*iwrite,name);
447 idx=fCombis.GetSlotIndex(name);
448 if (idx && idx<=fMaxtag) fAcombis.AddAt(ipass*iwrite,idx-1);
449
451 // (De)activate some tags for the combined pass*write statistics //
452 // which will enable to study event samples or background reduction //
454
455 namex="";
456 jdeact=0;
457 if (nact) jdeact=1; // The user has specified the tags to be activated
458
459 // Look for a user selection of activated tags
460 for (Int_t i=0; i<nact; i++)
461 {
462 TObjString* sox=(TObjString*)fAct->At(i);
463 if (!sox) continue;
464 namex=sox->GetString();
465 if (name.Contains(namex.Data()))
466 {
467 jdeact=0;
468 break;
469 }
470 }
471 // Look for a user selection of de-activated tags
472 // This may de-activate a previously activated tag
473 for (Int_t i=0; i<ndeact; i++)
474 {
475 TObjString* sox=(TObjString*)fDeact->At(i);
476 if (!sox) continue;
477 namex=sox->GetString();
478 if (name.Contains(namex.Data()))
479 {
480 jdeact=1;
481 break;
482 }
483 }
484
485 if (jdeact)
486 {
487 fCombis.SetDead(name);
488 }
489 else
490 {
491 if (ipass*iwrite) combflag=1;
492 }
493 } // End of tag loop
494
495 if (combflag) fNevtComb++;
496
497 // Update the various tag matrices for this event
498 ntags=fPass.GetNslots();
499 if (ntags>fMaxtag) ntags=fMaxtag;
500
501 for (Int_t irow=0; irow<ntags; irow++)
502 {
503 ival1=fApass.At(irow);
504 ival2=fAwrites.At(irow);
505 ival3=fAcombis.At(irow);
506 if (!ival1 && !ival2 && !ival3) continue;
507 for (Int_t icol=0; icol<ntags; icol++)
508 {
509 ival4=fApass.At(icol);
510 if (ival1 && ival4) fMpass(irow,icol)+=float(ival4);
511 ival4=fAwrites.At(icol);
512 if (ival2 && ival4) fMwrites(irow,icol)+=float(ival4);
513 ival4=fAcombis.At(icol);
514 if (ival3 && ival4) fMcombis(irow,icol)+=float(ival4);
515 }
516 }
517
518 if (fPfreq>0 && (!(ient%fPfreq) || (ient+1)==nen))
519 {
520 perc=100*(ient+1)/nen;
521 cout << " *** Processed input entry : " << ient << " run : " << jrun << " event : " << jevt << " (" << perc << "%)" << endl;
522 }
523
524 } // End of event loop
525
526 // List the final statistics overview
528}
529
530void NcDataStreamStats::AddInputFile(TString file,TString tree,TString branch)
531{
552
553 // Expand the path name of the provided input file
554 file=gSystem->ExpandPathName(file.Data());
555
556 // Initialise the master data Chain and the Branch name if needed
557 if (!fData)
558 {
559 fData=new TChain("Data");
560 fBranchname=branch;
561 }
562
563 TChain input(tree.Data());
564 input.Add(file.Data());
565
566 // Add the file(s) to the master data chain
567 fData->Add(&input);
568}
569
571{
578
579 fMaxevt=n;
580}
581
583{
590
591 fPfreq=m;
592}
593
594void NcDataStreamStats::ListInputFiles(Option_t* opt) const
595{
603
604 if (fData)
605 {
606 cout << endl;
607 fData->Print(opt);
608 }
609}
610
611TObject* NcDataStreamStats::Clone(const char* name) const
612{
621
622 NcDataStreamStats* fstat=new NcDataStreamStats(*this);
623 if (name)
624 {
625 if (strlen(name)) fstat->SetName(name);
626 }
627 return fstat;
628}
629
ClassImp(NcDataStreamStats)
Int_t GetSlotIndex(TString name, Int_t opt=0) const
Provide event classification tag statistics.
virtual TObject * Clone(const char *name="") const
void SetPrintFrequency(Int_t m)
void ListInputFiles(Option_t *opt="") const
virtual void Exec(Option_t *opt)
NcDataStreamStats(const char *name="NcDataStreamStats", const char *title="Event tag statistics")
void AddInputFile(TString file, TString tree, TString branch)
Signal (Hit) handling of a generic device.
Definition NcDevice.h:14
Int_t GetNhits() const
Definition NcDevice.cxx:437
NcSignal * GetHit(Int_t j) const
Definition NcDevice.cxx:489
Creation and investigation of an NCFS generic event structure.
Definition NcEvent.h:15
Generic handling of (extrapolated) detector signals.
Definition NcSignal.h:23
virtual Float_t GetSignal(Int_t j=1, Int_t mode=0) const
Definition NcSignal.cxx:651
TMatrixF fMpass
NcEvent * fEvtLast
TObjArray * fDeact
TObjArray * fAct
NcEvent * fEvt
NcSignal fWrites
TString fWritename
NcSignal fCombis
NcTaggingBase(const char *name="NcTaggingBase", const char *title="Base class for event tag processing")
TMatrixF fMwrites
NcEvent * fEvtFirst
TMatrixF fMcombis
TString fPassname