AliPhysics  c923f52 (c923f52)
 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 (!fLocalInitialized) 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  fLocalInitialized = 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 
163  // Configure trigger maker
164  if(!fTriggerMaker->IsConfigured()){
165  AliInfoStream() << "Trigger maker not yet configure - automatically configuring ..." << std::endl;
166  int runnumber = InputEvent()->GetRunNumber();
167  std::string dataset = "";
168  if(runnumber >= 145144 && runnumber <= 165746){
170  dataset = "pp 2011";
171  } else if(runnumber >= 167806 && runnumber <= 170593){
173  dataset = "Pb-Pb 2011";
174  } else if(runnumber >= 176326 && runnumber <= 193766){
176  dataset = "pp 2012";
177  } else if(runnumber >= 195344 && runnumber <= 197692){
178  // dataset contains also the setup for pp 2.76 TeV
180  dataset = "p-Pb 2013";
181  } else if((runnumber >= 224891 && runnumber <= 244628) || runnumber >= 253434){
182  // Configuration starting with LHC15f
184  dataset = "pp 2015-2016";
185  } else if(runnumber >= 244824 && runnumber <= 246994){
187  dataset = "Pb-Pb 2015";
188  }
189 
191  AliInfoStream() << "Applying configuration for " << dataset << std::endl;
192  } else {
193  AliErrorStream() << "No valid configuration found for the given dataset - trigger maker disabled" << std::endl;
194  fLocalInitialized = false;
195  }
196  }
197 
199  fTriggerMaker->Init();
200 }
201 
209  fCaloTriggersOut->Clear();
210  // prepare trigger maker
211  fTriggerMaker->Reset();
215  fTriggerMaker->SetIsMC(MCEvent());
217  AliEMCALTriggerPatchInfo *recpatch = NULL;
218  Int_t patchcounter = 0;
219  TString triggerstring;
220  AliDebug(2,Form("Trigger maker - Found %d patches\n", patches->GetEntries()));
221  for(TIter patchIter = TIter(patches).Begin(); patchIter != TIter::End(); ++patchIter){
222  recpatch = dynamic_cast<AliEMCALTriggerPatchInfo *>(*patchIter);
223  if(fDoQA){
224  //std::bitset<32> triggerbits = recpatch->GetTriggerBits();
225  std::stringstream triggerbitstring;
226  AliDebug(1, Form("Trigger maker - next patch: size %d, trigger bits %s", recpatch->GetPatchSize(), triggerbitstring.str().c_str()));
227  // Handle types different - online - offline - re
228  if(recpatch->IsJetHigh() || recpatch->IsJetLow()) FillQAHistos("EJEOnline", *recpatch);
229  if(recpatch->IsGammaHigh() || recpatch->IsGammaLow()) FillQAHistos("EGAOnline", *recpatch);
230  if(recpatch->IsJetHighSimple() || recpatch->IsJetLowSimple()) FillQAHistos("EJEOffline", *recpatch);
231  if(recpatch->IsGammaHighSimple() || recpatch->IsGammaLowSimple()) FillQAHistos("EGAOffline", *recpatch);
232  if(recpatch->IsLevel0()) FillQAHistos("EL0Online", *recpatch);
233  if(recpatch->IsRecalcJet()) FillQAHistos("EJERecalc", *recpatch);
234  if(recpatch->IsRecalcGamma()) FillQAHistos("EGARecalc", *recpatch);
235  // Redo checking of found trigger bits after masking of unwanted triggers
236  int tBits = recpatch->GetTriggerBits();
237  for(unsigned int ibit = 0; ibit < sizeof(tBits)*8; ibit++) {
238  if(tBits & (1 << ibit)){
239  fQAHistos->FillTH1("triggerBitsSel", ibit);
240  }
241  }
242  }
243  new((*fCaloTriggersOut)[patchcounter++]) AliEMCALTriggerPatchInfo(*recpatch);
244  }
245  if(patches) delete patches;
246  return true;
247 }
248 
252 }
253 
256  if(fBadFEEChannelOADB.Contains("alien://") && !gGrid) TGrid::Connect("alien://");
257  AliOADBContainer badchannelDB("EmcalBadChannelsAdditional");
258  badchannelDB.InitFromFile(fBadFEEChannelOADB.Data(), "EmcalBadChannelsAdditional");
259  TObjArray *badchannelmap = static_cast<TObjArray *>(badchannelDB.GetObject(InputEvent()->GetRunNumber()));
260  if(!badchannelmap || !badchannelmap->GetEntries()) return;
261  for(TIter citer = TIter(badchannelmap).Begin(); citer != TIter::End(); ++citer){
262  TParameter<int> *channelID = static_cast<TParameter<int> *>(*citer);
263  fTriggerMaker->AddOfflineBadChannel(channelID->GetVal());
264  }
265 }
266 
269  AliCDBManager *cdb = AliCDBManager::Instance();
270 
271  AliCDBEntry *en = cdb->Get("EMCAL/Calib/Trigger");
272  if(!en){
273  AliErrorStream() << GetName() << ": FastOR masking from CDB required, but OCDB entry is not available. No masking will be applied." << std::endl;
274  return;
275  }
276 
277  AliEMCALTriggerDCSConfig *trgconf = dynamic_cast<AliEMCALTriggerDCSConfig *>(en->GetObject());
278  if(!trgconf){
279  AliErrorStream() << GetName() << ": Failed decoding OCDB entry: Object is not of type AliEMCALTriggerDCSConfig." << std::endl;
280  return;
281  }
282 
283  // In run 1 the small supermodules were not contributing to triggers.
284  // Still the TRUs are counted. As access to the TRU config is not properly
285  // protected the loop over NTRU from the geometry will produce a segfault.
286  // As temporary workaround the loop limits are obtained from the DCS data itself.
287  Int_t fastOrAbsID(-1), ic(-1);
288  for(int itru = 0; itru < trgconf->GetTRUArr()->GetEntries(); itru++){
289  AliEMCALTriggerTRUDCSConfig *truconf = trgconf->GetTRUDCSConfig(itru);
290  // Test for each channel whether it is masked. The calculation is
291  // done reversely as the channel mapping is different between run1
292  // and run2: The loop is done over all masks and all bits inside the
293  // mask, and a handler matching to the correct mapping converts them
294  // into the channel ID. In case a masked channel is found, the absolute
295  // ID is calculated. For this the function GetAbsFastORIndexFromTRU
296  // is used - it is assumed that parameter 1 (iADC) corresponds to the
297  // channel ID.
298  for(unsigned int ifield = 0; ifield < 6; ifield++){
299  for(unsigned int ibit = 0; ibit < 16; ibit ++){
300  if((truconf->GetMaskReg(ifield) >> ibit) & 0x1){
301  try{
302  fGeom->GetTriggerMapping()->GetAbsFastORIndexFromTRU(itru, (ic = GetMaskHandler()(ifield, ibit)), fastOrAbsID);
303  AliDebugStream(1) << GetName() << "Channel " << ic << " in TRU " << itru << " ( abs fastor " << fastOrAbsID << ") masked." << std::endl;
304  fTriggerMaker->AddFastORBadChannel(fastOrAbsID);
305  } catch (int exept){
306  AliErrorStream() << GetName() << "Invalid mask: (" << ifield << "|" << ibit << "), exception " << exept << " thrown. Mask will not be recognized" << std::endl;
307  }
308  }
309  }
310  }
311  }
312 
313  // QA: Monitor all channels which are masked in the current run
314  Int_t globCol(-1), globRow(-1) ;
315  for(const auto &ifastOrID : fTriggerMaker->GetListOfBadFastORAbsIDs()){
316  fGeom->GetTriggerMapping()->GetPositionInEMCALFromAbsFastORIndex(ifastOrID, globCol, globRow);
317  fQAHistos->FillTH2("FastORMaskOnline", globCol, globRow);
318  }
319 }
320 
321 
322 std::function<int (unsigned int, unsigned int)> AliEmcalTriggerMakerTask::GetMaskHandler() const {
323  if(fGeom->GetTriggerMappingVersion() == 2){
324  // Run 2 - complicated TRU layout in 6 subregions
325  return [] (unsigned int ifield, unsigned int ibit) -> int {
326  if(ifield >= 6 || ibit >= 16) throw kInvalidChannelException;
327  const int kChannelMap[6][16] = {{ 8, 9,10,11,20,21,22,23,32,33,34,35,44,45,46,47}, // Channels in mask0
328  {56,57,58,59,68,69,70,71,80,81,82,83,92,93,94,95}, // Channels in mask1
329  { 4, 5, 6, 7,16,17,18,19,28,29,30,31,40,41,42,43}, // Channels in mask2
330  {52,53,54,55,64,65,66,67,76,77,78,79,88,89,90,91}, // Channels in mask3
331  { 0, 1, 2, 3,12,13,14,15,24,25,26,27,36,37,38,39}, // Channels in mask4
332  {48,49,50,51,60,61,62,63,72,73,74,75,84,85,86,87}}; // Channels in mask5
333  return kChannelMap[ifield][ibit];
334  };
335  } else {
336  // Run 1 - linear mapping was used
337  return [] (int ifield, int ibit) -> int {
338  if(ifield >= 6 || ibit >= 16) throw kInvalidChannelException;
339  return ifield * 16 + ibit;
340  };
341  }
342 }
343 
344 void AliEmcalTriggerMakerTask::FillQAHistos(const TString &patchtype, const AliEMCALTriggerPatchInfo &recpatch){
345  fQAHistos->FillTH2(Form("RCPos%s", patchtype.Data()), recpatch.GetColStart(), recpatch.GetRowStart());
346  fQAHistos->FillTH2(Form("EPCentPos%s", patchtype.Data()), recpatch.GetEtaGeo(), recpatch.GetPhiGeo());
347  fQAHistos->FillTH2(Form("PatchADCvsE%s", patchtype.Data()), recpatch.GetADCAmp(), recpatch.GetPatchE());
348  fQAHistos->FillTH2(Form("PatchADCOffvsE%s", patchtype.Data()), recpatch.GetADCOfflineAmp(), recpatch.GetPatchE());
349 }
AliVVZERO * fV0
! VZERO data
New configuration, distinction between high and low threshold.
Base task in the EMCAL framework.
Bool_t fLocalInitialized
whether or not the task has been already initialized
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)
virtual void RunChanged(Int_t newrun)
void FillQAHistos(const TString &patchtype, const AliEMCALTriggerPatchInfo &recpatch)
TString fBadFEEChannelOADB
name of the OADB container containing channels to be masked inside the trigger maker ...
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
THistManager * fQAHistos
! Histograms for QA
Bool_t fDoQA
Fill QA histograms.
void ReadCellData(AliVCaloCells *cells)
ClassImp(AliAnalysisTaskCascadeTester) AliAnalysisTaskCascadeTester