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 <TObjArray.h>
36 #include "AliMUONChamberCalibrationTask.h"
39 #include "AliCDBManager.h"
40 #include "AliGRPManager.h"
41 #include "AliESDEvent.h"
42 #include "AliESDInputHandler.h"
43 #include "AliESDtrack.h"
44 #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" ),
80 fCalibChoice(kNOGAIN),
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(kNOGAIN),
103 fClusterInfoTree(0x0),
109 fESDInputHandler(0x0),
116 fOCDBPath = ocdbpath;
117 if ( (my_calib_option >= ((Int_t)kNOGAIN)) && (my_calib_option <= ((Int_t)kINJECTIONGAIN)) )
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)kNOGAIN, (Int_t)kINJECTIONGAIN ) );
122 fCalibChoice = kNOGAIN;
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 AliGRPManager *grpMan = new AliGRPManager();
178 grpMan->ReadGRPEntry();
179 grpMan->SetMagField();
185 AliCDBManager* man = AliCDBManager::Instance();
186 man->SetDefaultStorage( fOCDBPath );
187 man->SetSpecificStorage( "MUON/Calib/MappingData", fOCDBPath );
188 man->SetSpecificStorage( "MUON/Calib/MappingRunData", fOCDBPath ); // for the manu serial numbers
191 if ( ! AliMpCDB::LoadDDLStore() ) {
192 AliFatal( "Could not access mapping from OCDB !" );
196 // Set the reconstruction parameters for track refitting
197 // (needed when applying any of the with-gain options)
199 fMuonRecoParam = AliMUONRecoParam::GetCosmicParam();
201 TString caliboption1 = "NOGAIN";
202 TString caliboption2 = "GAINCONSTANTCAPA";
203 TString caliboption3 = "GAIN";
204 TString caliboption4 = "INJECTIONGAIN";
206 TString caliboption = caliboption1;
207 if ( fCalibChoice == kGAINCONSTANTCAPA ) caliboption = caliboption2;
208 if ( fCalibChoice == kGAIN ) caliboption = caliboption3;
209 if ( fCalibChoice == kINJECTIONGAIN ) caliboption = caliboption4;
210 fMuonRecoParam->SetCalibrationMode(caliboption.Data());
212 for (Int_t iCh=0; iCh<10; iCh++) {
213 fMuonRecoParam->SetDefaultNonBendingReso( iCh, 0.152 ); // input ESD was aligned (default cosmic settings)
214 fMuonRecoParam->SetDefaultBendingReso( iCh, 0.027 );
216 fMuonRecoParam->SetMaxNonBendingDistanceToTrack(5.); // was at 1. in default cosmic settings
217 fMuonRecoParam->SetMaxBendingDistanceToTrack(5.);
219 fMuonRecoParam->RequestStation(1, kTRUE); // only St 4 and 5 enabled in default cosmic settings
220 fMuonRecoParam->ImproveTracks(kTRUE, 7.); // was 6. in default cosmic settings
222 AliInfo( "reconstruction parameters initialized as follows :" );
223 fMuonRecoParam->Print("FULL");
225 AliMUONESDInterface::ResetTracker(fMuonRecoParam);
228 //______________________________________________________________
229 void AliMUONChamberCalibrationTask::ConnectInputData( Option_t* /*option*/ )
232 /// Connect to ESD here
238 fESDInputHandler = dynamic_cast<AliESDInputHandler*>(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
241 if ( fESDInputHandler ) {
243 // The properly initialized ESD input handler reads ESD tree
244 // and connect it to ESD event, so we only need to retrieve the later
245 fESDInputEvent = fESDInputHandler->GetEvent();
246 if ( !fESDInputEvent ) {
248 AliFatal( "Could not get input ESD event !!! ");
253 AliError( "Could not get input ESD handler !!!" );
254 // If no input event handler we need to get the tree once
255 // from input slot 0 for the chain
256 tree = dynamic_cast<TTree*> (GetInputData(0));
257 if ( tree ) tree->GetReadEntry();
258 else AliFatal( "Could not read tree from input slot 0 !!!" );
262 //______________________________________________________________
263 void AliMUONChamberCalibrationTask::Exec( Option_t* /*option*/ )
266 /// Process the current event
267 /// (called for each event)
270 static Bool_t first = kTRUE;
277 if ( !fESDInputEvent ) {
278 AliError( "Input ESD event not available !!! " );
282 // load the current ESD event
283 fESDInterface->LoadEvent( *fESDInputEvent );
286 fDigitStore = fESDInterface->GetDigits();
288 // prepare access to calibration data
289 if ( !fCalibData ) fCalibData = new AliMUONCalibrationData( fESDInputEvent->GetESDRun()->GetRunNumber() );
291 // --------------------------------------------------------------------
292 // fill cluster info from clusters attached to each track of this event
293 // --------------------------------------------------------------------
295 Int_t nTracks = (Int_t)fESDInputEvent->GetNumberOfMuonTracks();
296 if ( nTracks < 1 ) return;
298 TIter nextTrack( fESDInterface->CreateTrackIterator() );
301 while ( (track = static_cast<AliMUONTrack*>(nextTrack())) ) { // loop over tracks
303 UInt_t muonClusterMap = BuildClusterMap( *track );
305 AliMUONTrackParam* trackParam =
306 static_cast<AliMUONTrackParam*>(track->GetTrackParamAtCluster()->First());
308 while ( trackParam ) { // loop over clusters
310 fClusterInfo->Clear("C");
313 AliMUONVCluster* cluster = trackParam->GetClusterPtr();
314 fClusterInfo->SetRunId( fESDInputEvent->GetRunNumber() );
315 fClusterInfo->SetEventId( fESDInputEvent->GetEventNumberInFile() );
316 fClusterInfo->SetZ( cluster->GetZ() );
317 fClusterInfo->SetClusterId( cluster->GetUniqueID() );
318 fClusterInfo->SetClusterXY( cluster->GetX(), cluster->GetY() );
319 fClusterInfo->SetClusterXYErr( cluster->GetErrX(), cluster->GetErrY() );
320 fClusterInfo->SetClusterChi2( cluster->GetChi2() );
321 fClusterInfo->SetClusterCharge( cluster->GetCharge() );
324 fClusterInfo->SetTrackId( track->GetUniqueID() );
325 fClusterInfo->SetTrackXY( trackParam->GetNonBendingCoor(), trackParam->GetBendingCoor() );
326 fClusterInfo->SetTrackThetaXY( TMath::ATan( trackParam->GetNonBendingSlope() ),
327 TMath::ATan( trackParam->GetBendingSlope() ) );
328 fClusterInfo->SetTrackP( trackParam->P() );
329 const TMatrixD paramCov = trackParam->GetCovariances();
330 fClusterInfo->SetTrackXYErr( TMath::Sqrt( paramCov(0,0) ),
331 TMath::Sqrt( paramCov(2,2) ) );
332 fClusterInfo->SetTrackChi2( track->GetNormalizedChi2() );
333 fClusterInfo->SetTrackCharge( (Short_t)trackParam->GetCharge() );
334 fClusterInfo->SetTrackNHits( track->GetNClusters() );
335 fClusterInfo->SetTrackChamberHitMap( muonClusterMap );
337 // fill pad info if available
338 for ( Int_t i=0; i<cluster->GetNDigits(); i++ ) {
340 AliMUONVDigit* digit = fDigitStore->FindObject( cluster->GetDigitId(i) );
341 if ( !digit ) continue;
344 const AliMpVSegmentation* seg = AliMpSegmentation::Instance()->
345 GetMpSegmentation( digit->DetElemId(), AliMp::GetCathodType( digit->Cathode() ) );
346 AliMpPad pad = seg->PadByIndices( digit->PadX(), digit->PadY() );
348 // calibration parameters
349 AliMUONVCalibParam* ped = fCalibData->Pedestals( digit->DetElemId(), digit->ManuId() );
350 AliMUONVCalibParam* gain = fCalibData->Gains( digit->DetElemId(), digit->ManuId() );
351 Int_t manuChannel = digit->ManuChannel();
353 if ( digit->ManuId() & AliMpConstants::ManuMask(AliMp::kNonBendingPlane) ) {
358 AliMUONPadInfo padInfo;
359 padInfo.SetPadId( digit->GetUniqueID() );
360 padInfo.SetPadPlaneType( planeType );
361 padInfo.SetPadXY( pad.GetPositionX(), pad.GetPositionY() );
362 padInfo.SetPadDimXY( pad.GetDimensionX(), pad.GetDimensionY() );
363 padInfo.SetPadCharge( (Double_t)digit->Charge() );
364 padInfo.SetPadADC( digit->ADC() );
365 padInfo.SetSaturated( digit->IsSaturated() );
366 padInfo.SetCalibrated( digit->IsCalibrated() );
367 padInfo.SetPedestal( ped->ValueAsFloatFast(manuChannel,0), // mean
368 ped->ValueAsFloatFast(manuChannel,1) ); // sigma
369 padInfo.SetGain( gain->ValueAsFloatFast(manuChannel,0), // a0
370 gain->ValueAsFloatFast(manuChannel,1), // a1
371 (Int_t)gain->ValueAsFloatFast(manuChannel,2), // threshold
372 (Int_t)gain->ValueAsFloatFast(manuChannel,3) ); // fit quality
374 fClusterInfo->AddPad( padInfo );
377 // fill cluster info tree
378 fClusterInfoTree->Fill();
380 trackParam = static_cast<AliMUONTrackParam*>(track->GetTrackParamAtCluster()->After(trackParam));
384 // Added protection in case the derived task is not an AOD producer.
385 AliAnalysisDataSlot *out0 = GetOutputSlot(0);
386 if (out0 && out0->IsConnected()) PostData( 0, fClusterInfoTree );
391 //______________________________________________________________
392 UInt_t AliMUONChamberCalibrationTask::BuildClusterMap( AliMUONTrack &track )
395 /// Build the map of clusters in tracking chambers
398 UInt_t muonClusterMap = 0;
400 AliMUONTrackParam* trackParam = static_cast<AliMUONTrackParam*>(track.GetTrackParamAtCluster()->First());
401 while ( trackParam ) {
403 muonClusterMap |= BIT(trackParam->GetClusterPtr()->GetChamberId());
405 trackParam = static_cast<AliMUONTrackParam*>(track.GetTrackParamAtCluster()->After(trackParam));
408 return muonClusterMap;
411 //______________________________________________________________
412 void AliMUONChamberCalibrationTask::Terminate( Option_t* /*option*/ )
415 /// Called once per task on the client machine at the end of the analysis.