<commit_before>#include <algorithm>
#include <map>
#include <vector>
#include <TArrayD.h>
#include <TGrid.h>
#include <THashList.h>
#include <THistManager.h>
#include <TLinearBinning.h>
#include <TObjArray.h>
#include <TParameter.h>

#include "AliEMCALGeometry.h"
#include "AliEmcalCellMonitorTask.h"
#include "AliInputEventHandler.h"
#include "AliLog.h"
#include "AliOADBContainer.h"
#include "AliVCaloCells.h"
#include "AliVEvent.h"

/// \cond CLASSIMP
ClassImp(AliEmcalCellMonitorTask)
/// \endcond

AliEmcalCellMonitorTask::AliEmcalCellMonitorTask() :
   AliAnalysisTaskSE(),
   fHistManager(nullptr),
   fGeometry(nullptr),
   fMinCellAmplitude(0),
   fRequestTrigger(AliVEvent::kAnyINT),
   fBadChannelContainer(""),
   fTriggerString(""),
   fNumberOfCells(12288),
   fOldRun(-1),
   fMaskedCells()
{

}

AliEmcalCellMonitorTask::AliEmcalCellMonitorTask(const char *name) :
   AliAnalysisTaskSE(name),
   fHistManager(nullptr),
   fGeometry(nullptr),
   fMinCellAmplitude(0),
   fRequestTrigger(AliVEvent::kAnyINT),
   fBadChannelContainer(""),
   fTriggerString(""),
   fNumberOfCells(12288),
   fOldRun(-1),
   fMaskedCells()
{
  DefineOutput(1, TList::Class());
}

AliEmcalCellMonitorTask::~AliEmcalCellMonitorTask() {
  if(fGeometry) delete fGeometry;
}

void AliEmcalCellMonitorTask::UserCreateOutputObjects(){
  fHistManager = new THistManager("EMCALCellMonitor");

  fHistManager->CreateTH1("cellMasking", "Monitoring for masked cells", TLinearBinning(fNumberOfCells, -0.5, fNumberOfCells - 0.5));
  fHistManager->CreateTH1("cellFrequency", "Frequency of cell firing", TLinearBinning(fNumberOfCells, -0.5, fNumberOfCells - 0.5));
  fHistManager->CreateTH2("cellAmplitude", "Energy distribution per cell", TLinearBinning(fNumberOfCells, -0.5, fNumberOfCells - 0.5), AliEmcalCellMonitorAmplitudeBinning());
  fHistManager->CreateTH2("cellAmplitudeCut", "Energy distribution per cell (after energy cut)", TLinearBinning(fNumberOfCells, -0.5, fNumberOfCells - 0.5), AliEmcalCellMonitorAmplitudeBinning());
  fHistManager->CreateTH2("cellTime", "Time distribution per cell", fNumberOfCells, -0.5, fNumberOfCells - 0.5, 200, -1e-6, 1e-6);
  fHistManager->CreateTH2("cellTimeOutlier", "Outlier time distribution per cell", fNumberOfCells, -0.5, fNumberOfCells - 0.5, 100, 1e-6, 5e-5);
  fHistManager->CreateTH2("cellTimeMain", "Time distribution per cell for the main bunch", fNumberOfCells, -0.5, fNumberOfCells - 0.5, 150, -50e-9, 100e-9);
  for(int ism = 0; ism < 20; ++ism){
    fHistManager->CreateTH2(Form("cellAmpSM%d", ism), Form("Integrated cell amplitudes for SM %d; col; row", ism), 48, -0.5, 47.5, 24, -0.5, 23.5);
    fHistManager->CreateTH2(Form("cellCountSM%d", ism), Form("Count rate per cell for SM %d; col; row", ism), 48, -0.5, 47.5, 24, -0.5, 23.5);
  }

  for(int ism = 0; ism < 20; ++ism){
    fHistManager->CreateTH2(Form("cellAmpTimeCorrSM%d", ism), Form("Correlation between cell amplitude and time in Supermodule %d", ism), 1000, -5e-7, 5e-7, 1000, 0., 100.);
  }

  PostData(1, fHistManager->GetListOfHistograms());
}

