SND@LHC Software
Loading...
Searching...
No Matches
ecalMatch.cxx
Go to the documentation of this file.
1#include "ecalMatch.h"
2
3#include "ecalCellMC.h"
4#include "ecalStructure.h"
5#include "ecalReconstructed.h"
6
7#include "ShipMCTrack.h"
8
9#include "TClonesArray.h"
10
11#include <iostream>
12#include <list>
13#include <map>
14
15using namespace std;
16
17void ecalMatch::Exec(Option_t* option,TClonesArray* reconstructed,TClonesArray* mctracks)
18{
19 fReconstucted=reconstructed;
20 fMCTracks=mctracks;
21 fEv++; fN=0; fRejected=0;
22
23 Int_t n=fReconstucted->GetEntries();
24 Int_t i;
26 ecalCell* cell;
27 ecalCellMC* mccell;
28 list<ecalCell*> cells;
29 list<ecalCell*>::const_iterator p;
30 map<Int_t, Float_t> e;
31 map<Int_t, Float_t> e2;
32 map<Int_t, Float_t>::const_iterator ep;
33 map<Int_t, Float_t>::reverse_iterator rp;
34 ShipMCTrack* tr;
35 Int_t trn;
36 Float_t max;
37// if (fVerbose>0) Info("Exec", "Event %d.", fEv);
38 for(i=0;i<n;i++)
39 {
41 cell=fStr->GetHitCell(rc->CellNum());
42 cells.clear();
43
44 if (fUse3x3)
45 {
46 cell->GetNeighborsList(cells); //3x3 without maximum
47 cells.push_back(cell);
48 }
49 else
50 cell->Get5x5Cluster(cells);
51
52 e.clear(); e2.clear();
53 //Counting energy depositions for all particles
54 for(p=cells.begin();p!=cells.end();++p)
55 {
56 mccell=(ecalCellMC*)(*p);
57 for(ep=mccell->GetTrackEnergyBegin();ep!=mccell->GetTrackEnergyEnd();++ep)
58 {
59 if (e.find(ep->first)==e.end())
60 e[ep->first]=ep->second;
61 else
62 e[ep->first]+=ep->second;
63 }
64 }
65
66 //...and parent photons and electrons/positrons
67 for(ep=e.begin();ep!=e.end();++ep)
68 {
69 if (e2.find(ep->first)==e.end())
70 e2[ep->first]=ep->second;
71 else
72 e2[ep->first]+=ep->second;
73 if (ep->first<0&&fVerbose==0) continue;
74 tr=(ShipMCTrack*)fMCTracks->At(ep->first);
75 if (tr==NULL)
76 {
77 Info("Exec", "Event %d. Can't find MCTrack %d.", fEv, ep->first);
78 continue;
79 }
80 for(;;)
81 {
82 if (tr->GetPdgCode()!=22&&TMath::Abs(tr->GetPdgCode())!=11) break;
83 trn=tr->GetMotherId();
84 if (trn<0) break;
85 tr=(ShipMCTrack*)fMCTracks->At(trn);
86 if (tr==NULL)
87 {
88 Info("Exec", "Event %d. Can't find MCTrack %d.", fEv, ep->first);
89 break;
90 }
91 if (tr->GetPdgCode()!=22&&TMath::Abs(tr->GetPdgCode())!=11) break;
92 if (e2.find(trn)==e2.end())
93 e2[trn]=ep->second;
94 else
95 e2[trn]+=ep->second;
96 }
97 }
98
99 //Maximum location
100 max=-1e11; trn=-1111;
101 for(rp=e2.rbegin();rp!=e2.rend();++rp)
102 {
103 if (rp->second>max)
104 { max=rp->second; trn=rp->first;}
105 }
106
107 if (trn>=0)
108 {
109 rc->SetMCTrack(trn);
110 fN++;
111 }
112 else
113 fRejected++;
114 }
115
116 if (fVerbose>0) Info("Exec", "Event %d. Matched %d. Skipped %d maxs.", fEv, fN, fRejected);
117}
118
120ecalMatch::ecalMatch(const char* name, const Int_t verbose)
121 : FairTask(name, verbose), fEv(0), fN(0), fRejected(0), fUse3x3(0),
122 fReconstucted(NULL), fMCTracks(NULL), fStr(NULL)
123{
124 ;
125}
126
129 : FairTask(), fEv(0), fN(0), fRejected(0), fUse3x3(0),
130 fReconstucted(NULL), fMCTracks(NULL), fStr(NULL)
131{
132 ;
133}
134
137{
138 ;
139}
140
143{
144 ;
145}
146
147InitStatus ecalMatch::Init()
148{
149 FairRootManager* io=FairRootManager::Instance();
150 if (!io)
151 {
152 Fatal("Init", "Can't find IOManager.");
153 return kFATAL;
154 }
155 fStr=(ecalStructure*)io->GetObject("EcalStructure");
156 if (!fStr)
157 {
158 Fatal("Init()", "Can't find calorimeter structure in the system.");
159 return kFATAL;
160 }
161 fReconstucted=(TClonesArray*)io->GetObject("EcalReco");
162 if (!fReconstucted)
163 {
164 Fatal("Init", "Can't find array of reconstructed calorimeter objects in the system.");
165 return kFATAL;
166 }
167 fMCTracks=(TClonesArray*)io->GetObject("MCTrack");
168 if (!fMCTracks)
169 {
170 Fatal("Init", "Can't find array of MC tracks in the system.");
171 return kFATAL;
172 }
173
174 fEv=0;
175 return kSUCCESS;
176}
177
178void ecalMatch::InitPython(ecalStructure* str, TClonesArray* reconstructed, TClonesArray* mctracks)
179{
180 fStr=str;
181 fReconstucted=reconstructed;
182 fMCTracks=mctracks;
183
184 fEv=0;
185}
186
Int_t GetPdgCode() const
Definition ShipMCTrack.h:58
Int_t GetMotherId() const
Definition ShipMCTrack.h:59
std::map< Int_t, Float_t >::const_iterator GetTrackEnergyBegin() const
Definition ecalCellMC.h:50
std::map< Int_t, Float_t >::const_iterator GetTrackEnergyEnd() const
Definition ecalCellMC.h:52
void GetNeighborsList(std::list< ecalCell * > &neib) const
Definition ecalCell.h:48
void Get5x5Cluster(std::list< ecalCell * > &cls)
Definition ecalCell.h:58
TClonesArray * fReconstucted
Definition ecalMatch.h:43
virtual void Finish()
virtual void Exec(Option_t *option, TClonesArray *reconstructed, TClonesArray *mctracks)
Definition ecalMatch.cxx:17
ecalStructure * fStr
Definition ecalMatch.h:47
void InitPython(ecalStructure *str, TClonesArray *reconstructed, TClonesArray *mctracks)
Int_t fN
Definition ecalMatch.h:36
Int_t fRejected
Definition ecalMatch.h:38
Int_t fUse3x3
Definition ecalMatch.h:40
TClonesArray * fMCTracks
Definition ecalMatch.h:45
virtual InitStatus Init()
Int_t fEv
Definition ecalMatch.h:34
ecalCell * GetHitCell(const Int_t hitId) const
ClassImp(ecalContFact) ecalContFact