]>
Commit | Line | Data |
---|---|---|
cad0c17d | 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 | ||
cad0c17d | 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 | ||
a7f38894 | 59 | using namespace std; |
60 | ||
cad0c17d | 61 | ClassImp(AliHLTTRDCalibHistoComponent); |
62 | ||
63 | AliHLTTRDCalibHistoComponent::AliHLTTRDCalibHistoComponent() | |
64 | : AliHLTProcessor(), | |
65 | fOutputSize(500000), | |
66 | fSpec(0), | |
67 | fTracksArray(NULL), | |
68 | fOutArray(NULL), | |
69 | fTRDCalibraFillHisto(NULL), | |
70 | fSavedTimeBins(kFALSE), | |
71 | fTrgStrings(NULL), | |
72 | fAccRejTrg(0), | |
73 | fMinClusters(0), | |
74 | fMinTracklets(0), | |
75 | fTakeAllEvents(kFALSE) | |
76 | { | |
77 | // Default constructor | |
78 | } | |
79 | ||
80 | AliHLTTRDCalibHistoComponent::~AliHLTTRDCalibHistoComponent() | |
81 | { | |
82 | // Destructor | |
83 | } | |
84 | ||
85 | const char* AliHLTTRDCalibHistoComponent::GetComponentID() | |
86 | { | |
87 | // Return the component ID const char * | |
88 | 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 | list.clear(); // We do not have any requirements for our input data type(s). | |
95 | list.push_back(AliHLTTRDDefinitions::fgkTracksDataType); | |
96 | } | |
97 | ||
98 | AliHLTComponentDataType AliHLTTRDCalibHistoComponent::GetOutputDataType() | |
99 | { | |
100 | // Get the output data type | |
101 | return kAliHLTMultipleDataType; | |
102 | // return AliHLTTRDDefinitions::fgkCalibrationDataType; | |
103 | ||
104 | } | |
105 | ||
106 | int AliHLTTRDCalibHistoComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList) | |
107 | { | |
108 | // Get the output data type | |
109 | tgtList.clear(); | |
110 | tgtList.push_back(AliHLTTRDDefinitions::fgkCalibrationDataType); | |
111 | return tgtList.size(); | |
112 | } | |
113 | ||
114 | void AliHLTTRDCalibHistoComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) | |
115 | { | |
116 | // Get the output data size | |
117 | constBase = fOutputSize; | |
118 | inputMultiplier = 0; | |
119 | } | |
120 | ||
121 | AliHLTComponent* AliHLTTRDCalibHistoComponent::Spawn() | |
122 | { | |
123 | // Spawn function, return new instance of this class | |
124 | return new AliHLTTRDCalibHistoComponent; | |
125 | }; | |
126 | ||
127 | int AliHLTTRDCalibHistoComponent::DoInit( int argc, const char** argv ) | |
128 | { | |
129 | int iResult=0; | |
130 | if(fTrgStrings) | |
131 | delete fTrgStrings; | |
132 | fTrgStrings = new TObjArray(); | |
133 | ||
134 | TString configuration=""; | |
135 | TString argument=""; | |
136 | for (int i=0; i<argc && iResult>=0; i++) { | |
137 | argument=argv[i]; | |
138 | if (!configuration.IsNull()) configuration+=" "; | |
139 | configuration+=argument; | |
140 | } | |
141 | ||
142 | if (!configuration.IsNull()) { | |
143 | iResult=Configure(configuration.Data()); | |
144 | } else { | |
145 | iResult=Reconfigure(NULL, NULL); | |
146 | } | |
147 | if(iResult>=0){ | |
148 | iResult=SetParams(); | |
149 | } | |
150 | return iResult; | |
151 | } | |
152 | ||
153 | int AliHLTTRDCalibHistoComponent::Configure(const char* arguments){ | |
154 | int iResult=0; | |
155 | if (!arguments) return iResult; | |
156 | ||
157 | TString allArgs=arguments; | |
158 | TString argument; | |
159 | int bMissingParam=0; | |
160 | ||
161 | TObjArray* pTokens=allArgs.Tokenize(" "); | |
162 | if (pTokens) { | |
163 | for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) { | |
164 | argument=((TObjString*)pTokens->At(i))->GetString(); | |
165 | if (argument.IsNull()) continue; | |
166 | ||
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(); | |
171 | continue; | |
172 | } | |
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(); | |
177 | continue; | |
178 | } | |
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(); | |
183 | continue; | |
184 | } | |
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())); | |
189 | continue; | |
190 | } | |
191 | else if (argument.CompareTo("-acceptTrgStr")==0) { | |
192 | fAccRejTrg=1; | |
193 | HLTInfo("Accept selected Trigger Strings only"); | |
194 | continue; | |
195 | } | |
196 | else if (argument.CompareTo("-rejectTrgStr")==0) { | |
197 | fAccRejTrg=-1; | |
198 | HLTInfo("Reject all selected Trigger Strings"); | |
199 | continue; | |
200 | } | |
201 | else if (argument.CompareTo("-takeAllEvents")==0) { | |
202 | fAccRejTrg=0; | |
203 | fTakeAllEvents = kTRUE; | |
204 | HLTInfo("Take all events independently of the trigger strings"); | |
205 | continue; | |
206 | } | |
207 | ||
208 | else { | |
209 | HLTError("unknown argument: %s", argument.Data()); | |
210 | iResult=-EINVAL; | |
211 | break; | |
212 | } | |
213 | } | |
214 | delete pTokens; | |
215 | } | |
216 | if (bMissingParam) { | |
217 | HLTError("missing parameter for argument %s", argument.Data()); | |
218 | iResult=-EINVAL; | |
219 | } | |
220 | return iResult; | |
221 | } | |
222 | ||
223 | int AliHLTTRDCalibHistoComponent::SetParams() | |
224 | { | |
225 | ||
226 | if(!fTrgStrings) | |
227 | fTrgStrings = new TObjArray(); | |
228 | ||
229 | if(!AliCDBManager::Instance()->IsDefaultStorageSet()){ | |
230 | HLTError("DefaultStorage is not set in CDBManager"); | |
231 | return -EINVAL; | |
232 | } | |
233 | if(AliCDBManager::Instance()->GetRun()<0){ | |
234 | HLTError("Run Number is not set in CDBManager"); | |
235 | return -EINVAL; | |
236 | } | |
237 | HLTInfo("CDB default storage: %s; RunNo: %i", (AliCDBManager::Instance()->GetDefaultStorage()->GetBaseFolder()).Data(), AliCDBManager::Instance()->GetRun()); | |
238 | ||
239 | if(fTrgStrings->GetEntriesFast()>0 && !fAccRejTrg){ | |
240 | HLTError("Trigger string(s) given, but acceptTrgStr or rejectTrgStr not selected"); | |
241 | return -EINVAL; | |
242 | } | |
243 | ||
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); | |
255 | ||
256 | if(!fTracksArray) fTracksArray = new TClonesArray("AliTRDtrackV1"); | |
257 | if(!fOutArray)fOutArray = new TObjArray(4); | |
258 | ||
259 | HLTDebug("run SetupCTPData"); | |
260 | SetupCTPData(); | |
261 | ||
262 | return 0; | |
263 | } | |
264 | ||
265 | int AliHLTTRDCalibHistoComponent::DoDeinit() | |
266 | { | |
267 | ||
268 | // Deinitialization of the component | |
269 | ||
270 | HLTDebug("DeinitCalibration"); | |
271 | delete fTracksArray; fTracksArray=0; | |
3310c421 | 272 | fTRDCalibraFillHisto->DestroyDebugStreamer(); |
cad0c17d | 273 | //fTRDCalibraFillHisto->Destroy(); |
274 | //fOutArray->Delete(); | |
275 | delete fOutArray; fOutArray=0; | |
276 | fTrgStrings->Delete(); | |
277 | delete fTrgStrings; fTrgStrings=0; | |
278 | 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 | 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; | |
294 | ||
295 | for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(AliHLTTRDDefinitions::fgkTracksDataType); pBlock; pBlock=GetNextInputBlock()) | |
296 | { | |
297 | TCAarray[0] = fTracksArray; | |
298 | AliHLTTRDUtils::ReadTracks(TCAarray[0], pBlock->fPtr, pBlock->fSize, &nTimeBins); | |
299 | fSpec |= pBlock->fSpecification; | |
300 | usedEntries = 1; | |
301 | blockOrObject = -1; | |
302 | } | |
303 | ||
304 | for(const TObject *iter = GetFirstInputObject(AliHLTTRDDefinitions::fgkHiLvlTracksDataType); iter; iter = GetNextInputObject()) | |
305 | { | |
306 | if(blockOrObject<0){ | |
307 | HLTError("You may not mix high level and low level!"); | |
308 | return -1; | |
309 | } | |
310 | ||
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())); | |
314 | if(!strg)continue; | |
315 | ||
316 | nTimeBins = strg->String().Atoi(); | |
317 | fSpec |= GetSpecification(iter); | |
318 | usedEntries++; | |
319 | blockOrObject = 1; | |
320 | } | |
321 | ||
322 | if(!blockOrObject) | |
323 | return 0; | |
324 | ||
325 | if(!fSavedTimeBins){ | |
326 | if(nTimeBins<0){ | |
327 | HLTFatal("Number of timebins is negative!"); | |
328 | return -1; | |
329 | } | |
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; | |
335 | } | |
336 | ||
337 | Bool_t bTriggerPassed = fTakeAllEvents; | |
338 | ||
339 | if(fAccRejTrg){ | |
340 | if(fAccRejTrg>0){ | |
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;} | |
346 | } | |
347 | } | |
348 | else{ | |
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;} | |
354 | } | |
355 | } | |
356 | } | |
357 | ||
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); | |
372 | } | |
373 | } | |
374 | ||
375 | if(!fOutArray->At(0))FormOutput(); | |
376 | PushBack(fOutArray, AliHLTTRDDefinitions::fgkCalibrationDataType, fSpec); | |
377 | ||
45546e5d | 378 | if(blockOrObject<0){ |
379 | TCAarray[0]->Delete(); | |
380 | } | |
381 | ||
cad0c17d | 382 | return 0; |
383 | } | |
384 | ||
385 | /** | |
386 | * Form output array of histrograms | |
387 | */ | |
388 | //============================================================================ | |
389 | void AliHLTTRDCalibHistoComponent::FormOutput() | |
390 | { | |
391 | // gain histo | |
392 | TH2I *hCH2d = fTRDCalibraFillHisto->GetCH2d(); | |
393 | fOutArray->Add(hCH2d); | |
394 | ||
395 | // drift velocity histo | |
396 | TProfile2D *hPH2d = fTRDCalibraFillHisto->GetPH2d(); | |
397 | fOutArray->Add(hPH2d); | |
398 | ||
399 | // PRF histo | |
400 | TProfile2D *hPRF2d = fTRDCalibraFillHisto->GetPRF2d(); | |
401 | fOutArray->Add(hPRF2d); | |
402 | ||
403 | // Vdrift Linear Fit | |
404 | AliTRDCalibraVdriftLinearFit *hVdriftLinearFitOne=(AliTRDCalibraVdriftLinearFit *)fTRDCalibraFillHisto->GetVdriftLinearFit(); | |
405 | fOutArray->Add(hVdriftLinearFitOne); | |
406 | ||
407 | HLTDebug("GetCH2d = 0x%x; NEntries = %i; size = %i", hCH2d, hCH2d->GetEntries(), sizeof(*hCH2d)); | |
408 | hCH2d->Print(); | |
409 | HLTDebug("GetPH2d = 0x%x; NEntries = %i; size = %i", hPH2d, hPH2d->GetEntries(), sizeof(*hPH2d)); | |
410 | hPH2d->Print(); | |
411 | HLTDebug("GetPRF2d = 0x%x; NEntries = %i; size = %i", hPRF2d, hPRF2d->GetEntries(), sizeof(*hPRF2d)); | |
412 | 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 | } | |
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 | if (cdbEntry) { | |
427 | path=cdbEntry; | |
428 | defaultNotify=" (default)"; | |
429 | } | |
430 | if (path) { | |
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()*/); | |
433 | if (pEntry) { | |
434 | TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject()); | |
435 | if (pString) { | |
436 | HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data()); | |
437 | iResult=Configure(pString->GetString().Data()); | |
438 | } else { | |
439 | HLTError("configuration object \"%s\" has wrong type, required TObjString", path); | |
440 | } | |
441 | } else { | |
442 | HLTError("cannot fetch object \"%s\" from CDB", path); | |
443 | } | |
444 | } | |
445 | ||
446 | return iResult; | |
447 | } |