24    gROOT->Macro(
"$VMCWORKDIR/gconfig/rootlogon.C");
 
   25    gSystem->Load(
"libHypGe");
 
   34         TString Filename = 
"$SIMDATADIR/COSY/"+Filename_ext;
 
   35         TString ParfileName = 
"$SIMDATADIR/COSY/"+Filename_ext;
 
   36         ParfileName.ReplaceAll(
".root",
"__Simparams.root");
 
   40         outfile += Filename_ext;
 
   41         outfile.ReplaceAll(
".root",
"");
 
   43         outfile += StartEvent;
 
   44         outfile += 
"_nEvents_";
 
   45         outfile += NoOfEvents;
 
   47         cout << outfile << endl;
 
   48         TFile* InputFile = 
new TFile(Filename);
 
   49         TFile* Parfile = 
new TFile(ParfileName);
 
   50                 Parfile->Get(
"FairBaseParSet");
 
   51         TFile* OutputFile = 
new TFile(outfile,
"RECREATE");
 
   54   TTree *
b=(TTree *) InputFile->Get(
"pndsim") ;
 
   55   TClonesArray* fHypGe=
new TClonesArray(
"PndHypGePoint");
 
   56   b->SetBranchAddress(
"HypGePoint",&fHypGe);
 
   57   TClonesArray* fMcTr=
new TClonesArray(
"PndMCTrack");
 
   58   b->SetBranchAddress(
"MCTrack",&fMcTr);
 
   64         TH1D*                                                                           hNeutronOriginGe;       
 
   65         TH1D*                                                                           hNHitsGeKermitBall;     
 
   67         TH1D*                                                                                   hAllParticlesGe;                
 
   68         TH2D*                                                                                   hAllParticlesEkinGe;    
 
   69         TH1D*                                                                                   hAllParticlesPiezo;             
 
   70         TH1D*                                                                                   hAllParticlesPiezo2;    
 
   75         TH1D*                                                                                   hNEnergyLossKermit;                             
 
   76         TH1D*                                                                                   hNEnergyLossBall;                               
 
   83         TCanvas*                                                                        cNHitsGeKermitBall;                             
 
   84         TCanvas*                                                                        cAllParticlesGe;                                        
 
   85         TCanvas*                                                                        cAllParticlesPiezo;                             
 
   86         TCanvas*                                                                        cNeutronEkinGe;                                         
 
   87         TCanvas*                                                                        cNeutronEkinKermit;                             
 
   88         TCanvas*                                                                        cNeutronEkinBall;                                       
 
   89         TCanvas*                                                                        cProtonEkinGe;                                          
 
   90         TCanvas*                                                                        cGammaEnergyGe;                                         
 
   94         TVector3                                                                        NeutronMomentum;
 
   96         TVector3                                                                        ProtonMomentum;
 
   98         TVector3                                                                        ParticleMomentum;
 
  102         fgeom = (TGeoManager*)gROOT->FindObject(
"FAIRGeom");
 
  106         hNHitsAngleGe = 
new TH1D(
"hNHitsAngleGe",
"Polar angle of primary neutrons interacting with the crystals",180, 90,180);
 
  107                 hNHitsAngleGe->SetXTitle(
"#Theta [#circ]");
 
  108                 hNHitsAngleGe->SetYTitle(
"Counts / 0.5 #circ");
 
  111         hNeutronOriginGe = 
new TH1D(
"hNeutronOriginGe",
"Origin of Neutrons",13,0,13);
 
  112                 hNeutronOriginGe->SetXTitle(
"Neutron Origin");
 
  113                 hNeutronOriginGe->SetYTitle(
"Counts");
 
  114                 hNeutronOriginGe->GetXaxis()->SetBinLabel(1,
"Target");                                                                          
 
  115                 hNeutronOriginGe->GetXaxis()->SetBinLabel(2,
"Target Support");                                          
 
  116                 hNeutronOriginGe->GetXaxis()->SetBinLabel(3,
"Al base plate");                                                                   
 
  117                 hNeutronOriginGe->GetXaxis()->SetBinLabel(4,
"Plastic blocks");                                          
 
  118                 hNeutronOriginGe->GetXaxis()->SetBinLabel(5,
"Maytec frame");                                                    
 
  119                 hNeutronOriginGe->GetXaxis()->SetBinLabel(6,
"Active neutron detector");         
 
  120                 hNeutronOriginGe->GetXaxis()->SetBinLabel(7,
"Passive neutron detector");        
 
  121                 hNeutronOriginGe->GetXaxis()->SetBinLabel(8,
"Crystal");                                                                         
 
  122                 hNeutronOriginGe->GetXaxis()->SetBinLabel(9,
"Cryostat");                                                                                
 
  123                 hNeutronOriginGe->GetXaxis()->SetBinLabel(10,
"Lumi glue test");                                         
 
  124                 hNeutronOriginGe->GetXaxis()->SetBinLabel(11,
"Lumi electronics test");          
 
  125                 hNeutronOriginGe->GetXaxis()->SetBinLabel(12,
"Beam dump");                                                              
 
  126                 hNeutronOriginGe->GetXaxis()->SetBinLabel(13,
"Cave");                                                                                   
 
  129         hNHitsGeKermitBall = 
