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