]>
Commit | Line | Data |
---|---|---|
e4af7295 | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
7 | * Permission to use, copy, modify and distribute this software and its * | |
8 | * documentation strictly for non-commercial purposes is hereby granted * | |
9 | * without fee, provided that the above copyright notice appears in all * | |
10 | * copies and that both the copyright notice and this permission notice * | |
11 | * appear in the supporting documentation. The authors make no claims * | |
12 | * about the suitability of this software for any purpose. It is * | |
13 | * provided "as is" without express or implied warranty. * | |
14 | **************************************************************************/ | |
15 | ||
16 | // $Id$ | |
17 | ||
18 | //----------------------------------------------------------------------------- | |
19 | /// \file AliMUONChamberCalibrationTask.cxx | |
20 | /// \brief Implementation of the AliMUONChamberCalibrationTask | |
21 | /// \author Andry Rakotozafindrabe CEA/IRFU/SPhN | |
22 | //----------------------------------------------------------------------------- | |
23 | ||
24 | #include <Riostream.h> | |
25 | ||
26 | #include <TBranch.h> | |
27 | #include <TChain.h> | |
28 | #include <TClonesArray.h> | |
29 | #include <TFile.h> | |
30 | #include <TMath.h> | |
31 | #include <TRandom.h> | |
32 | #include <TROOT.h> | |
33 | #include <TString.h> | |
34 | #include <TTree.h> | |
35 | ||
36 | #include "AliMUONChamberCalibrationTask.h" | |
37 | ||
38 | // STEER includes | |
39 | #include "AliCDBManager.h" | |
40 | #include "AliESDEvent.h" | |
41 | #include "AliESDInputHandler.h" | |
42 | #include "AliESDtrack.h" | |
43 | #include "AliESDMuonTrack.h" | |
44 | #include "AliLog.h" | |
45 | #include "AliMagF.h" | |
46 | #include "AliRecoParam.h" | |
47 | #include "AliTracker.h" | |
48 | ||
49 | // ANALYSIS includes | |
50 | #include "AliAnalysisDataSlot.h" | |
51 | #include "AliAnalysisManager.h" | |
52 | ||
53 | // MUON includes | |
54 | #include "AliMpConstants.h" | |
55 | #include "AliMpCDB.h" | |
56 | #include "AliMpPad.h" | |
57 | #include "AliMpSegmentation.h" | |
58 | #include "AliMpVSegmentation.h" | |
59 | #include "AliMUONCalibrationData.h" | |
60 | #include "AliMUONClusterInfo.h" | |
61 | #include "AliMUONESDInterface.h" | |
62 | #include "AliMUONPadInfo.h" | |
63 | #include "AliMUONRecoParam.h" | |
64 | #include "AliMUONTrack.h" | |
65 | #include "AliMUONTrackParam.h" | |
66 | #include "AliMUONVCalibParam.h" | |
67 | #include "AliMUONVCluster.h" | |
68 | //#include "AliMUONVClusterStore.h" | |
69 | #include "AliMUONVDigit.h" | |
70 | #include "AliMUONVDigitStore.h" | |
71 | ||
72 | /// \cond CLASSIMP | |
73 | ClassImp( AliMUONChamberCalibrationTask ) | |
74 | /// \endcond CLASSIMP | |
75 | ||
76 | //______________________________________________________________ | |
77 | AliMUONChamberCalibrationTask::AliMUONChamberCalibrationTask(): | |
78 | AliAnalysisTaskSE( "AliMUONChamberCalibrationTask" ), | |
79 | fCalibChoice(NOGAIN), | |
80 | fCalibData(0x0), | |
81 | fClusterInfoTree(0x0), | |
82 | fDigitStore(0x0), | |
83 | fESDInputHandler(0x0), | |
84 | fESDInputEvent(0x0), | |
85 | fMuonRecoParam(0x0), | |
86 | fOCDBPath( "local://$ALICE_ROOT/OCDB" ) | |
87 | { | |
88 | // | |
89 | /// Default constructor | |
90 | // | |
91 | ||
92 | fClusterInfo = new AliMUONClusterInfo(); | |
93 | fESDInterface = new AliMUONESDInterface(); | |
94 | ||
95 | } | |
96 | ||
97 | //______________________________________________________________ | |
98 | AliMUONChamberCalibrationTask::AliMUONChamberCalibrationTask( const char* name, | |
99 | char* ocdbpath, | |
100 | const Int_t my_calib_option ): | |
101 | AliAnalysisTaskSE( name ), | |
102 | fCalibData(0x0), | |
103 | fClusterInfoTree(0x0), | |
104 | fDigitStore(0x0), | |
105 | fESDInputHandler(0x0), | |
106 | fESDInputEvent(0x0), | |
107 | fMuonRecoParam(0x0) | |
108 | { | |
109 | // | |
110 | /// constructor | |
111 | // | |
112 | ||
113 | fClusterInfo = new AliMUONClusterInfo(); | |
114 | fESDInterface = new AliMUONESDInterface(); | |
115 | fOCDBPath = ocdbpath; | |
116 | if ( (my_calib_option >= ((Int_t)NOGAIN)) && (my_calib_option <= ((Int_t)INJECTIONGAIN)) ) | |
117 | fCalibChoice = (Calibration_t)my_calib_option; | |
118 | else { | |
119 | AliWarning( Form("Wrong value of the calibration option %d not within [%d, %d] !!! Will use NOGAIN", | |
120 | my_calib_option, (Int_t)NOGAIN, (Int_t)INJECTIONGAIN ) ); | |
121 | fCalibChoice = NOGAIN; | |
122 | } | |
123 | } | |
124 | ||
125 | //______________________________________________________________ | |
126 | AliMUONChamberCalibrationTask::~AliMUONChamberCalibrationTask() | |
127 | { | |
128 | // | |
129 | /// destructor | |
130 | // | |
131 | ||
132 | if ( fMuonRecoParam ) delete fMuonRecoParam; | |
133 | if ( fClusterInfo ) delete fClusterInfo; | |
134 | if ( fESDInterface ) delete fESDInterface; | |
135 | ||
136 | } | |
137 | //______________________________________________________________ | |
138 | void AliMUONChamberCalibrationTask::CreateOutputObjects() | |
139 | { | |
140 | // | |
141 | /// Creates the output TTree | |
142 | // | |
143 | ||
144 | AliDebug( 1, "" ); | |
145 | ||
146 | TFile* clusterInfoFile = OpenFile( 0, "RECREATE" ); | |
147 | if( clusterInfoFile ) clusterInfoFile->SetCompressionLevel(1); | |
148 | else AliError( "no output file created !!!" ); | |
149 | ||
150 | if ( !fClusterInfoTree ) fClusterInfoTree = new TTree( "clusterInfoTree", "clusterInfoTree" ); | |
151 | fClusterInfoTree->Branch( "clusterInfo" , &fClusterInfo, 32000, 99); | |
152 | } | |
153 | ||
154 | //______________________________________________________________ | |
155 | void AliMUONChamberCalibrationTask::LocalInit() | |
156 | { | |
157 | // | |
158 | /// Initialization | |
159 | /// Set the magnetic field, the mapping and the reconstruction parameters | |
160 | // | |
161 | ||
162 | AliDebug( 1, "" ); | |
163 | ||
164 | gRandom->SetSeed(0); | |
165 | ||
166 | // set mag field | |
167 | ||
168 | if ( !TGeoGlobalMagField::Instance()->GetField() ) { | |
169 | AliInfo( "Loading field map..." ); | |
170 | AliMagF* field = new AliMagF( "Maps","Maps", 2, 1., 1., 10., AliMagF::k5kG ); | |
171 | TGeoGlobalMagField::Instance()->SetField( field ); | |
172 | TGeoGlobalMagField::Instance()->Lock(); | |
173 | } | |
174 | ||
175 | // Load mapping | |
176 | ||
177 | AliCDBManager* man = AliCDBManager::Instance(); | |
178 | man->SetDefaultStorage( fOCDBPath ); | |
179 | man->SetSpecificStorage( "MUON/Calib/MappingData", fOCDBPath ); | |
180 | man->SetSpecificStorage( "MUON/Calib/Mapping", fOCDBPath ); | |
181 | man->SetSpecificStorage( "MUON/Calib/DDLStore", fOCDBPath ); | |
182 | man->Print(); | |
183 | man->SetRun(0); | |
184 | if ( ! AliMpCDB::LoadDDLStore() ) { | |
185 | AliFatal( "Could not access mapping from OCDB !" ); | |
186 | exit(-1); | |
187 | } | |
188 | ||
189 | // Set the reconstruction parameters for track refitting | |
190 | // (needed when applying any of the with-gain options) | |
191 | ||
192 | fMuonRecoParam = AliMUONRecoParam::GetCosmicParam(); | |
193 | ||
194 | TString caliboption1 = "NOGAIN"; | |
195 | TString caliboption2 = "GAINCONSTANTCAPA"; | |
196 | TString caliboption3 = "GAIN"; | |
197 | TString caliboption4 = "INJECTIONGAIN"; | |
198 | ||
199 | TString caliboption = caliboption1; | |
200 | if ( fCalibChoice == GAINCONSTANTCAPA ) caliboption = caliboption2; | |
201 | if ( fCalibChoice == GAIN ) caliboption = caliboption3; | |
202 | if ( fCalibChoice == INJECTIONGAIN ) caliboption = caliboption4; | |
203 | fMuonRecoParam->SetCalibrationMode(caliboption.Data()); | |
204 | ||
205 | for (Int_t iCh=0; iCh<10; iCh++) { | |
206 | fMuonRecoParam->SetDefaultNonBendingReso( iCh, 0.152 ); // input ESD was aligned (default cosmic settings) | |
207 | fMuonRecoParam->SetDefaultBendingReso( iCh, 0.027 ); | |
208 | } | |
209 | fMuonRecoParam->SetMaxNonBendingDistanceToTrack(5.); // was at 1. in default cosmic settings | |
210 | fMuonRecoParam->SetMaxBendingDistanceToTrack(5.); | |
211 | ||
212 | fMuonRecoParam->RequestStation(1, kTRUE); // only St 4 and 5 enabled in default cosmic settings | |
213 | fMuonRecoParam->ImproveTracks(kTRUE, 7.); // was 6. in default cosmic settings | |
214 | ||
215 | AliInfo( "reconstruction parameters initialized as follows :" ); | |
216 | fMuonRecoParam->Print("FULL"); | |
217 | ||
218 | AliMUONESDInterface::ResetTracker(fMuonRecoParam); | |
219 | } | |
220 | ||
221 | //______________________________________________________________ | |
222 | void AliMUONChamberCalibrationTask::ConnectInputData( Option_t* /*option*/ ) | |
223 | { | |
224 | // | |
225 | /// Connect to ESD here | |
226 | /// (called once) | |
227 | // | |
228 | ||
229 | AliDebug( 1, "" ); | |
230 | ||
231 | fESDInputHandler = dynamic_cast<AliESDInputHandler*>(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()); | |
232 | TTree* tree = NULL; | |
233 | ||
234 | if ( fESDInputHandler ) { | |
235 | ||
236 | // The properly initialized ESD input handler reads ESD tree | |
237 | // and connect it to ESD event, so we only need to retrieve the later | |
238 | fESDInputEvent = fESDInputHandler->GetEvent(); | |
239 | if ( !fESDInputEvent ) { | |
240 | ||
241 | AliFatal( "Could not get input ESD event !!! "); | |
242 | ||
f2deabf0 | 243 | } |
244 | } else { | |
e4af7295 | 245 | |
246 | AliError( "Could not get input ESD handler !!!" ); | |
247 | // If no input event handler we need to get the tree once | |
248 | // from input slot 0 for the chain | |
249 | tree = dynamic_cast<TTree*> (GetInputData(0)); | |
250 | if ( tree ) tree->GetReadEntry(); | |
f2deabf0 | 251 | else AliFatal( "Could not read tree from input slot 0 !!!" ); |
e4af7295 | 252 | } |
e4af7295 | 253 | } |
254 | ||
255 | //______________________________________________________________ | |
256 | void AliMUONChamberCalibrationTask::Exec( Option_t* /*option*/ ) | |
257 | { | |
258 | // | |
259 | /// Process the current event | |
260 | /// (called for each event) | |
261 | // | |
262 | ||
263 | static Bool_t first = kTRUE; | |
264 | ||
265 | if ( first ) { | |
266 | AliDebug( 1, "" ); | |
267 | first = kFALSE; | |
268 | } | |
269 | ||
270 | if ( !fESDInputEvent ) { | |
271 | AliError( "Input ESD event not available !!! " ); | |
272 | return; | |
273 | } | |
274 | ||
275 | // load the current ESD event | |
276 | fESDInterface->LoadEvent( *fESDInputEvent ); | |
277 | ||
278 | // get digit store | |
279 | fDigitStore = fESDInterface->GetDigits(); | |
280 | ||
281 | // prepare access to calibration data | |
282 | if ( !fCalibData ) fCalibData = new AliMUONCalibrationData( fESDInputEvent->GetESDRun()->GetRunNumber() ); | |
283 | ||
284 | // -------------------------------------------------------------------- | |
285 | // fill cluster info from clusters attached to each track of this event | |
286 | // -------------------------------------------------------------------- | |
287 | ||
288 | Int_t nTracks = (Int_t)fESDInputEvent->GetNumberOfMuonTracks(); | |
289 | if ( nTracks < 1 ) return; | |
290 | ||
291 | TIter nextTrack( fESDInterface->CreateTrackIterator() ); | |
292 | AliMUONTrack* track; | |
293 | ||
294 | while ( (track = static_cast<AliMUONTrack*>(nextTrack())) ) { // loop over tracks | |
295 | ||
296 | UInt_t muonClusterMap = BuildClusterMap( *track ); | |
297 | ||
298 | AliMUONTrackParam* trackParam = | |
299 | static_cast<AliMUONTrackParam*>(track->GetTrackParamAtCluster()->First()); | |
300 | ||
301 | while ( trackParam ) { // loop over clusters | |
302 | ||
303 | fClusterInfo->Clear("C"); | |
304 | ||
305 | // fill cluster info | |
306 | AliMUONVCluster* cluster = trackParam->GetClusterPtr(); | |
307 | fClusterInfo->SetRunId( fESDInputEvent->GetRunNumber() ); | |
308 | fClusterInfo->SetEventId( fESDInputEvent->GetEventNumberInFile() ); | |
309 | fClusterInfo->SetZ( cluster->GetZ() ); | |
310 | fClusterInfo->SetClusterId( cluster->GetUniqueID() ); | |
311 | fClusterInfo->SetClusterXY( cluster->GetX(), cluster->GetY() ); | |
312 | fClusterInfo->SetClusterXYErr( cluster->GetErrX(), cluster->GetErrY() ); | |
313 | fClusterInfo->SetClusterChi2( cluster->GetChi2() ); | |
314 | fClusterInfo->SetClusterCharge( cluster->GetCharge() ); | |
315 | ||
316 | // fill track info | |
317 | fClusterInfo->SetTrackId( track->GetUniqueID() ); | |
318 | fClusterInfo->SetTrackXY( trackParam->GetNonBendingCoor(), trackParam->GetBendingCoor() ); | |
319 | fClusterInfo->SetTrackThetaXY( TMath::ATan( trackParam->GetNonBendingSlope() ), | |
320 | TMath::ATan( trackParam->GetBendingSlope() ) ); | |
321 | fClusterInfo->SetTrackP( trackParam->P() ); | |
322 | const TMatrixD paramCov = trackParam->GetCovariances(); | |
323 | fClusterInfo->SetTrackXYErr( TMath::Sqrt( paramCov(0,0) ), | |
324 | TMath::Sqrt( paramCov(2,2) ) ); | |
325 | fClusterInfo->SetTrackChi2( track->GetNormalizedChi2() ); | |
326 | fClusterInfo->SetTrackCharge( (Short_t)trackParam->GetCharge() ); | |
327 | fClusterInfo->SetTrackNHits( track->GetNClusters() ); | |
328 | fClusterInfo->SetTrackChamberHitMap( muonClusterMap ); | |
329 | ||
330 | // fill pad info if available | |
331 | for ( Int_t i=0; i<cluster->GetNDigits(); i++ ) { | |
332 | ||
333 | AliMUONVDigit* digit = fDigitStore->FindObject( cluster->GetDigitId(i) ); | |
334 | if ( !digit ) continue; | |
335 | ||
336 | // pad location | |
337 | const AliMpVSegmentation* seg = AliMpSegmentation::Instance()-> | |
338 | GetMpSegmentation( digit->DetElemId(), AliMp::GetCathodType( digit->Cathode() ) ); | |
339 | AliMpPad pad = seg->PadByIndices( digit->PadX(), digit->PadY() ); | |
340 | ||
341 | // calibration parameters | |
342 | AliMUONVCalibParam* ped = fCalibData->Pedestals( digit->DetElemId(), digit->ManuId() ); | |
343 | AliMUONVCalibParam* gain = fCalibData->Gains( digit->DetElemId(), digit->ManuId() ); | |
344 | Int_t manuChannel = digit->ManuChannel(); | |
345 | Int_t planeType = 0; | |
346 | if ( digit->ManuId() & AliMpConstants::ManuMask(AliMp::kNonBendingPlane) ) { | |
347 | planeType = 1; | |
348 | } | |
349 | ||
350 | // fill pad info | |
351 | AliMUONPadInfo padInfo; | |
352 | padInfo.SetPadId( digit->GetUniqueID() ); | |
353 | padInfo.SetPadPlaneType( planeType ); | |
354 | padInfo.SetPadXY( pad.GetPositionX(), pad.GetPositionY() ); | |
355 | padInfo.SetPadDimXY( pad.GetDimensionX(), pad.GetDimensionY() ); | |
356 | padInfo.SetPadCharge( (Double_t)digit->Charge() ); | |
357 | padInfo.SetPadADC( digit->ADC() ); | |
358 | padInfo.SetSaturated( digit->IsSaturated() ); | |
359 | padInfo.SetCalibrated( digit->IsCalibrated() ); | |
360 | padInfo.SetPedestal( ped->ValueAsFloatFast(manuChannel,0), // mean | |
361 | ped->ValueAsFloatFast(manuChannel,1) ); // sigma | |
362 | padInfo.SetGain( gain->ValueAsFloatFast(manuChannel,0), // a0 | |
363 | gain->ValueAsFloatFast(manuChannel,1), // a1 | |
364 | gain->ValueAsFloatFast(manuChannel,2), // threshold | |
365 | gain->ValueAsFloatFast(manuChannel,3) ); // fit quality | |
366 | ||
367 | fClusterInfo->AddPad( padInfo ); | |
368 | } | |
369 | ||
370 | // fill cluster info tree | |
371 | fClusterInfoTree->Fill(); | |
372 | ||
373 | trackParam = static_cast<AliMUONTrackParam*>(track->GetTrackParamAtCluster()->After(trackParam)); | |
374 | } | |
375 | ||
376 | } | |
377 | // Added protection in case the derived task is not an AOD producer. | |
378 | AliAnalysisDataSlot *out0 = GetOutputSlot(0); | |
379 | if (out0 && out0->IsConnected()) PostData( 0, fClusterInfoTree ); | |
380 | ||
381 | } | |
382 | ||
383 | ||
384 | //______________________________________________________________ | |
385 | UInt_t AliMUONChamberCalibrationTask::BuildClusterMap( AliMUONTrack &track ) | |
386 | { | |
387 | // | |
388 | /// Build the map of clusters in tracking chambers | |
389 | // | |
390 | ||
391 | UInt_t muonClusterMap = 0; | |
392 | ||
393 | AliMUONTrackParam* trackParam = static_cast<AliMUONTrackParam*>(track.GetTrackParamAtCluster()->First()); | |
394 | while ( trackParam ) { | |
395 | ||
396 | muonClusterMap |= BIT(trackParam->GetClusterPtr()->GetChamberId()); | |
397 | ||
398 | trackParam = static_cast<AliMUONTrackParam*>(track.GetTrackParamAtCluster()->After(trackParam)); | |
399 | } | |
400 | ||
401 | return muonClusterMap; | |
402 | } | |
403 | ||
404 | //______________________________________________________________ | |
405 | void AliMUONChamberCalibrationTask::Terminate( Option_t* /*option*/ ) | |
406 | { | |
f2deabf0 | 407 | // |
408 | /// Called once per task on the client machine at the end of the analysis. | |
409 | // | |
410 | ||
e4af7295 | 411 | AliDebug( 1, "" ); |
412 | } |