]>
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 | ||
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 "AliHLTTRDCalibFitComponent.h" | |
34 | #include "AliHLTTRDDefinitions.h" | |
35 | #include "AliHLTTRDUtils.h" | |
36 | ||
37 | #include "AliRawReaderMemory.h" | |
38 | ||
39 | #include "AliTRDCalPad.h" | |
40 | #include "AliTRDCalDet.h" | |
41 | ||
42 | #include "AliTRDCalibraFillHisto.h" | |
43 | #include "AliTRDtrackV1.h" | |
44 | ||
45 | #include "AliTRDCalibraFit.h" | |
46 | #include "AliTRDCalibraMode.h" | |
47 | #include "AliTRDCalibraVector.h" | |
48 | #include "AliTRDCalibraVdriftLinearFit.h" | |
49 | #include "AliTRDReconstructor.h" | |
50 | #include "AliTRDrecoParam.h" | |
51 | ||
52 | #include <cstdlib> | |
53 | #include <cerrno> | |
54 | #include <string> | |
55 | ||
a7f38894 | 56 | using namespace std; |
57 | ||
cad0c17d | 58 | ClassImp(AliHLTTRDCalibFitComponent); |
59 | ||
60 | AliHLTTRDCalibFitComponent::AliHLTTRDCalibFitComponent() | |
61 | : AliHLTCalibrationProcessor(), | |
62 | fOutputSize(500000), | |
63 | fOutArray(NULL), | |
f6fabf3a | 64 | fAfterRunArray(NULL), |
65 | fNoOfSM(0), | |
66 | fNoOfIncSM(0) | |
cad0c17d | 67 | { |
68 | // Default constructor | |
288725ab | 69 | |
70 | for(int i=0; i<18; i++) | |
71 | fIncSM[i]=kFALSE; | |
72 | ||
cad0c17d | 73 | } |
74 | ||
75 | AliHLTTRDCalibFitComponent::~AliHLTTRDCalibFitComponent() | |
76 | { | |
77 | // Destructor | |
78 | } | |
79 | ||
80 | const char* AliHLTTRDCalibFitComponent::GetComponentID() | |
81 | { | |
82 | // Return the component ID const char * | |
83 | return "TRDCalibFit"; // The ID of this component | |
84 | } | |
85 | ||
86 | void AliHLTTRDCalibFitComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list) | |
87 | { | |
88 | // Get the list of input data | |
89 | list.clear(); // We do not have any requirements for our input data type(s). | |
90 | list.push_back(AliHLTTRDDefinitions::fgkCalibrationDataType); | |
91 | } | |
92 | ||
93 | AliHLTComponentDataType AliHLTTRDCalibFitComponent::GetOutputDataType() | |
94 | { | |
95 | // Get the output data type | |
96 | return kAliHLTMultipleDataType; | |
97 | // return AliHLTTRDDefinitions::fgkCalibrationDataType; | |
98 | ||
99 | } | |
100 | ||
101 | int AliHLTTRDCalibFitComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList) | |
102 | { | |
103 | // Get the output data type | |
104 | tgtList.clear(); | |
105 | tgtList.push_back(AliHLTTRDDefinitions::fgkCalibrationDataType); | |
106 | tgtList.push_back(AliHLTTRDDefinitions::fgkEORCalibrationDataType); | |
107 | return tgtList.size(); | |
108 | } | |
109 | ||
110 | void AliHLTTRDCalibFitComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) | |
111 | { | |
112 | // Get the output data size | |
113 | constBase = fOutputSize; | |
114 | inputMultiplier = 0; | |
115 | } | |
116 | ||
117 | AliHLTComponent* AliHLTTRDCalibFitComponent::Spawn() | |
118 | { | |
119 | // Spawn function, return new instance of this class | |
120 | return new AliHLTTRDCalibFitComponent; | |
121 | }; | |
122 | ||
123 | Int_t AliHLTTRDCalibFitComponent::InitCalibration() | |
124 | { | |
125 | for(int i=0; i<18; i++) | |
126 | fIncSM[i]=kFALSE; | |
127 | ||
128 | fOutArray = new TObjArray(4); | |
129 | fAfterRunArray=new TObjArray(5); | |
130 | ||
131 | return 0; | |
132 | } | |
133 | ||
134 | Int_t AliHLTTRDCalibFitComponent::DeinitCalibration() | |
135 | { | |
136 | ||
137 | // Deinitialization of the component | |
138 | ||
139 | HLTDebug("DeinitCalibration"); | |
140 | //fOutArray->Delete(); | |
cad0c17d | 141 | delete fOutArray; fOutArray=0; |
142 | fAfterRunArray->Delete(); | |
143 | delete fAfterRunArray; fAfterRunArray=0; | |
144 | return 0; | |
145 | } | |
146 | ||
147 | Int_t AliHLTTRDCalibFitComponent::ProcessCalibration(const AliHLTComponent_EventData& /*evtData*/, | |
148 | const AliHLTComponent_BlockData* /*blocks*/, | |
149 | AliHLTComponent_TriggerData& /*trigData*/, | |
150 | AliHLTUInt8_t* /*outputPtr*/, | |
151 | AliHLTUInt32_t& /*size*/, | |
152 | vector<AliHLTComponent_BlockData>& /*outputBlocks*/) | |
153 | { | |
154 | // Process an event | |
155 | ||
156 | if(!IsDataEvent())return 0; | |
157 | ||
158 | int lastSM = -1; | |
159 | ||
160 | for(const TObject* iter = GetFirstInputObject(AliHLTTRDDefinitions::fgkCalibrationDataType); | |
161 | iter != NULL; iter = GetNextInputObject() ) { | |
162 | ||
163 | if(!dynamic_cast<const TObjArray*>(iter)) | |
164 | continue; | |
165 | ||
166 | AliHLTUInt32_t spec = GetSpecification(iter); | |
167 | int SM = AliHLTTRDUtils::GetSM(spec); | |
168 | ||
169 | HLTInfo("Got Data from SM %i", SM); | |
170 | ||
171 | if(SM!=lastSM){ | |
172 | if(fIncSM[SM]){ | |
f6fabf3a | 173 | if(fNoOfIncSM<fNoOfSM) |
174 | return 0; | |
175 | fNoOfSM=fNoOfIncSM; | |
176 | PushBack(fOutArray, AliHLTTRDDefinitions::fgkCalibrationDataType); | |
cad0c17d | 177 | fOutArray->Delete(); |
178 | delete fOutArray; | |
f6fabf3a | 179 | fOutArray = NULL; |
cad0c17d | 180 | for(int i=0; i<18; i++) |
181 | fIncSM[i]=kFALSE; | |
f6fabf3a | 182 | fNoOfIncSM=0; |
cad0c17d | 183 | } |
184 | lastSM = SM; | |
185 | fIncSM[SM]=kTRUE; | |
f6fabf3a | 186 | fNoOfIncSM++; |
cad0c17d | 187 | } |
188 | ||
f6fabf3a | 189 | if(!fOutArray) fOutArray = (TObjArray*)iter->Clone(); |
cad0c17d | 190 | else{ |
191 | TObjArray* inArr = (TObjArray*)iter; | |
192 | for(int i = inArr->GetEntriesFast(); i--;){ | |
193 | const TH1* histo = dynamic_cast<const TH1*>(inArr->At(i)); | |
194 | if(histo){ | |
f6fabf3a | 195 | if(fOutArray->At(i)){ |
196 | ((TH1*)fOutArray->At(i))->Add(histo); | |
cad0c17d | 197 | }else{ |
f6fabf3a | 198 | fOutArray->AddAt(histo->Clone(), i); |
cad0c17d | 199 | } |
200 | continue; | |
201 | } | |
202 | AliTRDCalibraVdriftLinearFit* obj = dynamic_cast<AliTRDCalibraVdriftLinearFit*>(inArr->At(i)); | |
203 | if(obj){ | |
f6fabf3a | 204 | if(fOutArray->At(i)){ |
205 | ((AliTRDCalibraVdriftLinearFit*)fOutArray->At(i))->Add(obj); | |
cad0c17d | 206 | }else{ |
f6fabf3a | 207 | fOutArray->AddAt(new AliTRDCalibraVdriftLinearFit(*obj), i); |
cad0c17d | 208 | } |
209 | } | |
210 | } | |
211 | } | |
212 | ||
213 | } | |
214 | ||
215 | return 0; | |
216 | } | |
217 | ||
218 | Int_t AliHLTTRDCalibFitComponent::ShipDataToFXS(const AliHLTComponentEventData& /*evtData*/, AliHLTComponentTriggerData& /*trigData*/) | |
219 | { | |
cad0c17d | 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 | ||
252 | Int_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); | |
f5ef4659 | 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(); | |
cad0c17d | 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); | |
f5ef4659 | 289 | //nbtg = 540; |
290 | //nbfit = calibra->GetNumberFit(); | |
291 | //nbE = calibra->GetNumberEnt(); | |
cad0c17d | 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); | |
f5ef4659 | 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(); | |
cad0c17d | 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); | |
f5ef4659 | 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(); | |
cad0c17d | 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"); | |
5e0dedf7 | 354 | fAfterRunArray->Add(coefgain); |
355 | fAfterRunArray->Add(coefprf); | |
356 | fAfterRunArray->Add(coefdrift); | |
357 | fAfterRunArray->Add(coefdriftsecond); | |
358 | fAfterRunArray->Add(coeft0); | |
cad0c17d | 359 | |
fcfd6d99 | 360 | PushBack(fAfterRunArray, AliHLTTRDDefinitions::fgkEORCalibrationDataType); |
cad0c17d | 361 | |
362 | // TString fileName="/tmp/CalibHistoDump_run"; | |
363 | // fileName+=AliCDBManager::Instance()->GetRun(); | |
364 | // fileName+=".root"; | |
365 | // HLTInfo("Dumping Histogram file to %s",fileName.Data()); | |
366 | // TFile* file = TFile::Open(fileName, "RECREATE"); | |
367 | // fAfterRunArray->Write(); | |
368 | // fOutArray->Write(); | |
369 | // file->Close(); | |
370 | // HLTInfo("Histogram file dumped"); | |
371 | ||
372 | return 0; | |
373 | } | |
374 |