AliPhysics  97a96ce (97a96ce)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliEmcalTriggerMakerTask.cxx
Go to the documentation of this file.
1 /**************************************************************************
2  * Copyright(c) 1998-2013, ALICE Experiment at CERN, All rights reserved. *
3  * *
4  * Author: The ALICE Off-line Project. *
5  * Contributors are mentioned in the code where appropriate. *
6  * *
7  * Permission to use, copy, modify and distribute this software and its *
8  * documentation strictly for non-commercial purposes is hereby granted *
9  * without fee, provided that the above copyright notice appears in all *
10  * copies and that both the copyright notice and this permission notice *
11  * appear in the supporting documentation. The authors make no claims *
12  * about the suitability of this software for any purpose. It is *
13  * provided "as is" without express or implied warranty. *
14  **************************************************************************/
15 #include <TClonesArray.h>
16 #include <TGrid.h>
17 #include <THashList.h>
18 #include <THistManager.h>
19 #include <TObjArray.h>
20 #include <TParameter.h>
21 
22 #include "AliCDBEntry.h"
23 #include "AliCDBManager.h"
24 #include "AliEMCALGeometry.h"
25 #include "AliEMCALTriggerBitConfig.h"
26 #include "AliEMCALTriggerDCSConfig.h"
27 #include "AliEMCALTriggerTRUDCSConfig.h"
28 #include "AliEMCALTriggerPatchInfo.h"
31 #include "AliEMCALTriggerMapping.h"
32 #include "AliLog.h"
33 #include "AliOADBContainer.h"
34 
35 #include <bitset>
36 #include <iostream>
37 #include <sstream>
38 #include <string>
39 
43 
46  fTriggerMaker(NULL),
47  fV0(NULL),
48  fCaloTriggersOutName("EmcalTriggers"),
49  fV0InName("AliAODVZERO"),
50  fBadFEEChannelOADB(""),
51  fUseL0Amplitudes(kFALSE),
52  fLoadFastORMaskingFromOCDB(kFALSE),
53  fCaloTriggersOut(0),
54  fDoQA(kFALSE),
55  fQAHistos(NULL)
56 {
57 
58 }
59 
61  AliAnalysisTaskEmcal("AliEmcalTriggerMakerTask", doQA),
62  fTriggerMaker(NULL),
63  fV0(NULL),
64  fCaloTriggersOutName("EmcalTriggers"),
65  fV0InName("AliAODVZERO"),
66  fBadFEEChannelOADB(""),
67  fUseL0Amplitudes(kFALSE),
68  fLoadFastORMaskingFromOCDB(kFALSE),
69  fCaloTriggersOut(NULL),
70  fDoQA(doQA),
71  fQAHistos(NULL)
72 {
74 }
75 
77  if(fTriggerMaker) delete fTriggerMaker;
78 }
79 
85  const TString kTriggerTypeNames[3] = {"EJE", "EGA", "EL0"},
86  kPatchTypes[3] = {"Online", "Offline", "Recalc"};
87 
88  if(fDoQA && fOutput){
89  fQAHistos = new THistManager("TriggerQA");
90 
91  for(const TString *triggertype = kTriggerTypeNames; triggertype < kTriggerTypeNames + sizeof(kTriggerTypeNames)/sizeof(TString); triggertype++){
92  for(const TString *patchtype = kPatchTypes; patchtype < kPatchTypes + sizeof(kPatchTypes)/sizeof(TString); ++patchtype){
94  Form("RCPos%s%s", triggertype->Data(), patchtype->Data()),
95  Form("Lower edge position of %s %s patches (col-row);iEta;iPhi", patchtype->Data(), triggertype->Data()),
96  48, -0.5, 47.5, 104, -0.5, 103.5
97  );
99  Form("EPCentPos%s%s", triggertype->Data(), patchtype->Data()),
100  Form("Center position of the %s %s trigger patches;#eta;#phi", patchtype->Data(), triggertype->Data()),
101  20, -0.8, 0.8, 700, 0., 7.
102  );
104  Form("PatchADCvsE%s%s", triggertype->Data(), patchtype->Data()),
105  Form("Patch ADC value for trigger type %s %s;Trigger ADC;FEE patch energy (GeV)", patchtype->Data(), triggertype->Data()),
106  2000, 0., 2000, 200, 0., 200
107  );
109  Form("PatchADCOffvsE%s%s", triggertype->Data(), patchtype->Data()),
110  Form("Patch offline ADC value for trigger type %s %s;Trigger ADC;FEE patch energy (GeV)", patchtype->Data(), triggertype->Data()),
111  2000, 0., 2000, 200, 0., 200
112  );
113  }
114  }
115  fQAHistos->CreateTH1("triggerBitsAll", "Trigger bits for all incoming patches;bit nr", 64, -0.5, 63.5);
116  fQAHistos->CreateTH1("triggerBitsSel", "Trigger bits for reconstructed patches;bit nr", 64, -0.5, 63.5);
117  fQAHistos->CreateTH2("FastORMaskOnline", "Masked FastORs at online level; col; row", 48, -0.5, 47.5, 104, -0.5, 103.5);
119  PostData(1, fOutput);
120  }
121 }
122 
124 {
125  AliEMCALTriggerBitConfig *triggerBitConfig(NULL);
126  switch(bitConfig){
127  case kNewConfig:
128  triggerBitConfig = new AliEMCALTriggerBitConfigNew();
129  break;
130  case kOldConfig:
131  triggerBitConfig = new AliEMCALTriggerBitConfigOld();
132  break;
133  }
134  fTriggerMaker->SetTriggerBitConfig(triggerBitConfig);
135 }
136 
142 
143  if (!fInitialized) return;
144 
145  if (!fCaloTriggersOutName.IsNull()) {
146  fCaloTriggersOut = new TClonesArray("AliEMCALTriggerPatchInfo");
148 
149  if (!(InputEvent()->FindListObject(fCaloTriggersOutName))) {
150  InputEvent()->AddObject(fCaloTriggersOut);
151  }
152  else {
153  fInitialized = kFALSE;
154  AliFatal(Form("%s: Container with same name %s already present. Aborting", GetName(), fCaloTriggersOutName.Data()));
155  return;
156  }
157  }
158 
159  if (!fV0InName.IsNull()) {
160  fV0 = (AliVVZERO*)InputEvent()->FindListObject(fV0InName);
161  }
162 
164  fTriggerMaker->Init();
165 }
166 
174  fCaloTriggersOut->Clear();
175  // prepare trigger maker
176  fTriggerMaker->Reset();
180  fTriggerMaker->SetIsMC(MCEvent());
182  AliEMCALTriggerPatchInfo *recpatch = NULL;
183  Int_t patchcounter = 0;
184  TString triggerstring;
185  AliDebug(2,Form("Trigger maker - Found %d patches\n", patches->GetEntries()));
186  for(TIter patchIter = TIter(patches).Begin(); patchIter != TIter::End(); ++patchIter){
187  recpatch = dynamic_cast<AliEMCALTriggerPatchInfo *>(*patchIter);
188  if(fDoQA){
189  //std::bitset<32> triggerbits = recpatch->GetTriggerBits();
190  std::stringstream triggerbitstring;
191  AliDebug(1, Form("Trigger maker - next patch: size %d, trigger bits %s", recpatch->GetPatchSize(), triggerbitstring.str().c_str()));
192  // Handle types different - online - offline - re
193  if(recpatch->IsJetHigh() || recpatch->IsJetLow()) FillQAHistos("EJEOnline", *recpatch);
194  if(recpatch->IsGammaHigh() || recpatch->IsGammaLow()) FillQAHistos("EGAOnline", *recpatch);
195  if(recpatch->IsJetHighSimple() || recpatch->IsJetLowSimple()) FillQAHistos("EJEOffline", *recpatch);
196  if(recpatch->IsGammaHighSimple() || recpatch->IsGammaLowSimple()) FillQAHistos("EGAOffline", *recpatch);
197  if(recpatch->IsLevel0()) FillQAHistos("EL0Online", *recpatch);
198  if(recpatch->IsRecalcJet()) FillQAHistos("EJERecalc", *recpatch);
199  if(recpatch->IsRecalcGamma()) FillQAHistos("EGARecalc", *recpatch);
200  // Redo checking of found trigger bits after masking of unwanted triggers
201  int tBits = recpatch->GetTriggerBits();
202  for(unsigned int ibit = 0; ibit < sizeof(tBits)*8; ibit++) {
203  if(tBits & (1 << ibit)){
204  fQAHistos->FillTH1("triggerBitsSel", ibit);
205  }
206  }
207  }
208  new((*fCaloTriggersOut)[patchcounter++]) AliEMCALTriggerPatchInfo(*recpatch);
209  }
210  if(patches) delete patches;
211  return true;
212 }
213 
217 }
218 
221  if(fBadFEEChannelOADB.Contains("alien://") && !gGrid) TGrid::Connect("alien://");
222  AliOADBContainer badchannelDB("EmcalBadChannelsAdditional");
223  badchannelDB.InitFromFile(fBadFEEChannelOADB.Data(), "EmcalBadChannelsAdditional");
224  TObjArray *badchannelmap = static_cast<TObjArray *>(badchannelDB.GetObject(InputEvent()->GetRunNumber()));
225  if(!badchannelmap || !badchannelmap->GetEntries()) return;
226  for(TIter citer = TIter(badchannelmap).Begin(); citer != TIter::End(); ++citer){
227  TParameter<int> *channelID = static_cast<TParameter<int> *>(*citer);
228  fTriggerMaker->AddOfflineBadChannel(channelID->GetVal());
229  }
230 }
231 
234  AliCDBManager *cdb = AliCDBManager::Instance();
235 
236  AliCDBEntry *en = cdb->Get("EMCAL/Calib/Trigger");
237  if(!en){
238  AliErrorStream() << GetName() << ": FastOR masking from CDB required, but OCDB entry is not available. No masking will be applied." << std::endl;
239  return;
240  }
241 
242  AliEMCALTriggerDCSConfig *trgconf = dynamic_cast<AliEMCALTriggerDCSConfig *>(en->GetObject());
243  if(!trgconf){
244  AliErrorStream() << GetName() << ": Failed decoding OCDB entry: Object is not of type AliEMCALTriggerDCSConfig." << std::endl;
245  return;
246  }
247 
248  // In run 1 the small supermodules were not contributing to triggers.
249  // Still the TRUs are counted. As access to the TRU config is not properly
250  // protected the loop over NTRU from the geometry will produce a segfault.
251  // As temporary workaround the loop limits are obtained from the DCS data itself.
252  Int_t fastOrAbsID(-1), ic(-1);
253  for(int itru = 0; itru < trgconf->GetTRUArr()->GetEntries(); itru++){
254  AliEMCALTriggerTRUDCSConfig *truconf = trgconf->GetTRUDCSConfig(itru);
255  // Test for each channel whether it is masked. The calculation is
256  // done reversely as the channel mapping is different between run1
257  // and run2: The loop is done over all masks and all bits inside the
258  // mask, and a handler matching to the correct mapping converts them
259  // into the channel ID. In case a masked channel is found, the absolute
260  // ID is calculated. For this the function GetAbsFastORIndexFromTRU
261  // is used - it is assumed that parameter 1 (iADC) corresponds to the
262  // channel ID.
263  for(unsigned int ifield = 0; ifield < 6; ifield++){
264  for(unsigned int ibit = 0; ibit < 16; ibit ++){
265  if((truconf->GetMaskReg(ifield) >> ibit) & 0x1){
266  try{
267  fGeom->GetTriggerMapping()->GetAbsFastORIndexFromTRU(itru, (ic = GetMaskHandler()(ifield, ibit)), fastOrAbsID);
268  AliDebugStream(1) << GetName() << "Channel " << ic << " in TRU " << itru << " ( abs fastor " << fastOrAbsID << ") masked." << std::endl;
269  fTriggerMaker->AddFastORBadChannel(fastOrAbsID);
270  } catch (int exept){
271  AliErrorStream() << GetName() << "Invalid mask: (" << ifield << "|" << ibit << "), exception " << exept << " thrown. Mask will not be recognized" << std::endl;
272  }
273  }
274  }
275  }
276  }
277 
278  // QA: Monitor all channels which are masked in the current run
279  Int_t globCol(-1), globRow(-1) ;
280  for(const auto &ifastOrID : fTriggerMaker->GetListOfBadFastORAbsIDs()){
281  fGeom->GetTriggerMapping()->GetPositionInEMCALFromAbsFastORIndex(ifastOrID, globCol, globRow);
282  fQAHistos->FillTH2("FastORMaskOnline", globCol, globRow);
283  }
284 }
285 
286 
287 std::function<int (unsigned int, unsigned int)> AliEmcalTriggerMakerTask::GetMaskHandler() const {
288  if(fGeom->GetTriggerMappingVersion() == 2){
289  // Run 2 - complicated TRU layout in 6 subregions
290  return [] (unsigned int ifield, unsigned int ibit) -> int {
291  if(ifield >= 6 || ibit >= 16) throw kInvalidChannelException;
292  const int kChannelMap[6][16] = {{ 8, 9,10,11,20,21,22,23,32,33,34,35,44,45,46,47}, // Channels in mask0
293  {56,57,58,59,68,69,70,71,80,81,82,83,92,93,94,95}, // Channels in mask1
294  { 4, 5, 6, 7,16,17,18,19,28,29,30,31,40,41,42,43}, // Channels in mask2
295  {52,53,54,55,64,65,66,67,76,77,78,79,88,89,90,91}, // Channels in mask3
296  { 0, 1, 2, 3,12,13,14,15,24,25,26,27,36,37,38,39}, // Channels in mask4
297  {48,49,50,51,60,61,62,63,72,73,74,75,84,85,86,87}}; // Channels in mask5
298  return kChannelMap[ifield][ibit];
299  };
300  } else {
301  // Run 1 - linear mapping was used
302  return [] (int ifield, int ibit) -> int {
303  if(ifield >= 6 || ibit >= 16) throw kInvalidChannelException;
304  return ifield * 16 + ibit;
305  };
306  }
307 }
308 
309 void AliEmcalTriggerMakerTask::FillQAHistos(const TString &patchtype, const AliEMCALTriggerPatchInfo &recpatch){
310  fQAHistos->FillTH2(Form("RCPos%s", patchtype.Data()), recpatch.GetColStart(), recpatch.GetRowStart());
311  fQAHistos->FillTH2(Form("EPCentPos%s", patchtype.Data()), recpatch.GetEtaGeo(), recpatch.GetPhiGeo());
312  fQAHistos->FillTH2(Form("PatchADCvsE%s", patchtype.Data()), recpatch.GetADCAmp(), recpatch.GetPatchE());
313  fQAHistos->FillTH2(Form("PatchADCOffvsE%s", patchtype.Data()), recpatch.GetADCOfflineAmp(), recpatch.GetPatchE());
314 }
AliVVZERO * fV0
! VZERO data
New configuration, distinction between high and low threshold.
Base task in the EMCAL framework.
void FillTH2(const char *hname, double x, double y, double weight=1., Option_t *opt="")
TObjArray * CreateTriggerPatches(const AliVEvent *inputevent, Bool_t useL0amp=kFALSE)
void SetTriggerBitConfig(const AliEMCALTriggerBitConfig *const config)
Bool_t fUseL0Amplitudes
Use L0 amplitudes instead of L1 time sum (useful for runs where STU was not read) ...
Bool_t fLoadFastORMaskingFromOCDB
Load FastOR masking from the OCDB.
void ReadTriggerData(AliVCaloTrigger *trigger)
TString fV0InName
name of output track array
TH2 * CreateTH2(const char *name, const char *title, int nbinsx, double xmin, double xmax, int nbinsy, double ymin, double ymax, Option_t *opt="")
int Int_t
Definition: External.C:63
Old configuration, no distinction between high and low threshold.
THashList * GetListOfHistograms() const
Definition: THistManager.h:504
AliEMCALGeometry * fGeom
!emcal geometry
void SetUseTriggerBitConfig(TriggerMakerBitConfig_t bitConfig)
AliEmcalTriggerMakerKernel * fTriggerMaker
The actual trigger maker kernel.
TH1 * CreateTH1(const char *name, const char *title, int nbins, double xmin, double xmax, Option_t *opt="")
EMCAL trigger maker task.
void FillTH1(const char *hname, double x, double weight=1., Option_t *opt="")
const std::set< Short_t > & GetListOfBadFastORAbsIDs() const
AliVCaloCells * fCaloCells
!cells
void BuildL1ThresholdsOffline(const AliVVZERO *vzdata)
std::function< int(unsigned int, unsigned int)> GetMaskHandler() const
AliEmcalList * fOutput
!output list
void SetGeometry(const AliEMCALGeometry *const geo)
void FillQAHistos(const TString &patchtype, const AliEMCALTriggerPatchInfo &recpatch)
TString fBadFEEChannelOADB
name of the OADB container containing channels to be masked inside the trigger maker ...
ClassImp(AliAnalysisTaskCRC) AliAnalysisTaskCRC
TString fCaloTriggersOutName
name of output track array
TClonesArray * fCaloTriggersOut
! trigger array out
Container class for histograms for the high- charged particle analysis.
Definition: THistManager.h:43
Kernel of the EMCAL trigger patch maker.
Int_t GetRunNumber(TString)
Definition: PlotMuonQA.C:2235
AliVCaloTrigger * fCaloTriggers
!calo triggers
bool Bool_t
Definition: External.C:53
Bool_t fInitialized
whether or not the task has been already initialized
THistManager * fQAHistos
! Histograms for QA
Bool_t fDoQA
Fill QA histograms.
void ReadCellData(AliVCaloCells *cells)