new TH1D(
"hNHitsGeKermitBall",
"Total number of neutron hits on the 3 detectors",3,0,1);
 
  130                 hNHitsGeKermitBall->SetXTitle(
"Crystal number");
 
  131                 hNHitsGeKermitBall->SetYTitle(
"Counts per crystal");
 
  132                 hNHitsGeKermitBall->GetXaxis()->SetBinLabel(1,
"Germanium crystal");                             
 
  133                 hNHitsGeKermitBall->GetXaxis()->SetBinLabel(2,
"Active neutron detector");                               
 
  134                 hNHitsGeKermitBall->GetXaxis()->SetBinLabel(3,
"Passive neutron detector");                              
 
  137         hAllParticlesGe = 
new TH1D(
"hAllParticlesGe",
"Particles interaction in the crystals;PDG Code of particle; Counts", 2e4,-1e4,1e4);
 
  140         hAllParticlesEkinGe = 
new TH2D(
"hAllParticlesEkinGe",
"E_{kin} - Particle - Correlation;E_{kin} of particles [MeV]; particle",3000,0,3000,9,1,10);
 
  141                 hAllParticlesEkinGe->GetYaxis()->SetBinLabel(1,
"#pi^{-}");
 
  142                 hAllParticlesEkinGe->GetYaxis()->SetBinLabel(2,
"#mu^{+}");
 
  143                 hAllParticlesEkinGe->GetYaxis()->SetBinLabel(3,
"e^{+}");
 
  144                 hAllParticlesEkinGe->GetYaxis()->SetBinLabel(4,
"e^{-}");
 
  145                 hAllParticlesEkinGe->GetYaxis()->SetBinLabel(5,
"#mu^{-}");
 
  146                 hAllParticlesEkinGe->GetYaxis()->SetBinLabel(6,
"#gamma");
 
  147                 hAllParticlesEkinGe->GetYaxis()->SetBinLabel(7,
"#pi^{+}");
 
  148                 hAllParticlesEkinGe->GetYaxis()->SetBinLabel(8,
"neutron");
 
  149                 hAllParticlesEkinGe->GetYaxis()->SetBinLabel(9,
"proton");
 
  152         hAllParticlesPiezo = 
new TH1D(
"hAllParticlesPiezo",
"Particles interaction in the first piezo;PDG Code of particle; Counts", 2e4,-1e4,1e4);
 
  154         hAllParticlesPiezo2 = 
new TH1D(
"hAllParticlesPiezo2",
"Particles interaction in the second piezo;PDG Code of particle; Counts", 2e4,-1e4,1e4);
 
  158         hNEkinGe = 
new TH1D(
"hNEkinGe",
"E_{kin} of neutrons in the germanium;E_{kin} of neutrons  [MeV]; Counts", 2000,0,200);
 
  160         hNEkinKermit = 
new TH1D(
"hNEkinKermit",
"E_{kin} of neutrons in the active neutron detector;E_{kin} of neutrons [MeV]; Counts", 2000,0,200);
 
  162         hNEkinBall = 
new TH1D(
"hNEkinBall",
"E_{kin} of neutrons in the passive neutron detector;E_{kin} of neutrons [MeV]; Counts", 2000,0,200);
 
  165         hNEnergyLossGe = 
new TH1D(
"hNEnergyLossGe",
"Energy loss of neutrons inside the germanium;Energy loss of neutrons [MeV]; Counts", 2000,0,2);
 
  167         hNEnergyLossKermit = 
new TH1D(
"hNEnergyLossKermit",
"Energy loss of neutrons inside the active neutron detector;Energy loss of neutrons [MeV]; Counts", 2000,0,2);
 
  169         hNEnergyLossBall = 
new TH1D(
"hNEnergyLossBall",
"Energy loss of neutrons inside the passive neutron detecor;Energy loss of neutrons [MeV]; Counts", 2000,0,2);
 
  172         hPEkinGe = 
new TH1D(
"hPEkinGe",
"E_{kin} of protons in the germanium;E_{kin} of protons  [MeV]; Counts", 2000,0,200);
 
  174         hPEnergyLossGe = 
