1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
19 //_________________________________________________________________________
20 // Class for JetFinder Input preparation from simulated data
22 //*-- Author: Mark Horner (LBL/UCT)
27 #include "AliEMCALJetFinderInputSimPrep.h"
29 #include <TParticle.h>
30 #include <TParticlePDG.h>
34 #include <TObjectTable.h>
40 #include "AliEMCALFast.h"
42 #include "AliEMCALHit.h"
43 #include "AliEMCALGeometry.h"
44 #include "AliEMCALGetter.h"
45 #include "AliEMCALLoader.h"
46 #include "AliGenEventHeader.h"
47 #include "AliGenPythiaEventHeader.h"
48 #include "AliGenerator.h"
49 #include "AliHeader.h"
54 ClassImp(AliEMCALJetFinderInputSimPrep)
56 AliEMCALJetFinderInputSimPrep::AliEMCALJetFinderInputSimPrep()
58 // Default constructor
59 if (fDebug > 0) Info("AliEMCALJetFinderInputSimPrep","Beginning Constructor");
62 fSmearType = kSmearEffic;
64 fTrackType = kCharged;
68 AliEMCALJetFinderInputSimPrep::~AliEMCALJetFinderInputSimPrep()
70 if (fDebug > 0) Info("~AliEMCALJetFinderInputSimPrep","Beginning Destructor");
74 void AliEMCALJetFinderInputSimPrep::Reset(AliEMCALJetFinderResetType_t resettype)
76 // Method to reset data
77 if (fDebug > 1) Info("Reset","Beginning Reset");
81 fInputObject.Reset(resettype);
84 fInputObject.Reset(resettype);
87 fInputObject.Reset(resettype);
89 case kResetParameters:
90 fSmearType = kSmearEffic;
92 fTrackType = kCharged;
95 fSmearType = kSmearEffic;
97 fTrackType = kCharged;
98 fInputObject.Reset(resettype);
101 Warning("FillFromFile", "kResetPartons not implemented") ;
103 case kResetParticles:
104 Warning("FillFromFile", "kResetParticles not implemented") ;
107 Warning("FillFromFile", "kResetJets not implemented") ;
113 Int_t AliEMCALJetFinderInputSimPrep::FillFromFile(TString *filename, AliEMCALJetFinderFileType_t filetype,Int_t EventNumber,TString data="H")
115 if (fDebug > 1) Info("FillFromFile","Beginning FillFromFile");
116 fFileType = filetype;
117 AliEMCALGetter *gime = AliEMCALGetter::Instance(filename->Data());
118 if (fDebug > 1) Info("FillFromFile","Instantiated Getter with %s as the file",filename->Data());
119 if (data.Contains("S"))
121 gime->Event(EventNumber,"XS") ;
124 gime->Event(EventNumber,"XH") ;
126 if (fDebug > 1) Info("FillFromFile","Got event %i with option \"XH\"",EventNumber);
128 if ( fEMCALType == kHits ||
129 fEMCALType == kTimeCut )
131 if (data.Contains("S"))
139 if ( fTrackType != kNoTracks ) FillTracks();
140 if ( fFileType != kData){
143 /* gime->EmcalLoader()->UnloadRecParticles();
144 gime->EmcalLoader()->UnloadTracks();
149 void AliEMCALJetFinderInputSimPrep::FillHits()
151 // Fill from the hits to input object from simulation
152 if (fDebug > 1) Info("FillHits","Beginning FillHits");
154 // Access hit information
156 // AliEMCAL* pEMCAL = (AliEMCAL*) gAlice->GetModule("EMCAL");
157 // Info("AliEMCALJetFinderInputSimPrep","Title of the geometry is %s",pEMCAL->GetTitle());
158 AliEMCALGeometry* geom = AliEMCALGetter::Instance()->EMCALGeometry();
159 AliEMCALGetter *gime = AliEMCALGetter::Instance();
161 // TTree *treeH = AliEMCALGetter::Instance()->TreeH();
162 // Int_t ntracks = (Int_t) treeH->GetEntries();
168 /* for (Int_t track=0; track<ntracks;track++) {
170 nbytes += treeH->GetEvent(track);*/
174 for(Int_t i =0; i < gime->Hits()->GetEntries() ;i++)
177 if (fEMCALType == kTimeCut &&
178 (mHit->GetTime()>fTimeCut) ) continue;
179 Float_t x = mHit->X(); // x-pos of hit
180 Float_t y = mHit->Y(); // y-pos
181 Float_t z = mHit->Z(); // z-pos
182 Float_t eloss = mHit->GetEnergy(); // deposited energy
184 Float_t r = TMath::Sqrt(x*x+y*y);
185 Float_t theta = TMath::ATan2(r,z);
186 Float_t eta = -TMath::Log(TMath::Tan(theta/2.));
187 Float_t phi = TMath::ATan2(y,x);
188 etH = eloss*TMath::Sin(theta);
189 if (fDebug > 10) Info("FillHits","Values of hit energy %i",Int_t(1e7*etH));
190 if (geom->TowerIndexFromEtaPhi(eta,180.0/TMath::Pi()*phi) == -1)
194 Error("FillHits","Hit not inside EMCAL!");
199 fInputObject.AddEnergyToDigit(geom->TowerIndexFromEtaPhi(eta,180.0/TMath::Pi()*phi)-1,Int_t(1e7*etH));
205 void AliEMCALJetFinderInputSimPrep::FillTracks()
207 // Fill from particles simulating a TPC to input object from simulation
209 if (fDebug > 1) Info("FillTracks","Beginning FillTracks");
211 TParticlePDG* pdgP = 0;
213 Int_t npart = (gAlice->GetHeader())->GetNprimary();
214 if (fDebug > 1) Info("FillTracks","Header says there are %i primaries",npart);
215 //AliEMCALGetter *gime = AliEMCALGetter::Instance();
216 Float_t bfield,rEMCAL;
217 /* for (Int_t i =0; i<gime->NPrimaries(); i++)
219 cout<<gime->Primary(i)->GetFirstMother()<<endl;
220 if (gime->Primary(i)->GetFirstMother() == -1) {
222 gime->Primary(i)->Dump();
226 if (fDebug > 1) Info("FillTracks","Defining the geometry");
228 AliEMCAL* pEMCAL = (AliEMCAL*) gAlice->GetModule("EMCAL");
229 AliEMCALGeometry* geom = AliEMCALGeometry::GetInstance(pEMCAL->GetTitle(), "");
230 fEtaMax = geom->GetArm1EtaMax();
231 fEtaMin = geom->GetArm1EtaMin();
232 fPhiMax = TMath::Pi()/180.0*geom->GetArm1PhiMax();
233 fPhiMin = TMath::Pi()/180.0*geom->GetArm1PhiMin();
235 if (fDebug > 1) Info("FillTracks","Starting particle loop");
237 if (fDebug > 1) Info("FillTracks","Particle loop of %i",npart);
238 for (Int_t part = 0; part < npart; part++) {
239 mPart = gAlice->GetMCApp()->Particle(part);
240 //if (part%10) gObjectTable->Print();
241 pdgP = mPart->GetPDG();
243 if (fDebug > 5) Info("FillTracks","Checking if track is a primary");
245 if (fFileType == kPythia) {
246 if (mPart->GetStatusCode() != 1) continue;
247 } else if (fFileType == kHijing) {
248 if (mPart->GetFirstDaughter() >= 0 && mPart->GetFirstDaughter() < npart) continue;
251 if (fDebug > 15) Info("FillTracks","Checking if track (eta - %f, phi - %f) is in acceptance",mPart->Eta(),mPart->Phi());
252 if (fDebug > 10) Info("FillTracks","Checking if EMCAL acceptance ( %f < eta < %f, %f < phi < %f) is in acceptance",fEtaMin,fEtaMax,fPhiMin,fPhiMax);
254 if ((!fPythiaComparison)&&(mPart->Eta() > fEtaMax || mPart->Eta() < fEtaMin)) continue;
255 if ((!fPythiaComparison)&&(mPart->Phi() > fPhiMax || mPart->Phi() < fPhiMin)) continue;
258 {kProton, kProtonBar, kElectron, kPositron,
259 kNuE, kNuEBar, kGamma, kNeutron, kNeutronBar,
260 kMuonPlus, kMuonMinus, kK0Long , kPiPlus, kPiMinus,
261 kKPlus, kKMinus, kLambda0, kLambda0Bar, kK0Short,
262 kSigmaMinus, kSigmaPlus, kSigma0, kPi0, kK0, kK0Bar,
266 if (fDebug > 15) Info("FillTracks","Checking if track is rejected");
268 if ((fSmearType == kEfficiency ||
269 fSmearType == kSmearEffic) &&
271 if (AliEMCALFast::RandomReject(fEfficiency)) {
276 bfield = gAlice->Field()->SolenoidField();
277 rEMCAL = AliEMCALGeometry::GetInstance()->GetIPDistance();
278 Float_t rB = 3335.6 * mPart->Pt() / bfield; // [cm] (case of |charge|=1)
279 if (2.*rB < rEMCAL) continue; // track curls away
281 //if (part%10) gObjectTable->Print();
285 case kAllP: // All Stable particles to be included
286 if (fDebug > 5) Info("FillTracks","Storing track");
287 if (fSmearType == kSmear ||
288 fSmearType == kSmearEffic ){
290 TParticle *tmp = Smear(MPart);
291 fInputObject.AddTrack(Smear(MPart));
294 fInputObject.AddTrack(*mPart);
297 case kEM: // All Electromagnetic particles
298 if (mPart->GetPdgCode() == kElectron ||
299 mPart->GetPdgCode() == kMuonPlus ||
300 mPart->GetPdgCode() == kMuonMinus ||
301 mPart->GetPdgCode() == kPositron ){
302 if (fDebug > 5) Info("FillTracks","Storing electron or positron");
303 if (fSmearType == kSmear ||
304 fSmearType == kSmearEffic ){
306 TParticle *tmp = Smear(MPart);
307 fInputObject.AddTrack(tmp);
310 fInputObject.AddTrack(*mPart);
313 if ( mPart->GetPdgCode() == kGamma ){
314 fInputObject.AddTrack(*mPart);
315 if (fDebug > 5) Info("FillTracks","Storing gamma");
319 case kCharged: // All Particles with non-zero charge
320 if (pdgP->Charge() != 0) {
321 if (fDebug > 5) Info("FillTracks","Storing charged track");
322 if (fSmearType == kSmear ||
323 fSmearType == kSmearEffic ){
325 TParticle *tmp = Smear(MPart);
326 fInputObject.AddTrack(tmp);
329 fInputObject.AddTrack(*mPart);
333 case kNeutral: // All particles with no charge
334 if (pdgP->Charge() == 0){
335 fInputObject.AddTrack(*mPart);
336 if (fDebug > 5) Info("FillTracks","Storing neutral");
339 case kHadron: //All hadrons
340 if (mPart->GetPdgCode() != kElectron &&
341 mPart->GetPdgCode() != kPositron &&
342 mPart->GetPdgCode() != kMuonPlus &&
343 mPart->GetPdgCode() != kMuonMinus &&
344 mPart->GetPdgCode() != kGamma )
346 if (fDebug > 5) Info("FillTracks","Storing hadron");
347 if (pdgP->Charge() == 0){
348 fInputObject.AddTrack(*mPart);
350 if (fSmearType == kSmear ||
351 fSmearType == kSmearEffic ){
353 TParticle *tmp = Smear(MPart);
354 fInputObject.AddTrack(tmp);
357 fInputObject.AddTrack(*mPart);
362 case kChargedHadron: // only charged hadrons
363 if (mPart->GetPdgCode() != kElectron &&
364 mPart->GetPdgCode() != kPositron &&
365 mPart->GetPdgCode() != kGamma &&
366 mPart->GetPdgCode() != kMuonPlus &&
367 mPart->GetPdgCode() != kMuonMinus &&
368 pdgP->Charge() != 0 ){
369 if (fDebug > 5) Info("FillTracks","Storing charged hadron");
370 if (fSmearType == kSmear ||
371 fSmearType == kSmearEffic ){
373 TParticle *tmp = Smear(MPart);
374 fInputObject.AddTrack(tmp);
377 fInputObject.AddTrack(*mPart);
384 if (pdgP->Charge() != 0 || mPart->GetPdgCode() == kPi0 ||
385 mPart->GetPdgCode() == kGamma )
387 if (fDebug > 5) Info("FillTracks","Storing charged track");
388 if (fSmearType == kSmear ||
389 fSmearType == kSmearEffic ){
391 TParticle *tmp = Smear(MPart);
392 fInputObject.AddTrack(tmp);
395 fInputObject.AddTrack(*mPart);
399 case kNoNeutronNeutrinoKlong:
400 if ( mPart->GetPdgCode() != kNeutron &&
401 mPart->GetPdgCode() != kNeutronBar &&
402 mPart->GetPdgCode() != kK0Long &&
403 mPart->GetPdgCode() != kNuE &&
404 mPart->GetPdgCode() != kNuEBar &&
405 mPart->GetPdgCode() != kNuMu &&
406 mPart->GetPdgCode() != kNuMuBar &&
407 mPart->GetPdgCode() != kNuTau &&
408 mPart->GetPdgCode() != kNuTauBar )
410 if (fDebug > 5) Info("FillTracks","Storing charged track");
411 if (fSmearType == kSmear ||
412 fSmearType == kSmearEffic ){
414 TParticle *tmp = Smear(MPart);
415 fInputObject.AddTrack(tmp);
418 fInputObject.AddTrack(*mPart);
426 // Info("FillTracks","After Particle Storage");
427 //if (part%10) gObjectTable->Print();
429 } //end of particle loop
430 //gObjectTable->Print();
433 void AliEMCALJetFinderInputSimPrep::FillPartons()
436 // input object from simulation
437 if (fDebug > 1) Info("FillPartons","Beginning FillPartons");
439 AliGenEventHeader* evHeader = ((AliHeader*)(gAlice->GetHeader()))->GenEventHeader();
440 Float_t triggerJetValues[4];
441 AliEMCALParton tempParton;
443 if (fFileType == kPythia)
445 Int_t ntriggerjets = ((AliGenPythiaEventHeader*)evHeader)->NTriggerJets();
446 if (fDebug > 1) Info("FillPartons","Number of trigger jets --> %i",ntriggerjets);
447 for (Int_t jetcounter = 0 ; jetcounter < ntriggerjets; jetcounter++){
448 ((AliGenPythiaEventHeader*)evHeader)->TriggerJet(jetcounter,triggerJetValues);
449 TLorentzVector tempLParton;
450 tempLParton.SetPxPyPzE(triggerJetValues[0],triggerJetValues[1],triggerJetValues[2],triggerJetValues[3]);
451 tempParton.SetEnergy(tempLParton.Energy());
452 tempParton.SetEta(tempLParton.Eta());
453 tempParton.SetPhi(tempLParton.Phi());
454 FillPartonTracks(&tempParton);
455 fInputObject.AddParton(&tempParton);
461 void AliEMCALJetFinderInputSimPrep::FillParticles()
463 // Fill particles to input object from simulation
464 if (fDebug > 1) Info("FillParticles","Beginning FillParticles");
466 Int_t npart = (gAlice->GetHeader())->GetNprimary();
467 TParticlePDG* pdgP = 0;
469 for (Int_t part = 0; part < npart; part++) {
470 TParticle *mPart = gAlice->GetMCApp()->Particle(part);
471 pdgP = mPart->GetPDG();
473 if (fDebug > 10) Info("FillParticles","Checking if particle is a primary");
475 if (fFileType == kPythia) {
476 if (mPart->GetStatusCode() != 1) continue;
477 } else if (fFileType == kHijing) {
478 if (mPart->GetFirstDaughter() >= 0 && mPart->GetFirstDaughter() < npart) continue;
481 if (fDebug > 10) Info("FillParticles","Checking if particle is in acceptance");
483 if ((!fPythiaComparison)&&(mPart->Eta() > fEtaMax || mPart->Eta() < fEtaMin)) continue;
484 if ((!fPythiaComparison)&&(mPart->Phi() > fPhiMax || mPart->Phi() < fPhiMin)) continue;
488 {kProton, kProtonBar, kElectron, kPositron,
489 kNuE, kNuEBar, kGamma, kNeutron, kNeutronBar,
490 kMuonPlus, kMuonMinus, kK0Long , kPiPlus, kPiMinus,
491 kKPlus, kKMinus, kLambda0, kLambda0Bar, kK0Short,
492 kSigmaMinus, kSigmaPlus, kSigma0, kPi0, kK0, kK0Bar,
498 case kAllP: // All Stable particles to be included
499 if (fDebug > 5) Info("FillParticles","Storing particle");
500 fInputObject.AddParticle(mPart);
502 case kEM: // All Electromagnetic particles
503 if (mPart->GetPdgCode() == kElectron ||
504 mPart->GetPdgCode() == kPositron ||
505 mPart->GetPdgCode() == kGamma){
506 if (fDebug > 5) Info("FillParticles","Storing electromagnetic particle");
507 fInputObject.AddParticle(mPart);
510 case kCharged: // All Particles with non-zero charge
511 if (pdgP->Charge() != 0) {
512 if (fDebug > 5) Info("FillParticles","Storing charged particle");
513 fInputObject.AddParticle(mPart);
516 case kNeutral: // All particles with no charge
517 if (pdgP->Charge() == 0){
518 if (fDebug > 5) Info("FillParticles","Storing neutral particle");
519 fInputObject.AddParticle(mPart);
522 case kHadron: //All hadrons
523 if (mPart->GetPdgCode() != kElectron &&
524 mPart->GetPdgCode() != kPositron &&
525 mPart->GetPdgCode() != kGamma )
528 if (fDebug > 5) Info("FillParticles","Storing hadron");
529 fInputObject.AddParticle(mPart);
532 case kChargedHadron: // only charged hadrons
533 if (mPart->GetPdgCode() != kElectron &&
534 mPart->GetPdgCode() != kPositron &&
535 mPart->GetPdgCode() != kGamma &&
536 pdgP->Charge() != 0 ){
537 if (fDebug > 5) Info("FillParticles","Storing charged hadron");
538 fInputObject.AddParticle(mPart);
544 if (pdgP->Charge() != 0 || mPart->GetPdgCode() == kPi0 ||
545 mPart->GetPdgCode() == kGamma )
547 if (fDebug > 5) Info("FillTracks","Storing kEMChargedPi0 track");
548 if (fSmearType == kSmear ||
549 fSmearType == kSmearEffic ){
551 TParticle *tmp = Smear(MPart);
552 fInputObject.AddTrack(tmp);
555 fInputObject.AddTrack(*mPart);
559 case kNoNeutronNeutrinoKlong:
560 if ( mPart->GetPdgCode() != kNeutron &&
561 mPart->GetPdgCode() != kNeutronBar &&
562 mPart->GetPdgCode() != kK0Long &&
563 mPart->GetPdgCode() != kNuE &&
564 mPart->GetPdgCode() != kNuEBar &&
565 mPart->GetPdgCode() != kNuMu &&
566 mPart->GetPdgCode() != kNuMuBar &&
567 mPart->GetPdgCode() != kNuTau &&
568 mPart->GetPdgCode() != kNuTauBar )
570 if (fDebug > 5) Info("FillTracks","Storing kNoNeutronNeutrinoKlong track");
571 if (fSmearType == kSmear ||
572 fSmearType == kSmearEffic ){
574 TParticle *tmp = Smear(MPart);
575 fInputObject.AddTrack(tmp);
578 fInputObject.AddTrack(*mPart);
585 }// end of loop over particles
588 void AliEMCALJetFinderInputSimPrep::FillDigits()
590 // Fill digits to input object
593 void AliEMCALJetFinderInputSimPrep::FillSDigits()
595 Info("FillSDigits","Beginning FillSDigits");
596 AliEMCALGetter *gime = AliEMCALGetter::Instance();
598 // Fill digits to input object
599 for (Int_t towerid=0; towerid < gime->SDigits()->GetEntries(); towerid++)
601 fInputObject.AddEnergyToDigit(gime->SDigit(towerid)->GetId(), gime->SDigit(towerid)->GetAmp());
606 void AliEMCALJetFinderInputSimPrep::Smear(TParticle *particle)
608 // Smear particle momentum
609 if (fDebug > 5) Info("Smear","Beginning Smear");
611 Float_t tmp = AliEMCALFast::SmearMomentum(1,particle->P());
612 Float_t tmpt = (tmp/particle->P()) * particle->Pt();
613 if (fDebug > 10) Info("Smear","Smearing changed P from %f to %f",particle->Pt(),tmpt);
614 TLorentzVector tmpvector;
615 tmpvector.SetPtEtaPhiM(tmpt,particle->Eta(), particle->Phi(), particle->GetMass());
616 // create a new particle with smearing momentum - and no daughter or parent information and the same
619 TParticle tmparticle(particle->GetPdgCode(), 1, 0, 0,0,0,
620 tmpvector.Px() , tmpvector.Py(), tmpvector.Pz(), tmpvector.Energy(),
621 particle->Vx(), particle->Vy(), particle->Vz(), particle->T());
622 fInputObject.AddTrack(tmparticle);
626 void AliEMCALJetFinderInputSimPrep::FillPartonTracks(AliEMCALParton *parton)
628 // Populate parton tracks for input distributions
629 if (fDebug>1) Info("FillPartonTracks","Beginning FillPartonTracks");
630 Int_t npart = (gAlice->GetHeader())->GetNprimary();
632 TParticlePDG *getpdg;
634 for (Int_t part = 0; part < npart; part++)
636 tempPart = gAlice->GetMCApp()->Particle(part);
637 if (tempPart->GetStatusCode() != 1) continue;
638 if ((!fPythiaComparison)&&(tempPart->Eta() > fEtaMax || tempPart->Eta() < fEtaMin ||
639 tempPart->Phi() > fPhiMax || tempPart->Phi() < fPhiMin) ){
640 if (fDebug>10) Info("FillPartonTracks","Excluding particle not pointing at the EMCAL");
643 getpdg = tempPart->GetPDG();
644 if (getpdg->Charge() == 0.0 ) {
645 if (fDebug>10) Info("FillPartonTracks","Excluding a neutral particle");
648 if ( (parton->Eta() - tempPart->Eta())*(parton->Eta() - tempPart->Eta()) +
649 (parton->Phi() - tempPart->Phi())*(parton->Phi() - tempPart->Phi()) < 1.0 ) ntracks++;
651 Float_t *energy = new Float_t[ntracks];
652 Float_t *eta = new Float_t[ntracks];
653 Float_t *phi = new Float_t[ntracks];
654 Int_t *pdg = new Int_t[ntracks];
656 for (Int_t part = 0; part < npart; part++)
658 tempPart = gAlice->GetMCApp()->Particle(part);
659 if (tempPart->GetStatusCode() != 1) continue;
660 if ((!fPythiaComparison)&&(tempPart->Eta() > fEtaMax || tempPart->Eta() < fEtaMin ||
661 tempPart->Phi() > fPhiMax || tempPart->Phi() < fPhiMin) ){
662 if (fDebug>10) Info("FillPartonTracks","Excluding particle not pointing at the EMCAL");
665 if (tempPart->GetStatusCode() != 1) continue;
666 getpdg = tempPart->GetPDG();
667 if (getpdg->Charge() == 0.0 ) {
668 if (fDebug>10) Info("FillPartonTracks","Excluding a neutral particle");
671 if ( (parton->Eta() - tempPart->Eta())*(parton->Eta() - tempPart->Eta()) +
672 (parton->Phi() - tempPart->Phi())*(parton->Phi() - tempPart->Phi()) < 1.0 )
674 energy[ntracks] = tempPart->Pt();
675 eta[ntracks] = tempPart->Eta();
676 phi[ntracks] = tempPart->Phi();
677 pdg[ntracks] = tempPart->GetPdgCode();
681 parton->SetTrackList(ntracks,energy,eta,phi,pdg);