00001
00002
00003
00004
00005
00006
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"
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
00045
00046
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
00054
00055
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
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
00070
00071
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
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
00116
00117
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
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
00143 if(!(signal||bg)){
00144 continue;
00145 }
00146
00147
00148 if(nr->GetHeader().GetEventNo()<0){
00149 continue;
00150 }
00151
00152 if(nr->GetHeader().GetTrackLength()>25){
00153 continue;
00154 }
00155
00156
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
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
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
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
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
00257 ewhist.Reset();
00258 owhist.Reset();
00259 emhist.Reset();
00260 omhist.Reset();
00261 }
00262
00263 return JobCResult::kPassed;
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
00283
00284 MSG("MSTTemplate",Msg::kDebug)<<"In MSTTemplate::DefaultConfig"<<endl;
00285
00286 static Registry r;
00287
00288
00289 std::string name = this->GetName();
00290 name += ".config.default";
00291 r.SetName(name.c_str());
00292
00293
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
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 }