AliPhysics  cda3415 (cda3415)
 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  fMaskedFastorOADB(""),
52  fUseL0Amplitudes(kFALSE),
53  fLoadFastORMaskingFromOCDB(kFALSE),
54  fCaloTriggersOut(0),
55  fDoQA(kFALSE),
56  fQAHistos(NULL)
57 {
58 
59 }
60 
62  AliAnalysisTaskEmcal("AliEmcalTriggerMakerTask", doQA),
63  fTriggerMaker(NULL),
64  fV0(NULL),
65  fCaloTriggersOutName("EmcalTriggers"),
66  fV0InName("AliAODVZERO"),
67  fBadFEEChannelOADB(""),
68  fMaskedFastorOADB(""),
69  fUseL0Amplitudes(kFALSE),
70  fLoadFastORMaskingFromOCDB(kFALSE),
71  fCaloTriggersOut(NULL),
72  fDoQA(doQA),
73  fQAHistos(NULL)
74 {
76 }
77 
79  if(fTriggerMaker) delete fTriggerMaker;
80 }
81 
87  const TString kTriggerTypeNames[3] = {"EJE", "EGA", "EL0"},
88  kPatchTypes[3] = {"Online", "Offline", "Recalc"};
89 
90  if(fDoQA) std::cout << "Trigger maker - QA requested" << std::endl;
91  else std::cout << "Trigger maker - no QA requested" << std::endl;
92  if(!fOutput) std::cout << "No output container initialized" << std::endl;
93 
94  if(fDoQA){
95  if(fOutput){
96  AliInfoStream() << "Enabling QA for trigger maker" << std::endl;
97  fQAHistos = new THistManager("TriggerQA");
98 
99  for(const TString *triggertype = kTriggerTypeNames; triggertype < kTriggerTypeNames + sizeof(kTriggerTypeNames)/sizeof(TString); triggertype++){
100  for(const TString *patchtype = kPatchTypes; patchtype < kPatchTypes + sizeof(kPatchTypes)/sizeof(TString); ++patchtype){
102  Form("RCPos%s%s", triggertype->Data(), patchtype->Data()),
103  Form("Lower edge position of %s %s patches (col-row);iEta;iPhi", patchtype->Data(), triggertype->Data()),
104  48, -0.5, 47.5, 104, -0.5, 103.5
105  );
107  Form("EPCentPos%s%s", triggertype->Data(), patchtype->Data()),
108  Form("Center position of the %s %s trigger patches;#eta;#phi", patchtype->Data(), triggertype->Data()),
109  20, -0.8, 0.8, 700, 0., 7.
110  );
112  Form("PatchADCvsE%s%s", triggertype->Data(), patchtype->Data()),
113  Form("Patch ADC value for trigger type %s %s;Trigger ADC;FEE patch energy (GeV)", patchtype->Data(), triggertype->Data()),
114  2000, 0., 2000, 200, 0., 200
115  );
117  Form("PatchADCOffvsE%s%s", triggertype->Data(), patchtype->Data()),
118  Form("Patch offline ADC value for trigger type %s %s;Trigger ADC;FEE patch energy (GeV)", patchtype->Data(), triggertype->Data()),
119  2000, 0., 2000, 200, 0., 200
120  );
121  }
122  }
123  fQAHistos->CreateTH1("triggerBitsAll", "Trigger bits for all incoming patches;bit nr", 64, -0.5, 63.5);
124  fQAHistos->CreateTH1("triggerBitsSel", "Trigger bits for reconstructed patches;bit nr", 64, -0.5, 63.5);
125  fQAHistos->CreateTH2("FastORMaskOnline", "Masked FastORs at online level; col; row", 48, -0.5, 47.5, 104, -0.5, 103.5);
127  PostData(1, fOutput);
128  } else {
129  AliWarningStream() << "QA requested but no output container initialized - QA needs to be disabled" << std::endl;
130  fDoQA = kFALSE;
131  }
132  }
133 }
134 
136 {
137  AliEMCALTriggerBitConfig *triggerBitConfig(NULL);
138  switch(bitConfig){
139  case kNewConfig:
140  triggerBitConfig = new AliEMCALTriggerBitConfigNew();
141  break;
142  case kOldConfig:
143  triggerBitConfig = new AliEMCALTriggerBitConfigOld();
144  break;
145  }
146  fTriggerMaker->SetTriggerBitConfig(triggerBitConfig);
147 }
148 
154 
155  if (!fLocalInitialized) return;
156 
157  if (!fCaloTriggersOutName.IsNull()) {
158  fCaloTriggersOut = new TClonesArray("AliEMCALTriggerPatchInfo");
160 
161  if (!(InputEvent()->FindListObject(fCaloTriggersOutName))) {
162  InputEvent()->AddObject(fCaloTriggersOut);
163  }
164  else {
165  fLocalInitialized = kFALSE;
166  AliFatal(Form("%s: Container with same name %s already present. Aborting", GetName(), fCaloTriggersOutName.Data()));
167  return;
168  }
169  }
170 
171  if (!fV0InName.IsNull()) {
172  fV0 = (AliVVZERO*)InputEvent()->FindListObject(fV0InName);
173  }
174 
175  // Configure trigger maker
176  if(!fTriggerMaker->IsConfigured()){
177  AliInfoStream() << "Trigger maker not yet configure - automatically configuring ..." << std::endl;
178  int runnumber = InputEvent()->GetRunNumber();
179  std::string dataset = "";
180  if(runnumber >= 145144 && runnumber <= 165746){
182  dataset = "pp 2011";
183  } else if(runnumber >= 167806 && runnumber <= 170593){
185  dataset = "Pb-Pb 2011";
186  } else if(runnumber >= 176326 && runnumber <= 193766){
188  dataset = "pp 2012";
189  } else if(runnumber >= 195344 && runnumber <= 197692){
190  // dataset contains also the setup for pp 2.76 TeV
192  dataset = "p-Pb 2013";
193  } else if((runnumber >= 224891 && runnumber <= 244628) || runnumber >= 253434){
194  // Configuration starting with LHC15f
196  dataset = "pp 2015-2016";
197  } else if(runnumber >= 244824 && runnumber <= 246994){
199  dataset = "Pb-Pb 2015";
200  }
201 
203  AliInfoStream() << "Applying configuration for " << dataset << std::endl;
204  } else {
205  AliErrorStream() << "No valid configuration found for the given dataset - trigger maker disabled" << std::endl;
206  fLocalInitialized = false;
207  }
208  }
209 
211  fTriggerMaker->Init();
212 }
213 
221  fCaloTriggersOut->Clear();
222  // prepare trigger maker
223  fTriggerMaker->Reset();
227  fTriggerMaker->SetIsMC(MCEvent());
229  AliEMCALTriggerPatchInfo *recpatch = NULL;
230  Int_t patchcounter = 0;
231  TString triggerstring;
232  AliDebugStream(2) << GetName() << ": Found " << patches->GetEntries() << " patches" << std::endl;
233  for(TIter patchIter = TIter(patches).Begin(); patchIter != TIter::End(); ++patchIter){
234  recpatch = dynamic_cast<AliEMCALTriggerPatchInfo *>(*patchIter);
235  if(fDoQA){
236  AliDebugStream(3) << GetName() << ": Next patch: size " << recpatch->GetPatchSize() << " , trigger bits " << std::bitset<sizeof(Int_t)*8>(recpatch->GetTriggerBits()) << std::endl;
237  // Handle types different - online - offline - re
238  if(recpatch->IsJetHigh() || recpatch->IsJetLow()) FillQAHistos("EJEOnline", *recpatch);
239  if(recpatch->IsGammaHigh() || recpatch->IsGammaLow()) FillQAHistos("EGAOnline", *recpatch);
240  if(recpatch->IsJetHighSimple() || recpatch->IsJetLowSimple()) FillQAHistos("EJEOffline", *recpatch);
241  if(recpatch->IsGammaHighSimple() || recpatch->IsGammaLowSimple()) FillQAHistos("EGAOffline", *recpatch);
242  if(recpatch->IsLevel0()) FillQAHistos("EL0Online", *recpatch);
243  if(recpatch->IsRecalcJet()) FillQAHistos("EJERecalc", *recpatch);
244  if(recpatch->IsRecalcGamma()) FillQAHistos("EGARecalc", *recpatch);
245  // Redo checking of found trigger bits after masking of unwanted triggers
246  int tBits = recpatch->GetTriggerBits();
247  for(unsigned int ibit = 0; ibit < sizeof(tBits)*8; ibit++) {
248  if(tBits & (1 << ibit)){
249  fQAHistos->FillTH1("triggerBitsSel", ibit);
250  }
251  }
252  }
253  new((*fCaloTriggersOut)[patchcounter++]) AliEMCALTriggerPatchInfo(*recpatch);
254  }
255  if(patches) delete patches;
256  return true;
257 }
258 
265  // QA: Monitor all channels which are masked in the current run
266  if(fDoQA && fQAHistos){
267  Int_t globCol(-1), globRow(-1) ;
268  for(const auto &ifastOrID : fTriggerMaker->GetListOfBadFastORAbsIDs()){
269  fGeom->GetTriggerMapping()->GetPositionInEMCALFromAbsFastORIndex(ifastOrID, globCol, globRow);
270  fQAHistos->FillTH2("FastORMaskOnline", globCol, globRow);
271  }
272  }
273 }
274 
276  AliInfoStream() << "Loading additional bad FEE channels from OADB container " << fBadFEEChannelOADB << std::endl;
278  if(fBadFEEChannelOADB.Contains("alien://") && !gGrid) TGrid::Connect("alien://");
279  AliOADBContainer badchannelDB("EmcalBadChannelsAdditional");
280  badchannelDB.InitFromFile(fBadFEEChannelOADB.Data(), "EmcalBadChannelsAdditional");
281  TObjArray *badchannelmap = static_cast<TObjArray *>(badchannelDB.GetObject(InputEvent()->GetRunNumber()));
282  if(!badchannelmap || !badchannelmap->GetEntries()) return;
283  for(TIter citer = TIter(badchannelmap).Begin(); citer != TIter::End(); ++citer){
284  TParameter<int> *channelID = static_cast<TParameter<int> *>(*citer);
285  fTriggerMaker->AddOfflineBadChannel(channelID->GetVal());
286  }
287 }
288 
290  AliInfoStream() << "Loading masked fastors from OCDB" << std::endl;
291  AliCDBManager *cdb = AliCDBManager::Instance();
292 
293  AliCDBEntry *en = cdb->Get("EMCAL/Calib/Trigger");
294  if(!en){
295  AliErrorStream() << GetName() << ": FastOR masking from CDB required, but OCDB entry is not available. No masking will be applied." << std::endl;
296  return;
297  }
298 
299  AliEMCALTriggerDCSConfig *trgconf = dynamic_cast<AliEMCALTriggerDCSConfig *>(en->GetObject());
300  if(!trgconf){
301  AliErrorStream() << GetName() << ": Failed decoding OCDB entry: Object is not of type AliEMCALTriggerDCSConfig." << std::endl;
302  return;
303  }
304 
305  // In run 1 the small supermodules were not contributing to triggers.
306  // Still the TRUs are counted. As access to the TRU config is not properly
307  // protected the loop over NTRU from the geometry will produce a segfault.
308  // As temporary workaround the loop limits are obtained from the DCS data itself.
309  Int_t fastOrAbsID(-1), ic(-1);
310  for(int itru = 0; itru < trgconf->GetTRUArr()->GetEntries(); itru++){
311  AliEMCALTriggerTRUDCSConfig *truconf = trgconf->GetTRUDCSConfig(itru);
312  // Test for each channel whether it is masked. The calculation is
313  // done reversely as the channel mapping is different between run1
314  // and run2: The loop is done over all masks and all bits inside the
315  // mask, and a handler matching to the correct mapping converts them
316  // into the channel ID. In case a masked channel is found, the absolute
317  // ID is calculated. For this the function GetAbsFastORIndexFromTRU
318  // is used - it is assumed that parameter 1 (iADC) corresponds to the
319  // channel ID.
320  for(unsigned int ifield = 0; ifield < 6; ifield++){
321  for(unsigned int ibit = 0; ibit < 16; ibit ++){
322  if((truconf->GetMaskReg(ifield) >> ibit) & 0x1){
323  try{
324  fGeom->GetTriggerMapping()->GetAbsFastORIndexFromTRU(itru, (ic = GetMaskHandler()(ifield, ibit)), fastOrAbsID);
325  AliDebugStream(1) << GetName() << "Channel " << ic << " in TRU " << itru << " ( abs fastor " << fastOrAbsID << ") masked." << std::endl;
326  fTriggerMaker->AddFastORBadChannel(fastOrAbsID);
327  } catch (int exept){
328  AliErrorStream() << GetName() << "Invalid mask: (" << ifield << "|" << ibit << "), exception " << exept << " thrown. Mask will not be recognized" << std::endl;
329  }
330  }
331  }
332  }
333  }
334 }
335 
337  AliInfoStream() << "Initializing masked fastors from OADB container " << fMaskedFastorOADB.Data() << std::endl;
338  if(fMaskedFastorOADB.Contains("alien://") && !gGrid) TGrid::Connect("alien://");
339  AliOADBContainer badchannelDB("AliEmcalMaskedFastors");
340  badchannelDB.InitFromFile(fMaskedFastorOADB.Data(), "AliEmcalMaskedFastors");
341  TObjArray *badchannelmap = static_cast<TObjArray *>(badchannelDB.GetObject(InputEvent()->GetRunNumber()));
342  if(!badchannelmap || !badchannelmap->GetEntries()) return;
343  for(TIter citer = TIter(badchannelmap).Begin(); citer != TIter::End(); ++citer){
344  TParameter<int> *channelID = static_cast<TParameter<int> *>(*citer);
345  AliDebugStream(1) << GetName() << ": Found masked fastor channel " << channelID->GetVal() << std::endl;
346  fTriggerMaker->AddFastORBadChannel(channelID->GetVal());
347  }
348 }
349 
350 
351 std::function<int (unsigned int, unsigned int)> AliEmcalTriggerMakerTask::GetMaskHandler() const {
352  if(fGeom->GetTriggerMappingVersion() == 2){
353  // Run 2 - complicated TRU layout in 6 subregions
354  return [] (unsigned int ifield, unsigned int ibit) -> int {
355  if(ifield >= 6 || ibit >= 16) throw kInvalidChannelException;
356  const int kChannelMap[6][16] = {{ 8, 9,10,11,20,21,22,23,32,33,34,35,44,45,46,47}, // Channels in mask0
357  {56,57,58,59,68,69,70,71,80,81,82,83,92,93,94,95}, // Channels in mask1
358  { 4, 5, 6, 7,16,17,18,19,28,29,30,31,40,41,42,43}, // Channels in mask2
359  {52,53,54,55,64,65,66,67,76,77,78,79,88,89,90,91}, // Channels in mask3
360  { 0, 1, 2, 3,12,13,14,15,24,25,26,27,36,37,38,39}, // Channels in mask4
361  {48,49,50,51,60,61,62,63,72,73,74,75,84,85,86,87}}; // Channels in mask5
362  return kChannelMap[ifield][ibit];
363  };
364  } else {
365  // Run 1 - linear mapping was used
366  return [] (int ifield, int ibit) -> int {
367  if(ifield >= 6 || ibit >= 16) throw kInvalidChannelException;
368  return ifield * 16 + ibit;
369  };
370  }
371 }
372 
373 void AliEmcalTriggerMakerTask::FillQAHistos(const TString &patchtype, const AliEMCALTriggerPatchInfo &recpatch){
374  fQAHistos->FillTH2(Form("RCPos%s", patchtype.Data()), recpatch.GetColStart(), recpatch.GetRowStart());
375  fQAHistos->FillTH2(Form("EPCentPos%s", patchtype.Data()), recpatch.GetEtaGeo(), recpatch.GetPhiGeo());
376  fQAHistos->FillTH2(Form("PatchADCvsE%s", patchtype.Data()), recpatch.GetADCAmp(), recpatch.GetPatchE());
377  fQAHistos->FillTH2(Form("PatchADCOffvsE%s", patchtype.Data()), recpatch.GetADCOfflineAmp(), recpatch.GetPatchE());
378 }
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 ...
ClassImp(AliAnalysisTaskCRC) AliAnalysisTaskCRC
TString fCaloTriggersOutName
name of output track array
TClonesArray * fCaloTriggersOut
! trigger array out
Container class for histograms.
Definition: THistManager.h:43
Kernel of the EMCAL trigger patch maker.
TString fMaskedFastorOADB
name of the OADB container containing fastors to be masked inside the trigger 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)