new TH1D(
"hPEnergyLossGe",
"Energy loss of protons inside the germanium;Energy loss of protons [MeV]; Counts", 20000,0,200);
 
  177         hGammaSpecGe = 
new TH1D(
"hGammaSpecGe",
"Energy loss of gammas inside the germanium;Energy loss of gammas [MeV]; Counts/1 keV", 10000,0,10);
 
  182         Int_t *ActualTrackID ;
 
  196         TVector3 StartVertex;
 
  202                 EndEvent = b->GetEntriesFast();
 
  204                 EndEvent = StartEvent + NoOfEvents;
 
  206         Double_t NeutronEnergyLossArrayGe[50];                          
 
  207         Double_t NeutronEnergyLossArrayKermit[50];                              
 
  208         Double_t NeutronEnergyLossArrayBall[50];                                
 
  209         Double_t ProtonEnergyLossArrayGe[50];                           
 
  210         Double_t GammaEnergyLossArrayGe[50];                            
 
  213         for (Int_t k=StartEvent; k< EndEvent; k++)
 
  217                 for(Int_t 
i = 0; 
i < 50; 
i++)   
 
  219                         NeutronEnergyLossArrayGe[
i]=0;
 
  220                         NeutronEnergyLossArrayKermit[
i]=0;
 
  221                         NeutronEnergyLossArrayBall[
i]=0;
 
  222                         ProtonEnergyLossArrayGe[
i] =0;
 
  223                         GammaEnergyLossArrayGe[
i] = 0;
 
  225                 Int_t nNeutronsGe = -1;
 
  226                 Int_t NeutronTrackIDGe =-1;
 
  228                 Int_t nNeutronsKermit = -1;
 
  229                 Int_t NeutronTrackIDKermit =-1;
 
  230                 Bool_t newNeutronKermit = 1;
 
  231                 Int_t nNeutronsBall = -1;
 
  232                 Int_t NeutronTrackIDBall =-1;
 
  233                 Bool_t newNeutronBall = 1;
 
  234                 Int_t nProtonsGe = -1;
 
  235                 Int_t ProtonTrackIDGe =-1;
 
  238                 Int_t nGammasGe = -1;
 
  239                 Int_t GammaTrackIDGe =-1;
 
  242                 if (!((k*100)% NoOfEvents))     
 
  244                         cout << 
"Event number :\t" << k << endl;
 
  252                 for (Int_t 
i=0; 
i < fHypGe->GetEntriesFast(); 
i++)
 
  258                         VertexVolumeName =
gGeoManager->FindNode(StartVertex.X(),StartVertex.Y(),StartVertex.Z())->GetName();
 
  268                                 NeutronMomentum.SetX(hitgam->
GetPx());
 
  269                                 NeutronMomentum.SetY(hitgam->
GetPy());
 
  270                                 NeutronMomentum.SetZ(hitgam->
GetPz());
 
  271                                 NeutronEkin = 1./2.*NeutronMomentum.Mag2()/0.939565*1000; 
 
  280                                         if (!VertexVolumeName.Contains(
"Crystal_101") && ! VertexVolumeName.Contains (
"Capsule") && !VertexVolumeName.Contains (
"ColdFinger"))
 
  285                                                         hNHitsGeKermitBall->Fill(
"Germanium crystal",1);
 
  286                                                         hNEkinGe->Fill(NeutronEkin);
 
  297                                                 NeutronEnergyLossArrayGe[nNeutronsGe] += hitgam->
