BadMap test moved after misalignment
[u/mrichter/AliRoot.git] / ANALYSIS / TenderSupplies / AliPHOSTenderSupply.cxx
CommitLineData
f7d0ec90 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
17///////////////////////////////////////////////////////////////////////////////
18// //
19// PHOS tender, recalibrate PHOS clusters //
20// and do track matching //
21// Author : Dmitri Peressounko (RRC KI) //
22// //
23///////////////////////////////////////////////////////////////////////////////
24
25#include "TROOT.h"
26#include "TH2.h"
27#include "TFile.h"
28
29#include <AliLog.h>
30#include <AliVEvent.h>
31#include <AliAODEvent.h>
32#include <AliESDEvent.h>
33#include <AliAnalysisManager.h>
34#include <AliTender.h>
35#include <AliCDBManager.h>
36#include "AliMagF.h"
37#include "TGeoGlobalMagField.h"
38
39#include "AliVCluster.h"
40#include "AliPHOSTenderSupply.h"
41#include "AliPHOSCalibData.h"
42#include "AliPHOSGeometry.h"
43#include "AliPHOSEsdCluster.h"
44#include "AliPHOSAodCluster.h"
45#include "AliOADBContainer.h"
46#include "AliAODCaloCells.h"
47#include "AliESDCaloCells.h"
48
49ClassImp(AliPHOSTenderSupply)
50
51AliPHOSTenderSupply::AliPHOSTenderSupply() :
52 AliTenderSupply()
53 ,fOCDBpass("local://OCDB")
54 ,fNonlinearityVersion("Default")
55 ,fPHOSGeo(0x0)
56 ,fRecoPass(-1) //to be defined
57 ,fUsePrivateBadMap(0)
58 ,fUsePrivateCalib(0)
59 ,fPHOSCalibData(0x0)
60 ,fTask(0x0)
61 ,fIsMC(kFALSE)
62 ,fMCProduction("")
63{
64 //
65 // default ctor
66 //
67 for(Int_t i=0;i<10;i++)fNonlinearityParams[i]=0. ;
68 for(Int_t mod=0;mod<5;mod++)fPHOSBadMap[mod]=0x0 ;
69}
70
71//_____________________________________________________
72AliPHOSTenderSupply::AliPHOSTenderSupply(const char *name, const AliTender *tender) :
73 AliTenderSupply(name,tender)
74 ,fOCDBpass("alien:///alice/cern.ch/user/p/prsnko/PHOSrecalibrations/")
75 ,fNonlinearityVersion("Default")
76 ,fPHOSGeo(0x0)
77 ,fRecoPass(-1) //to be defined
78 ,fUsePrivateBadMap(0)
79 ,fUsePrivateCalib(0)
80 ,fPHOSCalibData(0x0)
81 ,fTask(0x0)
82 ,fIsMC(kFALSE)
83 ,fMCProduction("")
84{
85 //
86 // named ctor
87 //
88 for(Int_t i=0;i<10;i++)fNonlinearityParams[i]=0. ;
89 for(Int_t mod=0;mod<5;mod++)fPHOSBadMap[mod]=0x0 ;
90}
91
92//_____________________________________________________
93AliPHOSTenderSupply::~AliPHOSTenderSupply()
94{
95 //Destructor
96 if(fPHOSCalibData)
97 delete fPHOSCalibData;
98 fPHOSCalibData=0x0 ;
99}
100
101//_____________________________________________________
102void AliPHOSTenderSupply::InitTender()
103{
104 //
105 // Initialise PHOS tender
106 //
107 Int_t runNumber = 0;
108 if(fTender)
109 runNumber = fTender->GetRun();
110 else{
111 if(!fTask){
112 AliError("Neither Tender not Taks was not set") ;
113 return ;
114 }
115 AliAODEvent *aod = dynamic_cast<AliAODEvent*>(fTask->InputEvent()) ;
116 if(aod)
117 runNumber = aod->GetRunNumber() ;
118 else{
119 AliESDEvent *esd = dynamic_cast<AliESDEvent*>(fTask->InputEvent()) ;
120 if(esd)
121 runNumber = esd->GetRunNumber() ;
122 else{
123 AliError("Taks does not contain neither ESD nor AOD") ;
124 return ;
125 }
126 }
127 }
128
129 //In MC always reco pass 1
130 if(fIsMC)
131 fRecoPass=1 ;
132
133 if(fRecoPass<0){ //not defined yet
134 // read if from filename.
135 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
136 TTree * t = mgr->GetTree();
137 if(t){
138 TFile * f = t->GetCurrentFile() ;
139 if(f){
140 TString fname(f->GetName());
141 if(fname.Contains("pass1"))
142 fRecoPass=1;
143 else
144 if(fname.Contains("pass2"))
145 fRecoPass=2;
146 else
147 if(fname.Contains("pass3"))
148 fRecoPass=3;
149 else
150 if(fname.Contains("pass4"))
151 fRecoPass=4;
152 }
153 }
154 if(fRecoPass<0){
155 AliError("Can not find pass number from file name, set it manually");
156 }
157 }
158
159 //Init geometry
160 if(!fPHOSGeo){
161 AliOADBContainer geomContainer("phosGeo");
162 geomContainer.InitFromFile("$ALICE_ROOT/OADB/PHOS/PHOSGeometry.root","PHOSRotationMatrixes");
163 TObjArray *matrixes = (TObjArray*)geomContainer.GetObject(runNumber,"PHOSRotationMatrixes");
164 fPHOSGeo = AliPHOSGeometry::GetInstance("IHEP") ;
165 for(Int_t mod=0; mod<5; mod++) {
166 if(!matrixes->At(mod)) continue;
167 fPHOSGeo->SetMisalMatrix(((TGeoHMatrix*)matrixes->At(mod)),mod) ;
168 printf(".........Adding Matrix(%d), geo=%p\n",mod,fPHOSGeo) ;
e1c158c2 169 ((TGeoHMatrix*)matrixes->At(mod))->Print() ;
f7d0ec90 170 }
171 }
172
173 //Init Bad channels map
174 if(!fUsePrivateBadMap){
175 AliOADBContainer badmapContainer(Form("phosBadMap"));
176 badmapContainer.InitFromFile("$ALICE_ROOT/OADB/PHOS/PHOSBadMaps.root","phosBadMap");
177 TObjArray *maps = (TObjArray*)badmapContainer.GetObject(runNumber,"phosBadMap");
178 if(!maps){
179 AliError(Form("Can not read Bad map for run %d. \n You may choose to use your map with ForceUsingBadMap()\n",runNumber)) ;
180 }
181 else{
182 AliInfo(Form("Setting PHOS bad map with name %s \n",maps->GetName())) ;
183 for(Int_t mod=0; mod<5;mod++){
184 if(fPHOSBadMap[mod])
185 delete fPHOSBadMap[mod] ;
186 TH2I * h = (TH2I*)maps->At(mod) ;
187 if(h)
188 fPHOSBadMap[mod]=new TH2I(*h) ;
189 }
190 }
191 }
192
193 if(!fUsePrivateCalib){
194 if(fIsMC){ //re/de-calibration for MC productions
195 //Init recalibration
196 AliOADBContainer calibContainer("phosRecalibration");
197 calibContainer.InitFromFile("$ALICE_ROOT/OADB/PHOS/PHOSMCCalibrations.root","phosRecalibration");
198
199 TObjArray *recalib = (TObjArray*)calibContainer.GetObject(runNumber,"PHOSRecalibration");
200 if(!recalib){
201 AliFatal(Form("Can not read calibrations for run %d\n. You may choose your specific calibration with ForceUsingCalibration()\n",runNumber)) ;
202 }
203 else{
204 //Now try to find object with proper name
205 for(Int_t i=0; i<recalib->GetEntriesFast(); i++){
206 AliPHOSCalibData * tmp = (AliPHOSCalibData*)recalib->At(i) ;
207 if(fMCProduction.CompareTo(tmp->GetName())==0){
208 fPHOSCalibData = tmp ;
209 break ;
210 }
211 }
212 if(!fPHOSCalibData) {
213 AliFatal(Form("Can not find calibration for run %d, and name %s \n",runNumber, fMCProduction.Data())) ;
214 }
215 }
216
217 }
218 else{ //real data
219 //Init recalibration
220 //Check the pass1-pass2-pass3 reconstruction
221 AliOADBContainer calibContainer("phosRecalibration");
222 calibContainer.InitFromFile("$ALICE_ROOT/OADB/PHOS/PHOSCalibrations.root","phosRecalibration");
223 TObjArray *recalib = (TObjArray*)calibContainer.GetObject(runNumber,"PHOSRecalibration");
224 if(!recalib){
225 AliFatal(Form("Can not read calibrations for run %d\n. You may choose your specific calibration with ForceUsingCalibration()\n",runNumber)) ;
226 }
227 else{
228 fPHOSCalibData = (AliPHOSCalibData*)recalib->At(fRecoPass-1) ;
229 if(!fPHOSCalibData) {
230 AliFatal(Form("Can not find calibration for run %d, pass %d \n",runNumber, fRecoPass)) ;
231 }
232 }
233 }
234 }
235
236}
237
238//_____________________________________________________
239void AliPHOSTenderSupply::ProcessEvent()
240{
241 //Choose PHOS clusters and recalibrate them
242 //that it recalculate energy, position and distance
243 //to closest track extrapolation
244
245 AliESDEvent *esd = 0x0 ;
246 AliAODEvent *aod = 0x0 ;
247 if(fTender){
248 esd = fTender->GetEvent();
249 if(!esd)
250 return ;
251 }
252 else{
253 if(!fTask){
254 return ;
255 }
256 esd = dynamic_cast<AliESDEvent*>(fTask->InputEvent()) ;
257 aod = dynamic_cast<AliAODEvent*>(fTask->InputEvent()) ;
258 if(!esd && !aod)
259 return ;
260 }
261
262 if(!fPHOSCalibData
263 || (fTender && fTender->RunChanged())){ //In case of Task init called automatically
264 InitTender();
265
266 }
267
268 TVector3 vertex ;
269 if(esd){
270 const AliESDVertex *esdVertex = esd->GetPrimaryVertex();
271 vertex.SetXYZ(esdVertex->GetX(),esdVertex->GetY(),esdVertex->GetZ());
272 }
273 else{//AOD
274 const AliAODVertex *aodVertex = aod->GetPrimaryVertex();
275 vertex.SetXYZ(aodVertex->GetX(),aodVertex->GetY(),aodVertex->GetZ());
276 }
277 if(vertex.Mag()>99.) //vertex not defined?
278 vertex.SetXYZ(0.,0.,0.) ;
279
280
281 //For re-calibration
282 const Double_t logWeight=4.5 ;
283
284 if(esd){ //To avoid multiple if in loops we made
285 //almost identical pecies of code. Please apply changes to both!!!
286 Int_t multClust=esd->GetNumberOfCaloClusters();
287 AliESDCaloCells * cells = esd->GetPHOSCells() ;
288
289 for (Int_t i=0; i<multClust; i++) {
290 AliESDCaloCluster *clu = esd->GetCaloCluster(i);
291 if ( !clu->IsPHOS()) continue;
292
4b2c1eeb 293
294 //Apply re-Calibreation
295 AliPHOSEsdCluster cluPHOS(*clu);
296 cluPHOS.Recalibrate(fPHOSCalibData,cells); // modify the cell energies
297 cluPHOS.EvalAll(logWeight,vertex); // recalculate the cluster parameters
298 cluPHOS.SetE(CorrectNonlinearity(cluPHOS.E()));// Users's nonlinearity
299
f7d0ec90 300 Float_t position[3];
4b2c1eeb 301 cluPHOS.GetPosition(position);
302 clu->SetPosition(position); //rec.point position in MARS
303
f7d0ec90 304 TVector3 global(position) ;
305 Int_t relId[4] ;
306 fPHOSGeo->GlobalPos2RelId(global,relId) ;
307 Int_t mod = relId[0] ;
308 Int_t cellX = relId[2];
309 Int_t cellZ = relId[3] ;
310 if ( !IsGoodChannel(mod,cellX,cellZ) ) {
311 clu->SetE(0.) ;
312 continue ;
313 }
4b2c1eeb 314
5bd0f028 315 Double_t ecore=CoreEnergy(&cluPHOS) ;
316 ecore=CorrectNonlinearity(ecore) ;
317
f7d0ec90 318 //Correct Misalignment
e1c158c2 319// CorrectPHOSMisalignment(global,mod) ;
320// position[0]=global.X() ;
321// position[1]=global.Y() ;
322// position[2]=global.Z() ;
323// cluPHOS.GetPosition(position) ;
f7d0ec90 324
325 //Eval CoreDispersion
326 Double_t m02=0.,m20=0.;
327 EvalLambdas(&cluPHOS,m02, m20);
328 clu->SetDispersion(TestLambda(clu->E(),m20,m02)) ;
329
5bd0f028 330 clu->SetE(cluPHOS.E()); //total particle energy
331 clu->SetMCEnergyFraction(ecore); //core particle energy
332
f7d0ec90 333 // clu->SetDispersion(cluPHOS.GetDispersion()); //cluster dispersion
334 // ec->SetPID(rp->GetPID()) ; //array of particle identification
335 clu->SetM02(cluPHOS.GetM02()) ; //second moment M2x
336 clu->SetM20(cluPHOS.GetM20()) ; //second moment M2z
337 Double_t dx=0.,dz=0. ;
338 fPHOSGeo->GlobalPos2RelId(global,relId) ;
339 TVector3 locPos;
340 fPHOSGeo->Global2Local(locPos,global,mod) ;
341
342 Double_t pttrack=0.;
343 Int_t charge=0;
344 FindTrackMatching(mod,&locPos,dx,dz,pttrack,charge) ;
345 Double_t r=TestCPV(dx, dz, pttrack,charge) ;
346 clu->SetTrackDistance(dx,dz);
347
348 clu->SetEmcCpvDistance(r);
349 clu->SetChi2(TestLambda(clu->E(),clu->GetM20(),clu->GetM02())); //not yet implemented
d4657394 350 Double_t tof=EvalTOF(&cluPHOS,cells);
1e7fec1c 351// if(TMath::Abs(tof-clu->GetTOF())>100.e-9) //something wrong in cell TOF!
352// tof=clu->GetTOF() ;
d4657394 353 clu->SetTOF(tof);
393b3556 354 Double_t minDist=clu->GetDistanceToBadChannel() ;//Already calculated
355 DistanceToBadChannel(mod,&locPos,minDist);
356 clu->SetDistanceToBadChannel(minDist) ;
f7d0ec90 357
358 }
359 }
360 else{//AOD
361 Int_t multClust=aod->GetNumberOfCaloClusters();
362 AliAODCaloCells * cells = aod->GetPHOSCells() ;
363
364 for (Int_t i=0; i<multClust; i++) {
365 AliAODCaloCluster *clu = aod->GetCaloCluster(i);
366 if ( !clu->IsPHOS()) continue;
367
4b2c1eeb 368
369 //Apply re-Calibreation
370 AliPHOSAodCluster cluPHOS(*clu);
371 cluPHOS.Recalibrate(fPHOSCalibData,cells); // modify the cell energies
372 cluPHOS.EvalAll(logWeight,vertex); // recalculate the cluster parameters
373 cluPHOS.SetE(CorrectNonlinearity(cluPHOS.E()));// Users's nonlinearity
374
f7d0ec90 375 Float_t position[3];
4b2c1eeb 376 cluPHOS.GetPosition(position);
377 clu->SetPosition(position); //rec.point position in MARS
f7d0ec90 378 TVector3 global(position) ;
379 Int_t relId[4] ;
380 fPHOSGeo->GlobalPos2RelId(global,relId) ;
381 Int_t mod = relId[0] ;
382 Int_t cellX = relId[2];
383 Int_t cellZ = relId[3] ;
384 if ( !IsGoodChannel(mod,cellX,cellZ) ) {
385 clu->SetE(0.) ;
386 continue ;
387 }
388 TVector3 locPosOld; //Use it to re-calculate distance to track
389 fPHOSGeo->Global2Local(locPosOld,global,mod) ;
4b2c1eeb 390
5bd0f028 391 Double_t ecore=CoreEnergy(&cluPHOS) ;
392 ecore=CorrectNonlinearity(ecore) ;
393
394
f7d0ec90 395 //Correct Misalignment
e1c158c2 396// cluPHOS.GetPosition(position);
397// global.SetXYZ(position[0],position[1],position[2]);
398// CorrectPHOSMisalignment(global,mod) ;
399// position[0]=global.X() ;
400// position[1]=global.Y() ;
401// position[2]=global.Z() ;
f7d0ec90 402
5bd0f028 403 clu->SetE(cluPHOS.E()); //total particle energy
53442b36 404 clu->SetCoreEnergy(ecore); //core particle energy
f7d0ec90 405 clu->SetDispersion(cluPHOS.GetDispersion()); //cluster dispersion
406 // ec->SetPID(rp->GetPID()) ; //array of particle identification
407 clu->SetM02(cluPHOS.GetM02()) ; //second moment M2x
408 clu->SetM20(cluPHOS.GetM20()) ; //second moment M2z
409 //correct distance to track
410 Double_t dx=clu->GetTrackDx() ;
411 Double_t dz=clu->GetTrackDz() ;
412 TVector3 locPos;
413 fPHOSGeo->Global2Local(locPos,global,mod) ;
414 if(dx!=-999.){ //there is matched track
415 dx+=locPos.X()-locPosOld.X() ;
416 dz+=locPos.Z()-locPosOld.Z() ;
417 clu->SetTrackDistance(dx,dz);
418 }
419 Double_t r = 999. ; //Big distance
420 int nTracksMatched = clu->GetNTracksMatched();
421 if(nTracksMatched > 0) {
422 AliVTrack* track = dynamic_cast<AliVTrack*> (clu->GetTrackMatched(0));
423 if ( track ) {
424 Double_t pttrack = track->Pt();
425 Short_t charge = track->Charge();
426 r=TestCPV(dx, dz, pttrack,charge) ;
427 }
428 }
429 clu->SetEmcCpvDistance(r); //Distance in sigmas
430
431 clu->SetChi2(TestLambda(clu->E(),clu->GetM20(),clu->GetM02())); //not yet implemented
d4657394 432 Double_t tof=EvalTOF(&cluPHOS,cells);
1e7fec1c 433// if(TMath::Abs(tof-clu->GetTOF())>100.e-9) //something wrong in cell TOF!
434// tof=clu->GetTOF() ;
d4657394 435 clu->SetTOF(tof);
393b3556 436 Double_t minDist=clu->GetDistanceToBadChannel() ;//Already calculated
437 DistanceToBadChannel(mod,&locPos,minDist);
438 clu->SetDistanceToBadChannel(minDist) ;
53442b36 439 Double_t eCross=EvalEcross(&cluPHOS);
440 clu->SetMCEnergyFraction(eCross) ;
f7d0ec90 441 }
442 }
443
444}
445//___________________________________________________________________________________________________
446void AliPHOSTenderSupply::FindTrackMatching(Int_t mod,TVector3 *locpos,
447 Double_t &dx, Double_t &dz,
448 Double_t &pt,Int_t &charge){
449 //Find track with closest extrapolation to cluster
450 AliESDEvent *esd = 0x0 ;
451 if(fTender)
452 esd= fTender->GetEvent();
453 else{
454 esd= dynamic_cast<AliESDEvent*>(fTask->InputEvent());
455 }
456
457 if(!esd){
458 AliError("ESD is not found") ;
459 return ;
460 }
461 Double_t magF = esd->GetMagneticField();
462
463 Double_t magSign = 1.0;
464 if(magF<0)magSign = -1.0;
465
466 if (!TGeoGlobalMagField::Instance()->GetField()) {
ac45cf45 467 AliError("Margnetic filed was not initialized, use default") ;
f7d0ec90 468 AliMagF* field = new AliMagF("Maps","Maps", magSign, magSign, AliMagF::k5kG);
469 TGeoGlobalMagField::Instance()->SetField(field);
470 }
471
472 // *** Start the matching
473 Int_t nt=0;
474 nt = esd->GetNumberOfTracks();
475 //Calculate actual distance to PHOS module
476 TVector3 globaPos ;
477 fPHOSGeo->Local2Global(mod, 0.,0., globaPos) ;
478 const Double_t rPHOS = globaPos.Pt() ; //Distance to center of PHOS module
479 const Double_t kYmax = 72.+10. ; //Size of the module (with some reserve) in phi direction
480 const Double_t kZmax = 64.+10. ; //Size of the module (with some reserve) in z direction
481 const Double_t kAlpha0=330./180.*TMath::Pi() ; //First PHOS module angular direction
482 const Double_t kAlpha= 20./180.*TMath::Pi() ; //PHOS module angular size
483 Double_t minDistance = 1.e6;
484
485
486 Double_t gposTrack[3] ;
487
488 Double_t bz = ((AliMagF*)TGeoGlobalMagField::Instance()->GetField())->SolenoidField();
489 bz = TMath::Sign(0.5*kAlmost0Field,bz) + bz;
490
491 Double_t b[3];
492
493 for (Int_t i=0; i<nt; i++) {
494 AliESDtrack *esdTrack=esd->GetTrack(i);
495
496 // Skip the tracks having "wrong" status (has to be checked/tuned)
497 ULong_t status = esdTrack->GetStatus();
498 if ((status & AliESDtrack::kTPCout) == 0) continue;
499
500 //Continue extrapolation from TPC outer surface
501 const AliExternalTrackParam *outerParam=esdTrack->GetOuterParam();
502 if (!outerParam) continue;
503 AliExternalTrackParam t(*outerParam);
504
505 t.GetBxByBz(b) ;
506 //Direction to the current PHOS module
507 Double_t phiMod=kAlpha0-kAlpha*mod ;
508 if(!t.Rotate(phiMod))
509 continue ;
510
511 Double_t y; // Some tracks do not reach the PHOS
512 if (!t.GetYAt(rPHOS,bz,y)) continue; // because of the bending
513
514 Double_t z;
515 if(!t.GetZAt(rPHOS,bz,z))
516 continue ;
517 if (TMath::Abs(z) > kZmax)
518 continue; // Some tracks miss the PHOS in Z
519 if(TMath::Abs(y) < kYmax){
520 t.PropagateToBxByBz(rPHOS,b); // Propagate to the matching module
521 //t.CorrectForMaterial(...); // Correct for the TOF material, if needed
522 t.GetXYZ(gposTrack) ;
523 TVector3 globalPositionTr(gposTrack) ;
524 TVector3 localPositionTr ;
525 fPHOSGeo->Global2Local(localPositionTr,globalPositionTr,mod) ;
526 Double_t ddx = locpos->X()-localPositionTr.X();
527 Double_t ddz = locpos->Z()-localPositionTr.Z();
528 Double_t d2 = ddx*ddx + ddz*ddz;
529 if(d2 < minDistance) {
530 dx = ddx ;
531 dz = ddz ;
532 minDistance=d2 ;
533 pt=esdTrack->Pt() ;
534 charge=esdTrack->Charge() ;
535 }
536 }
537 }//Scanned all tracks
538
539}
540//____________________________________________________________
541Float_t AliPHOSTenderSupply::CorrectNonlinearity(Float_t en){
542
543 //For backward compatibility, if no RecoParameters found
544 if(fNonlinearityVersion=="Default"){
545 return 0.0241+1.0504*en+0.000249*en*en ;
546 }
547
548 if(fNonlinearityVersion=="NoCorrection"){
549 return en ;
550 }
551 if(fNonlinearityVersion=="Gustavo2005"){
552 return fNonlinearityParams[0]+fNonlinearityParams[1]*en + fNonlinearityParams[2]*en*en ;
553 }
554 if(fNonlinearityVersion=="Henrik2010"){
555 return en*(fNonlinearityParams[0]+fNonlinearityParams[1]*TMath::Exp(-en*fNonlinearityParams[2]))*(1.+fNonlinearityParams[3]*TMath::Exp(-en*fNonlinearityParams[4]))*(1.+fNonlinearityParams[6]/(en*en+fNonlinearityParams[5])) ;
556 }
557
558 return en ;
559}
560//_____________________________________________________________________________
561Double_t AliPHOSTenderSupply::TestLambda(Double_t pt,Double_t l1,Double_t l2){
562//Parameterization for core dispersion
563//For R=4.5
564 Double_t l1Mean = 1.150200 + 0.097886/(1.+1.486645*pt+0.000038*pt*pt) ;
565 Double_t l2Mean = 1.574706 + 0.997966*exp(-0.895075*pt)-0.010666*pt ;
566 Double_t l1Sigma = 0.100255 + 0.337177*exp(-0.517684*pt)+0.001170*pt ;
567 Double_t l2Sigma = 0.232580 + 0.573401*exp(-0.735903*pt)-0.002325*pt ;
568 Double_t c = -0.110983 -0.017353/(1.-1.836995*pt+0.934517*pt*pt) ;
569
570/*
571 //Parameterizatino for full dispersion
572 Double_t l2Mean = 1.53126+9.50835e+06/(1.+1.08728e+07*pt+1.73420e+06*pt*pt) ;
573 Double_t l1Mean = 1.12365+0.123770*TMath::Exp(-pt*0.246551)+5.30000e-03*pt ;
574 Double_t l2Sigma = 6.48260e-02+7.60261e+10/(1.+1.53012e+11*pt+5.01265e+05*pt*pt)+9.00000e-03*pt;
575 Double_t l1Sigma = 4.44719e-04+6.99839e-01/(1.+1.22497e+00*pt+6.78604e-07*pt*pt)+9.00000e-03*pt;
576 Double_t c=-0.35-0.550*TMath::Exp(-0.390730*pt) ;
577*/
578 Double_t R2=0.5*(l1-l1Mean)*(l1-l1Mean)/l1Sigma/l1Sigma +
579 0.5*(l2-l2Mean)*(l2-l2Mean)/l2Sigma/l2Sigma +
580 0.5*c*(l1-l1Mean)*(l2-l2Mean)/l1Sigma/l2Sigma ;
581 return R2 ;
582
583}
584//____________________________________________________________________________
585Double_t AliPHOSTenderSupply::TestCPV(Double_t dx, Double_t dz, Double_t pt, Int_t charge){
586 //Parameterization of LHC10h period
587 //_true if neutral_
588
589 Double_t meanX=0;
590 Double_t meanZ=0.;
591 Double_t sx=TMath::Min(5.4,2.59719e+02*TMath::Exp(-pt/1.02053e-01)+
592 6.58365e-01*5.91917e-01*5.91917e-01/((pt-9.61306e-01)*(pt-9.61306e-01)+5.91917e-01*5.91917e-01)+1.59219);
593 Double_t sz=TMath::Min(2.75,4.90341e+02*1.91456e-02*1.91456e-02/(pt*pt+1.91456e-02*1.91456e-02)+1.60) ;
594
595 Double_t mf = 0.; //Positive for ++ and negative for --
596 if(fTender){
597 AliESDEvent *esd = fTender->GetEvent();
598 mf = esd->GetMagneticField();
599 }
600 else{
601 if(fTask){
602 AliESDEvent *esd= dynamic_cast<AliESDEvent*>(fTask->InputEvent());
603 if(esd)
604 mf = esd->GetMagneticField();
605 else{
606 AliAODEvent *aod= dynamic_cast<AliAODEvent*>(fTask->InputEvent());
607 if(aod)
608 mf = aod->GetMagneticField();
609 }
610 }else{
611 AliError("Neither Tender nor Task defined") ;
612 }
613 }
614
615 if(mf<0.){ //field --
616 meanZ = -0.468318 ;
617 if(charge>0)
618 meanX=TMath::Min(7.3, 3.89994*1.20679*1.20679/(pt*pt+1.20679*1.20679)+0.249029+2.49088e+07*TMath::Exp(-pt*3.33650e+01)) ;
619 else
620 meanX=-TMath::Min(7.7,3.86040*0.912499*0.912499/(pt*pt+0.912499*0.912499)+1.23114+4.48277e+05*TMath::Exp(-pt*2.57070e+01)) ;
621 }
622 else{ //Field ++
623 meanZ= -0.468318;
624 if(charge>0)
625 meanX=-TMath::Min(8.0,3.86040*1.31357*1.31357/(pt*pt+1.31357*1.31357)+0.880579+7.56199e+06*TMath::Exp(-pt*3.08451e+01)) ;
626 else
627 meanX= TMath::Min(6.85, 3.89994*1.16240*1.16240/(pt*pt+1.16240*1.16240)-0.120787+2.20275e+05*TMath::Exp(-pt*2.40913e+01)) ;
628 }
629
630 Double_t rz=(dz-meanZ)/sz ;
631 Double_t rx=(dx-meanX)/sx ;
632 return TMath::Sqrt(rx*rx+rz*rz) ;
633}
634
635//________________________________________________________________________
636Bool_t AliPHOSTenderSupply::IsGoodChannel(Int_t mod, Int_t ix, Int_t iz)
637{
638 //Check if this channel belogs to the good ones
639
640 if(mod>4 || mod<1){
641// AliError(Form("No bad map for PHOS module %d ",mod)) ;
642 return kTRUE ;
643 }
644 if(!fPHOSBadMap[mod]){
645// AliError(Form("No Bad map for PHOS module %d",mod)) ;
646 return kTRUE ;
647 }
648 if(fPHOSBadMap[mod]->GetBinContent(ix,iz)>0)
649 return kFALSE ;
650 else
651 return kTRUE ;
652}
653//________________________________________________________________________
654void AliPHOSTenderSupply::ForceUsingBadMap(const char * filename){
655 //Read TH2I histograms with bad maps from local or alien file
656 TFile * fbm = TFile::Open(filename) ;
657 if(!fbm || !fbm->IsOpen()){
658 AliError(Form("Can not open BadMaps file %s",filename)) ;
659 return ;
660 }
661 gROOT->cd() ;
662 char key[55] ;
663 for(Int_t mod=1;mod<4; mod++){
664 snprintf(key,55,"PHOS_BadMap_mod%d",mod) ;
665 TH2I * h = (TH2I*)fbm->Get(key) ;
666 if(h)
667 fPHOSBadMap[mod] = new TH2I(*h) ;
668 }
669 fbm->Close() ;
670 fUsePrivateBadMap=kTRUE ;
671}
672//________________________________________________________________________
673void AliPHOSTenderSupply::ForceUsingCalibration(const char * filename){
674 //Read PHOS recalibration parameters from the file.
675 //We assume that file contains single entry: AliPHOSCalibData
676 TFile * fc = TFile::Open(filename) ;
677 if(!fc || !fc->IsOpen()){
678 AliFatal(Form("Can not open Calibration file %s",filename)) ;
679 return ;
680 }
681 fPHOSCalibData = (AliPHOSCalibData*)fc->Get("PHOSCalibration") ;
682 fc->Close() ;
683 fUsePrivateCalib=kTRUE;
684}
685//________________________________________________________________________
686void AliPHOSTenderSupply::CorrectPHOSMisalignment(TVector3 &global,Int_t mod){
687 //Correct for PHOS modules misalignment
688
689 //correct misalignment
690 const Float_t shiftX[6]={0.,-2.3,-2.11,-1.53,0.,0.} ;
691 const Float_t shiftZ[6]={0.,-0.4, 0.52, 0.8,0.,0.} ;
692 TVector3 localPos ;
693 fPHOSGeo->Global2Local(localPos,global,mod) ;
694 fPHOSGeo->Local2Global(mod,localPos.X()+shiftX[mod],localPos.Z()+shiftZ[mod],global);
695}
696//________________________________________________________________________
697void AliPHOSTenderSupply::EvalLambdas(AliVCluster * clu, Double_t &m02, Double_t &m20){
698 //calculate dispecrsion of the cluster in the circle with radius distanceCut around the maximum
699
700 const Double_t rCut=4.5 ;
701
702 Double32_t * elist = clu->GetCellsAmplitudeFraction() ;
703// Calculates the center of gravity in the local PHOS-module coordinates
704 Float_t wtot = 0;
705 Double_t xc[100]={0} ;
706 Double_t zc[100]={0} ;
707 Double_t x = 0 ;
708 Double_t z = 0 ;
709 Int_t mulDigit=TMath::Min(100,clu->GetNCells()) ;
710 const Double_t logWeight=4.5 ;
711 for(Int_t iDigit=0; iDigit<mulDigit; iDigit++) {
712 Int_t relid[4] ;
713 Float_t xi ;
714 Float_t zi ;
715 fPHOSGeo->AbsToRelNumbering(clu->GetCellAbsId(iDigit), relid) ;
716 fPHOSGeo->RelPosInModule(relid, xi, zi);
717 xc[iDigit]=xi ;
718 zc[iDigit]=zi ;
719 if (clu->E()>0 && elist[iDigit]>0) {
720 Float_t w = TMath::Max( 0., logWeight + TMath::Log( elist[iDigit] / clu->E() ) ) ;
721 x += xc[iDigit] * w ;
722 z += zc[iDigit] * w ;
723 wtot += w ;
724 }
725 }
726 if (wtot>0) {
727 x /= wtot ;
728 z /= wtot ;
729 }
730
731 wtot = 0. ;
732 Double_t dxx = 0.;
733 Double_t dzz = 0.;
734 Double_t dxz = 0.;
735 Double_t xCut = 0. ;
736 Double_t zCut = 0. ;
737 for(Int_t iDigit=0; iDigit<mulDigit; iDigit++) {
738 if (clu->E()>0 && elist[iDigit]>0.) {
739 Double_t w = TMath::Max( 0., logWeight + TMath::Log( elist[iDigit] / clu->E() ) ) ;
740 Double_t xi= xc[iDigit] ;
741 Double_t zi= zc[iDigit] ;
742 if((xi-x)*(xi-x)+(zi-z)*(zi-z) < rCut*rCut){
743 xCut += w * xi ;
744 zCut += w * zi ;
745 dxx += w * xi * xi ;
746 dzz += w * zi * zi ;
747 dxz += w * xi * zi ;
748 wtot += w ;
749 }
750 }
751
752 }
753 if (wtot>0) {
754 xCut/= wtot ;
755 zCut/= wtot ;
756 dxx /= wtot ;
757 dzz /= wtot ;
758 dxz /= wtot ;
759 dxx -= xCut * xCut ;
760 dzz -= zCut * zCut ;
761 dxz -= xCut * zCut ;
762
763 m02 = 0.5 * (dxx + dzz) + TMath::Sqrt( 0.25 * (dxx - dzz) * (dxx - dzz) + dxz * dxz ) ;
764 m20 = 0.5 * (dxx + dzz) - TMath::Sqrt( 0.25 * (dxx - dzz) * (dxx - dzz) + dxz * dxz ) ;
765 }
766 else {
767 m20=m02=0.;
768 }
769
770}
5bd0f028 771//____________________________________________________________________________
772Double_t AliPHOSTenderSupply::CoreEnergy(AliVCluster * clu){
773 //calculate energy of the cluster in the circle with radius distanceCut around the maximum
774
775 //Can not use already calculated coordinates?
776 //They have incidence correction...
777 const Double_t distanceCut =3.5 ;
778 const Double_t logWeight=4.5 ;
779
780 Double32_t * elist = clu->GetCellsAmplitudeFraction() ;
781// Calculates the center of gravity in the local PHOS-module coordinates
782 Float_t wtot = 0;
783 Double_t xc[100]={0} ;
784 Double_t zc[100]={0} ;
785 Double_t x = 0 ;
786 Double_t z = 0 ;
787 Int_t mulDigit=TMath::Min(100,clu->GetNCells()) ;
788 for(Int_t iDigit=0; iDigit<mulDigit; iDigit++) {
789 Int_t relid[4] ;
790 Float_t xi ;
791 Float_t zi ;
792 fPHOSGeo->AbsToRelNumbering(clu->GetCellAbsId(iDigit), relid) ;
793 fPHOSGeo->RelPosInModule(relid, xi, zi);
794 xc[iDigit]=xi ;
795 zc[iDigit]=zi ;
796 if (clu->E()>0 && elist[iDigit]>0) {
797 Float_t w = TMath::Max( 0., logWeight + TMath::Log( elist[iDigit] / clu->E() ) ) ;
798 x += xc[iDigit] * w ;
799 z += zc[iDigit] * w ;
800 wtot += w ;
801 }
802 }
803 if (wtot>0) {
804 x /= wtot ;
805 z /= wtot ;
806 }
807 Double_t coreE=0. ;
808 for(Int_t iDigit=0; iDigit < mulDigit; iDigit++) {
809 Double_t distance = TMath::Sqrt((xc[iDigit]-x)*(xc[iDigit]-x)+(zc[iDigit]-z)*(zc[iDigit]-z)) ;
810 if(distance < distanceCut)
811 coreE += elist[iDigit] ;
812 }
813 //Apply non-linearity correction
814 return coreE ;
815}
53442b36 816//____________________________________________________________________________
817Double_t AliPHOSTenderSupply::EvalEcross(AliVCluster * clu){
818 //Calculate propoerion of the cluster energy in cross around the
819 //cell with maximal energy deposition. Can be used to reject exotic clusters
820
821 Double32_t * elist = clu->GetCellsAmplitudeFraction() ;
822 Int_t mulDigit=clu->GetNCells() ;
823 // Calculates the center of gravity in the local PHOS-module coordinates
824 //Find cell with max E
825 Double_t eMax=0.;
826 Int_t iMax=0;
827 for(Int_t iDigit=0; iDigit<mulDigit; iDigit++) {
828 if(elist[iDigit]>eMax){
829 eMax=elist[iDigit] ;
830 iMax=iDigit ;
831 }
832 }
833 //Calculate e in cross
834 Double_t eCross=0 ;
835 Int_t relidMax[4] ;
836 fPHOSGeo->AbsToRelNumbering(clu->GetCellAbsId(iMax), relidMax) ;
837 Int_t relid[4] ;
838 for(Int_t iDigit=0; iDigit<mulDigit; iDigit++) {
839 fPHOSGeo->AbsToRelNumbering(clu->GetCellAbsId(iDigit), relid) ;
840 if(TMath::Abs(relid[2]-relidMax[2])+TMath::Abs(relid[3]-relidMax[3])==1)
841 eCross+= elist[iDigit] ;
842 }
843 if(eMax>0)
844 return 1.-eCross/eMax ;
845 else
846 return 0 ;
847}
848
849
f7d0ec90 850//________________________________________________________________________
851Double_t AliPHOSTenderSupply::EvalTOF(AliVCluster * clu,AliVCaloCells * cells){
852 //Evaluate TOF of the cluster after re-calibration
853 //TOF here is weighted average of digits
854 // -within 50ns from the most energetic cell
855 // -not too soft.
1e7fec1c 856
f7d0ec90 857 Double32_t * elist = clu->GetCellsAmplitudeFraction() ;
858 Int_t mulDigit=clu->GetNCells() ;
859
860 Float_t tMax= 0.; //Time at the maximum
861 Float_t eMax=0. ;
862 for(Int_t iDigit=0; iDigit<mulDigit; iDigit++) {
863 Int_t absId=clu->GetCellAbsId(iDigit) ;
864 Bool_t isHG=kTRUE ;
1e7fec1c 865 if(cells->GetCellMCLabel(absId)==-2){ //This is LG digit.
866 isHG=kFALSE ;
867 }
f7d0ec90 868 if( elist[iDigit]>eMax){
869 tMax=CalibrateTOF(cells->GetCellTime(absId),absId,isHG) ;
870 eMax=elist[iDigit] ;
871 }
872 }
f7d0ec90 873
874 //Try to improve accuracy
875 //Do not account time of soft cells:
876 // const Double_t part=0.5 ;
877 Double_t eMin=TMath::Min(0.5,0.2*eMax) ;
878 Float_t wtot = 0.;
879 Double_t t = 0. ;
880 for(Int_t iDigit=0; iDigit<mulDigit; iDigit++) {
881 Int_t absId=clu->GetCellAbsId(iDigit) ;
882 Bool_t isHG=kTRUE ;
1e7fec1c 883 if(cells->GetCellMCLabel(absId)==-2){ //This is LG digit.
f7d0ec90 884 isHG=kFALSE ;
1e7fec1c 885 }
886
f7d0ec90 887 Double_t ti=CalibrateTOF(cells->GetCellTime(absId),absId,isHG) ;
888 if(TMath::Abs(ti-tMax)>50.e-9) //remove soft cells with wrong time
889 continue ;
890
891 //Remove too soft cells
892 if(elist[iDigit]<eMin)
893 continue ;
894
895 if(elist[iDigit]>0){
896 //weight = 1./sigma^2
897 //Sigma is parameterization of TOF resolution 16.05.2013
898 Double_t wi2=0.;
899 if(isHG)
1e7fec1c 900 wi2=1./(2.4 + 3.9/elist[iDigit]) ;
f7d0ec90 901 else
1e7fec1c 902 wi2=1./(2.4 + 3.9/(0.1*elist[iDigit])) ; //E of LG digit is 1/16 of correcponding HG
f7d0ec90 903 t+=ti*wi2 ;
904 wtot+=wi2 ;
905 }
906 }
907 if(wtot>0){
908 t=t/wtot ;
1e7fec1c 909 }
910 else{
911 t=tMax ;
f7d0ec90 912 }
913
914 return t ;
915
916}
917//________________________________________________________________________
918Double_t AliPHOSTenderSupply::CalibrateTOF(Double_t tof, Int_t absId, Bool_t isHG){
919 //Apply time re-calibration separately for HG and LG channels
920 //By default (if not filled) shifts are zero.
921
922 Int_t relId[4];
923 fPHOSGeo->AbsToRelNumbering(absId,relId) ;
924 Int_t module = relId[0];
925 Int_t column = relId[3];
926 Int_t row = relId[2];
927 if(isHG)
928 tof-=fPHOSCalibData->GetTimeShiftEmc(module, column, row);
1e7fec1c 929 else{
f7d0ec90 930 tof-=fPHOSCalibData->GetLGTimeShiftEmc(module, column, row);
1e7fec1c 931 }
f7d0ec90 932 return tof ;
933
934}
393b3556 935//________________________________________________________________________
936void AliPHOSTenderSupply::DistanceToBadChannel(Int_t mod, TVector3 * locPos, Double_t &minDist){
937 //Check if distance to bad channel was reduced
938 Int_t range = minDist/2.2 +1 ; //Distance at which bad channels should be serached
939
940 Int_t relid[4]={0,0,0,0} ;
941 fPHOSGeo->RelPosToRelId(mod, locPos->X(), locPos->Z(), relid) ;
942 Int_t xmin=TMath::Max(1,relid[2]-range) ;
943 Int_t xmax=TMath::Min(64,relid[2]+range) ;
944 Int_t zmin=TMath::Max(1,relid[3]-range) ;
945 Int_t zmax=TMath::Min(56,relid[3]+range) ;
946
947 Float_t x=0.,z=0.;
948 for(Int_t ix=xmin;ix<=xmax;ix++){
949 for(Int_t iz=zmin;iz<=zmax;iz++){
950 if(fPHOSBadMap[mod]->GetBinContent(ix,iz)>0){ //Bad channel
951 Int_t relidBC[4]={mod,0,ix,iz} ;
952 fPHOSGeo->RelPosInModule(relidBC,x,z);
953 Double_t dist = TMath::Sqrt((x-locPos->X())*(x-locPos->X()) + (z-locPos->Z())*(z-locPos->Z()));
954 if(dist<minDist) minDist = dist;
955 }
956 }
957 }
958
959}
960
e1c158c2 961