ROOT logo



Int_t nLayers =0;
Int_t GetLayer(AliTrackReference *ref, TObject *obj);

void residuals(){

  gSystem->Load("libITSUpgradeBase.so");
  gSystem->Load("libITSUpgradeRec.so");
  gSystem->Load("libITSUpgradeSim.so");

  gROOT->SetStyle("Plain");
  gStyle->SetOptStat(1111111);
  Int_t nbins=100;
  Int_t xmin=0;
  Int_t xmax=50000;//00*1e-09;

  AliITSsegmentationUpgrade *seg = new AliITSsegmentationUpgrade();
  
  if(!seg){
    printf("no segmentation info available... Exiting");
    return;
  }

  nLayers = seg->GetNLayers();

  Int_t nbins=100;
  Int_t xmin = -10;
  Int_t xmax= 10;
  Int_t zmin = -3000;
  Int_t zmax= 3000;

  TH1D **hDiffx, **hDiffy, **hDiffz, **hDiffRphi, **hDiffR;
  
  hDiffx    = new TH1D[nLayers];
  hDiffy    = new TH1D[nLayers];
  hDiffz    = new TH1D[nLayers];
  hDiffRphi = new TH1D[nLayers];
  hDiffR    = new TH1D[nLayers];
    
  for(Int_t i=0; i<nLayers; i++){
    hDiffx[i] = new TH1D(Form("hDiffX%i",i),Form("#Delta X Glob (Clusters - track ref  [Layer %i])",i),100,-40,40);
    hDiffy[i] = new TH1D(Form("hDiffY%i",i),Form("#Delta Y Glob (Clusters - track ref  [Layer %i])",i),100,-40,40);
    if(i<4) hDiffz[i] = new TH1D(Form("hDiffZ%i",i),Form("#Delta Z Glob (Clusters - track ref  [Layer %i])",i),50,-300,300);
    else hDiffz[i] = new TH1D(Form("hDiffZ%i",i),Form("#Delta Z Glob (Clusters - track ref  [Layer %i])",i),100,-2000,2000);
    hDiffRphi[i] = new TH1D(Form("hDiffRphi%i",i),Form("#Delta R #phi [Layer %i]",i),200,-100,100);
    hDiffRphi[i]->SetXTitle("#mum");
    hDiffR[i]= new TH1D(Form("hR%i",i),Form("#Delta R (cluster-track ref) [Layer %i]",i),nbins,xmin/20.,xmax/20.);
    hDiffR[i]->SetXTitle("#mum");
  }

  gAlice=NULL;
  AliRunLoader* runLoader = AliRunLoader::Open("galice.root");
  runLoader->LoadgAlice();

  gAlice = runLoader->GetAliRun();

  runLoader->LoadHeader();
  runLoader->LoadKinematics();
  runLoader->LoadTrackRefs();
  runLoader->LoadRecPoints();

  AliLoader *dl = runLoader->GetDetectorLoader("ITS");

  //Trackf
  TTree *trackRefTree = 0x0; 
  TClonesArray *trackRef = new TClonesArray("AliTrackReference",1000);
  //RECPOINT
  TTree *clusTree = 0x0;
  TClonesArray statITSCluster("AliITSRecPointU");


  AliITSsegmentationUpgrade *segmentation2=segmentation2 = new AliITSsegmentationUpgrade();
  // Loop over events
  for(Int_t i=0; i<runLoader->GetNumberOfEvents(); i++){
    runLoader->GetEvent(i); 
    AliStack *stack = runLoader->Stack(); 
    trackRefTree=runLoader->TreeTR();
    TBranch *br = trackRefTree->GetBranch("TrackReferences");
    if(!br) {
      printf("no TR branch available , exiting \n");
      return;
    }
    br->SetAddress(&trackRef);

    printf("event : %i \n",i);
    // init the clusters tree 
    clusTree=dl->TreeR();
    TClonesArray *ITSCluster = &statITSCluster;
    TBranch* itsClusterBranch=clusTree->GetBranch("ITSRecPoints");
    if (!itsClusterBranch) {
      printf("can't get the branch with the ITS clusters ! \n");
      return;
    }

    itsClusterBranch->SetAddress(&ITSCluster);

    // init the trackRef tree 
    trackRefTree=runLoader->TreeTR();
    trackRefTree->SetBranchAddress("TrackReferences",&trackRef);

    //for(Int_t il=0; il<nLayers; il++){
    if (!clusTree->GetEvent(0))    continue;
    Int_t nCluster = ITSCluster->GetEntriesFast();
    for(Int_t in=0; in<nCluster; in++){
      AliITSRecPointU *recp = (AliITSRecPointU*)ITSCluster->UncheckedAt(in);
      Int_t il = recp->GetLayer();  
      Double_t xr,yr,zr = 0.;
      Double_t xz[2];
      xz[0]= recp->GetDetLocalX(); //gets fXloc
      xz[1]= recp->GetDetLocalZ();   //gets fZloc
      segmentation2->DetToGlobal(il,recp->GetModule(),xz[0], xz[1],xr,yr,zr);
      for(Int_t iLabel =0; iLabel<12; iLabel++){
	if(recp->GetTrackID(iLabel)<0) continue; 
	trackRefTree->GetEntry(stack->TreeKEntry(recp->GetTrackID(iLabel)));  	
	Int_t nref=trackRef->GetEntriesFast();
	for(Int_t iref =0; iref<nref; iref++){
	  Double_t x,y,z=0.;
	  Int_t labelTR=-999;
	  AliTrackReference *trR = (AliTrackReference*)trackRef->At(iref);
	  if(!trR) continue;
	  if(trR->DetectorId()!=AliTrackReference::kITS) continue;
	  if(!stack->IsPhysicalPrimary(recp->GetTrackID(iLabel))) continue;   
	  Int_t lay = GetLayer(trR, seg);    
	  if(TMath::Abs(lay-il)>0.5) continue;          
	  x=trR->X();
	  y=trR->Y();
	  z=trR->Z();
	  Double_t xx, zz;
	  Int_t mod;
	  segmentation2->GlobalToDet(il,x,y,x,xx,zz,mod);
	  //printf("cluster module %i  - module %i \n",recp->GetModule(),mod);
	  Double_t rTr = TMath::Sqrt(x*x+y*y); 

	  Double_t difx, dify, difz=0.;
	  Double_t dify=0.;
	  Double_t difz=0.;
	  Double_t deltaR=0.;
	  difx = xr - x;
	  dify = yr - y;
	  difz = zr - z;
	  Double_t phiGlob = TMath::ATan2(yr,xr);
	  if(yr<0) phiGlob+=TMath::TwoPi();
	  Double_t phiTr = TMath::ATan2(y,x);
	  if(y<0) phiTr+=TMath::TwoPi();
	  Double_t deltaPhi =  phiGlob-phiTr;
	      
	  Double_t deltaRphi = (phiGlob*TMath::Sqrt(xr*xr+yr*yr)-phiTr*rTr)*1e+04;
	  if(TMath::Abs(deltaRphi)/1e+04 > 3*(10000.*seg->GetCellSizeX(lay))) {
	    // printf("   Layer %i   type %i  dRphi %f  segm %f  \n",lay,recp->GetType(),deltaRphi/1e+04,seg->GetCellSizeX(lay)*10000.);
	    // printf("   Layer %i   type %i   Track (x,y,z) = (%f,%f,%f) Phi %f   Rphi %f         Cluster (x,y,z) = (%f,%f,%f)  Phi %f Rphi %f \n",lay,recp->GetType(),x,y,z,TMath::RadToDeg()*phiTr,phiTr*TMath::Sqrt(x*x+y*y),xr,yr,zr,TMath::RadToDeg()*phiGlob,phiGlob*TMath::Sqrt(xr*xr+yr*yr));
	  }              
	  deltaR = (TMath::Sqrt(xr*xr+yr*yr)-TMath::Sqrt(x*x+y*y))*1e+04;

	  hDiffx[il]->Fill(difx*1e04);
	  hDiffy[il]->Fill(dify*1e04);
	  hDiffz[il]->Fill(difz*1e04);
	  hDiffRphi[il]->Fill(deltaRphi);
	  hDiffR[il]->Fill(deltaR);
           
	}//loop entries fast 
      } 
    }//loop clusters
    //}//loop layer
  }//loop entries runloader
  
  TCanvas *c3x = new TCanvas("cGx","Delta in X global",200,10,900,900);
  c3x->Divide(3,nLayers/3);
  TCanvas *c3y = new TCanvas("cGy","Delta in Y global",200,10,900,900);
  c3y->Divide(3,nLayers/3);
  TCanvas *c3z = new TCanvas("cGz","Delta in Z global",200,10,900,900);
  c3z->Divide(3,nLayers/3);
  TCanvas *c3rphi = new TCanvas("cRphi","Delta R-Phi",200,10,900,900);
  c3rphi->Divide(3,nLayers/3);
  TCanvas *c3r = new TCanvas("cR","Delta R-Phi",200,10,900,900);
  c3r->Divide(3,nLayers/3);
  

  for(Int_t iL=0; iL< nLayers; iL++){
    c3x->cd(iL+1);
    hDiffx[iL]->Draw();
    c3y->cd(iL+1);
    hDiffy[iL]->Draw();
    c3z->cd(iL+1);
    hDiffz[iL]->Draw();
    c3rphi->cd(iL+1);
    hDiffRphi[iL]->Draw();
    c3r->cd(iL+1);
    hDiffR[iL]->Draw();
  }
 
}// main macro read


