Line data Source code
1 : // $Id: AliHLTTRDCalibHistoComponent.cxx 40282 2010-04-09 13:29:10Z richterm $
2 :
3 : /**************************************************************************
4 : * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5 : * *
6 : * Authors: *
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 AliHLTTRDCalibHistoComponent.cxx
19 : // @author Theodor Rascanu
20 : // @date 25.04.2010
21 : // @brief A TRDCalibration histogramming component for the HLT.
22 : //
23 :
24 : #include "TTree.h"
25 : #include "TFile.h"
26 : #include "TBranch.h"
27 : #include "TH2I.h"
28 : #include "TH2.h"
29 : #include "TProfile2D.h"
30 :
31 : #include "AliHLTReadoutList.h"
32 :
33 : #include "AliHLTTRDCalibHistoComponent.h"
34 : #include "AliHLTTRDDefinitions.h"
35 : #include "AliHLTTRDUtils.h"
36 :
37 : #include "AliCDBManager.h"
38 : #include "AliCDBStorage.h"
39 : #include "AliCDBEntry.h"
40 : #include "AliRawReaderMemory.h"
41 :
42 : #include "AliTRDCalPad.h"
43 : #include "AliTRDCalDet.h"
44 :
45 : #include "AliTRDCalibraFillHisto.h"
46 : #include "AliTRDtrackV1.h"
47 :
48 : #include "AliTRDCalibraFit.h"
49 : #include "AliTRDCalibraMode.h"
50 : #include "AliTRDCalibraVector.h"
51 : #include "AliTRDCalibraVdriftLinearFit.h"
52 : #include "AliTRDReconstructor.h"
53 : #include "AliTRDrecoParam.h"
54 :
55 : #include <cstdlib>
56 : #include <cerrno>
57 : #include <string>
58 :
59 : using namespace std;
60 :
61 6 : ClassImp(AliHLTTRDCalibHistoComponent);
62 :
63 : AliHLTTRDCalibHistoComponent::AliHLTTRDCalibHistoComponent()
64 3 : : AliHLTProcessor(),
65 3 : fOutputSize(500000),
66 3 : fSpec(0),
67 3 : fTracksArray(NULL),
68 3 : fOutArray(NULL),
69 3 : fTRDCalibraFillHisto(NULL),
70 3 : fSavedTimeBins(kFALSE),
71 3 : fTrgStrings(NULL),
72 3 : fAccRejTrg(0),
73 3 : fMinClusters(0),
74 3 : fMinTracklets(0),
75 3 : fTakeAllEvents(kFALSE)
76 15 : {
77 : // Default constructor
78 6 : }
79 :
80 : AliHLTTRDCalibHistoComponent::~AliHLTTRDCalibHistoComponent()
81 12 : {
82 : // Destructor
83 12 : }
84 :
85 : const char* AliHLTTRDCalibHistoComponent::GetComponentID()
86 : {
87 : // Return the component ID const char *
88 138 : return "TRDCalibHisto"; // The ID of this component
89 : }
90 :
91 : void AliHLTTRDCalibHistoComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
92 : {
93 : // Get the list of input data
94 0 : list.clear(); // We do not have any requirements for our input data type(s).
95 0 : list.push_back(AliHLTTRDDefinitions::fgkTracksDataType);
96 0 : }
97 :
98 : AliHLTComponentDataType AliHLTTRDCalibHistoComponent::GetOutputDataType()
99 : {
100 : // Get the output data type
101 0 : return kAliHLTMultipleDataType;
102 : // return AliHLTTRDDefinitions::fgkCalibrationDataType;
103 :
104 : }
105 :
106 : int AliHLTTRDCalibHistoComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList)
107 : {
108 : // Get the output data type
109 0 : tgtList.clear();
110 0 : tgtList.push_back(AliHLTTRDDefinitions::fgkCalibrationDataType);
111 0 : return tgtList.size();
112 : }
113 :
114 : void AliHLTTRDCalibHistoComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
115 : {
116 : // Get the output data size
117 0 : constBase = fOutputSize;
118 0 : inputMultiplier = 0;
119 0 : }
120 :
121 : AliHLTComponent* AliHLTTRDCalibHistoComponent::Spawn()
122 : {
123 : // Spawn function, return new instance of this class
124 0 : return new AliHLTTRDCalibHistoComponent;
125 0 : };
126 :
127 : int AliHLTTRDCalibHistoComponent::DoInit( int argc, const char** argv )
128 : {
129 : int iResult=0;
130 0 : if(fTrgStrings)
131 0 : delete fTrgStrings;
132 0 : fTrgStrings = new TObjArray();
133 :
134 0 : TString configuration="";
135 0 : TString argument="";
136 0 : for (int i=0; i<argc && iResult>=0; i++) {
137 0 : argument=argv[i];
138 0 : if (!configuration.IsNull()) configuration+=" ";
139 0 : configuration+=argument;
140 : }
141 :
142 0 : if (!configuration.IsNull()) {
143 0 : iResult=Configure(configuration.Data());
144 0 : } else {
145 0 : iResult=Reconfigure(NULL, NULL);
146 : }
147 0 : if(iResult>=0){
148 0 : iResult=SetParams();
149 0 : }
150 : return iResult;
151 0 : }
152 :
153 : int AliHLTTRDCalibHistoComponent::Configure(const char* arguments){
154 : int iResult=0;
155 0 : if (!arguments) return iResult;
156 :
157 0 : TString allArgs=arguments;
158 0 : TString argument;
159 : int bMissingParam=0;
160 :
161 0 : TObjArray* pTokens=allArgs.Tokenize(" ");
162 0 : if (pTokens) {
163 0 : for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
164 0 : argument=((TObjString*)pTokens->At(i))->GetString();
165 0 : if (argument.IsNull()) continue;
166 :
167 0 : if (argument.CompareTo("output_size")==0) {
168 0 : if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
169 0 : HLTInfo("Setting output size to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
170 0 : fOutputSize=((TObjString*)pTokens->At(i))->GetString().Atoi();
171 0 : continue;
172 : }
173 0 : else if (argument.CompareTo("-minClusters")==0) {
174 0 : if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
175 0 : HLTInfo("Setting minCusters to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
176 0 : fMinClusters=((TObjString*)pTokens->At(i))->GetString().Atoi();
177 0 : continue;
178 : }
179 0 : else if (argument.CompareTo("-minTracklets")==0) {
180 0 : if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
181 0 : HLTInfo("Setting minTracklets to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
182 0 : fMinTracklets=((TObjString*)pTokens->At(i))->GetString().Atoi();
183 0 : continue;
184 : }
185 0 : else if (argument.CompareTo("-TrgStr")==0) {
186 0 : if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
187 0 : HLTInfo("Select TrgStr: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
188 0 : fTrgStrings->Add(new TObjString(((TObjString*)pTokens->At(i))->GetString().Data()));
189 0 : continue;
190 : }
191 0 : else if (argument.CompareTo("-acceptTrgStr")==0) {
192 0 : fAccRejTrg=1;
193 0 : HLTInfo("Accept selected Trigger Strings only");
194 : continue;
195 : }
196 0 : else if (argument.CompareTo("-rejectTrgStr")==0) {
197 0 : fAccRejTrg=-1;
198 0 : HLTInfo("Reject all selected Trigger Strings");
199 : continue;
200 : }
201 0 : else if (argument.CompareTo("-takeAllEvents")==0) {
202 0 : fAccRejTrg=0;
203 0 : fTakeAllEvents = kTRUE;
204 0 : HLTInfo("Take all events independently of the trigger strings");
205 : continue;
206 : }
207 :
208 : else {
209 0 : HLTError("unknown argument: %s", argument.Data());
210 : iResult=-EINVAL;
211 0 : break;
212 : }
213 : }
214 0 : delete pTokens;
215 : }
216 0 : if (bMissingParam) {
217 0 : HLTError("missing parameter for argument %s", argument.Data());
218 : iResult=-EINVAL;
219 0 : }
220 : return iResult;
221 0 : }
222 :
223 : int AliHLTTRDCalibHistoComponent::SetParams()
224 : {
225 :
226 0 : if(!fTrgStrings)
227 0 : fTrgStrings = new TObjArray();
228 :
229 0 : if(!AliCDBManager::Instance()->IsDefaultStorageSet()){
230 0 : HLTError("DefaultStorage is not set in CDBManager");
231 0 : return -EINVAL;
232 : }
233 0 : if(AliCDBManager::Instance()->GetRun()<0){
234 0 : HLTError("Run Number is not set in CDBManager");
235 0 : return -EINVAL;
236 : }
237 0 : HLTInfo("CDB default storage: %s; RunNo: %i", (AliCDBManager::Instance()->GetDefaultStorage()->GetBaseFolder()).Data(), AliCDBManager::Instance()->GetRun());
238 :
239 0 : if(fTrgStrings->GetEntriesFast()>0 && !fAccRejTrg){
240 0 : HLTError("Trigger string(s) given, but acceptTrgStr or rejectTrgStr not selected");
241 0 : return -EINVAL;
242 : }
243 :
244 0 : fTRDCalibraFillHisto = AliTRDCalibraFillHisto::Instance();
245 0 : fTRDCalibraFillHisto->SetIsHLT(kTRUE);
246 0 : fTRDCalibraFillHisto->SetHisto2d(); // choose to use histograms
247 0 : fTRDCalibraFillHisto->SetCH2dOn(); // choose to calibrate the gain
248 0 : fTRDCalibraFillHisto->SetPH2dOn(); // choose to calibrate the drift velocity
249 0 : fTRDCalibraFillHisto->SetPRF2dOn(); // choose to look at the PRF
250 0 : fTRDCalibraFillHisto->SetIsHLT(); // per detector
251 : //fTRDCalibraFillHisto->SetDebugLevel(1);// debug
252 0 : fTRDCalibraFillHisto->SetFillWithZero(kTRUE);
253 0 : fTRDCalibraFillHisto->SetLinearFitterOn(kTRUE);
254 0 : fTRDCalibraFillHisto->SetNumberBinCharge(100);
255 :
256 0 : if(!fTracksArray) fTracksArray = new TClonesArray("AliTRDtrackV1");
257 0 : if(!fOutArray)fOutArray = new TObjArray(4);
258 :
259 : HLTDebug("run SetupCTPData");
260 0 : SetupCTPData();
261 :
262 0 : return 0;
263 0 : }
264 :
265 : int AliHLTTRDCalibHistoComponent::DoDeinit()
266 : {
267 :
268 : // Deinitialization of the component
269 :
270 : HLTDebug("DeinitCalibration");
271 0 : delete fTracksArray; fTracksArray=0;
272 0 : fTRDCalibraFillHisto->DestroyDebugStreamer();
273 : //fTRDCalibraFillHisto->Destroy();
274 : //fOutArray->Delete();
275 0 : delete fOutArray; fOutArray=0;
276 0 : fTrgStrings->Delete();
277 0 : delete fTrgStrings; fTrgStrings=0;
278 0 : return 0;
279 : }
280 :
281 : Int_t AliHLTTRDCalibHistoComponent::DoEvent(const AliHLTComponent_EventData& /*evtData*/,
282 : const AliHLTComponent_BlockData* /*blocks*/,
283 : AliHLTComponent_TriggerData& /*trigData*/,
284 : AliHLTUInt8_t* /*outputPtr*/,
285 : AliHLTUInt32_t& /*size*/,
286 : vector<AliHLTComponent_BlockData>& /*outputBlocks*/)
287 : {
288 : // Process an event
289 :
290 0 : TClonesArray* TCAarray[18] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
291 : Int_t usedEntries = 0;
292 : Int_t blockOrObject = 0;
293 0 : Int_t nTimeBins = -1;
294 :
295 0 : for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(AliHLTTRDDefinitions::fgkTracksDataType); pBlock; pBlock=GetNextInputBlock())
296 : {
297 0 : TCAarray[0] = fTracksArray;
298 0 : AliHLTTRDUtils::ReadTracks(TCAarray[0], pBlock->fPtr, pBlock->fSize, &nTimeBins);
299 0 : fSpec |= pBlock->fSpecification;
300 : usedEntries = 1;
301 : blockOrObject = -1;
302 : }
303 :
304 0 : for(const TObject *iter = GetFirstInputObject(AliHLTTRDDefinitions::fgkHiLvlTracksDataType); iter; iter = GetNextInputObject())
305 : {
306 0 : if(blockOrObject<0){
307 0 : HLTError("You may not mix high level and low level!");
308 0 : return -1;
309 : }
310 :
311 0 : TCAarray[usedEntries] = dynamic_cast<TClonesArray*>(const_cast<TObject*>(iter));
312 0 : if(TCAarray[usedEntries])continue;
313 0 : TObjString* strg = dynamic_cast<TObjString*>(const_cast<TObject*>(GetNextInputObject()));
314 0 : if(!strg)continue;
315 :
316 0 : nTimeBins = strg->String().Atoi();
317 0 : fSpec |= GetSpecification(iter);
318 0 : usedEntries++;
319 : blockOrObject = 1;
320 0 : }
321 :
322 0 : if(!blockOrObject)
323 0 : return 0;
324 :
325 0 : if(!fSavedTimeBins){
326 0 : if(nTimeBins<0){
327 0 : HLTFatal("Number of timebins is negative!");
328 0 : return -1;
329 : }
330 : HLTDebug("Saving number of time bins which was read from input block. Value is: %d", nTimeBins);
331 0 : fTRDCalibraFillHisto->Init2Dhistos(nTimeBins); // initialise the histos
332 0 : fTRDCalibraFillHisto->SetNumberClusters(fMinClusters); // At least fMinClusters clusters
333 0 : fTRDCalibraFillHisto->SetNumberClustersf(nTimeBins); // Not more than %d clusters
334 0 : fSavedTimeBins=kTRUE;
335 0 : }
336 :
337 0 : Bool_t bTriggerPassed = fTakeAllEvents;
338 :
339 0 : if(fAccRejTrg){
340 0 : if(fAccRejTrg>0){
341 : bTriggerPassed=kFALSE;
342 0 : for(int i = 0; i < fTrgStrings->GetEntriesFast(); i++){
343 0 : const TObjString *const obString=(TObjString*)fTrgStrings->At(i);
344 0 : const TString tString=obString->GetString();
345 0 : if(CheckCTPTrigger(tString.Data())>0){bTriggerPassed=kTRUE; break;}
346 0 : }
347 0 : }
348 : else{
349 : bTriggerPassed=kTRUE;
350 0 : for(int i = 0; i < fTrgStrings->GetEntriesFast(); i++){
351 0 : const TObjString *const obString=(TObjString*)fTrgStrings->At(i);
352 0 : const TString tString=obString->GetString();
353 0 : if(CheckCTPTrigger(tString.Data())>0){bTriggerPassed=kFALSE; break;}
354 0 : }
355 : }
356 : }
357 :
358 0 : fTRDCalibraFillHisto->SetCH2dOn(bTriggerPassed);
359 0 : fTRDCalibraFillHisto->SetPH2dOn(bTriggerPassed);
360 0 : for(int i=0; i<usedEntries; i++){
361 0 : const TClonesArray *const inArr = TCAarray[i];
362 0 : Int_t nbEntries = inArr->GetEntries();
363 : HLTDebug(" %i TRDtracks in tracksArray", nbEntries);
364 : AliTRDtrackV1* trdTrack = 0x0;
365 0 : for (Int_t ii = 0; ii < nbEntries; ii++){
366 : HLTDebug("%i/%i: ", ii+1, nbEntries);
367 0 : trdTrack = (AliTRDtrackV1*)inArr->At(ii);
368 0 : if(trdTrack->GetNumberOfTracklets()<fMinTracklets)continue;
369 0 : fTRDCalibraFillHisto->UpdateHistogramsV1(trdTrack);
370 : // for(int i3=0; i3<7; i3++)
371 : // if(trdTrack->GetTracklet(i3))trdTrack->GetTracklet(i3)->Bootstrap(fReconstructor);
372 0 : }
373 : }
374 :
375 0 : if(!fOutArray->At(0))FormOutput();
376 0 : PushBack(fOutArray, AliHLTTRDDefinitions::fgkCalibrationDataType, fSpec);
377 :
378 0 : if(blockOrObject<0){
379 0 : TCAarray[0]->Delete();
380 0 : }
381 :
382 : return 0;
383 0 : }
384 :
385 : /**
386 : * Form output array of histrograms
387 : */
388 : //============================================================================
389 : void AliHLTTRDCalibHistoComponent::FormOutput()
390 : {
391 : // gain histo
392 0 : TH2I *hCH2d = fTRDCalibraFillHisto->GetCH2d();
393 0 : fOutArray->Add(hCH2d);
394 :
395 : // drift velocity histo
396 0 : TProfile2D *hPH2d = fTRDCalibraFillHisto->GetPH2d();
397 0 : fOutArray->Add(hPH2d);
398 :
399 : // PRF histo
400 0 : TProfile2D *hPRF2d = fTRDCalibraFillHisto->GetPRF2d();
401 0 : fOutArray->Add(hPRF2d);
402 :
403 : // Vdrift Linear Fit
404 0 : AliTRDCalibraVdriftLinearFit *hVdriftLinearFitOne=(AliTRDCalibraVdriftLinearFit *)fTRDCalibraFillHisto->GetVdriftLinearFit();
405 0 : fOutArray->Add(hVdriftLinearFitOne);
406 :
407 : HLTDebug("GetCH2d = 0x%x; NEntries = %i; size = %i", hCH2d, hCH2d->GetEntries(), sizeof(*hCH2d));
408 0 : hCH2d->Print();
409 : HLTDebug("GetPH2d = 0x%x; NEntries = %i; size = %i", hPH2d, hPH2d->GetEntries(), sizeof(*hPH2d));
410 0 : hPH2d->Print();
411 : HLTDebug("GetPRF2d = 0x%x; NEntries = %i; size = %i", hPRF2d, hPRF2d->GetEntries(), sizeof(*hPRF2d));
412 0 : hPRF2d->Print();
413 : HLTDebug("GetVdriftLinearFit = 0x%x; size = %i", hVdriftLinearFitOne, sizeof(hVdriftLinearFitOne));
414 :
415 : HLTDebug("output Array: pointer = 0x%x; NEntries = %i; size = %i", fOutArray, fOutArray->GetEntries(), sizeof(fOutArray));
416 :
417 0 : }
418 :
419 : int AliHLTTRDCalibHistoComponent::Reconfigure(const char* cdbEntry, const char* chainId)
420 : {
421 : // see header file for class documentation
422 :
423 : int iResult=0;
424 : const char* path="HLT/ConfigTRD/CalibHistoComponent";
425 : const char* defaultNotify="";
426 0 : if (cdbEntry) {
427 : path=cdbEntry;
428 : defaultNotify=" (default)";
429 0 : }
430 0 : if (path) {
431 0 : HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
432 0 : AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
433 0 : if (pEntry) {
434 0 : TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
435 0 : if (pString) {
436 0 : HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
437 0 : iResult=Configure(pString->GetString().Data());
438 0 : } else {
439 0 : HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
440 : }
441 0 : } else {
442 0 : HLTError("cannot fetch object \"%s\" from CDB", path);
443 : }
444 0 : }
445 :
446 0 : return iResult;
447 0 : }
|