Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

MSTTemplate.cxx

Go to the documentation of this file.
00001 
00002 // $Id: MSTTemplate.cxx,v 1.4 2008/11/19 18:22:51 rhatcher Exp $
00003 //
00004 // FILL_IN: [Document your code!!]
00005 //
00006 // vahle@hep.ucl.ac.uk
00008 #include "TH1F.h"
00009 #include "TProfile2D.h"
00010 #include "TFile.h"
00011 #include "TMath.h"
00012 #include "Conventions/Detector.h"
00013 #include "NueAna/MSTTemplate.h"
00014 #include "NueAna/NueRecord.h"
00015 #include "MessageService/MsgService.h"
00016 #include "MinosObjectMap/MomNavigator.h"
00017 #include "MessageService/MsgService.h"
00018 #include "JobControl/JobCModuleRegistry.h" // For JOBMODULE macro
00019 #include "HistMan/HistMan.h"
00020 
00021 const int CALend=110;
00022 const int SM1end=230;
00023 const int SM2end=484;
00024 const int NXBINS=31;
00025 const int NYBINS=10;
00026 const int NZBINS=31;
00027 const int NYMBINS=21;
00028 
00029 
00030 JOBMODULE(MSTTemplate, "MSTTemplate",
00031           "Makes hists to compare MST variables between detectors and truth classes");
00032 CVSID("$Id: MSTTemplate.cxx,v 1.4 2008/11/19 18:22:51 rhatcher Exp $");
00033 //......................................................................
00034 
00035 MSTTemplate::MSTTemplate():
00036   counter(0),
00037   fname(),
00038   fout(0),
00039   nlambdanele(0),
00040   nlambdanother(0),
00041   mipdistele(0),  
00042   mipdistother(0)
00043 {
00044   //x corresponds to the number of edges in the event
00045   //it goes from 0-30, then all events with 60<=#edges<300
00046   //are grouped together in one bin
00047   xbins=new double[NXBINS];
00048   for(int i=0;i<NXBINS-1;i++){
00049     xbins[i]=1.*i;
00050   }
00051   xbins[NXBINS-1]=300;
00052   
00053   //y corresponds to the values of the weights
00054   //it goes from 0-40, in steps of 5, 40<weights<1000 are
00055   //grouped together in one bin
00056   ybins=new double[NYBINS];
00057   for(int i=0;i<NYBINS-1;i++){
00058     ybins[i]=i*5.;
00059   }
00060   ybins[NYBINS-1]=1000.;
00061   
00062   //ymbins corresponds to the mip distributions, not great yet
00063   ymbins=new double[NYMBINS];
00064   for(int i=0;i<NYMBINS-1;i++){
00065     ymbins[i]=i*5;
00066   }
00067   ymbins[NYMBINS-1]=150;
00068   
00069   //z also corresponds to the number of edges in the event
00070   //it goes from 0-30, then all events with 30<#edges<100
00071   //are grouped together in one bin
00072   zbins=new double[NZBINS];
00073   for(int i=0;i<NZBINS-1;i++){
00074     zbins[i]=i;
00075   }
00076   zbins[NZBINS-1]=100;
00077 
00078 }
00079 
00080 //......................................................................
00081 
00082 MSTTemplate::~MSTTemplate()
00083 {
00084   delete [] xbins;
00085 
00086 }
00087 
00088 //......................................................................
00089 void MSTTemplate::BeginJob()
00090 {
00091 
00092   fout=new TFile(fname.c_str(),"RECREATE");
00093   
00094    //create the template hisograms
00095    nlambdanele=new TProfile2D("nlambdanele","nlambdanele",
00096                               NXBINS-1,xbins,NYBINS-1,ybins);
00097    nlambdanother=new TProfile2D("nlambdanother","nlambdanother",
00098                                 NXBINS-1,xbins,NYBINS-1,ybins);
00099    
00100    mipdistele=new TProfile2D("mipdistele","mipdistele",
00101                              NXBINS-1,xbins,NYMBINS-1,ymbins);
00102    mipdistother=new TProfile2D("mipdistother","mipdistother",
00103                                NXBINS-1,xbins,NYMBINS-1,ymbins);
00104 
00105 }
00106 
00107 
00108 JobCResult MSTTemplate::Ana(const MomNavigator* mom)
00109 {
00110   if(counter%1000==0){
00111     cout<<"on entry "<<counter<<endl;
00112   }
00113   counter++;
00114 
00115    //get all NueRecords from mom 
00116    //may have more than one per go since mom reads in a snarl's worth of data
00117    //so, this is a little more complicated than just asking for a NueRecord
00118    TObject *obj=0;
00119    TIter objiter = mom->FragmentIter();
00120    while((obj=objiter.Next())){
00121       NueRecord *nr = static_cast<NueRecord *>(obj);
00122       if(nr){
00123          MSG("MSTTemplate",Msg::kDebug)<<"Found a NueRecord in MOM"<<endl;
00124       }
00125       else{
00126          MSG("MSTTemplate",Msg::kError)<<"Didn't find a NueRecord in MOM"<<endl;
00127          continue;
00128       }
00129       MSG("MSTTemplate",Msg::kDebug)<<"Found a NueRecord "<<nr<<endl;
00130       
00131       //figure out whether event is signal or background
00132       bool signal = false;
00133       bool bg = false;
00134       if(abs(nr->mctrue.nuFlavor)==12&&nr->mctrue.interactionType==1&&
00135          nr->mctrue.resonanceCode==1001){
00136         signal=true;
00137       }
00138       if(nr->mctrue.interactionType==0){
00139         bg=true;
00140       }
00141 
00142       //if it's neither signal or bg, go on
00143       if(!(signal||bg)){
00144         continue;
00145       }
00146 
00147       //need at least 1 sucessfully reconstructed event
00148       if(nr->GetHeader().GetEventNo()<0){
00149         continue;
00150       }
00151       //only look at events for which mst actually gets calculated
00152       if(nr->GetHeader().GetTrackLength()>25){
00153         continue;
00154       }
00155       //only look at contained events (vertex contained, end doesn't go past 
00156       //calorimeter or sm gap
00157       if(nr->GetHeader().GetVldContext().GetDetector()==Detector::kFar){
00158         if(sqrt(pow(nr->srevent.vtxX,2)+pow(nr->srevent.vtxY,2))>3.87){
00159           continue;
00160         }
00161         if(nr->srevent.vtxZ<1||(nr->srevent.vtxZ>14&&nr->srevent.vtxZ<17)||
00162            nr->srevent.vtxZ>20){
00163           continue;
00164         }
00165         if((nr->srevent.begPlane<SM1end&&nr->srevent.endPlane>SM1end-2)||
00166            (nr->srevent.begPlane>SM1end&&nr->srevent.endPlane>SM2end-2)){
00167           continue;
00168         }         
00169       }
00170       else if(nr->GetHeader().GetVldContext().GetDetector()==Detector::kNear){
00171         if(sqrt(pow(nr->srevent.vtxX-1.5,2)+pow(nr->srevent.vtxY,2))>1.0){
00172           continue;
00173         }
00174         if(nr->srevent.vtxZ<4||nr->srevent.vtxZ>6.5){
00175           continue;
00176         }
00177         if(nr->srevent.endPlane>CALend-2){
00178           continue;
00179         }         
00180       }
00181       
00182     
00183       //make some temporary histograms
00184       TH1F ewhist("ewhist","ewhist",NYBINS-1,ybins);
00185       TH1F emhist("emhist","emhist",NYMBINS-1,ymbins);
00186       TH1F owhist("owhist","owhist",NYBINS-1,ybins);
00187       TH1F omhist("omhist","omhist",NYMBINS-1,ymbins);
00188 
00189       //fill the temp hists.
00190       for(int i=0;i<nr->mstvars.enn1;i++){
00191          if(nr->mstvars.eallw1[i]!=0){
00192             ewhist.Fill(nr->mstvars.eallw1[i]);
00193          }
00194          if(nr->mstvars.eallm1[i]!=0){   
00195             emhist.Fill(nr->mstvars.eallm1[i]);     
00196          }
00197       }
00198       for(int i=0;i<nr->mstvars.onn1;i++){
00199          if(nr->mstvars.oallw1[i]!=0){
00200             owhist.Fill(nr->mstvars.oallw1[i]);
00201          }
00202          if(nr->mstvars.oallm1[i]!=0){
00203             omhist.Fill(nr->mstvars.oallm1[i]);     
00204          }
00205       }
00206       
00207 
00208       if(signal){
00209          //fill signal profile hist.
00210          for(int j=1;j<=ewhist.GetNbinsX()+1;j++){
00211             nlambdanele->Fill(nr->mstvars.enn1,
00212                               ewhist.GetBinCenter(j),
00213                               ewhist.GetBinContent(j));
00214          }
00215          for(int j=1;j<=owhist.GetNbinsX()+1;j++){
00216             nlambdanele->Fill(nr->mstvars.onn1,
00217                               owhist.GetBinCenter(j),
00218                               owhist.GetBinContent(j));
00219          }
00220          for(int j=1;j<=emhist.GetNbinsX()+1;j++){
00221             mipdistele->Fill(nr->mstvars.enn1,
00222                              emhist.GetBinCenter(j),
00223                              emhist.GetBinContent(j));
00224          }
00225          for(int j=1;j<=omhist.GetNbinsX()+1;j++){
00226             mipdistele->Fill(nr->mstvars.onn1,
00227                              omhist.GetBinCenter(j),
00228                              omhist.GetBinContent(j));
00229          }
00230 
00231       }
00232       else if(bg){
00233          //fill bg profile hist.
00234          for(int j=1;j<=ewhist.GetNbinsX()+1;j++){
00235             nlambdanother->Fill(nr->mstvars.enn1,
00236                                 ewhist.GetBinCenter(j),
00237                                 ewhist.GetBinContent(j));
00238          }
00239          for(int j=1;j<=owhist.GetNbinsX()+1;j++){
00240             nlambdanother->Fill(nr->mstvars.onn1,
00241                                 owhist.GetBinCenter(j),
00242                                 owhist.GetBinContent(j));
00243          }
00244          for(int j=1;j<=emhist.GetNbinsX()+1;j++){
00245             mipdistother->Fill(nr->mstvars.enn1,
00246                                emhist.GetBinCenter(j),
00247                                emhist.GetBinContent(j));
00248          }
00249          for(int j=1;j<=omhist.GetNbinsX()+1;j++){
00250             mipdistother->Fill(nr->mstvars.onn1,
00251                                omhist.GetBinCenter(j),
00252                                omhist.GetBinContent(j));
00253          }
00254       }
00255 
00256       //reset the temp histograms
00257       ewhist.Reset();
00258       owhist.Reset();
00259       emhist.Reset();
00260       omhist.Reset();
00261    }
00262   
00263    return JobCResult::kPassed; // kNoDecision, kFailed, etc.
00264 }
00265 
00267 void MSTTemplate::EndJob()
00268 {
00269   if(fout!=0){
00270     if(fout->IsOpen()){
00271       fout->Write();
00272       fout->Close();
00273     }
00274   }
00275 }
00276 
00277 //......................................................................
00278 
00279 const Registry& MSTTemplate::DefaultConfig() const
00280 {
00281 //======================================================================
00282 // Supply the default configuration for the module
00283 //======================================================================
00284    MSG("MSTTemplate",Msg::kDebug)<<"In MSTTemplate::DefaultConfig"<<endl;
00285 
00286   static Registry r; // Default configuration for module
00287 
00288   // Set name of config
00289   std::string name = this->GetName();
00290   name += ".config.default";
00291   r.SetName(name.c_str());
00292 
00293   // Set values in configuration
00294   r.UnLockValues();
00295   r.Set("MSTTmpltFile","templates.root");
00296   r.LockValues();
00297 
00298   return r;
00299 }
00300 
00301 //......................................................................
00302 
00303 void MSTTemplate::Config(const Registry& r)
00304 {
00305 //======================================================================
00306 // Configure the module given the Registry r
00307 //======================================================================
00308   MSG("MSTTemplate",Msg::kDebug)<<"In MSTTemplate::Config"<<endl;
00309 
00310   const char* tmps;
00311 
00312   if(r.Get("MSTTmpltFile",tmps)) { fname = (string)(tmps);}
00313 }

Generated on Mon Feb 15 11:07:01 2010 for loon by  doxygen 1.3.9.1