]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/trigger/AliHLTTriggerCaloClusterEnergy.cxx
Implemented GetOCDBObject funtion for Calorimeter threshold triggers
[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   fgkOCDBEntry(""), 
52   fgkInputDataType()
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 //const char* AliHLTTriggerCaloClusterEnergy::fgkOCDBEntry="HLT/ConfigHLT/CaloClusterEnergyTrigger";
66
67 AliHLTTriggerCaloClusterEnergy::~AliHLTTriggerCaloClusterEnergy() {
68   // see header file for class documentation
69   if (fClusterReader)
70     delete fClusterReader;
71   fClusterReader = NULL;
72
73   if(fClustersRefs)
74     delete fClustersRefs;
75   fClustersRefs = NULL;
76 }
77
78 Int_t AliHLTTriggerCaloClusterEnergy::DoTrigger() {
79   // see header file for class documentation
80   
81   Int_t iResult = 0;
82
83
84   if ( GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR ) )
85     return 0;
86
87   //Try the caloclusterstruct input
88
89   
90   for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(fgkInputDataType); pBlock!=NULL; pBlock=GetNextInputBlock()) {
91     AliHLTCaloClusterHeaderStruct *caloClusterHeader = reinterpret_cast<AliHLTCaloClusterHeaderStruct*>(pBlock->fPtr);
92     fClusterReader->SetMemory(caloClusterHeader);
93     
94     AliHLTCaloClusterDataStruct * caloClusterStruct;
95     while( (caloClusterStruct = fClusterReader->NextCluster()) != 0) {
96       if (TriggerOnCluster(caloClusterStruct)) {
97         return iResult;
98       }
99     }
100   }
101
102   //Try the ESD input
103   const TObject* obj = GetFirstInputObject(kAliHLTAllDataTypes, "AliESDEvent");
104   AliESDEvent* esd = dynamic_cast<AliESDEvent*>(const_cast<TObject*>(obj));
105   
106   if (esd != NULL) {
107     esd->GetStdContent();
108
109     Int_t ncc = GetClustersFromEsd(esd, fClustersRefs); 
110     
111     for (Int_t i = 0; i < ncc ; i++) {
112       
113       AliESDCaloCluster * cluster = static_cast<AliESDCaloCluster*>(fClustersRefs->At(i));
114       if(TriggerOnCluster(cluster)) {
115         return iResult;
116       }
117     }
118   }
119
120   // If we got to this point then we did not find any clusters with E > fEThreshold
121   // generate negative trigger decision
122   TString description;
123   description.Form("No %s clusters containing energy > %.02f GeV found.", fDetector.Data(), fEThreshold);
124   SetDescription(description.Data());
125   TriggerEvent(false);
126   return iResult;
127
128 }
129
130
131 template <class T>
132 Bool_t AliHLTTriggerCaloClusterEnergy::TriggerOnCluster(T* cluster) {
133   
134   if (cluster->E() > fEThreshold) {
135
136     //We have a cluster satisfying trigger criteria
137     TString description;
138     description.Form("Event contains at least one %s cluster with energy > %.02f GeV.", fDetector.Data(), fEThreshold);
139     SetDescription(description.Data());
140     
141     // Enable the detectors for readout.
142     GetReadoutList().Enable( AliHLTReadoutList::kPHOS );
143     
144     // Add the available HLT information for readout too.
145     GetTriggerDomain().Add(kAliHLTAnyDataTypeID, fDetector.Data());
146     
147     //Set trigger decision
148     TriggerEvent(kTRUE);
149     
150     return kTRUE;
151   } 
152
153
154   return kFALSE;
155
156 }
157
158
159
160
161 int AliHLTTriggerCaloClusterEnergy::DoInit(int argc, const char** argv) {
162   // see header file for class documentation
163
164   // first configure the default
165   int iResult=ConfigureFromCDBTObjString(fgkOCDBEntry);
166
167   // configure from the command line parameters if specified
168   if (iResult>=0 && argc>0) {
169     iResult=ConfigureFromArgumentString(argc, argv);
170     HLTImportant("Trigger threshold set from argument string:  %.02f GeV:", fEThreshold ); 
171   } else if ( iResult >=0 ) {
172     HLTImportant("Trigger threshold set from OCDB database entry:  %.02f GeV:", fEThreshold ); 
173   }
174   return iResult;
175 }
176
177 int AliHLTTriggerCaloClusterEnergy::DoDeinit() {
178
179   // see header file for class documentation
180  
181   return 0;
182 }
183
184 int AliHLTTriggerCaloClusterEnergy::Reconfigure(const char* cdbEntry, const char* /*chainId*/) {
185   // see header file for class documentation
186
187   // configure from the specified antry or the default one
188   const char* entry=cdbEntry;
189   if (!entry || entry[0]==0) entry=fgkOCDBEntry;
190
191   return ConfigureFromCDBTObjString(entry);
192 }
193
194 int AliHLTTriggerCaloClusterEnergy::ScanConfigurationArgument(int argc, const char** argv) {
195   // see header file for class documentation
196   if (argc<=0) return 0;
197   int i=0;
198   TString argument=argv[i];
199
200   // -maxpt
201   if (argument.CompareTo("-energy")==0) {
202     if (++i>=argc) return -EPROTO;
203     argument=argv[i];
204     fEThreshold=argument.Atof();
205     return 2;
206   }    
207   
208   // unknown argument
209   return -EINVAL;
210 }
211
212 void AliHLTTriggerCaloClusterEnergy::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier) {
213   // see header file for documentation
214   constBase = sizeof(AliHLTTriggerDecision) + sizeof(AliHLTDomainEntry)*14;
215   inputMultiplier = 1;
216 }
217
218
219 void AliHLTTriggerCaloClusterEnergy::GetOCDBObjectDescription( TMap* const targetMap) {
220   // Get a list of OCDB object description.
221   if (!targetMap) return;
222   targetMap->Add(new TObjString(fgkOCDBEntry),
223                  new TObjString(Form("%s threshold trigger OCDB object", fDetector.Data()) ) 
224                  );
225 }