void AliEmcalCellMonitorTask::UserExec(Option_t *){
  if(!fGeometry) fGeometry = AliEMCALGeometry::GetInstanceFromRunNumber(fInputEvent->GetRunNumber());

  // Run change
  if(InputEvent()->GetRunNumber() != fOldRun){
    if(fBadChannelContainer.Length()) LoadCellMasking();

    for(auto cellID : fMaskedCells) fHistManager->FillTH1("cellMasking", cellID);
    fOldRun = InputEvent()->GetRunNumber();
  }

  // Check trigger
  if(!(fInputHandler->IsEventSelected() & fRequestTrigger)) return;
  if(fTriggerString.Length()){
    if(!TString(InputEvent()->GetFiredTriggerClasses()).Contains(fTriggerString)) return;
  }

  AliVCaloCells *emcalcells = fInputEvent->GetEMCALCells();

  // input data
  Short_t cellNumber;
  Double_t amplitude, celltime, efrac;
  Int_t mclabel;

  Int_t sm, mod, meta, mphi, ieta, iphi;
  for(int icell = 0; icell < emcalcells->GetNumberOfCells(); icell++){
    emcalcells->GetCell(icell, cellNumber, amplitude, celltime, mclabel, efrac);
    if(IsCellMasked(cellNumber)) continue;
    fHistManager->FillTH2("cellAmplitude", cellNumber, amplitude);
    if(amplitude < fMinCellAmplitude) continue;
    fHistManager->FillTH1("cellAmplitudeCut", cellNumber, amplitude);
    fHistManager->FillTH1("cellFrequency", cellNumber);
    fHistManager->FillTH2("cellTime", cellNumber, celltime);
    if(celltime >= 1e-6) fHistManager->FillTH2("cellTimeOutlier", cellNumber, celltime);<commit_msg>Add simple event counter histogram<commit_after>#include <algorithm>
#include <map>
#include <vector>
#include <TArrayD.h>
#include <TGrid.h>
#include <THashList.h>
#include <THistManager.h>
#include <TLinearBinning.h>
#include <TObjArray.h>
#include <TParameter.h>

#include "AliEMCALGeometry.h"
#include "AliEmcalCellMonitorTask.h"
#include "AliInputEventHandler.h"
#include "AliLog.h"
#include "AliOADBContainer.h"
#include "AliVCaloCells.h"
#include "AliVEvent.h"

/// \cond CLASSIMP
ClassImp(AliEmcalCellMonitorTask)
/// \endcond

AliEmcalCellMonitorTask::AliEmcalCellMonitorTask() :
   AliAnalysisTaskSE(),
   fHistManager(nullptr),
   fGeometry(nullptr),
   fMinCellAmplitude(0),
   fRequestTrigger(AliVEvent::kAnyINT),
   fBadChannelContainer(""),
   fTriggerString(""),
   fNumberOfCells(12288),
   fOldRun(-1),
   fMaskedCells()
{

}

AliEmcalCellMonitorTask::AliEmcalCellMonitorTask(const char *name) :
   AliAnalysisTaskSE(name),
   fHistManager(nullptr),
   fGeometry(nullptr),
   fMinCellAmplitude(0),
   fRequestTrigger(AliVEvent::kAnyINT),
   fBadChannelContainer(""),
   fTriggerString(""),
   fNumberOfCells(12288),
   fOldRun(-1),
   fMaskedCells()
{
  DefineOutput(1, TList::Class());
}

AliEmcalCellMonitorTask::~AliEmcalCellMonitorTask() {
  if(fGeometry) delete fGeometry;
}

void AliEmcalCellMonitorTask::UserCreateOutputObjects(){
  fHistManager = new THistManager("EMCALCellMonitor");

  fHistManager->CreateTH1("events", "Number of events", 1, 0.5, 1.5);
  fHistManager->CreateTH1("cellMasking", "Monitoring for masked cells", TLinearBinning(fNumberOfCells, -0.5, fNumberOfCells - 0.5));
  fHistManager->CreateTH1("cellFrequency", "Frequency of cell firing", TLinearBinning(fNumberOfCells, -0.5, fNumberOfCells - 0.5));
  fHistManager->CreateTH2("cellAmplitude", "Energy distribution per cell", TLinearBinning(fNumberOfCells, -0.5, fNumberOfCells - 0.5), AliEmcalCellMonitorAmplitudeBinning());
  fHistManager->CreateTH2("cellAmplitudeCut", "Energy distribution per cell (after energy cut)", TLinearBinning(fNumberOfCells, -0.5, fNumberOfCells - 0.5), AliEmcalCellMonitorAmplitudeBinning());
  fHistManager->CreateTH2("cellTime", "Time distribution per cell", fNumberOfCells, -0.5, fNumberOfCells - 0.5, 200, -1e-6, 1e-6);
  fHistManager->CreateTH2("cellTimeOutlier", "Outlier time distribution per cell", fNumberOfCells, -0.5, fNumberOfCells - 0.5, 100, 1e-6, 5e-5);
  fHistManager->CreateTH2("cellTimeMain", "Time distribution per cell for the main bunch", fNumberOfCells, -0.5, fNumberOfCells - 0.5, 150, -50e-9, 100e-9);
  for(int ism = 0; ism < 20; ++ism){
    fHistManager->CreateTH2(Form("cellAmpSM%d", ism), Form("Integrated cell amplitudes for SM %d; col; row", ism), 48, -0.5, 47.5, 24, -0.5, 23.5);
    fHistManager->CreateTH2(Form("cellCountSM%d", ism), Form("Count rate per cell for SM %d; col; row", ism), 48, -0.5, 47.5, 24, -0.5, 23.5);
  }

  for(int ism = 0; ism < 20; ++ism){
    fHistManager->CreateTH2(Form("cellAmpTimeCorrSM%d", ism), Form("Correlation between cell amplitude and time in Supermodule %d", ism), 1000, -5e-7, 5e-7, 1000, 0., 100.);
  }

  PostData(1, fHistManager->GetListOfHistograms());
}

void AliEmcalCellMonitorTask::UserExec(Option_t *){
  if(!fGeometry) fGeometry = AliEMCALGeometry::GetInstanceFromRunNumber(fInputEvent->GetRunNumber());

  // Run change
  if(InputEvent()->GetRunNumber() != fOldRun){
    if(fBadChannelContainer.Length()) LoadCellMasking();

    for(auto cellID : fMaskedCells) fHistManager->FillTH1("cellMasking", cellID);
    fOldRun = InputEvent()->GetRunNumber();
  }

  // Check trigger
  if(!(fInputHandler->IsEventSelected() & fRequestTrigger)) return;
  if(fTriggerString.Length()){
    if(!TString(InputEvent()->GetFiredTriggerClasses()).Contains(fTriggerString)) return;
  }

  fHistManager->FillTH1("events", 1);

  AliVCaloCells *emcalcells = fInputEvent->GetEMCALCells();

  // input data
  Short_t cellNumber;
  Double_t amplitude, celltime, efrac;
  Int_t mclabel;

  Int_t sm, mod, meta, mphi, ieta, iphi;
  for(int icell = 0; icell < emcalcells->GetNumberOfCells(); icell++){
    emcalcells->GetCell(icell, cellNumber, amplitude, celltime, mclabel, efrac);
    if(IsCellMasked(cellNumber)) continue;
    fHistManager->FillTH2("cellAmplitude", cellNumber, amplitude);
    if(amplitude < fMinCellAmplitude) continue;
    fHistManager->FillTH1("cellAmplitudeCut", cellNumber, amplitude);
    fHistManager->FillTH1("cellFrequency", cellNumber);
    fHistManager->FillTH2("cellTime", cellNumber, celltime);
    if(celltime >= 1e-6) fHistManager->FillTH2("cellTimeOutlier", cellNumber, celltime);
{'fraction_non_alphanumeric': 0.14905119152691967, 'fraction_numerical': 0.031112091791703444, 'mean_word_length': 5.851851851851852, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 77, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4145697', 'n_tokens_mistral': 3410, 'n_tokens_neox': 3177, 'n_words': 614}