Major update required to handle old and new AliHLTEventDDL structures within HLT...
[u/mrichter/AliRoot.git] / HLT / TRD / AliHLTTRDCalibFitComponent.cxx
CommitLineData
cad0c17d 1// $Id: AliHLTTRDCalibFitComponent.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 AliHLTTRDCalibFitComponent.cxx
19// @author Theodor Rascanu
20// @date 25.04.2010
21// @brief A TRDCalibration fitting component for the HLT.
22//
23
24#if __GNUC__ >= 3
25using namespace std;
26#endif
27
28#include "TTree.h"
29#include "TFile.h"
30#include "TBranch.h"
31#include "TH2I.h"
32#include "TH2.h"
33#include "TProfile2D.h"
34
35#include "AliHLTReadoutList.h"
36
37#include "AliHLTTRDCalibFitComponent.h"
38#include "AliHLTTRDDefinitions.h"
39#include "AliHLTTRDUtils.h"
40
41#include "AliRawReaderMemory.h"
42
43#include "AliTRDCalPad.h"
44#include "AliTRDCalDet.h"
45
46#include "AliTRDCalibraFillHisto.h"
47#include "AliTRDtrackV1.h"
48
49#include "AliTRDCalibraFit.h"
50#include "AliTRDCalibraMode.h"
51#include "AliTRDCalibraVector.h"
52#include "AliTRDCalibraVdriftLinearFit.h"
53#include "AliTRDReconstructor.h"
54#include "AliTRDrecoParam.h"
55
56#include <cstdlib>
57#include <cerrno>
58#include <string>
59
60ClassImp(AliHLTTRDCalibFitComponent);
61
62AliHLTTRDCalibFitComponent::AliHLTTRDCalibFitComponent()
63 : AliHLTCalibrationProcessor(),
64 fOutputSize(500000),
65 fOutArray(NULL),
f6fabf3a 66 fAfterRunArray(NULL),
67 fNoOfSM(0),
68 fNoOfIncSM(0)
cad0c17d 69{
70 // Default constructor
71}
72
73AliHLTTRDCalibFitComponent::~AliHLTTRDCalibFitComponent()
74{
75 // Destructor
76}
77
78const char* AliHLTTRDCalibFitComponent::GetComponentID()
79{
80 // Return the component ID const char *
81 return "TRDCalibFit"; // The ID of this component
82}
83
84void AliHLTTRDCalibFitComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
85{
86 // Get the list of input data
87 list.clear(); // We do not have any requirements for our input data type(s).
88 list.push_back(AliHLTTRDDefinitions::fgkCalibrationDataType);
89}
90
91AliHLTComponentDataType AliHLTTRDCalibFitComponent::GetOutputDataType()
92{
93 // Get the output data type
94 return kAliHLTMultipleDataType;
95 // return AliHLTTRDDefinitions::fgkCalibrationDataType;
96
97}
98
99int AliHLTTRDCalibFitComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList)
100{
101 // Get the output data type
102 tgtList.clear();
103 tgtList.push_back(AliHLTTRDDefinitions::fgkCalibrationDataType);
104 tgtList.push_back(AliHLTTRDDefinitions::fgkEORCalibrationDataType);
105 return tgtList.size();
106}
107
108void AliHLTTRDCalibFitComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
109{
110 // Get the output data size
111 constBase = fOutputSize;
112 inputMultiplier = 0;
113}
114
115AliHLTComponent* AliHLTTRDCalibFitComponent::Spawn()
116{
117 // Spawn function, return new instance of this class
118 return new AliHLTTRDCalibFitComponent;
119};
120
121Int_t AliHLTTRDCalibFitComponent::InitCalibration()
122{
123 for(int i=0; i<18; i++)
124 fIncSM[i]=kFALSE;
125
126 fOutArray = new TObjArray(4);
127 fAfterRunArray=new TObjArray(5);
128
129 return 0;
130}
131
132Int_t AliHLTTRDCalibFitComponent::DeinitCalibration()
133{
134
135 // Deinitialization of the component
136
137 HLTDebug("DeinitCalibration");
138 //fOutArray->Delete();
cad0c17d 139 delete fOutArray; fOutArray=0;
140 fAfterRunArray->Delete();
141 delete fAfterRunArray; fAfterRunArray=0;
142 return 0;
143}
144
145Int_t AliHLTTRDCalibFitComponent::ProcessCalibration(const AliHLTComponent_EventData& /*evtData*/,
146 const AliHLTComponent_BlockData* /*blocks*/,
147 AliHLTComponent_TriggerData& /*trigData*/,
148 AliHLTUInt8_t* /*outputPtr*/,
149 AliHLTUInt32_t& /*size*/,
150 vector<AliHLTComponent_BlockData>& /*outputBlocks*/)
151{
152 // Process an event
153
154 if(!IsDataEvent())return 0;
155
156 int lastSM = -1;
157
158 for(const TObject* iter = GetFirstInputObject(AliHLTTRDDefinitions::fgkCalibrationDataType);
159 iter != NULL; iter = GetNextInputObject() ) {
160
161 if(!dynamic_cast<const TObjArray*>(iter))
162 continue;
163
164 AliHLTUInt32_t spec = GetSpecification(iter);
165 int SM = AliHLTTRDUtils::GetSM(spec);
166
167 HLTInfo("Got Data from SM %i", SM);
168
169 if(SM!=lastSM){
170 if(fIncSM[SM]){
f6fabf3a 171 if(fNoOfIncSM<fNoOfSM)
172 return 0;
173 fNoOfSM=fNoOfIncSM;
174 PushBack(fOutArray, AliHLTTRDDefinitions::fgkCalibrationDataType);
cad0c17d 175 fOutArray->Delete();
176 delete fOutArray;
f6fabf3a 177 fOutArray = NULL;
cad0c17d 178 for(int i=0; i<18; i++)
179 fIncSM[i]=kFALSE;
f6fabf3a 180 fNoOfIncSM=0;
cad0c17d 181 }
182 lastSM = SM;
183 fIncSM[SM]=kTRUE;
f6fabf3a 184 fNoOfIncSM++;
cad0c17d 185 }
186
f6fabf3a 187 if(!fOutArray) fOutArray = (TObjArray*)iter->Clone();
cad0c17d 188 else{
189 TObjArray* inArr = (TObjArray*)iter;
190 for(int i = inArr->GetEntriesFast(); i--;){
191 const TH1* histo = dynamic_cast<const TH1*>(inArr->At(i));
192 if(histo){
f6fabf3a 193 if(fOutArray->At(i)){
194 ((TH1*)fOutArray->At(i))->Add(histo);
cad0c17d 195 }else{
f6fabf3a 196 fOutArray->AddAt(histo->Clone(), i);
cad0c17d 197 }
198 continue;
199 }
200 AliTRDCalibraVdriftLinearFit* obj = dynamic_cast<AliTRDCalibraVdriftLinearFit*>(inArr->At(i));
201 if(obj){
f6fabf3a 202 if(fOutArray->At(i)){
203 ((AliTRDCalibraVdriftLinearFit*)fOutArray->At(i))->Add(obj);
cad0c17d 204 }else{
f6fabf3a 205 fOutArray->AddAt(new AliTRDCalibraVdriftLinearFit(*obj), i);
cad0c17d 206 }
207 }
208 }
209 }
210
211 }
212
213 return 0;
214}
215
216Int_t AliHLTTRDCalibFitComponent::ShipDataToFXS(const AliHLTComponentEventData& /*evtData*/, AliHLTComponentTriggerData& /*trigData*/)
217{
218 //fTRDCalibraFillHisto->DestroyDebugStreamer();
219
220 AliHLTReadoutList rdList(AliHLTReadoutList::kTRD);
221
222 EORCalibration();
223
224 fOutArray->Remove(fOutArray->FindObject("AliTRDCalibraVdriftLinearFit"));
225 //fOutArray->Remove(fOutArray->FindObject("PRF2d"));
226 //fOutArray->Remove(fOutArray->FindObject("PH2d"));
227 //fOutArray->Remove(fOutArray->FindObject("CH2d"));
228
229 if(!(fOutArray->FindObject("CH2d"))) {
230 TH2I * ch2d = new TH2I("CH2d","Nz0Nrphi0",100,0.0,300.0,540,0,540);
231 fOutArray->Add(ch2d);
232 }
233
234 if(!(fOutArray->FindObject("PH2d"))) {
235 TProfile2D * ph2d = new TProfile2D("PH2d","Nz0Nrphi0",30,-0.05,2.95,540,0,540);
236 fOutArray->Add(ph2d);
237 }
238
239 if(!(fOutArray->FindObject("PRF2d"))) {
240 TProfile2D * prf2d = new TProfile2D("PRF2d","Nz0Nrphi0Ngp3",60,-9.0,9.0,540,0,540);
241 fOutArray->Add(prf2d);
242 }
243
244 HLTDebug("Size of the fOutArray is %d\n",fOutArray->GetEntriesFast());
245
89413559 246 PushToFXS((TObject*)fOutArray, "TRD", "GAINDRIFTPRF", &rdList );
cad0c17d 247 //PushToFXS((TObject*)fOutArray->FindObject("CH2d"), "TRD", "GAINDRIFTPRF", rdList.Buffer() );
248
249 return 0;
250}
251
252Int_t AliHLTTRDCalibFitComponent::EORCalibration()
253{
254 //Also Fill histograms for the online display
255 TH2I *hCH2d=(TH2I*)fOutArray->FindObject("CH2d");
256 TProfile2D *hPH2d=(TProfile2D*)fOutArray->FindObject("PH2d");
257 TProfile2D *hPRF2d= (TProfile2D*)fOutArray->FindObject("PRF2d");
258 AliTRDCalibraVdriftLinearFit* hVdriftLinearFit = (AliTRDCalibraVdriftLinearFit*)fOutArray->FindObject("AliTRDCalibraVdriftLinearFit");
259
260
261 if(!hCH2d || !hPH2d || !hPRF2d || !hVdriftLinearFit) return 0;
262
263 //Fit
264 AliTRDCalibraFit *calibra = AliTRDCalibraFit::Instance();
265
266 //Gain
267 calibra->SetMinEntries(100);
268 calibra->AnalyseCH(hCH2d);
269 Int_t nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(0))
270 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(0));
271 Int_t nbfit = calibra->GetNumberFit();
272 Int_t nbE = calibra->GetNumberEnt();
273 TH1F *coefgain = 0x0;
274 // enough statistics
275 //if ((nbtg > 0) &&
276 // (nbfit >= 0.2*nbE)) {
277 // create the cal objects
278 //calibra->PutMeanValueOtherVectorFit(1,kTRUE);
279 TObjArray object = calibra->GetVectorFit();
280 AliTRDCalDet *objgaindet = calibra->CreateDetObjectGain(&object,kFALSE);
281 coefgain = objgaindet->MakeHisto1DAsFunctionOfDet();
282 //}
283 calibra->ResetVectorFit();
284
285 // vdrift second method
286 calibra->SetMinEntries(100); // If there is less than 100
287 hVdriftLinearFit->FillPEArray();
288 calibra->AnalyseLinearFitters(hVdriftLinearFit);
289 nbtg = 540;
290 nbfit = calibra->GetNumberFit();
291 nbE = calibra->GetNumberEnt();
292 TH1F *coefdriftsecond = 0x0;
293 // enough statistics
294 //if ((nbtg > 0) &&
295 // (nbfit >= 0.1*nbE)) {
296 // create the cal objects
297 //calibra->PutMeanValueOtherVectorFit(1,kTRUE);
298 object = calibra->GetVectorFit();
299 AliTRDCalDet *objdriftvelocitydetsecond = calibra->CreateDetObjectVdrift(&object,kTRUE);
300 objdriftvelocitydetsecond->SetTitle("secondmethodvdrift");
301 coefdriftsecond = objdriftvelocitydetsecond->MakeHisto1DAsFunctionOfDet();
302 //}
303 calibra->ResetVectorFit();
304
305 // vdrift first method
306 calibra->SetMinEntries(100*20); // If there is less than 20000
307 calibra->AnalysePH(hPH2d);
308 nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(1))
309 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(1));
310 nbfit = calibra->GetNumberFit();
311 nbE = calibra->GetNumberEnt();
312 TH1F *coefdrift = 0x0;
313 TH1F *coeft0 = 0x0;
314 // enough statistics
315 //if ((nbtg > 0) &&
316 // (nbfit >= 0.2*nbE)) {
317 // create the cal objects
318 //calibra->PutMeanValueOtherVectorFit(1,kTRUE);
319 //calibra->PutMeanValueOtherVectorFit2(1,kTRUE);
320 object = calibra->GetVectorFit();
321 AliTRDCalDet *objdriftvelocitydet = calibra->CreateDetObjectVdrift(&object,kTRUE);
322 coefdrift = objdriftvelocitydet->MakeHisto1DAsFunctionOfDet();
323 object = calibra->GetVectorFit2();
324 AliTRDCalDet *objtime0det = calibra->CreateDetObjectT0(&object,kTRUE);
325 coeft0 = objtime0det->MakeHisto1DAsFunctionOfDet();
326 //}
327 calibra->ResetVectorFit();
328
329
330 //PRF
331 calibra->SetMinEntries(200);
332 calibra->AnalysePRFMarianFit(hPRF2d);
333 nbtg = 6*4*18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb0(2))
334 + 6* 18*((Int_t) ((AliTRDCalibraMode *)calibra->GetCalibraMode())->GetDetChamb2(2));
335 nbfit = calibra->GetNumberFit();
336 nbE = calibra->GetNumberEnt();
337 TH1F *coefprf = 0x0;
338 // enough statistics
339 //if ((nbtg > 0) &&
340 // (nbfit >= 0.95*nbE)) {
341 // create cal pad objects
342 object = calibra->GetVectorFit();
343 TObject *objPRFpad = calibra->CreatePadObjectPRF(&object);
344 coefprf = ((AliTRDCalPad *) objPRFpad)->MakeHisto1D();
345 //}
346 calibra->ResetVectorFit();
347
348
349 coefgain->SetName("coefgain");
350 coefprf->SetName("coefprf");
351 coefdrift->SetName("coefdrift");
352 coefdriftsecond->SetName("coefdriftsecond");
353 coeft0->SetName("coeft0");
354 if(coefgain) fAfterRunArray->Add(coefgain);
355 if(coefprf) fAfterRunArray->Add(coefprf);
356 if(coefdrift) fAfterRunArray->Add(coefdrift);
357 if(coefdriftsecond) fAfterRunArray->Add(coefdriftsecond);
358 if(coeft0) fAfterRunArray->Add(coeft0);
359
360
361 if(coefgain||coefprf||coefdrift||coeft0||coefdriftsecond) {
362 PushBack(fAfterRunArray, AliHLTTRDDefinitions::fgkEORCalibrationDataType);
363 }
364
365 // TString fileName="/tmp/CalibHistoDump_run";
366 // fileName+=AliCDBManager::Instance()->GetRun();
367 // fileName+=".root";
368 // HLTInfo("Dumping Histogram file to %s",fileName.Data());
369 // TFile* file = TFile::Open(fileName, "RECREATE");
370 // fAfterRunArray->Write();
371 // fOutArray->Write();
372 // file->Close();
373 // HLTInfo("Histogram file dumped");
374
375 return 0;
376}
377