]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TRD/AliHLTTRDTrackHistoComponent.cxx
updated HLT TRD macros (Theo)
[u/mrichter/AliRoot.git] / HLT / TRD / AliHLTTRDTrackHistoComponent.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   AliHLTTRDTrackHistoComponent.cxx
18     @author Raphaelle and Theodor
19     @brief  Component for ploting charge in clusters
20 */
21
22 #if __GNUC__>= 3
23 using namespace std;
24 #endif
25
26 #include <time.h>
27
28 #include "AliHLTTRDTrackHistoComponent.h"
29 #include "AliHLTTRDDefinitions.h"
30 #include "AliCDBEntry.h"
31 #include "AliCDBManager.h"
32 #include <TFile.h>
33 #include <TString.h>
34 #include "TObjString.h"
35 #include "TClonesArray.h"
36 #include "TTimeStamp.h"
37 #include "AliHLTTRDUtils.h"
38 #include "TH1F.h"
39 #include "AliTRDcluster.h"
40 #include "AliTRDtrackV1.h"
41 #include "AliTRDseedV1.h"
42
43 //#include "AliHLTTRD.h"
44 //#include <stdlib.h>
45 //#include <cerrno>
46
47 /** ROOT macro for the implementation of ROOT specific class methods */
48 ClassImp(AliHLTTRDTrackHistoComponent)
49
50 AliHLTTRDTrackHistoComponent::AliHLTTRDTrackHistoComponent()
51 : AliHLTProcessor(),
52   fOutputSize(100000),
53   fSpec(0),
54   fTracksArray(NULL),
55   fClPerTrkl(NULL),
56   fTrklPerTrk(NULL),
57   fEvSize(NULL),
58   fEtaDistrib(NULL),
59   fPhiDistrib(NULL),
60   fPtDistrib(NULL)
61 {
62   // see header file for class documentation
63   // or
64   // refer to README to build package
65   // or
66   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
67
68 }
69
70 AliHLTTRDTrackHistoComponent::~AliHLTTRDTrackHistoComponent()
71 {
72   // see header file for class documentation
73 }
74
75 // Public functions to implement AliHLTComponent's interface.
76 // These functions are required for the registration process
77
78 const char* AliHLTTRDTrackHistoComponent::GetComponentID()
79 {
80   // see header file for class documentation
81   
82   return "TRDTrackHisto";
83 }
84
85 void AliHLTTRDTrackHistoComponent::GetInputDataTypes(AliHLTComponentDataTypeList& list)
86 {
87   // see header file for class documentation
88   list.clear();
89   list.push_back( AliHLTTRDDefinitions::fgkTracksDataType );
90 }
91
92 AliHLTComponentDataType AliHLTTRDTrackHistoComponent::GetOutputDataType()
93 {
94   // see header file for class documentation
95   return kAliHLTDataTypeHistogram  | kAliHLTDataOriginTRD;
96
97 }
98
99 void AliHLTTRDTrackHistoComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
100 {
101   // see header file for class documentation
102   constBase = fOutputSize;
103   inputMultiplier = 0;
104 }
105
106 AliHLTComponent* AliHLTTRDTrackHistoComponent::Spawn()
107 {
108   // see header file for class documentation
109   return new AliHLTTRDTrackHistoComponent;
110 }
111
112 int AliHLTTRDTrackHistoComponent::DoInit(int argc, const char** argv)
113 {
114   // Initialize histograms
115   int iResult=0;
116   
117   TString configuration="";
118   TString argument="";
119   for (int i=0; i<argc && iResult>=0; i++) {
120     argument=argv[i];
121     if (!configuration.IsNull()) configuration+=" ";
122     configuration+=argument;
123   }
124
125   if (!configuration.IsNull()) {
126     iResult=Configure(configuration.Data());
127   } 
128
129   fTracksArray = new TClonesArray("AliTRDtrackV1");
130
131   fClPerTrkl = new TH1F("TrdClPerTrkl","Clusters per Tracklet", AliTRDseedV1::kNtb, -0.5, AliTRDseedV1::kNtb - 0.5);
132   fTrklPerTrk = new TH1F("TrdTrklPerTrk","Tracklets per Track", 7, -0.5, 6.5);
133   fEvSize = new TH1F("TrdTrEvSize", "Tracks size per event per ddl in kbyte", 512, 0, 512);
134   fEtaDistrib = new TH1F("TrdTrEtaDistrib", "Eta distribution of tracks", 51, -1, 1);
135   fPhiDistrib = new TH1F("TrdTrPhiDistrib", "Phi distribution of tracks", 63, 0, 6.3);
136   fPtDistrib = new TH1F("TrdTrPtDistrib", "Pt distribution of tracks", 101, 0, 10);
137   return 0;
138 }
139   
140 int AliHLTTRDTrackHistoComponent::DoDeinit()
141 {
142   // see header file for class documentation
143
144   fTracksArray->Delete();
145   delete fTracksArray;
146
147   // delete histograms
148   if (fClPerTrkl) delete fClPerTrkl;
149   if (fTrklPerTrk) delete fTrklPerTrk;
150   
151   return 0;
152 }
153
154 int AliHLTTRDTrackHistoComponent::DoEvent(const AliHLTComponentEventData& /*evtData*/,
155                                             AliHLTComponentTriggerData& /*trigData*/)
156 {
157
158   // if (GetFirstInputBlock(kAliHLTDataTypeSOR)) return 0;
159   // else if (GetFirstInputBlock(kAliHLTDataTypeEOR))
160   //   {
161   //     TString fileName="/tmp/TracksHistoDump_run";
162   //     fileName+=AliCDBManager::Instance()->GetRun();
163   //     fileName+=".root";
164   //     HLTInfo("Dumping Histogram file to %s",fileName.Data());
165   //     TFile* file = TFile::Open(fileName, "RECREATE");
166   //     fClPerTrkl->Write();
167   //     fTrklPerTrk->Write();
168   //     file->Close();
169   //     HLTInfo("Histogram file dumped");
170   //     return 0;
171   //   }
172
173   if(!IsDataEvent())return 0;
174
175   const AliHLTComponentBlockData* iter = NULL;
176   Bool_t gotData = kFALSE;
177   
178   for(iter = GetFirstInputBlock(AliHLTTRDDefinitions::fgkTracksDataType); 
179         iter != NULL; iter = GetNextInputBlock() ) {
180     
181     fEvSize->Fill((iter->fSize+0.5f)/1024);
182     AliHLTTRDUtils::ReadTracks(fTracksArray, iter->fPtr, iter->fSize);
183     HLTDebug("TClonesArray of tracks: nbEntries = %i", fTracksArray->GetEntriesFast());
184     gotData=kTRUE;
185     fSpec |= iter->fSpecification;
186   }
187   
188   if(!gotData) return 0;
189   
190   AliTRDtrackV1 *trk;
191   
192   // loop over tracks
193   for(int i=0;i<fTracksArray->GetEntriesFast();i++) {
194     trk=(AliTRDtrackV1*)fTracksArray->At(i);
195     fEtaDistrib->Fill(trk->Eta());
196     fPhiDistrib->Fill(trk->Phi());
197     fPtDistrib->Fill(trk->Pt());
198     Int_t nrOfTrkls=0;
199     for(int seedNr=0; seedNr<6; seedNr++){
200       AliTRDseedV1* seed = trk->GetTracklet(seedNr);
201       if(!seed)continue;
202       nrOfTrkls++;
203       Int_t nrOfCls=0;
204       for(int clsNr=0; clsNr<AliTRDseedV1::kNtb; clsNr++)
205         if(seed->GetClusters(clsNr))nrOfCls++;
206       fClPerTrkl->Fill(nrOfCls);
207     }
208     fTrklPerTrk->Fill(nrOfTrkls);
209   }
210   
211   fTracksArray->Delete();
212   
213   PushBack((TObject*)fClPerTrkl, kAliHLTDataTypeHistogram | kAliHLTDataOriginTRD, fSpec);   
214   PushBack((TObject*)fTrklPerTrk, kAliHLTDataTypeHistogram | kAliHLTDataOriginTRD, fSpec);  
215   PushBack((TObject*)fEvSize, kAliHLTDataTypeHistogram | kAliHLTDataOriginTRD, fSpec);
216   PushBack((TObject*)fEtaDistrib, kAliHLTDataTypeHistogram | kAliHLTDataOriginTRD, fSpec);   
217   PushBack((TObject*)fPhiDistrib, kAliHLTDataTypeHistogram | kAliHLTDataOriginTRD, fSpec);  
218   PushBack((TObject*)fPtDistrib, kAliHLTDataTypeHistogram | kAliHLTDataOriginTRD, fSpec);
219   
220   return 0;
221 }
222
223 int AliHLTTRDTrackHistoComponent::Configure(const char* arguments){
224   int iResult=0;
225   if (!arguments) return iResult;
226   
227   TString allArgs=arguments;
228   TString argument;
229   int bMissingParam=0;
230
231   TObjArray* pTokens=allArgs.Tokenize(" ");
232   if (pTokens) {
233     for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
234       argument=((TObjString*)pTokens->At(i))->GetString();
235       if (argument.IsNull()) continue;
236       
237       if (argument.CompareTo("output_size")==0) {
238         if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
239         HLTInfo("Setting output size to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
240         fOutputSize=((TObjString*)pTokens->At(i))->GetString().Atoi();
241         continue;
242       } 
243       if (argument.CompareTo("-everyNevent")==0) {
244         if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
245         HLTInfo("Option -everyNevent depreceated");
246         continue;
247       } 
248       else {
249         HLTError("unknown argument: %s", argument.Data());
250         iResult=-EINVAL;
251         break;
252       }
253     }
254     delete pTokens;
255   }
256   if (bMissingParam) {
257     HLTError("missing parameter for argument %s", argument.Data());
258     iResult=-EINVAL;
259   }
260   return iResult;
261 }