FairRoot/PandaRoot
Functions
analysis_cluster_energyCorrection_Ntuple.C File Reference
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include "TF1.h"

Go to the source code of this file.

Functions

int analysis_cluster_energyCorrection_Ntuple ()
 

Function Documentation

int analysis_cluster_energyCorrection_Ntuple ( )

Double_t highestenergy_sumOfclusters=0; // (set per event)

highestenergy_sumOfclusters += highestenergy[k]; if (k==NumberOfClusters_thresholdPassed-1) //eventually write the summation of the cluster enegies

cout <<"highestenergy_sumOfclusters = "<< highestenergy_sumOfclusters <<'
'<<endl;

Definition at line 7 of file analysis_cluster_energyCorrection_Ntuple.C.

References cluster_array, cluster_energy, ctime, digi_array, Double_t, ene_mc, PndEmcCluster::energy(), fsim, PndMCTrack::Get4Momentum(), PndEmcCluster::GetModule(), PndMCTrack::GetMomentum(), i, mctrack, mctrack_array, ncounts, p4mom, PndEmcCluster::phi(), phi_mc, photon_momentum, Pi, printf(), rtime, PndEmcCluster::theta(), theta_mc, timer, tsim, and TString.

8 {
9  TStopwatch timer;
10  timer.Start();
11  gROOT->LoadMacro("$VMCWORKDIR/macro/mvd/Tools.C");
12  gROOT->Macro("$VMCWORKDIR/gconfig/rootlogon.C");
13 
15  TString inputfile("/home/moini/myPandaRoot/myCodes/ROOTfiles/FullEmc_isotropicPhotonGeneration/emc_complete_10to5000MeVphotons.root");
16  TString outputfile("./energyCorrectionFactors_30MeVthreshold_cond2_Ntuple_10MillionEvt.root");
17  //TString inputfile("/home/moini/myPandaRoot/myCodes/ROOTfiles/FwEndCapResolution_vacuum_noMagField/assuming150photonsperMeV/emc_complete_1GeVphotons.root");
18  //TString outputfile("../seinsitivityToBinning/h_cAndEta_c/moduleDistribution_1GeVphotons_onlyFWendCap.root");
20  TFile* fsim = new TFile(inputfile);
21 
22  TNtuple evtParams("EventParams", "Selected Event parameters","eMc:eCluster:ClustEnCorrFactor:clustTheta:clustPhi");
23 
24  TTree *tsim=(TTree *) fsim->Get("pndsim") ;
25  TClonesArray* mctrack_array=new TClonesArray("PndMCTrack");
26  tsim->SetBranchAddress("MCTrack",&mctrack_array);
27 
28  TClonesArray* digi_array=new TClonesArray("PndEmcDigi");
29  tsim->SetBranchAddress("EmcDigi",&digi_array);
30 
31  TClonesArray* cluster_array=new TClonesArray("PndEmcCluster");
32  tsim->SetBranchAddress("EmcCluster",&cluster_array);
33 
34  //TClonesArray* bump_array=new TClonesArray("PndEmcBump");
35  //tsim->SetBranchAddress("EmcBump",&bump_array);
36 
38  TVector3 photon_momentum;
39  TLorentzVector p4mom;
40  Double_t clusterThresholdEnergy=0.030;//in GeV
41 
42  Int_t ncounts = tsim->GetEntriesFast();
43  cout << "Number of events = " << ncounts<< endl;
44  //ncounts=200000; //to analyse specific number of events
45 
46  TH1I *HISTnumberOfClusters_thresholdPassed = new TH1I("HISTnumberOfClusters_thresholdPassed","Total number of clusters per event satisfying cluster threshold",140,0,70);
47  TH1F *moduleDistribution_3MeVthreshold = new TH1F("moduleDistribution_3MeVthreshold","",10,0.25,5.25);
48  TH1F *moduleDistribution_10MeVthreshold = new TH1F("moduleDistribution_10MeVthreshold","",10,0.25,5.25);
49  TH1F *moduleDistribution_30MeVthreshold = new TH1F("moduleDistribution_30MeVthreshold","",10,0.25,5.25);
50 
51  Double_t clusterEnergyCorrectionFactor_max = 0;
52  Double_t ene_mc_max = 0;
53 
54  for (int j = 0; j < ncounts; j++) {
55 
56  Double_t clusterEnergyCorrectionFactor = 0;
57  float ClustEnergy = 0.0;
58  float clustPhi, clustTheta;
59 
60  tsim->GetEntry(j);
61 
62  PndMCTrack *mctrack=(PndMCTrack *) mctrack_array->At(0);
63  photon_momentum=mctrack->GetMomentum();
64  theta_mc=photon_momentum.Theta()*(180./TMath::Pi());
65  phi_mc=photon_momentum.Phi()*(180./TMath::Pi());
66  p4mom=mctrack->Get4Momentum();
67  ene_mc=p4mom.E();
69  Int_t NumberOfClusters, ClustNo, NumberOfClusters_thresholdPassed;
70  NumberOfClusters=ClustNo=NumberOfClusters_thresholdPassed=0; //set per event
71  Int_t idClusterSatisfiedThresholdEnergy=-1;
73  Double_t totalClusterEnergies = 0;
74 
75  std::vector <double> highestenergy;
76  std::vector <double> originalClusterIndex;
77 
78  if (cluster_array->GetEntriesFast() > 0)
79  {
80  NumberOfClusters=cluster_array->GetEntriesFast();
81  std::vector <double> clusterEnergies;
82  std::vector <double> clusterEnergies_original;
83 
84  for (Int_t i=0; i<NumberOfClusters; i++) //loop over all clusters of the present event under analysis (ndigi>=1)
85  {
86  PndEmcCluster *cluster=(PndEmcCluster*)cluster_array->At(i);
87  Double_t cluster_energy=cluster->energy();
88  clusterEnergies.push_back(cluster_energy); //first push all the cluster energies into the vector; no sorting yet
89  clusterEnergies_original.push_back(cluster_energy); //make another one, in order to keep track of indices
91  if (cluster_energy >= 0.003)
92  moduleDistribution_3MeVthreshold->Fill(cluster->GetModule());
93  if (cluster_energy >= 0.010)
94  moduleDistribution_10MeVthreshold->Fill(cluster->GetModule());
95  if (cluster_energy >= 0.030)
96  moduleDistribution_30MeVthreshold->Fill(cluster->GetModule());
98  if (cluster_energy >= clusterThresholdEnergy)
99  {
100  NumberOfClusters_thresholdPassed++;
101  totalClusterEnergies += cluster_energy;
102  }
103  }
104 
105  // Per-event analysis of all the clusters
106  std::sort(clusterEnergies.begin(), clusterEnergies.end()); //now sort all the recognized clusters in the FwEndCap
107  //std::reverse(clusterEnergies.begin(), clusterEnergies.end());
108 
109  if (NumberOfClusters_thresholdPassed >= 1) //finding at least one cluster satisfying threshold energy
110  {
111  for (int k=0; k<NumberOfClusters; k++)
112  {
113  highestenergy.push_back(clusterEnergies[(NumberOfClusters-1)-k]);
114  //cout << "decsendingly sorted energy of cluster # " << k+1 << " = " << highestenergy[k] << '\n';
118 
119  for (int i=0; i<NumberOfClusters; i++)//finding the original cluster index of the cluster
120  if (!(clusterEnergies_original[i]>highestenergy[k]) && !(clusterEnergies_original[i]<highestenergy[k]))//practically the equality sign
121  originalClusterIndex.push_back(i);
122 
123 
124  PndEmcCluster *cluster=(PndEmcCluster*)cluster_array->At(originalClusterIndex[k]);
125  //(k==0 corresponds to the cluster with highest energy deposit)
126  if (k==0 && (totalClusterEnergies >= (ene_mc - 0.050)) && NumberOfClusters_thresholdPassed==1)//&& ((cluster->theta()*(180./TMath::Pi()))-theta_mc)<=5.
127  //&& requiring the condition on the event energy (assuming 50 MeV tolerance on the energy) ----> cond1
128  //&& requiring only one cluster per event satisfying the threshold ----> cond2
129  //&& requiring a tolerance for the allowed difference between the theta angles of this cluster and the Monte Carlo angle ----> cond3
130  {
131  ClustEnergy = cluster->energy();
132  clusterEnergyCorrectionFactor = ene_mc/ClustEnergy;
133  if (clusterEnergyCorrectionFactor > clusterEnergyCorrectionFactor_max)
134  {
135  clusterEnergyCorrectionFactor_max = clusterEnergyCorrectionFactor;
136  ene_mc_max = ene_mc;
137  }
138  clustPhi = cluster->phi()*(180./TMath::Pi());
139  clustTheta = cluster->theta()*(180./TMath::Pi());
140 
141  // Fill Ntuple
142  evtParams.Fill(ene_mc, ClustEnergy, clusterEnergyCorrectionFactor, clustTheta, clustPhi);
143 
144  }
145  }
146  }
147  }
148 
149  if (NumberOfClusters_thresholdPassed>0)
150  HISTnumberOfClusters_thresholdPassed->Fill(NumberOfClusters_thresholdPassed); //number of clusters per event, having more than or equal to one digi per cluster
151 
152 
153  if (j%1000 ==0)
154  cout<<"Evt. No. "<< j<<endl;
155  }
156 cout << "clusterEnergyCorrectionFactor_max= "<<clusterEnergyCorrectionFactor_max << " for the Monte Carlo energy of "<< ene_mc_max<< " GeV\n"<< endl;
157  //++++++++++++++++++++++++++++++++++++++++
158 
159  TFile myoutPutFile(outputfile,"RECREATE","Woww", 9);
160  HISTnumberOfClusters_thresholdPassed->Write();
161  moduleDistribution_3MeVthreshold->Write();
162  moduleDistribution_10MeVthreshold->Write();
163  moduleDistribution_30MeVthreshold->Write();
164 
165  evtParams.Write();
166 
167  myoutPutFile.Close();
168 
169 
170  timer.Stop();
171  Double_t rtime = timer.RealTime();
172  Double_t ctime = timer.CpuTime();
173  printf("RealTime=%f seconds, CpuTime=%f seconds\n",rtime,ctime);
174  return 0;
175 }
PndMCTrack * mctrack
printf("RealTime=%f seconds, CpuTime=%f seconds\n", rtime, ctime)
Double_t theta_mc
Int_t i
Definition: run_full.C:25
TVector3 photon_momentum
Short_t GetModule() const
TClonesArray * digi_array
TVector3 GetMomentum() const
Definition: PndMCTrack.h:78
TLorentzVector Get4Momentum() const
Definition: PndMCTrack.cxx:102
TClonesArray * cluster_array
Double_t
TStopwatch timer
Definition: hit_dirc.C:51
Double_t cluster_energy
a cluster (group of neighboring crystals) of hit emc crystals
Definition: PndEmcCluster.h:29
Double_t ctime
Definition: hit_dirc.C:114
virtual Double_t energy() const
Double_t theta() const
TClonesArray * mctrack_array
TLorentzVector p4mom
Double_t rtime
Definition: hit_dirc.C:113
Double_t Pi
Double_t phi() const