3 /****************************************************************************
4 * AliTkJetTrigger.cxx *
5 * Test version of jet-trigger, includes many analysis functions to tune *
7 * Thorsten Kollegger <kollegge@ikf.physik.uni-frankfurt.de> *
8 ***************************************************************************/
10 #include <Riostream.h>
13 #include <TParticle.h>
14 #include <TClonesArray.h>
16 #include "AliTkChargedJetFinder.h"
17 #include "AliTkJetTriggerDecision.h"
18 #include "AliTkJetTriggerEvent.h"
19 #include "AliTkJetTrigger.h"
21 void AliTkJetTrigger::init() {
22 // open file and create tree...
23 if (getEvOutFilename() != NULL) {
24 cout << "Writing events to " << getEvOutFilename() << endl;
25 mEvOutFile = new TFile(getEvOutFilename(),"RECREATE");
26 mEvOutEvent = new AliTkJetTriggerEvent();
27 mEvOutTree = new TTree("jetTrigger","");
28 mEvOutTree->Branch("event","AliTkJetTriggerEvent",&mEvOutEvent,32000,99);
32 void AliTkJetTrigger::initEvent() {
33 // can not be implemented, we need the particles...
36 void AliTkJetTrigger::initEvent(TClonesArray *particles, Int_t type) {
37 setParticleType(type);
41 void AliTkJetTrigger::initEvent(TClonesArray *particles) {
42 const UInt_t mParticlesDefaultSize = getExpectedParticleNumber();
43 // make a copy of all accepted particles
44 // just to be sure that they are not modified...
50 mParticles = new TClonesArray("TParticle",mParticlesDefaultSize);
51 TIterator *iter = particles->MakeIterator();
54 while ((particle = (TParticle *) iter->Next()) != NULL) {
55 if (isParticleAccepted(particle)) {
56 if(particle->Pt()>fParticleMinPt)
57 new ((*mParticles)[pos++]) TParticle(*particle);
64 void AliTkJetTrigger::make() {
65 // fill the matrix containing trigger decision for all different cone radia,
66 // nParticles and PtThresholds...
67 // loop over all seedpoints...
68 cout << "generated " << seedPoints.size() << " seedpoints" << endl;
69 for (list<AliTkEtaPhiVector>::const_iterator seedIter = seedPoints.begin();
70 seedIter != seedPoints.end(); ++seedIter) {
71 AliTkEtaPhiVector coneCenter(*seedIter);
72 for (list<Float_t>::const_iterator radiusIter = mConeRadia.begin();
73 radiusIter != mConeRadia.end(); ++radiusIter) {
74 // get particles in cone
75 list<TParticle*> *myParticles = getParticlesInCone(coneCenter,
77 // loop over all PtThresholds...
78 for (list<Float_t>::const_iterator PtThreshold =mConePtThreshold.begin();
79 PtThreshold != mConePtThreshold.end(); ++PtThreshold) {
80 // loop over all nParticles thresholds...
81 for (list<UInt_t>::const_iterator nParticles = mConeNParticles.begin();
82 nParticles != mConeNParticles.end(); ++nParticles) {
83 // what's the decision???
84 if (decide(myParticles,*PtThreshold,*nParticles)) {
85 AliTkJetTriggerDecision *d = new AliTkJetTriggerDecision();
86 d->setConeRadius(*radiusIter);
87 d->setPtThreshold(*PtThreshold);
88 d->setNParticles(*nParticles);
89 mEvOutEvent->addDecision(d);
90 // new change, requires testing
93 } // end of nParticle threshold loop
94 } // end of PtThreshold loop
95 myParticles->erase(myParticles->begin(),myParticles->end());
97 } // end of cone radia loop
98 } // end of seed point loop
101 void AliTkJetTrigger::finishEvent() {
102 // let's write out all triggered settings...
108 mEvOutEvent->clear();
109 seedPoints.erase(seedPoints.begin(),seedPoints.end());
112 void AliTkJetTrigger::finish() {
113 // write object containing settings
116 if (!mEvOutFile->IsOpen()) { cerr << "WHAT?" << endl; }
123 void AliTkJetTrigger::setDefaults() {
125 fParticleMinPtSeed=1;
132 addConeNParticles(1);
133 addConeNParticles(2);
134 addConeNParticles(3);
135 addConeNParticles(4);
136 addConeNParticles(5);
137 addConePtThreshold(1.);
138 addConePtThreshold(2.);
139 addConePtThreshold(3.);
140 addConePtThreshold(4.);
141 addConePtThreshold(5.);
143 setEvOutFilename("$JF_DATADIR/trigger.evout.root");
144 setExpectedParticleNumber(30000);
147 void AliTkJetTrigger::setParticleType(Int_t type) {
148 mParticleType = type;
149 // current used particles types:
150 // 1 == TParticle from TPythia6
151 // 2 == TParticle from THijing
152 // 3 == TParticle from TPythia6 + ALICE acceptance approximation
153 // 4 == TParticle from THijing + ALICE acceptance approximation
156 void AliTkJetTrigger::addConeRadius(Float_t radius) {
157 mConeRadia.push_back(radius);
160 void AliTkJetTrigger::addConeNParticles(UInt_t nParticles) {
161 mConeNParticles.push_back(nParticles);
164 void AliTkJetTrigger::addConePtThreshold(Float_t ptThreshold) {
165 mConePtThreshold.push_back(ptThreshold);
168 void AliTkJetTrigger::mixParticles(TClonesArray *particles, Int_t type) {
169 // mixes particles to the existing event
176 TParticle *particle = NULL;
178 pos = mParticles->GetLast()+1;
179 TIterator *iter = particles->MakeIterator();
180 while ((particle = (TParticle *) iter->Next()) != NULL) {
181 if (isParticleAccepted(particle,type)) {
182 new ((*mParticles)[pos++]) TParticle(*particle);
186 // we need to generate new seedPoints...
187 seedPoints.erase(seedPoints.begin(),seedPoints.end());
191 void AliTkJetTrigger::createSeedPoints() {
193 TIterator *iter = mParticles->MakeIterator();
194 while ((particle = (TParticle *)iter->Next()) != NULL) {
195 // particles are checked for acceptance during initEvent, mixParticles
196 // if (isParticleAccepted(particle)) {
197 if (particle->Pt() > fParticleMinPtSeed) {
198 AliTkEtaPhiVector v(particle->Eta(),particle->Phi());
199 seedPoints.push_back(v);
206 Bool_t AliTkJetTrigger::isParticleAccepted(TParticle *particle) {
207 return isParticleAccepted(particle,getParticleType());
210 Bool_t AliTkJetTrigger::isParticleAccepted(TParticle *particle, Int_t type) {
213 return isParticleAcceptedPythia(particle);
216 return isParticleAcceptedHijing(particle);
219 return isParticleAcceptedPythiaAliceGeo(particle);
222 return isParticleAcceptedHijingAliceGeo(particle);
228 Bool_t AliTkJetTrigger::isParticleAcceptedPythia(TParticle *particle) {
229 // check for stable particle
230 if (particle->GetStatusCode() != 1) {
236 Bool_t AliTkJetTrigger::isParticleAcceptedPythiaAliceGeo(TParticle *particle) {
237 // check if valid PYTHIA particle
238 if (!isParticleAcceptedPythia(particle)) {
241 // check if particle is in |eta| < 1
242 if (TMath::Abs(particle->Eta()) > 1) {
245 // check if charged particle
246 TParticlePDG *partPDG = particle->GetPDG();
247 if (partPDG->Charge() == 0) {
253 Bool_t AliTkJetTrigger::isParticleAcceptedHijing(TParticle */*particle*/) {
257 Bool_t AliTkJetTrigger::isParticleAcceptedHijingAliceGeo(TParticle *particle) {
258 if (!isParticleAcceptedHijing(particle)) {
261 // check if particle is in |eta| < 1
262 if (TMath::Abs(particle->Eta()) > 1) {
265 // check if charged particle
266 TParticlePDG *partPDG = particle->GetPDG();
267 if (partPDG->Charge() == 0) {
273 void AliTkJetTrigger::clearParticles() {
274 // delete my particle copy...
276 mParticles->Delete();
282 list<TParticle*> *AliTkJetTrigger::getParticlesInCone(AliTkEtaPhiVector center,
284 return getParticlesInCone(center,radius,mParticles);
287 list<TParticle*> *AliTkJetTrigger::getParticlesInCone(AliTkEtaPhiVector center,
289 TClonesArray *particles) {
290 // returns a list with all particles which are in a cone with radius around
292 // one can easily speed up this part by saving the last cone+parameters and
293 // calculate the new one from this one if there is some overlap
294 list<TParticle*> *myParticles = new list<TParticle*>;
295 Float_t radiusSq = radius*radius;
296 TIterator *iter = particles->MakeIterator();
298 while ((particle = (TParticle *)iter->Next()) != NULL) {
299 AliTkEtaPhiVector pos(particle->Eta(),particle->Phi());
300 if (center.diffSq(pos) < radiusSq) {
301 myParticles->push_back(particle);
308 Bool_t AliTkJetTrigger::decide(list<TParticle*> *particles, Float_t ptThreshold,
311 for (list<TParticle*>::const_iterator iter = particles->begin();
312 iter != particles->end(); ++iter) {
313 if ((*iter)->Pt() > ptThreshold) {
317 if (n >= nParticles) {
323 void AliTkJetTrigger::setEvOutFilename(Char_t *filename) {
325 mEvOutName = new Char_t[4096];
327 strcpy(mEvOutName,filename);
331 ClassImp(AliTkJetTrigger)