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" ),
79 fOCDBPath( "local://$ALICE_ROOT/OCDB" ),
81 fClusterInfoTree(0x0),
87 fESDInputHandler(0x0),
91 /// Default constructor
96 //______________________________________________________________
97 AliMUONChamberCalibrationTask::AliMUONChamberCalibrationTask( const char* name,
99 const Int_t my_calib_option ):
100 AliAnalysisTaskSE( name ),
101 fOCDBPath( "local://$ALICE_ROOT/OCDB" ),
102 fCalibChoice(NOGAIN),
103 fClusterInfoTree(0x0),
109 fESDInputHandler(0x0),
116 fOCDBPath = ocdbpath;
117 if ( (my_calib_option >= ((Int_t)NOGAIN)) && (my_calib_option <= ((Int_t)INJECTIONGAIN)) )
118 fCalibChoice = (Calibration_t)my_calib_option;
120 AliWarning( Form("Wrong value of the calibration option %d not within [%d, %d] !!! Will use NOGAIN",
121 my_calib_option, (Int_t)NOGAIN, (Int_t)INJECTIONGAIN ) );
122 fCalibChoice = NOGAIN;
126 //______________________________________________________________
127 AliMUONChamberCalibrationTask::~AliMUONChamberCalibrationTask()
133 delete fMuonRecoParam;
135 delete fESDInterface;
138 //______________________________________________________________
139 void AliMUONChamberCalibrationTask::CreateOutputObjects()
142 /// Creates the output TTree
147 TFile* clusterInfoFile = OpenFile( 0, "RECREATE" );
148 if( clusterInfoFile ) clusterInfoFile->SetCompressionLevel(1);
149 else AliError( "no output file created !!!" );
151 if ( !fClusterInfoTree ) fClusterInfoTree = new TTree( "clusterInfoTree", "clusterInfoTree" );
152 fClusterInfoTree->Branch( "clusterInfo" , &fClusterInfo, 32000, 99);
155 //______________________________________________________________
156 void AliMUONChamberCalibrationTask::LocalInit()
160 /// Initialize the cluster info and the ESD interface
161 /// Set the magnetic field, the mapping and the reconstruction parameters
166 // initialize the cluster info and the ESD interface
168 fClusterInfo = new AliMUONClusterInfo();
169 fESDInterface = new AliMUONESDInterface();
175 if ( !TGeoGlobalMagField::Instance()->GetField() ) {
176 AliInfo( "Loading field map..." );
177 AliMagF* field = new AliMagF( "Maps","Maps", 2, 1., 1., 10., AliMagF::k5kG );
178 TGeoGlobalMagField::Instance()->SetField( field );
179 TGeoGlobalMagField::Instance()->Lock();
184 AliCDBManager* man = AliCDBManager::Instance();
185 man->SetDefaultStorage( fOCDBPath );
186 man->SetSpecificStorage( "MUON/Calib/MappingData", fOCDBPath );
187 man->SetSpecificStorage( "MUON/Calib/MappingRunData", fOCDBPath ); // for the manu serial numbers
190 if ( ! AliMpCDB::LoadDDLStore() ) {
191 AliFatal( "Could not access mapping from OCDB !" );
195 // Set the reconstruction parameters for track refitting
196 // (needed when applying any of the with-gain options)
198 fMuonRecoParam = AliMUONRecoParam::GetCosmicParam();
200 TString caliboption1 = "NOGAIN";
201 TString caliboption2 = "GAINCONSTANTCAPA";
202 TString caliboption3 = "GAIN";
203 TString caliboption4 = "INJECTIONGAIN";
205 TString caliboption = caliboption1;
206 if ( fCalibChoice == GAINCONSTANTCAPA ) caliboption = caliboption2;
207 if ( fCalibChoice == GAIN ) caliboption = caliboption3;
208 if ( fCalibChoice == INJECTIONGAIN ) caliboption = caliboption4;
209 fMuonRecoParam->SetCalibrationMode(caliboption.Data());
211 for (Int_t iCh=0; iCh<10; iCh++) {
212 fMuonRecoParam->SetDefaultNonBendingReso( iCh, 0.152 ); // input ESD was aligned (default cosmic settings)
213 fMuonRecoParam->SetDefaultBendingReso( iCh, 0.027 );
215 fMuonRecoParam->SetMaxNonBendingDistanceToTrack(5.); // was at 1. in default cosmic settings
216 fMuonRecoParam->SetMaxBendingDistanceToTrack(5.);
218 fMuonRecoParam->RequestStation(1, kTRUE); // only St 4 and 5 enabled in default cosmic settings
219 fMuonRecoParam->ImproveTracks(kTRUE, 7.); // was 6. in default cosmic settings
221 AliInfo( "reconstruction parameters initialized as follows :" );
222 fMuonRecoParam->Print("FULL");
224 AliMUONESDInterface::ResetTracker(fMuonRecoParam);
227 //______________________________________________________________
228 void AliMUONChamberCalibrationTask::ConnectInputData( Option_t* /*option*/ )
231 /// Connect to ESD here
237 fESDInputHandler = dynamic_cast<AliESDInputHandler*>(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
240 if ( fESDInputHandler ) {
242 // The properly initialized ESD input handler reads ESD tree
243 // and connect it to ESD event, so we only need to retrieve the later
244 fESDInputEvent = fESDInputHandler->GetEvent();
245 if ( !fESDInputEvent ) {
247 AliFatal( "Could not get input ESD event !!! ");
252 AliError( "Could not get input ESD handler !!!" );
253 // If no input event handler we need to get the tree once
254 // from input slot 0 for the chain
255 tree = dynamic_cast<TTree*> (GetInputData(0));
256 if ( tree ) tree->GetReadEntry();
257 else AliFatal( "Could not read tree from input slot 0 !!!" );
261 //______________________________________________________________
262 void AliMUONChamberCalibrationTask::Exec( Option_t* /*option*/ )
265 /// Process the current event
266 /// (called for each event)
269 static Bool_t first = kTRUE;
276 if ( !fESDInputEvent ) {
277 AliError( "Input ESD event not available !!! " );
281 // load the current ESD event
282 fESDInterface->LoadEvent( *fESDInputEvent );
285 fDigitStore = fESDInterface->GetDigits();
287 // prepare access to calibration data
288 if ( !fCalibData ) fCalibData = new AliMUONCalibrationData( fESDInputEvent->GetESDRun()->GetRunNumber() );
290 // --------------------------------------------------------------------
291 // fill cluster info from clusters attached to each track of this event
292 // --------------------------------------------------------------------
294 Int_t nTracks = (Int_t)fESDInputEvent->GetNumberOfMuonTracks();
295 if ( nTracks < 1 ) return;
297 TIter nextTrack( fESDInterface->CreateTrackIterator() );
300 while ( (track = static_cast<AliMUONTrack*>(nextTrack())) ) { // loop over tracks
302 UInt_t muonClusterMap = BuildClusterMap( *track );
304 AliMUONTrackParam* trackParam =
305 static_cast<AliMUONTrackParam*>(track->GetTrackParamAtCluster()->First());
307 while ( trackParam ) { // loop over clusters
309 fClusterInfo->Clear("C");
312 AliMUONVCluster* cluster = trackParam->GetClusterPtr();
313 fClusterInfo->SetRunId( fESDInputEvent->GetRunNumber() );
314 fClusterInfo->SetEventId( fESDInputEvent->GetEventNumberInFile() );
315 fClusterInfo->SetZ( cluster->GetZ() );
316 fClusterInfo->SetClusterId( cluster->GetUniqueID() );
317 fClusterInfo->SetClusterXY( cluster->GetX(), cluster->GetY() );
318 fClusterInfo->SetClusterXYErr( cluster->GetErrX(), cluster->GetErrY() );
319 fClusterInfo->SetClusterChi2( cluster->GetChi2() );
320 fClusterInfo->SetClusterCharge( cluster->GetCharge() );
323 fClusterInfo->SetTrackId( track->GetUniqueID() );
324 fClusterInfo->SetTrackXY( trackParam->GetNonBendingCoor(), trackParam->GetBendingCoor() );
325 fClusterInfo->SetTrackThetaXY( TMath::ATan( trackParam->GetNonBendingSlope() ),
326 TMath::ATan( trackParam->GetBendingSlope() ) );
327 fClusterInfo->SetTrackP( trackParam->P() );
328 const TMatrixD paramCov = trackParam->GetCovariances();
329 fClusterInfo->SetTrackXYErr( TMath::Sqrt( paramCov(0,0) ),
330 TMath::Sqrt( paramCov(2,2) ) );
331 fClusterInfo->SetTrackChi2( track->GetNormalizedChi2() );
332 fClusterInfo->SetTrackCharge( (Short_t)trackParam->GetCharge() );
333 fClusterInfo->SetTrackNHits( track->GetNClusters() );
334 fClusterInfo->SetTrackChamberHitMap( muonClusterMap );
336 // fill pad info if available
337 for ( Int_t i=0; i<cluster->GetNDigits(); i++ ) {
339 AliMUONVDigit* digit = fDigitStore->FindObject( cluster->GetDigitId(i) );
340 if ( !digit ) continue;
343 const AliMpVSegmentation* seg = AliMpSegmentation::Instance()->
344 GetMpSegmentation( digit->DetElemId(), AliMp::GetCathodType( digit->Cathode() ) );
345 AliMpPad pad = seg->PadByIndices( digit->PadX(), digit->PadY() );
347 // calibration parameters
348 AliMUONVCalibParam* ped = fCalibData->Pedestals( digit->DetElemId(), digit->ManuId() );
349 AliMUONVCalibParam* gain = fCalibData->Gains( digit->DetElemId(), digit->ManuId() );
350 Int_t manuChannel = digit->ManuChannel();
352 if ( digit->ManuId() & AliMpConstants::ManuMask(AliMp::kNonBendingPlane) ) {
357 AliMUONPadInfo padInfo;
358 padInfo.SetPadId( digit->GetUniqueID() );
359 padInfo.SetPadPlaneType( planeType );
360 padInfo.SetPadXY( pad.GetPositionX(), pad.GetPositionY() );
361 padInfo.SetPadDimXY( pad.GetDimensionX(), pad.GetDimensionY() );
362 padInfo.SetPadCharge( (Double_t)digit->Charge() );
363 padInfo.SetPadADC( digit->ADC() );
364 padInfo.SetSaturated( digit->IsSaturated() );
365 padInfo.SetCalibrated( digit->IsCalibrated() );
366 padInfo.SetPedestal( ped->ValueAsFloatFast(manuChannel,0), // mean
367 ped->ValueAsFloatFast(manuChannel,1) ); // sigma
368 padInfo.SetGain( gain->ValueAsFloatFast(manuChannel,0), // a0
369 gain->ValueAsFloatFast(manuChannel,1), // a1
370 (Int_t)gain->ValueAsFloatFast(manuChannel,2), // threshold
371 (Int_t)gain->ValueAsFloatFast(manuChannel,3) ); // fit quality
373 fClusterInfo->AddPad( padInfo );
376 // fill cluster info tree
377 fClusterInfoTree->Fill();
379 trackParam = static_cast<AliMUONTrackParam*>(track->GetTrackParamAtCluster()->After(trackParam));
383 // Added protection in case the derived task is not an AOD producer.
384 AliAnalysisDataSlot *out0 = GetOutputSlot(0);
385 if (out0 && out0->IsConnected()) PostData( 0, fClusterInfoTree );
390 //______________________________________________________________
391 UInt_t AliMUONChamberCalibrationTask::BuildClusterMap( AliMUONTrack &track )
394 /// Build the map of clusters in tracking chambers
397 UInt_t muonClusterMap = 0;
399 AliMUONTrackParam* trackParam = static_cast<AliMUONTrackParam*>(track.GetTrackParamAtCluster()->First());
400 while ( trackParam ) {
402 muonClusterMap |= BIT(trackParam->GetClusterPtr()->GetChamberId());
404 trackParam = static_cast<AliMUONTrackParam*>(track.GetTrackParamAtCluster()->After(trackParam));
407 return muonClusterMap;
410 //______________________________________________________________
411 void AliMUONChamberCalibrationTask::Terminate( Option_t* /*option*/ )
414 /// Called once per task on the client machine at the end of the analysis.