scripts/GetMedia.C

Go to the documentation of this file.
00001 //____________________________________________________________________
00002 //
00003 // $Id: GetMedia.C,v 1.2 2006/03/17 11:42:24 cholm Exp $
00004 //
00005 // Script that contains a class to get the media where a certain track
00006 // was created.   This is used for background studies. 
00007 //
00008 // Use the script `Compile.C' to compile this class using ACLic. 
00009 //
00010 #include <TH2D.h>
00011 #include <AliFMDHit.h>
00012 #include <AliFMDInput.h>
00013 #include <iostream>
00014 #include <TStyle.h>
00015 #include <TArrayF.h>
00016 #include <TArrayI.h>
00017 #include <AliRun.h>
00018 #include <TNtuple.h>
00019 
00024 struct Media : public TNamed
00025 {
00026   TArrayI*        fMeds;
00027   TNtuple*        fCount;
00028   Media(const char* name, const char* title) 
00029     : TNamed(name, title), fMeds(0) 
00030   {
00031     fCount = new TNtuple(GetName(), "E/I:DET:RNG:SEC:STR:X/F:Y:Z:EDEP:PDG/I");
00032   }
00033   Media(const char* name) 
00034     : TNamed(name, "Media information"), fMeds(0), fCount(0)
00035   {
00036     AliDetector* det = gAlice->GetDetector(name);
00037     if (!det) {
00038       Warning("Media", "Detector %s not found in gAlice", name);
00039       return;
00040     }
00041     fMeds = det->GetIdtmed();
00042     if (!fMeds) {
00043       Warning("Media", "No mediums for detector %s found", name);
00044       return;
00045     }
00046     fCount = new TNtuple(GetName(), "E/I:DET:RNG:SEC:STR:X/F:Y:Z:EDEP:PDG/I");
00047   }
00048 };
00049 
00050 
00051 //____________________________________________________________________
00062 class GetMedia : public AliFMDInputHits
00063 {
00064 private:
00065   TString    fModList;
00066   TObjArray  fMedia;
00067   Media*     fOther;
00068   Media*     fAll;
00069   Int_t      fEv;
00070   TFile*     fOutput;
00071 public:
00072   //__________________________________________________________________
00073   GetMedia(const char* modlist="FMD:ITS:BODY:ABSO:START:PIPE", 
00074            const char* output="media.root") 
00075   { 
00076     fOutput = TFile::Open(output, "RECREATE");
00077     fOther  = new Media("other", "Unknown media"),
00078     fAll    = new Media("All", "All media")
00079     fEv     = 0;
00080     AddLoad(kKinematics);
00081   }
00082   //__________________________________________________________________
00083   Media* FindMedia(Int_t med) 
00084   {
00085     TIter next(&fMedia);
00086     Media* media = 0;
00087     while ((media == static_cast<Media*>(next()))) {
00088       if (!media->fMeds) continue;
00089       TArrayI& ids = *(media->fMeds);
00090       for (Int_t i = 0; i < ids.fN; i++) 
00091         if (med == ids[i]) return media;
00092     }
00093     return 0;
00094   }
00095   //__________________________________________________________________
00096   Bool_t Init()
00097   {
00098     if (!gGeoManager) {
00099       Error("GetMedia", "No geometry defined - make sure you have that");
00100       return kFALSE;
00101     }
00102     if (!gAlice) {
00103       Error("GetMedia", "gAlice not defined");
00104       return kFALSE;
00105     }
00106     Int_t now = 0;
00107     Int_t colon;
00108     while ((colon = fModList.Index(":", now)) >= 0) {
00109       fMedia.Add(new Media(fModList(now, colon-now)));
00110       now = colon+1;
00111     }
00112     if (now < fModList.Length()) 
00113       fMedia.Add(new Media(now, fModList.Length()-now));
00114     if (fMedia.GetEntries() <= 0) return kFALSE;
00115     return AliFMDInputHits::Init();
00116   }  
00117   //__________________________________________________________________
00121   Bool_t Begin(Int_t ev) 
00122   {
00123     fEv = ev;
00124     return AliFMDInputHits::Begin(ev);
00125   }
00126   //__________________________________________________________________
00127   Bool_t ProcessHit(AliFMDHit* hit, TParticle* track) 
00128   {
00129     if (!hit || !track) {
00130       std::cout << "No hit or track (hit: " << hit << ", track: " 
00131                 << track << ")" << std::endl;
00132       return kFALSE;
00133     }
00134     // Get production vertex 
00135     Double_t vx = track->Vx();
00136     Double_t vy = track->Vy();
00137     Double_t vz = track->Vz();
00138     
00139     fAll->fCounts->Fill(fEv, hit->Detector(),Int_t(hit->Ring()),
00140                         hit->Sector(), hit->Strip(), 
00141                         hit->X(), hit->Y(), hit->Z(), hit->Edep(), 
00142                         hit->Pdg());
00143     // Get node 
00144     TGeoNode* prodNode = gGeoManager->FindNode(vx,vy,vz);
00145     if (!prodNode) return kTRUE;
00146     
00147     // Get volume 
00148     TGeoVolume* prodVol = prodNode->GetVolume();
00149     if (!prodVol) return kTRUE;
00150     
00151     // Med medium 
00152     TGeoMedium* prodMed = prodVol->GetMedium();
00153     if (!prodMed) return kTRUE;
00154     
00155     Media* media = FindMedia(prodMed->GetUniqueID());
00156     if (media) media = fOther; 
00157     
00158     // r = TMath::Sqrt(hit->X() * hit->X() + hit->Y() * hit->Y());
00159     // if(r!=0) Float_t wgt=1./(2. * 3.1415*r);
00160     media->fCounts->Fill(fEv, hit->Detector(),Int_t(hit->Ring()),
00161                          hit->Sector(), hit->Strip(), 
00162                          hit->X(), hit->Y(), hit->Z(), hit->Edep(), 
00163                          hit->Pdg());
00164     return kTRUE;
00165   }
00166   //__________________________________________________________________
00167   Bool_t Finish()
00168   {
00169     fOutput->Write();
00170     fOutput->Close();
00171     return kTRUE;
00172   }
00173 };
00174 
00175 //____________________________________________________________________
00176 //
00177 // EOF
00178 //

Generated on Fri Mar 24 17:11:21 2006 for ALICE FMD Off-line by  doxygen 1.4.6