GetEnergyLoss()*1000;
 
  301                                                 NHit.SetX(hitgam->
GetX());
 
  302                                                 NHit.SetY(hitgam->
GetY());
 
  303                                                 NHit.SetZ(hitgam->
GetZ());                                      
 
  304                                                 hNHitsAngleGe->Fill(180/
TMath::Pi()*NHit.Theta());                              
 
  308                                         if( VertexVolumeName.Contains(
"Target") || VertexVolumeName.Contains(
"Piezo"))
 
  309                                                 hNeutronOriginGe->Fill(
"Target",1);
 
  310                                         if( VertexVolumeName.Contains(
"ScrewHead") || VertexVolumeName.Contains(
"Goniometer")|| VertexVolumeName.Contains(
"Bracket")|| VertexVolumeName.Contains(
"AlPlate"))
 
  311                                                 hNeutronOriginGe->Fill(
"Target Support",1);
 
  312                                         if( VertexVolumeName.Contains(
"AlBasePlate"))
 
  313                                                 hNeutronOriginGe->Fill(
"Al base plate",1);
 
  314                                         if( VertexVolumeName.Contains(
"PlasticBlock"))
 
  315                                                 hNeutronOriginGe->Fill(
"Plastic blocks",1);
 
  316                                         if( VertexVolumeName.Contains(
"Beam") || VertexVolumeName.Contains(
"Pillar"))
 
  317                                                 hNeutronOriginGe->Fill(
"Maytec frame",1);
 
  318                                         if( VertexVolumeName.Contains(
"KermitCrystal"))
 
  319                                                 hNeutronOriginGe->Fill(
"Active neutron detector",1);
 
  320                                         if( VertexVolumeName.Contains(
"KermitCrystal"))
 
  321                                                 hNeutronOriginGe->Fill(
"Active neutron detector",1);
 
  322                                         if( VertexVolumeName.Contains(
"NeutronBallCrystal"))
 
  323                                                         hNeutronOriginGe->Fill(
"Passive neutron detector",1);
 
  324                                         if (VertexVolumeName.Contains(
"Crystal_101"))
 
  325                                                 hNeutronOriginGe->Fill(
"Crystal",1);
 
  326                                         if (VertexVolumeName.Contains (
"Capsule") || VertexVolumeName.Contains (
"ColdFinger") || VertexVolumeName.Contains (
"Cryostat"))
 
  327                                                 hNeutronOriginGe->Fill(
"Cryostat",1);
 
  328                                         if (VertexVolumeName.Contains(
"Glue"))
 
  329                                                 hNeutronOriginGe->Fill(
"Lumi glue test",1);
 
  330                                         if (VertexVolumeName.Contains(
"LumiElectronics"))
 
  331                                                 hNeutronOriginGe->Fill(
"Lumi electronics test",1);
 
  332                                         if (VertexVolumeName.Contains(
"BeamDump"))
 
  333                                                 hNeutronOriginGe->Fill(
"Beam dump",1);
 
  334                                         if (VertexVolumeName.Contains(
"cave"))
 
  335                                                 hNeutronOriginGe->Fill(
"Cave",1);
 
  342                                         if (!VertexVolumeName.Contains(
"Kermit") )
 
  344                                                 if (newNeutronKermit)
 
  347                                                         hNHitsGeKermitBall->Fill(
"Active neutron detector",1);
 
  348                                                         hNEkinKermit->Fill(NeutronEkin);
 
  349                                                         newNeutronKermit = 0;
 
  352                                                 if (NeutronTrackIDKermit !=hitgam->
GetTrackID()) 
 
  356                                                         newNeutronKermit = 1;
 
  359                                                 NeutronEnergyLossArrayKermit[nNeutronsKermit] += hitgam->
GetEnergyLoss()*1000;
 
  362                                                 hNHitsGeKermitBall->Fill(
"Active neutron detector",1);
 
  364                                                 hNEkinKermit->Fill(NeutronEkin);
 
  373                                         if (!VertexVolumeName.Contains(
"NeutronBall") )
 
  378                                                         hNHitsGeKermitBall->Fill(
"Passive neutron detector",1);
 
  379                                                         hNEkinBall->Fill(NeutronEkin);
 
  383                                                 if (NeutronTrackIDBall !=hitgam->
GetTrackID()) 
 
  390                                                 NeutronEnergyLossArrayBall[nNeutronsBall] += hitgam->
GetEnergyLoss()*1000;
 
  501                         for (Int_t 
i = 0; 
i <= nNeutronsGe; 
i++)
 
  504                                 hNEnergyLossGe->Fill(NeutronEnergyLossArrayGe[
i]);
 
  508                 if (nNeutronsKermit>-1)
 
  511                         for (Int_t 
i = 0; 
i <= nNeutronsKermit; 
i++)
 
  514                                 hNEnergyLossKermit->Fill(NeutronEnergyLossArrayKermit[
i]);
 
  518                 if (nNeutronsBall>-1)
 
  521                         for (Int_t 
i = 0; 
i <= nNeutronsBall; 
i++)
 
  524                                 hNEnergyLossBall->Fill(NeutronEnergyLossArrayBall[
i]);
 
  530                         for (Int_t 
i = 0; 
i <= nProtonsGe; 
i++)
 
  533                                 hPEnergyLossGe->Fill(ProtonEnergyLossArrayGe[
i]);
 
  539                                         for (Int_t 
i = 0; 
i <= nGammasGe; 
i++)
 
  542                                                 hGammaSpecGe->Fill(GammaEnergyLossArrayGe[
i]);
 
  550         cNHitsGe = 
new TCanvas(
"cNHitsGe",
"Neutron Hits",1600,600);
 
  551                 cNHitsGe->Divide(2,1);
 
  553         cNHitsGeKermitBall = 
