FairRoot/PandaRoot
PndMvdRadDamTask.cxx
Go to the documentation of this file.
1 /*
2  * PndMvdRadDamTask.cxx
3  *
4  * Created on: Dec 16, 2008
5  * Author: stockman
6  */
7 
8 #include "PndMvdRadDamTask.h"
9 
10 #include "FairRootManager.h"
11 #include "PndSdsMCPoint.h"
12 #include "PndMCTrack.h"
13 #include "PndMvdRadDamHit.h"
14 #include "PndStringSeparator.h"
15 
16 
17 #include <iostream>
18 
20  fPersistance(kTRUE),
21  fMCTracks(NULL),
22  fMCHits(NULL),
23  fRadDamHits(NULL),
24  fElectronList(NULL),
25  fProtonList(NULL),
26  fNeutronList(NULL),
27  fPionList(NULL),
28  fGeoH(PndGeoHandling::Instance()),
29  fMapDetHistos(),
30  fRadDamHisto(NULL),
31  fWeightListsMap()
32 {
33 }
34 
36 {
37  for (std::map<std::string, TH2*>::iterator it = fMapDetHistos.begin(); it != fMapDetHistos.end(); it++)
38  delete(it->second);
39  fMapDetHistos.clear();
40  delete (fRadDamHisto);
41 }
42 
43 
45 {
46 }
47 
49 {
51  return kSUCCESS;
52 }
53 
55 {
56  FairRootManager* ioman = FairRootManager::Instance();
57 
58  if (!ioman)
59  {
60  std::cout << "-E- PndMvdRadDamTask::Init: "
61  << "RootManager not instantiated!" << std::endl;
62  return kFATAL;
63  }
64 
65  fMCTracks = (TClonesArray*) ioman->GetObject("MCTrack");
66  if (!fMCTracks)
67  {
68  std::cout << "-W- PndMvdRadDamTask::Init: " << "No MCTrack array!"
69  << std::endl;
70  return kERROR;
71  }
72 
73  fMCHits = (TClonesArray*) ioman->GetObject("MVDPoint");
74  if (!fMCHits)
75  {
76  std::cout << "-W- PndMvdRadDamTask::Init: " << "No MVDPoint array!"
77  << std::endl;
78  return kERROR;
79  }
80 
81  // Create and register output array
82  fRadDamHits = new TClonesArray("PndMvdRadDamHit");
83  ioman->Register("MVDRadDamHit", "MVD", fRadDamHits, fPersistance);
84 
86  fRadDamHisto = new TH1D("radDamH","Weight Factors", 1000,0,100);
87 
88  std::cout << "-I- PndMvdRadDamTask: Initialization successful" << std::endl;
89 
90  return kSUCCESS;
91 }
92 
94 {
95  fElectronList = new PndMvdRadDamList("$VMCWORKDIR/pandaroot/mvd/MvdTools/MvdRadDamage/electronsWeight.root");
96  fProtonList = new PndMvdRadDamList("$VMCWORKDIR/pandaroot/mvd/MvdTools/MvdRadDamage/protonsWeight.root");
97  fNeutronList = new PndMvdRadDamList("$VMCWORKDIR/pandaroot/mvd/MvdTools/MvdRadDamage/neutronsWeight.root");
98  fPionList = new PndMvdRadDamList("$VMCWORKDIR/pandaroot/mvd/MvdTools/MvdRadDamage/pionsWeight.root");
99 
100  fWeightListsMap[11] = fElectronList; //e-
101  fWeightListsMap[-11] = fElectronList; //e+
102  fWeightListsMap[2212] = fProtonList; //p+
103  fWeightListsMap[-2212] = fProtonList; //p-
104  fWeightListsMap[2112] = fNeutronList; //n
105  fWeightListsMap[-2112] = fNeutronList; //n_bar
106  fWeightListsMap[111] = fPionList; //pi0
107  fWeightListsMap[211] = fPionList; //pi+
108  fWeightListsMap[-211] = fPionList; //pi-
109  fWeightListsMap[1000010030] = fProtonList; //Tritium
110  fWeightListsMap[1000010020] = fProtonList; //Deuterium
111 
112 
113 }
114 
115 void PndMvdRadDamTask::Exec(Option_t*)
116 {
117  // Reset output array
118  if ( ! fRadDamHits )
119  Fatal("Exec", "No RadDamArray");
120  fRadDamHits->Delete();
121 
122  PndSdsMCPoint* mcPoint;
123  PndMCTrack* mcTrack;
124 
125  for (int i = 0; i < fMCHits->GetEntriesFast(); i++){
126  mcPoint = (PndSdsMCPoint*)fMCHits->At(i);
127  mcTrack = (PndMCTrack*)(fMCTracks->At(mcPoint->GetTrackID()));
128  TVector3 mom;
129  mcPoint->Momentum(mom);
130  Double_t Ekin = mom.Mag();
131  Int_t pid = mcTrack->GetPdgCode();
132  Double_t weight = 0;
133  if (fWeightListsMap[pid] != NULL){
134  weight = fWeightListsMap[pid]->GetWeight(Ekin);
135  }
136  //std::cout << "WeightCalc: pid: " << pid << " Energy: " << Ekin << " Weight: " << weight << std::endl;
137  new ((*fRadDamHits)[i]) PndMvdRadDamHit(mcPoint->GetTrackID(), i, mcPoint->GetSensorID(), pid, Ekin,
138  mcPoint->GetPosition(), mom, weight);
139  TString detname = fGeoH->GetPath(mcPoint->GetSensorID());
140  if (fMapDetHistos[detname.Data()] == 0){
141  PndStringSeparator svec(detname.Data(),"/");
142  TVector3 sensDim = fGeoH->GetSensorDimensionsShortId(mcPoint->GetSensorID());
143  fMapDetHistos[detname.Data()] = new TH2D(svec.Replace("/","o").c_str(),
144  fGeoH->GetPath(mcPoint->GetSensorID()),
145  (Int_t)(2*sensDim.X()*10),-sensDim.X(),sensDim.X(), // point resolution mm^2
146  (Int_t)(2*sensDim.Y()*10),-sensDim.Y(),sensDim.Y());
147  }
148  TVector3 localHit = fGeoH->MasterToLocalShortId(mcPoint->GetPosition(), mcPoint->GetSensorID());
149  ((TH2D*)(fMapDetHistos[detname.Data()]))->Fill(localHit.X(), localHit.Y(), weight);
150  fRadDamHisto->Fill(weight);
151  }
152 }
153 
155 {
156  for (std::map<std::string, TH2*>::iterator it = fMapDetHistos.begin(); it != fMapDetHistos.end(); it++)
157  it->second->Write();
158  fRadDamHisto->Write();
159 }
160 
161 
TClonesArray * fMCHits
Int_t i
Definition: run_full.C:25
PndGeoHandling * fGeoH
Definition: anasim.C:34
TClonesArray * fMCTracks
std::map< Int_t, PndMvdRadDamList * > fWeightListsMap
Int_t GetPdgCode() const
Definition: PndMCTrack.h:73
PndGeoHandling * fGeoH
PndMvdRadDamList * fNeutronList
int pid()
virtual InitStatus Init()
Double_t mom
Definition: plot_dirc.C:14
Int_t GetSensorID() const
Definition: PndSdsMCPoint.h:89
TString GetPath(Int_t shortID)
for a given shortID the path is returned
TVector3 GetSensorDimensionsShortId(Int_t shortId)
Class to access the naming information of the MVD.
Double_t
TClonesArray * fRadDamHits
TString detname
Definition: anasim.C:61
TVector3 MasterToLocalShortId(const TVector3 &master, const Int_t &shortId)
virtual void Exec(Option_t *opt)
TVector3 GetPosition() const
Definition: PndSdsMCPoint.h:90
ClassImp(PndMvdRadDamTask)
virtual InitStatus ReInit()
PndMvdRadDamList * fProtonList
PndMvdRadDamList * fPionList
PndMvdRadDamList * fElectronList
virtual void Finish()
std::map< std::string, TH2 * > fMapDetHistos
virtual void SetParContainers()