2 #include <EVENT/LCObject.h>
3 #include <EVENT/LCCollection.h>
4 #include <EVENT/SimCalorimeterHit.h>
5 #include <IMPL/ClusterImpl.h>
6 #include <IMPL/LCCollectionVec.h>
7 #include <IMPL/LCRelationImpl.h>
8 #include <UTIL/LCTOOLS.h>
9 #include <UTIL/LCRelationNavigator.h>
11 #include "ClusterShapes.h"
21 #include <marlin/Global.h>
22 #include <gear/GEAR.h>
23 #include <gear/TPCParameters.h>
24 #include <gear/CalorimeterParameters.h>
28 #define MASK_K (unsigned int) 0x3F000000
31 #define MASK_M (unsigned int) 0x00000007
34 using namespace lcio ;
35 using namespace marlin ;
40 bool to_be_saved(
const MCParticle * parm ,
const float cut ,
const CalorimeterHit* calhit);
46 _description =
"Creates true clusters..." ;
48 registerOutputCollection( LCIO::CLUSTER,
49 "TrueClusterCollection",
50 "Collection of True Clusters",
52 std::string(
"TrueClusters"));
54 registerOutputCollection( LCIO::LCRELATION,
55 "TrueClusterToMCPCollection",
56 "Relation Collection Cluster to MCP",
58 std::string(
"TrueClusterToMCP"));
60 std::vector<std::string> caloCollections;
62 caloCollections.push_back(std::string(
"ECAL"));
63 caloCollections.push_back(std::string(
"HCAL"));
66 registerInputCollections( LCIO::CALORIMETERHIT,
68 "Calorimeter Collection Names",
72 registerInputCollection( LCIO::LCRELATION,
74 "SimCaloHit to CaloHit Relations Collection Name",
76 std::string(
"RelationCaloHit"));
78 registerInputCollection( LCIO::MCPARTICLE,
79 "MCParticleCollection",
80 "Calorimeter Collection Names",
82 std::string(
"MCParticle"));
84 registerProcessorParameter(
"CutBackscatter",
85 "Not to connect hist from backscatter",
89 registerProcessorParameter(
"MinHitsInCluster",
90 "Minimal number of hits in cluster",
102 const gear::TPCParameters& pTPC = Global::GEAR->getTPCParameters();
103 gearRMax =pTPC.getDoubleVal(
"tpcOuterRadius");
104 zmax= pTPC.getMaxDriftLength();
122 float noPointerEcal=0.0;
125 typedef std::map <MCParticle*,ClusterImpl*> mapMCP2Clust;
127 mapMCP2Clust p2clust;
133 const LCCollection * relcol ;
136 unsigned int nhits = col->getNumberOfElements();
142 LCRelationNavigator navigate(relcol);
144 for (
unsigned int j=0; j < nhits; ++j)
146 CalorimeterHit * calhit =
dynamic_cast<CalorimeterHit*
>(col->getElementAt(j));
147 LCObjectVec objectVec = navigate.getRelatedToObjects(calhit);
149 if (objectVec.size() > 0) {
151 vector<MCParticle*> vpar;
152 vector<float>contrib;
153 SimCalorimeterHit * simhit=0;
154 unsigned int ncontrib;
155 vector<MCParticle*>::iterator testp;
156 for(
unsigned int k=0;
k<objectVec.size();++
k)
158 simhit=
dynamic_cast<SimCalorimeterHit*
>( objectVec[
k]);
159 ncontrib=simhit->getNMCContributions();
161 for (
unsigned int kk=0; kk<ncontrib;++kk)
163 MCParticle * par=simhit->getParticleCont(kk);
166 testp=find(vpar.begin(),vpar.end(),par);
167 countp=testp-vpar.begin();
169 if( testp == vpar.end())
172 contrib.push_back(simhit->getEnergyCont(kk));
174 contrib[countp]+=simhit->getEnergyCont(kk);
178 vector<float>::iterator naj;
179 naj=max_element(contrib.begin(),contrib.end());
182 int max=naj-contrib.begin();
184 MCParticle * par =vpar[max];
191 if (p2clust[par] == NULL)
194 float x=par->getVertex()[0];
195 float y=par->getVertex()[1];
196 float z=par->getVertex()[2];
197 float radius=sqrt(x*x+y*y);
198 x=par->getEndpoint()[0];
199 y=par->getEndpoint()[1];
200 float z1=par->getEndpoint()[2];
201 float radius1=sqrt(x*x+y*y);
209 ClusterImpl * cluster =
new ClusterImpl();
210 p2clust[par]=cluster;
212 cluster->addHit(calhit,(
float)1.0);
214 if(par->getParents().size()!=0)
216 par=par->getParents()[0];
223 ClusterImpl * cluster = p2clust[par];
225 cluster->addHit(calhit,(
float)1.0);
230 noPointerEcal+=simhit->getEnergyCont(0);
243 mapMCP2Clust::iterator pos;
245 for (pos = p2clust.begin(); pos != p2clust.end(); ++pos)
247 MCParticle * mcp = pos->first;
249 ClusterImpl * cluster = pos->second;
252 CalorimeterHitVec calohitvec = cluster->getCalorimeterHits();
253 int nhcl = (int)calohitvec.size();
261 center[0]=0.0; center[1]=0.0; center[2]=0.0;
262 for (
int i=0; i< nhcl; ++i)
264 CalorimeterHit * calhit = calohitvec[i];
265 float energy=calhit->getEnergy();
266 center[0]+= (calhit->getPosition()[0])*energy;
267 center[1]+= (calhit->getPosition()[1])*energy;
268 center[2]+= (calhit->getPosition()[2])*energy;
272 center[0]=center[0]/totene;
273 center[1]=center[1]/totene;
274 center[2]=center[2]/totene;
275 cluster->setPosition(center);
276 cluster->setEnergy(totene);
277 clscol->addElement(cluster);
279 LCRelationImpl * rel =
new LCRelationImpl(cluster,mcp,(
float)1.0);
280 relationcol->addElement( rel );
298 cout <<
"cluster cheater n hits lost = " <<
_nlost << endl;
301 bool to_be_saved(
const MCParticle * parm ,
const float cut,
const CalorimeterHit * calhit )
305 vector<MCParticle*> particlesToRec ;
307 for(
unsigned int pp=0;pp<parm->getDaughters().size();++pp)
309 MCParticle * par =parm->getDaughters()[pp];
311 stack <MCParticle*> krk;
316 int testz=count(particlesToRec.begin(),particlesToRec.end(),par);
333 int testz=count(particlesToRec.begin(),particlesToRec.end(),par);
337 particlesToRec.push_back(par);
339 for(
unsigned int i=0;i<par->getDaughters().size();++i)
341 krk.push(par->getDaughters()[i]);
342 particlesToRec.push_back(par->getDaughters()[i]);
351 vector<MCParticle*> particlesToBack ;
352 stack <MCParticle*> krk;
353 for (
unsigned int i=0; i< particlesToRec.size();++i)
355 if( particlesToRec[i]->isBackscatter() )
357 particlesToBack.push_back( particlesToRec[i]);
358 krk.push(particlesToRec[i]);
365 MCParticle* par=krk.top();
369 int testz=count(particlesToBack.begin(),particlesToBack.end(),par);
373 particlesToBack.push_back(par);
375 for(
unsigned int i=0;i<par->getDaughters().size();++i)
377 krk.push(par->getDaughters()[i]);
378 particlesToBack.push_back(par->getDaughters()[i]);
387 float x1=calhit->getPosition()[0];
388 float y1=calhit->getPosition()[1];
389 float z1=calhit->getPosition()[2];
390 float px=parm->getMomentum()[0];
391 float py=parm->getMomentum()[1];
392 float pz=parm->getMomentum()[2];
393 for (
unsigned int i=0; i< particlesToBack.size();++i)
395 float x=particlesToBack[i]->getEndpoint()[0];
396 float y=particlesToBack[i]->getEndpoint()[1];
397 float z=particlesToBack[i]->getEndpoint()[2];
401 float dd=px*x1+py*y1+pz*z1;
402 float d=sqrt((x-x1)*(x-x1)+(y-y1)*(y-y1)+(z-z1)*(z-z1));
404 if ( d< cut || dd<0.0)
std::string _trueClustToMCP
std::string _relCollection
ClusterCheater5_3 aClusterCheater5_3
virtual void processRunHeader(LCRunHeader *run)
Called for every run.
std::string _trueClustCollection
virtual void end()
Called after data processing for clean up.
std::map< MCParticle *, ClusterImpl * > map_MCP_Clust
virtual void processEvent(LCEvent *evt)
Called for every event - the working horse.
virtual void init()
Initialization.
std::vector< std::string > _caloCollections
std::string _MCcollection
std::vector< LCCollection * > LCCollectionVec
virtual void check(LCEvent *evt)
std::map< MCParticle *, HelixClass * > map_MCP_Helix
bool to_be_saved(const MCParticle *parm, const float cut, const CalorimeterHit *calhit)