Int_t GetLayer(AliTrackReference *ref, TObject *obj){
 
  AliITSsegmentationUpgrade *seg = (AliITSsegmentationUpgrade*)obj;
  Int_t ilayer =-1;
  for(Int_t ila=0; ila<6; ila++){
    if(ila==(nLayers-1)){
      if(ref->R()>seg->GetRadius(ila)+seg->GetThickness(ila)) ilayer=(nLayers-1);
    }
    else {
      if(ref->R()>seg->GetRadius(ila)+seg->GetThickness(ila) && ref->R()<seg->GetRadius(ila+1)) ilayer=ila;
    }
  }
  return ilayer;
}

 residuals.C:1
 residuals.C:2
 residuals.C:3
 residuals.C:4
 residuals.C:5
 residuals.C:6
 residuals.C:7
 residuals.C:8
 residuals.C:9
 residuals.C:10
 residuals.C:11
 residuals.C:12
 residuals.C:13
 residuals.C:14
 residuals.C:15
 residuals.C:16
 residuals.C:17
 residuals.C:18
 residuals.C:19
 residuals.C:20
 residuals.C:21
 residuals.C:22
 residuals.C:23
 residuals.C:24
 residuals.C:25
 residuals.C:26
 residuals.C:27
 residuals.C:28
 residuals.C:29
 residuals.C:30
 residuals.C:31
 residuals.C:32
 residuals.C:33
 residuals.C:34
 residuals.C:35
 residuals.C:36
 residuals.C:37
 residuals.C:38
 residuals.C:39
 residuals.C:40
 residuals.C:41
 residuals.C:42
 residuals.C:43
 residuals.C:44
 residuals.C:45
 residuals.C:46
 residuals.C:47
 residuals.C:48
 residuals.C:49
 residuals.C:50
 residuals.C:51
 residuals.C:52
 residuals.C:53
 residuals.C:54
 residuals.C:55
 residuals.C:56
 residuals.C:57
 residuals.C:58
 residuals.C:59
 residuals.C:60
 residuals.C:61
 residuals.C:62
 residuals.C:63
 residuals.C:64
 residuals.C:65
 residuals.C:66
 residuals.C:67
 residuals.C:68
 residuals.C:69
 residuals.C:70
 residuals.C:71
 residuals.C:72
 residuals.C:73
 residuals.C:74
 residuals.C:75
 residuals.C:76
 residuals.C:77
 residuals.C:78
 residuals.C:79
 residuals.C:80
 residuals.C:81
 residuals.C:82
 residuals.C:83
 residuals.C:84
 residuals.C:85
 residuals.C:86
 residuals.C:87
 residuals.C:88
 residuals.C:89
 residuals.C:90
 residuals.C:91
 residuals.C:92
 residuals.C:93
 residuals.C:94
 residuals.C:95
 residuals.C:96
 residuals.C:97
 residuals.C:98
 residuals.C:99
 residuals.C:100
 residuals.C:101
 residuals.C:102
 residuals.C:103
 residuals.C:104
 residuals.C:105
 residuals.C:106
 residuals.C:107
 residuals.C:108
 residuals.C:109
 residuals.C:110
 residuals.C:111
 residuals.C:112
 residuals.C:113
 residuals.C:114
 residuals.C:115
 residuals.C:116
 residuals.C:117
 residuals.C:118
 residuals.C:119
 residuals.C:120
 residuals.C:121
 residuals.C:122
 residuals.C:123
 residuals.C:124
 residuals.C:125
 residuals.C:126
 residuals.C:127
 residuals.C:128
 residuals.C:129
 residuals.C:130
 residuals.C:131
 residuals.C:132
 residuals.C:133
 residuals.C:134
 residuals.C:135
 residuals.C:136
 residuals.C:137
 residuals.C:138
 residuals.C:139
 residuals.C:140
 residuals.C:141
 residuals.C:142
 residuals.C:143
 residuals.C:144
 residuals.C:145
 residuals.C:146
 residuals.C:147
 residuals.C:148
 residuals.C:149
 residuals.C:150
 residuals.C:151
 residuals.C:152
 residuals.C:153
 residuals.C:154
 residuals.C:155
 residuals.C:156
 residuals.C:157
 residuals.C:158
 residuals.C:159
 residuals.C:160
 residuals.C:161
 residuals.C:162
 residuals.C:163
 residuals.C:164
 residuals.C:165
 residuals.C:166
 residuals.C:167
 residuals.C:168
 residuals.C:169
 residuals.C:170
 residuals.C:171
 residuals.C:172
 residuals.C:173
 residuals.C:174
 residuals.C:175
 residuals.C:176
 residuals.C:177
 residuals.C:178
 residuals.C:179
 residuals.C:180
 residuals.C:181
 residuals.C:182
 residuals.C:183
 residuals.C:184
 residuals.C:185
 residuals.C:186
 residuals.C:187
 residuals.C:188
 residuals.C:189
 residuals.C:190
 residuals.C:191
 residuals.C:192
 residuals.C:193
 residuals.C:194
 residuals.C:195
 residuals.C:196
 residuals.C:197
 residuals.C:198
 residuals.C:199
 residuals.C:200
 residuals.C:201
 residuals.C:202
 residuals.C:203
 residuals.C:204
 residuals.C:205
 residuals.C:206
 residuals.C:207
 residuals.C:208
 residuals.C:209
 residuals.C:210
 residuals.C:211