15 #include <TClonesArray.h>
17 #include <THashList.h>
18 #include "AliAODCaloTrigger.h"
19 #include "AliEMCALGeometry.h"
22 #include "AliEMCALTriggerConstants.h"
23 #include "AliEMCALTriggerDataGrid.h"
24 #include "AliEMCALTriggerPatchInfo.h"
26 #include "AliVCaloCells.h"
27 #include "AliVCaloTrigger.h"
28 #include "AliVVZERO.h"
29 #include "THistManager.h"
44 const TString
AliEmcalTriggerMaker::fgkTriggerTypeNames[5] = {
"EJE",
"EGA",
"EL0",
"REJE",
"REGA"};
51 fCaloTriggersOutName(
"EmcalTriggers"),
52 fCaloTriggerSetupOutName(
"EmcalTriggersSetup"),
53 fV0InName(
"AliAODVZERO"),
54 fUseTriggerBitConfig(kNewConfig),
55 fTriggerBitConfig(NULL),
57 fCaloTriggerSetupOut(0),
58 fSimpleOfflineTriggers(0),
60 fPatchAmplitudes(NULL),
61 fPatchADCSimple(NULL),
66 fRejectOffAcceptancePatches(kFALSE),
85 fCaloTriggersOutName(
"EmcalTriggers"),
86 fCaloTriggerSetupOutName(
"EmcalTriggersSetup"),
87 fV0InName(
"AliAODVZERO"),
88 fUseTriggerBitConfig(kNewConfig),
89 fTriggerBitConfig(NULL),
91 fCaloTriggerSetupOut(0),
92 fSimpleOfflineTriggers(0),
94 fPatchAmplitudes(NULL),
95 fPatchADCSimple(NULL),
100 fRejectOffAcceptancePatches(kFALSE),
151 AliFatal(Form(
"%s: Container with same name %s already present. Aborting", GetName(),
fCaloTriggersOutName.Data()));
165 AliFatal(Form(
"%s: Container with same name %s already present. Aborting", GetName(),
fCaloTriggerSetupOutName.Data()));
171 fV0 = (AliVVZERO*)InputEvent()->FindListObject(
fV0InName);
176 int nrows =
fGeom->GetNTotalTRU() * 2;
177 std::cout <<
"Allocating channel grid with 48 columns in eta and " << nrows <<
" rows in phi" << std::endl;
202 fQAHistos =
new THistManager(
"TriggerQA");
203 const char *patchtypes[2] = {
"Online",
"Offline"};
205 for(
int itype = 0; itype < 5; itype++){
206 for(
const char **patchtype = patchtypes; patchtype < patchtypes + 2; ++patchtype){
207 fQAHistos->CreateTH2(Form(
"RCPos%s%s",
fgkTriggerTypeNames[itype].
Data(), *patchtype), Form(
"Lower edge position of %s %s patches (col-row);iEta;iPhi", *patchtype,
fgkTriggerTypeNames[itype].
Data()), 48, -0.5, 47.5, 104, -0.5, 103.5);
208 fQAHistos->CreateTH2(Form(
"EPCentPos%s%s",
fgkTriggerTypeNames[itype].
Data(), *patchtype), Form(
"Center position of the %s %s trigger patches;#eta;#phi", *patchtype,
fgkTriggerTypeNames[itype].
Data()), 20, -0.8, 0.8, 700, 0., 7.);
209 fQAHistos->CreateTH2(Form(
"PatchADCvsE%s%s",
fgkTriggerTypeNames[itype].
Data(), *patchtype), Form(
"Patch ADC value for trigger type %s %s;Trigger ADC;FEE patch energy (GeV)", *patchtype,
fgkTriggerTypeNames[itype].
Data()), 2000, 0., 2000, 200, 0., 200);
212 fQAHistos->CreateTH1(
"triggerBitsAll",
"Trigger bits for all incoming patches;bit nr", 64, -0.5, 63.5);
213 fQAHistos->CreateTH1(
"triggerBitsSel",
"Trigger bits for reconstructed patches;bit nr", 64, -0.5, 63.5);
225 AliEMCALTriggerPatchInfo *trigger, *triggerMainJet, *triggerMainGamma, *triggerMainLevel0;
226 AliEMCALTriggerPatchInfo *triggerMainJetSimple, *triggerMainGammaSimple;
233 AliError(Form(
"Calo triggers container %s not available.",
fCaloTriggersName.Data()));
237 AliError(Form(
"Calo cells container %s not available.",
fCaloCellsName.Data()));
241 AliError(Form(
"V0 container %s not available.",
fV0InName.Data()));
274 Int_t globCol=-1, globRow=-1;
283 (*fPatchADC)(globCol,globRow) = adcAmp;
291 Float_t amplitude(0);
293 if(amplitude < 0) amplitude = 0;
294 (*fPatchAmplitudes)(globCol,globRow) = amplitude;
298 TArrayI l0times(nl0times);
300 for(
int itime = 0; itime < nl0times; itime++){
301 if(l0times[itime] >7 && l0times[itime] < 10){
302 (*fLevel0TimeMap)(globCol,globRow) = static_cast<Char_t>(l0times[itime]);
312 for(Int_t iCell = 0; iCell < nCell; ++iCell) {
314 Short_t cellId =
fCaloCells->GetCellNumber(iCell);
315 Double_t amp =
fCaloCells->GetAmplitude(iCell);
318 fGeom->GetFastORIndexFromCellIndex(cellId, absId);
319 Int_t globCol=-1, globRow=-1;
320 fGeom->GetPositionInEMCALFromAbsFastORIndex(absId, globCol, globRow);
322 (*fPatchADCSimple)(globCol,globRow) += amp/EMCALTrigger::kEMCL1ADCtoGeV;
335 v0[0] =
fV0->GetTriggerChargeA();
336 v0[1] =
fV0->GetTriggerChargeC();
337 ULong64_t v0S = v0[0] + v0[1];
340 for (Int_t i = 0; i < 4; ++i) {
364 triggerMainGamma = 0;
366 triggerMainGammaSimple = 0;
367 triggerMainJetSimple = 0;
368 triggerMainLevel0 = 0;
371 Bool_t isOfflineSimple=0;
379 if (!isOfflineSimple) {
380 if (triggerMainJet == 0 || (triggerMainJet->GetPatchE() < trigger->GetPatchE()))
381 triggerMainJet = trigger;
383 if (triggerMainJetSimple == 0 || (triggerMainJetSimple->GetPatchE() < trigger->GetPatchE()))
384 triggerMainJetSimple = trigger;
395 if (!isOfflineSimple) {
396 if (triggerMainGamma == 0 || (triggerMainGamma->GetPatchE() < trigger->GetPatchE()))
397 triggerMainGamma = trigger;
399 if (triggerMainGammaSimple == 0 || (triggerMainGammaSimple->GetPatchE() < trigger->GetPatchE()))
400 triggerMainGammaSimple = trigger;
406 if(!isOfflineSimple){
411 if (!triggerMainLevel0 || (triggerMainLevel0->GetPatchE() < trigger->GetPatchE()))
412 triggerMainLevel0 = trigger;
426 if (triggerMainJet != 0) {
427 Int_t tBits = triggerMainJet->GetTriggerBits();
430 triggerMainJet->SetTriggerBits( tBits );
432 if (triggerMainJetSimple != 0) {
433 Int_t tBits = triggerMainJetSimple->GetTriggerBits();
436 triggerMainJetSimple->SetTriggerBits(tBits);
438 if (triggerMainGamma != 0) {
439 Int_t tBits = triggerMainGamma->GetTriggerBits();
442 triggerMainGamma->SetTriggerBits( tBits );
444 if (triggerMainGammaSimple != 0) {
445 Int_t tBits = triggerMainGammaSimple->GetTriggerBits();
448 triggerMainGammaSimple->SetTriggerBits( tBits );
450 if(triggerMainLevel0){
451 Int_t tBits = triggerMainLevel0->GetTriggerBits();
454 triggerMainLevel0->SetTriggerBits(tBits);
459 int npatchOnline = 0;
460 for(TIter patchIter = TIter(
fCaloTriggersOut).Begin(); patchIter != TIter::End(); ++patchIter){
461 AliEMCALTriggerPatchInfo *mypatch =
static_cast<AliEMCALTriggerPatchInfo *
>(*patchIter);
462 if(mypatch->IsOfflineSimple())
continue;
463 AliDebug(1,Form(
"Patch with bits: %s, types: JH[%s], JL[%s], GH[%s], GL[%s], L0[%s]",
464 std::bitset<
sizeof(
int)*4>(mypatch->GetTriggerBits()).to_string().c_str(),
465 (mypatch->IsJetHigh() ?
"y" :
"n"), (mypatch->IsJetLow() ?
"y" :
"n"),
466 (mypatch->IsGammaHigh() ?
"y" :
"n"), (mypatch->IsGammaLow() ?
"y" :
"n"),(mypatch->IsLevel0() ?
"y" :
"n")));
469 AliDebug(1, Form(
"Number of online patches: %d", npatchOnline));
484 if (!isOfflineSimple)
490 for(
unsigned int ibit = 0; ibit <
sizeof(tBits)*8; ibit++) {
491 if(tBits & (1 << ibit)){
492 fQAHistos->FillTH1(
"triggerBitsAll", ibit);
510 Int_t globCol=-1, globRow=-1;
511 if (!isOfflineSimple)
519 Int_t runno = InputEvent()->GetRunNumber();
520 if(runno > 176000 && runno <= 197692){
523 AliDebug(1, Form(
"Jet patch in inactive area: row[%d]", globRow));
530 const int kRowsPhi =
fGeom->GetNTotalTRU() * 2;
532 if((globCol + patchsize >=
kColsEta) || (globCol + patchsize >= kRowsPhi)){
533 AliError(Form(
"Invalid patch position for patch type %s: Col[%d], Row[%d] - patch rejected",
fgkTriggerTypeNames[type].
Data(), globCol, globRow));
540 fGeom->GetAbsFastORIndexFromPositionInEMCAL(globCol, globRow, absId);
542 Int_t cellAbsId[4]={-1,-1,-1,-1};
543 fGeom->GetCellIndexFromFastORIndex(absId, cellAbsId);
547 fGeom->GetGlobal(cellAbsId[0], edge1);
548 Int_t colEdge1 = globCol, rowEdge1 = globRow, absIdEdge1 = absId, cellIdEdge1 = cellAbsId[0];
557 Double_t adcOfflineAmp = 0;
559 for (Int_t i = 0; i < nfastor; ++i) {
560 for (Int_t j = 0; j < nfastor; ++j) {
562 fGeom->GetAbsFastORIndexFromPositionInEMCAL(globCol+i, globRow+j, absId);
563 fGeom->GetCellIndexFromFastORIndex(absId, cellAbsId);
565 for (Int_t k = 0; k < 4; ++k) {
566 Float_t ca =
fCaloCells->GetCellAmplitude(cellAbsId[k]);
569 cmiCol += ca*(Float_t)i;
570 cmiRow += ca*(Float_t)j;
575 adcAmp +=
static_cast<Int_t
>((*fPatchAmplitudes)(globCol+i,globRow+j) * 4);
578 std::cerr << e.what() << std::endl;
583 adcAmp += (*fPatchADC)(globCol+i,globRow+j);
586 std::cerr << e.what() << std::endl;
592 adcOfflineAmp += (*fPatchADCSimple)(globCol+i,globRow+j);
595 std::cerr << e.what() << std::endl;
602 AliDebug(2,
"EMCal trigger patch with 0 energy.");
609 Int_t cmCol = globCol + (Int_t)cmiCol;
610 Int_t cmRow = globRow + (Int_t)cmiRow;
613 fGeom->GetAbsFastORIndexFromPositionInEMCAL( cmCol, cmRow, absId );
614 fGeom->GetCellIndexFromFastORIndex( absId, cellAbsId );
617 Int_t cmiCellCol = TMath::Nint(cmiCol * 2.);
618 Int_t cmiCellRow = TMath::Nint(cmiRow * 2.);
620 fGeom->GetGlobal(cellAbsId[(cmiCellRow%2)*2 + cmiCellCol%2], centerMass);
641 fGeom->GetAbsFastORIndexFromPositionInEMCAL(globCol+posOffset, globRow+posOffset, absId);
642 fGeom->GetCellIndexFromFastORIndex(absId, cellAbsId);
644 fGeom->GetGlobal(cellAbsId[3], edge2);
645 Int_t colEdge2 = globCol+posOffset, rowEdge2 = globRow+posOffset, absIdEdge2 = absId, cellIdEdge2 = cellAbsId[3];
666 fGeom->GetAbsFastORIndexFromPositionInEMCAL(globCol+posOffset, globRow+posOffset, absId);
667 fGeom->GetCellIndexFromFastORIndex(absId, cellAbsId);
669 fGeom->GetGlobal(cellAbsId[3], center1);
684 fGeom->GetAbsFastORIndexFromPositionInEMCAL(globCol+posOffset, globRow+posOffset, absId);
685 fGeom->GetCellIndexFromFastORIndex(absId, cellAbsId);
687 fGeom->GetGlobal(cellAbsId[0], center2);
689 TVector3 centerGeo(center1);
690 centerGeo += center2;
694 TVector3 edge1tmp = edge1, edge2tmp = edge2;
696 centerMass -= vertex;
700 if(!(edge1[0] || edge1[1] || edge1[2])){
701 AliWarning(Form(
"Inconsistency in patch position for edge1: [%f|%f|%f]", edge1[0], edge1[1], edge1[2]));
702 AliWarning(
"Original vectors:");
703 AliWarning(Form(
"edge1: [%f|%f|%f]", edge1tmp[0], edge1tmp[1], edge1tmp[2]));
704 AliWarning(Form(
"vertex: [%f|%f|%f]", vertex[0], vertex[1], vertex[2]));
705 AliWarning(Form(
"Col: %d, Row: %d, FABSID: %d, Cell: %d", colEdge1, rowEdge1, absIdEdge1, cellIdEdge1));
706 AliWarning(Form(
"Offline: %s", isOfflineSimple ?
"yes" :
"no"));
708 if(!(edge2[0] || edge2[1] || edge2[2])){
709 AliWarning(Form(
"Inconsistency in patch position for edge2: [%f|%f|%f]", edge2[0], edge2[1], edge2[2]));
710 AliWarning(
"Original vectors:");
711 AliWarning(Form(
"edge2: [%f|%f|%f]", edge2tmp[0], edge2tmp[1], edge2tmp[2]));
712 AliWarning(Form(
"vertex: [%f|%f|%f]", vertex[0], vertex[1], vertex[2]));
713 AliWarning(Form(
"Col: %d, Row: %d, FABSID: %d, Cell: %d", colEdge2, rowEdge2, absIdEdge2, cellIdEdge2));
714 AliWarning(Form(
"Offline: %s", isOfflineSimple ?
"yes" :
"no"));
717 Int_t
isMC = MCEvent() ? 1 : 0;
746 AliEMCALTriggerPatchInfo *trigger =
747 new ((*fCaloTriggersOut)[
fITrigger]) AliEMCALTriggerPatchInfo();
750 trigger->SetCenterGeo(centerGeo, amp);
751 trigger->SetCenterMass(centerMass, amp);
752 trigger->SetEdge1(edge1, amp);
753 trigger->SetEdge2(edge2, amp);
754 trigger->SetADCAmp(adcAmp);
755 trigger->SetADCOfflineAmp(Int_t(adcOfflineAmp));
756 trigger->SetTriggerBits(tBits);
757 trigger->SetOffSet(offSet);
758 trigger->SetCol0(globCol);
759 trigger->SetRowStart(globRow);
760 trigger->SetEdgeCell(globCol*2, globRow*2);
763 TString patchtype = isOfflineSimple ?
"Offline" :
"Online";
766 fQAHistos->FillTH2(Form(
"PatchADCvsE%s%s",
fgkTriggerTypeNames[type].
Data(), patchtype.Data()), isOfflineSimple ? adcOfflineAmp : adcAmp, trigger->GetPatchE());
768 for(
unsigned int ibit = 0; ibit <
sizeof(tBits)*8; ibit++) {
769 if(tBits & (1 << ibit)){
770 fQAHistos->FillTH1(
"triggerBitsSel", ibit);
788 TArrayI tBitsArray(4), rowArray(4), colArray(4);
808 Double_t maxPatchADCoffline = -1;
809 Int_t maxPatchADC = -1;
812 Int_t maxRow =
fGeom->GetNTotalTRU()*2;
816 int runnumber = InputEvent()->GetRunNumber();
817 if(runnumber > 139517 && runnumber <= 170593) maxRow = 60;
818 Int_t
isMC = MCEvent() ? 1 : 0;
820 for (Int_t i = 0; i <= (maxCol-16); i += 4) {
821 for (Int_t j = 0; j <= (maxRow-16); j += 4) {
822 Double_t tSumOffline = 0;
826 for (Int_t k = 0; k < 16; ++k) {
827 for (Int_t l = 0; l < 16; ++l) {
828 tSumOffline += (*fPatchADCSimple)(i+k,j+l);
829 tSum +=
static_cast<ULong64_t
>((*fPatchADC)(i+k,j+l));
833 if (tSum > maxPatchADC) {
839 if (tSumOffline > maxPatchADCoffline) {
840 maxPatchADCoffline = tSumOffline;
855 tBitsArray.Set( tBitsArray.GetSize() + 1 );
856 colArray.Set( colArray.GetSize() + 1 );
857 rowArray.Set( rowArray.GetSize() + 1 );
858 tBitsArray[tBitsArray.GetSize()-1] = tBits;
859 colArray[colArray.GetSize()-1] = i;
860 rowArray[rowArray.GetSize()-1] = j;
867 maxPatchADCoffline = -1;
869 for (Int_t i = 0; i <= (maxCol-2); ++i) {
870 for (Int_t j = 0; j <= (maxRow-2); ++j) {
872 Double_t tSumOffline = 0;
876 for (Int_t k = 0; k < 2; ++k) {
877 for (Int_t l = 0; l < 2; ++l) {
878 tSumOffline += (*fPatchADCSimple)(i+k,j+l);
879 tSum +=
static_cast<ULong64_t
>((*fPatchADC)(i+k,j+l));
883 if (tSum > maxPatchADC) {
888 if (tSumOffline > maxPatchADCoffline) {
889 maxPatchADCoffline = tSumOffline;
904 tBitsArray.Set( tBitsArray.GetSize() + 1 );
905 colArray.Set( colArray.GetSize() + 1 );
906 rowArray.Set( rowArray.GetSize() + 1 );
907 tBitsArray[tBitsArray.GetSize()-1] = tBits;
908 colArray[colArray.GetSize()-1] = i;
909 rowArray[rowArray.GetSize()-1] = j;
917 for (Int_t i = 0; i < tBitsArray.GetSize(); ++i){
930 isOfflineSimple = kFALSE;
934 isOfflineSimple = kTRUE;
946 Int_t row(-1), col(-1); trg.GetPosition(col, row);
947 if(col < 0 || row < 0){
948 AliError(Form(
"Patch outside range [col %d, row %d]", col, row));
951 Int_t truref(-1), trumod(-1), absFastor(-1), adc(-1);
952 fGeom->GetAbsFastORIndexFromPositionInEMCAL(col, row, absFastor);
953 fGeom->GetTRUFromAbsFastORIndex(absFastor, truref, adc);
955 const int kNRowsPhi =
fGeom->GetNTotalTRU() * 2;
956 for(
int ipos = 0; ipos < 2; ipos++){
957 if(row + ipos >= kNRowsPhi)
continue;
958 for(
int jpos = 0; jpos < 2; jpos++){
959 if(col + jpos >=
kColsEta)
continue;
962 fGeom->GetAbsFastORIndexFromPositionInEMCAL(col+jpos, row+ipos, absFastor);
963 fGeom->GetTRUFromAbsFastORIndex(absFastor, trumod, adc);
964 if(trumod != truref)
continue;
965 if(col + jpos >=
kColsEta) AliError(Form(
"Boundary error in col [%d, %d + %d]", col + jpos, col, jpos));
966 if(row + ipos >= kNRowsPhi) AliError(Form(
"Boundary error in row [%d, %d + %d]", row + ipos, row, ipos));
967 Char_t l0times = (*fLevel0TimeMap)(col + jpos,row + ipos);
968 if(l0times > 7 && l0times < 10) nvalid++;
971 if (nvalid != 4)
return false;
Bool_t fRejectOffAcceptancePatches
Switch for rejection of patches outside the acceptance.
Int_t GetThresholdJetHighSimple() const
Int_t GetThresholdGammaHighSimple() const
TString fCaloTriggersOutName
name of output track array
Class to make array of trigger patch objects in AOD/ESD events.
Old configuration, no distinction between high and low threshold.
AliEMCALTriggerDataGrid< double > * fPatchADCSimple
! patch map for simple offline trigger
TriggerMakerBitConfig_t fUseTriggerBitConfig
type of trigger config
Base task in the EMCAL framework.
TriggerMakerTriggerType_t
Definition of different trigger patch types.
Bool_t fDoQA
Fill QA histograms.
Int_t fITrigger
! trigger counter
void UserCreateOutputObjects()
static const int kColsEta
Number of columns in eta direction.
Int_t GetThresholdGammaLowSimple() const
New configuration, distiction between high and low threshold.
static const TString fgkTriggerTypeNames[5]
Histogram name tags.
const AliEMCALTriggerBitConfig * fTriggerBitConfig
Trigger bit configuration, aliroot-dependent.
Trigger bit indicating the main (highest energy) trigger patch of a given type per event...
AliEMCALTriggerDataGrid< float > * fPatchAmplitudes
! TRU Amplitudes (for L0)
Bool_t IsEGA(Int_t tBits) const
AliEMCALGeometry * fGeom
!emcal geometry
TString fCaloTriggersName
name of calo triggers collection
Int_t fThresholdConstants[4][3]
simple offline trigger thresholds constants
Bool_t IsEJE(Int_t tBits) const
Int_t GetThresholdJetLowSimple() const
AliEMCALTriggerChannelContainer fBadChannels
Container of bad channels.
TString fCaloCellsName
name of calo cell collection
TString fV0InName
name of output track array
EMCAL Jet patches, recalculated.
Manager for constants used in the trigger maker.
AliEmcalTriggerSetupInfo * fCaloTriggerSetupOut
! trigger setup
Bool_t Data(TH1F *h, Double_t *rangefit, Bool_t writefit, Double_t &sgn, Double_t &errsgn, Double_t &bkg, Double_t &errbkg, Double_t &sgnf, Double_t &errsgnf, Double_t &sigmafit, Int_t &status)
Int_t fDebugLevel
Debug lebel;.
AliVCaloCells * fCaloCells
!cells
AliVVZERO * fV0
! V0 object
AliAODCaloTrigger * fSimpleOfflineTriggers
! simple offline trigger
EMCAL trigger patch maker.
AliEmcalList * fOutput
!output list
TClonesArray * fCaloTriggersOut
! trigger array out
THistManager * fQAHistos
! Histograms for QA
ClassImp(AliAnalysisTaskCRC) AliAnalysisTaskCRC
Double_t fVertex[3]
!event vertex
EMCAL Gamma patches, recalculated.
Int_t GetRunNumber(TString)
AliVCaloTrigger * fCaloTriggers
!calo triggers
void UserCreateOutputObjects()
Bool_t fRunTriggerType[5]
Run patch maker for a given trigger type.
void RunSimpleOfflineTrigger()
AliEMCALTriggerDataGrid< char > * fLevel0TimeMap
! Map needed to store the level0 times
Bool_t fInitialized
whether or not the task has been already initialized
TString fCaloTriggerSetupOutName
name of output track array
Settings manager for the trigger patch algorithmThis class contains the main settings (trigger thresh...
void SetThresholdsSimple(Int_t i0, Int_t i1, Int_t i2, Int_t i3)
Bool_t NextTrigger(Bool_t &isOfflineSimple)
AliEMCALTriggerPatchInfo * ProcessPatch(TriggerMakerTriggerType_t type, Bool_t isOfflineSimple)
virtual ~AliEmcalTriggerMaker()
void SetThresholds(Int_t i0, Int_t i1, Int_t i2, Int_t i3)
Bool_t CheckForL0(const AliVCaloTrigger &trg) const
AliEMCALTriggerDataGrid< int > * fPatchADC
! ADC values map