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 "AliGenEventHeader.h"
46 #include "AliGenPythiaEventHeader.h"
47 #include "AliGenerator.h"
48 #include "AliHeader.h"
52 ClassImp(AliEMCALJetFinderInputSimPrep)
54 AliEMCALJetFinderInputSimPrep::AliEMCALJetFinderInputSimPrep()
56 if (fDebug > 0) Info("AliEMCALJetFinderInputSimPrep","Beginning Constructor");
59 fSmearType = kSmearEffic;
61 fTrackType = kCharged;
65 AliEMCALJetFinderInputSimPrep::~AliEMCALJetFinderInputSimPrep()
67 if (fDebug > 0) Info("~AliEMCALJetFinderInputSimPrep","Beginning Destructor");
71 void AliEMCALJetFinderInputSimPrep::Reset(AliEMCALJetFinderResetType_t resettype)
73 if (fDebug > 1) Info("Reset","Beginning Reset");
77 fInputObject.Reset(resettype);
80 fInputObject.Reset(resettype);
83 fInputObject.Reset(resettype);
85 case kResetParameters:
86 fSmearType = kSmearEffic;
88 fTrackType = kCharged;
91 fSmearType = kSmearEffic;
93 fTrackType = kCharged;
94 fInputObject.Reset(resettype);
97 Warning("FillFromFile", "kResetPartons not implemented") ;
100 Warning("FillFromFile", "kResetParticles not implemented") ;
103 Warning("FillFromFile", "kResetJets not implemented") ;
109 Int_t AliEMCALJetFinderInputSimPrep::FillFromFile(TString *filename, AliEMCALJetFinderFileType_t filetype,Int_t EventNumber)
111 // gObjectTable->Print();
112 // Test that file exists - Getter doesn't like bogus filenames
113 if (fDebug > 1) Info("FillFromFile","Beginning FillFromFile");
114 fFileType = filetype;
115 TFile file(filename->Data());
117 Error("FillFromFile","Could not open file in FillFromFile");
122 gAlice = static_cast<AliRun *>(file.Get("gAlice"));
123 AliEMCAL* pEMCAL = (AliEMCAL*) gAlice->GetModule("EMCAL");
124 if (gAlice->GetEvent(EventNumber) < 0){
125 Error("FillFromFile","Could not open event in FillFromFile");
129 AliEMCALGetter *gime = AliEMCALGetter::Instance(filename->Data());
130 gime->Event(EventNumber) ;
132 if ( fEMCALType == kHits ||
133 fEMCALType == kTimeCut ) FillHits();
134 if ( fTrackType != kNoTracks ) FillTracks();
135 if ( fFileType != kData){
140 // gObjectTable->Print();
145 void AliEMCALJetFinderInputSimPrep::FillHits() // Fill from the hits to input object from simulation
147 if (fDebug > 1) Info("FillHits","Beginning FillHits");
149 // Access hit information
151 AliEMCAL* pEMCAL = (AliEMCAL*) gAlice->GetModule("EMCAL");
152 Info("AliEMCALJetFinderInputSimPrep","Title of the geometry is %s",pEMCAL->GetTitle());
153 AliEMCALGeometry* geom = AliEMCALGetter::Instance()->EMCALGeometry();
154 // Float_t samplingF = geom->GetSampling();
155 Float_t samplingF = 11.6;
156 Info("AliEMCALJetFinderInputSimPrep","Sampling fraction is %f",samplingF);
157 TTree *treeH = AliEMCALGetter::Instance()->TreeH();
158 Int_t ntracks = (Int_t) treeH->GetEntries();
165 for (Int_t track=0; track<ntracks;track++) {
167 nbytes += treeH->GetEvent(track);
171 for(mHit=(AliEMCALHit*) pEMCAL->FirstHit(-1);
173 mHit=(AliEMCALHit*) pEMCAL->NextHit())
175 if (fEMCALType == kTimeCut &&
176 (mHit->GetTime()>fTimeCut) ) continue;
177 Float_t x = mHit->X(); // x-pos of hit
178 Float_t y = mHit->Y(); // y-pos
179 Float_t z = mHit->Z(); // z-pos
180 Float_t eloss = mHit->GetEnergy(); // deposited energy
182 Float_t r = TMath::Sqrt(x*x+y*y);
183 Float_t theta = TMath::ATan2(r,z);
184 Float_t eta = -TMath::Log(TMath::Tan(theta/2.));
185 Float_t phi = TMath::ATan2(y,x);
186 etH = samplingF*eloss*TMath::Sin(theta);
187 if (fDebug > 10) Info("FillHits","Values of hit energy %i",Int_t(1e7*etH));
188 if (geom->TowerIndexFromEtaPhi(eta,180.0/TMath::Pi()*phi) == -1)
192 Error("FillHits","Hit not inside EMCAL!");
197 fInputObject.AddEnergyToDigit(geom->TowerIndexFromEtaPhi(eta,180.0/TMath::Pi()*phi)-1,Int_t(1e7*etH));
203 void AliEMCALJetFinderInputSimPrep::FillTracks() // Fill from particles simulating a TPC to input object from simulation
206 if (fDebug > 1) Info("FillTracks","Beginning FillTracks");
208 TParticlePDG* pdgP = 0;
210 Int_t npart = (gAlice->GetHeader())->GetNprimary();
211 Float_t bfield,rEMCAL;
213 if (fDebug > 1) Info("FillTracks","Defining the geometry");
215 AliEMCAL* pEMCAL = (AliEMCAL*) gAlice->GetModule("EMCAL");
216 AliEMCALGeometry* geom = AliEMCALGeometry::GetInstance(pEMCAL->GetTitle(), "");
217 fEtaMax = geom->GetArm1EtaMax();
218 fEtaMin = geom->GetArm1EtaMin();
219 fPhiMax = TMath::Pi()/180.0*geom->GetArm1PhiMax();
220 fPhiMin = TMath::Pi()/180.0*geom->GetArm1PhiMin();
222 if (fDebug > 1) Info("FillTracks","Starting particle loop");
224 for (Int_t part = 0; part < npart; part++) {
225 MPart = gAlice->GetMCApp()->Particle(part);
226 //if (part%10) gObjectTable->Print();
227 pdgP = MPart->GetPDG();
229 if (fDebug > 5) Info("FillTracks","Checking if track is a primary");
231 if (fFileType == kPythia) {
232 if (MPart->GetStatusCode() != 1) continue;
233 } else if (fFileType == kHijing) {
234 if (MPart->GetFirstDaughter() >= 0 && MPart->GetFirstDaughter() < npart) continue;
237 if (fDebug > 15) Info("FillTracks","Checking if track (eta - %f, phi - %f) is in acceptance",MPart->Eta(),MPart->Phi());
238 if (fDebug > 10) Info("FillTracks","Checking if EMCAL acceptance ( %f < eta < %f, %f < phi < %f) is in acceptance",fEtaMin,fEtaMax,fPhiMin,fPhiMax);
240 if (MPart->Eta() > fEtaMax || MPart->Eta() < fEtaMin) continue;
241 if (MPart->Phi() > fPhiMax || MPart->Phi() < fPhiMin ) continue;
244 {kProton, kProtonBar, kElectron, kPositron,
245 kNuE, kNuEBar, kGamma, kNeutron, kNeutronBar,
246 kMuonPlus, kMuonMinus, kK0Long , kPiPlus, kPiMinus,
247 kKPlus, kKMinus, kLambda0, kLambda0Bar, kK0Short,
248 kSigmaMinus, kSigmaPlus, kSigma0, kPi0, kK0, kK0Bar,
252 if (fDebug > 15) Info("FillTracks","Checking if track is rejected");
254 if ((fSmearType == kEfficiency ||
255 fSmearType == kSmearEffic) &&
257 if (AliEMCALFast::RandomReject(fEfficiency)) {
262 bfield = gAlice->Field()->SolenoidField();
263 rEMCAL = AliEMCALGeometry::GetInstance()->GetIPDistance();
264 Float_t rB = 3335.6 * MPart->Pt() / bfield; // [cm] (case of |charge|=1)
265 if (2.*rB < rEMCAL) continue; // track curls away
267 //if (part%10) gObjectTable->Print();
271 case kAll: // All Stable particles to be included
272 if (fDebug > 5) Info("FillTracks","Storing track");
273 if (fSmearType == kSmear ||
274 fSmearType == kSmearEffic ){
276 TParticle *tmp = Smear(MPart);
277 fInputObject.AddTrack(Smear(MPart));
280 fInputObject.AddTrack(*MPart);
283 case kEM: // All Electromagnetic particles
284 if (MPart->GetPdgCode() == kElectron ||
285 MPart->GetPdgCode() == kMuonPlus ||
286 MPart->GetPdgCode() == kMuonMinus ||
287 MPart->GetPdgCode() == kPositron ){
288 if (fDebug > 5) Info("FillTracks","Storing electron or positron");
289 if (fSmearType == kSmear ||
290 fSmearType == kSmearEffic ){
292 TParticle *tmp = Smear(MPart);
293 fInputObject.AddTrack(tmp);
296 fInputObject.AddTrack(*MPart);
299 if ( MPart->GetPdgCode() == kGamma ){
300 fInputObject.AddTrack(*MPart);
301 if (fDebug > 5) Info("FillTracks","Storing gamma");
305 case kCharged: // All Particles with non-zero charge
306 if (pdgP->Charge() != 0) {
307 if (fDebug > 5) Info("FillTracks","Storing charged track");
308 if (fSmearType == kSmear ||
309 fSmearType == kSmearEffic ){
311 TParticle *tmp = Smear(MPart);
312 fInputObject.AddTrack(tmp);
315 fInputObject.AddTrack(*MPart);
319 case kNeutral: // All particles with no charge
320 if (pdgP->Charge() == 0){
321 fInputObject.AddTrack(*MPart);
322 if (fDebug > 5) Info("FillTracks","Storing neutral");
325 case kHadron: //All hadrons
326 if (MPart->GetPdgCode() != kElectron &&
327 MPart->GetPdgCode() != kPositron &&
328 MPart->GetPdgCode() != kMuonPlus &&
329 MPart->GetPdgCode() != kMuonMinus &&
330 MPart->GetPdgCode() != kGamma )
332 if (fDebug > 5) Info("FillTracks","Storing hadron");
333 if (pdgP->Charge() == 0){
334 fInputObject.AddTrack(*MPart);
336 if (fSmearType == kSmear ||
337 fSmearType == kSmearEffic ){
339 TParticle *tmp = Smear(MPart);
340 fInputObject.AddTrack(tmp);
343 fInputObject.AddTrack(*MPart);
348 case kChargedHadron: // only charged hadrons
349 if (MPart->GetPdgCode() != kElectron &&
350 MPart->GetPdgCode() != kPositron &&
351 MPart->GetPdgCode() != kGamma &&
352 MPart->GetPdgCode() != kMuonPlus &&
353 MPart->GetPdgCode() != kMuonMinus &&
354 pdgP->Charge() != 0 ){
355 if (fDebug > 5) Info("FillTracks","Storing charged hadron");
356 if (fSmearType == kSmear ||
357 fSmearType == kSmearEffic ){
359 TParticle *tmp = Smear(MPart);
360 fInputObject.AddTrack(tmp);
363 fInputObject.AddTrack(*MPart);
373 // Info("FillTracks","After Particle Storage");
374 //if (part%10) gObjectTable->Print();
376 } //end of particle loop
377 //gObjectTable->Print();
380 void AliEMCALJetFinderInputSimPrep::FillPartons() // Fill partons to input object from simulation
382 if (fDebug > 1) Info("FillPartons","Beginning FillPartons");
384 AliGenEventHeader* evHeader = ((AliHeader*)(gAlice->GetHeader()))->GenEventHeader();
385 Float_t triggerJetValues[4];
386 AliEMCALParton tempParton;
388 if (fFileType == kPythia)
390 Int_t ntriggerjets = ((AliGenPythiaEventHeader*)evHeader)->NTriggerJets();
391 if (fDebug > 1) Info("FillPartons","Number of trigger jets --> %i",ntriggerjets);
392 for (Int_t jetcounter = 0 ; jetcounter < ntriggerjets; jetcounter++){
393 ((AliGenPythiaEventHeader*)evHeader)->TriggerJet(jetcounter,triggerJetValues);
394 TLorentzVector tempLParton;
395 tempLParton.SetPxPyPzE(triggerJetValues[0],triggerJetValues[1],triggerJetValues[2],triggerJetValues[3]);
396 tempParton.SetEnergy(tempLParton.Energy());
397 tempParton.SetEta(tempLParton.Eta());
398 tempParton.SetPhi(tempLParton.Phi());
399 FillPartonTracks(&tempParton);
400 fInputObject.AddParton(&tempParton);
406 void AliEMCALJetFinderInputSimPrep::FillParticles() // Fill particles to input object from simulation
408 if (fDebug > 1) Info("FillParticles","Beginning FillParticles");
410 Int_t npart = (gAlice->GetHeader())->GetNprimary();
411 TParticlePDG* pdgP = 0;
413 for (Int_t part = 0; part < npart; part++) {
414 TParticle *MPart = gAlice->GetMCApp()->Particle(part);
415 pdgP = MPart->GetPDG();
417 if (fDebug > 10) Info("FillParticles","Checking if particle is a primary");
419 if (fFileType == kPythia) {
420 if (MPart->GetStatusCode() != 1) continue;
421 } else if (fFileType == kHijing) {
422 if (MPart->GetFirstDaughter() >= 0 && MPart->GetFirstDaughter() < npart) continue;
425 if (fDebug > 10) Info("FillParticles","Checking if particle is in acceptance");
427 if (MPart->Eta() > fEtaMax || MPart->Eta() < fEtaMin) continue;
428 if (MPart->Phi() > fPhiMax || MPart->Phi() < fPhiMin ) continue;
432 {kProton, kProtonBar, kElectron, kPositron,
433 kNuE, kNuEBar, kGamma, kNeutron, kNeutronBar,
434 kMuonPlus, kMuonMinus, kK0Long , kPiPlus, kPiMinus,
435 kKPlus, kKMinus, kLambda0, kLambda0Bar, kK0Short,
436 kSigmaMinus, kSigmaPlus, kSigma0, kPi0, kK0, kK0Bar,
442 case kAll: // All Stable particles to be included
443 if (fDebug > 5) Info("FillParticles","Storing particle");
444 fInputObject.AddParticle(MPart);
446 case kEM: // All Electromagnetic particles
447 if (MPart->GetPdgCode() == kElectron ||
448 MPart->GetPdgCode() == kPositron ||
449 MPart->GetPdgCode() == kGamma){
450 if (fDebug > 5) Info("FillParticles","Storing electromagnetic particle");
451 fInputObject.AddParticle(MPart);
454 case kCharged: // All Particles with non-zero charge
455 if (pdgP->Charge() != 0) {
456 if (fDebug > 5) Info("FillParticles","Storing charged particle");
457 fInputObject.AddParticle(MPart);
460 case kNeutral: // All particles with no charge
461 if (pdgP->Charge() == 0){
462 if (fDebug > 5) Info("FillParticles","Storing neutral particle");
463 fInputObject.AddParticle(MPart);
466 case kHadron: //All hadrons
467 if (MPart->GetPdgCode() != kElectron &&
468 MPart->GetPdgCode() != kPositron &&
469 MPart->GetPdgCode() != kGamma )
472 if (fDebug > 5) Info("FillParticles","Storing hadron");
473 fInputObject.AddParticle(MPart);
476 case kChargedHadron: // only charged hadrons
477 if (MPart->GetPdgCode() != kElectron &&
478 MPart->GetPdgCode() != kPositron &&
479 MPart->GetPdgCode() != kGamma &&
480 pdgP->Charge() != 0 ){
481 if (fDebug > 5) Info("FillParticles","Storing charged hadron");
482 fInputObject.AddParticle(MPart);
490 }// end of loop over particles
493 void AliEMCALJetFinderInputSimPrep::FillDigits() // Fill digits to input object
498 void AliEMCALJetFinderInputSimPrep::Smear(TParticle *particle)
500 if (fDebug > 5) Info("Smear","Beginning Smear");
502 Float_t tmp = AliEMCALFast::SmearMomentum(1,particle->P());
503 Float_t tmpt = (tmp/particle->P()) * particle->Pt();
504 if (fDebug > 10) Info("Smear","Smearing changed P from %f to %f",particle->Pt(),tmpt);
505 TLorentzVector tmpvector;
506 tmpvector.SetPtEtaPhiM(tmpt,particle->Eta(), particle->Phi(), particle->GetMass());
507 // create a new particle with smearing momentum - and no daughter or parent information and the same
510 TParticle tmparticle(particle->GetPdgCode(), 1, 0, 0,0,0,
511 tmpvector.Px() , tmpvector.Py(), tmpvector.Pz(), tmpvector.Energy(),
512 particle->Vx(), particle->Vy(), particle->Vz(), particle->T());
513 fInputObject.AddTrack(tmparticle);
517 void AliEMCALJetFinderInputSimPrep::FillPartonTracks(AliEMCALParton *parton)
520 if (fDebug>1) Info("FillPartonTracks","Beginning FillPartonTracks");
521 Int_t npart = (gAlice->GetHeader())->GetNprimary();
523 TParticlePDG *getpdg;
525 for (Int_t part = 0; part < npart; part++)
527 tempPart = gAlice->GetMCApp()->Particle(part);
528 if (tempPart->GetStatusCode() != 1) continue;
529 if (tempPart->Eta() > fEtaMax || tempPart->Eta() < fEtaMin ||
530 tempPart->Phi() > fPhiMax || tempPart->Phi() < fPhiMin ){
531 if (fDebug>10) Info("FillPartonTracks","Excluding particle not pointing at the EMCAL");
534 getpdg = tempPart->GetPDG();
535 if (getpdg->Charge() == 0.0 ) {
536 if (fDebug>10) Info("FillPartonTracks","Excluding a neutral particle");
539 if ( (parton->Eta() - tempPart->Eta())*(parton->Eta() - tempPart->Eta()) +
540 (parton->Phi() - tempPart->Phi())*(parton->Phi() - tempPart->Phi()) < 1.0 ) ntracks++;
542 Float_t *Energy = new Float_t[ntracks];
543 Float_t *Eta = new Float_t[ntracks];
544 Float_t *Phi = new Float_t[ntracks];
545 Int_t *Pdg = new Int_t[ntracks];
547 for (Int_t part = 0; part < npart; part++)
549 tempPart = gAlice->GetMCApp()->Particle(part);
550 if (tempPart->GetStatusCode() != 1) continue;
551 if (tempPart->Eta() > fEtaMax || tempPart->Eta() < fEtaMin ||
552 tempPart->Phi() > fPhiMax || tempPart->Phi() < fPhiMin ){
553 if (fDebug>10) Info("FillPartonTracks","Excluding particle not pointing at the EMCAL");
556 if (tempPart->GetStatusCode() != 1) continue;
557 getpdg = tempPart->GetPDG();
558 if (getpdg->Charge() == 0.0 ) {
559 if (fDebug>10) Info("FillPartonTracks","Excluding a neutral particle");
562 if ( (parton->Eta() - tempPart->Eta())*(parton->Eta() - tempPart->Eta()) +
563 (parton->Phi() - tempPart->Phi())*(parton->Phi() - tempPart->Phi()) < 1.0 )
565 Energy[ntracks] = tempPart->Pt();
566 Eta[ntracks] = tempPart->Eta();
567 Phi[ntracks] = tempPart->Phi();
568 Pdg[ntracks] = tempPart->GetPdgCode();
572 parton->SetTrackList(ntracks,Energy,Eta,Phi,Pdg);