new TCanvas(
"cNHitsGeKermitBall",
"Neutron Hits on all 3 detectors",800,600);
 
  555         cAllParticlesGe = 
new TCanvas(
"cAllParticles",
"All particles interacting in the germanium crystal", 1600, 600);
 
  556                 cAllParticlesGe->Divide(2,1);
 
  558         cAllParticlesPiezo = 
new TCanvas(
"cAllParticlesPiazo",
"All particles interacting in the piezo", 1600, 600);
 
  559                 cAllParticlesPiezo->Divide(2,1);
 
  561         cNeutronEkinGe = 
new TCanvas(
"cNeutronEkinGe",
"E_{kin} of neutrons", 1600, 600);
 
  562                 cNeutronEkinGe->Divide(2,1);
 
  564         cNeutronEkinKermit = 
new TCanvas(
"cNeutronEkinKermit",
"E_{kin} of neutrons", 1600, 600);
 
  565                 cNeutronEkinKermit->Divide(2,1);
 
  567         cNeutronEkinBall = 
new TCanvas(
"cNeutronEkinBall",
"E_{kin} of neutrons", 1600, 600);
 
  568                 cNeutronEkinBall->Divide(2,1);
 
  570         cProtonEkinGe = 
new TCanvas(
"cProtonEkinGe",
"E_{kin} of protons", 1600, 600);
 
  571                 cProtonEkinGe->Divide(2,1);
 
  573         cGammaEnergyGe= 
new TCanvas(
"cGammaEnergyGe",
"#gamma spectrum", 800, 600);
 
  576         hNHitsAngleGe->DrawCopy();      
 
  578         hNeutronOriginGe->DrawCopy();
 
  580         cNHitsGeKermitBall->cd();
 
  581         hNHitsGeKermitBall->DrawCopy();
 
  583         cAllParticlesGe->cd(1);
 
  584         hAllParticlesGe->DrawCopy();    
 
  585         cAllParticlesGe->cd(2);
 
  586         hAllParticlesEkinGe->DrawCopy(
"colz");
 
  588         cAllParticlesPiezo->cd(1);
 
  589         hAllParticlesPiezo->DrawCopy(); 
 
  590         cAllParticlesPiezo->cd(2);
 
  591         hAllParticlesPiezo2->DrawCopy();
 
  593         cNeutronEkinGe->cd(1);
 
  594         hNEkinGe->DrawCopy();                                           
 
  595         cNeutronEkinKermit->cd(1);
 
  596         hNEkinKermit->DrawCopy();                                               
 
  597         cNeutronEkinBall->cd(1);
 
  598         hNEkinBall->DrawCopy();                                         
 
  600         cNeutronEkinGe->cd(2);
 
  601         hNEnergyLossGe->DrawCopy();                     
 
  602         cNeutronEkinKermit->cd(2);
 
  603         hNEnergyLossKermit->DrawCopy();                 
 
  604         cNeutronEkinBall->cd(2);
 
  605         hNEnergyLossBall->DrawCopy();                   
 
  607         cProtonEkinGe->cd(1);
 
  608         hPEkinGe->DrawCopy();                                           
 
  609         cProtonEkinGe->cd(2);
 
  610         hPEnergyLossGe->DrawCopy();                     
 
  612         cGammaEnergyGe->cd();
 
  613         hGammaSpecGe->DrawCopy();                                               
 
  617         hNHitsAngleGe->Write(); 
 
  618         hNeutronOriginGe->Write();
 
  619         hNHitsGeKermitBall->Write();
 
  629         hNEkinKermit->Write();                                          
 
  642         for(
int i = 0;
i<hAllParticlesGe->GetNbinsX(); 
i++)
 
  644                 if (hAllParticlesGe->GetBinContent(
i) != 0)
 
  646                         cout << 
"PDG code:\t" << hAllParticlesGe->GetBinCenter(
i)-0.5 << 
"\tCount:\t"<<hAllParticlesGe->GetBinContent(
i) << endl;
 
  650         cout << 
"HypGe COSYBackgroundSim Ana:\tAnalysis finished succesfully" << endl;
 
  661         cout << endl << endl;
 
  662         cout << 
"Macro finished succesfully." << endl;
 
  664         cout << 
"Real time " << rtime << 
" s, CPU time " << ctime << 
" s" << endl;
 
  667         cout << 
"Hits\t" << Hits << endl;
 
TGeoManager * gGeoManager
TVector3 GetStartVertex() const 
Int_t GetDetectorID() const 
Double_t GetEnergyLoss() const 
Double_t GetpdgCode() const