]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/trigger/AliHLTTriggerCaloClusterEnergy.cxx
Fix for updating CTP counters.
[u/mrichter/AliRoot.git] / HLT / trigger / AliHLTTriggerCaloClusterEnergy.cxx
1 // $Id$
2 //**************************************************************************
3 //* This file is property of and copyright by the ALICE HLT Project        * 
4 //* ALICE Experiment at CERN, All rights reserved.                         *
5 //*                                                                        *
6 //* Primary Authors: Svein Lindal <svein.lindal@gmail.com>                 *
7 //*                  for The ALICE HLT Project.                            *
8 //*                                                                        *
9 //* Permission to use, copy, modify and distribute this software and its   *
10 //* documentation strictly for non-commercial purposes is hereby granted   *
11 //* without fee, provided that the above copyright notice appears in all   *
12 //* copies and that both the copyright notice and this permission notice   *
13 //* appear in the supporting documentation. The authors make no claims     *
14 //* about the suitability of this software for any purpose. It is          *
15 //* provided "as is" without express or implied warranty.                  *
16 //**************************************************************************
17
18 /// @file   AliHLTTriggerCaloClusterEnergy.cxx
19 /// @author Svein Lindal <slindal@fys.uio.no>
20 /// @date   2009-08-17
21 /// @brief  BASE class for energy threshold trigger for Calorimeters
22 ///      
23
24 // see header file for class documentation
25 // or
26 // refer to README to build package
27 // or
28 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
29
30
31 #include "AliHLTTriggerCaloClusterEnergy.h"
32 #include "AliESDEvent.h"
33 #include "AliESDCaloCluster.h"
34 #include "AliHLTTriggerDecision.h"
35 #include "AliHLTDomainEntry.h"
36 #include "AliHLTCaloClusterReader.h"
37 #include "AliHLTCaloClusterDataStruct.h"
38 #include "TRefArray.h"
39 #include "TString.h"
40 #include "TMap.h"
41
42 /** ROOT macro for the implementation of ROOT specific class methods */
43 ClassImp(AliHLTTriggerCaloClusterEnergy)
44
45 AliHLTTriggerCaloClusterEnergy::AliHLTTriggerCaloClusterEnergy(TString detector) : 
46   AliHLTTrigger(),
47   fEThreshold(0.0),
48   fClustersRefs(NULL),
49   fDetector(detector),
50   fClusterReader(NULL),
51   fOCDBEntry(""), 
52   fInputDataType()
53 {
54   // see header file for class documentation
55   // or
56   // refer to README to build package
57   // or
58   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlts
59
60   fClusterReader = new AliHLTCaloClusterReader();
61   fClustersRefs = new TRefArray();
62
63 }
64
65
66 AliHLTTriggerCaloClusterEnergy::~AliHLTTriggerCaloClusterEnergy() {
67   // see header file for class documentation
68   if (fClusterReader)
69     delete fClusterReader;
70   fClusterReader = NULL;
71
72   if(fClustersRefs)
73     delete fClustersRefs;
74   fClustersRefs = NULL;
75 }
76
77 Int_t AliHLTTriggerCaloClusterEnergy::DoTrigger() {
78   // see header file for class documentation
79   
80   Int_t iResult = 0;
81
82
83   if ( GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR ) )
84     return 0;
85
86   //Try the caloclusterstruct input
87
88   
89   for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(fInputDataType); pBlock!=NULL; pBlock=GetNextInputBlock()) {
90     AliHLTCaloClusterHeaderStruct *caloClusterHeader = reinterpret_cast<AliHLTCaloClusterHeaderStruct*>(pBlock->fPtr);
91     fClusterReader->SetMemory(caloClusterHeader);
92     
93     AliHLTCaloClusterDataStruct * caloClusterStruct;
94     while( (caloClusterStruct = fClusterReader->NextCluster()) != 0) {
95       if (TriggerOnCluster(caloClusterStruct)) {
96         return iResult;
97       }
98     }
99   }
100
101   //Try the ESD input
102   const TObject* obj = GetFirstInputObject(kAliHLTAllDataTypes, "AliESDEvent");
103   AliESDEvent* esd = dynamic_cast<AliESDEvent*>(const_cast<TObject*>(obj));
104   
105   if (esd != NULL) {
106     esd->GetStdContent();
107
108     Int_t ncc = GetClustersFromEsd(esd, fClustersRefs); 
109     
110     for (Int_t i = 0; i < ncc ; i++) {
111       
112       AliESDCaloCluster * cluster = static_cast<AliESDCaloCluster*>(fClustersRefs->At(i));
113       if(TriggerOnCluster(cluster)) {
114         return iResult;
115       }
116     }
117   }
118
119   // If we got to this point then we did not find any clusters with E > fEThreshold
120   // generate negative trigger decision
121   TString description;
122   description.Form("No %s clusters containing energy > %.02f GeV found.", fDetector.Data(), fEThreshold);
123   SetDescription(description.Data());
124   TriggerEvent(false);
125   return iResult;
126
127 }
128
129
130 template <class T>
131 Bool_t AliHLTTriggerCaloClusterEnergy::TriggerOnCluster(T* cluster) {
132   
133   if (cluster->E() > fEThreshold) {
134
135     //We have a cluster satisfying trigger criteria
136     TString description;
137     description.Form("Event contains at least one %s cluster with energy > %.02f GeV.", fDetector.Data(), fEThreshold);
138     SetDescription(description.Data());
139     
140     // Enable the detectors for readout.
141     GetReadoutList().Enable( AliHLTReadoutList::kPHOS );
142     
143     // Add the available HLT information for readout too.
144     GetTriggerDomain().Add(kAliHLTAnyDataTypeID, fDetector.Data());
145     
146     //Set trigger decision
147     TriggerEvent(kTRUE);
148     
149     return kTRUE;
150   } 
151
152
153   return kFALSE;
154
155 }
156
157
158
159
160 int AliHLTTriggerCaloClusterEnergy::DoInit(int argc, const char** argv) {
161   // see header file for class documentation
162
163   // first configure the default
164   int iResult=ConfigureFromCDBTObjString(fOCDBEntry);
165
166   // configure from the command line parameters if specified
167   if (iResult>=0 && argc>0) {
168     iResult=ConfigureFromArgumentString(argc, argv);
169     HLTImportant("Trigger threshold set from argument string:  %.02f GeV:", fEThreshold ); 
170   } else if ( iResult >=0 ) {
171     HLTImportant("Trigger threshold set from OCDB database entry:  %.02f GeV:", fEThreshold ); 
172   }
173   return iResult;
174 }
175
176 int AliHLTTriggerCaloClusterEnergy::DoDeinit() {
177
178   // see header file for class documentation
179  
180   return 0;
181 }
182
183 int AliHLTTriggerCaloClusterEnergy::Reconfigure(const char* cdbEntry, const char* /*chainId*/) {
184   // see header file for class documentation
185
186   // configure from the specified antry or the default one
187   const char* entry=cdbEntry;
188   if (!entry || entry[0]==0) entry=fOCDBEntry;
189
190   return ConfigureFromCDBTObjString(entry);
191 }
192
193 int AliHLTTriggerCaloClusterEnergy::ScanConfigurationArgument(int argc, const char** argv) {
194   // see header file for class documentation
195   if (argc<=0) return 0;
196   int i=0;
197   TString argument=argv[i];
198
199   // -maxpt
200   if (argument.CompareTo("-energy")==0) {
201     if (++i>=argc) return -EPROTO;
202     argument=argv[i];
203     fEThreshold=argument.Atof();
204     return 2;
205   }    
206   
207   // unknown argument
208   return -EINVAL;
209 }
210
211 void AliHLTTriggerCaloClusterEnergy::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier) {
212   // see header file for documentation
213   constBase = sizeof(AliHLTTriggerDecision) + sizeof(AliHLTDomainEntry)*14;
214   inputMultiplier = 1;
215 }
216
217
218 void AliHLTTriggerCaloClusterEnergy::GetOCDBObjectDescription( TMap* const targetMap) {
219   // Get a list of OCDB object description.
220   if (!targetMap) return;
221   targetMap->Add(new TObjString(fOCDBEntry),
222                  new TObjString(Form("%s threshold trigger OCDB object", fDetector.Data()) ) 
223                  );
224 }