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 **************************************************************************/
20 #include "TDecompLU.h"
22 #include "AliAnalysisTask.h"
23 #include "AliAnalysisManager.h"
25 #include "AliESDEvent.h"
26 #include "AliESDInputHandler.h"
27 #include "AliESDZDC.h"
28 #include "AliZDCTowerCalibTask.h"
29 #include "AliZDCTowerCalib.h"
30 #include "AliCDBManager.h"
32 #include "AliCDBRunRange.h"
33 #include "AliCDBStorage.h"
35 ClassImp(AliZDCTowerCalibTask)
37 //________________________________________________________________________
38 AliZDCTowerCalibTask::AliZDCTowerCalibTask()
49 //________________________________________________________________________
50 AliZDCTowerCalibTask::AliZDCTowerCalibTask(const char *name)
51 : AliAnalysisTask(name, ""),
59 // Default constructor
61 // Define input and output slots here
62 // Input slot #0 works with a TChain
63 DefineInput(0, TChain::Class());
64 // // Output slot #0 writes into a TH1 container
65 // DefineOutput(0, TH1F::Class());
79 //________________________________________________________________________
80 void AliZDCTowerCalibTask::ConnectInputData(Option_t *)
82 // Connect ESD or AOD here
85 TTree* tree = dynamic_cast<TTree*> (GetInputData(0));
86 if (!tree) Printf("ERROR: Could not read chain from input slot 0");
88 // Disable all branches and enable only the needed ones
89 // The next two lines are different when data produced as AliESDEvent is read
91 tree->SetBranchStatus("*", kFALSE);
92 tree->SetBranchStatus("fTracks.*", kTRUE);
95 AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
96 if (!esdH) Printf("ERROR: Could not get ESDInputHandler");
97 else fESD = esdH->GetEvent();
101 //________________________________________________________________________
102 void AliZDCTowerCalibTask::CreateOutputObjects(){
107 //________________________________________________________________________
108 void AliZDCTowerCalibTask::Exec(Option_t *)
111 // Called for each event
114 Printf("ERROR: fESD not available");
118 AliESDZDC *zdcEvent = fESD->GetESDZDC();
119 Double_t *ezn1 = 0, *ezn2 = 0;
120 if(fESD->GetEventType()==7){
121 ezn1 = (Double_t *) zdcEvent->GetZN1TowerEnergy(); // znc
122 ezn2 = (Double_t *) zdcEvent->GetZN2TowerEnergy(); // zna
124 Double_t ezn1sum = ezn1[1] + ezn1[2] + ezn1[3] + ezn1[4];
125 Double_t ezn2sum = ezn2[1] + ezn2[2] + ezn2[3] + ezn2[4];
127 Bool_t isZNAAccepted = kTRUE;
128 if (ezn2[0] < fADCMin || ezn2sum < fADCMin) isZNAAccepted = kFALSE;
129 Bool_t isZNCAccepted = kTRUE;
130 if (ezn1[0] < fADCMin || ezn1sum < fADCMin) isZNCAccepted = kFALSE;
131 // calculate coefficient matrix and known terms
132 for (Int_t i=0; i<4; i++) {
133 for (Int_t j=0; j<4; j++) {
134 if (isZNAAccepted) fAZNA[i][j] += ezn2[ i + 1 ] * ezn2[ j + 1 ] / ezn2[0];
135 if (isZNCAccepted) fAZNC[i][j] += ezn1[ i + 1 ] * ezn1[ j + 1 ] / ezn1[0];
137 if (isZNAAccepted) fBZNA[i] += ezn2[ i + 1 ];
138 if (isZNCAccepted) fBZNC[i] += ezn1[ i + 1 ];
141 // PostData(0, fHistPt);
144 //________________________________________________________________________
145 void AliZDCTowerCalibTask::Terminate(Option_t *)
147 // solve the system of linear equations giving the calibration coefficients
150 TDecompLU luZNA(fAZNA);
152 TVectorD coeffZNA = luZNA.Solve(fBZNA,isZNAOk);
154 printf ("ZNA: coefficient matrix:\n");
156 printf ("ZNA: known terms:\n");
158 printf ("ZNA: Fitted calibration coefficients:\n");
162 printf ("Singular coefficient matrix for ZNA! Setting all coefficients to 1\n");
163 for (Int_t i=0; i<4; i++) coeffZNA[i] = 1;
166 TDecompLU luZNC(fAZNC);
168 TVectorD coeffZNC = luZNC.Solve(fBZNC,isZNCOk);
170 printf ("ZNC: coefficient matrix:\n");
172 printf ("ZNC: known terms:\n");
174 printf ("ZNC: Fitted calibration coefficients:\n");
178 printf ("Singular coefficient matrix for ZNC! Setting all coefficients to 1\n");
179 for (Int_t i=0; i<4; i++) coeffZNC[i] = 1;
185 AliZDCTowerCalib *towerCalib = new AliZDCTowerCalib();
187 towerCalib->SetZN1EqualCoeff(0, 1.);
188 towerCalib->SetZN2EqualCoeff(0, 1.);
190 for(Int_t j=1; j<5; j++){
191 towerCalib->SetZN1EqualCoeff(j, coeffZNC[j+1]);
192 towerCalib->SetZN2EqualCoeff(j, coeffZNA[j+1]);
194 towerCalib->Print("");
196 AliCDBManager *manager = AliCDBManager::Instance();
197 manager->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
199 AliCDBMetaData *md = new AliCDBMetaData();
200 md->SetResponsible("Chiara Oppedisano");
201 md->SetComment("Calibration object for ZDC written by a macro");
202 md->SetObjectClassName("AliZDCTowerCalib");
203 md->SetAliRootVersion(gSystem->Getenv("ARVERSION"));
204 md->SetBeamPeriod(0);
206 AliCDBId id("ZDC/Calib/TowerCalib",fESD->GetRunNumber(),AliCDBRunRange::Infinity());
207 manager->GetDefaultStorage()->Put(towerCalib,id, md);