]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TRD/AliHLTTRDClusterHistoComponent.cxx
activating individual HLT simulations from digits and raw data
[u/mrichter/AliRoot.git] / HLT / TRD / AliHLTTRDClusterHistoComponent.cxx
1 //**************************************************************************
2 //* This file is property of and copyright by the ALICE HLT Project        * 
3 //* ALICE Experiment at CERN, All rights reserved.                         *
4 //*                                                                        *
5 //* Primary Authors: Sylwester Radomski radomski@physi.uni-heidelberg.de    *
6 //*                  for The ALICE HLT Project.                            *
7 //*                                                                        *
8 //* Permission to use, copy, modify and distribute this software and its   *
9 //* documentation strictly for non-commercial purposes is hereby granted   *
10 //* without fee, provided that the above copyright notice appears in all   *
11 //* copies and that both the copyright notice and this permission notice   *
12 //* appear in the supporting documentation. The authors make no claims     *
13 //* about the suitability of this software for any purpose. It is          *
14 //* provided "as is" without express or implied warranty.                  *
15 //**************************************************************************
16
17 /** @file   AliHLTTRDClusterHistoComponent.cxx
18     @author Sylwester Radomski
19     @brief  Component for ploting charge in clusters
20 */
21
22 #if __GNUC__>= 3
23 using namespace std;
24 #endif
25
26 #include "TFile.h"
27 #include "TString.h"
28 #include "TObjString.h"
29 #include "TClonesArray.h"
30 #include "TH1F.h"
31
32 #include "AliHLTTRDClusterHistoComponent.h"
33 #include "AliHLTTRDDefinitions.h"
34 #include "AliTRDcluster.h"
35 #include "AliCDBEntry.h"
36 #include "AliCDBManager.h"
37 #include "AliHLTTRDUtils.h"
38
39 //#include "AliHLTTRD.h"
40 //#include <stdlib.h>
41 //#include <cerrno>
42
43 /** ROOT macro for the implementation of ROOT specific class methods */
44 ClassImp(AliHLTTRDClusterHistoComponent)
45
46 AliHLTTRDClusterHistoComponent::AliHLTTRDClusterHistoComponent()
47 : AliHLTProcessor(),
48   fOutputSize(100000),
49   fSpec(0),
50   fClusterArray(NULL),
51   fNClsDet(NULL),
52   fClsAmp(NULL),
53   fClsAmpDrift(NULL),
54   fClsTB(NULL),
55   fClsAmpDist(NULL),
56   fSClsDist(NULL),
57   fNScls(NULL),
58   fEvSize(NULL)
59 {
60   // see header file for class documentation
61   // or
62   // refer to README to build package
63   // or
64   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
65
66 }
67
68 AliHLTTRDClusterHistoComponent::~AliHLTTRDClusterHistoComponent()
69 {
70   // see header file for class documentation
71 }
72
73 // Public functions to implement AliHLTComponent's interface.
74 // These functions are required for the registration process
75
76 const char* AliHLTTRDClusterHistoComponent::GetComponentID()
77 {
78   // see header file for class documentation
79   
80   return "TRDClusterHisto";
81 }
82
83 void AliHLTTRDClusterHistoComponent::GetInputDataTypes(AliHLTComponentDataTypeList& list)
84 {
85   // see header file for class documentation
86   list.clear();
87   list.push_back( AliHLTTRDDefinitions::fgkClusterDataType );
88 }
89
90 AliHLTComponentDataType AliHLTTRDClusterHistoComponent::GetOutputDataType()
91 {
92   // see header file for class documentation
93   return kAliHLTDataTypeHistogram  | kAliHLTDataOriginTRD;
94
95 }
96
97 void AliHLTTRDClusterHistoComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
98 {
99   // see header file for class documentation
100   constBase = fOutputSize;
101   inputMultiplier = 0;
102 }
103
104 AliHLTComponent* AliHLTTRDClusterHistoComponent::Spawn()
105 {
106   // see header file for class documentation
107   return new AliHLTTRDClusterHistoComponent;
108 }
109
110 int AliHLTTRDClusterHistoComponent::DoInit(int argc, const char** argv)
111 {
112   // Initialize histograms
113   int iResult=0;
114   
115   TString configuration="";
116   TString argument="";
117   for (int i=0; i<argc && iResult>=0; i++) {
118     argument=argv[i];
119     if (!configuration.IsNull()) configuration+=" ";
120     configuration+=argument;
121   }
122
123   if (!configuration.IsNull()) {
124     iResult=Configure(configuration.Data());
125   } 
126
127   fClusterArray = new TClonesArray("AliTRDcluster");
128
129   fNClsDet = new TH1F("trdClsDet", ";detector", 540, -0.5, 539.5);
130   fClsAmp  = new TH1F("trdClsAmp", ";amplitude", 200, -0.5, 1999.5);
131   fClsAmpDrift = new TH1F("trdClsAmpDrift", ";amplitude", 200, -0.5, 199.5) ;
132   fClsTB = new TH1F("trdClsTB", ";time bin", 35, -0.5, 34.5);
133   fClsAmpDist = new TH1F("trdClsAmpDist", "mean amplitude", 200, 0, 1000);
134   fSClsDist = new TH1F("sclsdist", "Super cluster spectrum", 200, 0, 8000);
135   fNScls = new TH1F("nscls", "No. of Kr clusters per event", 540, 0, 540);
136   fEvSize = new TH1F("TrdClEvSize", "Clusters size per event per ddl in kbyte", 512, 0, 512);
137
138   for(int i=0; i<540; i++) {
139     fClsAmpDriftDet[i] = new TH1F(Form("trdClsDriftDet_%d",i), "", 200, -0.5, 199.5);
140   }
141   
142   return 0;
143 }
144   
145 int AliHLTTRDClusterHistoComponent::DoDeinit()
146 {
147   // see header file for class documentation
148
149   fClusterArray->Delete();
150   delete fClusterArray;
151
152   // delete histograms
153   if (fNClsDet) delete fNClsDet;
154   if (fClsAmp) delete fClsAmp;
155   if (fClsAmpDrift) delete fClsAmpDrift;
156   if (fClsTB) delete fClsTB;
157   if (fClsAmpDist) delete fClsAmpDist;
158   if (fSClsDist) delete fSClsDist;
159   if (fNScls) delete fNScls;
160   if (fEvSize) delete fEvSize;
161
162   for(int i=0; i<540; i++){
163     if (fClsAmpDriftDet[i]) delete fClsAmpDriftDet[i];
164   }
165
166   return 0;
167 }
168
169 int AliHLTTRDClusterHistoComponent::DoEvent(const AliHLTComponentEventData& /*evtData*/,
170                                             AliHLTComponentTriggerData& /*trigData*/)
171 {
172
173   // if (GetFirstInputBlock(kAliHLTDataTypeSOR)) return 0;
174   // else if (GetFirstInputBlock(kAliHLTDataTypeEOR))
175   //   {
176   //     TString fileName="/tmp/ClusterHistoDump_run";
177   //     fileName+=AliCDBManager::Instance()->GetRun();
178   //     fileName+=".root";
179   //     HLTInfo("Dumping Histogram file to %s",fileName.Data());
180   //     TFile* file = TFile::Open(fileName, "RECREATE");
181   //     fNClsDet->Write();
182   //     fClsAmp->Write();
183   //     fClsAmpDrift->Write();
184   //     fClsTB->Write();
185   //     fClsAmpDist->Write(); 
186   //     fSClsDist->Write();
187   //     fNScls->Write();
188   //     file->Close();
189   //     HLTInfo("Histogram file dumped");
190   //     return 0;
191   //   }
192
193   if(!IsDataEvent())return 0;
194
195   const AliHLTComponentBlockData* iter = NULL;
196   Bool_t gotData = kFALSE;
197
198   for ( iter = GetFirstInputBlock(AliHLTTRDDefinitions::fgkClusterDataType); 
199         iter != NULL; iter = GetNextInputBlock() ) {
200
201     fEvSize->Fill((iter->fSize+0.5f)/1024);
202     AliHLTTRDUtils::ReadClusters(fClusterArray, iter->fPtr, iter->fSize);
203     HLTDebug("TClonesArray of clusters: nbEntries = %i", fClusterArray->GetEntriesFast());
204     gotData = kTRUE;
205     fSpec |= iter->fSpecification;
206   }
207
208   if(!gotData) return 0;
209
210   Float_t sClusterCharge[540] = { 0 };
211     AliTRDcluster *cls;
212
213     // loop over clusters 
214     for(int i=0;i<fClusterArray->GetEntriesFast();i++) {
215
216       cls=(AliTRDcluster*)fClusterArray->At(i);
217       
218       fNClsDet->Fill(cls->GetDetector());
219       fClsAmp->Fill(cls->GetQ());
220       
221       int tb = cls->GetPadTime();
222       fClsTB->Fill(tb);
223     if (tb > 5 && tb <25){
224         fClsAmpDrift->Fill(cls->GetQ()); 
225     }
226       
227     //fClsAmpDriftDet[cls->GetDetector()]->Fill(cls->GetQ());
228
229       Int_t det = cls->GetDetector();
230       sClusterCharge[det] += cls->GetQ();
231
232     }
233     
234     fClusterArray->Delete();
235     
236   //fClsAmpDist->Reset();
237   //Int_t nSClusters = 0;
238   for(int det=0; det<540; det++) {
239     // if (fClsAmpDriftDet[det]->GetSum() > 0) 
240     //   fClsAmpDist->Fill(fClsAmpDriftDet[det]->GetMean());
241     if(sClusterCharge[det])
242     fSClsDist->Fill(sClusterCharge[det]);
243   }
244
245   //fNScls->Fill(nSClusters);
246
247   PushBack((TObject*)fNClsDet, kAliHLTDataTypeHistogram | kAliHLTDataOriginTRD, fSpec);
248   PushBack((TObject*)fClsAmp, kAliHLTDataTypeHistogram | kAliHLTDataOriginTRD, fSpec);
249   PushBack((TObject*)fClsAmpDrift, kAliHLTDataTypeHistogram | kAliHLTDataOriginTRD, fSpec);
250   PushBack((TObject*)fClsTB, kAliHLTDataTypeHistogram | kAliHLTDataOriginTRD, fSpec);
251   //PushBack((TObject*)fClsAmpDist, kAliHLTDataTypeHistogram | kAliHLTDataOriginTRD, fSpec);
252   //PushBack((TObject*)fNScls, kAliHLTDataTypeHistogram | kAliHLTDataOriginTRD, fSpec);
253   PushBack((TObject*)fSClsDist, kAliHLTDataTypeHistogram | kAliHLTDataOriginTRD, fSpec);
254   PushBack((TObject*)fEvSize, kAliHLTDataTypeHistogram | kAliHLTDataOriginTRD, fSpec);
255
256   return 0;
257 }
258
259 int AliHLTTRDClusterHistoComponent::Configure(const char* arguments){
260   int iResult=0;
261   if (!arguments) return iResult;
262   
263   TString allArgs=arguments;
264   TString argument;
265   int bMissingParam=0;
266
267   TObjArray* pTokens=allArgs.Tokenize(" ");
268   if (pTokens) {
269     for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
270       argument=((TObjString*)pTokens->At(i))->GetString();
271       if (argument.IsNull()) continue;
272       
273       if (argument.CompareTo("output_size")==0) {
274         if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
275         HLTInfo("Setting output size to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
276         fOutputSize=((TObjString*)pTokens->At(i))->GetString().Atoi();
277         continue;
278       } 
279       else {
280         HLTError("unknown argument: %s", argument.Data());
281         iResult=-EINVAL;
282         break;
283       }
284     }
285     delete pTokens;
286   }
287   if (bMissingParam) {
288     HLTError("missing parameter for argument %s", argument.Data());
289     iResult=-EINVAL;
290   }
291   return iResult;
292 }