1 // $Id: AliHLTTRDCalibHistoComponent.cxx 40282 2010-04-09 13:29:10Z richterm $
3 /**************************************************************************
4 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
7 * for The ALICE HLT Project. *
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 **************************************************************************/
18 // @file AliHLTTRDCalibHistoComponent.cxx
19 // @author Theodor Rascanu
21 // @brief A TRDCalibration histogramming component for the HLT.
29 #include "TProfile2D.h"
31 #include "AliHLTReadoutList.h"
33 #include "AliHLTTRDCalibHistoComponent.h"
34 #include "AliHLTTRDDefinitions.h"
35 #include "AliHLTTRDUtils.h"
37 #include "AliCDBManager.h"
38 #include "AliCDBStorage.h"
39 #include "AliCDBEntry.h"
40 #include "AliRawReaderMemory.h"
42 #include "AliTRDCalPad.h"
43 #include "AliTRDCalDet.h"
45 #include "AliTRDCalibraFillHisto.h"
46 #include "AliTRDtrackV1.h"
48 #include "AliTRDCalibraFit.h"
49 #include "AliTRDCalibraMode.h"
50 #include "AliTRDCalibraVector.h"
51 #include "AliTRDCalibraVdriftLinearFit.h"
52 #include "AliTRDReconstructor.h"
53 #include "AliTRDrecoParam.h"
61 ClassImp(AliHLTTRDCalibHistoComponent);
63 AliHLTTRDCalibHistoComponent::AliHLTTRDCalibHistoComponent()
69 fTRDCalibraFillHisto(NULL),
70 fSavedTimeBins(kFALSE),
75 fTakeAllEvents(kFALSE)
77 // Default constructor
80 AliHLTTRDCalibHistoComponent::~AliHLTTRDCalibHistoComponent()
85 const char* AliHLTTRDCalibHistoComponent::GetComponentID()
87 // Return the component ID const char *
88 return "TRDCalibHisto"; // The ID of this component
91 void AliHLTTRDCalibHistoComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
93 // Get the list of input data
94 list.clear(); // We do not have any requirements for our input data type(s).
95 list.push_back(AliHLTTRDDefinitions::fgkTracksDataType);
98 AliHLTComponentDataType AliHLTTRDCalibHistoComponent::GetOutputDataType()
100 // Get the output data type
101 return kAliHLTMultipleDataType;
102 // return AliHLTTRDDefinitions::fgkCalibrationDataType;
106 int AliHLTTRDCalibHistoComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList)
108 // Get the output data type
110 tgtList.push_back(AliHLTTRDDefinitions::fgkCalibrationDataType);
111 return tgtList.size();
114 void AliHLTTRDCalibHistoComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
116 // Get the output data size
117 constBase = fOutputSize;
121 AliHLTComponent* AliHLTTRDCalibHistoComponent::Spawn()
123 // Spawn function, return new instance of this class
124 return new AliHLTTRDCalibHistoComponent;
127 int AliHLTTRDCalibHistoComponent::DoInit( int argc, const char** argv )
132 fTrgStrings = new TObjArray();
134 TString configuration="";
136 for (int i=0; i<argc && iResult>=0; i++) {
138 if (!configuration.IsNull()) configuration+=" ";
139 configuration+=argument;
142 if (!configuration.IsNull()) {
143 iResult=Configure(configuration.Data());
145 iResult=Reconfigure(NULL, NULL);
153 int AliHLTTRDCalibHistoComponent::Configure(const char* arguments){
155 if (!arguments) return iResult;
157 TString allArgs=arguments;
161 TObjArray* pTokens=allArgs.Tokenize(" ");
163 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
164 argument=((TObjString*)pTokens->At(i))->GetString();
165 if (argument.IsNull()) continue;
167 if (argument.CompareTo("output_size")==0) {
168 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
169 HLTInfo("Setting output size to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
170 fOutputSize=((TObjString*)pTokens->At(i))->GetString().Atoi();
173 else if (argument.CompareTo("-minClusters")==0) {
174 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
175 HLTInfo("Setting minCusters to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
176 fMinClusters=((TObjString*)pTokens->At(i))->GetString().Atoi();
179 else if (argument.CompareTo("-minTracklets")==0) {
180 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
181 HLTInfo("Setting minTracklets to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
182 fMinTracklets=((TObjString*)pTokens->At(i))->GetString().Atoi();
185 else if (argument.CompareTo("-TrgStr")==0) {
186 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
187 HLTInfo("Select TrgStr: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
188 fTrgStrings->Add(new TObjString(((TObjString*)pTokens->At(i))->GetString().Data()));
191 else if (argument.CompareTo("-acceptTrgStr")==0) {
193 HLTInfo("Accept selected Trigger Strings only");
196 else if (argument.CompareTo("-rejectTrgStr")==0) {
198 HLTInfo("Reject all selected Trigger Strings");
201 else if (argument.CompareTo("-takeAllEvents")==0) {
203 fTakeAllEvents = kTRUE;
204 HLTInfo("Take all events independently of the trigger strings");
209 HLTError("unknown argument: %s", argument.Data());
217 HLTError("missing parameter for argument %s", argument.Data());
223 int AliHLTTRDCalibHistoComponent::SetParams()
227 fTrgStrings = new TObjArray();
229 if(!AliCDBManager::Instance()->IsDefaultStorageSet()){
230 HLTError("DefaultStorage is not set in CDBManager");
233 if(AliCDBManager::Instance()->GetRun()<0){
234 HLTError("Run Number is not set in CDBManager");
237 HLTInfo("CDB default storage: %s; RunNo: %i", (AliCDBManager::Instance()->GetDefaultStorage()->GetBaseFolder()).Data(), AliCDBManager::Instance()->GetRun());
239 if(fTrgStrings->GetEntriesFast()>0 && !fAccRejTrg){
240 HLTError("Trigger string(s) given, but acceptTrgStr or rejectTrgStr not selected");
244 fTRDCalibraFillHisto = AliTRDCalibraFillHisto::Instance();
245 fTRDCalibraFillHisto->SetIsHLT(kTRUE);
246 fTRDCalibraFillHisto->SetHisto2d(); // choose to use histograms
247 fTRDCalibraFillHisto->SetCH2dOn(); // choose to calibrate the gain
248 fTRDCalibraFillHisto->SetPH2dOn(); // choose to calibrate the drift velocity
249 fTRDCalibraFillHisto->SetPRF2dOn(); // choose to look at the PRF
250 fTRDCalibraFillHisto->SetIsHLT(); // per detector
251 //fTRDCalibraFillHisto->SetDebugLevel(1);// debug
252 fTRDCalibraFillHisto->SetFillWithZero(kTRUE);
253 fTRDCalibraFillHisto->SetLinearFitterOn(kTRUE);
254 fTRDCalibraFillHisto->SetNumberBinCharge(100);
256 if(!fTracksArray) fTracksArray = new TClonesArray("AliTRDtrackV1");
257 if(!fOutArray)fOutArray = new TObjArray(4);
259 HLTDebug("run SetupCTPData");
265 int AliHLTTRDCalibHistoComponent::DoDeinit()
268 // Deinitialization of the component
270 HLTDebug("DeinitCalibration");
271 delete fTracksArray; fTracksArray=0;
272 fTRDCalibraFillHisto->DestroyDebugStreamer();
273 //fTRDCalibraFillHisto->Destroy();
274 //fOutArray->Delete();
275 delete fOutArray; fOutArray=0;
276 fTrgStrings->Delete();
277 delete fTrgStrings; fTrgStrings=0;
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*/)
290 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 Int_t nTimeBins = -1;
295 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(AliHLTTRDDefinitions::fgkTracksDataType); pBlock; pBlock=GetNextInputBlock())
297 TCAarray[0] = fTracksArray;
298 AliHLTTRDUtils::ReadTracks(TCAarray[0], pBlock->fPtr, pBlock->fSize, &nTimeBins);
299 fSpec |= pBlock->fSpecification;
304 for(const TObject *iter = GetFirstInputObject(AliHLTTRDDefinitions::fgkHiLvlTracksDataType); iter; iter = GetNextInputObject())
307 HLTError("You may not mix high level and low level!");
311 TCAarray[usedEntries] = dynamic_cast<TClonesArray*>(const_cast<TObject*>(iter));
312 if(TCAarray[usedEntries])continue;
313 TObjString* strg = dynamic_cast<TObjString*>(const_cast<TObject*>(GetNextInputObject()));
316 nTimeBins = strg->String().Atoi();
317 fSpec |= GetSpecification(iter);
327 HLTFatal("Number of timebins is negative!");
330 HLTDebug("Saving number of time bins which was read from input block. Value is: %d", nTimeBins);
331 fTRDCalibraFillHisto->Init2Dhistos(nTimeBins); // initialise the histos
332 fTRDCalibraFillHisto->SetNumberClusters(fMinClusters); // At least fMinClusters clusters
333 fTRDCalibraFillHisto->SetNumberClustersf(nTimeBins); // Not more than %d clusters
334 fSavedTimeBins=kTRUE;
337 Bool_t bTriggerPassed = fTakeAllEvents;
341 bTriggerPassed=kFALSE;
342 for(int i = 0; i < fTrgStrings->GetEntriesFast(); i++){
343 const TObjString *const obString=(TObjString*)fTrgStrings->At(i);
344 const TString tString=obString->GetString();
345 if(CheckCTPTrigger(tString.Data())>0){bTriggerPassed=kTRUE; break;}
349 bTriggerPassed=kTRUE;
350 for(int i = 0; i < fTrgStrings->GetEntriesFast(); i++){
351 const TObjString *const obString=(TObjString*)fTrgStrings->At(i);
352 const TString tString=obString->GetString();
353 if(CheckCTPTrigger(tString.Data())>0){bTriggerPassed=kFALSE; break;}
358 fTRDCalibraFillHisto->SetCH2dOn(bTriggerPassed);
359 fTRDCalibraFillHisto->SetPH2dOn(bTriggerPassed);
360 for(int i=0; i<usedEntries; i++){
361 const TClonesArray *const inArr = TCAarray[i];
362 Int_t nbEntries = inArr->GetEntries();
363 HLTDebug(" %i TRDtracks in tracksArray", nbEntries);
364 AliTRDtrackV1* trdTrack = 0x0;
365 for (Int_t ii = 0; ii < nbEntries; ii++){
366 HLTDebug("%i/%i: ", ii+1, nbEntries);
367 trdTrack = (AliTRDtrackV1*)inArr->At(ii);
368 if(trdTrack->GetNumberOfTracklets()<fMinTracklets)continue;
369 fTRDCalibraFillHisto->UpdateHistogramsV1(trdTrack);
370 // for(int i3=0; i3<7; i3++)
371 // if(trdTrack->GetTracklet(i3))trdTrack->GetTracklet(i3)->Bootstrap(fReconstructor);
375 if(!fOutArray->At(0))FormOutput();
376 PushBack(fOutArray, AliHLTTRDDefinitions::fgkCalibrationDataType, fSpec);
379 TCAarray[0]->Delete();
386 * Form output array of histrograms
388 //============================================================================
389 void AliHLTTRDCalibHistoComponent::FormOutput()
392 TH2I *hCH2d = fTRDCalibraFillHisto->GetCH2d();
393 fOutArray->Add(hCH2d);
395 // drift velocity histo
396 TProfile2D *hPH2d = fTRDCalibraFillHisto->GetPH2d();
397 fOutArray->Add(hPH2d);
400 TProfile2D *hPRF2d = fTRDCalibraFillHisto->GetPRF2d();
401 fOutArray->Add(hPRF2d);
404 AliTRDCalibraVdriftLinearFit *hVdriftLinearFitOne=(AliTRDCalibraVdriftLinearFit *)fTRDCalibraFillHisto->GetVdriftLinearFit();
405 fOutArray->Add(hVdriftLinearFitOne);
407 HLTDebug("GetCH2d = 0x%x; NEntries = %i; size = %i", hCH2d, hCH2d->GetEntries(), sizeof(*hCH2d));
409 HLTDebug("GetPH2d = 0x%x; NEntries = %i; size = %i", hPH2d, hPH2d->GetEntries(), sizeof(*hPH2d));
411 HLTDebug("GetPRF2d = 0x%x; NEntries = %i; size = %i", hPRF2d, hPRF2d->GetEntries(), sizeof(*hPRF2d));
413 HLTDebug("GetVdriftLinearFit = 0x%x; size = %i", hVdriftLinearFitOne, sizeof(hVdriftLinearFitOne));
415 HLTDebug("output Array: pointer = 0x%x; NEntries = %i; size = %i", fOutArray, fOutArray->GetEntries(), sizeof(fOutArray));
419 int AliHLTTRDCalibHistoComponent::Reconfigure(const char* cdbEntry, const char* chainId)
421 // see header file for class documentation
424 const char* path="HLT/ConfigTRD/CalibHistoComponent";
425 const char* defaultNotify="";
428 defaultNotify=" (default)";
431 HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
432 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
434 TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
436 HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
437 iResult=Configure(pString->GetString().Data());
439 HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
442 HLTError("cannot fetch object \"%s\" from CDB", path);