1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 //-----------------------------------------------------------------------------
19 /// \file AliMUONChamberCalibrationTask.cxx
20 /// \brief Implementation of the AliMUONChamberCalibrationTask
21 /// \author Andry Rakotozafindrabe CEA/IRFU/SPhN
22 //-----------------------------------------------------------------------------
24 #include <Riostream.h>
28 #include <TClonesArray.h>
36 #include "AliMUONChamberCalibrationTask.h"
39 #include "AliCDBManager.h"
40 #include "AliESDEvent.h"
41 #include "AliESDInputHandler.h"
42 #include "AliESDtrack.h"
43 #include "AliESDMuonTrack.h"
46 #include "AliRecoParam.h"
47 #include "AliTracker.h"
50 #include "AliAnalysisDataSlot.h"
51 #include "AliAnalysisManager.h"
54 #include "AliMpConstants.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"
73 ClassImp( AliMUONChamberCalibrationTask )
76 //______________________________________________________________
77 AliMUONChamberCalibrationTask::AliMUONChamberCalibrationTask():
78 AliAnalysisTaskSE( "AliMUONChamberCalibrationTask" ),
81 fClusterInfoTree(0x0),
83 fESDInputHandler(0x0),
86 fOCDBPath( "local://$ALICE_ROOT/OCDB" )
89 /// Default constructor
92 fClusterInfo = new AliMUONClusterInfo();
93 fESDInterface = new AliMUONESDInterface();
97 //______________________________________________________________
98 AliMUONChamberCalibrationTask::AliMUONChamberCalibrationTask( const char* name,
100 const Int_t my_calib_option ):
101 AliAnalysisTaskSE( name ),
103 fClusterInfoTree(0x0),
105 fESDInputHandler(0x0),
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;
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;
125 //______________________________________________________________
126 AliMUONChamberCalibrationTask::~AliMUONChamberCalibrationTask()
132 if ( fMuonRecoParam ) delete fMuonRecoParam;
133 if ( fClusterInfo ) delete fClusterInfo;
134 if ( fESDInterface ) delete fESDInterface;
137 //______________________________________________________________
138 void AliMUONChamberCalibrationTask::CreateOutputObjects()
141 /// Creates the output TTree
146 TFile* clusterInfoFile = OpenFile( 0, "RECREATE" );
147 if( clusterInfoFile ) clusterInfoFile->SetCompressionLevel(1);
148 else AliError( "no output file created !!!" );
150 if ( !fClusterInfoTree ) fClusterInfoTree = new TTree( "clusterInfoTree", "clusterInfoTree" );
151 fClusterInfoTree->Branch( "clusterInfo" , &fClusterInfo, 32000, 99);
154 //______________________________________________________________
155 void AliMUONChamberCalibrationTask::LocalInit()
159 /// Set the magnetic field, the mapping and the reconstruction parameters
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();
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 );
184 if ( ! AliMpCDB::LoadDDLStore() ) {
185 AliFatal( "Could not access mapping from OCDB !" );
189 // Set the reconstruction parameters for track refitting
190 // (needed when applying any of the with-gain options)
192 fMuonRecoParam = AliMUONRecoParam::GetCosmicParam();
194 TString caliboption1 = "NOGAIN";
195 TString caliboption2 = "GAINCONSTANTCAPA";
196 TString caliboption3 = "GAIN";
197 TString caliboption4 = "INJECTIONGAIN";
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());
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 );
209 fMuonRecoParam->SetMaxNonBendingDistanceToTrack(5.); // was at 1. in default cosmic settings
210 fMuonRecoParam->SetMaxBendingDistanceToTrack(5.);
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
215 AliInfo( "reconstruction parameters initialized as follows :" );
216 fMuonRecoParam->Print("FULL");
218 AliMUONESDInterface::ResetTracker(fMuonRecoParam);
221 //______________________________________________________________
222 void AliMUONChamberCalibrationTask::ConnectInputData( Option_t* /*option*/ )
225 /// Connect to ESD here
231 fESDInputHandler = dynamic_cast<AliESDInputHandler*>(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
234 if ( fESDInputHandler ) {
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 ) {
241 AliFatal( "Could not get input ESD event !!! ");
245 AliError( "Could not get input ESD handler !!!" );
246 // If no input event handler we need to get the tree once
247 // from input slot 0 for the chain
248 tree = dynamic_cast<TTree*> (GetInputData(0));
249 if ( tree ) tree->GetReadEntry();
250 else AliError( "Could not read tree from input slot 0 !!!" );
256 //______________________________________________________________
257 void AliMUONChamberCalibrationTask::Exec( Option_t* /*option*/ )
260 /// Process the current event
261 /// (called for each event)
264 static Bool_t first = kTRUE;
271 if ( !fESDInputEvent ) {
272 AliError( "Input ESD event not available !!! " );
276 // load the current ESD event
277 fESDInterface->LoadEvent( *fESDInputEvent );
280 fDigitStore = fESDInterface->GetDigits();
282 // prepare access to calibration data
283 if ( !fCalibData ) fCalibData = new AliMUONCalibrationData( fESDInputEvent->GetESDRun()->GetRunNumber() );
285 // --------------------------------------------------------------------
286 // fill cluster info from clusters attached to each track of this event
287 // --------------------------------------------------------------------
289 Int_t nTracks = (Int_t)fESDInputEvent->GetNumberOfMuonTracks();
290 if ( nTracks < 1 ) return;
292 TIter nextTrack( fESDInterface->CreateTrackIterator() );
295 while ( (track = static_cast<AliMUONTrack*>(nextTrack())) ) { // loop over tracks
297 UInt_t muonClusterMap = BuildClusterMap( *track );
299 AliMUONTrackParam* trackParam =
300 static_cast<AliMUONTrackParam*>(track->GetTrackParamAtCluster()->First());
302 while ( trackParam ) { // loop over clusters
304 fClusterInfo->Clear("C");
307 AliMUONVCluster* cluster = trackParam->GetClusterPtr();
308 fClusterInfo->SetRunId( fESDInputEvent->GetRunNumber() );
309 fClusterInfo->SetEventId( fESDInputEvent->GetEventNumberInFile() );
310 fClusterInfo->SetZ( cluster->GetZ() );
311 fClusterInfo->SetClusterId( cluster->GetUniqueID() );
312 fClusterInfo->SetClusterXY( cluster->GetX(), cluster->GetY() );
313 fClusterInfo->SetClusterXYErr( cluster->GetErrX(), cluster->GetErrY() );
314 fClusterInfo->SetClusterChi2( cluster->GetChi2() );
315 fClusterInfo->SetClusterCharge( cluster->GetCharge() );
318 fClusterInfo->SetTrackId( track->GetUniqueID() );
319 fClusterInfo->SetTrackXY( trackParam->GetNonBendingCoor(), trackParam->GetBendingCoor() );
320 fClusterInfo->SetTrackThetaXY( TMath::ATan( trackParam->GetNonBendingSlope() ),
321 TMath::ATan( trackParam->GetBendingSlope() ) );
322 fClusterInfo->SetTrackP( trackParam->P() );
323 const TMatrixD paramCov = trackParam->GetCovariances();
324 fClusterInfo->SetTrackXYErr( TMath::Sqrt( paramCov(0,0) ),
325 TMath::Sqrt( paramCov(2,2) ) );
326 fClusterInfo->SetTrackChi2( track->GetNormalizedChi2() );
327 fClusterInfo->SetTrackCharge( (Short_t)trackParam->GetCharge() );
328 fClusterInfo->SetTrackNHits( track->GetNClusters() );
329 fClusterInfo->SetTrackChamberHitMap( muonClusterMap );
331 // fill pad info if available
332 for ( Int_t i=0; i<cluster->GetNDigits(); i++ ) {
334 AliMUONVDigit* digit = fDigitStore->FindObject( cluster->GetDigitId(i) );
335 if ( !digit ) continue;
338 const AliMpVSegmentation* seg = AliMpSegmentation::Instance()->
339 GetMpSegmentation( digit->DetElemId(), AliMp::GetCathodType( digit->Cathode() ) );
340 AliMpPad pad = seg->PadByIndices( digit->PadX(), digit->PadY() );
342 // calibration parameters
343 AliMUONVCalibParam* ped = fCalibData->Pedestals( digit->DetElemId(), digit->ManuId() );
344 AliMUONVCalibParam* gain = fCalibData->Gains( digit->DetElemId(), digit->ManuId() );
345 Int_t manuChannel = digit->ManuChannel();
347 if ( digit->ManuId() & AliMpConstants::ManuMask(AliMp::kNonBendingPlane) ) {
352 AliMUONPadInfo padInfo;
353 padInfo.SetPadId( digit->GetUniqueID() );
354 padInfo.SetPadPlaneType( planeType );
355 padInfo.SetPadXY( pad.GetPositionX(), pad.GetPositionY() );
356 padInfo.SetPadDimXY( pad.GetDimensionX(), pad.GetDimensionY() );
357 padInfo.SetPadCharge( (Double_t)digit->Charge() );
358 padInfo.SetPadADC( digit->ADC() );
359 padInfo.SetSaturated( digit->IsSaturated() );
360 padInfo.SetCalibrated( digit->IsCalibrated() );
361 padInfo.SetPedestal( ped->ValueAsFloatFast(manuChannel,0), // mean
362 ped->ValueAsFloatFast(manuChannel,1) ); // sigma
363 padInfo.SetGain( gain->ValueAsFloatFast(manuChannel,0), // a0
364 gain->ValueAsFloatFast(manuChannel,1), // a1
365 gain->ValueAsFloatFast(manuChannel,2), // threshold
366 gain->ValueAsFloatFast(manuChannel,3) ); // fit quality
368 fClusterInfo->AddPad( padInfo );
371 // fill cluster info tree
372 fClusterInfoTree->Fill();
374 trackParam = static_cast<AliMUONTrackParam*>(track->GetTrackParamAtCluster()->After(trackParam));
378 // Added protection in case the derived task is not an AOD producer.
379 AliAnalysisDataSlot *out0 = GetOutputSlot(0);
380 if (out0 && out0->IsConnected()) PostData( 0, fClusterInfoTree );
385 //______________________________________________________________
386 UInt_t AliMUONChamberCalibrationTask::BuildClusterMap( AliMUONTrack &track )
389 /// Build the map of clusters in tracking chambers
392 UInt_t muonClusterMap = 0;
394 AliMUONTrackParam* trackParam = static_cast<AliMUONTrackParam*>(track.GetTrackParamAtCluster()->First());
395 while ( trackParam ) {
397 muonClusterMap |= BIT(trackParam->GetClusterPtr()->GetChamberId());
399 trackParam = static_cast<AliMUONTrackParam*>(track.GetTrackParamAtCluster()->After(trackParam));
402 return muonClusterMap;
405 //______________________________________________________________
406 void AliMUONChamberCalibrationTask::Terminate( Option_t* /*option*/ )