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

MCMonitorCosmicHistograms.cxx

Go to the documentation of this file.
00001 
00002 //
00003 // Histograms used by MCMonitor (includes useful ancillary functions)
00004 //
00005 // Kregg Arms (arms@physics.umn.edu)
00007 #include <iostream>
00008 #include <sstream>
00009 #include "TClonesArray.h"
00010 #include "TDatabasePDG.h"
00011 #include "TParticlePDG.h"
00012 
00013 #include "MCMonitorCosmicHistograms.h"
00014 #include "MessageService/MsgService.h"
00015 #include "Conventions/Munits.h"
00016 #include "HistMan/HistMan.h"
00017 #include "MCNtuple/NtpMCRecord.h"
00018 #include "MCNtuple/NtpMCDigiScintHit.h"
00019 #include "MCNtuple/NtpMCStdHep.h"
00020 #include "MCNtuple/NtpMCTruth.h"
00021 #include "CandNtupleSR/NtpSRRecord.h"
00022 #include "CandNtupleSR/NtpSRShower.h"
00023 #include "CandNtupleSR/NtpSRTrack.h"
00024 #include "CandNtupleSR/NtpSRStrip.h"
00025 #include "TruthHelperNtuple/NtpTHRecord.h"
00026 #include "TruthHelperNtuple/NtpTHTrack.h"
00027 #include "StandardNtuple/NtpStRecord.h"
00028 #include "Plex/PlexPlaneId.h"
00029 
00030 CVSID("$Id: MCMonitorCosmicHistograms.cxx,v 1.1 2007/10/10 03:11:22 schubert Exp $");
00031 
00032 //_______________________________________________________________________
00033 MCMonitorCosmicHistograms::MCMonitorCosmicHistograms(std::string name)
00034 : fName(name),fDetector(Detector::kUnknown),fShieldFlag(kAll),fParticleId(0) {
00035   // Default constructor
00036 
00037 }
00038 
00039 //_______________________________________________________________________
00040 MCMonitorCosmicHistograms::~MCMonitorCosmicHistograms() {
00041   // Destructor
00042 
00043 }
00044 
00045 //_______________________________________________________________________
00046 void MCMonitorCosmicHistograms::FillHistograms(const NtpStRecord* strec,
00047                                                const NtpMCRecord* mcrec,
00048                                                const NtpSRRecord* srrec,
00049                                                const NtpTHRecord* threc) {
00050   // Public method to fill all histograms. Histograms created on first call.
00051 
00052   if (!strec && !mcrec && !srrec && !threc) return;
00053   
00054   // Set detector type
00055   const VldContext* vldc 
00056            = (strec)? strec->GetVldContext() : mcrec->GetVldContext();
00057   fDetector = vldc->GetDetector();
00058   
00059   std::string basepath = fName;
00060   FillHistsTrue(basepath,strec,mcrec);
00061   FillHistsReco(basepath,strec,srrec);
00062   FillHistsReTr(basepath,strec,mcrec,srrec,threc);
00063 
00064 }
00065   
00066 //_______________________________________________________________________
00067 void MCMonitorCosmicHistograms::FillHistsTrue(std::string basepath,
00068                                               const NtpStRecord* strec,
00069                                               const NtpMCRecord* mcrec) {
00070   // Private method to fill all ../True/.. histograms
00071 
00072   if (!strec && !mcrec) return;
00073   
00074   std::string truepath = basepath + "/True";
00075   
00076   const NtpMCSummary& mchdr = (strec)? strec->mchdr : mcrec->mchdr;
00077   
00078   // mchdr
00079   FillTrueNumEvt(truepath,mchdr.nmc);
00080   FillTrueNumStdHep(truepath,mchdr.nstdhep);
00081   FillTrueNumDigiHit(truepath,mchdr.ndigihit);
00082 
00083   const TDatabasePDG& dbpdg = *(TDatabasePDG::Instance());
00084   const int npid = 5;
00085   int pidarray[npid] = {13,-13,11,-11,2212}; // mu-,mu+,e-,e+,p
00086   
00087   // digihit
00088   const TClonesArray* digihitarray 
00089                        = (strec) ? strec->digihit : mcrec->digihit;
00090   if ( digihitarray ) {
00091     // Fill first without shield hits
00092     fShieldFlag = kNoShield;
00093     fParticleId = 0;
00094     FillHistsTrueDigiHit(truepath+"/NoShield",digihitarray,
00095                         " (VS Excl)");
00096     // Now fill for each particle type of interest
00097     for ( int ipid = 0; ipid < npid; ipid++ ) {
00098       fParticleId = pidarray[ipid]; // mu+
00099       std::string partname = "???";
00100       if ( dbpdg.GetParticle(fParticleId) ) partname
00101                               = dbpdg.GetParticle(fParticleId)->GetName();
00102       std::string partpath = truepath+"/NoShield/"+partname;
00103       std::string clause = " (VS Excl) (" + partname + ")";
00104       FillHistsTrueDigiHit(partpath,digihitarray,clause);
00105     }
00106     
00107     // Fill next with shield hits only
00108     fParticleId = 0;
00109     fShieldFlag = kShieldOnly;
00110     FillHistsTrueDigiHit(truepath+"/ShieldOnly",digihitarray,
00111                                                " (VS Only)");
00112     fShieldFlag = kAll;
00113   }
00114   
00115 }
00116 
00117 //_______________________________________________________________________
00118 void MCMonitorCosmicHistograms::FillHistsReco(std::string basepath,
00119                                               const NtpStRecord* strec,
00120                                               const NtpSRRecord* srrec) {
00121   // Private method to fill all ../Reco/.. histograms
00122 
00123   if (!strec && !srrec) return;
00124   
00125   std::string recopath = basepath + "/Reco";
00126   
00127   // strip
00128   const TClonesArray* stparray = (strec) ? strec->stp: srrec->stp;
00129   FillHistsRecoStp(recopath,stparray);
00130   
00131   // shower
00132   const TClonesArray* shwarray = (strec) ? strec->shw : srrec->shw;
00133   FillHistsRecoShw(recopath,shwarray);
00134 
00135   // track
00136   const TClonesArray* trkarray = (strec) ? strec->trk : srrec->trk;
00137   FillHistsRecoTrk(recopath,trkarray);
00138 
00139   // event
00140   //const TClonesArray* evtarray = (strec) ? strec->evt : srrec->evt;
00141   //FillHistsRecoEvt(recopath,evtarray);
00142   
00143   
00144 }
00145 
00146 //_______________________________________________________________________
00147 void MCMonitorCosmicHistograms::FillHistsReTr(std::string basepath,
00148                                               const NtpStRecord* strec,
00149                                               const NtpMCRecord* mcrec,
00150                                               const NtpSRRecord* srrec,
00151                                               const NtpTHRecord* threc) {
00152   // Private method to fill all ../ReTr/.. histograms
00153 
00154   if (!strec && (!mcrec || !srrec || !threc) ) return;
00155   
00156   std::string retrpath = basepath + "/ReTr";
00157 
00158   // tracks
00159   const TClonesArray* stdheparray = (strec) ? strec->stdhep : mcrec->stdhep;
00160   const TClonesArray* trkarray = (strec) ? strec->trk : srrec->trk;
00161   const TClonesArray* thtrkarray = (strec) ? strec->thtrk : threc->thtrk;
00162   FillHistsReTrTrk(retrpath,stdheparray,trkarray,thtrkarray);
00163   
00164 }
00165 
00166 //_______________________________________________________________________
00167 void MCMonitorCosmicHistograms::FillHistsReTrTrk(std::string retrpath,
00168                                               const TClonesArray* stdheparray,
00169                                               const TClonesArray* trkarray,
00170                                               const TClonesArray* thtrkarray) {
00171   // Private method to fill all ../ReTr/(PartType)/Trk histograms
00172   
00173   if ( !stdheparray || !trkarray || !thtrkarray ) return;
00174   
00175   for (int itrk = 0; itrk < thtrkarray->GetEntriesFast(); itrk++) {
00176     NtpTHTrack* thtrk = dynamic_cast<NtpTHTrack*>(thtrkarray->At(itrk));
00177     Int_t istdhep = thtrk->trkstdhep;
00178     if ( istdhep < 0 ) continue; // truth helper failed to find match if true
00179     NtpMCStdHep* stdhep=dynamic_cast<NtpMCStdHep*>(stdheparray->At(istdhep));
00180     std::string partname = stdhep->ParticleName();
00181     std::string partpath = retrpath + "/" + partname;
00182     NtpSRTrack*  srtrk = dynamic_cast<NtpSRTrack*>(trkarray->At(itrk));
00183     std::string clause = " (" + partname + ")";
00184     FillReTrDelQPCurve(partpath,*stdhep,*srtrk,clause);
00185   }
00186 
00187 }
00188 
00189 //_______________________________________________________________________
00190 void MCMonitorCosmicHistograms::FillReTrDelQPCurve(std::string partpath,
00191                             const NtpMCStdHep& stdhep,const NtpSRTrack& trk,
00192                             std::string clause) {
00193   // Private method to fill ../DelQPCurve histogram
00194 
00195   HistMan hm(partpath.c_str());
00196   TH1F* hist1 = hm.Get<TH1F>("DelQPCurve");
00197 
00198   if ( !hist1 ) {
00199     hist1 = new TH1F("DelQPCurve","[p/q - p/q(curvature)]",40,-100.,100.);
00200     std::string xtitle = "[p/q(true) - p/q(curvature)]"+clause;
00201     hist1->SetXTitle(xtitle.c_str());
00202     hist1->SetYTitle("Entries/5. GeV/c");
00203     hm.Adopt("",hist1);
00204   }
00205   
00206   double trkqp = (TMath::Abs(trk.momentum.qp) > 0.) ? (1/trk.momentum.qp) : 0;
00207   double stdhepqp = (stdhep.Charge() != 0 ) ? stdhep.P()/stdhep.Charge() : 0;
00208   hist1 -> Fill(stdhepqp - trkqp);
00209                                               
00210 }
00211 
00212 //_______________________________________________________________________
00213 void MCMonitorCosmicHistograms::FillHistsRecoStp(std::string recopath,
00214                                          const TClonesArray* stparray) {
00215   // Private method to fill ../Stp* histograms
00216   
00217   if ( !stparray ) return;
00218 
00219   HistMan hm(recopath.c_str());
00220 
00221   // For performance reasons, pre-read stp hists
00222   TH1F* eastphpe = 0;
00223   TH1F* westphpe = 0;
00224   FillRecoStpPerSnarl(recopath,stparray->GetEntriesFast());
00225   
00226   for ( int istp = 0; istp < stparray->GetEntriesFast(); istp++ ) {
00227     const NtpSRStrip& strip 
00228              = *(dynamic_cast<NtpSRStrip*>(stparray->At(istp)));
00229 
00230     if ( !eastphpe ) eastphpe = hm.Get<TH1F>("StpEastPHPE");
00231     if ( !westphpe ) westphpe = hm.Get<TH1F>("StpWestPHPE");
00232     
00233     // Determine if this is shield associated strip or not
00234     PlexPlaneId plexId(fDetector,strip.plane);
00235     bool isShield = plexId.IsVetoShield();
00236     if ( isShield ) continue;
00237 
00238     FillRecoStpEastPHPE(recopath,strip,eastphpe," (VS Excl) ");
00239     FillRecoStpWestPHPE(recopath,strip,westphpe," (VS Excl) ");
00240  
00241   }
00242 
00243   return;
00244   
00245 }
00246 
00247 
00248 //_______________________________________________________________________
00249 void MCMonitorCosmicHistograms::FillHistsRecoTrk(std::string recopath,
00250                                          const TClonesArray* trkarray) {
00251   // Private method to fill all ../Reco/Trk* histograms
00252   
00253   if ( !trkarray ) return;
00254 
00255   HistMan hm(recopath.c_str());
00256   FillRecoTrkPerSnarl(recopath,trkarray->GetEntriesFast());
00257   
00258   for ( int itrk = 0; itrk < trkarray->GetEntriesFast(); itrk++ ) {
00259     const NtpSRTrack& track 
00260              = *(dynamic_cast<NtpSRTrack*>(trkarray->At(itrk)));
00261 
00262     FillRecoTrkVtxDCosX(recopath,track);
00263     FillRecoTrkVtxDCosY(recopath,track);
00264     FillRecoTrkVtxDCosZ(recopath,track);
00265     FillRecoTrkRange(recopath,track);
00266     
00267   }
00268   
00269   return;
00270   
00271 }
00272 
00273 //_______________________________________________________________________
00274 void MCMonitorCosmicHistograms::FillRecoStpEastPHPE(std::string recopath,
00275                                                     const NtpSRStrip& stp,
00276                                                     TH1F* hist1,
00277                                                     std::string clause) {
00278   // Private method to fill ../StpEastPHPE histogram
00279 
00280   if ( !hist1 ) {
00281     HistMan hm(recopath.c_str());
00282     hist1 = new TH1F("StpEastPHPE","Strip East PH",100,0.,2000.);
00283     std::string xtitle = "Strip East PH(PE)" + clause;
00284     hist1->SetXTitle(xtitle.c_str());
00285     hist1->SetYTitle("Entries/20 PE");
00286     hm.Adopt("",hist1);
00287   }
00288   
00289   hist1 -> Fill(stp.ph0.sigcor);
00290                                               
00291 }
00292 
00293 //_______________________________________________________________________
00294 void MCMonitorCosmicHistograms::FillRecoStpWestPHPE(std::string recopath,
00295                                                     const NtpSRStrip& stp,
00296                                                     TH1F* hist1,
00297                                                     std::string clause) {
00298   // Private method to fill ../StpWestPHPE histogram
00299 
00300   if ( !hist1 ) {
00301     HistMan hm(recopath.c_str());
00302     hist1 = new TH1F("StpWestPHPE","Strip West PH",100,0.,2000.);
00303     std::string xtitle = "Strip West PH(PE)" + clause;
00304     hist1->SetXTitle(xtitle.c_str());
00305     hist1->SetYTitle("Entries/20 PE");
00306     hm.Adopt("",hist1);
00307   }
00308   
00309   hist1 -> Fill(stp.ph1.sigcor);
00310                                               
00311 }
00312 
00313 //_______________________________________________________________________
00314 void MCMonitorCosmicHistograms::FillRecoTrkVtxDCosX(std::string recopath,
00315                                                     const NtpSRTrack& trk,
00316                                                     std::string particlename) {
00317   // Private method to fill ../TrkVtxDCosX histogram
00318 
00319   HistMan hm(recopath.c_str());
00320 
00321   TH1F* hist1 = hm.Get<TH1F>("TrkVtxDCosX");
00322   if ( !hist1 ) {
00323     hist1 = new TH1F("TrkVtxDCosX","reco trk vtx dcos(x)",40,-1.,1.);
00324     std::string xtitle = particlename + " Reco Trk Vtx DCos(X)";
00325     hist1->SetXTitle(xtitle.c_str());
00326     hist1->SetYTitle("Entries/0.05");
00327     hm.Adopt("",hist1);
00328   }
00329   
00330   hist1 -> Fill(trk.vtx.dcosx);
00331                                               
00332 }
00333 
00334 //_______________________________________________________________________
00335 void MCMonitorCosmicHistograms::FillRecoTrkVtxDCosY(std::string recopath,
00336                                                     const NtpSRTrack& trk,
00337                                                     std::string particlename) {
00338   // Private method to fill all ../TrkVtxDCosY histogram
00339 
00340   HistMan hm(recopath.c_str());
00341 
00342   TH1F* hist1 = hm.Get<TH1F>("TrkVtxDCosY");
00343   if ( !hist1 ) {
00344     hist1 = new TH1F("TrkVtxDCosY","reco trk vtx dcos(y)",40,-1.,1.);
00345     std::string xtitle = particlename + " Reco Trk Vtx DCos(Y)";
00346     hist1->SetXTitle(xtitle.c_str());
00347     hist1->SetYTitle("Entries/0.05");
00348     hm.Adopt("",hist1);
00349   }
00350   
00351   hist1 -> Fill(trk.vtx.dcosy);
00352                                               
00353 }
00354 
00355 //_______________________________________________________________________
00356 void MCMonitorCosmicHistograms::FillRecoTrkVtxDCosZ(std::string recopath,
00357                                                     const NtpSRTrack& trk,
00358                                                     std::string particlename) {
00359   // Private method to fill all ../TrkVtxDCosZ histograms
00360 
00361   HistMan hm(recopath.c_str());
00362 
00363   TH1F* hist1 = hm.Get<TH1F>("TrkVtxDCosZ");
00364   if ( !hist1 ) {
00365     hist1 = new TH1F("TrkVtxDCosZ","reco trk vtx dcos(z)",40,-1.,1.);
00366     std::string xtitle = particlename + " Reco Trk Vtx DCos(Z)";
00367     hist1->SetXTitle(xtitle.c_str());
00368     hist1->SetYTitle("Entries/0.05");
00369     hm.Adopt("",hist1);
00370   }
00371   
00372   hist1 -> Fill(trk.vtx.dcosz);
00373                                               
00374 }
00375 
00376 //_______________________________________________________________________
00377 void MCMonitorCosmicHistograms::FillRecoTrkRange(std::string recopath,
00378                                                  const NtpSRTrack& trk,
00379                                                  std::string particlename) {
00380   // Private method to fill ../TrkRange histogram
00381 
00382   HistMan hm(recopath.c_str());
00383 
00384   TH1F* hist1 = hm.Get<TH1F>("TrkRange");
00385   if ( !hist1 ) {
00386     hist1 = new TH1F("TrkRange","reco trk range",64,0.,32.);
00387     std::string xtitle = particlename + " Reco Trk Range (m)";
00388     hist1->SetXTitle(xtitle.c_str());
00389     hist1->SetYTitle("Entries/0.5 m");
00390     hm.Adopt("",hist1);
00391   }
00392   
00393   hist1 -> Fill(trk.ds);
00394                                               
00395 }
00396 
00397 //_______________________________________________________________________
00398 void MCMonitorCosmicHistograms::FillRecoTrkPerSnarl(std::string recopath,
00399                                                     unsigned int ntrack) {
00400   // Private method to fill ../TrkPerSnarl histogram
00401 
00402   HistMan hm(recopath.c_str());
00403 
00404   TH1F* hist1 = hm.Get<TH1F>("TrkPerSnarl");
00405   if ( !hist1 ) {
00406     hist1 = new TH1F("TrkPerSnarl","track per snarl",21,-0.5,20.5);
00407     hist1->SetXTitle("tracks/snarl");
00408     hist1->SetYTitle("Entries/1");
00409     hm.Adopt("",hist1);
00410   }
00411   
00412   hist1 -> Fill(ntrack);
00413                                               
00414 }
00415 
00416 //_______________________________________________________________________
00417 void MCMonitorCosmicHistograms::FillRecoShwPerSnarl(std::string recopath,
00418                                                     unsigned int nshower) {
00419   // Private method to fill ../ShwPerSnarl histogram
00420 
00421   HistMan hm(recopath.c_str());
00422 
00423   TH1F* hist1 = hm.Get<TH1F>("ShwPerSnarl");
00424   if ( !hist1 ) {
00425     hist1 = new TH1F("ShwPerSnarl","shower per snarl",21,-0.5,20.5);
00426     hist1->SetXTitle("showers/snarl");
00427     hist1->SetYTitle("Entries/1");
00428     hm.Adopt("",hist1);
00429   }
00430   
00431   hist1 -> Fill(nshower);
00432                                               
00433 }
00434 
00435 //_______________________________________________________________________
00436 void MCMonitorCosmicHistograms::FillRecoStpPerSnarl(std::string recopath,
00437                                                     unsigned int nstrip) {
00438   // Private method to fill ../StpPerSnarl histogram
00439 
00440   HistMan hm(recopath.c_str());
00441 
00442   TH1F* hist1 = hm.Get<TH1F>("StpPerSnarl");
00443   if ( !hist1 ) {
00444     hist1 = new TH1F("StpPerSnarl","strip per snarl",100,-0.5,999.5);
00445     hist1->SetXTitle("strips/snarl");
00446     hist1->SetYTitle("Entries/1");
00447     hm.Adopt("",hist1);
00448   }
00449   
00450   hist1 -> Fill(nstrip);
00451                                               
00452 }
00453 
00454 //_______________________________________________________________________
00455 void MCMonitorCosmicHistograms::FillHistsRecoShw(std::string recopath,
00456                                        const TClonesArray* shwarray) {
00457   // Private method to fill all ../Reco/Shw* histograms
00458   
00459   if ( !shwarray ) return;
00460 
00461   HistMan hm(recopath.c_str());
00462 
00463   FillRecoShwPerSnarl(recopath,shwarray->GetEntriesFast());
00464   
00465   for ( int ishw = 0; ishw < shwarray->GetEntriesFast(); ishw++ ) {
00466     const NtpSRShower& shower 
00467              = *(dynamic_cast<NtpSRShower*>(shwarray->At(ishw)));
00468 
00469     FillRecoShwNumPlanes(recopath,shower);
00470     FillRecoShwEMGeV(recopath,shower);
00471     
00472   }
00473   
00474   return;
00475   
00476 }
00477 
00478 //_______________________________________________________________________
00479 void MCMonitorCosmicHistograms::FillRecoShwNumPlanes(std::string recopath,
00480                                               const NtpSRShower& shw) {
00481   // Private method to fill all ../ShwNumPlanes histograms
00482 
00483   HistMan hm(recopath.c_str());
00484 
00485   TH1F* hist1 = hm.Get<TH1F>("ShwNumPlanes");
00486   if ( !hist1 ) {
00487     hist1 = new TH1F("ShwNumPlanes","Shw Num Planes",25,0.,50.);
00488     hist1->SetXTitle("Shwr Num Planes");
00489     hist1->SetYTitle("Entries/2");
00490     hm.Adopt("",hist1);
00491   }
00492   
00493   hist1 -> Fill(shw.plane.n);
00494   
00495 }
00496 
00497 //_______________________________________________________________________
00498 void MCMonitorCosmicHistograms::FillRecoShwEMGeV(std::string recopath,
00499                                                  const NtpSRShower& shw) {
00500 
00501   // Private method to fill all ../ShwEMGeV histograms
00502 
00503   HistMan hm(recopath.c_str());
00504 
00505   TH1F* hist1 = hm.Get<TH1F>("ShwEMGeV");
00506   if ( !hist1 ) {
00507     hist1 = new TH1F("ShwEMGeV","Shw EM",40,0.,20.);
00508     hist1->SetXTitle("Shwr EM (GeV)");
00509     hist1->SetYTitle("Entries/0.5 GeV");
00510     hm.Adopt("",hist1);
00511   }
00512   
00513   hist1 -> Fill(shw.shwph.EMgev);
00514   
00515 }
00516 
00517 //_______________________________________________________________________
00518 void MCMonitorCosmicHistograms::FillTrueNumEvt(std::string truepath,
00519                                                int nmc) {
00520   // Private method to fill ../True/NumEvtPerSnarl 
00521   
00522   HistMan hm(truepath.c_str());
00523 
00524   TH1F* hist1 = hm.Get<TH1F>("NumEvtPerSnarl");
00525   if ( !hist1 ) {
00526     hist1 = new TH1F("NumEvtPerSnarl","True Num Evt/Snarl",60,0.,60.);
00527     hist1->SetXTitle("True Num Evt/Snarl");
00528     hist1->SetYTitle("Entries/1");
00529     hm.Adopt("",hist1);
00530   }
00531   
00532   hist1 -> Fill(nmc);
00533   
00534 }
00535 
00536 //_______________________________________________________________________
00537 void MCMonitorCosmicHistograms::FillTrueNumStdHep(std::string truepath,
00538                                                   int nstdhep) {
00539   // Private method to fill ../True/NumStdHepPerSnarl 
00540   
00541   HistMan hm(truepath.c_str());
00542 
00543   TH1F* hist1 = hm.Get<TH1F>("NumStdHepPerSnarl");
00544   if ( !hist1 ) {
00545     hist1 = new TH1F("NumStdHepPerSnarl","Num StdHep/Snarl",50,0.,100.);
00546     hist1->SetXTitle("Num StdHep/Snarl");
00547     hist1->SetYTitle("Entries/2");
00548     hm.Adopt("",hist1);
00549   }
00550   
00551   hist1 -> Fill(nstdhep);
00552   
00553 }
00554   
00555 //_______________________________________________________________________
00556 void MCMonitorCosmicHistograms::FillTrueNumDigiHit(std::string truepath,
00557                                       int ndigihit, std::string clause) {
00558   // Private method to fill ../True/NumDigiHitPerSnarl 
00559   
00560   HistMan hm(truepath.c_str());
00561 
00562   TH1F* hist1 = hm.Get<TH1F>("NumDigiHitPerSnarl");
00563   if ( !hist1 ) {
00564     Float_t maxrange = 10000;
00565     Int_t nbin = 50;
00566     if ( fParticleId == -13 || fParticleId == 13 || fParticleId == -11 ) 
00567                                              { maxrange=250; nbin=50; }
00568     //if ( fParticleId == 2212 ) { maxrange = 10; nbin = 40; }
00569     
00570     hist1 = new TH1F("NumDigiHitPerSnarl","Num DigiHit/Snarl",nbin,
00571                                                       0.,maxrange);
00572     std::string xtitle = "Num DigiHits/Snarl" + clause;
00573     hist1->SetXTitle(xtitle.c_str());
00574     Float_t binwidth = maxrange/nbin;
00575     std::ostringstream oss;
00576     oss << std::dec << binwidth;
00577     std::string ytitle = "Entries/"+oss.str();
00578     hist1->SetYTitle(ytitle.c_str());
00579     hm.Adopt("",hist1);
00580   }
00581   
00582   hist1 -> Fill(ndigihit);
00583   
00584 }
00585 
00586 //_______________________________________________________________________
00587 void MCMonitorCosmicHistograms::FillHistsTrueDigiHit(std::string truepath,
00588                                        const TClonesArray* digihitarray,
00589                                        std::string clause) {
00590   // Private method to fill all ../True/DigiHit/.. histograms
00591   
00592   if ( !digihitarray ) return;
00593   std::string digihitpath = truepath + "/DigiHit";
00594 
00595   HistMan hm(digihitpath.c_str());
00596   // For performance reasons, pre-read digihit hists
00597   TH1F* dshist1 = 0;
00598   TH1F* dsbyephist1 = 0;
00599   TProfile* dsbyepvsdsprof = 0;
00600   TH1F* dehist1 = 0;
00601   TH1F* dedshist1 = 0;
00602   TH1F* dedsbyephist1 = 0;
00603   TProfile* dedsvspeprof = 0;
00604   TProfile* dedsbyepvspeprof = 0;
00605   
00606   int ndigihit = 0;
00607   for ( int ihit = 0; ihit < digihitarray->GetEntriesFast(); ihit++ ) {
00608     const NtpMCDigiScintHit& digihit 
00609              = *(dynamic_cast<NtpMCDigiScintHit*>(digihitarray->At(ihit)));
00610 
00611     // Determine if this is shield associated hit or not
00612     PlexPlaneId plexId(fDetector,digihit.plane);
00613     bool isShield = plexId.IsVetoShield();
00614     if ( isShield && fShieldFlag == kNoShield ) continue;
00615     if ( !isShield && fShieldFlag == kShieldOnly ) continue;
00616     if ( fParticleId != 0 && digihit.pId != fParticleId ) continue;
00617     
00618     ndigihit++;
00619     
00620     if ( !dshist1 ) dshist1 = hm.Get<TH1F>("dS");
00621     if ( !dsbyephist1 ) dsbyephist1 = hm.Get<TH1F>("dSByEndPoints");
00622     if ( !dsbyepvsdsprof) dsbyepvsdsprof=hm.Get<TProfile>("dSByEndPointsvsdS");
00623     if ( !dehist1 ) dehist1 = hm.Get<TH1F>("dE");
00624     if ( !dedshist1 ) dedshist1 = hm.Get<TH1F>("dEdS");
00625     if ( !dedsbyephist1 ) dedsbyephist1 = hm.Get<TH1F>("dEdSByEndPoints");
00626     if ( !dedsvspeprof) dedsvspeprof = hm.Get<TProfile>("dEdSvspE");
00627     if ( !dedsbyepvspeprof) dedsbyepvspeprof = hm.Get<TProfile>("dEdSByEndPointsvspE");
00628 
00629     FillTrueDigiHitdS(digihitpath,digihit,dshist1,clause);
00630     FillTrueDigiHitdSByEndPoints(digihitpath,digihit,dsbyephist1,clause);
00631     FillTrueDigiHitdSByEndPointsvsdS(digihitpath,digihit,dsbyepvsdsprof,
00632                                      clause);
00633     FillTrueDigiHitdE(digihitpath,digihit,dehist1,clause);
00634     FillTrueDigiHitdEdS(digihitpath,digihit,dedshist1,clause);
00635     FillTrueDigiHitdEdSByEndPoints(digihitpath,digihit,dedsbyephist1,clause);
00636     FillTrueDigiHitdEdSvspE(digihitpath,digihit,dedsvspeprof,clause);
00637     FillTrueDigiHitdEdSByEndPointsvspE(digihitpath,digihit,dedsbyepvspeprof,
00638                                       clause);
00639 
00640   }
00641 
00642   FillTrueNumDigiHit(digihitpath,ndigihit,clause);
00643   
00644   return;
00645   
00646 }
00647 
00648 //_______________________________________________________________________
00649 void MCMonitorCosmicHistograms::FillTrueDigiHitpId(
00650        std::string digihitpath, const NtpMCDigiScintHit& digihit,
00651        TH1F* hist1,std::string clause) {
00652   // Private method to fill ../DigiHit/pId histogram
00653 
00654   if ( !hist1 ) {
00655     hist1 = new TH1F("pId","DigiHit Particle Id",5000,-2500.,2500.);
00656     std::string xtitle = "DigiHit Particle Id" + clause;
00657     hist1->SetXTitle(xtitle.c_str());
00658     hist1->SetYTitle("Entries/1");
00659     HistMan hm(digihitpath.c_str());
00660     hm.Adopt("",hist1);
00661   }
00662   
00663   hist1 -> Fill(digihit.pId);
00664 
00665 }
00666 
00667 //_______________________________________________________________________
00668 void MCMonitorCosmicHistograms::FillTrueDigiHitTrkId(
00669        std::string digihitpath, const NtpMCDigiScintHit& digihit,
00670        TH1F* hist1,std::string clause) {
00671   // Private method to fill ../DigiHit/TrkId histogram
00672 
00673   if ( !hist1 ) {
00674     hist1 = new TH1F("TrkId","DigiHit StdHep Array Index",200,-100.,100.);
00675     std::string xtitle = "DigiHit StdHep Array Index" + clause;
00676     hist1->SetXTitle(xtitle.c_str());
00677     hist1->SetYTitle("Entries/1");
00678     HistMan hm(digihitpath.c_str());
00679     hm.Adopt("",hist1);
00680   }
00681   
00682   hist1 -> Fill(digihit.trkId);
00683 
00684 }
00685 
00686 //_______________________________________________________________________
00687 void MCMonitorCosmicHistograms::FillTrueDigiHitdS(
00688        std::string digihitpath, const NtpMCDigiScintHit& digihit,
00689        TH1F* hist1,std::string clause) {
00690   // Private method to fill ../DigiHit/dS histogram
00691 
00692   if ( !hist1 ) {
00693     hist1 = new TH1F("dS","DigiHits Hit dS",150,0.,5.);
00694     std::string xtitle = "DigiHit dS (cm)" + clause;
00695     hist1->SetXTitle(xtitle.c_str());
00696     hist1->SetYTitle("Entries/0.033 cm");
00697     HistMan hm(digihitpath.c_str());
00698     hm.Adopt("",hist1);
00699   }
00700 
00701   hist1 -> Fill(digihit.dS/Munits::cm);
00702 
00703 }
00704 
00705 //_______________________________________________________________________
00706 void MCMonitorCosmicHistograms::FillTrueDigiHitdSByEndPoints(
00707        std::string digihitpath, const NtpMCDigiScintHit& digihit,
00708        TH1F* hist1,std::string clause) {
00709   // Private method to fill ../DigiHit/dS histogram
00710 
00711   if ( !hist1 ) {
00712     hist1 = new TH1F("dSByEndPoints","DigiHits dS by EndPoints",150,0.,5.);
00713     std::string xtitle = "DigiHit dS_{linear} (cm)" + clause;
00714     hist1->SetXTitle(xtitle.c_str());
00715     hist1->SetYTitle("Entries/0.033 cm");
00716     HistMan hm(digihitpath.c_str());
00717     hm.Adopt("",hist1);
00718   }
00719 
00720   double dx = digihit.x1 - digihit.x0;
00721   double dy = digihit.y1 - digihit.y0;
00722   double dz = digihit.z1 - digihit.z0;
00723   double dsbyendpoints = sqrt(dx*dx+dy*dy+dz*dz)/Munits::cm;
00724 
00725   hist1 -> Fill(dsbyendpoints);
00726 
00727 }
00728 
00729 //_______________________________________________________________________
00730 void MCMonitorCosmicHistograms::FillTrueDigiHitdE(
00731        std::string digihitpath, const NtpMCDigiScintHit& digihit,
00732        TH1F* hist1,std::string clause) {
00733   // Private method to fill ../DigiHit/dE
00734 
00735   if ( !hist1 ) {
00736     hist1 = new TH1F("dE","DigiHits Hit dE",100,0.,5.);
00737     std::string xtitle = "DigiHit dE (MeV)" + clause;
00738     hist1->SetXTitle(xtitle.c_str());
00739     hist1->SetYTitle("Entries/0.05 MeV");
00740     HistMan hm(digihitpath.c_str());
00741     hm.Adopt("",hist1);
00742   }
00743 
00744   hist1 -> Fill(digihit.dE/Munits::MeV);
00745 
00746 }
00747 
00748 //_______________________________________________________________________
00749 void MCMonitorCosmicHistograms::FillTrueDigiHitdEdS(
00750        std::string digihitpath, const NtpMCDigiScintHit& digihit,
00751        TH1F* hist1,std::string clause) {
00752   // Private method to fill ../DigiHit/dEdS histogram
00753 
00754   if ( !hist1 ) {
00755     hist1 = new TH1F("dEdS","DigiHits Hit dE/dS",100,0.,5.);
00756     std::string xtitle = "DigiHit dE/dS (MeV/cm)" + clause;
00757     hist1->SetXTitle(xtitle.c_str());
00758     hist1->SetYTitle("Entries/0.05 MeV/cm");
00759     HistMan hm(digihitpath.c_str());
00760     hm.Adopt("",hist1);
00761   }
00762 
00763   double dEdS = ( digihit.dS > 1.e-10 ) ?
00764     digihit.dE/Munits::MeV/(digihit.dS/Munits::cm) : 999.;
00765   
00766   hist1 -> Fill(dEdS);
00767 
00768 }
00769 
00770 //_______________________________________________________________________
00771 void MCMonitorCosmicHistograms::FillTrueDigiHitdEdSByEndPoints(
00772        std::string digihitpath, const NtpMCDigiScintHit& digihit,
00773        TH1F* hist1,std::string clause) {
00774   // Private method to fill ../DigiHit/dEdSByEndPoints histogram
00775 
00776   if ( !hist1 ) {
00777     hist1 = new TH1F("dEdSByEndPoints","DigiHits Hit dE/dS By EndPoints",
00778                                                             100,0.,5.);
00779     std::string xtitle = "DigiHit dE/dS_{linear} (MeV/cm)" + clause;
00780     hist1->SetXTitle(xtitle.c_str());
00781     hist1->SetYTitle("Entries/0.05 MeV/cm");
00782     HistMan hm(digihitpath.c_str());
00783     hm.Adopt("",hist1);
00784   }
00785 
00786   double dx = digihit.x1 - digihit.x0;
00787   double dy = digihit.y1 - digihit.y0;
00788   double dz = digihit.z1 - digihit.z0;
00789   double dsbyendpoints = sqrt(dx*dx+dy*dy+dz*dz);
00790 
00791   // for ds greater than a micron
00792   double dEdS = ( dsbyendpoints > 1.e-10 ) ?
00793     digihit.dE/Munits::MeV/(dsbyendpoints/Munits::cm) : 999.;
00794   
00795   hist1 -> Fill(dEdS);
00796 
00797 }
00798 
00799 //_______________________________________________________________________
00800 void MCMonitorCosmicHistograms::FillTrueDigiHitdSByEndPointsvsdS (
00801        std::string digihitpath, const NtpMCDigiScintHit& digihit,
00802        TProfile* prof,std::string clause) {
00803   // Private method to fill ../DigiHit/dEdSvspE profile
00804 
00805   if ( !prof ) { 
00806     prof = new TProfile("dSByEndPointsvsdS","DigiHit dSByEndPoints vs dS",
00807                                                     150,0.,5.,0.,5.,"");
00808     std::string xtitle = "dS (cm)" + clause;
00809     prof->SetXTitle(xtitle.c_str());
00810     prof->SetYTitle("dS_{linear} (cm)");
00811     HistMan hm(digihitpath.c_str());
00812     hm.Adopt("",prof);
00813   }
00814 
00815   double dx = digihit.x1 - digihit.x0;
00816   double dy = digihit.y1 - digihit.y0;
00817   double dz = digihit.z1 - digihit.z0;
00818   double dsbyendpoints = sqrt(dx*dx+dy*dy+dz*dz)/Munits::cm;
00819   prof -> Fill(digihit.dS/Munits::cm,dsbyendpoints);
00820 
00821 }
00822 
00823 //_______________________________________________________________________
00824 void MCMonitorCosmicHistograms::FillTrueDigiHitdEdSvspE (
00825        std::string digihitpath, const NtpMCDigiScintHit& digihit,
00826        TProfile* prof,std::string clause) {
00827   // Private method to fill ../DigiHit/dEdSvspE profile
00828 
00829   if ( !prof ) { 
00830     prof = new TProfile("dEdSvspE","DigiHit dE/dx vs log10(gamma*beta)",
00831                                                     40,-1.,3.,0.,50.,"");
00832     std::string xtitle = "log10(#gamma*#beta = p/Mc)" + clause;
00833     prof->SetXTitle(xtitle.c_str());
00834     prof->SetYTitle("DigiHit dE/dS (MeV/cm)");
00835     HistMan hm(digihitpath.c_str());
00836     hm.Adopt("",prof);
00837   }
00838 
00839   double dEdS = ( digihit.dS > 1.e-10 ) ?
00840     (digihit.dE/Munits::MeV)/(digihit.dS/Munits::cm) : -999.;
00841   if ( dEdS < 0 ) return;
00842   
00843   //cout << "dE " << digihit.dE << " dS " << digihit.dS 
00844   //      << " dEdS (MeV/cm)" << dEdS << endl;
00845   
00846   const TDatabasePDG& dbpdg = *(TDatabasePDG::Instance());
00847   TParticlePDG* particle = dbpdg.GetParticle(digihit.pId);
00848   if ( !particle ) {
00849     MSG("MCMon",Msg::kWarning) << "In FillTrueDigiHitdEdSvspE:\n"
00850                                << "No particle of type " << digihit.pId
00851                                << " in PDG database. Skipped hit." << endl;
00852     return;
00853   }
00854   
00855   Double_t partmass = particle->Mass();
00856   //cout << "partmass " << partmass << endl;
00857   //cout << "digihit.pE " << digihit.pE << endl;
00858  
00859   Double_t betagamma2 = pow(digihit.pE/partmass,2) - 1.;
00860   if ( betagamma2 < 0. ) return; // precision errors
00861   
00862   Double_t log10betagamma = log10(sqrt(betagamma2));
00863   //cout << "log10(beta*gamma) " << log10betagamma << endl;
00864   
00865   prof -> Fill(log10betagamma,dEdS);
00866 
00867 }
00868 
00869 //_______________________________________________________________________
00870 void MCMonitorCosmicHistograms::FillTrueDigiHitdEdSByEndPointsvspE (
00871        std::string digihitpath, const NtpMCDigiScintHit& digihit,
00872        TProfile* prof,std::string clause) {
00873   // Private method to fill ../DigiHit/dEdSByEndPointsvspE profile
00874 
00875   if ( !prof ) { 
00876     prof = new TProfile("dEdSByEndPointsvspE",
00877                         "DigiHit dE/dx_{linear} vs log10(gamma*beta)",
00878                                                     40,-1.,3.,0.,50.,"");
00879     std::string xtitle = "log10(#gamma*#beta = p/Mc)" + clause;
00880     prof->SetXTitle(xtitle.c_str());
00881     prof->SetYTitle("DigiHit dE/dS (MeV/cm)");
00882     HistMan hm(digihitpath.c_str());
00883     hm.Adopt("",prof);
00884   }
00885 
00886   double dx = digihit.x1 - digihit.x0;
00887   double dy = digihit.y1 - digihit.y0;
00888   double dz = digihit.z1 - digihit.z0;
00889   double dsbyendpoints = sqrt(dx*dx+dy*dy+dz*dz);
00890 
00891   double dEdS = ( dsbyendpoints > 1.e-10 ) ?
00892     (digihit.dE/Munits::MeV)/(dsbyendpoints/Munits::cm) : -999.;
00893   if ( dEdS < 0 ) return;
00894   
00895   
00896   const TDatabasePDG& dbpdg = *(TDatabasePDG::Instance());
00897   TParticlePDG* particle = dbpdg.GetParticle(digihit.pId);
00898   if ( !particle ) {
00899     MSG("MCMon",Msg::kWarning) << "In FillTrueDigiHitdEdSByEndPointsvspE:\n"
00900                                << "No particle of type " << digihit.pId
00901                                << " in PDG database. Skipped hit." << endl;
00902     return;
00903   }
00904   
00905   Double_t partmass = particle->Mass();
00906  
00907   Double_t betagamma2 = pow(digihit.pE/partmass,2) - 1.;
00908   if ( betagamma2 < 0. ) return; // precision errors
00909   
00910   Double_t log10betagamma = log10(sqrt(betagamma2));
00911   
00912   prof -> Fill(log10betagamma,dEdS);
00913 
00914 }
00915 
00916   
00917 //_______________________________________________________________________
00918 int MCMonitorCosmicHistograms::NumHistograms(const TFolder* baseFolder) const {
00919   // Default argument null => start at base folder
00920   // number of histograms in the class
00921   
00922   int numHist = 0;
00923   
00924   if ( !baseFolder ) {
00925     HistMan hm(fName.c_str());
00926     const TFolder* folder = dynamic_cast<TFolder*>
00927                             (hm.BaseFolder().FindObject(fName.c_str()));
00928     if ( folder ) return NumHistograms(folder);
00929   }
00930   else {
00931     cout << "In NumHistograms for folder " << baseFolder -> GetName() << endl;
00932 
00933     TCollection* objlist = baseFolder -> GetListOfFolders();
00934     TIter nextobj(objlist);
00935     TObject* obj = 0;
00936     while ( ( obj = (TObject*)nextobj() ) ) {
00937       cout << "Printing object" << endl;
00938       obj -> Print();
00939       TFolder* folder = dynamic_cast<TFolder*>(obj);
00940       if ( folder ) numHist += this -> NumHistograms(folder);
00941       else numHist++;
00942     }
00943   }
00944   
00945   return numHist;
00946    
00947 }
00948 
00949 //_______________________________________________________________________
00950 void MCMonitorCosmicHistograms::SetCanRebin(const TFolder* baseFolder) {
00951   // Default argument null => start at base folder
00952   // Set all the histograms so they can be rebinned by the user by default
00953 
00954   if ( !baseFolder ) {
00955     HistMan hm(fName.c_str());
00956     const TFolder* folder = dynamic_cast<TFolder*>
00957                             (hm.BaseFolder().FindObject(fName.c_str()));
00958     if ( folder ) return SetCanRebin(folder);
00959   }
00960   else {
00961     cout << "In SetCanRebin for folder " << baseFolder -> GetName() << endl;
00962 
00963     TCollection* objlist = baseFolder -> GetListOfFolders();
00964     TIter nextobj(objlist);
00965     TObject* obj = 0;
00966     while ( ( obj = (TObject*)nextobj() ) ) {
00967       cout << "Printing object" << endl;
00968       obj -> Print();
00969       TFolder* folder = dynamic_cast<TFolder*>(obj);
00970       if ( folder ) this -> SetCanRebin(folder);
00971       else {
00972         TH1* hist = dynamic_cast<TH1*>(obj);
00973         hist -> SetBit(TH1::kCanRebin);
00974       }
00975     }
00976   }
00977   
00978   return;
00979    
00980 }
00981 
00982 //_______________________________________________________________________
00983 void MCMonitorCosmicHistograms::AllSumw2(const TFolder* baseFolder) {
00984   // Default argument null => start at base folder
00985   // sets default Poisson errors on all histograms
00986   
00987   if ( !baseFolder ) {
00988     HistMan hm(fName.c_str());
00989     const TFolder* folder = dynamic_cast<TFolder*>
00990                             (hm.BaseFolder().FindObject(fName.c_str()));
00991     if ( folder ) return AllSumw2(folder);
00992   }
00993   else {
00994     cout << "In AllSumw2 for folder " << baseFolder -> GetName() << endl;
00995 
00996     TCollection* objlist = baseFolder -> GetListOfFolders();
00997     TIter nextobj(objlist);
00998     TObject* obj = 0;
00999     while ( ( obj = (TObject*)nextobj() ) ) {
01000       cout << "Printing object" << endl;
01001       obj -> Print();
01002       TFolder* folder = dynamic_cast<TFolder*>(obj);
01003       if ( folder ) this -> AllSumw2(folder);
01004       else {
01005         TH1* hist = dynamic_cast<TH1*>(obj);
01006         if ( hist ) {
01007           TProfile* prof = dynamic_cast<TProfile*>(obj);
01008           if (!prof) hist -> Sumw2();
01009         }
01010       }
01011     }
01012   }
01013   
01014   return;
01015    
01016 }
01017 

Generated on Mon Feb 15 11:06:58 2010 for loon by  doxygen 1.3.9.1